diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index 1d634c03255ea..ce00d5f81313c 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -815,13 +815,13 @@ impl<'hir> LoweringContext<'_, 'hir> { } } -struct SelfResolver<'a> { - resolver: &'a mut ResolverAstLowering, +struct SelfResolver<'a, 'tcx> { + resolver: &'a mut ResolverAstLowering<'tcx>, path_id: NodeId, self_param_id: NodeId, } -impl<'a> SelfResolver<'a> { +impl SelfResolver<'_, '_> { fn try_replace_id(&mut self, id: NodeId) { if let Some(res) = self.resolver.partial_res_map.get(&id) && let Some(Res::Local(sig_id)) = res.full_res() @@ -833,7 +833,7 @@ impl<'a> SelfResolver<'a> { } } -impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a> { +impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a, '_> { fn visit_id(&mut self, id: NodeId) { self.try_replace_id(id); } diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index c17eb7c633d1b..ed78b77a704f6 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -27,7 +27,7 @@ use super::{ pub(super) struct ItemLowerer<'a, 'hir> { pub(super) tcx: TyCtxt<'hir>, - pub(super) resolver: &'a mut ResolverAstLowering, + pub(super) resolver: &'a mut ResolverAstLowering<'hir>, pub(super) ast_index: &'a IndexSlice>, pub(super) owners: &'a mut IndexVec>, } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 5c293b82a4209..0086525ef624d 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir> { // will be in AST index. ast_index: &'a IndexSlice>, - resolver: &'a mut ResolverAstLowering, + resolver: &'a mut ResolverAstLowering<'hir>, disambiguator: DisambiguatorState, /// Used to allocate HIR nodes. @@ -133,7 +133,7 @@ struct LoweringContext<'a, 'hir> { current_hir_id_owner: hir::OwnerId, item_local_id_counter: hir::ItemLocalId, - trait_map: ItemLocalMap>, + trait_map: ItemLocalMap<&'hir [TraitCandidate<'hir>]>, impl_trait_defs: Vec>, impl_trait_bounds: Vec>, @@ -162,7 +162,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn new( tcx: TyCtxt<'hir>, ast_index: &'a IndexSlice>, - resolver: &'a mut ResolverAstLowering, + resolver: &'a mut ResolverAstLowering<'hir>, ) -> Self { let registered_tools = tcx.registered_tools(()).iter().map(|x| x.name).collect(); Self { @@ -248,7 +248,7 @@ impl SpanLowerer { } #[extension(trait ResolverAstLoweringExt)] -impl ResolverAstLowering { +impl ResolverAstLowering<'_> { fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'_>) -> Option> { let ExprKind::Path(None, path) = &expr.kind else { return None; @@ -748,8 +748,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id))); } - if let Some(traits) = self.resolver.trait_map.remove(&ast_node_id) { - self.trait_map.insert(hir_id.local_id, traits.into_boxed_slice()); + if let Some(&traits) = self.resolver.trait_map.get(&ast_node_id) { + self.trait_map.insert(hir_id.local_id, traits); } // Check whether the same `NodeId` is lowered more than once. diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 949aff7d6600a..45a363b97722a 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1633,7 +1633,7 @@ pub struct OwnerInfo<'hir> { pub attrs: AttributeMap<'hir>, /// Map indicating what traits are in scope for places where this /// is relevant; generated by resolve. - pub trait_map: ItemLocalMap>, + pub trait_map: ItemLocalMap<&'hir [TraitCandidate<'hir>]>, /// Lints delayed during ast lowering to be emitted /// after hir has completely built @@ -4683,10 +4683,10 @@ pub struct Upvar { // The TraitCandidate's import_ids is empty if the trait is defined in the same module, and // has length > 0 if the trait is found through an chain of imports, starting with the // import/use statement in the scope where the trait is used. -#[derive(Debug, Clone, HashStable_Generic)] -pub struct TraitCandidate { +#[derive(Debug, Clone, Copy, HashStable_Generic)] +pub struct TraitCandidate<'hir> { pub def_id: DefId, - pub import_ids: SmallVec<[LocalDefId; 1]>, + pub import_ids: &'hir [LocalDefId], // Indicates whether this trait candidate is ambiguously glob imported // in it's scope. Related to the AMBIGUOUS_GLOB_IMPORTED_TRAITS lint. // If this is set to true and the trait is used as a result of method lookup, this diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index e5abcd34ad1fe..0d49e06240532 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -1008,7 +1008,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); let container_id = pick.item.container_id(self.tcx); let container = with_no_trimmed_paths!(self.tcx.def_path_str(container_id)); - for def_id in pick.import_ids { + for &def_id in pick.import_ids { let hir_id = self.tcx.local_def_id_to_hir_id(def_id); path_span .push_span_label(self.tcx.hir_span(hir_id), format!("`{container}` imported here")); diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index 746678e2865f8..083e29bff04f7 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -196,7 +196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // NOTE: on the failure path, we also record the possibly-used trait methods // since an unused import warning is kinda distracting from the method error. - for &import_id in &pick.import_ids { + for &import_id in pick.import_ids { debug!("used_trait_import: {:?}", import_id); self.typeck_results.borrow_mut().used_trait_imports.insert(import_id); } @@ -554,7 +554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!(?pick); { let mut typeck_results = self.typeck_results.borrow_mut(); - for import_id in pick.import_ids { + for &import_id in pick.import_ids { debug!(used_trait_import=?import_id); typeck_results.used_trait_imports.insert(import_id); } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 8d92ee03ff472..7f82d5df148f2 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -36,7 +36,7 @@ use rustc_trait_selection::traits::query::method_autoderef::{ CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult, }; use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt}; -use smallvec::{SmallVec, smallvec}; +use smallvec::SmallVec; use tracing::{debug, instrument}; use self::CandidateKind::*; @@ -99,7 +99,7 @@ impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> { pub(crate) struct Candidate<'tcx> { pub(crate) item: ty::AssocItem, pub(crate) kind: CandidateKind<'tcx>, - pub(crate) import_ids: SmallVec<[LocalDefId; 1]>, + pub(crate) import_ids: &'tcx [LocalDefId], } #[derive(Debug, Clone)] @@ -206,7 +206,7 @@ impl PickConstraintsForShadowed { pub(crate) struct Pick<'tcx> { pub item: ty::AssocItem, pub kind: PickKind<'tcx>, - pub import_ids: SmallVec<[LocalDefId; 1]>, + pub import_ids: &'tcx [LocalDefId], /// Indicates that the source expression should be autoderef'd N times /// ```ignore (not-rust) @@ -574,7 +574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Binder::dummy(trait_ref), false, ), - import_ids: smallvec![], + import_ids: &[], }, false, ); @@ -946,7 +946,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { Candidate { item, kind: InherentImplCandidate { impl_def_id, receiver_steps }, - import_ids: smallvec![], + import_ids: &[], }, true, ); @@ -979,11 +979,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { traits::supertraits(self.tcx, trait_ref), |this, new_trait_ref, item| { this.push_candidate( - Candidate { - item, - kind: ObjectCandidate(new_trait_ref), - import_ids: smallvec![], - }, + Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: &[] }, true, ); }, @@ -1018,11 +1014,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| { this.push_candidate( - Candidate { - item, - kind: WhereClauseCandidate(poly_trait_ref), - import_ids: smallvec![], - }, + Candidate { item, kind: WhereClauseCandidate(poly_trait_ref), import_ids: &[] }, true, ); }); @@ -1072,11 +1064,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let mut duplicates = FxHashSet::default(); for trait_info in suggest::all_traits(self.tcx) { if duplicates.insert(trait_info.def_id) { - self.assemble_extension_candidates_for_trait( - &smallvec![], - trait_info.def_id, - false, - ); + self.assemble_extension_candidates_for_trait(&[], trait_info.def_id, false); } } } @@ -1100,7 +1088,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { #[instrument(level = "debug", skip(self))] fn assemble_extension_candidates_for_trait( &mut self, - import_ids: &SmallVec<[LocalDefId; 1]>, + import_ids: &'tcx [LocalDefId], trait_def_id: DefId, lint_ambiguous: bool, ) { @@ -1123,7 +1111,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { self.push_candidate( Candidate { item, - import_ids: import_ids.clone(), + import_ids, kind: TraitCandidate(bound_trait_ref, lint_ambiguous), }, false, @@ -1146,7 +1134,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { self.push_candidate( Candidate { item, - import_ids: import_ids.clone(), + import_ids, kind: TraitCandidate(ty::Binder::dummy(trait_ref), lint_ambiguous), }, false, @@ -2353,7 +2341,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { Some(Pick { item: probes[0].0.item, kind: TraitPick(lint_ambiguous), - import_ids: probes[0].0.import_ids.clone(), + import_ids: probes[0].0.import_ids, autoderefs: 0, autoref_or_ptr_adjustment: None, self_ty, @@ -2430,7 +2418,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { Some(Pick { item: child_candidate.item, kind: TraitPick(lint_ambiguous), - import_ids: child_candidate.import_ids.clone(), + import_ids: child_candidate.import_ids, autoderefs: 0, autoref_or_ptr_adjustment: None, self_ty, @@ -2707,7 +2695,7 @@ impl<'tcx> Candidate<'tcx> { WhereClausePick(trait_ref) } }, - import_ids: self.import_ids.clone(), + import_ids: self.import_ids, autoderefs: 0, autoref_or_ptr_adjustment: None, self_ty, diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 77f7053689d27..1fe82bc7ff6b8 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -199,7 +199,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // NOTE: Reporting a method error should also suppress any unused trait errors, // since the method error is very possibly the reason why the trait wasn't used. for &import_id in - self.tcx.in_scope_traits(call_id).into_iter().flatten().flat_map(|c| &c.import_ids) + self.tcx.in_scope_traits(call_id).into_iter().flatten().flat_map(|c| c.import_ids) { self.typeck_results.borrow_mut().used_trait_imports.insert(import_id); } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index cdfe80e1fe963..a280b2a2a6bf7 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -781,7 +781,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P fn resolver_for_lowering_raw<'tcx>( tcx: TyCtxt<'tcx>, (): (), -) -> (&'tcx Steal<(ty::ResolverAstLowering, Arc)>, &'tcx ty::ResolverGlobalCtxt) { +) -> (&'tcx Steal<(ty::ResolverAstLowering<'tcx>, Arc)>, &'tcx ty::ResolverGlobalCtxt) { let arenas = Resolver::arenas(); let _ = tcx.registered_tools(()); // Uses `crate_for_resolver`. let (krate, pre_configured_attrs) = tcx.crate_for_resolver(()).steal(); diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 640e6f9838510..33237ef840415 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -32,7 +32,7 @@ macro_rules! arena_types { rustc_middle::ty::DefinitionSiteHiddenType<'tcx>, >, [] resolver: rustc_data_structures::steal::Steal<( - rustc_middle::ty::ResolverAstLowering, + rustc_middle::ty::ResolverAstLowering<'tcx>, std::sync::Arc, )>, [] crate_for_resolver: rustc_data_structures::steal::Steal<(rustc_ast::Crate, rustc_ast::AttrVec)>, diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index db98d6cf5ae5b..5d80e0febfb84 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -199,7 +199,7 @@ rustc_queries! { desc { "getting the resolver outputs" } } - query resolver_for_lowering_raw(_: ()) -> (&'tcx Steal<(ty::ResolverAstLowering, Arc)>, &'tcx ty::ResolverGlobalCtxt) { + query resolver_for_lowering_raw(_: ()) -> (&'tcx Steal<(ty::ResolverAstLowering<'tcx>, Arc)>, &'tcx ty::ResolverGlobalCtxt) { eval_always no_hash desc { "getting the resolver for lowering" } @@ -1910,7 +1910,7 @@ rustc_queries! { desc { "computing whether impls specialize one another" } } query in_scope_traits_map(_: hir::OwnerId) - -> Option<&'tcx ItemLocalMap>> { + -> Option<&'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>> { desc { "getting traits in scope at a block" } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 8f94fc921563d..f35ad4b9bc9a2 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2614,7 +2614,7 @@ impl<'tcx> TyCtxt<'tcx> { lint_level(self.sess, lint, level, None, decorate); } - pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate]> { + pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate<'tcx>]> { let map = self.in_scope_traits_map(id.owner)?; let candidates = map.get(&id.local_id)?; Some(candidates) @@ -2777,7 +2777,9 @@ impl<'tcx> TyCtxt<'tcx> { self.resolutions(()).extern_crate_map.get(&def_id).copied() } - pub fn resolver_for_lowering(self) -> &'tcx Steal<(ty::ResolverAstLowering, Arc)> { + pub fn resolver_for_lowering( + self, + ) -> &'tcx Steal<(ty::ResolverAstLowering<'tcx>, Arc)> { self.resolver_for_lowering_raw(()).0 } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 9a78b35488503..d1899e3f5d817 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -198,7 +198,7 @@ pub struct ResolverGlobalCtxt { /// Resolutions that should only be used for lowering. /// This struct is meant to be consumed by lowering. #[derive(Debug)] -pub struct ResolverAstLowering { +pub struct ResolverAstLowering<'tcx> { /// Resolutions for nodes that have a single resolution. pub partial_res_map: NodeMap, /// Resolutions for import nodes, which have multiple resolutions in different namespaces. @@ -214,7 +214,7 @@ pub struct ResolverAstLowering { pub node_id_to_def_id: NodeMap, - pub trait_map: NodeMap>, + pub trait_map: NodeMap<&'tcx [hir::TraitCandidate<'tcx>]>, /// List functions and methods for which lifetime elision was successful. pub lifetime_elision_allowed: FxHashSet, diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 25aea8e9f82a0..b6fb9937dfa45 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -32,7 +32,7 @@ pub(crate) enum Duplicate { struct LanguageItemCollector<'ast, 'tcx> { items: LanguageItems, tcx: TyCtxt<'tcx>, - resolver: &'ast ResolverAstLowering, + resolver: &'ast ResolverAstLowering<'tcx>, // FIXME(#118552): We should probably feed def_span eagerly on def-id creation // so we can avoid constructing this map for local def-ids. item_spans: FxHashMap, @@ -42,7 +42,7 @@ struct LanguageItemCollector<'ast, 'tcx> { impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> { fn new( tcx: TyCtxt<'tcx>, - resolver: &'ast ResolverAstLowering, + resolver: &'ast ResolverAstLowering<'tcx>, ) -> LanguageItemCollector<'ast, 'tcx> { LanguageItemCollector { tcx, diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 6e9d4a38d987c..c7b0cb192433e 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -5258,7 +5258,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } } - fn traits_in_scope(&mut self, ident: Ident, ns: Namespace) -> Vec { + fn traits_in_scope(&mut self, ident: Ident, ns: Namespace) -> &'tcx [TraitCandidate<'tcx>] { self.r.traits_in_scope( self.current_trait_ref.as_ref().map(|(module, _)| *module), &self.parent_scope, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 6b3b5e2ec45f0..da68c4bee9934 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1155,9 +1155,9 @@ impl MacroData { } } -pub struct ResolverOutputs { +pub struct ResolverOutputs<'tcx> { pub global_ctxt: ResolverGlobalCtxt, - pub ast_lowering: ResolverAstLowering, + pub ast_lowering: ResolverAstLowering<'tcx>, } /// The main resolver class. @@ -1212,7 +1212,7 @@ pub struct Resolver<'ra, 'tcx> { extern_crate_map: UnordMap = Default::default(), module_children: LocalDefIdMap> = Default::default(), ambig_module_children: LocalDefIdMap> = Default::default(), - trait_map: NodeMap> = Default::default(), + trait_map: NodeMap<&'tcx [TraitCandidate<'tcx>]> = Default::default(), /// A map from nodes to anonymous modules. /// Anonymous modules are pseudo-modules that are implicitly created around items @@ -1806,7 +1806,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { self.visibilities_for_hashing.push((feed.def_id(), vis)); } - pub fn into_outputs(self) -> ResolverOutputs { + pub fn into_outputs(self) -> ResolverOutputs<'tcx> { let proc_macros = self.proc_macros; let expn_that_defined = self.expn_that_defined; let extern_crate_map = self.extern_crate_map; @@ -1952,7 +1952,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { parent_scope: &ParentScope<'ra>, sp: Span, assoc_item: Option<(Symbol, Namespace)>, - ) -> Vec { + ) -> &'tcx [TraitCandidate<'tcx>] { let mut found_traits = Vec::new(); if let Some(module) = current_trait { @@ -1960,7 +1960,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let def_id = module.def_id(); found_traits.push(TraitCandidate { def_id, - import_ids: smallvec![], + import_ids: &[], lint_ambiguous: false, }); } @@ -1990,14 +1990,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ControlFlow::<()>::Continue(()) }); - found_traits + self.tcx.hir_arena.alloc_slice(&found_traits) } fn traits_in_module( &mut self, module: Module<'ra>, assoc_item: Option<(Symbol, Namespace)>, - found_traits: &mut Vec, + found_traits: &mut Vec>, ) { module.ensure_traits(self); let traits = module.traits.borrow(); @@ -2036,8 +2036,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { &mut self, mut kind: &DeclKind<'_>, trait_name: Symbol, - ) -> SmallVec<[LocalDefId; 1]> { - let mut import_ids = smallvec![]; + ) -> &'tcx [LocalDefId] { + let mut import_ids: SmallVec<[LocalDefId; 1]> = smallvec![]; while let DeclKind::Import { import, source_decl, .. } = kind { if let Some(node_id) = import.id() { let def_id = self.local_def_id(node_id); @@ -2047,7 +2047,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { self.add_to_glob_map(*import, trait_name); kind = &source_decl.kind; } - import_ids + + self.tcx.hir_arena.alloc_slice(&import_ids) } fn resolutions(&self, module: Module<'ra>) -> &'ra Resolutions<'ra> { diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 1538f0329efa8..bc9ad1606b8a4 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -1041,10 +1041,10 @@ fn maybe_from_hir_attr(attr: &hir::Attribute, item_id: ItemId, tcx: TyCtxt<'_>) for attr_span in test_attrs { // FIXME: This is ugly, remove when `test_attrs` has been ported to new attribute API. if let Ok(snippet) = source_map.span_to_snippet(*attr_span) { - ret.push(Attribute::Other(format!("#[doc(test(attr({snippet})))"))); + ret.push(Attribute::Other(format!("#[doc(test(attr({snippet})))]"))); } } - toggle_attr(&mut ret, "no_crate_inject", no_crate_inject); + toggle_attr(&mut ret, "test(no_crate_inject)", no_crate_inject); return ret; } diff --git a/tests/rustdoc-json/attrs/no_crate_inject.rs b/tests/rustdoc-json/attrs/no_crate_inject.rs new file mode 100644 index 0000000000000..7750066bbdfa5 --- /dev/null +++ b/tests/rustdoc-json/attrs/no_crate_inject.rs @@ -0,0 +1,7 @@ +// Regression test for rustdoc JSON emitting +// `#[doc(no_crate_inject)]` instead of `#[doc(test(no_crate_inject))]`: +// https://github.com/rust-lang/rust/pull/153465 + +//@ is "$.index[?(@.inner.module.is_crate)].attrs" '[{"other": "#[doc(test(no_crate_inject))]"}]' + +#![doc(test(no_crate_inject))] diff --git a/tests/rustdoc-json/attrs/trailing_bracket.rs b/tests/rustdoc-json/attrs/trailing_bracket.rs new file mode 100644 index 0000000000000..0e3e1afca565a --- /dev/null +++ b/tests/rustdoc-json/attrs/trailing_bracket.rs @@ -0,0 +1,7 @@ +// Regression test for rustdoc JSON emitting +// `#[doc(test(attr(deny(rust_2018_idioms))))` without the trailing `]`: +// https://github.com/rust-lang/rust/pull/153465 + +//@ is "$.index[?(@.inner.module.is_crate)].attrs" '[{"other": "#[doc(test(attr(deny(rust_2018_idioms))))]"}]' + +#![doc(test(attr(deny(rust_2018_idioms))))]