From 562389d360f8d1e726055ae7c40f390f365a11d7 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 31 Dec 2019 21:25:16 +0100 Subject: [PATCH] - remove syntax::{span_warn!, span_err!, span_fatal!. struct_err!} - remove syntax::{help!, span_help!, span_note!} - remove unused syntax::{struct_span_fatal, struct_span_err_or_warn!, span_err_or_warn!} - lintify check_for_bindings_named_same_as_variants + conflicting_repr_hints - inline syntax::{struct_span_warn!, diagnostic_used!} - stringify_error_code! -> error_code! & use it more. - find_plugin_registrar: de-fatalize an error - de-fatalize metadata errors - move type_error_struct! to rustc_typeck - struct_span_err! -> rustc_errors --- Cargo.lock | 2 + src/librustc/hir/check_attr.rs | 23 ++- src/librustc/infer/error_reporting/mod.rs | 2 +- .../infer/error_reporting/need_type_info.rs | 15 +- .../nice_region_error/different_lifetimes.rs | 1 + .../nice_region_error/named_anon_conflict.rs | 2 +- src/librustc/infer/error_reporting/note.rs | 2 +- src/librustc/infer/opaque_types/mod.rs | 8 +- src/librustc/lint/builtin.rs | 13 ++ src/librustc/lint/context.rs | 7 +- src/librustc/lint/levels.rs | 7 +- src/librustc/middle/lang_items.rs | 6 +- src/librustc/middle/weak_lang_items.rs | 10 +- src/librustc/mir/interpret/error.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/on_unimplemented.rs | 11 +- src/librustc/traits/query/dropck_outlives.rs | 8 +- src/librustc/traits/specialize/mod.rs | 1 + src/librustc/ty/query/plumbing.rs | 6 +- src/librustc_ast_lowering/expr.rs | 18 +- src/librustc_ast_lowering/item.rs | 2 +- src/librustc_ast_lowering/lib.rs | 9 +- src/librustc_builtin_macros/asm.rs | 33 ++-- .../deriving/default.rs | 10 +- src/librustc_codegen_ssa/common.rs | 3 +- src/librustc_codegen_ssa/lib.rs | 2 - src/librustc_codegen_ssa/mir/statement.rs | 11 +- src/librustc_errors/diagnostic_builder.rs | 19 ++ src/librustc_metadata/creader.rs | 8 +- src/librustc_metadata/locator.rs | 17 +- src/librustc_metadata/native_libs.rs | 4 +- .../borrow_check/type_check/mod.rs | 1 + src/librustc_mir/hair/pattern/check_match.rs | 40 +++-- src/librustc_mir/hair/pattern/mod.rs | 7 +- src/librustc_mir/lib.rs | 2 - .../transform/check_consts/ops.rs | 18 +- .../transform/check_consts/validation.rs | 1 + src/librustc_mir/transform/check_unsafety.rs | 5 +- src/librustc_mir/util/borrowck_errors.rs | 5 +- src/librustc_parse/parser/diagnostics.rs | 4 +- src/librustc_parse/parser/item.rs | 3 +- src/librustc_parse/parser/mod.rs | 3 +- src/librustc_parse/parser/ty.rs | 3 +- src/librustc_passes/ast_validation.rs | 33 +++- src/librustc_passes/check_const.rs | 4 +- src/librustc_passes/diagnostic_items.rs | 2 +- src/librustc_passes/entry.rs | 9 +- src/librustc_passes/intrinsicck.rs | 1 + src/librustc_passes/lib.rs | 2 - src/librustc_passes/lib_features.rs | 1 + src/librustc_passes/loops.rs | 3 +- src/librustc_passes/region.rs | 4 +- src/librustc_passes/stability.rs | 1 + src/librustc_plugin_impl/Cargo.toml | 1 + src/librustc_plugin_impl/load.rs | 2 +- src/librustc_privacy/Cargo.toml | 1 + src/librustc_privacy/lib.rs | 4 +- src/librustc_resolve/build_reduced_graph.rs | 25 +-- src/librustc_resolve/diagnostics.rs | 3 +- src/librustc_resolve/imports.rs | 4 +- src/librustc_resolve/late.rs | 40 ++--- src/librustc_resolve/late/diagnostics.rs | 11 +- src/librustc_resolve/lib.rs | 4 +- src/librustc_resolve/lifetimes.rs | 44 +++-- src/librustc_typeck/astconv.rs | 25 ++- src/librustc_typeck/check/autoderef.rs | 1 + src/librustc_typeck/check/callee.rs | 3 +- src/librustc_typeck/check/cast.rs | 20 ++- src/librustc_typeck/check/coercion.rs | 2 +- src/librustc_typeck/check/compare_method.rs | 4 +- src/librustc_typeck/check/dropck.rs | 2 +- src/librustc_typeck/check/expr.rs | 13 +- src/librustc_typeck/check/intrinsic.rs | 16 +- src/librustc_typeck/check/method/probe.rs | 6 +- src/librustc_typeck/check/method/suggest.rs | 12 +- src/librustc_typeck/check/mod.rs | 33 +++- src/librustc_typeck/check/op.rs | 2 +- src/librustc_typeck/check/pat.rs | 13 +- src/librustc_typeck/check/wfcheck.rs | 6 +- src/librustc_typeck/coherence/builtin.rs | 42 ++--- .../coherence/inherent_impls.rs | 1 + .../coherence/inherent_impls_overlap.rs | 2 +- src/librustc_typeck/coherence/mod.rs | 1 + src/librustc_typeck/coherence/orphan.rs | 1 + src/librustc_typeck/coherence/unsafety.rs | 17 +- src/librustc_typeck/collect.rs | 47 +++-- src/librustc_typeck/impl_wf_check.rs | 1 + src/librustc_typeck/lib.rs | 3 +- src/librustc_typeck/outlives/test.rs | 6 +- src/librustc_typeck/structured_errors.rs | 6 +- src/librustc_typeck/variance/test.rs | 3 +- src/libsyntax/attr/builtin.rs | 73 +++++--- src/libsyntax/diagnostics/macros.rs | 169 ------------------ src/libsyntax/feature_gate/check.rs | 28 ++- src/libsyntax/lib.rs | 6 - src/test/ui/conflicting-repr-hints.stderr | 2 + .../feature-gate-repr-simd.stderr | 2 + src/test/ui/issues/issue-14221.stderr | 2 + src/test/ui/issues/issue-19100.stderr | 2 + src/test/ui/issues/issue-30302.stderr | 2 + src/test/ui/issues/issue-39720.stderr | 2 + src/test/ui/issues/issue-47094.stderr | 2 + .../ui/lint/lint-uppercase-variables.stderr | 2 + 103 files changed, 562 insertions(+), 573 deletions(-) delete mode 100644 src/libsyntax/diagnostics/macros.rs diff --git a/Cargo.lock b/Cargo.lock index ba0f55ab5af6f..9f5ce7dd195e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3774,6 +3774,7 @@ version = "0.0.0" dependencies = [ "rustc", "rustc_error_codes", + "rustc_errors", "rustc_metadata", "rustc_span", "syntax", @@ -3787,6 +3788,7 @@ dependencies = [ "rustc", "rustc_data_structures", "rustc_error_codes", + "rustc_errors", "rustc_span", "rustc_typeck", "syntax", diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 2b201cfe0a962..b212b4880d3c7 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -8,11 +8,13 @@ use crate::hir::def_id::DefId; use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; use crate::hir::DUMMY_HIR_ID; use crate::hir::{self, Attribute, HirId, Item, ItemKind, TraitItem, TraitItemKind}; -use crate::lint::builtin::UNUSED_ATTRIBUTES; +use crate::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES}; use crate::ty::query::Providers; use crate::ty::TyCtxt; +use errors::{error_code, struct_span_err}; use rustc_span::Span; + use std::fmt::{self, Display}; use syntax::{attr, symbol::sym}; @@ -192,7 +194,7 @@ impl CheckAttrVisitor<'tcx> { self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id)); } - self.check_repr(attrs, span, target, item); + self.check_repr(attrs, span, target, item, hir_id); self.check_used(attrs, target); } @@ -353,6 +355,7 @@ impl CheckAttrVisitor<'tcx> { span: &Span, target: Target, item: Option<&Item<'_>>, + hir_id: HirId, ) { // Extract the names of all repr hints, e.g., [foo, bar, align] for: // ``` @@ -428,21 +431,29 @@ impl CheckAttrVisitor<'tcx> { // Error on repr(transparent, ). if is_transparent && hints.len() > 1 { let hint_spans: Vec<_> = hint_spans.clone().collect(); - span_err!( + struct_span_err!( self.tcx.sess, hint_spans, E0692, "transparent {} cannot have other repr hints", target - ); + ) + .emit(); } // Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8) if (int_reprs > 1) || (is_simd && is_c) || (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item))) { - let hint_spans: Vec<_> = hint_spans.collect(); - span_warn!(self.tcx.sess, hint_spans, E0566, "conflicting representation hints"); + self.tcx + .struct_span_lint_hir( + CONFLICTING_REPR_HINTS, + hir_id, + hint_spans.collect::>(), + "conflicting representation hints", + ) + .code(error_code!(E0566)) + .emit(); } } diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index e2b70abe6f0f5..56473b43cdca6 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -65,7 +65,7 @@ use crate::ty::{ Region, Ty, TyCtxt, TypeFoldable, }; -use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder, DiagnosticStyledString}; use rustc_error_codes::*; use rustc_span::{Pos, Span}; use rustc_target::spec::abi; diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index a94595b227b2e..07afa4869f253 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -5,7 +5,7 @@ use crate::infer::type_variable::TypeVariableOriginKind; use crate::infer::InferCtxt; use crate::ty::print::Print; use crate::ty::{self, DefIdTree, Infer, Ty, TyVar}; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_span::Span; use std::borrow::Cow; use syntax::source_map::DesugaringKind; @@ -153,14 +153,11 @@ pub enum TypeAnnotationNeeded { impl Into for TypeAnnotationNeeded { fn into(self) -> errors::DiagnosticId { - syntax::diagnostic_used!(E0282); - syntax::diagnostic_used!(E0283); - syntax::diagnostic_used!(E0284); - errors::DiagnosticId::Error(match self { - Self::E0282 => "E0282".to_string(), - Self::E0283 => "E0283".to_string(), - Self::E0284 => "E0284".to_string(), - }) + match self { + Self::E0282 => errors::error_code!(E0282), + Self::E0283 => errors::error_code!(E0283), + Self::E0284 => errors::error_code!(E0284), + } } } diff --git a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs index cfb6d5bd244b9..b73fb40f637ed 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -5,6 +5,7 @@ use crate::infer::error_reporting::nice_region_error::util::AnonymousParamInfo; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::util::common::ErrorReported; +use errors::struct_span_err; use rustc_error_codes::*; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { diff --git a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 94b8d16668a3f..f92ad5ce30ce7 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -3,7 +3,7 @@ use crate::hir::{FunctionRetTy, TyKind}; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::ty; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_error_codes::*; diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index 979bcca619c2f..cb927cb6a2cda 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -2,7 +2,7 @@ use crate::infer::{self, InferCtxt, SubregionOrigin}; use crate::middle::region; use crate::ty::error::TypeError; use crate::ty::{self, Region}; -use errors::DiagnosticBuilder; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc_error_codes::*; diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 8399737b3e610..4efa3cbab0f48 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -9,7 +9,7 @@ use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor}; use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef}; use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt}; use crate::util::nodemap::DefIdMap; -use errors::DiagnosticBuilder; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc::session::config::nightly_options; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; @@ -523,11 +523,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { err.span_label(span, label); if nightly_options::is_nightly_build() { - help!( - err, - "add #![feature(member_constraints)] to the crate attributes \ - to enable" - ); + err.help("add #![feature(member_constraints)] to the crate attributes to enable"); } err.emit(); diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index fa6e93d867b4e..16fc142eb7a6e 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -95,6 +95,18 @@ declare_lint! { "detects overlapping patterns" } +declare_lint! { + pub BINDING_VARIANT_NAME, + Warn, + "detects pattern bindings with the same name as one of the matched variants" +} + +declare_lint! { + pub CONFLICTING_REPR_HINTS, + Warn, + "detects when more than one `#[repr(..)]` attribute, with different meaning, is applied" +} + declare_lint! { pub UNUSED_MACROS, Warn, @@ -459,6 +471,7 @@ declare_lint_pass! { UNREACHABLE_CODE, UNREACHABLE_PATTERNS, OVERLAPPING_PATTERNS, + BINDING_VARIANT_NAME, UNUSED_MACROS, WARNINGS, UNUSED_FEATURES, diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 6e0bb3a2a2b38..ba4ee8c1aefad 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -32,9 +32,9 @@ use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt}; use crate::util::common::time; use crate::util::nodemap::FxHashMap; -use errors::DiagnosticBuilder; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc_data_structures::sync::{self, join, par_iter, ParallelIterator}; -use rustc_span::{symbol::Symbol, MultiSpan, Span}; +use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP}; use std::slice; use syntax::ast; use syntax::util::lev_distance::find_best_match_for_name; @@ -295,7 +295,8 @@ impl LintStore { CheckLintNameResult::Ok(_) => None, CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)), CheckLintNameResult::NoLint(suggestion) => { - let mut err = struct_err!(sess, E0602, "unknown lint: `{}`", lint_name); + let mut err = + struct_span_err!(sess, DUMMY_SP, E0602, "unknown lint: `{}`", lint_name); if let Some(suggestion) = suggestion { err.help(&format!("did you mean: `{}`", suggestion)); diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index edf7df16c87fa..aba0c789c241a 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -7,7 +7,7 @@ use crate::lint::context::{CheckLintNameResult, LintStore}; use crate::lint::{self, Level, Lint, LintId, LintSource}; use crate::session::Session; use crate::util::nodemap::FxHashMap; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use syntax::ast; use syntax::attr; @@ -274,13 +274,14 @@ impl<'a> LintLevelsBuilder<'a> { let tool_name = if meta_item.path.segments.len() > 1 { let tool_ident = meta_item.path.segments[0].ident; if !attr::is_known_lint_tool(tool_ident) { - span_err!( + struct_span_err!( sess, tool_ident.span, E0710, "an unknown tool name found in scoped lint: `{}`", pprust::path_to_string(&meta_item.path), - ); + ) + .emit(); continue; } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index c07b65acff218..2807f3a7e9169 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -18,6 +18,7 @@ use crate::util::nodemap::FxHashMap; use crate::hir; use crate::hir::itemlikevisit::ItemLikeVisitor; +use errors::struct_span_err; use rustc_macros::HashStable; use rustc_span::Span; use syntax::ast; @@ -184,7 +185,8 @@ impl LanguageItemCollector<'tcx> { span, E0152, "duplicate lang item found: `{}`.", - name), + name + ), None => { match self.tcx.extern_crate(item_def_id) { Some(ExternCrate {dependency_of, ..}) => { @@ -204,7 +206,7 @@ impl LanguageItemCollector<'tcx> { }, }; if let Some(span) = self.tcx.hir().span_if_local(original_def_id) { - span_note!(&mut err, span, "first defined here."); + err.span_note(span, "first defined here."); } else { match self.tcx.extern_crate(original_def_id) { Some(ExternCrate {dependency_of, ..}) => { diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs index 011c9fc27e05e..1e365d944b6cb 100644 --- a/src/librustc/middle/weak_lang_items.rs +++ b/src/librustc/middle/weak_lang_items.rs @@ -8,6 +8,7 @@ use crate::hir::def_id::DefId; use crate::hir::intravisit; use crate::hir::intravisit::{NestedVisitorMap, Visitor}; use crate::ty::TyCtxt; +use errors::struct_span_err; use rustc_data_structures::fx::FxHashSet; use rustc_span::Span; use rustc_target::spec::PanicStrategy; @@ -124,9 +125,12 @@ impl<'a, 'tcx> Context<'a, 'tcx> { self.items.missing.push(lang_items::$item); } } else)* { - span_err!(self.tcx.sess, span, E0264, - "unknown external lang item: `{}`", - name); + struct_span_err!( + self.tcx.sess, span, E0264, + "unknown external lang item: `{}`", + name + ) + .emit(); } } } diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 2308da5d610e8..7daf58b705734 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -8,7 +8,7 @@ use crate::ty::query::TyCtxtAt; use crate::ty::{self, layout, Ty}; use backtrace::Backtrace; -use errors::DiagnosticBuilder; +use errors::{struct_span_err, DiagnosticBuilder}; use hir::GeneratorKind; use rustc_macros::HashStable; use rustc_span::{Pos, Span}; diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 8a5a92fcfa6d9..e7e8328707798 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -23,7 +23,7 @@ use crate::ty::TypeckTables; use crate::ty::{self, AdtKind, DefIdTree, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable}; use crate::util::nodemap::{FxHashMap, FxHashSet}; -use errors::{pluralize, Applicability, DiagnosticBuilder, Style}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style}; use rustc::hir::def_id::LOCAL_CRATE; use rustc_span::source_map::SourceMap; use rustc_span::{ExpnKind, MultiSpan, Span, DUMMY_SP}; diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs index 5d90018e80a38..4225c3fbc3a1e 100644 --- a/src/librustc/traits/on_unimplemented.rs +++ b/src/librustc/traits/on_unimplemented.rs @@ -5,6 +5,7 @@ use crate::ty::{self, GenericParamDefKind, TyCtxt}; use crate::util::common::ErrorReported; use crate::util::nodemap::FxHashMap; +use errors::struct_span_err; use rustc_span::Span; use syntax::ast::{MetaItem, NestedMetaItem}; use syntax::attr; @@ -293,26 +294,28 @@ impl<'tcx> OnUnimplementedFormatString { match generics.params.iter().find(|param| param.name == s) { Some(_) => (), None => { - span_err!( + struct_span_err!( tcx.sess, span, E0230, "there is no parameter `{}` on trait `{}`", s, name - ); + ) + .emit(); result = Err(ErrorReported); } } } // `{:1}` and `{}` are not to be used Position::ArgumentIs(_) | Position::ArgumentImplicitlyIs(_) => { - span_err!( + struct_span_err!( tcx.sess, span, E0231, "only named substitution parameters are allowed" - ); + ) + .emit(); result = Err(ErrorReported); } }, diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs index 80a82021c9a34..9f84b5e9fd4f7 100644 --- a/src/librustc/traits/query/dropck_outlives.rs +++ b/src/librustc/traits/query/dropck_outlives.rs @@ -76,15 +76,15 @@ pub struct DropckOutlivesResult<'tcx> { impl<'tcx> DropckOutlivesResult<'tcx> { pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) { if let Some(overflow_ty) = self.overflows.iter().next() { - let mut err = struct_span_err!( + errors::struct_span_err!( tcx.sess, span, E0320, "overflow while adding drop-check rules for {}", ty, - ); - err.note(&format!("overflowed on {}", overflow_ty)); - err.emit(); + ) + .note(&format!("overflowed on {}", overflow_ty)) + .emit(); } } diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 9d3e9e309c697..8193236b37390 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -18,6 +18,7 @@ use crate::traits::select::IntercrateAmbiguityCause; use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine}; use crate::ty::subst::{InternalSubsts, Subst, SubstsRef}; use crate::ty::{self, TyCtxt, TypeFoldable}; +use errors::struct_span_err; use rustc_data_structures::fx::FxHashSet; use rustc_span::DUMMY_SP; diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 0642de8c744c2..6ab41854bd30b 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -9,11 +9,7 @@ use crate::ty::query::Query; use crate::ty::tls; use crate::ty::{self, TyCtxt}; -use errors::Diagnostic; -use errors::DiagnosticBuilder; -use errors::FatalError; -use errors::Handler; -use errors::Level; +use errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level}; #[cfg(not(parallel_compiler))] use rustc_data_structures::cold_path; use rustc_data_structures::fx::{FxHashMap, FxHasher}; diff --git a/src/librustc_ast_lowering/expr.rs b/src/librustc_ast_lowering/expr.rs index a3e2bc04bd5fb..b299601fd480e 100644 --- a/src/librustc_ast_lowering/expr.rs +++ b/src/librustc_ast_lowering/expr.rs @@ -5,12 +5,12 @@ use rustc::hir; use rustc::hir::def::Res; use rustc_data_structures::thin_vec::ThinVec; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned}; use rustc_span::symbol::{sym, Symbol}; use syntax::ast::*; use syntax::attr; use syntax::ptr::P as AstP; -use syntax::{span_err, struct_span_err}; impl<'hir> LoweringContext<'_, 'hir> { fn lower_exprs(&mut self, exprs: &[AstP]) -> &'hir [hir::Expr<'hir>] { @@ -701,12 +701,13 @@ impl<'hir> LoweringContext<'_, 'hir> { match generator_kind { Some(hir::GeneratorKind::Gen) => { if !decl.inputs.is_empty() { - span_err!( + struct_span_err!( self.sess, fn_decl_span, E0628, "generators cannot have explicit parameters" - ); + ) + .emit(); } Some(movability) } @@ -715,7 +716,8 @@ impl<'hir> LoweringContext<'_, 'hir> { } None => { if movability == Movability::Static { - span_err!(self.sess, fn_decl_span, E0697, "closures cannot be static"); + struct_span_err!(self.sess, fn_decl_span, E0697, "closures cannot be static") + .emit(); } None } @@ -962,7 +964,13 @@ impl<'hir> LoweringContext<'_, 'hir> { match self.generator_kind { Some(hir::GeneratorKind::Gen) => {} Some(hir::GeneratorKind::Async(_)) => { - span_err!(self.sess, span, E0727, "`async` generators are not yet supported",); + struct_span_err!( + self.sess, + span, + E0727, + "`async` generators are not yet supported" + ) + .emit(); return hir::ExprKind::Err; } None => self.generator_kind = Some(hir::GeneratorKind::Gen), diff --git a/src/librustc_ast_lowering/item.rs b/src/librustc_ast_lowering/item.rs index c1eb8be0f8aad..08464180cf122 100644 --- a/src/librustc_ast_lowering/item.rs +++ b/src/librustc_ast_lowering/item.rs @@ -8,13 +8,13 @@ use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::DefId; use rustc::util::nodemap::NodeMap; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_span::source_map::{respan, DesugaringKind}; use rustc_span::symbol::{kw, sym}; use rustc_span::Span; use rustc_target::spec::abi; use syntax::ast::*; use syntax::attr; -use syntax::struct_span_err; use syntax::visit::{self, Visitor}; use log::debug; diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index a9214f31e7d2e..460f79d29b817 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -52,7 +52,7 @@ use rustc::{bug, span_bug}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_error_codes::*; -use rustc_errors::Applicability; +use rustc_errors::{struct_span_err, Applicability}; use rustc_index::vec::IndexVec; use rustc_span::hygiene::ExpnId; use rustc_span::source_map::{respan, DesugaringKind, ExpnData, ExpnKind, Spanned}; @@ -67,7 +67,7 @@ use syntax::sess::ParseSess; use syntax::token::{self, Nonterminal, Token}; use syntax::tokenstream::{TokenStream, TokenTree}; use syntax::visit::{self, Visitor}; -use syntax::{help, struct_span_err, walk_list}; +use syntax::walk_list; use log::{debug, trace}; use smallvec::{smallvec, SmallVec}; @@ -1347,10 +1347,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ); if pos == ImplTraitPosition::Binding && nightly_options::is_nightly_build() { - help!( - err, + err.help( "add `#![feature(impl_trait_in_bindings)]` to the crate \ - attributes to enable" + attributes to enable", ); } err.emit(); diff --git a/src/librustc_builtin_macros/asm.rs b/src/librustc_builtin_macros/asm.rs index 71d6d058d90be..bdae48b65a622 100644 --- a/src/librustc_builtin_macros/asm.rs +++ b/src/librustc_builtin_macros/asm.rs @@ -2,7 +2,7 @@ // use State::*; -use errors::{DiagnosticBuilder, PResult}; +use errors::{struct_span_err, DiagnosticBuilder, PResult}; use rustc_expand::base::*; use rustc_parse::parser::Parser; use rustc_span::Span; @@ -11,7 +11,6 @@ use syntax::ptr::P; use syntax::symbol::{kw, sym, Symbol}; use syntax::token::{self, Token}; use syntax::tokenstream::{self, TokenStream}; -use syntax::{span_err, struct_span_err}; use rustc_error_codes::*; @@ -173,12 +172,13 @@ fn parse_inline_asm<'a>( Some('=') => None, Some('+') => Some(Symbol::intern(&format!("={}", ch.as_str()))), _ => { - span_err!( - cx, + struct_span_err!( + cx.parse_sess.span_diagnostic, span, E0661, "output operand constraint lacks '=' or '+'" - ); + ) + .emit(); None } }; @@ -202,9 +202,21 @@ fn parse_inline_asm<'a>( let constraint = parse_asm_str(&mut p)?; if constraint.as_str().starts_with("=") { - span_err!(cx, p.prev_span, E0662, "input operand constraint contains '='"); + struct_span_err!( + cx.parse_sess.span_diagnostic, + p.prev_span, + E0662, + "input operand constraint contains '='" + ) + .emit(); } else if constraint.as_str().starts_with("+") { - span_err!(cx, p.prev_span, E0663, "input operand constraint contains '+'"); + struct_span_err!( + cx.parse_sess.span_diagnostic, + p.prev_span, + E0663, + "input operand constraint contains '+'" + ) + .emit(); } p.expect(&token::OpenDelim(token::Paren))?; @@ -225,12 +237,13 @@ fn parse_inline_asm<'a>( if OPTIONS.iter().any(|&opt| s == opt) { cx.span_warn(p.prev_span, "expected a clobber, found an option"); } else if s.as_str().starts_with("{") || s.as_str().ends_with("}") { - span_err!( - cx, + struct_span_err!( + cx.parse_sess.span_diagnostic, p.prev_span, E0664, "clobber should not be surrounded by braces" - ); + ) + .emit(); } clobs.push(s); diff --git a/src/librustc_builtin_macros/deriving/default.rs b/src/librustc_builtin_macros/deriving/default.rs index 43185f924e79c..235567e0004af 100644 --- a/src/librustc_builtin_macros/deriving/default.rs +++ b/src/librustc_builtin_macros/deriving/default.rs @@ -2,11 +2,11 @@ use crate::deriving::generic::ty::*; use crate::deriving::generic::*; use crate::deriving::path_std; +use errors::struct_span_err; use rustc_expand::base::{Annotatable, DummyResult, ExtCtxt}; use rustc_span::Span; use syntax::ast::{Expr, MetaItem}; use syntax::ptr::P; -use syntax::span_err; use syntax::symbol::{kw, sym}; use rustc_error_codes::*; @@ -74,7 +74,13 @@ fn default_substructure( } }, StaticEnum(..) => { - span_err!(cx, trait_span, E0665, "`Default` cannot be derived for enums, only structs"); + struct_span_err!( + cx.parse_sess.span_diagnostic, + trait_span, + E0665, + "`Default` cannot be derived for enums, only structs" + ) + .emit(); // let compilation continue DummyResult::raw_expr(trait_span, true) } diff --git a/src/librustc_codegen_ssa/common.rs b/src/librustc_codegen_ssa/common.rs index e0505daed8a62..d14aad10e96f0 100644 --- a/src/librustc_codegen_ssa/common.rs +++ b/src/librustc_codegen_ssa/common.rs @@ -2,6 +2,7 @@ use rustc::session::Session; use rustc::ty::{Ty, TyCtxt}; +use rustc_errors::struct_span_err; use rustc_span::Span; use crate::base; @@ -196,5 +197,5 @@ pub fn shift_mask_val<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( } pub fn span_invalid_monomorphization_error(a: &Session, b: Span, c: &str) { - span_err!(a, b, E0511, "{}", c); + struct_span_err!(a, b, E0511, "{}", c).emit(); } diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index fd31361d67950..1dffb77a833eb 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -21,8 +21,6 @@ extern crate log; #[macro_use] extern crate rustc; -#[macro_use] -extern crate syntax; use rustc::dep_graph::WorkProduct; use rustc::hir::def_id::CrateNum; diff --git a/src/librustc_codegen_ssa/mir/statement.rs b/src/librustc_codegen_ssa/mir/statement.rs index 48ba64143a708..574c06d9ceb41 100644 --- a/src/librustc_codegen_ssa/mir/statement.rs +++ b/src/librustc_codegen_ssa/mir/statement.rs @@ -1,4 +1,5 @@ use rustc::mir; +use rustc_errors::struct_span_err; use super::FunctionCx; use super::LocalRef; @@ -81,12 +82,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { if let OperandValue::Immediate(_) = op.val { acc.push(op.immediate()); } else { - span_err!( + struct_span_err!( bx.sess(), span.to_owned(), E0669, "invalid value for constraint in inline assembly" - ); + ) + .emit(); } acc }, @@ -100,12 +102,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { statement.source_info.span, ); if !res { - span_err!( + struct_span_err!( bx.sess(), statement.source_info.span, E0668, "malformed inline assembly" - ); + ) + .emit(); } } bx diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 79ec9ad7b0329..73f66d5503740 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -385,3 +385,22 @@ impl<'a> Drop for DiagnosticBuilder<'a> { } } } + +#[macro_export] +macro_rules! struct_span_err { + ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ + $session.struct_span_err_with_code( + $span, + &format!($($message)*), + $crate::error_code!($code), + ) + }) +} + +#[macro_export] +macro_rules! error_code { + ($code:ident) => {{ + let _ = $code; + $crate::DiagnosticId::Error(stringify!($code).to_owned()) + }}; +} diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index adb73d1c5fcc3..c0418b64bab25 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -20,6 +20,7 @@ use rustc_target::spec::{PanicStrategy, TargetTriple}; use std::path::Path; use std::{cmp, fs}; +use errors::struct_span_err; use log::{debug, info, log_enabled}; use proc_macro::bridge::client::ProcMacro; use rustc_expand::base::SyntaxExtension; @@ -28,7 +29,6 @@ use syntax::ast; use syntax::attr; use syntax::edition::Edition; use syntax::expand::allocator::{global_allocator_spans, AllocatorKind}; -use syntax::span_fatal; use syntax::symbol::{sym, Symbol}; use rustc_error_codes::*; @@ -261,7 +261,7 @@ impl<'a> CrateLoader<'a> { if self.local_crate_name == root.name() && self.sess.local_crate_disambiguator() == root.disambiguator() { - span_fatal!( + struct_span_err!( self.sess, span, E0519, @@ -271,6 +271,7 @@ impl<'a> CrateLoader<'a> { will result in symbol conflicts between the two.", root.name() ) + .emit() } // Check for conflicts with any crate loaded so far @@ -280,7 +281,7 @@ impl<'a> CrateLoader<'a> { other.hash() != root.hash() { // but different SVH - span_fatal!( + struct_span_err!( self.sess, span, E0523, @@ -289,6 +290,7 @@ impl<'a> CrateLoader<'a> { will result in symbol conflicts between the two.", root.name() ) + .emit(); } }); } diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index 93b29cf81d752..86e51eb5632fe 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -215,6 +215,7 @@ use crate::creader::Library; use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER}; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc::middle::cstore::{CrateSource, MetadataLoader}; use rustc::session::filesearch::{FileDoesntMatch, FileMatches, FileSearch}; use rustc::session::search_paths::PathKind; @@ -223,13 +224,9 @@ use rustc::util::nodemap::FxHashMap; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::MetadataRef; - -use errors::DiagnosticBuilder; use rustc_span::Span; use rustc_target::spec::{Target, TargetTriple}; -use syntax::struct_span_err; use syntax::symbol::{sym, Symbol}; -use syntax::{span_err, span_fatal}; use std::cmp; use std::fmt; @@ -1039,28 +1036,28 @@ pub fn find_plugin_registrar( }; if target_only { - // Need to abort before syntax expansion. let message = format!( - "plugin `{}` is not available for triple `{}` \ - (only found {})", + "plugin `{}` is not available for triple `{}` (only found {})", name, config::host_triple(), sess.opts.target_triple ); - span_fatal!(sess, span, E0456, "{}", &message); + struct_span_err!(sess, span, E0456, "{}", &message).emit(); + return None; } match library.source.dylib { Some(dylib) => Some((dylib.0, library.metadata.get_root().disambiguator())), None => { - span_err!( + struct_span_err!( sess, span, E0457, "plugin `{}` only found in rlib format, but must be available \ in dylib format", name - ); + ) + .emit(); // No need to abort because the loading code will just ignore this // empty dylib. None diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index 06240994da3a8..00eb44e511a35 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -1,3 +1,4 @@ +use errors::struct_span_err; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::middle::cstore::{self, NativeLibrary}; @@ -9,7 +10,6 @@ use syntax::attr; use syntax::feature_gate::feature_err; use syntax::source_map::Span; use syntax::symbol::{kw, sym, Symbol}; -use syntax::{span_err, struct_span_err}; use rustc_error_codes::*; @@ -159,7 +159,7 @@ impl Collector<'tcx> { if lib.kind == cstore::NativeFramework && !is_osx { let msg = "native frameworks are only available on macOS targets"; match span { - Some(span) => span_err!(self.tcx.sess, span, E0455, "{}", msg), + Some(span) => struct_span_err!(self.tcx.sess, span, E0455, "{}", msg).emit(), None => self.tcx.sess.err(msg), } } diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 369bce64724ab..d2b063099db31 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -30,6 +30,7 @@ use rustc::ty::{ }; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_index::vec::{Idx, IndexVec}; use rustc_span::{Span, DUMMY_SP}; diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 12d75033da2cf..73bcf296062b4 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -14,7 +14,7 @@ use rustc::session::Session; use rustc::ty::subst::{InternalSubsts, SubstsRef}; use rustc::ty::{self, Ty, TyCtxt}; use rustc_error_codes::*; -use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder}; use rustc_span::symbol::sym; use rustc_span::{MultiSpan, Span}; use syntax::ast::Mutability; @@ -116,7 +116,7 @@ impl PatCtxt<'_, '_> { } fn span_e0158(&self, span: Span, text: &str) { - span_err!(self.tcx.sess, span, E0158, "{}", text) + struct_span_err!(self.tcx.sess, span, E0158, "{}", text).emit(); } } @@ -291,24 +291,26 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa variant.ident == ident && variant.ctor_kind == CtorKind::Const }) { - // FIXME(Centril): Should be a lint? let ty_path = cx.tcx.def_path_str(edef.did); - let mut err = struct_span_warn!( - cx.tcx.sess, - p.span, - E0170, - "pattern binding `{}` is named the same as one \ - of the variants of the type `{}`", - ident, - ty_path - ); - err.span_suggestion( - p.span, - "to match on the variant, qualify the path", - format!("{}::{}", ty_path, ident), - Applicability::MachineApplicable, - ); - err.emit(); + cx.tcx + .struct_span_lint_hir( + lint::builtin::BINDING_VARIANT_NAME, + p.hir_id, + p.span, + &format!( + "pattern binding `{}` is named the same as one \ + of the variants of the type `{}`", + ident, ty_path + ), + ) + .code(error_code!(E0170)) + .span_suggestion( + p.span, + "to match on the variant, qualify the path", + format!("{}::{}", ty_path, ident), + Applicability::MachineApplicable, + ) + .emit(); } } } diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index f5d8ed877ec5c..c87bc35a0b452 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -19,7 +19,7 @@ use rustc::ty::layout::VariantIdx; use rustc::ty::subst::{GenericArg, SubstsRef}; use rustc::ty::{self, AdtDef, DefIdTree, Region, Ty, TyCtxt, UserType}; use rustc::ty::{CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations}; - +use rustc_errors::struct_span_err; use rustc_index::vec::Idx; use rustc_span::{Span, DUMMY_SP}; @@ -463,12 +463,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { PatKind::Range(PatRange { lo, hi, end }) } (RangeEnd::Excluded, _) => { - span_err!( + struct_span_err!( self.tcx.sess, lo_expr.span, E0579, "lower range bound must be less than upper", - ); + ) + .emit(); PatKind::Wild } (RangeEnd::Included, Some(Ordering::Equal)) => { diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 32b35c4139dad..9f70f1dd57688 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -35,8 +35,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! extern crate log; #[macro_use] extern crate rustc; -#[macro_use] -extern crate syntax; mod borrow_check; mod build; diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index 37435fbf4d16f..402bf20626fb8 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -3,6 +3,7 @@ use rustc::hir::def_id::DefId; use rustc::session::config::nightly_options; use rustc::ty::TyCtxt; +use rustc_errors::struct_span_err; use rustc_span::{Span, Symbol}; use syntax::feature_gate::feature_err; use syntax::symbol::sym; @@ -115,12 +116,7 @@ impl NonConstOp for FnCallUnstable { &format!("`{}` is not yet stable as a const fn", item.tcx.def_path_str(def_id)), ); if nightly_options::is_nightly_build() { - help!( - &mut err, - "add `#![feature({})]` to the \ - crate attributes to enable", - feature - ); + err.help(&format!("add `#![feature({})]` to the crate attributes to enable", feature)); } err.emit(); } @@ -197,13 +193,14 @@ impl NonConstOp for Loop { pub struct CellBorrow; impl NonConstOp for CellBorrow { fn emit_error(&self, item: &Item<'_, '_>, span: Span) { - span_err!( + struct_span_err!( item.tcx.sess, span, E0492, "cannot borrow a constant which may contain \ interior mutability, create a static instead" - ); + ) + .emit(); } } @@ -375,13 +372,14 @@ impl NonConstOp for ThreadLocalAccess { const IS_SUPPORTED_IN_MIRI: bool = false; fn emit_error(&self, item: &Item<'_, '_>, span: Span) { - span_err!( + struct_span_err!( item.tcx.sess, span, E0625, "thread-local statics cannot be \ accessed at compile-time" - ); + ) + .emit(); } } diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index 19cad453e25e6..54282a845527b 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -8,6 +8,7 @@ use rustc::traits::{self, TraitEngine}; use rustc::ty::cast::CastTy; use rustc::ty::{self, TyCtxt}; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_index::bit_set::BitSet; use rustc_span::Span; use syntax::symbol::sym; diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 8b8f1b6f670ef..7dfa1b5eb5f4d 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -1,5 +1,3 @@ -use rustc_data_structures::fx::FxHashSet; - use rustc::hir; use rustc::hir::def_id::DefId; use rustc::hir::Node; @@ -9,7 +7,8 @@ use rustc::mir::*; use rustc::ty::cast::CastTy; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt}; - +use rustc_data_structures::fx::FxHashSet; +use rustc_errors::struct_span_err; use syntax::symbol::{sym, Symbol}; use std::ops::Bound; diff --git a/src/librustc_mir/util/borrowck_errors.rs b/src/librustc_mir/util/borrowck_errors.rs index 9f67109b34a1b..c275eecfb33b6 100644 --- a/src/librustc_mir/util/borrowck_errors.rs +++ b/src/librustc_mir/util/borrowck_errors.rs @@ -1,8 +1,7 @@ use rustc::ty::{self, Ty, TyCtxt}; -use rustc_errors::{DiagnosticBuilder, DiagnosticId}; -use rustc_span::{MultiSpan, Span}; - use rustc_error_codes::*; +use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId}; +use rustc_span::{MultiSpan, Span}; impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> { crate fn cannot_move_when_borrowed(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> { diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index bf03f731c9f90..359386f4643d6 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -2,7 +2,8 @@ use super::{BlockMode, Parser, PathStyle, SemiColonMode, SeqSep, TokenExpectType use rustc_data_structures::fx::FxHashSet; use rustc_error_codes::*; -use rustc_errors::{self, pluralize, Applicability, DiagnosticBuilder, Handler, PResult}; +use rustc_errors::{pluralize, struct_span_err}; +use rustc_errors::{Applicability, DiagnosticBuilder, Handler, PResult}; use rustc_span::symbol::kw; use rustc_span::{MultiSpan, Span, SpanSnippetError, DUMMY_SP}; use syntax::ast::{ @@ -11,7 +12,6 @@ use syntax::ast::{ use syntax::ast::{AttrVec, ItemKind, Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind}; use syntax::print::pprust; use syntax::ptr::P; -use syntax::struct_span_err; use syntax::token::{self, token_can_begin_expr, TokenKind}; use syntax::util::parser::AssocOp; diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index a05bc48981efe..918e826fc26bf 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -4,7 +4,7 @@ use super::{FollowedByType, Parser, PathStyle}; use crate::maybe_whole; use rustc_error_codes::*; -use rustc_errors::{Applicability, DiagnosticBuilder, PResult, StashKey}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, PResult, StashKey}; use rustc_span::source_map::{self, respan, Span}; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::BytePos; @@ -16,7 +16,6 @@ use syntax::ast::{EnumDef, Generics, StructField, TraitRef, Ty, TyKind, Variant, use syntax::ast::{FnHeader, ForeignItem, ForeignItemKind, Mutability, Visibility, VisibilityKind}; use syntax::print::pprust; use syntax::ptr::P; -use syntax::struct_span_err; use syntax::token; use syntax::tokenstream::{DelimSpan, TokenStream, TokenTree}; diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index 6dcffcf0bd7b8..411397f63f5ea 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -15,7 +15,7 @@ use crate::lexer::UnmatchedBrace; use crate::{Directory, DirectoryOwnership}; use log::debug; -use rustc_errors::{Applicability, DiagnosticBuilder, FatalError, PResult}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, FatalError, PResult}; use rustc_span::source_map::respan; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::{BytePos, FileName, Span, DUMMY_SP}; @@ -24,7 +24,6 @@ use syntax::ast::{IsAsync, MacArgs, MacDelimiter, Mutability, StrLit, Visibility use syntax::print::pprust; use syntax::ptr::P; use syntax::sess::ParseSess; -use syntax::struct_span_err; use syntax::token::{self, DelimToken, Token, TokenKind}; use syntax::tokenstream::{self, DelimSpan, TokenStream, TokenTree, TreeAndJoint}; use syntax::util::comments::{doc_comment_style, strip_doc_comment_decoration}; diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs index 4122aa17f83d3..f96c82a1ab37d 100644 --- a/src/librustc_parse/parser/ty.rs +++ b/src/librustc_parse/parser/ty.rs @@ -4,7 +4,7 @@ use super::{Parser, PathStyle, PrevTokenKind, TokenType}; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; use rustc_error_codes::*; -use rustc_errors::{pluralize, Applicability, PResult}; +use rustc_errors::{pluralize, struct_span_err, Applicability, PResult}; use rustc_span::source_map::Span; use rustc_span::symbol::kw; use syntax::ast::{ @@ -15,7 +15,6 @@ use syntax::ast::{ }; use syntax::ast::{Mac, Mutability}; use syntax::ptr::P; -use syntax::struct_span_err; use syntax::token::{self, Token}; /// Returns `true` if `IDENT t` can start a type -- `IDENT::a::b`, `IDENT`, diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index a0d5467893de0..b49bec8fcaac6 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -6,7 +6,7 @@ // This pass is supposed to perform only simple checks not requiring name resolution // or type checking or some other kind of complex analysis. -use errors::{Applicability, FatalError}; +use errors::{struct_span_err, Applicability, FatalError}; use rustc::lint; use rustc::session::Session; use rustc_data_structures::fx::FxHashMap; @@ -20,7 +20,7 @@ use syntax::print::pprust; use syntax::source_map::Spanned; use syntax::symbol::{kw, sym}; use syntax::visit::{self, Visitor}; -use syntax::{span_err, struct_span_err, walk_list}; +use syntax::walk_list; use rustc_error_codes::*; @@ -470,7 +470,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { self.check_fn_decl(fn_decl); } ExprKind::InlineAsm(..) if !self.session.target.target.options.allow_asm => { - span_err!(self.session, expr.span, E0472, "asm! is unsupported on this target"); + struct_span_err!( + self.session, + expr.span, + E0472, + "asm! is unsupported on this target" + ) + .emit(); } _ => {} } @@ -498,12 +504,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { for bound in bounds { if let GenericBound::Outlives(ref lifetime) = *bound { if any_lifetime_bounds { - span_err!( + struct_span_err!( self.session, lifetime.ident.span, E0226, "only a single explicit lifetime bound is permitted" - ); + ) + .emit(); break; } any_lifetime_bounds = true; @@ -575,7 +582,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { .emit(); } if unsafety == Unsafety::Unsafe && polarity == ImplPolarity::Negative { - span_err!(self.session, item.span, E0198, "negative impls cannot be unsafe"); + struct_span_err!( + self.session, + item.span, + E0198, + "negative impls cannot be unsafe" + ) + .emit(); } for impl_item in impl_items { self.invalid_visibility(&impl_item.vis, None); @@ -591,7 +604,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { Some("place qualifiers on individual impl items instead"), ); if unsafety == Unsafety::Unsafe { - span_err!(self.session, item.span, E0197, "inherent impls cannot be unsafe"); + struct_span_err!( + self.session, + item.span, + E0197, + "inherent impls cannot be unsafe" + ) + .emit(); } if polarity == ImplPolarity::Negative { self.err_handler().span_err(item.span, "inherent impls cannot be negative"); diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index c08aab2e200fc..d68d207959831 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -7,6 +7,7 @@ //! errors. We still look for those primitives in the MIR const-checker to ensure nothing slips //! through, but errors for structured control flow in a `const` should be emitted here. +use errors::struct_span_err; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; @@ -18,7 +19,6 @@ use rustc_error_codes::*; use rustc_span::{sym, Span, Symbol}; use syntax::ast::Mutability; use syntax::feature_gate::feature_err; -use syntax::span_err; use std::fmt; @@ -154,7 +154,7 @@ impl<'tcx> CheckConstVisitor<'tcx> { required_gates.iter().copied().filter(|&g| !features.enabled(g)).collect(); match missing_gates.as_slice() { - &[] => span_err!(self.tcx.sess, span, E0744, "{}", msg), + &[] => struct_span_err!(self.tcx.sess, span, E0744, "{}", msg).emit(), // If the user enabled `#![feature(const_loop)]` but not `#![feature(const_if_match)]`, // explain why their `while` loop is being rejected. diff --git a/src/librustc_passes/diagnostic_items.rs b/src/librustc_passes/diagnostic_items.rs index 65138fad43bd8..330e7bc8aba99 100644 --- a/src/librustc_passes/diagnostic_items.rs +++ b/src/librustc_passes/diagnostic_items.rs @@ -74,7 +74,7 @@ fn collect_item( )), }; if let Some(span) = tcx.hir().span_if_local(original_def_id) { - span_note!(&mut err, span, "first defined here."); + err.span_note(span, "first defined here."); } else { err.note(&format!( "first defined in crate `{}`.", diff --git a/src/librustc_passes/entry.rs b/src/librustc_passes/entry.rs index 3b7728a18d36d..96849137c4232 100644 --- a/src/librustc_passes/entry.rs +++ b/src/librustc_passes/entry.rs @@ -1,3 +1,4 @@ +use errors::struct_span_err; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::map as hir_map; @@ -6,7 +7,7 @@ use rustc::session::config::EntryFnType; use rustc::session::{config, Session}; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; -use rustc_span::Span; +use rustc_span::{Span, DUMMY_SP}; use syntax::attr; use syntax::entry::EntryPointType; use syntax::symbol::sym; @@ -108,7 +109,8 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) { if ctxt.main_fn.is_none() { ctxt.main_fn = Some((item.hir_id, item.span)); } else { - span_err!(ctxt.session, item.span, E0136, "multiple `main` functions"); + struct_span_err!(ctxt.session, item.span, E0136, "multiple `main` functions") + .emit(); } } EntryPointType::OtherMain => { @@ -166,8 +168,9 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) { } // There is no main function. - let mut err = struct_err!( + let mut err = struct_span_err!( tcx.sess, + DUMMY_SP, E0601, "`main` function not found in crate `{}`", tcx.crate_name(LOCAL_CRATE) diff --git a/src/librustc_passes/intrinsicck.rs b/src/librustc_passes/intrinsicck.rs index 95dc31cc29bf4..4a94057fb71a4 100644 --- a/src/librustc_passes/intrinsicck.rs +++ b/src/librustc_passes/intrinsicck.rs @@ -1,3 +1,4 @@ +use errors::struct_span_err; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::DefId; use rustc::ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx}; diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index a692c45ced40b..f128d3891d7b8 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -14,8 +14,6 @@ extern crate rustc; #[macro_use] extern crate log; -#[macro_use] -extern crate syntax; use rustc::ty::query::Providers; diff --git a/src/librustc_passes/lib_features.rs b/src/librustc_passes/lib_features.rs index 2f486e3038fb8..a776f3e1bd240 100644 --- a/src/librustc_passes/lib_features.rs +++ b/src/librustc_passes/lib_features.rs @@ -4,6 +4,7 @@ // and `#[unstable (..)]`), but are not declared in one single location // (unlike lang features), which means we need to collect them instead. +use errors::struct_span_err; use rustc::hir::def_id::LOCAL_CRATE; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::middle::lib_features::LibFeatures; diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index f5011ceef142e..4d29ba4bd602d 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -2,7 +2,7 @@ use Context::*; use rustc::session::Session; -use errors::Applicability; +use errors::{struct_span_err, Applicability}; use rustc::hir::def_id::DefId; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; @@ -10,7 +10,6 @@ use rustc::hir::{self, Destination, Movability, Node}; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; use rustc_span::Span; -use syntax::struct_span_err; use rustc_error_codes::*; diff --git a/src/librustc_passes/region.rs b/src/librustc_passes/region.rs index 1004e639b6ef7..6d625a7dc2942 100644 --- a/src/librustc_passes/region.rs +++ b/src/librustc_passes/region.rs @@ -15,10 +15,10 @@ use rustc::middle::region::*; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; use rustc::util::nodemap::FxHashSet; - use rustc_index::vec::Idx; +use rustc_span::source_map; use rustc_span::Span; -use syntax::source_map; +use syntax::walk_list; use std::mem; diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index fcbc742b9a00b..0c96b3a4817ee 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -1,6 +1,7 @@ //! A pass that annotates every item and method with its stability level, //! propagating default levels lexically from parent to children ast nodes. +use errors::struct_span_err; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; diff --git a/src/librustc_plugin_impl/Cargo.toml b/src/librustc_plugin_impl/Cargo.toml index a9bbe429c00cc..0e873359e67ea 100644 --- a/src/librustc_plugin_impl/Cargo.toml +++ b/src/librustc_plugin_impl/Cargo.toml @@ -12,6 +12,7 @@ doctest = false [dependencies] rustc = { path = "../librustc" } +rustc_errors = { path = "../librustc_errors" } rustc_metadata = { path = "../librustc_metadata" } syntax = { path = "../libsyntax" } rustc_span = { path = "../librustc_span" } diff --git a/src/librustc_plugin_impl/load.rs b/src/librustc_plugin_impl/load.rs index 3010691dba20d..eff195292be73 100644 --- a/src/librustc_plugin_impl/load.rs +++ b/src/librustc_plugin_impl/load.rs @@ -3,6 +3,7 @@ use crate::Registry; use rustc::middle::cstore::MetadataLoader; use rustc::session::Session; +use rustc_errors::struct_span_err; use rustc_metadata::locator; use rustc_span::Span; @@ -11,7 +12,6 @@ use std::env; use std::mem; use std::path::PathBuf; use syntax::ast::{Crate, Ident}; -use syntax::struct_span_err; use syntax::symbol::sym; use rustc_error_codes::*; diff --git a/src/librustc_privacy/Cargo.toml b/src/librustc_privacy/Cargo.toml index e39c0b427dab1..59513d9ea5c91 100644 --- a/src/librustc_privacy/Cargo.toml +++ b/src/librustc_privacy/Cargo.toml @@ -10,6 +10,7 @@ path = "lib.rs" [dependencies] rustc = { path = "../librustc" } +rustc_errors = { path = "../librustc_errors" } rustc_typeck = { path = "../librustc_typeck" } syntax = { path = "../libsyntax" } rustc_span = { path = "../librustc_span" } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 6c3053f016bf0..3ac62d3b85a68 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -3,9 +3,6 @@ #![feature(nll)] #![recursion_limit = "256"] -#[macro_use] -extern crate syntax; - use rustc::bug; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; @@ -20,6 +17,7 @@ use rustc::ty::subst::InternalSubsts; use rustc::ty::{self, GenericParamDefKind, TraitRef, Ty, TyCtxt, TypeFoldable}; use rustc::util::nodemap::HirIdSet; use rustc_data_structures::fx::FxHashSet; +use rustc_errors::struct_span_err; use rustc_span::hygiene::Transparency; use rustc_span::Span; use syntax::ast::Ident; diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 911de5d2174e6..1690427991081 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -27,7 +27,7 @@ use rustc_data_structures::sync::Lrc; use std::cell::Cell; use std::ptr; -use errors::Applicability; +use errors::{struct_span_err, Applicability}; use rustc_expand::base::SyntaxExtension; use rustc_expand::expand::AstFragment; @@ -38,7 +38,6 @@ use syntax::ast::{AssocItem, AssocItemKind, MetaItemKind, StmtKind}; use syntax::ast::{Ident, Name}; use syntax::attr; use syntax::source_map::{respan, Spanned}; -use syntax::span_err; use syntax::symbol::{kw, sym}; use syntax::token::{self, Token}; use syntax::visit::{self, Visitor}; @@ -957,22 +956,27 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { for attr in &item.attrs { if attr.check_name(sym::macro_use) { if self.parent_scope.module.parent.is_some() { - span_err!( + struct_span_err!( self.r.session, item.span, E0468, "an `extern crate` loading macros must be at the crate root" - ); + ) + .emit(); } if let ItemKind::ExternCrate(Some(orig_name)) = item.kind { if orig_name == kw::SelfLower { - self.r.session.span_err( - attr.span, - "`macro_use` is not supported on `extern crate self`", - ); + self.r + .session + .struct_span_err( + attr.span, + "`macro_use` is not supported on `extern crate self`", + ) + .emit(); } } - let ill_formed = |span| span_err!(self.r.session, span, E0466, "bad macro import"); + let ill_formed = + |span| struct_span_err!(self.r.session, span, E0466, "bad macro import").emit(); match attr.meta() { Some(meta) => match meta.kind { MetaItemKind::Word => { @@ -1045,7 +1049,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { allow_shadowing, ); } else { - span_err!(self.r.session, ident.span, E0469, "imported macro not found"); + struct_span_err!(self.r.session, ident.span, E0469, "imported macro not found") + .emit(); } } } diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 2553ac6208c57..48aef0e352134 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -1,6 +1,6 @@ use std::cmp::Reverse; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use log::debug; use rustc::bug; use rustc::hir::def::Namespace::{self, *}; @@ -15,7 +15,6 @@ use rustc_span::{BytePos, MultiSpan, Span}; use syntax::ast::{self, Ident, Path}; use syntax::print::pprust; use syntax::source_map::SourceMap; -use syntax::struct_span_err; use syntax::symbol::{kw, Symbol}; use syntax::util::lev_distance::find_best_match_for_name; diff --git a/src/librustc_resolve/imports.rs b/src/librustc_resolve/imports.rs index c79a97f93f07f..8d09c1aacc0ca 100644 --- a/src/librustc_resolve/imports.rs +++ b/src/librustc_resolve/imports.rs @@ -11,7 +11,7 @@ use crate::{BindingKey, ModuleKind, ResolutionError, Resolver, Segment}; use crate::{CrateLint, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet, Weak}; use crate::{NameBinding, NameBindingKind, PathResult, PrivacyError, ToNameBinding}; -use errors::{pluralize, Applicability}; +use errors::{pluralize, struct_span_err, Applicability}; use rustc::hir::def::{self, Export, PartialRes}; use rustc::hir::def_id::DefId; @@ -27,8 +27,8 @@ use rustc_span::hygiene::ExpnId; use rustc_span::{MultiSpan, Span}; use syntax::ast::{Ident, Name, NodeId}; use syntax::symbol::kw; +use syntax::unwrap_or; use syntax::util::lev_distance::find_best_match_for_name; -use syntax::{struct_span_err, unwrap_or}; use rustc_error_codes::*; diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index a0d59fa4829e8..5c128b72e3490 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -11,6 +11,7 @@ use crate::{path_names_to_string, BindingError, CrateLint, LexicalScopeBinding}; use crate::{Module, ModuleOrUniformRoot, NameBindingKind, ParentScope, PathResult}; use crate::{ResolutionError, Resolver, Segment, UseError}; +use errors::DiagnosticId; use log::debug; use rustc::hir::def::Namespace::{self, *}; use rustc::hir::def::{self, CtorKind, DefKind, PartialRes, PerNS}; @@ -304,32 +305,21 @@ impl<'a> PathSource<'a> { } } - fn error_code(self, has_unexpected_resolution: bool) -> &'static str { - syntax::diagnostic_used!(E0404); - syntax::diagnostic_used!(E0405); - syntax::diagnostic_used!(E0412); - syntax::diagnostic_used!(E0422); - syntax::diagnostic_used!(E0423); - syntax::diagnostic_used!(E0425); - syntax::diagnostic_used!(E0531); - syntax::diagnostic_used!(E0532); - syntax::diagnostic_used!(E0573); - syntax::diagnostic_used!(E0574); - syntax::diagnostic_used!(E0575); - syntax::diagnostic_used!(E0576); + fn error_code(self, has_unexpected_resolution: bool) -> DiagnosticId { + use errors::error_code; match (self, has_unexpected_resolution) { - (PathSource::Trait(_), true) => "E0404", - (PathSource::Trait(_), false) => "E0405", - (PathSource::Type, true) => "E0573", - (PathSource::Type, false) => "E0412", - (PathSource::Struct, true) => "E0574", - (PathSource::Struct, false) => "E0422", - (PathSource::Expr(..), true) => "E0423", - (PathSource::Expr(..), false) => "E0425", - (PathSource::Pat, true) | (PathSource::TupleStruct, true) => "E0532", - (PathSource::Pat, false) | (PathSource::TupleStruct, false) => "E0531", - (PathSource::TraitItem(..), true) => "E0575", - (PathSource::TraitItem(..), false) => "E0576", + (PathSource::Trait(_), true) => error_code!(E0404), + (PathSource::Trait(_), false) => error_code!(E0405), + (PathSource::Type, true) => error_code!(E0573), + (PathSource::Type, false) => error_code!(E0412), + (PathSource::Struct, true) => error_code!(E0574), + (PathSource::Struct, false) => error_code!(E0422), + (PathSource::Expr(..), true) => error_code!(E0423), + (PathSource::Expr(..), false) => error_code!(E0425), + (PathSource::Pat, true) | (PathSource::TupleStruct, true) => error_code!(E0532), + (PathSource::Pat, false) | (PathSource::TupleStruct, false) => error_code!(E0531), + (PathSource::TraitItem(..), true) => error_code!(E0575), + (PathSource::TraitItem(..), false) => error_code!(E0576), } } } diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 5e59efac53647..cf8aed8962b4a 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -4,7 +4,7 @@ use crate::path_names_to_string; use crate::{CrateLint, Module, ModuleKind, ModuleOrUniformRoot}; use crate::{PathResult, PathSource, Segment}; -use errors::{Applicability, DiagnosticBuilder, DiagnosticId}; +use errors::{Applicability, DiagnosticBuilder}; use log::debug; use rustc::hir::def::Namespace::{self, *}; use rustc::hir::def::{self, CtorKind, DefKind}; @@ -73,7 +73,6 @@ impl<'a> LateResolutionVisitor<'a, '_> { let expected = source.descr_expected(); let path_str = Segment::names_to_string(path); let item_str = path.last().unwrap().ident; - let code = source.error_code(res.is_some()); let (base_msg, fallback_label, base_span, could_be_expr) = if let Some(res) = res { ( format!("expected {}, found {} `{}`", expected, res.descr(), path_str), @@ -123,7 +122,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { ) }; - let code = DiagnosticId::Error(code.into()); + let code = source.error_code(res.is_some()); let mut err = self.r.session.struct_span_err_with_code(base_span, &base_msg, code); // Emit help message for fake-self from other languages (e.g., `this` in Javascript). @@ -140,8 +139,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { // Emit special messages for unresolved `Self` and `self`. if is_self_type(path, ns) { - syntax::diagnostic_used!(E0411); - err.code(DiagnosticId::Error("E0411".into())); + err.code(errors::error_code!(E0411)); err.span_label( span, format!("`Self` is only available in impls, traits, and type definitions"), @@ -151,8 +149,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { if is_self_value(path, ns) { debug!("smart_resolve_path_fragment: E0424, source={:?}", source); - syntax::diagnostic_used!(E0424); - err.code(DiagnosticId::Error("E0424".into())); + err.code(errors::error_code!(E0424)); err.span_label(span, match source { PathSource::Pat => format!( "`self` value is a keyword and may not be bound to variables or shadowed", diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b1be98834795a..6fbdaf2d14fe1 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -36,7 +36,7 @@ use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, NodeMap, NodeSet}; use rustc_metadata::creader::{CStore, CrateLoader}; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_expand::base::SyntaxExtension; use rustc_span::hygiene::{ExpnId, ExpnKind, MacroKind, SyntaxContext, Transparency}; use rustc_span::{Span, DUMMY_SP}; @@ -47,8 +47,8 @@ use syntax::attr; use syntax::print::pprust; use syntax::source_map::Spanned; use syntax::symbol::{kw, sym}; +use syntax::unwrap_or; use syntax::visit::{self, Visitor}; -use syntax::{struct_span_err, unwrap_or}; use log::debug; diff --git a/src/librustc_resolve/lifetimes.rs b/src/librustc_resolve/lifetimes.rs index 1f8573e44f1e1..52f1824024d58 100644 --- a/src/librustc_resolve/lifetimes.rs +++ b/src/librustc_resolve/lifetimes.rs @@ -11,7 +11,7 @@ use rustc::hir::map::Map; use rustc::hir::{GenericArg, GenericParam, LifetimeName, Node, ParamName, QPath}; use rustc::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; -use errors::{pluralize, Applicability, DiagnosticBuilder}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc::lint; use rustc::session::Session; use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet}; @@ -28,7 +28,7 @@ use rustc::hir::{self, GenericParamKind, LifetimeParamKind}; use log::debug; use rustc::{bug, span_bug}; -use syntax::{help, span_err, struct_span_err, walk_list}; +use syntax::walk_list; use rustc::middle::resolve_lifetime::*; use rustc_error_codes::*; @@ -592,13 +592,14 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { || krate.impl_items.contains_key(&parent_impl_id) || krate.trait_items.contains_key(&parent_trait_id)) { - span_err!( + struct_span_err!( self.tcx.sess, lifetime.span, E0657, "`impl Trait` can only capture lifetimes \ bound at the fn or impl level" - ); + ) + .emit(); self.uninsert_lifetime_on_error(lifetime, def.unwrap()); } } @@ -944,12 +945,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { }) { if self.trait_ref_hack { - span_err!( + struct_span_err!( self.tcx.sess, trait_ref.span, E0316, "nested quantification of lifetimes" - ); + ) + .emit(); } let next_early_index = self.next_early_index(); let scope = Scope::Binder { @@ -2434,36 +2436,32 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } if len == 0 { - help!( - db, - "this function's return type contains a borrowed value, but \ - there is no value for it to be borrowed from" + db.help( + "this function's return type contains a borrowed value, \ + but there is no value for it to be borrowed from", ); self.suggest_lifetime(db, span, "consider giving it a 'static lifetime") } else if elided_len == 0 { - help!( - db, + db.help( "this function's return type contains a borrowed value with \ an elided lifetime, but the lifetime cannot be derived from \ - the arguments" + the arguments", ); let msg = "consider giving it an explicit bounded or 'static lifetime"; self.suggest_lifetime(db, span, msg) } else if elided_len == 1 { - help!( - db, - "this function's return type contains a borrowed value, but \ - the signature does not say which {} it is borrowed from", + db.help(&format!( + "this function's return type contains a borrowed value, \ + but the signature does not say which {} it is borrowed from", m - ); + )); true } else { - help!( - db, - "this function's return type contains a borrowed value, but \ - the signature does not say whether it is borrowed from {}", + db.help(&format!( + "this function's return type contains a borrowed value, \ + but the signature does not say whether it is borrowed from {}", m - ); + )); true } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 8934fd4df742a..0e07bd969ce31 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -15,7 +15,7 @@ use crate::namespace::Namespace; use crate::require_c_abi_if_c_variadic; use crate::util::common::ErrorReported; use crate::util::nodemap::FxHashMap; -use errors::{Applicability, DiagnosticId}; +use errors::{struct_span_err, Applicability, DiagnosticId}; use rustc::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS; use rustc::traits; use rustc::ty::subst::{self, InternalSubsts, Subst, SubstsRef}; @@ -1118,13 +1118,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if unbound.is_none() { unbound = Some(&ptr.trait_ref); } else { - span_err!( + struct_span_err!( tcx.sess, span, E0203, "type parameter has more than one relaxed default \ bound, only one is supported" - ); + ) + .emit(); } } } @@ -1444,7 +1445,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } if regular_traits.is_empty() && auto_traits.is_empty() { - span_err!(tcx.sess, span, E0224, "at least one trait is required for an object type"); + struct_span_err!( + tcx.sess, + span, + E0224, + "at least one trait is required for an object type" + ) + .emit(); return tcx.types.err; } @@ -1599,13 +1606,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.ast_region_to_region(lifetime, None) } else { self.re_infer(None, span).unwrap_or_else(|| { - span_err!( + struct_span_err!( tcx.sess, span, E0228, "the lifetime bound for this object type cannot be deduced \ from context; please supply an explicit bound" - ); + ) + .emit(); tcx.lifetimes.re_static }) } @@ -2878,12 +2886,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // error. let r = derived_region_bounds[0]; if derived_region_bounds[1..].iter().any(|r1| r != *r1) { - span_err!( + struct_span_err!( tcx.sess, span, E0227, "ambiguous lifetime bound, explicit lifetime bound required" - ); + ) + .emit(); } return Some(r); } diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index 45c9922c579ce..8d2b7d6a39029 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -1,6 +1,7 @@ use super::method::MethodCallee; use super::{FnCtxt, Needs, PlaceOp}; +use errors::struct_span_err; use rustc::hir; use rustc::infer::{InferCtxt, InferOk}; use rustc::session::DiagnosticMessageId; diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 4b6bb2e05bfaa..19f9ee01b7566 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -1,8 +1,9 @@ use super::autoderef::Autoderef; use super::method::MethodCallee; use super::{Expectation, FnCtxt, Needs, TupleArgumentsFlag}; +use crate::type_error_struct; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use hir::def::Res; use hir::def_id::{DefId, LOCAL_CRATE}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 445a723e3cb7d..13718dbf516c6 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -32,8 +32,9 @@ use super::FnCtxt; use crate::hir::def_id::DefId; use crate::lint; +use crate::type_error_struct; use crate::util::common::ErrorReported; -use errors::{Applicability, DiagnosticBuilder}; +use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir; use rustc::middle::lang_items; use rustc::session::Session; @@ -423,17 +424,16 @@ impl<'a, 'tcx> CastCheck<'tcx> { ); } Err(_) => { - span_help!(err, self.cast_span, "did you mean `&{}{}`?", mtstr, tstr) + let msg = &format!("did you mean `&{}{}`?", mtstr, tstr); + err.span_help(self.cast_span, msg); } } } else { - span_help!( - err, - self.span, + let msg = &format!( "consider using an implicit coercion to `&{}{}` instead", - mtstr, - tstr + mtstr, tstr ); + err.span_help(self.span, msg); } } ty::Adt(def, ..) if def.is_box() => { @@ -446,11 +446,13 @@ impl<'a, 'tcx> CastCheck<'tcx> { Applicability::MachineApplicable, ); } - Err(_) => span_help!(err, self.cast_span, "did you mean `Box<{}>`?", tstr), + Err(_) => { + err.span_help(self.cast_span, &format!("did you mean `Box<{}>`?", tstr)); + } } } _ => { - span_help!(err, self.expr.span, "consider using a box or reference as appropriate"); + err.span_help(self.expr.span, "consider using a box or reference as appropriate"); } } err.emit(); diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index e079b42f81d5e..4151706beebb6 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -51,7 +51,7 @@ //! we may want to adjust precisely when coercions occur. use crate::check::{FnCtxt, Needs}; -use errors::DiagnosticBuilder; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index d6ef3889ee83d..eb714903da1ad 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -1,4 +1,4 @@ -use errors::{Applicability, DiagnosticId}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticId}; use rustc::hir::def::{DefKind, Res}; use rustc::hir::{self, GenericParamKind, ImplItemKind, TraitItemKind}; use rustc::infer::{self, InferOk}; @@ -8,9 +8,7 @@ use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::ty::util::ExplicitSelf; use rustc::ty::{self, GenericParamDefKind, TyCtxt}; use rustc::util::common::ErrorReported; - use rustc_span::Span; -use syntax::errors::pluralize; use super::{potentially_plural_count, FnCtxt, Inherited}; diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 6f2d529bc34f7..a5764d0d9ea27 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -1,8 +1,8 @@ use crate::check::regionck::RegionCtxt; - use crate::hir; use crate::hir::def_id::DefId; use crate::util::common::ErrorReported; +use errors::struct_span_err; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::{InferOk, SuppressRegionErrors}; use rustc::middle::region; diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 9ac047faa52fc..c4a09bd51bd5b 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -14,10 +14,11 @@ use crate::check::Expectation::{self, ExpectCastableToType, ExpectHasType, NoExp use crate::check::FnCtxt; use crate::check::Needs; use crate::check::TupleArgumentsFlag::DontTupleArguments; +use crate::type_error_struct; use crate::util::common::ErrorReported; use crate::util::nodemap::FxHashMap; -use errors::{pluralize, Applicability, DiagnosticBuilder, DiagnosticId}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc::hir; use rustc::hir::def::{CtorKind, DefKind, Res}; use rustc::hir::def_id::DefId; @@ -1108,13 +1109,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Prohibit struct expressions when non-exhaustive flag is set. let adt = adt_ty.ty_adt_def().expect("`check_struct_path` returned non-ADT type"); if !adt.did.is_local() && variant.is_field_list_non_exhaustive() { - span_err!( + struct_span_err!( self.tcx.sess, expr.span, E0639, "cannot create non-exhaustive {} using struct expression", adt.variant_descr() - ); + ) + .emit(); } let error_happened = self.check_expr_struct_fields( @@ -1152,12 +1154,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .insert(expr.hir_id, fru_field_types); } _ => { - span_err!( + struct_span_err!( self.tcx.sess, base_expr.span, E0436, "functional record update syntax requires a struct" - ); + ) + .emit(); } } } diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 66d3c797cf996..635bf01800f42 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -2,17 +2,16 @@ //! intrinsics that the compiler exposes. use crate::require_same_types; + +use errors::struct_span_err; +use rustc::hir; use rustc::traits::{ObligationCause, ObligationCauseCode}; use rustc::ty::subst::Subst; use rustc::ty::{self, Ty, TyCtxt}; - +use rustc_error_codes::*; use rustc_target::spec::abi::Abi; use syntax::symbol::Symbol; -use rustc::hir; - -use rustc_error_codes::*; - use std::iter; fn equate_intrinsic_type<'tcx>( @@ -413,19 +412,20 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) (2, params, param(1)) } Err(_) => { - span_err!( + struct_span_err!( tcx.sess, it.span, E0439, "invalid `simd_shuffle`, needs length: `{}`", name - ); + ) + .emit(); return; } }, _ => { let msg = format!("unrecognized platform-specific intrinsic function: `{}`", name); - tcx.sess.span_err(it.span, &msg); + tcx.sess.struct_span_err(it.span, &msg).emit(); return; } }; diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index acf449d384cca..7458fd53a931f 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -9,6 +9,7 @@ use crate::hir::def::DefKind; use crate::hir::def_id::DefId; use crate::namespace::Namespace; +use errors::struct_span_err; use rustc::hir; use rustc::infer::canonical::OriginalQueryValues; use rustc::infer::canonical::{Canonical, QueryResponse}; @@ -373,13 +374,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // so we do a future-compat lint here for the 2015 edition // (see https://github.com/rust-lang/rust/issues/46906) if self.tcx.sess.rust_2018() { - span_err!( + struct_span_err!( self.tcx.sess, span, E0699, "the type of this value must be known \ to call a method on a raw pointer on it" - ); + ) + .emit(); } else { self.tcx.lint_hir( lint::builtin::TYVAR_BEHIND_RAW_POINTER, diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 7c5671f0f5024..b9f792b819a5b 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -5,7 +5,7 @@ use crate::check::FnCtxt; use crate::middle::lang_items::FnOnceTraitLangItem; use crate::namespace::Namespace; use crate::util::nodemap::FxHashSet; -use errors::{pluralize, Applicability, DiagnosticBuilder}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir::def::{DefKind, Res}; use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::hir::map as hir_map; @@ -191,21 +191,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let item_span = self.tcx.sess.source_map().def_span(self.tcx.def_span(item.def_id)); let idx = if sources.len() > 1 { - span_note!( - err, - item_span, + let msg = &format!( "candidate #{} is defined in the trait `{}`", idx + 1, self.tcx.def_path_str(trait_did) ); + err.span_note(item_span, msg); Some(idx + 1) } else { - span_note!( - err, - item_span, + let msg = &format!( "the candidate is defined in the trait `{}`", self.tcx.def_path_str(trait_did) ); + err.span_note(item_span, msg); None }; let path = self.tcx.def_path_str(trait_did); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 86f92ce9b8923..1ff8821816fad 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -90,7 +90,7 @@ pub mod writeback; use crate::astconv::{AstConv, PathSeg}; use crate::middle::lang_items; use crate::namespace::Namespace; -use errors::{pluralize, Applicability, DiagnosticBuilder, DiagnosticId}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc::hir::def::{CtorOf, DefKind, Res}; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; @@ -155,6 +155,17 @@ use self::method::{MethodCallee, SelfSource}; pub use self::Expectation::*; use self::TupleArgumentsFlag::*; +#[macro_export] +macro_rules! type_error_struct { + ($session:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({ + if $typ.references_error() { + $session.diagnostic().struct_dummy() + } else { + errors::struct_span_err!($session, $span, $code, $($message)*) + } + }) +} + /// The type of a local binding, including the revealed type for anon types. #[derive(Copy, Clone, Debug)] pub struct LocalTy<'tcx> { @@ -2088,7 +2099,7 @@ fn check_impl_items_against_trait<'tcx>( if !invalidated_items.is_empty() { let invalidator = overridden_associated_type.unwrap(); - span_err!( + struct_span_err!( tcx.sess, invalidator.span, E0399, @@ -2096,6 +2107,7 @@ fn check_impl_items_against_trait<'tcx>( invalidator.ident, invalidated_items.iter().map(|name| name.to_string()).collect::>().join("`, `") ) + .emit(); } } @@ -2238,7 +2250,7 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { if def.is_struct() { let fields = &def.non_enum_variant().fields; if fields.is_empty() { - span_err!(tcx.sess, sp, E0075, "SIMD vector cannot be empty"); + struct_span_err!(tcx.sess, sp, E0075, "SIMD vector cannot be empty").emit(); return; } let e = fields[0].ty(tcx, substs); @@ -2252,12 +2264,13 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) { ty::Param(_) => { /* struct(T, T, T, T) is ok */ } _ if e.is_machine() => { /* struct(u8, u8, u8, u8) is ok */ } _ => { - span_err!( + struct_span_err!( tcx.sess, sp, E0077, "SIMD vector element type should be machine type" - ); + ) + .emit(); return; } } @@ -2542,14 +2555,15 @@ pub fn check_enum<'tcx>( } fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, span: Span, qpath: &QPath<'_>) { - span_err!( + struct_span_err!( tcx.sess, span, E0533, "expected unit struct, unit variant or constant, found {} `{}`", res.descr(), hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false)) - ); + ) + .emit(); } impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { @@ -3759,13 +3773,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { arg_types.iter().map(|k| k.expect_ty()).collect() } _ => { - span_err!( + struct_span_err!( tcx.sess, sp, E0059, "cannot use call notation; the first type parameter \ for the function trait is neither a tuple nor unit" - ); + ) + .emit(); expected_arg_tys = vec![]; self.err_args(args.len()) } diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index e0035c4afc7cc..0560f008c7d62 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -2,7 +2,7 @@ use super::method::MethodCallee; use super::{FnCtxt, Needs}; -use errors::{self, Applicability}; +use errors::{self, struct_span_err, Applicability}; use rustc::hir; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 251c8427ffd54..703ee76fe0be6 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -1,6 +1,6 @@ use crate::check::FnCtxt; use crate::util::nodemap::FxHashMap; -use errors::{pluralize, Applicability, DiagnosticBuilder}; +use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir::def::{CtorKind, DefKind, Res}; use rustc::hir::pat_util::EnumerateAndAdjustIterator; use rustc::hir::{self, HirId, Pat, PatKind}; @@ -982,22 +982,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Require `..` if struct has non_exhaustive attribute. if variant.is_field_list_non_exhaustive() && !adt.did.is_local() && !etc { - span_err!( + struct_span_err!( tcx.sess, span, E0638, "`..` required with {} marked as non-exhaustive", kind_name - ); + ) + .emit(); } // Report an error if incorrect number of the fields were specified. if kind_name == "union" { if fields.len() != 1 { - tcx.sess.span_err(span, "union patterns should have exactly one field"); + tcx.sess + .struct_span_err(span, "union patterns should have exactly one field") + .emit(); } if etc { - tcx.sess.span_err(span, "`..` cannot be used in union patterns"); + tcx.sess.struct_span_err(span, "`..` cannot be used in union patterns").emit(); } } else if !etc && unmentioned_fields.len() > 0 { self.error_unmentioned_fields(span, &unmentioned_fields, variant); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index bf2c6776d1aa5..11afbd79141e0 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -2,14 +2,13 @@ use crate::check::{FnCtxt, Inherited}; use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter}; use crate::hir::def_id::DefId; +use errors::{struct_span_err, DiagnosticBuilder}; use rustc::infer::opaque_types::may_define_opaque_type; use rustc::middle::lang_items; use rustc::traits::{self, ObligationCause, ObligationCauseCode}; use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::ty::{self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc::util::nodemap::{FxHashMap, FxHashSet}; - -use errors::DiagnosticBuilder; use rustc_span::Span; use syntax::ast; use syntax::feature_gate; @@ -112,13 +111,14 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: DefId) { ty::ImplPolarity::Negative => { // FIXME(#27579): what amount of WF checking do we need for neg impls? if trait_ref.is_some() && !is_auto { - span_err!( + struct_span_err!( tcx.sess, item.span, E0192, "negative impls are only allowed for \ auto traits (e.g., `Send` and `Sync`)" ) + .emit() } } ty::ImplPolarity::Reservation => { diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 7f7e21838d22f..a41fb19d327c5 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -1,22 +1,19 @@ //! Check properties that are required by built-in traits and set //! up data structures required by type-checking/codegen. +use errors::struct_span_err; +use rustc::hir::def_id::DefId; +use rustc::hir::{self, ItemKind, Node}; +use rustc::infer; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::SuppressRegionErrors; use rustc::middle::lang_items::UnsizeTraitLangItem; use rustc::middle::region; - -use rustc::infer; use rustc::traits::{self, ObligationCause, TraitEngine}; use rustc::ty::adjustment::CoerceUnsizedInfo; use rustc::ty::util::CopyImplementationError; use rustc::ty::TypeFoldable; use rustc::ty::{self, Ty, TyCtxt}; - -use hir::Node; -use rustc::hir::def_id::DefId; -use rustc::hir::{self, ItemKind}; - use rustc_error_codes::*; pub fn check_trait(tcx: TyCtxt<'_>, trait_def_id: DefId) { @@ -401,7 +398,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn if def_a != def_b { let source_path = tcx.def_path_str(def_a.did); let target_path = tcx.def_path_str(def_b.did); - span_err!( + struct_span_err!( tcx.sess, span, E0377, @@ -410,7 +407,8 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn definition; expected `{}`, found `{}`", source_path, target_path - ); + ) + .emit(); return err_info; } @@ -487,14 +485,15 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn .collect::>(); if diff_fields.is_empty() { - span_err!( + struct_span_err!( tcx.sess, span, E0374, "the trait `CoerceUnsized` may only be implemented \ for a coercion between structures with one field \ being coerced, none found" - ); + ) + .emit(); return err_info; } else if diff_fields.len() > 1 { let item = tcx.hir().expect_item(impl_hir_id); @@ -504,19 +503,19 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn tcx.hir().span(impl_hir_id) }; - let mut err = struct_span_err!( + struct_span_err!( tcx.sess, span, E0375, "implementing the trait \ `CoerceUnsized` requires multiple \ coercions" - ); - err.note( + ) + .note( "`CoerceUnsized` may only be implemented for \ a coercion between structures with one field being coerced", - ); - err.note(&format!( + ) + .note(&format!( "currently, {} fields need coercions: {}", diff_fields.len(), diff_fields @@ -526,9 +525,9 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn }) .collect::>() .join(", ") - )); - err.span_label(span, "requires multiple coercions"); - err.emit(); + )) + .span_label(span, "requires multiple coercions") + .emit(); return err_info; } @@ -538,13 +537,14 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn } _ => { - span_err!( + struct_span_err!( tcx.sess, span, E0376, "the trait `CoerceUnsized` may only be implemented \ for a coercion between structures" - ); + ) + .emit(); return err_info; } }; diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 4e75134a04cfd..67357964be9c5 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -7,6 +7,7 @@ //! `tcx.inherent_impls(def_id)`). That value, however, //! is computed by selecting an idea from this table. +use errors::struct_span_err; use rustc::hir; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir::itemlikevisit::ItemLikeVisitor; diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index 76eb8f5379c0e..a78e879b8d5b1 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -1,10 +1,10 @@ use crate::namespace::Namespace; +use errors::struct_span_err; use rustc::hir; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::traits::{self, IntercrateMode}; use rustc::ty::TyCtxt; - use rustc_error_codes::*; pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, crate_num: CrateNum) { diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index cba0436774d15..8071135f50ce5 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -7,6 +7,7 @@ use crate::hir::def_id::{DefId, LOCAL_CRATE}; use crate::hir::HirId; +use errors::struct_span_err; use rustc::traits; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt, TypeFoldable}; diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index b387a5d152017..3c6cf99b1780d 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -1,6 +1,7 @@ //! Orphan checker: every impl either implements a trait defined in this //! crate or pertains to a type defined in this crate. +use errors::struct_span_err; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::traits; diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index eee292c55a8a4..296388210f00b 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -1,10 +1,10 @@ //! Unsafety checker: every impl either implements a trait defined in this //! crate or pertains to a type defined in this crate. +use errors::struct_span_err; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::{self, Unsafety}; use rustc::ty::TyCtxt; - use rustc_error_codes::*; pub fn check(tcx: TyCtxt<'_>) { @@ -32,23 +32,25 @@ impl UnsafetyChecker<'tcx> { }); match (trait_def.unsafety, unsafe_attr, unsafety, polarity) { (Unsafety::Normal, None, Unsafety::Unsafe, hir::ImplPolarity::Positive) => { - span_err!( + struct_span_err!( self.tcx.sess, item.span, E0199, "implementing the trait `{}` is not unsafe", trait_ref.print_only_trait_path() - ); + ) + .emit(); } (Unsafety::Unsafe, _, Unsafety::Normal, hir::ImplPolarity::Positive) => { - span_err!( + struct_span_err!( self.tcx.sess, item.span, E0200, "the trait `{}` requires an `unsafe impl` declaration", trait_ref.print_only_trait_path() - ); + ) + .emit(); } ( @@ -57,13 +59,14 @@ impl UnsafetyChecker<'tcx> { Unsafety::Normal, hir::ImplPolarity::Positive, ) => { - span_err!( + struct_span_err!( self.tcx.sess, item.span, E0569, "requires an `unsafe impl` declaration due to `#[{}]` attribute", attr_name - ); + ) + .emit(); } (_, _, Unsafety::Unsafe, hir::ImplPolarity::Negative) => { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index dfbeb0353a61c..ad2d010a32663 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -46,7 +46,7 @@ use rustc::hir::GenericParamKind; use rustc::hir::Node; use rustc::hir::{self, CodegenFnAttrFlags, CodegenFnAttrs, Unsafety}; -use errors::{Applicability, StashKey}; +use errors::{struct_span_err, Applicability, StashKey}; use rustc_error_codes::*; @@ -321,13 +321,14 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> { self.tcx().mk_projection(item_def_id, item_substs) } else { // There are no late-bound regions; we can just ignore the binder. - span_err!( + struct_span_err!( self.tcx().sess, span, E0212, "cannot extract an associated type from a higher-ranked trait bound \ in this context" - ); + ) + .emit(); self.tcx().types.err } } @@ -862,17 +863,14 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TraitDef { let paren_sugar = tcx.has_attr(def_id, sym::rustc_paren_sugar); if paren_sugar && !tcx.features().unboxed_closures { - let mut err = tcx.sess.struct_span_err( - item.span, - "the `#[rustc_paren_sugar]` attribute is a temporary means of controlling \ + tcx.sess + .struct_span_err( + item.span, + "the `#[rustc_paren_sugar]` attribute is a temporary means of controlling \ which traits can use parenthetical notation", - ); - help!( - &mut err, - "add `#![feature(unboxed_closures)]` to \ - the crate attributes to use it" - ); - err.emit(); + ) + .help("add `#![feature(unboxed_closures)]` to the crate attributes to use it") + .emit(); } let is_marker = tcx.has_attr(def_id, sym::marker); @@ -1207,12 +1205,13 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics { } fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) { - span_err!( + struct_span_err!( tcx.sess, span, E0202, "associated types are not yet supported in inherent impls (see #8995)" - ); + ) + .emit(); } fn infer_placeholder_type( @@ -2768,14 +2767,26 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { mark_used(attr); inline_span = Some(attr.span); if items.len() != 1 { - span_err!(tcx.sess.diagnostic(), attr.span, E0534, "expected one argument"); + struct_span_err!( + tcx.sess.diagnostic(), + attr.span, + E0534, + "expected one argument" + ) + .emit(); InlineAttr::None } else if list_contains_name(&items[..], sym::always) { InlineAttr::Always } else if list_contains_name(&items[..], sym::never) { InlineAttr::Never } else { - span_err!(tcx.sess.diagnostic(), items[0].span(), E0535, "invalid argument"); + struct_span_err!( + tcx.sess.diagnostic(), + items[0].span(), + E0535, + "invalid argument" + ) + .emit(); InlineAttr::None } @@ -2789,7 +2800,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { if !attr.has_name(sym::optimize) { return ia; } - let err = |sp, s| span_err!(tcx.sess.diagnostic(), sp, E0722, "{}", s); + let err = |sp, s| struct_span_err!(tcx.sess.diagnostic(), sp, E0722, "{}", s).emit(); match attr.meta().map(|i| i.kind) { Some(MetaItemKind::Word) => { err(attr.span, "expected one argument"); diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index 82632bbc17c05..50875c99c5ea2 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -9,6 +9,7 @@ //! fixed, but for the moment it's easier to do these checks early. use crate::constrained_generic_params as cgp; +use errors::struct_span_err; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::hir::itemlikevisit::ItemLikeVisitor; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 289a4dc3ecb6d..4006c3114788e 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -71,8 +71,6 @@ This API is completely unstable and subject to change. #[macro_use] extern crate log; -#[macro_use] -extern crate syntax; #[macro_use] extern crate rustc; @@ -93,6 +91,7 @@ mod outlives; mod structured_errors; mod variance; +use errors::struct_span_err; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::hir::{self, Node}; use rustc::infer::InferOk; diff --git a/src/librustc_typeck/outlives/test.rs b/src/librustc_typeck/outlives/test.rs index 13430b752c11a..a99518a98df42 100644 --- a/src/librustc_typeck/outlives/test.rs +++ b/src/librustc_typeck/outlives/test.rs @@ -1,9 +1,9 @@ +use errors::struct_span_err; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::ty::TyCtxt; -use syntax::symbol::sym; - use rustc_error_codes::*; +use syntax::symbol::sym; pub fn test_inferred_outlives(tcx: TyCtxt<'_>) { tcx.hir().krate().visit_all_item_likes(&mut OutlivesTest { tcx }); @@ -21,7 +21,7 @@ impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> { // attribute and report an error with various results if found. if self.tcx.has_attr(item_def_id, sym::rustc_outlives) { let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id); - span_err!(self.tcx.sess, item.span, E0640, "{:?}", inferred_outlives_of); + struct_span_err!(self.tcx.sess, item.span, E0640, "{:?}", inferred_outlives_of).emit(); } } diff --git a/src/librustc_typeck/structured_errors.rs b/src/librustc_typeck/structured_errors.rs index 251732b6f1233..dc6c45b41842c 100644 --- a/src/librustc_typeck/structured_errors.rs +++ b/src/librustc_typeck/structured_errors.rs @@ -50,8 +50,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for VariadicError<'tcx> { } fn code(&self) -> DiagnosticId { - syntax::diagnostic_used!(E0617); - DiagnosticId::Error("E0617".to_owned()) + errors::error_code!(E0617) } fn common(&self) -> DiagnosticBuilder<'tcx> { @@ -112,8 +111,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCastError<'tcx> { } fn code(&self) -> DiagnosticId { - syntax::diagnostic_used!(E0607); - DiagnosticId::Error("E0607".to_owned()) + errors::error_code!(E0607) } fn common(&self) -> DiagnosticBuilder<'tcx> { diff --git a/src/librustc_typeck/variance/test.rs b/src/librustc_typeck/variance/test.rs index f098fb9de1009..6797c0086d23d 100644 --- a/src/librustc_typeck/variance/test.rs +++ b/src/librustc_typeck/variance/test.rs @@ -1,3 +1,4 @@ +use errors::struct_span_err; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::ty::TyCtxt; @@ -21,7 +22,7 @@ impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { // attribute and report an error with various results if found. if self.tcx.has_attr(item_def_id, sym::rustc_variance) { let variances_of = self.tcx.variances_of(item_def_id); - span_err!(self.tcx.sess, item.span, E0208, "{:?}", variances_of); + struct_span_err!(self.tcx.sess, item.span, E0208, "{:?}", variances_of).emit(); } } diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 04c28dd5c5bcb..b308d479545be 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -6,7 +6,7 @@ use crate::feature_gate::feature_err; use crate::print::pprust; use crate::sess::ParseSess; -use errors::{Applicability, Handler}; +use errors::{struct_span_err, Applicability, Handler}; use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg}; use rustc_macros::HashStable_Generic; use rustc_span::hygiene::Transparency; @@ -31,17 +31,21 @@ enum AttrError { fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) { let diag = &sess.span_diagnostic; match error { - AttrError::MultipleItem(item) => span_err!(diag, span, E0538, "multiple '{}' items", item), + AttrError::MultipleItem(item) => { + struct_span_err!(diag, span, E0538, "multiple '{}' items", item).emit(); + } AttrError::UnknownMetaItem(item, expected) => { let expected = expected.iter().map(|name| format!("`{}`", name)).collect::>(); struct_span_err!(diag, span, E0541, "unknown meta item '{}'", item) .span_label(span, format!("expected one of {}", expected.join(", "))) .emit(); } - AttrError::MissingSince => span_err!(diag, span, E0542, "missing 'since'"), - AttrError::MissingFeature => span_err!(diag, span, E0546, "missing 'feature'"), + AttrError::MissingSince => struct_span_err!(diag, span, E0542, "missing 'since'").emit(), + AttrError::MissingFeature => { + struct_span_err!(diag, span, E0546, "missing 'feature'").emit(); + } AttrError::MultipleStabilityLevels => { - span_err!(diag, span, E0544, "multiple stability levels") + struct_span_err!(diag, span, E0544, "multiple stability levels").emit(); } AttrError::UnsupportedLiteral(msg, is_bytestr) => { let mut err = struct_span_err!(diag, span, E0565, "{}", msg); @@ -283,7 +287,7 @@ where *item = Some(v); true } else { - span_err!(diagnostic, meta.span, E0539, "incorrect meta item"); + struct_span_err!(diagnostic, meta.span, E0539, "incorrect meta item").emit(); false } }; @@ -331,12 +335,13 @@ where match meta_name { sym::rustc_deprecated => { if rustc_depr.is_some() { - span_err!( + struct_span_err!( diagnostic, item_sp, E0540, "multiple rustc_deprecated attributes" - ); + ) + .emit(); continue 'outer; } @@ -351,7 +356,8 @@ where continue; } _ => { - span_err!(diagnostic, attr.span, E0543, "missing 'reason'"); + struct_span_err!(diagnostic, attr.span, E0543, "missing 'reason'") + .emit(); continue; } } @@ -426,12 +432,13 @@ where // Disallowing this requires updates to some submodules NonZeroU32::new(num) } else { - span_err!( + struct_span_err!( diagnostic, attr.span, E0545, "incorrect 'issue'" - ); + ) + .emit(); continue; } } @@ -453,7 +460,8 @@ where continue; } _ => { - span_err!(diagnostic, attr.span, E0547, "missing 'issue'"); + struct_span_err!(diagnostic, attr.span, E0547, "missing 'issue'") + .emit(); continue; } } @@ -539,13 +547,14 @@ where if let Some(ref mut stab) = stab { stab.rustc_depr = Some(rustc_depr); } else { - span_err!( + struct_span_err!( diagnostic, item_sp, E0549, "rustc_deprecated attribute must be paired with \ either stable or unstable attribute" - ); + ) + .emit(); } } @@ -555,14 +564,15 @@ where stab.promotable = promotable; stab.allow_const_fn_ptr = allow_const_fn_ptr; } else { - span_err!( + struct_span_err!( diagnostic, item_sp, E0717, "rustc_promotable and rustc_allow_const_fn_ptr attributes \ must be paired with either a rustc_const_unstable or a rustc_const_stable \ attribute" - ); + ) + .emit(); } } @@ -649,20 +659,27 @@ pub fn eval_condition( } sym::not => { if mis.len() != 1 { - span_err!(sess.span_diagnostic, cfg.span, E0536, "expected 1 cfg-pattern"); + struct_span_err!( + sess.span_diagnostic, + cfg.span, + E0536, + "expected 1 cfg-pattern" + ) + .emit(); return false; } !eval_condition(mis[0].meta_item().unwrap(), sess, eval) } _ => { - span_err!( + struct_span_err!( sess.span_diagnostic, cfg.span, E0537, "invalid predicate `{}`", pprust::path_to_string(&cfg.path) - ); + ) + .emit(); false } } @@ -703,7 +720,7 @@ where } if depr.is_some() { - span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes"); + struct_span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes").emit(); break; } @@ -741,7 +758,8 @@ where ), ); } else { - span_err!(diagnostic, meta.span, E0551, "incorrect meta item"); + struct_span_err!(diagnostic, meta.span, E0551, "incorrect meta item") + .emit(); } false @@ -900,13 +918,14 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec { }; } if let Some(literal_error) = literal_error { - span_err!( + struct_span_err!( diagnostic, item.span(), E0589, "invalid `repr(align)` attribute: {}", literal_error - ); + ) + .emit(); } } else { if let Some(meta_item) = item.meta_item() { @@ -945,7 +964,13 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec { } if !recognised { // Not a word we recognize - span_err!(diagnostic, item.span(), E0552, "unrecognized representation hint"); + struct_span_err!( + diagnostic, + item.span(), + E0552, + "unrecognized representation hint" + ) + .emit(); } } } diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs deleted file mode 100644 index 4ed17418c30ba..0000000000000 --- a/src/libsyntax/diagnostics/macros.rs +++ /dev/null @@ -1,169 +0,0 @@ -#[macro_export] -macro_rules! diagnostic_used { - ($code:ident) => { - let _ = $code; - }; -} - -#[macro_export] -macro_rules! span_fatal { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.span_fatal_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! span_err { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! span_warn { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! struct_err { - ($session:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_err_with_code( - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! span_err_or_warn { - ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - if $is_warning { - $session.span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } else { - $session.span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } - }) -} - -#[macro_export] -macro_rules! struct_span_fatal { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_span_fatal_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! struct_span_err { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! stringify_error_code { - ($code:ident) => {{ - $crate::diagnostic_used!($code); - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()) - }}; -} - -#[macro_export] -macro_rules! type_error_struct { - ($session:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({ - if $typ.references_error() { - $session.diagnostic().struct_dummy() - } else { - struct_span_err!($session, $span, $code, $($message)*) - } - }) -} - -#[macro_export] -macro_rules! struct_span_warn { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! struct_span_err_or_warn { - ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - if $is_warning { - $session.struct_span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } else { - $session.struct_span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } - }) -} - -#[macro_export] -macro_rules! span_note { - ($err:expr, $span:expr, $($message:tt)*) => ({ - ($err).span_note($span, &format!($($message)*)); - }) -} - -#[macro_export] -macro_rules! span_help { - ($err:expr, $span:expr, $($message:tt)*) => ({ - ($err).span_help($span, &format!($($message)*)); - }) -} - -#[macro_export] -macro_rules! help { - ($err:expr, $($message:tt)*) => ({ - ($err).help(&format!($($message)*)); - }) -} diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index e5635eaf1e915..4e48c6a95a578 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -14,7 +14,7 @@ use crate::source_map::Spanned; use crate::symbol::{sym, Symbol}; use crate::visit::{self, FnKind, Visitor}; -use errors::{Applicability, DiagnosticBuilder, Handler}; +use errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder, Handler}; use log::debug; use rustc_data_structures::fx::FxHashMap; use rustc_span::{MultiSpan, Span, DUMMY_SP}; @@ -92,9 +92,7 @@ fn leveled_feature_err<'a>( let diag = &sess.span_diagnostic; let mut err = match level { - GateStrength::Hard => { - diag.struct_span_err_with_code(span, explain, stringify_error_code!(E0658)) - } + GateStrength::Hard => diag.struct_span_err_with_code(span, explain, error_code!(E0658)), GateStrength::Soft => diag.struct_span_warn(span, explain), }; @@ -828,15 +826,9 @@ pub fn get_features( }; if let Some(edition) = edition_enabled_features.get(&name) { - struct_span_warn!( - span_handler, - mi.span(), - E0705, - "the feature `{}` is included in the Rust {} edition", - name, - edition, - ) - .emit(); + let msg = + &format!("the feature `{}` is included in the Rust {} edition", name, edition); + span_handler.struct_span_warn_with_code(mi.span(), msg, error_code!(E0705)).emit(); continue; } @@ -864,13 +856,14 @@ pub fn get_features( if let Some(allowed) = allow_features.as_ref() { if allowed.iter().find(|&f| name.as_str() == *f).is_none() { - span_err!( + struct_span_err!( span_handler, mi.span(), E0725, "the feature `{}` is not in the list of allowed features", name - ); + ) + .emit(); continue; } } @@ -954,13 +947,14 @@ pub fn check_crate( fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate, unstable: UnstableFeatures) { if !unstable.is_nightly_build() { for attr in krate.attrs.iter().filter(|attr| attr.check_name(sym::feature)) { - span_err!( + struct_span_err!( span_handler, attr.span, E0554, "`#![feature]` may not be used on the {} release channel", option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)") - ); + ) + .emit(); } } } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index b537f16ffcd9a..6fa9a8ffcf8a3 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -68,12 +68,6 @@ where scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals); -#[macro_use] -pub mod diagnostics { - #[macro_use] - pub mod macros; -} - pub mod util { pub mod classify; pub mod comments; diff --git a/src/test/ui/conflicting-repr-hints.stderr b/src/test/ui/conflicting-repr-hints.stderr index 414c15f93bc18..48ddd4503eebd 100644 --- a/src/test/ui/conflicting-repr-hints.stderr +++ b/src/test/ui/conflicting-repr-hints.stderr @@ -3,6 +3,8 @@ warning[E0566]: conflicting representation hints | LL | #[repr(C, u64)] | ^ ^^^ + | + = note: `#[warn(conflicting_repr_hints)]` on by default warning[E0566]: conflicting representation hints --> $DIR/conflicting-repr-hints.rs:12:8 diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr index 02c8400e03e82..d79d4ae27f11e 100644 --- a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr +++ b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr @@ -23,6 +23,8 @@ LL | #[repr(C)] | ^ LL | #[repr(simd)] | ^^^^ + | + = note: `#[warn(conflicting_repr_hints)]` on by default error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-14221.stderr b/src/test/ui/issues/issue-14221.stderr index 3e5e25a9f6d1f..a5dae1a1ce38b 100644 --- a/src/test/ui/issues/issue-14221.stderr +++ b/src/test/ui/issues/issue-14221.stderr @@ -3,6 +3,8 @@ warning[E0170]: pattern binding `A` is named the same as one of the variants of | LL | A => "A", | ^ help: to match on the variant, qualify the path: `E::A` + | + = note: `#[warn(binding_variant_name)]` on by default warning[E0170]: pattern binding `B` is named the same as one of the variants of the type `E` --> $DIR/issue-14221.rs:15:13 diff --git a/src/test/ui/issues/issue-19100.stderr b/src/test/ui/issues/issue-19100.stderr index 1ab13477e37ed..e7dd2c1e681d7 100644 --- a/src/test/ui/issues/issue-19100.stderr +++ b/src/test/ui/issues/issue-19100.stderr @@ -3,6 +3,8 @@ warning[E0170]: pattern binding `Bar` is named the same as one of the variants o | LL | Bar if true | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` + | + = note: `#[warn(binding_variant_name)]` on by default warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` --> $DIR/issue-19100.rs:22:1 diff --git a/src/test/ui/issues/issue-30302.stderr b/src/test/ui/issues/issue-30302.stderr index d762d6f2b3d5e..14ae9aa5a7b50 100644 --- a/src/test/ui/issues/issue-30302.stderr +++ b/src/test/ui/issues/issue-30302.stderr @@ -3,6 +3,8 @@ warning[E0170]: pattern binding `Nil` is named the same as one of the variants o | LL | Nil => true, | ^^^ help: to match on the variant, qualify the path: `Stack::Nil` + | + = note: `#[warn(binding_variant_name)]` on by default error: unreachable pattern --> $DIR/issue-30302.rs:15:9 diff --git a/src/test/ui/issues/issue-39720.stderr b/src/test/ui/issues/issue-39720.stderr index 8121ed2894045..e33fc823fbecc 100644 --- a/src/test/ui/issues/issue-39720.stderr +++ b/src/test/ui/issues/issue-39720.stderr @@ -5,6 +5,8 @@ LL | #[repr(C)] | ^ LL | #[repr(simd)] | ^^^^ + | + = note: `#[warn(conflicting_repr_hints)]` on by default warning[E0566]: conflicting representation hints --> $DIR/issue-39720.rs:13:8 diff --git a/src/test/ui/issues/issue-47094.stderr b/src/test/ui/issues/issue-47094.stderr index 16bcec0c7bb3a..570fe53c26352 100644 --- a/src/test/ui/issues/issue-47094.stderr +++ b/src/test/ui/issues/issue-47094.stderr @@ -3,6 +3,8 @@ warning[E0566]: conflicting representation hints | LL | #[repr(C,u8)] | ^ ^^ + | + = note: `#[warn(conflicting_repr_hints)]` on by default warning[E0566]: conflicting representation hints --> $DIR/issue-47094.rs:9:8 diff --git a/src/test/ui/lint/lint-uppercase-variables.stderr b/src/test/ui/lint/lint-uppercase-variables.stderr index f614d5d71f88c..0519a63e05585 100644 --- a/src/test/ui/lint/lint-uppercase-variables.stderr +++ b/src/test/ui/lint/lint-uppercase-variables.stderr @@ -3,6 +3,8 @@ warning[E0170]: pattern binding `Foo` is named the same as one of the variants o | LL | Foo => {} | ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo` + | + = note: `#[warn(binding_variant_name)]` on by default warning: unused variable: `Foo` --> $DIR/lint-uppercase-variables.rs:22:9