diff options
| author | bors <bors@rust-lang.org> | 2023-02-26 17:17:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-02-26 17:17:25 +0000 |
| commit | 56ac6bfc87cce22feffc079c0540c8774b00a5ca (patch) | |
| tree | e430c91fb4e29070945f79df7a47639e5cf4f9b1 /compiler/rustc_passes/src | |
| parent | ffd12f67cfa28891bbd1fa81d5e80a128f346ace (diff) | |
| parent | cb45103358c0fef99d7659e0949b3c65b3eabdd6 (diff) | |
| download | rust-56ac6bfc87cce22feffc079c0540c8774b00a5ca.tar.gz rust-56ac6bfc87cce22feffc079c0540c8774b00a5ca.zip | |
Auto merge of #2803 - RalfJung:rustup, r=RalfJung
Rustup
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 41 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/dead.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 104 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/lib.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/liveness.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/naked_functions.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/stability.rs | 9 |
7 files changed, 108 insertions, 65 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 8ad4a5ef958..5ef3e13eff8 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -4,10 +4,10 @@ //! conflicts between multiple such attributes attached to the same //! item. -use crate::errors; +use crate::{errors, fluent_generated as fluent}; use rustc_ast::{ast, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem}; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{fluent, Applicability, IntoDiagnosticArg, MultiSpan}; +use rustc_errors::{Applicability, IntoDiagnosticArg, MultiSpan}; use rustc_expand::base::resolve_path; use rustc_feature::{AttributeDuplicates, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP}; use rustc_hir as hir; @@ -23,7 +23,8 @@ use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_session::lint::builtin::{ - CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES, + CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS, + UNUSED_ATTRIBUTES, }; use rustc_session::parse::feature_err; use rustc_span::symbol::{kw, sym, Symbol}; @@ -935,15 +936,15 @@ impl CheckAttrVisitor<'_> { src.insert(1, '!'); err.span_suggestion_verbose( attr.span, - fluent::suggestion, + fluent::passes_suggestion, src, Applicability::MaybeIncorrect, ); } else { - err.span_help(attr.span, fluent::help); + err.span_help(attr.span, fluent::passes_help); } } - err.note(fluent::note); + err.note(fluent::passes_note); err }, ); @@ -2102,7 +2103,33 @@ impl CheckAttrVisitor<'_> { fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) { if target != Target::MacroDef { - self.tcx.emit_spanned_lint(UNUSED_ATTRIBUTES, hir_id, attr.span, errors::MacroExport); + self.tcx.emit_spanned_lint( + UNUSED_ATTRIBUTES, + hir_id, + attr.span, + errors::MacroExport::Normal, + ); + } else if let Some(meta_item_list) = attr.meta_item_list() && + !meta_item_list.is_empty() { + if meta_item_list.len() > 1 { + self.tcx.emit_spanned_lint( + INVALID_MACRO_EXPORT_ARGUMENTS, + hir_id, + attr.span, + errors::MacroExport::TooManyItems, + ); + } else { + if meta_item_list[0].name_or_empty() != sym::local_inner_macros { + self.tcx.emit_spanned_lint( + INVALID_MACRO_EXPORT_ARGUMENTS, + hir_id, + meta_item_list[0].span(), + errors::MacroExport::UnknownItem { + name: meta_item_list[0].name_or_empty(), + }, + ); + } + } } } diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 668c159f3cc..e2f858a34b6 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -395,6 +395,9 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> { self.mark_as_used_if_union(*adt, fields); } } + hir::ExprKind::Closure(cls) => { + self.insert_def_id(cls.def_id.to_def_id()); + } _ => (), } @@ -691,7 +694,7 @@ impl<'tcx> DeadVisitor<'tcx> { }) .collect(); - let descr = tcx.def_kind(first_id).descr(first_id.to_def_id()); + let descr = tcx.def_descr(first_id.to_def_id()); let num = dead_codes.len(); let multiple = num > 6; let name_list = names.into(); @@ -703,7 +706,7 @@ impl<'tcx> DeadVisitor<'tcx> { }; let parent_info = if let Some(parent_item) = parent_item { - let parent_descr = tcx.def_kind(parent_item).descr(parent_item.to_def_id()); + let parent_descr = tcx.def_descr(parent_item.to_def_id()); Some(ParentInfo { num, descr, diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 68b098e3457..2c0d21b4798 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -3,6 +3,7 @@ use std::{ path::{Path, PathBuf}, }; +use crate::fluent_generated as fluent; use rustc_ast::Label; use rustc_errors::{ error_code, Applicability, DiagnosticSymbolList, ErrorGuaranteed, IntoDiagnostic, MultiSpan, @@ -261,7 +262,7 @@ pub struct DocKeywordConflict { pub struct DocInlineOnlyUse { #[label] pub attr_span: Span, - #[label(not_a_use_item_label)] + #[label(passes_not_a_use_item_label)] pub item_span: Option<Span>, } @@ -300,7 +301,7 @@ pub struct DocTestUnknownAny { #[derive(LintDiagnostic)] #[diag(passes_doc_test_unknown_spotlight)] #[note] -#[note(no_op_note)] +#[note(passes_no_op_note)] pub struct DocTestUnknownSpotlight { pub path: String, #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")] @@ -573,9 +574,9 @@ pub struct DebugVisualizerPlacement { #[derive(Diagnostic)] #[diag(passes_debug_visualizer_invalid)] -#[note(note_1)] -#[note(note_2)] -#[note(note_3)] +#[note(passes_note_1)] +#[note(passes_note_2)] +#[note(passes_note_3)] pub struct DebugVisualizerInvalid { #[primary_span] pub span: Span, @@ -640,8 +641,16 @@ pub struct MacroUse { } #[derive(LintDiagnostic)] -#[diag(passes_macro_export)] -pub struct MacroExport; +pub enum MacroExport { + #[diag(passes_macro_export)] + Normal, + + #[diag(passes_invalid_macro_export_arguments)] + UnknownItem { name: Symbol }, + + #[diag(passes_invalid_macro_export_arguments_too_many_items)] + TooManyItems, +} #[derive(LintDiagnostic)] #[diag(passes_plugin_registrar)] @@ -782,7 +791,7 @@ impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel { self, handler: &'_ rustc_errors::Handler, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { - let mut diag = handler.struct_err(rustc_errors::fluent::passes_invalid_attr_at_crate_level); + let mut diag = handler.struct_err(fluent::passes_invalid_attr_at_crate_level); diag.set_span(self.span); diag.set_arg("name", self.name); // Only emit an error with a suggestion if we can create a string out @@ -791,7 +800,7 @@ impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel { let replacement = src.replace("#!", "#"); diag.span_suggestion_verbose( self.span, - rustc_errors::fluent::suggestion, + fluent::passes_suggestion, replacement, rustc_errors::Applicability::MachineApplicable, ); @@ -917,17 +926,17 @@ impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> { ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { let mut diag = handler.struct_span_err_with_code( self.span, - rustc_errors::fluent::passes_break_non_loop, + fluent::passes_break_non_loop, error_code!(E0571), ); diag.set_arg("kind", self.kind); - diag.span_label(self.span, rustc_errors::fluent::label); + diag.span_label(self.span, fluent::passes_label); if let Some(head) = self.head { - diag.span_label(head, rustc_errors::fluent::label2); + diag.span_label(head, fluent::passes_label2); } diag.span_suggestion( self.span, - rustc_errors::fluent::suggestion, + fluent::passes_suggestion, self.suggestion, Applicability::MaybeIncorrect, ); @@ -945,7 +954,7 @@ impl<'a> IntoDiagnostic<'_> for BreakNonLoop<'a> { _ => { diag.span_suggestion( self.break_expr_span, - rustc_errors::fluent::break_expr_suggestion, + fluent::passes_break_expr_suggestion, label.ident, Applicability::MaybeIncorrect, ); @@ -962,7 +971,7 @@ pub struct ContinueLabeledBlock { #[primary_span] #[label] pub span: Span, - #[label(block_label)] + #[label(passes_block_label)] pub block_span: Span, } @@ -972,7 +981,7 @@ pub struct BreakInsideClosure<'a> { #[primary_span] #[label] pub span: Span, - #[label(closure_label)] + #[label(passes_closure_label)] pub closure_span: Span, pub name: &'a str, } @@ -983,7 +992,7 @@ pub struct BreakInsideAsyncBlock<'a> { #[primary_span] #[label] pub span: Span, - #[label(async_block_label)] + #[label(passes_async_block_label)] pub closure_span: Span, pub name: &'a str, } @@ -1056,14 +1065,14 @@ impl IntoDiagnostic<'_> for NakedFunctionsAsmBlock { ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { let mut diag = handler.struct_span_err_with_code( self.span, - rustc_errors::fluent::passes_naked_functions_asm_block, + fluent::passes_naked_functions_asm_block, error_code!(E0787), ); for span in self.multiple_asms.iter() { - diag.span_label(*span, rustc_errors::fluent::label_multiple_asm); + diag.span_label(*span, fluent::passes_label_multiple_asm); } for span in self.non_asms.iter() { - diag.span_label(*span, rustc_errors::fluent::label_non_asm); + diag.span_label(*span, fluent::passes_label_non_asm); } diag } @@ -1122,9 +1131,9 @@ pub struct AttrOnlyInFunctions { pub struct MultipleRustcMain { #[primary_span] pub span: Span, - #[label(first)] + #[label(passes_first)] pub first: Span, - #[label(additional)] + #[label(passes_additional)] pub additional: Span, } @@ -1135,7 +1144,7 @@ pub struct MultipleStartFunctions { pub span: Span, #[label] pub labeled: Span, - #[label(previous)] + #[label(passes_previous)] pub previous: Span, } @@ -1180,7 +1189,7 @@ impl<'a> IntoDiagnostic<'a> for NoMainErr { ) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> { let mut diag = handler.struct_span_err_with_code( DUMMY_SP, - rustc_errors::fluent::passes_no_main_function, + fluent::passes_no_main_function, error_code!(E0601), ); diag.set_arg("crate_name", self.crate_name); @@ -1188,16 +1197,16 @@ impl<'a> IntoDiagnostic<'a> for NoMainErr { diag.set_arg("has_filename", self.has_filename); let note = if !self.non_main_fns.is_empty() { for &span in &self.non_main_fns { - diag.span_note(span, rustc_errors::fluent::here_is_main); + diag.span_note(span, fluent::passes_here_is_main); } - diag.note(rustc_errors::fluent::one_or_more_possible_main); - diag.help(rustc_errors::fluent::consider_moving_main); + diag.note(fluent::passes_one_or_more_possible_main); + diag.help(fluent::passes_consider_moving_main); // There were some functions named `main` though. Try to give the user a hint. - rustc_errors::fluent::main_must_be_defined_at_crate + fluent::passes_main_must_be_defined_at_crate } else if self.has_filename { - rustc_errors::fluent::consider_adding_main_to_file + fluent::passes_consider_adding_main_to_file } else { - rustc_errors::fluent::consider_adding_main_at_crate + fluent::passes_consider_adding_main_at_crate }; if self.file_empty { diag.note(note); @@ -1208,11 +1217,11 @@ impl<'a> IntoDiagnostic<'a> for NoMainErr { if let Some(main_def) = self.main_def_opt && main_def.opt_fn_def_id().is_none(){ // There is something at `crate::main`, but it is not a function definition. - diag.span_label(main_def.span, rustc_errors::fluent::non_function_main); + diag.span_label(main_def.span, fluent::passes_non_function_main); } if self.add_teach_note { - diag.note(rustc_errors::fluent::teach_note); + diag.note(fluent::passes_teach_note); } diag } @@ -1241,12 +1250,9 @@ impl IntoDiagnostic<'_> for DuplicateLangItem { ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { let mut diag = handler.struct_err_with_code( match self.duplicate { - Duplicate::Plain => rustc_errors::fluent::passes_duplicate_lang_item, - - Duplicate::Crate => rustc_errors::fluent::passes_duplicate_lang_item_crate, - Duplicate::CrateDepends => { - rustc_errors::fluent::passes_duplicate_lang_item_crate_depends - } + Duplicate::Plain => fluent::passes_duplicate_lang_item, + Duplicate::Crate => fluent::passes_duplicate_lang_item_crate, + Duplicate::CrateDepends => fluent::passes_duplicate_lang_item_crate_depends, }, error_code!(E0152), ); @@ -1261,24 +1267,24 @@ impl IntoDiagnostic<'_> for DuplicateLangItem { diag.set_span(span); } if let Some(span) = self.first_defined_span { - diag.span_note(span, rustc_errors::fluent::first_defined_span); + diag.span_note(span, fluent::passes_first_defined_span); } else { if self.orig_dependency_of.is_empty() { - diag.note(rustc_errors::fluent::first_defined_crate); + diag.note(fluent::passes_first_defined_crate); } else { - diag.note(rustc_errors::fluent::first_defined_crate_depends); + diag.note(fluent::passes_first_defined_crate_depends); } if self.orig_is_local { - diag.note(rustc_errors::fluent::first_definition_local); + diag.note(fluent::passes_first_definition_local); } else { - diag.note(rustc_errors::fluent::first_definition_path); + diag.note(fluent::passes_first_definition_path); } if self.is_local { - diag.note(rustc_errors::fluent::second_definition_local); + diag.note(fluent::passes_second_definition_local); } else { - diag.note(rustc_errors::fluent::second_definition_path); + diag.note(fluent::passes_second_definition_path); } } diag @@ -1389,7 +1395,7 @@ pub struct UselessStability { #[primary_span] #[label] pub span: Span, - #[label(item)] + #[label(passes_item)] pub item_sp: Span, } @@ -1399,7 +1405,7 @@ pub struct InvalidStability { #[primary_span] #[label] pub span: Span, - #[label(item)] + #[label(passes_item)] pub item_sp: Span, } @@ -1409,7 +1415,7 @@ pub struct CannotStabilizeDeprecated { #[primary_span] #[label] pub span: Span, - #[label(item)] + #[label(passes_item)] pub item_sp: Span, } @@ -1419,7 +1425,7 @@ pub struct InvalidDeprecationVersion { #[primary_span] #[label] pub span: Span, - #[label(item)] + #[label(passes_item)] pub item_sp: Span, } diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs index 6e621b7eb5e..0cb8424082c 100644 --- a/compiler/rustc_passes/src/lib.rs +++ b/compiler/rustc_passes/src/lib.rs @@ -18,6 +18,8 @@ extern crate rustc_middle; #[macro_use] extern crate tracing; +use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_macros::fluent_messages; use rustc_middle::ty::query::Providers; mod check_attr; @@ -40,6 +42,8 @@ pub mod stability; mod upvars; mod weak_lang_items; +fluent_messages! { "../locales/en-US.ftl" } + pub fn provide(providers: &mut Providers) { check_attr::provide(providers); check_const::provide(providers); diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 678f1815d01..df5c8f53ec1 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -475,7 +475,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { | hir::ExprKind::InlineAsm(..) | hir::ExprKind::Box(..) | hir::ExprKind::Type(..) - | hir::ExprKind::Err + | hir::ExprKind::Err(_) | hir::ExprKind::Path(hir::QPath::TypeRelative(..)) | hir::ExprKind::Path(hir::QPath::LangItem(..)) => { intravisit::walk_expr(self, expr); @@ -1129,7 +1129,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { hir::ExprKind::Lit(..) | hir::ExprKind::ConstBlock(..) - | hir::ExprKind::Err + | hir::ExprKind::Err(_) | hir::ExprKind::Path(hir::QPath::TypeRelative(..)) | hir::ExprKind::Path(hir::QPath::LangItem(..)) => succ, @@ -1427,7 +1427,7 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr<'tcx>) { | hir::ExprKind::Yield(..) | hir::ExprKind::Box(..) | hir::ExprKind::Type(..) - | hir::ExprKind::Err => {} + | hir::ExprKind::Err(_) => {} } } diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index acc54e7e110..c5b5cf7f5a9 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -219,7 +219,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> { hir::intravisit::walk_expr(self, expr); } - ExprKind::Err => { + ExprKind::Err(_) => { self.items.push((ItemKind::Err, span)); } } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 2e736039fb5..16194a6f196 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -523,7 +523,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && stab.is_none() && self.effective_visibilities.is_reachable(def_id) { - let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id()); + let descr = self.tcx.def_descr(def_id.to_def_id()); self.tcx.sess.emit_err(errors::MissingStabilityAttr { span, descr }); } } @@ -551,7 +551,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { let is_reachable = self.effective_visibilities.is_reachable(def_id); if is_const && is_stable && missing_const_stability_attribute && is_reachable { - let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id()); + let descr = self.tcx.def_descr(def_id.to_def_id()); self.tcx.sess.emit_err(errors::MissingConstStabAttr { span, descr }); } } @@ -748,7 +748,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { let mut c = CheckTraitImplStable { tcx: self.tcx, fully_stable: true }; c.visit_ty(self_ty); c.visit_trait_ref(t); - if c.fully_stable { + + // do not lint when the trait isn't resolved, since resolution error should + // be fixed first + if t.path.res != Res::Err && c.fully_stable { self.tcx.struct_span_lint_hir( INEFFECTIVE_UNSTABLE_TRAIT_IMPL, item.hir_id(), |
