From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_passes/src/check_attr.rs | 15 ++++++++-- compiler/rustc_passes/src/dead.rs | 19 +++++------- compiler/rustc_passes/src/debugger_visualizer.rs | 6 ++-- compiler/rustc_passes/src/diagnostic_items.rs | 10 ++----- compiler/rustc_passes/src/entry.rs | 2 +- compiler/rustc_passes/src/errors.rs | 7 +++++ compiler/rustc_passes/src/hir_stats.rs | 8 ++--- compiler/rustc_passes/src/lang_items.rs | 2 -- compiler/rustc_passes/src/layout_test.rs | 2 +- compiler/rustc_passes/src/lib_features.rs | 6 ++++ compiler/rustc_passes/src/liveness.rs | 38 +++++++++++------------- compiler/rustc_passes/src/reachable.rs | 4 +-- compiler/rustc_passes/src/stability.rs | 4 +-- compiler/rustc_passes/src/weak_lang_items.rs | 4 +-- 14 files changed, 68 insertions(+), 59 deletions(-) (limited to 'compiler/rustc_passes') diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 2e2874dbc..f9f9799d3 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -82,6 +82,7 @@ impl CheckAttrVisitor<'_> { let attrs = self.tcx.hir().attrs(hir_id); for attr in attrs { let attr_is_valid = match attr.name_or_empty() { + sym::do_not_recommend => self.check_do_not_recommend(attr.span, target), sym::inline => self.check_inline(hir_id, attr, span, target), sym::no_coverage => self.check_no_coverage(hir_id, attr, span, target), sym::non_exhaustive => self.check_non_exhaustive(hir_id, attr, span, target), @@ -241,6 +242,16 @@ impl CheckAttrVisitor<'_> { ); } + /// Checks if `#[do_not_recommend]` is applied on a trait impl. + fn check_do_not_recommend(&self, attr_span: Span, target: Target) -> bool { + if let Target::Impl = target { + true + } else { + self.tcx.sess.emit_err(errors::IncorrectDoNotRecommendLocation { span: attr_span }); + false + } + } + /// Checks if an `#[inline]` is applied to a function or a closure. Returns `true` if valid. fn check_inline(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool { match target { @@ -1090,9 +1101,7 @@ impl CheckAttrVisitor<'_> { errors::DocTestUnknownInclude { path, value: value.to_string(), - inner: (attr.style == AttrStyle::Inner) - .then_some("!") - .unwrap_or(""), + inner: if attr.style == AttrStyle::Inner { "!" } else { "" }, sugg: (attr.meta().unwrap().span, applicability), } ); diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index a71ae717a..94171b4b0 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -266,7 +266,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of) && self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads) { - let trait_ref = self.tcx.impl_trait_ref(impl_of).unwrap(); + let trait_ref = self.tcx.impl_trait_ref(impl_of).unwrap().subst_identity(); if let ty::Adt(adt_def, _) = trait_ref.self_ty().kind() && let Some(adt_def_id) = adt_def.did().as_local() { @@ -571,7 +571,7 @@ fn check_item<'tcx>( } } -fn check_trait_item<'tcx>(tcx: TyCtxt<'tcx>, worklist: &mut Vec, id: hir::TraitItemId) { +fn check_trait_item(tcx: TyCtxt<'_>, worklist: &mut Vec, id: hir::TraitItemId) { use hir::TraitItemKind::{Const, Fn}; if matches!(tcx.def_kind(id.owner_id), DefKind::AssocConst | DefKind::AssocFn) { let trait_item = tcx.hir().trait_item(id); @@ -583,11 +583,7 @@ fn check_trait_item<'tcx>(tcx: TyCtxt<'tcx>, worklist: &mut Vec, id: } } -fn check_foreign_item<'tcx>( - tcx: TyCtxt<'tcx>, - worklist: &mut Vec, - id: hir::ForeignItemId, -) { +fn check_foreign_item(tcx: TyCtxt<'_>, worklist: &mut Vec, id: hir::ForeignItemId) { if matches!(tcx.def_kind(id.owner_id), DefKind::Static(_) | DefKind::Fn) && has_allow_dead_code_or_lang_attr(tcx, id.hir_id()) { @@ -595,8 +591,8 @@ fn check_foreign_item<'tcx>( } } -fn create_and_seed_worklist<'tcx>( - tcx: TyCtxt<'tcx>, +fn create_and_seed_worklist( + tcx: TyCtxt<'_>, ) -> (Vec, FxHashMap) { let effective_visibilities = &tcx.effective_visibilities(()); // see `MarkSymbolVisitor::struct_constructors` @@ -626,8 +622,8 @@ fn create_and_seed_worklist<'tcx>( (worklist, struct_constructors) } -fn live_symbols_and_ignored_derived_traits<'tcx>( - tcx: TyCtxt<'tcx>, +fn live_symbols_and_ignored_derived_traits( + tcx: TyCtxt<'_>, (): (), ) -> (FxHashSet, FxHashMap>) { let (worklist, struct_constructors) = create_and_seed_worklist(tcx); @@ -787,7 +783,6 @@ impl<'tcx> DeadVisitor<'tcx> { let mut dead_codes = dead_codes .iter() .filter(|v| !v.name.as_str().starts_with('_')) - .map(|v| v) .collect::>(); if dead_codes.is_empty() { return; diff --git a/compiler/rustc_passes/src/debugger_visualizer.rs b/compiler/rustc_passes/src/debugger_visualizer.rs index 253b0a88e..aeacbaa67 100644 --- a/compiler/rustc_passes/src/debugger_visualizer.rs +++ b/compiler/rustc_passes/src/debugger_visualizer.rs @@ -15,8 +15,8 @@ use std::sync::Arc; use crate::errors::DebugVisualizerUnreadable; -fn check_for_debugger_visualizer<'tcx>( - tcx: TyCtxt<'tcx>, +fn check_for_debugger_visualizer( + tcx: TyCtxt<'_>, hir_id: HirId, debugger_visualizers: &mut FxHashSet, ) { @@ -69,7 +69,7 @@ fn check_for_debugger_visualizer<'tcx>( } /// Traverses and collects the debugger visualizers for a specific crate. -fn debugger_visualizers<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> Vec { +fn debugger_visualizers(tcx: TyCtxt<'_>, cnum: CrateNum) -> Vec { assert_eq!(cnum, LOCAL_CRATE); // Initialize the collector. diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index a72056e00..10ffa87ef 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -18,11 +18,7 @@ use rustc_span::symbol::{kw::Empty, sym, Symbol}; use crate::errors::{DuplicateDiagnosticItem, DuplicateDiagnosticItemInCrate}; -fn observe_item<'tcx>( - tcx: TyCtxt<'tcx>, - diagnostic_items: &mut DiagnosticItems, - def_id: LocalDefId, -) { +fn observe_item(tcx: TyCtxt<'_>, diagnostic_items: &mut DiagnosticItems, def_id: LocalDefId) { let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let attrs = tcx.hir().attrs(hir_id); if let Some(name) = extract(attrs) { @@ -63,7 +59,7 @@ fn extract(attrs: &[ast::Attribute]) -> Option { } /// Traverse and collect the diagnostic items in the current -fn diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> DiagnosticItems { +fn diagnostic_items(tcx: TyCtxt<'_>, cnum: CrateNum) -> DiagnosticItems { assert_eq!(cnum, LOCAL_CRATE); // Initialize the collector. @@ -92,7 +88,7 @@ fn diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> DiagnosticItems } /// Traverse and collect all the diagnostic items in all crates. -fn all_diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> DiagnosticItems { +fn all_diagnostic_items(tcx: TyCtxt<'_>, (): ()) -> DiagnosticItems { // Initialize the collector. let mut items = DiagnosticItems::default(); diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 5885f45ae..b327ba633 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -195,7 +195,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) { // There is no main function. let mut has_filename = true; - let filename = tcx.sess.local_crate_source_file.clone().unwrap_or_else(|| { + let filename = tcx.sess.local_crate_source_file().unwrap_or_else(|| { has_filename = false; Default::default() }); diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index c6cd69add..9c6519ea4 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -14,6 +14,13 @@ use rustc_span::{Span, Symbol, DUMMY_SP}; use crate::lang_items::Duplicate; +#[derive(Diagnostic)] +#[diag(passes_incorrect_do_not_recommend_location)] +pub struct IncorrectDoNotRecommendLocation { + #[primary_span] + pub span: Span, +} + #[derive(LintDiagnostic)] #[diag(passes_outer_crate_level_attr)] pub struct OuterCrateLevelAttr; diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index a7854cd49..b86d23168 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -121,7 +121,7 @@ impl<'k> StatCollector<'k> { fn print(&self, title: &str, prefix: &str) { let mut nodes: Vec<_> = self.nodes.iter().collect(); - nodes.sort_by_key(|&(_, ref node)| node.stats.count * node.stats.size); + nodes.sort_by_key(|(_, node)| node.stats.count * node.stats.size); let total_size = nodes.iter().map(|(_, node)| node.stats.count * node.stats.size).sum(); @@ -147,7 +147,7 @@ impl<'k> StatCollector<'k> { ); if !node.subnodes.is_empty() { let mut subnodes: Vec<_> = node.subnodes.iter().collect(); - subnodes.sort_by_key(|&(_, ref subnode)| subnode.count * subnode.size); + subnodes.sort_by_key(|(_, subnode)| subnode.count * subnode.size); for (label, subnode) in subnodes { let size = subnode.count * subnode.size; @@ -324,7 +324,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { Slice, Array, Ptr, - Rptr, + Ref, BareFn, Never, Tup, @@ -580,7 +580,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { Slice, Array, Ptr, - Rptr, + Ref, BareFn, Never, Tup, diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 99efed0b7..9a40b847d 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -83,7 +83,6 @@ impl<'tcx> LanguageItemCollector<'tcx> { .map(|p| p.display().to_string()) .collect::>() .join(", ") - .into() }; let first_defined_span = self.tcx.hir().span_if_local(original_def_id); let mut orig_crate_name = Empty; @@ -98,7 +97,6 @@ impl<'tcx> LanguageItemCollector<'tcx> { .map(|p| p.display().to_string()) .collect::>() .join(", ") - .into() }; if first_defined_span.is_none() { orig_crate_name = self.tcx.crate_name(original_def_id.krate); diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index 5322baee7..827d86780 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -26,7 +26,7 @@ pub fn test_layout(tcx: TyCtxt<'_>) { } } -fn dump_layout_of<'tcx>(tcx: TyCtxt<'tcx>, item_def_id: LocalDefId, attr: &Attribute) { +fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) { let tcx = tcx; let param_env = tcx.param_env(item_def_id); let ty = tcx.type_of(item_def_id); diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index b5843c0ae..4c6a9b23f 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -137,6 +137,12 @@ impl<'tcx> Visitor<'tcx> for LibFeatureCollector<'tcx> { } fn lib_features(tcx: TyCtxt<'_>, (): ()) -> LibFeatures { + // If `staged_api` is not enabled then we aren't allowed to define lib + // features; there is no point collecting them. + if !tcx.features().staged_api { + return new_lib_features(); + } + let mut collector = LibFeatureCollector::new(tcx); tcx.hir().walk_attributes(&mut collector); collector.lib_features diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 1f65cc8b6..6afdcc37f 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -108,15 +108,13 @@ use std::rc::Rc; mod rwu_table; rustc_index::newtype_index! { - pub struct Variable { - DEBUG_FORMAT = "v({})", - } + #[debug_format = "v({})"] + pub struct Variable {} } rustc_index::newtype_index! { - pub struct LiveNode { - DEBUG_FORMAT = "ln({})", - } + #[debug_format = "ln({})"] + pub struct LiveNode {} } #[derive(Copy, Clone, PartialEq, Debug)] @@ -193,9 +191,9 @@ pub fn provide(providers: &mut Providers) { // Creating ir_maps // // This is the first pass and the one that drives the main -// computation. It walks up and down the IR once. On the way down, +// computation. It walks up and down the IR once. On the way down, // we count for each function the number of variables as well as -// liveness nodes. A liveness node is basically an expression or +// liveness nodes. A liveness node is basically an expression or // capture clause that does something of interest: either it has // interesting control flow or it uses/defines a local variable. // @@ -205,11 +203,11 @@ pub fn provide(providers: &mut Providers) { // of live variables at each program point. // // Finally, we run back over the IR one last time and, using the -// computed liveness, check various safety conditions. For example, +// computed liveness, check various safety conditions. For example, // there must be no live nodes at the definition site for a variable -// unless it has an initializer. Similarly, each non-mutable local +// unless it has an initializer. Similarly, each non-mutable local // variable must not be assigned if there is some successor -// assignment. And so forth. +// assignment. And so forth. struct CaptureInfo { ln: LiveNode, @@ -419,7 +417,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id)); // Make a live_node for each mentioned variable, with the span - // being the location that the variable is used. This results + // being the location that the variable is used. This results // in better error messages than just pointing at the closure // construction site. let mut call_caps = Vec::new(); @@ -794,7 +792,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { match stmt.kind { hir::StmtKind::Local(ref local) => { // Note: we mark the variable as defined regardless of whether - // there is an initializer. Initially I had thought to only mark + // there is an initializer. Initially I had thought to only mark // the live variable as defined if it was initialized, and then we // could check for uninit variables just by scanning what is live // at the start of the function. But that doesn't work so well for @@ -1171,24 +1169,24 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // // # Tracked places // - // A tracked place is a local variable/argument `x`. In + // A tracked place is a local variable/argument `x`. In // these cases, the link_node where the write occurs is linked - // to node id of `x`. The `write_place()` routine generates - // the contents of this node. There are no subcomponents to + // to node id of `x`. The `write_place()` routine generates + // the contents of this node. There are no subcomponents to // consider. // // # Non-tracked places // - // These are places like `x[5]` or `x.f`. In that case, we + // These are places like `x[5]` or `x.f`. In that case, we // basically ignore the value which is written to but generate - // reads for the components---`x` in these two examples. The + // reads for the components---`x` in these two examples. The // components reads are generated by // `propagate_through_place_components()` (this fn). // // # Illegal places // // It is still possible to observe assignments to non-places; - // these errors are detected in the later pass borrowck. We + // these errors are detected in the later pass borrowck. We // just ignore such cases and treat them as reads. match expr.kind { @@ -1206,7 +1204,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } // We do not track other places, so just propagate through - // to their subcomponents. Also, it may happen that + // to their subcomponents. Also, it may happen that // non-places occur here, because those are detected in the // later pass borrowck. _ => succ, diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index e7c3c7128..ad0952203 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -347,7 +347,7 @@ fn check_item<'tcx>( } } -fn has_custom_linkage<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> bool { +fn has_custom_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { // Anything which has custom linkage gets thrown on the worklist no // matter where it is in the crate, along with "special std symbols" // which are currently akin to allocator symbols. @@ -364,7 +364,7 @@ fn has_custom_linkage<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> bool { || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) } -fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet { +fn reachable_set(tcx: TyCtxt<'_>, (): ()) -> FxHashSet { let effective_visibilities = &tcx.effective_visibilities(()); let any_library = diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index da7155234..34e1abb78 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -147,7 +147,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { } if !self.tcx.features().staged_api { - // Propagate unstability. This can happen even for non-staged-api crates in case + // Propagate unstability. This can happen even for non-staged-api crates in case // -Zforce-unstable-if-unmarked is set. if let Some(stab) = self.parent_stab { if inherit_deprecation.yes() && stab.is_unstable() { @@ -853,7 +853,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { /// Check whether a path is a `use` item that has been marked as unstable. /// /// See issue #94972 for details on why this is a special case -fn is_unstable_reexport<'tcx>(tcx: TyCtxt<'tcx>, id: hir::HirId) -> bool { +fn is_unstable_reexport(tcx: TyCtxt<'_>, id: hir::HirId) -> bool { // Get the LocalDefId so we can lookup the item to check the kind. let Some(def_id) = tcx.hir().opt_local_def_id(id) else { return false; }; diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs index f0815fcd8..fc6372cf9 100644 --- a/compiler/rustc_passes/src/weak_lang_items.rs +++ b/compiler/rustc_passes/src/weak_lang_items.rs @@ -11,7 +11,7 @@ use crate::errors::{MissingLangItem, MissingPanicHandler, UnknownExternLangItem} /// Checks the crate for usage of weak lang items, returning a vector of all the /// language items required by this crate, but not defined yet. -pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItems) { +pub fn check_crate(tcx: TyCtxt<'_>, items: &mut lang_items::LanguageItems) { // These are never called by user code, they're generated by the compiler. // They will never implicitly be added to the `missing` array unless we do // so here. @@ -40,7 +40,7 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItem verify(tcx, items); } -fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) { +fn verify(tcx: TyCtxt<'_>, items: &lang_items::LanguageItems) { // We only need to check for the presence of weak lang items if we're // emitting something that's not an rlib. let needs_check = tcx.sess.crate_types().iter().any(|kind| match *kind { -- cgit v1.2.3