From 27b280e1b5370640fc0f181a52eaae6dc379d353 Mon Sep 17 00:00:00 2001 From: Deadbeef <ent3rm4n@gmail.com> Date: Tue, 27 Sep 2022 13:42:32 +0000 Subject: [PATCH 01/14] Fix ICE in const_trait check code This fixes #102156. --- compiler/rustc_passes/src/check_const.rs | 2 +- .../rfc-2632-const-trait-impl/issue-102156.rs | 15 +++++++++++++++ .../issue-102156.stderr | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index 4062862ad747c..0af538454f068 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -199,7 +199,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { .. }) = item.kind { - let def_id = trait_ref.trait_def_id().unwrap(); + let Some(def_id) = trait_ref.trait_def_id() else { return; }; let source_map = tcx.sess.source_map(); if !tcx.has_attr(def_id, sym::const_trait) { tcx.sess diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs new file mode 100644 index 0000000000000..fe4e910813013 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs @@ -0,0 +1,15 @@ +#![feature(allocator_api)] +#![feature(const_trait_impl)] + +use core::convert::{From, TryFrom}; +//~^ ERROR +//~| ERROR + +use std::pin::Pin; +use std::alloc::Allocator; +impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>> +where + A: 'static, +{} + +pub fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr new file mode 100644 index 0000000000000..8bf00eaff1fb9 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr @@ -0,0 +1,19 @@ +error[E0433]: failed to resolve: maybe a missing crate `core`? + --> $DIR/issue-102156.rs:4:5 + | +LL | use core::convert::{From, TryFrom}; + | ^^^^ maybe a missing crate `core`? + | + = help: consider adding `extern crate core` to use the `core` crate + +error[E0433]: failed to resolve: maybe a missing crate `core`? + --> $DIR/issue-102156.rs:4:5 + | +LL | use core::convert::{From, TryFrom}; + | ^^^^ maybe a missing crate `core`? + | + = help: consider adding `extern crate core` to use the `core` crate + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0433`. From 8a96884981c97c4c35e304004290271308a67637 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 27 Sep 2022 20:56:05 +0200 Subject: [PATCH 02/14] Flush delayed bugs before codegen Sometimes it can happen that invalid code like a TyKind::Error makes its way through the compiler without triggering any errors (this is always a bug in rustc but bugs do happen sometimes :)). These ICEs will manifest in the backend like as cg_llvm not being able to get the layout of `[type error]`, which makes it hard to debug. By flushing before codegen, we display all the delayed bugs, making it easier to trace it to the root of the problem. --- compiler/rustc_errors/src/lib.rs | 6 ++++++ compiler/rustc_interface/src/queries.rs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 4d262ae0f5ec8..b4e99225f811f 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1133,6 +1133,12 @@ impl Handler { ); std::mem::take(&mut self.inner.borrow_mut().fulfilled_expectations) } + + pub fn flush_delayed(&self) { + let mut inner = self.inner.lock(); + let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new()); + inner.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued"); + } } impl HandlerInner { diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 6c725a01b5315..60ed48d89886f 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -246,6 +246,8 @@ impl<'tcx> Queries<'tcx> { // Don't do code generation if there were any errors self.session().compile_status()?; + self.session().diagnostic().flush_delayed(); + // Hook for UI tests. Self::check_for_rustc_errors_attr(tcx); From c1c3dacc7870584a7d11b853da8c5956878c6c65 Mon Sep 17 00:00:00 2001 From: Michael Goulet <michael@errs.io> Date: Thu, 29 Sep 2022 22:27:50 +0000 Subject: [PATCH 03/14] Generate synthetic impl region even in closure body in associated fn --- .../src/diagnostics/region_name.rs | 8 ++---- src/test/ui/borrowck/issue-102209.rs | 28 +++++++++++++++++++ src/test/ui/borrowck/issue-102209.stderr | 22 +++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/borrowck/issue-102209.rs create mode 100644 src/test/ui/borrowck/issue-102209.stderr diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 419e6c817915f..4d251cf7ac752 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -864,15 +864,13 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { }; let tcx = self.infcx.tcx; - let body_parent_did = tcx.opt_parent(self.mir_def_id().to_def_id())?; - if tcx.parent(region.def_id) != body_parent_did - || tcx.def_kind(body_parent_did) != DefKind::Impl - { + let region_parent = tcx.parent(region.def_id); + if tcx.def_kind(region_parent) != DefKind::Impl { return None; } let mut found = false; - tcx.fold_regions(tcx.type_of(body_parent_did), |r: ty::Region<'tcx>, _| { + tcx.fold_regions(tcx.type_of(region_parent), |r: ty::Region<'tcx>, _| { if *r == ty::ReEarlyBound(region) { found = true; } diff --git a/src/test/ui/borrowck/issue-102209.rs b/src/test/ui/borrowck/issue-102209.rs new file mode 100644 index 0000000000000..37628bff7df4b --- /dev/null +++ b/src/test/ui/borrowck/issue-102209.rs @@ -0,0 +1,28 @@ +use std::marker::PhantomData; + +pub struct NfaBuilder<'brand> { + brand: PhantomData<&'brand mut &'brand mut ()>, +} + +impl NfaBuilder<'_> { + pub fn with<R, F: FnOnce(NfaBuilder<'_>) -> R>(f: F) -> R { + Brand::with(|brand| { + f(Self { brand: brand.lt }) + //~^ ERROR lifetime may not live long enough + //~| ERROR lifetime may not live long enough + }) + } +} + +#[derive(Clone, Copy)] +pub struct Brand<'brand> { + lt: PhantomData<&'brand mut &'brand mut ()>, +} + +impl Brand<'_> { + pub fn with<R, F: FnOnce(Brand<'_>) -> R>(f: F) -> R { + f(Self { lt: PhantomData }) + } +} + +fn main() {} diff --git a/src/test/ui/borrowck/issue-102209.stderr b/src/test/ui/borrowck/issue-102209.stderr new file mode 100644 index 0000000000000..351de8217b234 --- /dev/null +++ b/src/test/ui/borrowck/issue-102209.stderr @@ -0,0 +1,22 @@ +error: lifetime may not live long enough + --> $DIR/issue-102209.rs:10:29 + | +LL | impl NfaBuilder<'_> { + | -- lifetime `'2` appears in the `impl`'s self type +LL | pub fn with<R, F: FnOnce(NfaBuilder<'_>) -> R>(f: F) -> R { +LL | Brand::with(|brand| { + | ----- has type `Brand<'1>` +LL | f(Self { brand: brand.lt }) + | ^^^^^^^^ this usage requires that `'1` must outlive `'2` + +error: lifetime may not live long enough + --> $DIR/issue-102209.rs:10:29 + | +LL | impl NfaBuilder<'_> { + | -- lifetime `'1` appears in the `impl`'s self type +... +LL | f(Self { brand: brand.lt }) + | ^^^^^^^^ this usage requires that `'1` must outlive `'static` + +error: aborting due to 2 previous errors + From 3722ad4c26d650b113353e264a91c7f2ddf324ae Mon Sep 17 00:00:00 2001 From: Michael Goulet <michael@errs.io> Date: Thu, 29 Sep 2022 22:44:24 +0000 Subject: [PATCH 04/14] Don't lower assoc bindings just to deny them --- .../rustc_hir_analysis/src/astconv/generics.rs | 4 ++-- compiler/rustc_hir_analysis/src/astconv/mod.rs | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/generics.rs b/compiler/rustc_hir_analysis/src/astconv/generics.rs index afac75de2d96d..fbb0c8918d2bd 100644 --- a/compiler/rustc_hir_analysis/src/astconv/generics.rs +++ b/compiler/rustc_hir_analysis/src/astconv/generics.rs @@ -448,8 +448,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let infer_lifetimes = (gen_pos != GenericArgPosition::Type || infer_args) && !gen_args.has_lifetime_params(); - if gen_pos != GenericArgPosition::Type && !gen_args.bindings.is_empty() { - Self::prohibit_assoc_ty_binding(tcx, gen_args.bindings[0].span); + if gen_pos != GenericArgPosition::Type && let Some(b) = gen_args.bindings.first() { + Self::prohibit_assoc_ty_binding(tcx, b.span); } let explicit_late_bound = diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 244018ebbeb74..52bd4d95a000c 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -276,9 +276,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { item_segment.infer_args, None, ); - let assoc_bindings = self.create_assoc_bindings_for_generic_args(item_segment.args()); - - if let Some(b) = assoc_bindings.first() { + if let Some(b) = item_segment.args().bindings.first() { Self::prohibit_assoc_ty_binding(self.tcx(), b.span); } @@ -605,8 +603,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { None, ); - let assoc_bindings = self.create_assoc_bindings_for_generic_args(item_segment.args()); - if let Some(b) = assoc_bindings.first() { + if let Some(b) = item_segment.args().bindings.first() { Self::prohibit_assoc_ty_binding(self.tcx(), b.span); } @@ -794,8 +791,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { trait_segment, is_impl, ); - let assoc_bindings = self.create_assoc_bindings_for_generic_args(trait_segment.args()); - if let Some(b) = assoc_bindings.first() { + if let Some(b) = trait_segment.args().bindings.first() { Self::prohibit_assoc_ty_binding(self.tcx(), b.span); } ty::TraitRef::new(trait_def_id, substs) @@ -2208,8 +2204,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { for segment in segments { // Only emit the first error to avoid overloading the user with error messages. - if let [binding, ..] = segment.args().bindings { - Self::prohibit_assoc_ty_binding(self.tcx(), binding.span); + if let Some(b) = segment.args().bindings.first() { + Self::prohibit_assoc_ty_binding(self.tcx(), b.span); return true; } } From d7fe44d98814f98354dd29532e01f1836b046d9e Mon Sep 17 00:00:00 2001 From: fee1-dead <ent3rm4n@gmail.com> Date: Fri, 30 Sep 2022 00:31:53 +0000 Subject: [PATCH 05/14] Use let chains instead of let else --- compiler/rustc_passes/src/check_const.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index 0af538454f068..116aaf4834981 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -198,8 +198,8 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { of_trait: Some(trait_ref), .. }) = item.kind + && let Some(def_id) = trait_ref.trait_def_id() { - let Some(def_id) = trait_ref.trait_def_id() else { return; }; let source_map = tcx.sess.source_map(); if !tcx.has_attr(def_id, sym::const_trait) { tcx.sess From 477846f491284973f1f3f8b4bf9c6d9deb6ad98e Mon Sep 17 00:00:00 2001 From: nils <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 30 Sep 2022 14:11:18 +0200 Subject: [PATCH 06/14] Add comment explaining why we flush delayed bugs before codegen --- compiler/rustc_interface/src/queries.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 60ed48d89886f..05775f376472a 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -246,6 +246,8 @@ impl<'tcx> Queries<'tcx> { // Don't do code generation if there were any errors self.session().compile_status()?; + // If we have any delayed bugs, for example beacuse we created TyKind::Error earlier, + // it's likey that codegen will only cause more ICEs, obscuring the original problem self.session().diagnostic().flush_delayed(); // Hook for UI tests. From 8728e178554eb7b0eeb4d8c2e254b07a3bccd4cb Mon Sep 17 00:00:00 2001 From: Michael Howell <michael@notriddle.com> Date: Fri, 30 Sep 2022 09:42:07 -0700 Subject: [PATCH 07/14] rustdoc: add missing margin to no-docblock methods Fixes another regression caused by 8846c0853d8687fda0e5f23f6687b03b243980ee, this time fixing the appearance of methods that have no docblock (we didn't notice this one because libstd docs *always* have docblocks). See how it looks without the fix at https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/enum.Type.html#implementations --- src/librustdoc/html/static/css/rustdoc.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index eb5271aaf7e38..37c95f6c784f2 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -2008,7 +2008,9 @@ in storage.js plus the media query with (min-width: 701px) .method-toggle summary, .implementors-toggle summary, .impl, -#implementors-list > .docblock { +#implementors-list > .docblock, +.impl-items > section, + { margin-bottom: 0.75em; } From f145f283f737d766404f39b26dd773eadc98e344 Mon Sep 17 00:00:00 2001 From: Michael Howell <michael@notriddle.com> Date: Fri, 30 Sep 2022 10:15:59 -0700 Subject: [PATCH 08/14] rustdoc: add missing margin to no-docblock trait items Fixes another regression caused by 8846c0853d8687fda0e5f23f6687b03b243980ee, this time fixing the appearance of methods that have no docblock (we didn't notice this one because libstd docs *always* have docblocks). See how it looks at https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/trait.AttributesExt.html --- src/librustdoc/html/render/print_item.rs | 4 ++-- src/librustdoc/html/static/css/rustdoc.css | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 9f6b6b5253605..7bd0dbf9325fa 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -718,7 +718,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: if toggled { write!(w, "<details class=\"rustdoc-toggle method-toggle\" open><summary>"); } - write!(w, "<div id=\"{}\" class=\"method has-srclink\">", id); + write!(w, "<section id=\"{}\" class=\"method has-srclink\">", id); render_rightside(w, cx, m, t, RenderMode::Normal); write!(w, "<h4 class=\"code-header\">"); render_assoc_item( @@ -730,7 +730,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: RenderMode::Normal, ); w.write_str("</h4>"); - w.write_str("</div>"); + w.write_str("</section>"); if toggled { write!(w, "</summary>"); w.push_buffer(content); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 37c95f6c784f2..8ffd092426dd9 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -2010,7 +2010,8 @@ in storage.js plus the media query with (min-width: 701px) .impl, #implementors-list > .docblock, .impl-items > section, - { +.methods > section +{ margin-bottom: 0.75em; } From 1dcbe72031caf6d29b3db6e1dd9901b23650de4c Mon Sep 17 00:00:00 2001 From: Michael Howell <michael@notriddle.com> Date: Fri, 30 Sep 2022 10:44:15 -0700 Subject: [PATCH 09/14] rustdoc: add gui test for no-docblock margins --- src/test/rustdoc-gui/no-docblock.goml | 8 ++++++++ src/test/rustdoc-gui/src/test_docs/lib.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/test/rustdoc-gui/no-docblock.goml diff --git a/src/test/rustdoc-gui/no-docblock.goml b/src/test/rustdoc-gui/no-docblock.goml new file mode 100644 index 0000000000000..2408be4534b5e --- /dev/null +++ b/src/test/rustdoc-gui/no-docblock.goml @@ -0,0 +1,8 @@ +// This test checks that there are margins applied to methods with no docblocks. +goto: file://|DOC_PATH|/test_docs/trait.TraitWithNoDocblocks.html +// Check that the two methods are more than 24px apart. +compare-elements-position-near-false: ("//*[@id='tymethod.first_fn']", "//*[@id='tymethod.second_fn']", {"y": 24}) + +goto: file://|DOC_PATH|/test_docs/struct.TypeWithNoDocblocks.html +// Check that the two methods are more than 24px apart. +compare-elements-position-near-false: ("//*[@id='method.first_fn']", "//*[@id='method.second_fn']", {"y": 24}) diff --git a/src/test/rustdoc-gui/src/test_docs/lib.rs b/src/test/rustdoc-gui/src/test_docs/lib.rs index 1c066206c1f21..0281973c1ba20 100644 --- a/src/test/rustdoc-gui/src/test_docs/lib.rs +++ b/src/test/rustdoc-gui/src/test_docs/lib.rs @@ -355,3 +355,15 @@ impl<R: std::io::Read> std::iter::Iterator for NotableStructWithLongName<R> { fn next(&mut self) -> Option<Self::Item> { () } } + +pub trait TraitWithNoDocblocks { + fn first_fn(&self); + fn second_fn(&self); +} + +pub struct TypeWithNoDocblocks; + +impl TypeWithNoDocblocks { + pub fn first_fn(&self) {} + pub fn second_fn(&self) {} +} From 4b1cf846bd39a7409949a394f4c1655f2410c7e6 Mon Sep 17 00:00:00 2001 From: Camille Gillot <gillot.camille@gmail.com> Date: Fri, 30 Sep 2022 19:50:48 +0200 Subject: [PATCH 10/14] Update compiler/rustc_interface/src/queries.rs --- compiler/rustc_interface/src/queries.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 05775f376472a..6dfaa4453ef3e 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -246,7 +246,7 @@ impl<'tcx> Queries<'tcx> { // Don't do code generation if there were any errors self.session().compile_status()?; - // If we have any delayed bugs, for example beacuse we created TyKind::Error earlier, + // If we have any delayed bugs, for example because we created TyKind::Error earlier, // it's likey that codegen will only cause more ICEs, obscuring the original problem self.session().diagnostic().flush_delayed(); From b2bef02bcdc322a42ccde2688f34dce01a0cbb50 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino <spastorino@gmail.com> Date: Fri, 30 Sep 2022 10:45:02 -0300 Subject: [PATCH 11/14] create def ids for impl traits during ast lowering --- compiler/rustc_ast_lowering/src/lib.rs | 27 ++++++++++++------- compiler/rustc_middle/src/hir/map/mod.rs | 4 +-- compiler/rustc_query_system/src/ich/hcx.rs | 4 +-- compiler/rustc_resolve/src/def_collector.rs | 15 ----------- .../print/generator-print-verbose-1.stderr | 8 +++--- .../ty-outlives/impl-trait-captures.stderr | 8 +++--- 6 files changed, 30 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 275ceed30d7da..8281164ab1207 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -61,8 +61,8 @@ use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::definitions::DefPathData; use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate}; use rustc_index::vec::{Idx, IndexVec}; -use rustc_middle::span_bug; use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; +use rustc_middle::{bug, span_bug}; use rustc_session::parse::feature_err; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::DesugaringKind; @@ -1060,13 +1060,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by // constructing the HIR for `impl bounds...` and then lowering that. - let parent_def_id = self.current_hir_id_owner; let impl_trait_node_id = self.next_node_id(); - self.create_def( - parent_def_id.def_id, - impl_trait_node_id, - DefPathData::ImplTrait, - ); self.with_dyn_type_scope(false, |this| { let node_id = this.next_node_id(); @@ -1357,9 +1351,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { def_node_id, bounds, false, - &ImplTraitContext::TypeAliasesOpaqueTy, + itctx, ), ImplTraitContext::Universal => { + self.create_def( + self.current_hir_id_owner.def_id, + def_node_id, + DefPathData::ImplTrait, + ); let span = t.span; let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span); let (param, bounds, path) = @@ -1453,7 +1452,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // frequently opened issues show. let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None); - let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id); + let opaque_ty_def_id = match origin { + hir::OpaqueTyOrigin::TyAlias => self.create_def( + self.current_hir_id_owner.def_id, + opaque_ty_node_id, + DefPathData::ImplTrait, + ), + hir::OpaqueTyOrigin::FnReturn(fn_def_id) => { + self.create_def(fn_def_id, opaque_ty_node_id, DefPathData::ImplTrait) + } + hir::OpaqueTyOrigin::AsyncFn(..) => bug!("unreachable"), + }; debug!(?opaque_ty_def_id); // Contains the new lifetime definitions created for the TAIT (if any). diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index b5f7b26ea7ab6..8523b5ca0ec33 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -14,7 +14,7 @@ use rustc_index::vec::Idx; use rustc_middle::hir::nested_filter; use rustc_span::def_id::StableCrateId; use rustc_span::symbol::{kw, sym, Ident, Symbol}; -use rustc_span::Span; +use rustc_span::{Span, DUMMY_SP}; use rustc_target::spec::abi::Abi; #[inline] @@ -1131,7 +1131,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { .filter_map(|(def_id, info)| { let _ = info.as_owner()?; let def_path_hash = definitions.def_path_hash(def_id); - let span = resolutions.source_span[def_id]; + let span = resolutions.source_span.get(def_id).unwrap_or(&DUMMY_SP); debug_assert_eq!(span.parent(), None); Some((def_path_hash, span)) }) diff --git a/compiler/rustc_query_system/src/ich/hcx.rs b/compiler/rustc_query_system/src/ich/hcx.rs index 8140c243453bd..148eabb38e230 100644 --- a/compiler/rustc_query_system/src/ich/hcx.rs +++ b/compiler/rustc_query_system/src/ich/hcx.rs @@ -12,7 +12,7 @@ use rustc_session::cstore::CrateStore; use rustc_session::Session; use rustc_span::source_map::SourceMap; use rustc_span::symbol::Symbol; -use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData}; +use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData, DUMMY_SP}; /// This is the context state available during incr. comp. hashing. It contains /// enough information to transform `DefId`s and `HirId`s into stable `DefPath`s (i.e., @@ -185,7 +185,7 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> { #[inline] fn def_span(&self, def_id: LocalDefId) -> Span { - self.source_span[def_id] + *self.source_span.get(def_id).unwrap_or(&DUMMY_SP) } #[inline] diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 7e83f2a722107..38a3c9dd71a5e 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -285,21 +285,6 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> { fn visit_ty(&mut self, ty: &'a Ty) { match ty.kind { TyKind::MacCall(..) => self.visit_macro_invoc(ty.id), - TyKind::ImplTrait(node_id, _) => { - let parent_def = match self.impl_trait_context { - ImplTraitContext::Universal(item_def) => self.resolver.create_def( - item_def, - node_id, - DefPathData::ImplTrait, - self.expansion.to_expn_id(), - ty.span, - ), - ImplTraitContext::Existential => { - self.create_def(node_id, DefPathData::ImplTrait, ty.span) - } - }; - self.with_parent(parent_def, |this| visit::walk_ty(this, ty)) - } _ => visit::walk_ty(self, ty), } } diff --git a/src/test/ui/generator/print/generator-print-verbose-1.stderr b/src/test/ui/generator/print/generator-print-verbose-1.stderr index 3a83021dd9950..2e02078048027 100644 --- a/src/test/ui/generator/print/generator-print-verbose-1.stderr +++ b/src/test/ui/generator/print/generator-print-verbose-1.stderr @@ -9,7 +9,7 @@ note: generator is not `Send` as this value is used across a yield --> $DIR/generator-print-verbose-1.rs:35:9 | LL | let _non_send_gen = make_non_send_generator(); - | ------------- has type `Opaque(DefId(0:34 ~ generator_print_verbose_1[749a]::make_non_send_generator::{opaque#0}), [])` which is not `Send` + | ------------- has type `Opaque(DefId(0:44 ~ generator_print_verbose_1[749a]::make_non_send_generator::{opaque#0}), [])` which is not `Send` LL | yield; | ^^^^^ yield occurs here, with `_non_send_gen` maybe used later LL | }; @@ -35,17 +35,17 @@ note: required because it's used within this generator | LL | || { | ^^ -note: required because it appears within the type `Opaque(DefId(0:39 ~ generator_print_verbose_1[749a]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::RefCell<i32>>])` +note: required because it appears within the type `Opaque(DefId(0:45 ~ generator_print_verbose_1[749a]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::RefCell<i32>>])` --> $DIR/generator-print-verbose-1.rs:41:30 | LL | pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: required because it appears within the type `Opaque(DefId(0:42 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])` +note: required because it appears within the type `Opaque(DefId(0:46 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])` --> $DIR/generator-print-verbose-1.rs:47:34 | LL | fn make_non_send_generator2() -> impl Generator<Return = Arc<RefCell<i32>>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: required because it captures the following types: `Opaque(DefId(0:42 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`, `()` + = note: required because it captures the following types: `Opaque(DefId(0:46 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`, `()` note: required because it's used within this generator --> $DIR/generator-print-verbose-1.rs:52:20 | diff --git a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr index 330c6fafa2d61..6a8a1ad1caadd 100644 --- a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr +++ b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr @@ -1,14 +1,14 @@ -error[E0700]: hidden type for `Opaque(DefId(0:11 ~ impl_trait_captures[1afc]::foo::{opaque#0}), [ReStatic, T, ReEarlyBound(0, 'a)])` captures lifetime that does not appear in bounds +error[E0700]: hidden type for `Opaque(DefId(0:13 ~ impl_trait_captures[1afc]::foo::{opaque#0}), [ReStatic, T, ReEarlyBound(0, 'a)])` captures lifetime that does not appear in bounds --> $DIR/impl-trait-captures.rs:11:5 | LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> { - | -- hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_)) T` captures the anonymous lifetime defined here + | -- hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_)) T` captures the anonymous lifetime defined here LL | x | ^ | -help: to declare that the `impl Trait` captures `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_))`, you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_))` lifetime bound +help: to declare that the `impl Trait` captures `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_))`, you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_))` lifetime bound | -LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_)) { +LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_)) { | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ error: aborting due to previous error From 8308c4bd359c4d300475055d67d5e1b0f6cd6856 Mon Sep 17 00:00:00 2001 From: Michael Howell <michael@notriddle.com> Date: Fri, 30 Sep 2022 11:17:03 -0700 Subject: [PATCH 12/14] rustdoc: update test cases for `<section>` tags in traits --- src/test/rustdoc-gui/sidebar-mobile-scroll.goml | 6 +++--- src/test/rustdoc/anchors.no_const_anchor.html | 2 +- src/test/rustdoc/anchors.no_trait_method_anchor.html | 2 +- src/test/rustdoc/anchors.no_tymethod_anchor.html | 2 +- src/test/rustdoc/anchors.no_type_anchor.html | 2 +- src/test/rustdoc/rfc-2632-const-trait-impl.rs | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/rustdoc-gui/sidebar-mobile-scroll.goml b/src/test/rustdoc-gui/sidebar-mobile-scroll.goml index 9af7c636a0cac..6cb492cfc64e5 100644 --- a/src/test/rustdoc-gui/sidebar-mobile-scroll.goml +++ b/src/test/rustdoc-gui/sidebar-mobile-scroll.goml @@ -6,7 +6,7 @@ assert-css: (".sidebar", {"display": "block", "left": "-1000px"}) // Scroll down. scroll-to: "//h2[@id='blanket-implementations']" -assert-window-property: {"pageYOffset": "639"} +assert-window-property: {"pageYOffset": "651"} // Open the sidebar menu. click: ".sidebar-menu-toggle" @@ -21,11 +21,11 @@ assert-window-property: {"pageYOffset": "0"} // Close the sidebar menu. Make sure the scroll position gets restored. click: ".sidebar-menu-toggle" wait-for-css: (".sidebar", {"left": "-1000px"}) -assert-window-property: {"pageYOffset": "639"} +assert-window-property: {"pageYOffset": "651"} // Now test that scrollability returns when the browser window is just resized. click: ".sidebar-menu-toggle" wait-for-css: (".sidebar", {"left": "0px"}) assert-window-property: {"pageYOffset": "0"} size: (900, 600) -assert-window-property: {"pageYOffset": "639"} +assert-window-property: {"pageYOffset": "651"} diff --git a/src/test/rustdoc/anchors.no_const_anchor.html b/src/test/rustdoc/anchors.no_const_anchor.html index 4da1ffead2a4c..75e67330a3ebf 100644 --- a/src/test/rustdoc/anchors.no_const_anchor.html +++ b/src/test/rustdoc/anchors.no_const_anchor.html @@ -1 +1 @@ -<div id="associatedconstant.YOLO" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#16">source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></div> \ No newline at end of file +<section id="associatedconstant.YOLO" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#16">source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section> \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_trait_method_anchor.html b/src/test/rustdoc/anchors.no_trait_method_anchor.html index 6b78c7c811a06..d7bd525ff0f53 100644 --- a/src/test/rustdoc/anchors.no_trait_method_anchor.html +++ b/src/test/rustdoc/anchors.no_trait_method_anchor.html @@ -1 +1 @@ -<div id="method.bar" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#23">source</a><h4 class="code-header">fn <a href="#method.bar" class="fnname">bar</a>()</h4></div> \ No newline at end of file +<section id="method.bar" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#23">source</a><h4 class="code-header">fn <a href="#method.bar" class="fnname">bar</a>()</h4></section> \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_tymethod_anchor.html b/src/test/rustdoc/anchors.no_tymethod_anchor.html index c08f4427cf697..e668e5e4db15c 100644 --- a/src/test/rustdoc/anchors.no_tymethod_anchor.html +++ b/src/test/rustdoc/anchors.no_tymethod_anchor.html @@ -1 +1 @@ -<div id="tymethod.foo" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#20">source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fnname">foo</a>()</h4></div> \ No newline at end of file +<section id="tymethod.foo" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#20">source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fnname">foo</a>()</h4></section> \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_type_anchor.html b/src/test/rustdoc/anchors.no_type_anchor.html index ba8e65443ec81..2c66d5aa315ab 100644 --- a/src/test/rustdoc/anchors.no_type_anchor.html +++ b/src/test/rustdoc/anchors.no_type_anchor.html @@ -1 +1 @@ -<div id="associatedtype.T" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#13">source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></div> \ No newline at end of file +<section id="associatedtype.T" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#13">source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></section> \ No newline at end of file diff --git a/src/test/rustdoc/rfc-2632-const-trait-impl.rs b/src/test/rustdoc/rfc-2632-const-trait-impl.rs index 8bd402291aabf..602ee1b1b1fca 100644 --- a/src/test/rustdoc/rfc-2632-const-trait-impl.rs +++ b/src/test/rustdoc/rfc-2632-const-trait-impl.rs @@ -18,10 +18,10 @@ pub struct S<T>(T); // @has - '//pre[@class="rust trait"]/code/span[@class="where"]' ': Clone' #[const_trait] pub trait Tr<T> { - // @!has - '//div[@id="method.a"]/h4[@class="code-header"]' '~const' - // @has - '//div[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Clone' - // @!has - '//div[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const' - // @has - '//div[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone' + // @!has - '//section[@id="method.a"]/h4[@class="code-header"]' '~const' + // @has - '//section[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Clone' + // @!has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const' + // @has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone' fn a<A: ~const Clone + ~const Destruct>() where Option<A>: ~const Clone + ~const Destruct, From e8f1bfe1937c51c1a408c98cf810d10ead454314 Mon Sep 17 00:00:00 2001 From: nils <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 30 Sep 2022 21:02:53 +0200 Subject: [PATCH 13/14] Fix typo --- compiler/rustc_interface/src/queries.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 6dfaa4453ef3e..91d180e1eb7e5 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -247,7 +247,7 @@ impl<'tcx> Queries<'tcx> { self.session().compile_status()?; // If we have any delayed bugs, for example because we created TyKind::Error earlier, - // it's likey that codegen will only cause more ICEs, obscuring the original problem + // it's likely that codegen will only cause more ICEs, obscuring the original problem self.session().diagnostic().flush_delayed(); // Hook for UI tests. From 5ab68a82d592c43f7699d739003a4a7680f35e8f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote <n.nethercote@gmail.com> Date: Fri, 30 Sep 2022 09:23:55 +1000 Subject: [PATCH 14/14] Group together more size assertions. Also add a few more assertions for some relevant token-related types. And fix an erroneous comment in `rustc_errors`. --- compiler/rustc_ast/src/token.rs | 21 ++++++++++++------- compiler/rustc_ast/src/tokenstream.rs | 21 ++++++++++++------- compiler/rustc_errors/src/lib.rs | 2 +- .../rustc_parse/src/parser/attr_wrapper.rs | 18 +++++++++------- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index fa6162c51847a..0d3bfe04a2555 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -256,10 +256,6 @@ pub enum TokenKind { Eof, } -// `TokenKind` is used a lot. Make sure it doesn't unintentionally get bigger. -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(TokenKind, 16); - #[derive(Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub struct Token { pub kind: TokenKind, @@ -751,10 +747,6 @@ pub enum Nonterminal { NtVis(P<ast::Visibility>), } -// `Nonterminal` is used a lot. Make sure it doesn't unintentionally get bigger. -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Nonterminal, 16); - #[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable)] pub enum NonterminalKind { Item, @@ -893,3 +885,16 @@ where panic!("interpolated tokens should not be present in the HIR") } } + +// Some types are used a lot. Make sure they don't unintentionally get bigger. +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] +mod size_asserts { + use super::*; + use rustc_data_structures::static_assert_size; + // These are in alphabetical order, which is easy to maintain. + static_assert_size!(Lit, 12); + static_assert_size!(LitKind, 2); + static_assert_size!(Nonterminal, 16); + static_assert_size!(Token, 24); + static_assert_size!(TokenKind, 16); +} diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 875cd620dfc6c..824206a99d8d3 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -47,10 +47,6 @@ pub enum TokenTree { Delimited(DelimSpan, Delimiter, TokenStream), } -// This type is used a lot. Make sure it doesn't unintentionally get bigger. -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(TokenTree, 32); - // Ensure all fields of `TokenTree` is `Send` and `Sync`. #[cfg(parallel_compiler)] fn _dummy() @@ -308,10 +304,6 @@ pub struct AttributesData { #[derive(Clone, Debug, Default, Encodable, Decodable)] pub struct TokenStream(pub(crate) Lrc<Vec<TokenTree>>); -// `TokenStream` is used a lot. Make sure it doesn't unintentionally get bigger. -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(TokenStream, 8); - #[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)] pub enum Spacing { Alone, @@ -664,3 +656,16 @@ impl DelimSpan { self.open.with_hi(self.close.hi()) } } + +// Some types are used a lot. Make sure they don't unintentionally get bigger. +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] +mod size_asserts { + use super::*; + use rustc_data_structures::static_assert_size; + // These are in alphabetical order, which is easy to maintain. + static_assert_size!(AttrTokenStream, 8); + static_assert_size!(AttrTokenTree, 32); + static_assert_size!(LazyAttrTokenStream, 8); + static_assert_size!(TokenStream, 8); + static_assert_size!(TokenTree, 32); +} diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index d3effb7c1c0f4..cdb2c2af7d62a 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -66,7 +66,7 @@ pub type PErr<'a> = DiagnosticBuilder<'a, ErrorGuaranteed>; pub type PResult<'a, T> = Result<T, PErr<'a>>; // `PResult` is used a lot. Make sure it doesn't unintentionally get bigger. -// (See also the comment on `DiagnosticBuilder`'s `diagnostic` field.) +// (See also the comment on `DiagnosticBuilderInner`'s `diagnostic` field.) #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] rustc_data_structures::static_assert_size!(PResult<'_, ()>, 16); #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index 86c386b94c834..0dc05475ce944 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -32,11 +32,6 @@ pub struct AttrWrapper { start_pos: usize, } -// This struct is passed around very frequently, -// so make sure it doesn't accidentally get larger -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(AttrWrapper, 16); - impl AttrWrapper { pub(super) fn new(attrs: AttrVec, start_pos: usize) -> AttrWrapper { AttrWrapper { attrs, start_pos } @@ -96,9 +91,6 @@ struct LazyAttrTokenStreamImpl { replace_ranges: Box<[ReplaceRange]>, } -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(LazyAttrTokenStreamImpl, 144); - impl ToAttrTokenStream for LazyAttrTokenStreamImpl { fn to_attr_token_stream(&self) -> AttrTokenStream { // The token produced by the final call to `{,inlined_}next` was not @@ -461,3 +453,13 @@ fn make_token_stream( } AttrTokenStream::new(final_buf.inner) } + +// Some types are used a lot. Make sure they don't unintentionally get bigger. +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] +mod size_asserts { + use super::*; + use rustc_data_structures::static_assert_size; + // These are in alphabetical order, which is easy to maintain. + static_assert_size!(AttrWrapper, 16); + static_assert_size!(LazyAttrTokenStreamImpl, 144); +}