From 9a240e485758889426af78a230f198c00c77f967 Mon Sep 17 00:00:00 2001 From: pierwill Date: Sun, 3 Jan 2021 11:54:56 -0800 Subject: [PATCH 01/18] Edit rustc_ast::tokenstream docs Fix some punctuation and wording, and add intra-documentation links. --- compiler/rustc_ast/src/tokenstream.rs | 33 ++++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 0550f53a96f..00354b42ebb 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -1,15 +1,15 @@ //! # Token Streams //! //! `TokenStream`s represent syntactic objects before they are converted into ASTs. -//! A `TokenStream` is, roughly speaking, a sequence (eg stream) of `TokenTree`s, -//! which are themselves a single `Token` or a `Delimited` subsequence of tokens. +//! A `TokenStream` is, roughly speaking, a sequence of [`TokenTree`]s, +//! which are themselves a single [`Token`] or a `Delimited` subsequence of tokens. //! //! ## Ownership //! //! `TokenStream`s are persistent data structures constructed as ropes with reference //! counted-children. In general, this means that calling an operation on a `TokenStream` //! (such as `slice`) produces an entirely new `TokenStream` from the borrowed reference to -//! the original. This essentially coerces `TokenStream`s into 'views' of their subparts, +//! the original. This essentially coerces `TokenStream`s into "views" of their subparts, //! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking //! ownership of the original. @@ -24,9 +24,9 @@ use smallvec::{smallvec, SmallVec}; use std::{fmt, iter, mem}; -/// When the main rust parser encounters a syntax-extension invocation, it -/// parses the arguments to the invocation as a token-tree. This is a very -/// loose structure, such that all sorts of different AST-fragments can +/// When the main Rust parser encounters a syntax-extension invocation, it +/// parses the arguments to the invocation as a token tree. This is a very +/// loose structure, such that all sorts of different AST fragments can /// be passed to syntax extensions using a uniform type. /// /// If the syntax extension is an MBE macro, it will attempt to match its @@ -38,9 +38,9 @@ use std::{fmt, iter, mem}; /// Nothing special happens to misnamed or misplaced `SubstNt`s. #[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)] pub enum TokenTree { - /// A single token + /// A single token. Token(Token), - /// A delimited sequence of token trees + /// A delimited sequence of token trees. Delimited(DelimSpan, DelimToken, TokenStream), } @@ -62,7 +62,7 @@ where } impl TokenTree { - /// Checks if this TokenTree is equal to the other, regardless of span information. + /// Checks if this `TokenTree` is equal to the other, regardless of span information. pub fn eq_unspanned(&self, other: &TokenTree) -> bool { match (self, other) { (TokenTree::Token(token), TokenTree::Token(token2)) => token.kind == token2.kind, @@ -73,7 +73,7 @@ impl TokenTree { } } - /// Retrieves the TokenTree's span. + /// Retrieves the `TokenTree`'s span. pub fn span(&self) -> Span { match self { TokenTree::Token(token) => token.span, @@ -140,7 +140,7 @@ impl CreateTokenStream for TokenStream { } } -/// A lazy version of `TokenStream`, which defers creation +/// A lazy version of [`TokenStream`], which defers creation /// of an actual `TokenStream` until it is needed. /// `Box` is here only to reduce the structure size. #[derive(Clone)] @@ -188,11 +188,12 @@ impl HashStable for LazyTokenStream { } } -/// A `TokenStream` is an abstract sequence of tokens, organized into `TokenTree`s. +/// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s. /// /// The goal is for procedural macros to work with `TokenStream`s and `TokenTree`s /// instead of a representation of the abstract syntax tree. -/// Today's `TokenTree`s can still contain AST via `token::Interpolated` for back-compat. +/// Today's `TokenTree`s can still contain AST via `token::Interpolated` for +/// backwards compatability. #[derive(Clone, Debug, Default, Encodable, Decodable)] pub struct TokenStream(pub(crate) Lrc>); @@ -429,7 +430,7 @@ impl TokenStreamBuilder { } } -/// By-reference iterator over a `TokenStream`. +/// By-reference iterator over a [`TokenStream`]. #[derive(Clone)] pub struct CursorRef<'t> { stream: &'t TokenStream, @@ -457,8 +458,8 @@ impl<'t> Iterator for CursorRef<'t> { } } -/// Owning by-value iterator over a `TokenStream`. -/// FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones. +/// Owning by-value iterator over a [`TokenStream`]. +// FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones. #[derive(Clone)] pub struct Cursor { pub stream: TokenStream, From b4a0ef066d645b430091017203882b6ea39b73a1 Mon Sep 17 00:00:00 2001 From: max-heller Date: Sun, 3 Jan 2021 15:34:06 -0500 Subject: [PATCH 02/18] fix issue 80559 --- src/librustdoc/passes/collect_intra_doc_links.rs | 15 ++++++++++----- src/test/rustdoc/issue-80559.rs | 4 ++++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/test/rustdoc/issue-80559.rs diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 0cefbb34791..fd63d5eb5c9 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -394,10 +394,14 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { ns, impl_, ) - .map(|item| match item.kind { - ty::AssocKind::Fn => "method", - ty::AssocKind::Const => "associatedconstant", - ty::AssocKind::Type => "associatedtype", + .map(|item| { + let kind = item.kind; + self.kind_side_channel.set(Some((kind.as_def_kind(), item.def_id))); + match kind { + ty::AssocKind::Fn => "method", + ty::AssocKind::Const => "associatedconstant", + ty::AssocKind::Type => "associatedtype", + } }) .map(|out| { ( @@ -1143,7 +1147,7 @@ impl LinkCollector<'_, '_> { ); }; match res { - Res::Primitive(_) => match disambiguator { + Res::Primitive(_) if self.kind_side_channel.get().is_none() => match disambiguator { Some(Disambiguator::Primitive | Disambiguator::Namespace(_)) | None => { Some(ItemLink { link: ori_link.link, link_text, did: None, fragment }) } @@ -1152,6 +1156,7 @@ impl LinkCollector<'_, '_> { None } }, + Res::Primitive(_) => Some(ItemLink { link: ori_link, link_text, did: None, fragment }), Res::Def(kind, id) => { debug!("intra-doc link to {} resolved to {:?}", path_str, res); diff --git a/src/test/rustdoc/issue-80559.rs b/src/test/rustdoc/issue-80559.rs new file mode 100644 index 00000000000..34905c48653 --- /dev/null +++ b/src/test/rustdoc/issue-80559.rs @@ -0,0 +1,4 @@ +#![deny(broken_intra_doc_links)] +// Should link to https://doc.rust-lang.org/nightly/std/primitive.str.html#method.trim +// and not suggest prefixing with `prim@` +//! [str::trim()] From e33a205bdfb0fbbbad80f49e4d39180dc78087bf Mon Sep 17 00:00:00 2001 From: max-heller Date: Sun, 3 Jan 2021 20:34:07 -0500 Subject: [PATCH 03/18] primitive disambiguator tests --- .../rustdoc/intra-doc/incompatible-primitive-disambiguator.rs | 2 ++ src/test/rustdoc/intra-doc/primitive-disambiguators.rs | 4 ++++ src/test/rustdoc/issue-80559.rs | 4 ---- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 src/test/rustdoc/intra-doc/incompatible-primitive-disambiguator.rs create mode 100644 src/test/rustdoc/intra-doc/primitive-disambiguators.rs delete mode 100644 src/test/rustdoc/issue-80559.rs diff --git a/src/test/rustdoc/intra-doc/incompatible-primitive-disambiguator.rs b/src/test/rustdoc/intra-doc/incompatible-primitive-disambiguator.rs new file mode 100644 index 00000000000..1ea6ad9c7e6 --- /dev/null +++ b/src/test/rustdoc/intra-doc/incompatible-primitive-disambiguator.rs @@ -0,0 +1,2 @@ +#![deny(broken_intra_doc_links)] +//! [struct@str::trim] //~ ERROR incompatible link diff --git a/src/test/rustdoc/intra-doc/primitive-disambiguators.rs b/src/test/rustdoc/intra-doc/primitive-disambiguators.rs new file mode 100644 index 00000000000..acdd07566c9 --- /dev/null +++ b/src/test/rustdoc/intra-doc/primitive-disambiguators.rs @@ -0,0 +1,4 @@ +#![deny(broken_intra_doc_links)] +// @has primitive_disambiguators/index.html +// @has - '//a/@href' 'https://doc.rust-lang.org/nightly/std/primitive.str.html#method.trim' +//! [str::trim()] diff --git a/src/test/rustdoc/issue-80559.rs b/src/test/rustdoc/issue-80559.rs deleted file mode 100644 index 34905c48653..00000000000 --- a/src/test/rustdoc/issue-80559.rs +++ /dev/null @@ -1,4 +0,0 @@ -#![deny(broken_intra_doc_links)] -// Should link to https://doc.rust-lang.org/nightly/std/primitive.str.html#method.trim -// and not suggest prefixing with `prim@` -//! [str::trim()] From fc3a4058cefc09bebe98039c7fb8d74d1be9c6e6 Mon Sep 17 00:00:00 2001 From: max-heller Date: Sun, 3 Jan 2021 20:35:18 -0500 Subject: [PATCH 04/18] still verify disambiguators for primitives --- .../passes/collect_intra_doc_links.rs | 104 ++++++++++-------- 1 file changed, 57 insertions(+), 47 deletions(-) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index fd63d5eb5c9..090c45b30ff 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1146,60 +1146,70 @@ impl LinkCollector<'_, '_> { callback, ); }; - match res { - Res::Primitive(_) if self.kind_side_channel.get().is_none() => match disambiguator { - Some(Disambiguator::Primitive | Disambiguator::Namespace(_)) | None => { - Some(ItemLink { link: ori_link.link, link_text, did: None, fragment }) - } - Some(other) => { - report_mismatch(other, Disambiguator::Primitive); - None - } - }, - Res::Primitive(_) => Some(ItemLink { link: ori_link, link_text, did: None, fragment }), - Res::Def(kind, id) => { - debug!("intra-doc link to {} resolved to {:?}", path_str, res); - // Disallow e.g. linking to enums with `struct@` - debug!("saw kind {:?} with disambiguator {:?}", kind, disambiguator); - match (self.kind_side_channel.take().map(|(kind, _)| kind).unwrap_or(kind), disambiguator) { - | (DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst, Some(Disambiguator::Kind(DefKind::Const))) - // NOTE: this allows 'method' to mean both normal functions and associated functions - // This can't cause ambiguity because both are in the same namespace. - | (DefKind::Fn | DefKind::AssocFn, Some(Disambiguator::Kind(DefKind::Fn))) - // These are namespaces; allow anything in the namespace to match - | (_, Some(Disambiguator::Namespace(_))) - // If no disambiguator given, allow anything - | (_, None) - // All of these are valid, so do nothing - => {} - (actual, Some(Disambiguator::Kind(expected))) if actual == expected => {} - (_, Some(specified @ Disambiguator::Kind(_) | specified @ Disambiguator::Primitive)) => { - report_mismatch(specified, Disambiguator::Kind(kind)); - return None; + let (kind, id) = match res { + Res::Primitive(_) => { + if let Some((kind, id)) = self.kind_side_channel.take() { + (kind, id) + } else { + match disambiguator { + Some(Disambiguator::Primitive | Disambiguator::Namespace(_)) | None => { + return Some(ItemLink { + link: ori_link.link, + link_text, + did: None, + fragment, + }); + } + Some(other) => { + report_mismatch(other, Disambiguator::Primitive); + return None; + } } } + } + Res::Def(kind, id) => (kind, id), + }; - // item can be non-local e.g. when using #[doc(primitive = "pointer")] - if let Some((src_id, dst_id)) = id - .as_local() - .and_then(|dst_id| item.def_id.as_local().map(|src_id| (src_id, dst_id))) - { - use rustc_hir::def_id::LOCAL_CRATE; + debug!("intra-doc link to {} resolved to {:?}", path_str, res); - let hir_src = self.cx.tcx.hir().local_def_id_to_hir_id(src_id); - let hir_dst = self.cx.tcx.hir().local_def_id_to_hir_id(dst_id); - - if self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_src) - && !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst) - { - privacy_error(cx, &item, &path_str, dox, &ori_link); - } - } - let id = clean::register_res(cx, rustc_hir::def::Res::Def(kind, id)); - Some(ItemLink { link: ori_link.link, link_text, did: Some(id), fragment }) + // Disallow e.g. linking to enums with `struct@` + debug!("saw kind {:?} with disambiguator {:?}", kind, disambiguator); + match (self.kind_side_channel.take().map(|(kind, _)| kind).unwrap_or(kind), disambiguator) { + | (DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst, Some(Disambiguator::Kind(DefKind::Const))) + // NOTE: this allows 'method' to mean both normal functions and associated functions + // This can't cause ambiguity because both are in the same namespace. + | (DefKind::Fn | DefKind::AssocFn, Some(Disambiguator::Kind(DefKind::Fn))) + // These are namespaces; allow anything in the namespace to match + | (_, Some(Disambiguator::Namespace(_))) + // If no disambiguator given, allow anything + | (_, None) + // All of these are valid, so do nothing + => {} + (actual, Some(Disambiguator::Kind(expected))) if actual == expected => {} + (_, Some(specified @ Disambiguator::Kind(_) | specified @ Disambiguator::Primitive)) => { + report_mismatch(specified, Disambiguator::Kind(kind)); + return None; } } + + // item can be non-local e.g. when using #[doc(primitive = "pointer")] + if let Some((src_id, dst_id)) = + id.as_local().and_then(|dst_id| item.def_id.as_local().map(|src_id| (src_id, dst_id))) + { + use rustc_hir::def_id::LOCAL_CRATE; + + let hir_src = self.cx.tcx.hir().local_def_id_to_hir_id(src_id); + let hir_dst = self.cx.tcx.hir().local_def_id_to_hir_id(dst_id); + + if self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_src) + && !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst) + { + privacy_error(cx, &item, &path_str, dox, &ori_link); + } + } + let id = clean::register_res(cx, rustc_hir::def::Res::Def(kind, id)); + Some(ItemLink { link: ori_link.link, link_text, did: Some(id), fragment }) } fn resolve_with_disambiguator_cached( From 06b0900a2dc53ed4b5fa98c859fec5c224929eb8 Mon Sep 17 00:00:00 2001 From: max-heller Date: Sun, 3 Jan 2021 21:55:53 -0500 Subject: [PATCH 05/18] half working --- .../passes/collect_intra_doc_links.rs | 101 +++++++++--------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 090c45b30ff..f8e37d7bb56 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1147,69 +1147,70 @@ impl LinkCollector<'_, '_> { ); }; - let (kind, id) = match res { + let verify = |kind: DefKind, id: DefId| { + debug!("intra-doc link to {} resolved to {:?}", path_str, res); + + // Disallow e.g. linking to enums with `struct@` + debug!("saw kind {:?} with disambiguator {:?}", kind, disambiguator); + match (self.kind_side_channel.take().map(|(kind, _)| kind).unwrap_or(kind), disambiguator) { + | (DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst, Some(Disambiguator::Kind(DefKind::Const))) + // NOTE: this allows 'method' to mean both normal functions and associated functions + // This can't cause ambiguity because both are in the same namespace. + | (DefKind::Fn | DefKind::AssocFn, Some(Disambiguator::Kind(DefKind::Fn))) + // These are namespaces; allow anything in the namespace to match + | (_, Some(Disambiguator::Namespace(_))) + // If no disambiguator given, allow anything + | (_, None) + // All of these are valid, so do nothing + => {} + (actual, Some(Disambiguator::Kind(expected))) if actual == expected => {} + (_, Some(specified @ Disambiguator::Kind(_) | specified @ Disambiguator::Primitive)) => { + report_mismatch(specified, Disambiguator::Kind(kind)); + return None; + } + } + + // item can be non-local e.g. when using #[doc(primitive = "pointer")] + if let Some((src_id, dst_id)) = id + .as_local() + .and_then(|dst_id| item.def_id.as_local().map(|src_id| (src_id, dst_id))) + { + use rustc_hir::def_id::LOCAL_CRATE; + + let hir_src = self.cx.tcx.hir().local_def_id_to_hir_id(src_id); + let hir_dst = self.cx.tcx.hir().local_def_id_to_hir_id(dst_id); + + if self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_src) + && !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst) + { + privacy_error(cx, &item, &path_str, dox, &ori_link); + } + } + + Some((kind, id)) + }; + + match res { Res::Primitive(_) => { if let Some((kind, id)) = self.kind_side_channel.take() { - (kind, id) + verify(kind, id)?; } else { match disambiguator { - Some(Disambiguator::Primitive | Disambiguator::Namespace(_)) | None => { - return Some(ItemLink { - link: ori_link.link, - link_text, - did: None, - fragment, - }); - } + Some(Disambiguator::Primitive | Disambiguator::Namespace(_)) | None => {} Some(other) => { report_mismatch(other, Disambiguator::Primitive); return None; } } } + Some(ItemLink { link: ori_link.link, link_text, did: None, fragment }) } - Res::Def(kind, id) => (kind, id), - }; - - debug!("intra-doc link to {} resolved to {:?}", path_str, res); - - // Disallow e.g. linking to enums with `struct@` - debug!("saw kind {:?} with disambiguator {:?}", kind, disambiguator); - match (self.kind_side_channel.take().map(|(kind, _)| kind).unwrap_or(kind), disambiguator) { - | (DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst, Some(Disambiguator::Kind(DefKind::Const))) - // NOTE: this allows 'method' to mean both normal functions and associated functions - // This can't cause ambiguity because both are in the same namespace. - | (DefKind::Fn | DefKind::AssocFn, Some(Disambiguator::Kind(DefKind::Fn))) - // These are namespaces; allow anything in the namespace to match - | (_, Some(Disambiguator::Namespace(_))) - // If no disambiguator given, allow anything - | (_, None) - // All of these are valid, so do nothing - => {} - (actual, Some(Disambiguator::Kind(expected))) if actual == expected => {} - (_, Some(specified @ Disambiguator::Kind(_) | specified @ Disambiguator::Primitive)) => { - report_mismatch(specified, Disambiguator::Kind(kind)); - return None; + Res::Def(kind, id) => { + let (kind, id) = verify(kind, id)?; + let id = clean::register_res(cx, rustc_hir::def::Res::Def(kind, id)); + Some(ItemLink { link: ori_link.link, link_text, did: Some(id), fragment }) } } - - // item can be non-local e.g. when using #[doc(primitive = "pointer")] - if let Some((src_id, dst_id)) = - id.as_local().and_then(|dst_id| item.def_id.as_local().map(|src_id| (src_id, dst_id))) - { - use rustc_hir::def_id::LOCAL_CRATE; - - let hir_src = self.cx.tcx.hir().local_def_id_to_hir_id(src_id); - let hir_dst = self.cx.tcx.hir().local_def_id_to_hir_id(dst_id); - - if self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_src) - && !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst) - { - privacy_error(cx, &item, &path_str, dox, &ori_link); - } - } - let id = clean::register_res(cx, rustc_hir::def::Res::Def(kind, id)); - Some(ItemLink { link: ori_link.link, link_text, did: Some(id), fragment }) } fn resolve_with_disambiguator_cached( From e4aa99fe7afaabf846d9c67dc68364e7661a0bde Mon Sep 17 00:00:00 2001 From: Rich Kadel Date: Sat, 2 Jan 2021 09:40:15 -0800 Subject: [PATCH 06/18] Inlining enabled by -mir-opt-level > 1 is incompatible with coverage Fixes: #80060 Also adds additional test cases for coverage of doctests. --- compiler/rustc_mir/src/transform/inline.rs | 9 ++ compiler/rustc_session/src/config.rs | 10 +- .../expected_show_coverage.doctest.txt | 124 +++++++++++------- ...est.main.-------.InstrumentCoverage.0.html | 104 +++++++-------- .../run-make-fulldeps/coverage/doctest.rs | 43 +++++- .../inline-instrument-coverage-fail.rs | 21 +++ .../inline-instrument-coverage-fail.stderr | 2 + 7 files changed, 210 insertions(+), 103 deletions(-) create mode 100644 src/test/ui/mir/mir-inlining/inline-instrument-coverage-fail.rs create mode 100644 src/test/ui/mir/mir-inlining/inline-instrument-coverage-fail.stderr diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index 6e7575c1d71..f06172ab7da 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -41,6 +41,15 @@ impl<'tcx> MirPass<'tcx> for Inline { return; } + if tcx.sess.opts.debugging_opts.instrument_coverage { + // Since `Inline` happens after `InstrumentCoverage`, the function-specific coverage + // counters can be invalidated, such as by merging coverage counter statements from + // a pre-inlined function into a different function. This kind of change is invalid, + // so inlining must be skipped. Note: This check is performed here so inlining can + // be disabled without preventing other optimizations (regardless of `mir_opt_level`). + return; + } + if inline(tcx, body) { debug!("running simplify cfg on {:?}", body.source); CfgSimplifier::new(body).simplify(); diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index c9ddcbdb5f5..e42889670b9 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1830,11 +1830,17 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { } if debugging_opts.mir_opt_level > 1 { + // Functions inlined during MIR transform can, at best, make it impossible to + // effectively cover inlined functions, and, at worst, break coverage map generation + // during LLVM codegen. For example, function counter IDs are only unique within a + // function. Inlining after these counters are injected can produce duplicate counters, + // resulting in an invalid coverage map (and ICE); so this option combination is not + // allowed. early_warn( error_format, &format!( - "`-Z mir-opt-level={}` (any level > 1) enables function inlining, which \ - limits the effectiveness of `-Z instrument-coverage`.", + "`-Z mir-opt-level={}` (or any level > 1) enables function inlining, which \ + is incompatible with `-Z instrument-coverage`. Inlining will be disabled.", debugging_opts.mir_opt_level, ), ); diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.doctest.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.doctest.txt index e1731c7223c..8f67170561a 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.doctest.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.doctest.txt @@ -21,50 +21,86 @@ 20| |//! 21| |//! doctest returning a result: 22| 1|//! ``` - 23| 1|//! #[derive(Debug)] - 24| 1|//! struct SomeError; - 25| 1|//! let mut res = Err(SomeError); - 26| 1|//! if res.is_ok() { - 27| 0|//! res?; - 28| 1|//! } else { - 29| 1|//! res = Ok(0); - 30| 1|//! } - 31| |//! // need to be explicit because rustdoc cant infer the return type - 32| 1|//! Ok::<(), SomeError>(()) - 33| 1|//! ``` - 34| |//! - 35| |//! doctest with custom main: - 36| |//! ``` - 37| |//! #[derive(Debug)] - 38| |//! struct SomeError; - 39| |//! - 40| |//! extern crate doctest_crate; - 41| |//! - 42| 1|//! fn doctest_main() -> Result<(), SomeError> { - 43| 1|//! doctest_crate::fn_run_in_doctests(2); - 44| 1|//! Ok(()) - 45| 1|//! } - 46| |//! - 47| |//! // this `main` is not shown as covered, as it clashes with all the other - 48| |//! // `main` functions that were automatically generated for doctests - 49| |//! fn main() -> Result<(), SomeError> { - 50| |//! doctest_main() - 51| |//! } - 52| |//! ``` - 53| | - 54| |/// doctest attached to fn testing external code: - 55| |/// ``` - 56| 1|/// extern crate doctest_crate; - 57| 1|/// doctest_crate::fn_run_in_doctests(3); - 58| 1|/// ``` - 59| |/// - 60| 1|fn main() { - 61| 1| if true { - 62| 1| assert_eq!(1, 1); - 63| | } else { - 64| | assert_eq!(1, 2); - 65| | } - 66| 1|} + 23| 2|//! #[derive(Debug, PartialEq)] + ^1 + 24| 1|//! struct SomeError { + 25| 1|//! msg: String, + 26| 1|//! } + 27| 1|//! let mut res = Err(SomeError { msg: String::from("a message") }); + 28| 1|//! if res.is_ok() { + 29| 0|//! res?; + 30| |//! } else { + 31| 1|//! if *res.as_ref().unwrap_err() == *res.as_ref().unwrap_err() { + 32| 1|//! println!("{:?}", res); + 33| 1|//! } + ^0 + 34| 1|//! if *res.as_ref().unwrap_err() == *res.as_ref().unwrap_err() { + 35| 1|//! res = Ok(1); + 36| 1|//! } + ^0 + 37| 1|//! res = Ok(0); + 38| |//! } + 39| |//! // need to be explicit because rustdoc cant infer the return type + 40| 1|//! Ok::<(), SomeError>(()) + 41| 1|//! ``` + 42| |//! + 43| |//! doctest with custom main: + 44| |//! ``` + 45| 1|//! fn some_func() { + 46| 1|//! println!("called some_func()"); + 47| 1|//! } + 48| |//! + 49| |//! #[derive(Debug)] + 50| |//! struct SomeError; + 51| |//! + 52| |//! extern crate doctest_crate; + 53| |//! + 54| 1|//! fn doctest_main() -> Result<(), SomeError> { + 55| 1|//! some_func(); + 56| 1|//! doctest_crate::fn_run_in_doctests(2); + 57| 1|//! Ok(()) + 58| 1|//! } + 59| |//! + 60| |//! // this `main` is not shown as covered, as it clashes with all the other + 61| |//! // `main` functions that were automatically generated for doctests + 62| |//! fn main() -> Result<(), SomeError> { + 63| |//! doctest_main() + 64| |//! } + 65| |//! ``` + 66| | + 67| |/// doctest attached to fn testing external code: + 68| |/// ``` + 69| 1|/// extern crate doctest_crate; + 70| 1|/// doctest_crate::fn_run_in_doctests(3); + 71| 1|/// ``` + 72| |/// + 73| 1|fn main() { + 74| 1| if true { + 75| 1| assert_eq!(1, 1); + 76| | } else { + 77| | assert_eq!(1, 2); + 78| | } + 79| 1|} + 80| | + 81| |// FIXME(Swatinem): Fix known issue that coverage code region columns need to be offset by the + 82| |// doc comment line prefix (`///` or `//!`) and any additional indent (before or after the doc + 83| |// comment characters). This test produces `llvm-cov show` results demonstrating the problem. + 84| |// + 85| |// One of the above tests now includes: `derive(Debug, PartialEq)`, producing an `llvm-cov show` + 86| |// result with a distinct count for `Debug`, denoted by `^1`, but the caret points to the wrong + 87| |// column. Similarly, the `if` blocks without `else` blocks show `^0`, which should point at, or + 88| |// one character past, the `if` block's closing brace. In both cases, these are most likely off + 89| |// by the number of characters stripped from the beginning of each doc comment line: indent + 90| |// whitespace, if any, doc comment prefix (`//!` in this case) and (I assume) one space character + 91| |// (?). Note, when viewing `llvm-cov show` results in `--color` mode, the column offset errors are + 92| |// more pronounced, and show up in more places, with background color used to show some distinct + 93| |// code regions with different coverage counts. + 94| |// + 95| |// NOTE: Since the doc comment line prefix may vary, one possible solution is to replace each + 96| |// character stripped from the beginning of doc comment lines with a space. This will give coverage + 97| |// results the correct column offsets, and I think it should compile correctly, but I don't know + 98| |// what affect it might have on diagnostic messages from the compiler, and whether anyone would care + 99| |// if the indentation changed. I don't know if there is a more viable solution. ../coverage/lib/doctest_crate.rs: 1| |/// A function run only from within doctests diff --git a/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.doctest/doctest.main.-------.InstrumentCoverage.0.html b/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.doctest/doctest.main.-------.InstrumentCoverage.0.html index 8d074558aae..333476a2df5 100644 --- a/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.doctest/doctest.main.-------.InstrumentCoverage.0.html +++ b/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.doctest/doctest.main.-------.InstrumentCoverage.0.html @@ -69,59 +69,59 @@ For revisions in Pull Requests (PR): -
@0⦊fn main() ⦉@0{ - if @0⦊true⦉@0 { - @5⦊@4,6,7,8,9⦊assert_eq!(1, 1);⦉@4,6,7,8,9⦉@5 +
@0⦊fn main() ⦉@0{ + if @0⦊true⦉@0 { + @5⦊@4,6,7,8,9⦊assert_eq!(1, 1);⦉@4,6,7,8,9⦉@5 } else { - @11⦊@10,12,13,14,15⦊assert_eq!(1, 2);⦉@10,12,13,14,15⦉@11 + @11⦊@10,12,13,14,15⦊assert_eq!(1, 2);⦉@10,12,13,14,15⦉@11 } -}@16⦊⦉@16
+}@16⦊⦉@16
diff --git a/src/test/run-make-fulldeps/coverage/doctest.rs b/src/test/run-make-fulldeps/coverage/doctest.rs index e41d669bf0c..ec04ea57063 100644 --- a/src/test/run-make-fulldeps/coverage/doctest.rs +++ b/src/test/run-make-fulldeps/coverage/doctest.rs @@ -20,13 +20,21 @@ //! //! doctest returning a result: //! ``` -//! #[derive(Debug)] -//! struct SomeError; -//! let mut res = Err(SomeError); +//! #[derive(Debug, PartialEq)] +//! struct SomeError { +//! msg: String, +//! } +//! let mut res = Err(SomeError { msg: String::from("a message") }); //! if res.is_ok() { -//! res?; +//! res?; //! } else { -//! res = Ok(0); +//! if *res.as_ref().unwrap_err() == *res.as_ref().unwrap_err() { +//! println!("{:?}", res); +//! } +//! if *res.as_ref().unwrap_err() == *res.as_ref().unwrap_err() { +//! res = Ok(1); +//! } +//! res = Ok(0); //! } //! // need to be explicit because rustdoc cant infer the return type //! Ok::<(), SomeError>(()) @@ -34,12 +42,17 @@ //! //! doctest with custom main: //! ``` +//! fn some_func() { +//! println!("called some_func()"); +//! } +//! //! #[derive(Debug)] //! struct SomeError; //! //! extern crate doctest_crate; //! //! fn doctest_main() -> Result<(), SomeError> { +//! some_func(); //! doctest_crate::fn_run_in_doctests(2); //! Ok(()) //! } @@ -64,3 +77,23 @@ fn main() { assert_eq!(1, 2); } } + +// FIXME(Swatinem): Fix known issue that coverage code region columns need to be offset by the +// doc comment line prefix (`///` or `//!`) and any additional indent (before or after the doc +// comment characters). This test produces `llvm-cov show` results demonstrating the problem. +// +// One of the above tests now includes: `derive(Debug, PartialEq)`, producing an `llvm-cov show` +// result with a distinct count for `Debug`, denoted by `^1`, but the caret points to the wrong +// column. Similarly, the `if` blocks without `else` blocks show `^0`, which should point at, or +// one character past, the `if` block's closing brace. In both cases, these are most likely off +// by the number of characters stripped from the beginning of each doc comment line: indent +// whitespace, if any, doc comment prefix (`//!` in this case) and (I assume) one space character +// (?). Note, when viewing `llvm-cov show` results in `--color` mode, the column offset errors are +// more pronounced, and show up in more places, with background color used to show some distinct +// code regions with different coverage counts. +// +// NOTE: Since the doc comment line prefix may vary, one possible solution is to replace each +// character stripped from the beginning of doc comment lines with a space. This will give coverage +// results the correct column offsets, and I think it should compile correctly, but I don't know +// what affect it might have on diagnostic messages from the compiler, and whether anyone would care +// if the indentation changed. I don't know if there is a more viable solution. diff --git a/src/test/ui/mir/mir-inlining/inline-instrument-coverage-fail.rs b/src/test/ui/mir/mir-inlining/inline-instrument-coverage-fail.rs new file mode 100644 index 00000000000..2437155d981 --- /dev/null +++ b/src/test/ui/mir/mir-inlining/inline-instrument-coverage-fail.rs @@ -0,0 +1,21 @@ +// Ensures -Zmir-opt-level=2 (specifically, inlining) is not allowed with -Zinstrument-coverage. +// Regression test for issue #80060. +// +// needs-profiler-support +// build-pass +// compile-flags: -Zmir-opt-level=2 -Zinstrument-coverage +#[inline(never)] +fn foo() {} + +pub fn baz() { + bar(); +} + +#[inline(always)] +fn bar() { + foo(); +} + +fn main() { + bar(); +} diff --git a/src/test/ui/mir/mir-inlining/inline-instrument-coverage-fail.stderr b/src/test/ui/mir/mir-inlining/inline-instrument-coverage-fail.stderr new file mode 100644 index 00000000000..eb50e5075ca --- /dev/null +++ b/src/test/ui/mir/mir-inlining/inline-instrument-coverage-fail.stderr @@ -0,0 +1,2 @@ +warning: `-Z mir-opt-level=2` (or any level > 1) enables function inlining, which is incompatible with `-Z instrument-coverage`. Inlining will be disabled. + From 6f0413316f786dc27de5af8d15a070f368f8746d Mon Sep 17 00:00:00 2001 From: max-heller Date: Mon, 4 Jan 2021 15:38:30 -0500 Subject: [PATCH 07/18] fix incompatible disambiguator test --- .../incompatible-primitive-disambiguator.rs | 3 +++ .../incompatible-primitive-disambiguator.stderr | 15 +++++++++++++++ .../incompatible-primitive-disambiguator.rs | 2 -- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs create mode 100644 src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr delete mode 100644 src/test/rustdoc/intra-doc/incompatible-primitive-disambiguator.rs diff --git a/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs new file mode 100644 index 00000000000..0d1d5d1134b --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs @@ -0,0 +1,3 @@ +#![deny(broken_intra_doc_links)] +//! [static@u8::MIN] +//~^ ERROR incompatible link kind diff --git a/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr new file mode 100644 index 00000000000..ed1c10f9e0c --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr @@ -0,0 +1,15 @@ +error: incompatible link kind for `u8::MIN` + --> $DIR/incompatible-primitive-disambiguator.rs:2:6 + | +LL | //! [static@u8::MIN] + | ^^^^^^^^^^^^^^ help: to link to the associated constant, prefix with `const@`: `const@u8::MIN` + | +note: the lint level is defined here + --> $DIR/incompatible-primitive-disambiguator.rs:1:9 + | +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ + = note: this link resolved to an associated constant, which is not a static + +error: aborting due to previous error + diff --git a/src/test/rustdoc/intra-doc/incompatible-primitive-disambiguator.rs b/src/test/rustdoc/intra-doc/incompatible-primitive-disambiguator.rs deleted file mode 100644 index 1ea6ad9c7e6..00000000000 --- a/src/test/rustdoc/intra-doc/incompatible-primitive-disambiguator.rs +++ /dev/null @@ -1,2 +0,0 @@ -#![deny(broken_intra_doc_links)] -//! [struct@str::trim] //~ ERROR incompatible link From 2bdbb0d1b4a8be7e8fef6d1e35856190f5c91e0f Mon Sep 17 00:00:00 2001 From: max-heller Date: Tue, 5 Jan 2021 15:15:25 -0500 Subject: [PATCH 08/18] Document hackiness around primitive associated item disambiguators --- src/librustdoc/passes/collect_intra_doc_links.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index f8e37d7bb56..11ee59b2401 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1193,6 +1193,14 @@ impl LinkCollector<'_, '_> { match res { Res::Primitive(_) => { if let Some((kind, id)) = self.kind_side_channel.take() { + // We're actually resolving an associated item of a primitive, so we need to + // verify the disambiguator (if any) matches the type of the associated item. + // This case should really follow the same flow as the `Res::Def` branch below, + // but attempting to add a call to `clean::register_res` causes an ICE. @jyn514 + // thinks `register_res` is only needed for cross-crate re-exports, but Rust + // doesn't allow statements like `use str::trim;`, making this a (hopefully) + // valid omission. See https://github.com/rust-lang/rust/pull/80660#discussion_r551585677 + // for discussion on the matter. verify(kind, id)?; } else { match disambiguator { From aea9a4b449c0b7006c65b9dfb5818a9bdf6fab86 Mon Sep 17 00:00:00 2001 From: Aru Sahni Date: Tue, 5 Jan 2021 18:53:23 -0500 Subject: [PATCH 09/18] Remove bottom margin from crate version when the sidebar is collapsed. This fixes a mobile UI bug where a vertical scrollbar would always be rendered on the sidebar nav when the menu was closed. --- src/librustdoc/html/static/rustdoc.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 28b118ea78e..8dad26dced9 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1412,6 +1412,7 @@ h4 > .notable-traits { .sidebar > .block.version { border-bottom: none; margin-top: 12px; + margin-bottom: 0; } nav.sub { From e636805eee49ff2e8bc30429ab91a8e2508656b3 Mon Sep 17 00:00:00 2001 From: Camelid Date: Tue, 5 Jan 2021 16:32:50 -0800 Subject: [PATCH 10/18] rustdoc: Turn `next_def_id` comments into docs --- src/librustdoc/clean/types.rs | 4 +++- src/librustdoc/core.rs | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index cc31461646c..0364bfd5951 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -291,7 +291,9 @@ impl Item { } } - /// See comments on next_def_id + /// See the documentation for [`next_def_id()`]. + /// + /// [`next_def_id()`]: crate::core::DocContext::next_def_id() crate fn is_fake(&self) -> bool { MAX_DEF_ID.with(|m| { m.borrow().get(&self.def_id.krate).map(|id| self.def_id >= *id).unwrap_or(false) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 4aeca0faea7..ac3b8895996 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -120,14 +120,20 @@ impl<'tcx> DocContext<'tcx> { r } - // This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly - // refactoring either librustdoc or librustc_middle. In particular, allowing new DefIds to be - // registered after the AST is constructed would require storing the defid mapping in a - // RefCell, decreasing the performance for normal compilation for very little gain. - // - // Instead, we construct 'fake' def ids, which start immediately after the last DefId. - // In the Debug impl for clean::Item, we explicitly check for fake - // def ids, as we'll end up with a panic if we use the DefId Debug impl for fake DefIds + /// Create a new "fake" [`DefId`]. + /// + /// This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly + /// refactoring either `librustdoc` or [`rustc_middle`]. In particular, allowing new [`DefId`]s + /// to be registered after the AST is constructed would require storing the [`DefId`] mapping + /// in a [`RefCell`], decreasing the performance for normal compilation for very little gain. + /// + /// Instead, we construct "fake" [`DefId`]s, which start immediately after the last `DefId`. + /// In the [`Debug`] impl for [`clean::Item`], we explicitly check for fake `DefId`s, + /// as we'll end up with a panic if we use the `DefId` `Debug` impl for fake `DefId`s. + /// + /// [`RefCell`]: std::cell::RefCell + /// [`Debug`]: std::fmt::Debug + /// [`clean::Item`]: crate::clean::types::Item crate fn next_def_id(&self, crate_num: CrateNum) -> DefId { let start_def_id = { let num_def_ids = if crate_num == LOCAL_CRATE { From 7428e2d1349fe03da821ee2181ccf7395b9cfe30 Mon Sep 17 00:00:00 2001 From: Camelid Date: Tue, 5 Jan 2021 19:46:51 -0800 Subject: [PATCH 11/18] Apply suggestions from code review Co-authored-by: Joshua Nelson --- src/librustdoc/clean/types.rs | 2 +- src/librustdoc/core.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 0364bfd5951..38791fcea54 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -293,7 +293,7 @@ impl Item { /// See the documentation for [`next_def_id()`]. /// - /// [`next_def_id()`]: crate::core::DocContext::next_def_id() + /// [`next_def_id()`]: DocContext::next_def_id() crate fn is_fake(&self) -> bool { MAX_DEF_ID.with(|m| { m.borrow().get(&self.def_id.krate).map(|id| self.def_id >= *id).unwrap_or(false) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index ac3b8895996..43aaefa0870 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -123,7 +123,7 @@ impl<'tcx> DocContext<'tcx> { /// Create a new "fake" [`DefId`]. /// /// This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly - /// refactoring either `librustdoc` or [`rustc_middle`]. In particular, allowing new [`DefId`]s + /// refactoring either rustdoc or [`rustc_middle`]. In particular, allowing new [`DefId`]s /// to be registered after the AST is constructed would require storing the [`DefId`] mapping /// in a [`RefCell`], decreasing the performance for normal compilation for very little gain. /// From 7bc22e96d38828070ac7bf60dbc41e2455422af4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 6 Jan 2021 10:59:50 +0100 Subject: [PATCH 12/18] Don't use to_string on Symbol --- compiler/rustc_passes/src/check_attr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 420c002c5fc..a6a61ffc5da 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -359,7 +359,7 @@ impl CheckAttrVisitor<'tcx> { return false; } let item_name = self.tcx.hir().name(hir_id); - if item_name.to_string() == doc_alias { + if &*item_name.as_str() == doc_alias { self.tcx .sess .struct_span_err( From 2b8109f229b83d8c2b90b444a9077111e0877bb0 Mon Sep 17 00:00:00 2001 From: Ejez <48388358+ejez@users.noreply.github.com> Date: Thu, 7 Jan 2021 07:47:03 +0300 Subject: [PATCH 13/18] Improve wording of parse doc Change: ``` `parse` can parse any type that... ``` to: ``` `parse` can parse into any type that... ``` Word `into` added to be more precise and in coherence with other parts of the doc. --- library/core/src/str/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index ba495a1a9fb..ae7892291ed 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -2175,7 +2175,7 @@ impl str { /// helps the inference algorithm understand specifically which type /// you're trying to parse into. /// - /// `parse` can parse any type that implements the [`FromStr`] trait. + /// `parse` can parse into any type that implements the [`FromStr`] trait. /// /// # Errors From f03907b33f73c4fd0e3f3b4ddb8f1301f5eafd0e Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Mon, 14 Dec 2020 00:32:59 +0900 Subject: [PATCH 14/18] Add pointing const identifier when emitting E0435 --- compiler/rustc_resolve/src/diagnostics.rs | 8 ++++- compiler/rustc_resolve/src/late.rs | 38 +++++++++++++++------ compiler/rustc_resolve/src/lib.rs | 40 ++++++++++++++++++----- 3 files changed, 67 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 809de9beff6..6a181dbab5a 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -398,13 +398,19 @@ impl<'a> Resolver<'a> { err.help("use the `|| { ... }` closure form instead"); err } - ResolutionError::AttemptToUseNonConstantValueInConstant => { + ResolutionError::AttemptToUseNonConstantValueInConstant(ident, sugg) => { let mut err = struct_span_err!( self.session, span, E0435, "attempt to use a non-constant value in a constant" ); + err.span_suggestion( + ident.span, + &sugg, + "".to_string(), + Applicability::MaybeIncorrect, + ); err.span_label(span, "non-constant value"); err } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index fbe99a31150..fbaec149d54 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -92,6 +92,12 @@ crate enum HasGenericParams { No, } +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +crate enum ConstantItemKind { + Const, + Static, +} + /// The rib kind restricts certain accesses, /// e.g. to a `Res::Local` of an outer item. #[derive(Copy, Clone, Debug)] @@ -119,7 +125,7 @@ crate enum RibKind<'a> { /// /// The `bool` indicates if this constant may reference generic parameters /// and is used to only allow generic parameters to be used in trivial constant expressions. - ConstantItemRibKind(bool), + ConstantItemRibKind(bool, Option<(Ident, ConstantItemKind)>), /// We passed through a module. ModuleRibKind(Module<'a>), @@ -145,7 +151,7 @@ impl RibKind<'_> { NormalRibKind | ClosureOrAsyncRibKind | FnItemRibKind - | ConstantItemRibKind(_) + | ConstantItemRibKind(..) | ModuleRibKind(_) | MacroDefinition(_) | ConstParamTyRibKind => false, @@ -634,7 +640,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { // Note that we might not be inside of an repeat expression here, // but considering that `IsRepeatExpr` is only relevant for // non-trivial constants this is doesn't matter. - self.with_constant_rib(IsRepeatExpr::No, true, |this| { + self.with_constant_rib(IsRepeatExpr::No, true, None, |this| { this.smart_resolve_path( ty.id, qself.as_ref(), @@ -843,7 +849,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { | ClosureOrAsyncRibKind | FnItemRibKind | ItemRibKind(..) - | ConstantItemRibKind(_) + | ConstantItemRibKind(..) | ModuleRibKind(..) | ForwardTyParamBanRibKind | ConstParamTyRibKind => { @@ -970,6 +976,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { this.with_constant_rib( IsRepeatExpr::No, true, + None, |this| this.visit_expr(expr), ); } @@ -1012,11 +1019,19 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { self.with_item_rib(HasGenericParams::No, |this| { this.visit_ty(ty); if let Some(expr) = expr { + let constant_item_kind = match item.kind { + ItemKind::Const(..) => ConstantItemKind::Const, + ItemKind::Static(..) => ConstantItemKind::Static, + _ => unreachable!(), + }; // We already forbid generic params because of the above item rib, // so it doesn't matter whether this is a trivial constant. - this.with_constant_rib(IsRepeatExpr::No, true, |this| { - this.visit_expr(expr) - }); + this.with_constant_rib( + IsRepeatExpr::No, + true, + Some((item.ident, constant_item_kind)), + |this| this.visit_expr(expr), + ); } }); } @@ -1118,15 +1133,16 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { &mut self, is_repeat: IsRepeatExpr, is_trivial: bool, + item: Option<(Ident, ConstantItemKind)>, f: impl FnOnce(&mut Self), ) { debug!("with_constant_rib: is_repeat={:?} is_trivial={}", is_repeat, is_trivial); - self.with_rib(ValueNS, ConstantItemRibKind(is_trivial), |this| { + self.with_rib(ValueNS, ConstantItemRibKind(is_trivial, item), |this| { this.with_rib( TypeNS, - ConstantItemRibKind(is_repeat == IsRepeatExpr::Yes || is_trivial), + ConstantItemRibKind(is_repeat == IsRepeatExpr::Yes || is_trivial, item), |this| { - this.with_label_rib(ConstantItemRibKind(is_trivial), f); + this.with_label_rib(ConstantItemRibKind(is_trivial, item), f); }, ) }); @@ -1266,6 +1282,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { this.with_constant_rib( IsRepeatExpr::No, true, + None, |this| { visit::walk_assoc_item( this, @@ -2200,6 +2217,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { self.with_constant_rib( is_repeat, constant.value.is_potential_trivial_const_param(), + None, |this| { visit::walk_anon_const(this, constant); }, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 0de732b2cf9..ebfe5301b69 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -64,7 +64,7 @@ use tracing::debug; use diagnostics::{extend_span_to_previous_binding, find_span_of_binding_until_next_binding}; use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion}; use imports::{Import, ImportKind, ImportResolver, NameResolution}; -use late::{HasGenericParams, PathSource, Rib, RibKind::*}; +use late::{ConstantItemKind, HasGenericParams, PathSource, Rib, RibKind::*}; use macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef}; type Res = def::Res; @@ -210,7 +210,7 @@ enum ResolutionError<'a> { /// Error E0434: can't capture dynamic environment in a fn item. CannotCaptureDynamicEnvironmentInFnItem, /// Error E0435: attempt to use a non-constant value in a constant. - AttemptToUseNonConstantValueInConstant, + AttemptToUseNonConstantValueInConstant(Ident, String), /// Error E0530: `X` bindings cannot shadow `Y`s. BindingShadowsSomethingUnacceptable(&'static str, Symbol, &'a NameBinding<'a>), /// Error E0128: type parameters with a default cannot use forward-declared identifiers. @@ -1821,14 +1821,16 @@ impl<'a> Resolver<'a> { // Use the rib kind to determine whether we are resolving parameters // (macro 2.0 hygiene) or local variables (`macro_rules` hygiene). let rib_ident = if ribs[i].kind.contains_params() { normalized_ident } else { ident }; - if let Some(res) = ribs[i].bindings.get(&rib_ident).cloned() { + if let Some((original_rib_ident_def, res)) = ribs[i].bindings.get_key_value(&rib_ident) + { // The ident resolves to a type parameter or local variable. return Some(LexicalScopeBinding::Res(self.validate_res_from_ribs( i, rib_ident, - res, + *res, record_used, path_span, + *original_rib_ident_def, ribs, ))); } @@ -2540,6 +2542,7 @@ impl<'a> Resolver<'a> { mut res: Res, record_used: bool, span: Span, + original_rib_ident_def: Ident, all_ribs: &[Rib<'a>], ) -> Res { const CG_BUG_STR: &str = "min_const_generics resolve check didn't stop compilation"; @@ -2586,10 +2589,31 @@ impl<'a> Resolver<'a> { res_err = Some(CannotCaptureDynamicEnvironmentInFnItem); } } - ConstantItemRibKind(_) => { + ConstantItemRibKind(_, item) => { // Still doesn't deal with upvars if record_used { - self.report_error(span, AttemptToUseNonConstantValueInConstant); + let (span, resolution_error) = + if let Some((ident, constant_item_kind)) = item { + let kind_str = match constant_item_kind { + ConstantItemKind::Const => "const", + ConstantItemKind::Static => "static", + }; + let sugg = format!( + "consider using `let` instead of `{}`", + kind_str + ); + (span, AttemptToUseNonConstantValueInConstant(ident, sugg)) + } else { + let sugg = "consider using `const` instead of `let`"; + ( + rib_ident.span, + AttemptToUseNonConstantValueInConstant( + original_rib_ident_def, + sugg.to_string(), + ), + ) + }; + self.report_error(span, resolution_error); } return Res::Err; } @@ -2625,7 +2649,7 @@ impl<'a> Resolver<'a> { in_ty_param_default = true; continue; } - ConstantItemRibKind(trivial) => { + ConstantItemRibKind(trivial, _) => { let features = self.session.features_untracked(); // HACK(min_const_generics): We currently only allow `N` or `{ N }`. if !(trivial @@ -2718,7 +2742,7 @@ impl<'a> Resolver<'a> { in_ty_param_default = true; continue; } - ConstantItemRibKind(trivial) => { + ConstantItemRibKind(trivial, _) => { let features = self.session.features_untracked(); // HACK(min_const_generics): We currently only allow `N` or `{ N }`. if !(trivial From c9e7045e816496298cf2162731af55888f326935 Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Mon, 14 Dec 2020 00:40:59 +0900 Subject: [PATCH 15/18] bless tests --- src/test/ui/error-codes/E0435.stderr | 2 ++ src/test/ui/impl-trait/bindings.stderr | 16 ++++++++++++---- src/test/ui/issues/issue-27433.stderr | 4 +++- src/test/ui/issues/issue-3521-2.stderr | 4 +++- src/test/ui/issues/issue-3521.stderr | 3 +++ src/test/ui/issues/issue-3668-2.stderr | 4 +++- src/test/ui/issues/issue-3668.stderr | 4 +++- src/test/ui/issues/issue-42060.stderr | 4 ++++ src/test/ui/issues/issue-44239.stderr | 3 +++ src/test/ui/non-constant-expr-for-arr-len.stderr | 2 ++ src/test/ui/repeat_count.stderr | 2 ++ .../type/type-dependent-def-issue-49241.stderr | 4 +++- 12 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/test/ui/error-codes/E0435.stderr b/src/test/ui/error-codes/E0435.stderr index 349aa0d07c5..21827d1fd87 100644 --- a/src/test/ui/error-codes/E0435.stderr +++ b/src/test/ui/error-codes/E0435.stderr @@ -1,6 +1,8 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/E0435.rs:3:17 | +LL | let foo = 42u32; + | --- help: consider using `const` instead of `let` LL | let _: [u8; foo]; | ^^^ non-constant value diff --git a/src/test/ui/impl-trait/bindings.stderr b/src/test/ui/impl-trait/bindings.stderr index e983fdecdba..ad5f13d0672 100644 --- a/src/test/ui/impl-trait/bindings.stderr +++ b/src/test/ui/impl-trait/bindings.stderr @@ -2,25 +2,33 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/bindings.rs:5:29 | LL | const foo: impl Clone = x; - | ^ non-constant value + | --- ^ non-constant value + | | + | help: consider using `let` instead of `const` error[E0435]: attempt to use a non-constant value in a constant --> $DIR/bindings.rs:11:33 | LL | const foo: impl Clone = x; - | ^ non-constant value + | --- ^ non-constant value + | | + | help: consider using `let` instead of `const` error[E0435]: attempt to use a non-constant value in a constant --> $DIR/bindings.rs:18:33 | LL | const foo: impl Clone = x; - | ^ non-constant value + | --- ^ non-constant value + | | + | help: consider using `let` instead of `const` error[E0435]: attempt to use a non-constant value in a constant --> $DIR/bindings.rs:25:33 | LL | const foo: impl Clone = x; - | ^ non-constant value + | --- ^ non-constant value + | | + | help: consider using `let` instead of `const` warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/bindings.rs:1:12 diff --git a/src/test/ui/issues/issue-27433.stderr b/src/test/ui/issues/issue-27433.stderr index e232d17e6d7..201b7e8549c 100644 --- a/src/test/ui/issues/issue-27433.stderr +++ b/src/test/ui/issues/issue-27433.stderr @@ -2,7 +2,9 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/issue-27433.rs:3:23 | LL | const FOO : u32 = foo; - | ^^^ non-constant value + | --- ^^^ non-constant value + | | + | help: consider using `let` instead of `const` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-3521-2.stderr b/src/test/ui/issues/issue-3521-2.stderr index d54bbbcdc33..ba29d1becb8 100644 --- a/src/test/ui/issues/issue-3521-2.stderr +++ b/src/test/ui/issues/issue-3521-2.stderr @@ -2,7 +2,9 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/issue-3521-2.rs:4:23 | LL | static y: isize = foo + 1; - | ^^^ non-constant value + | - ^^^ non-constant value + | | + | help: consider using `let` instead of `static` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-3521.stderr b/src/test/ui/issues/issue-3521.stderr index ae199875269..8473526006c 100644 --- a/src/test/ui/issues/issue-3521.stderr +++ b/src/test/ui/issues/issue-3521.stderr @@ -1,6 +1,9 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/issue-3521.rs:6:15 | +LL | let foo = 100; + | --- help: consider using `const` instead of `let` +... LL | Bar = foo | ^^^ non-constant value diff --git a/src/test/ui/issues/issue-3668-2.stderr b/src/test/ui/issues/issue-3668-2.stderr index d6a6e837960..7cee497b0bc 100644 --- a/src/test/ui/issues/issue-3668-2.stderr +++ b/src/test/ui/issues/issue-3668-2.stderr @@ -2,7 +2,9 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/issue-3668-2.rs:2:27 | LL | static child: isize = x + 1; - | ^ non-constant value + | ----- ^ non-constant value + | | + | help: consider using `let` instead of `static` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-3668.stderr b/src/test/ui/issues/issue-3668.stderr index 98cd3631a53..e45472929ab 100644 --- a/src/test/ui/issues/issue-3668.stderr +++ b/src/test/ui/issues/issue-3668.stderr @@ -2,7 +2,9 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/issue-3668.rs:8:34 | LL | static childVal: Box

= self.child.get(); - | ^^^^ non-constant value + | -------- ^^^^ non-constant value + | | + | help: consider using `let` instead of `static` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-42060.stderr b/src/test/ui/issues/issue-42060.stderr index 72408c79194..dc089b856bb 100644 --- a/src/test/ui/issues/issue-42060.stderr +++ b/src/test/ui/issues/issue-42060.stderr @@ -1,12 +1,16 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/issue-42060.rs:3:23 | +LL | let thing = (); + | ----- help: consider using `const` instead of `let` LL | let other: typeof(thing) = thing; | ^^^^^ non-constant value error[E0435]: attempt to use a non-constant value in a constant --> $DIR/issue-42060.rs:9:13 | +LL | let q = 1; + | - help: consider using `const` instead of `let` LL | ::N | ^ non-constant value diff --git a/src/test/ui/issues/issue-44239.stderr b/src/test/ui/issues/issue-44239.stderr index bc5a6a03f03..bbd3d116c96 100644 --- a/src/test/ui/issues/issue-44239.stderr +++ b/src/test/ui/issues/issue-44239.stderr @@ -1,6 +1,9 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/issue-44239.rs:6:26 | +LL | let n = 0; + | - help: consider using `const` instead of `let` +... LL | const N: usize = n; | ^ non-constant value diff --git a/src/test/ui/non-constant-expr-for-arr-len.stderr b/src/test/ui/non-constant-expr-for-arr-len.stderr index b947cb7e19c..01da6bcf49a 100644 --- a/src/test/ui/non-constant-expr-for-arr-len.stderr +++ b/src/test/ui/non-constant-expr-for-arr-len.stderr @@ -1,6 +1,8 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/non-constant-expr-for-arr-len.rs:5:22 | +LL | fn bar(n: usize) { + | - help: consider using `const` instead of `let` LL | let _x = [0; n]; | ^ non-constant value diff --git a/src/test/ui/repeat_count.stderr b/src/test/ui/repeat_count.stderr index 5fcda348ab3..aa1b2e60d51 100644 --- a/src/test/ui/repeat_count.stderr +++ b/src/test/ui/repeat_count.stderr @@ -1,6 +1,8 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/repeat_count.rs:5:17 | +LL | let n = 1; + | - help: consider using `const` instead of `let` LL | let a = [0; n]; | ^ non-constant value diff --git a/src/test/ui/type/type-dependent-def-issue-49241.stderr b/src/test/ui/type/type-dependent-def-issue-49241.stderr index c5dcfa7a431..df791435e88 100644 --- a/src/test/ui/type/type-dependent-def-issue-49241.stderr +++ b/src/test/ui/type/type-dependent-def-issue-49241.stderr @@ -2,7 +2,9 @@ error[E0435]: attempt to use a non-constant value in a constant --> $DIR/type-dependent-def-issue-49241.rs:3:22 | LL | const l: usize = v.count(); - | ^ non-constant value + | - ^ non-constant value + | | + | help: consider using `let` instead of `const` error: aborting due to previous error From c71348a9c6d8c27c4d0a39428b7478c19b0c97d9 Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Sat, 26 Dec 2020 21:15:51 +0900 Subject: [PATCH 16/18] Refine E0435 description --- compiler/rustc_error_codes/src/error_codes/E0435.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_error_codes/src/error_codes/E0435.md b/compiler/rustc_error_codes/src/error_codes/E0435.md index 424e5ce1e2e..798a20d48b6 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0435.md +++ b/compiler/rustc_error_codes/src/error_codes/E0435.md @@ -7,6 +7,12 @@ let foo = 42; let a: [u8; foo]; // error: attempt to use a non-constant value in a constant ``` +'constant' means 'a compile-time value'. + +More details can be found in the [Variables and Mutability] section of the book. + +[Variables and Mutability]: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants + To fix this error, please replace the value with a constant. Example: ``` From f942c3cbf4a49e7f92215d6ee6a7aff1b4e03e90 Mon Sep 17 00:00:00 2001 From: Hanzhen Liang Date: Thu, 7 Jan 2021 13:20:04 +0100 Subject: [PATCH 17/18] Return EOF_CHAR constant instead of magic char. --- compiler/rustc_lexer/src/cursor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lexer/src/cursor.rs b/compiler/rustc_lexer/src/cursor.rs index c0045d3f79b..297f3d19ca1 100644 --- a/compiler/rustc_lexer/src/cursor.rs +++ b/compiler/rustc_lexer/src/cursor.rs @@ -33,7 +33,7 @@ impl<'a> Cursor<'a> { #[cfg(not(debug_assertions))] { - '\0' + EOF_CHAR } } From 0dab0763586bdcc131d775033d010495a7bacc60 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 7 Jan 2021 16:43:22 +0300 Subject: [PATCH 18/18] rustc_parse: Better spans for synthesized token streams --- compiler/rustc_ast/src/token.rs | 2 +- compiler/rustc_ast_lowering/src/lib.rs | 10 +- compiler/rustc_expand/src/base.rs | 2 +- compiler/rustc_expand/src/expand.rs | 1 - compiler/rustc_expand/src/proc_macro.rs | 7 +- .../rustc_expand/src/proc_macro_server.rs | 2 +- compiler/rustc_parse/src/lib.rs | 20 +- .../proc-macro/issue-75930-derive-cfg.stdout | 256 +++++++++--------- .../issue-78675-captured-inner-attrs.stdout | 18 +- 9 files changed, 151 insertions(+), 167 deletions(-) diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index b311f9fdcb9..90bfb01d6c7 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -771,7 +771,7 @@ impl fmt::Display for NonterminalKind { } impl Nonterminal { - fn span(&self) -> Span { + pub fn span(&self) -> Span { match self { NtItem(item) => item.span, NtBlock(block) => block.span, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index fe96e1c5c04..ab9861b85ab 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -206,8 +206,7 @@ pub trait ResolverAstLowering { ) -> LocalDefId; } -type NtToTokenstream = - fn(&Nonterminal, &ParseSess, Span, CanSynthesizeMissingTokens) -> TokenStream; +type NtToTokenstream = fn(&Nonterminal, &ParseSess, CanSynthesizeMissingTokens) -> TokenStream; /// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree, /// and if so, what meaning it has. @@ -417,12 +416,7 @@ impl<'a> TokenStreamLowering<'a> { fn lower_token(&mut self, token: Token) -> TokenStream { match token.kind { token::Interpolated(nt) => { - let tts = (self.nt_to_tokenstream)( - &nt, - self.parse_sess, - token.span, - self.synthesize_tokens, - ); + let tts = (self.nt_to_tokenstream)(&nt, self.parse_sess, self.synthesize_tokens); TokenTree::Delimited( DelimSpan::from_single(token.span), DelimToken::NoDelim, diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 887e12b46f6..b2ba720e0d7 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -141,7 +141,7 @@ impl Annotatable { } crate fn into_tokens(self, sess: &ParseSess) -> TokenStream { - nt_to_tokenstream(&self.into_nonterminal(), sess, DUMMY_SP, CanSynthesizeMissingTokens::No) + nt_to_tokenstream(&self.into_nonterminal(), sess, CanSynthesizeMissingTokens::No) } pub fn expect_item(self) -> P { diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 1453627f6e1..fa80a20dc8b 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -743,7 +743,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { AttrStyle::Inner => rustc_parse::fake_token_stream( &self.cx.sess.parse_sess, &item.into_nonterminal(), - span, ), }; let attr_item = attr.unwrap_normal_item(); diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index e8e098b6212..02129e9b5e5 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -94,12 +94,7 @@ impl MultiItemModifier for ProcMacroDerive { let input = if item.pretty_printing_compatibility_hack() { TokenTree::token(token::Interpolated(Lrc::new(item)), DUMMY_SP).into() } else { - nt_to_tokenstream( - &item, - &ecx.sess.parse_sess, - DUMMY_SP, - CanSynthesizeMissingTokens::Yes, - ) + nt_to_tokenstream(&item, &ecx.sess.parse_sess, CanSynthesizeMissingTokens::Yes) }; let server = proc_macro_server::Rustc::new(ecx); diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 02ae842675f..b6195d3bbc4 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -179,7 +179,7 @@ impl FromInternal<(TreeAndSpacing, &'_ ParseSess, &'_ mut Vec)> { TokenTree::Ident(Ident::new(sess, name.name, is_raw, name.span)) } else { - let stream = nt_to_tokenstream(&nt, sess, span, CanSynthesizeMissingTokens::No); + let stream = nt_to_tokenstream(&nt, sess, CanSynthesizeMissingTokens::No); TokenTree::Group(Group { delimiter: Delimiter::None, stream, diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 9abffbacfc3..4fa9768febb 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -236,7 +236,6 @@ pub fn parse_in<'a, T>( pub fn nt_to_tokenstream( nt: &Nonterminal, sess: &ParseSess, - span: Span, synthesize_tokens: CanSynthesizeMissingTokens, ) -> TokenStream { // A `Nonterminal` is often a parsed AST item. At this point we now @@ -256,11 +255,9 @@ pub fn nt_to_tokenstream( |tokens: Option<&LazyTokenStream>| tokens.as_ref().map(|t| t.create_token_stream()); let tokens = match *nt { - Nonterminal::NtItem(ref item) => { - prepend_attrs(sess, &item.attrs, nt, span, item.tokens.as_ref()) - } + Nonterminal::NtItem(ref item) => prepend_attrs(sess, &item.attrs, nt, item.tokens.as_ref()), Nonterminal::NtBlock(ref block) => convert_tokens(block.tokens.as_ref()), - Nonterminal::NtStmt(ref stmt) => prepend_attrs(sess, stmt.attrs(), nt, span, stmt.tokens()), + Nonterminal::NtStmt(ref stmt) => prepend_attrs(sess, stmt.attrs(), nt, stmt.tokens()), Nonterminal::NtPat(ref pat) => convert_tokens(pat.tokens.as_ref()), Nonterminal::NtTy(ref ty) => convert_tokens(ty.tokens.as_ref()), Nonterminal::NtIdent(ident, is_raw) => { @@ -277,31 +274,30 @@ pub fn nt_to_tokenstream( if expr.tokens.is_none() { debug!("missing tokens for expr {:?}", expr); } - prepend_attrs(sess, &expr.attrs, nt, span, expr.tokens.as_ref()) + prepend_attrs(sess, &expr.attrs, nt, expr.tokens.as_ref()) } }; if let Some(tokens) = tokens { return tokens; } else if matches!(synthesize_tokens, CanSynthesizeMissingTokens::Yes) { - return fake_token_stream(sess, nt, span); + return fake_token_stream(sess, nt); } else { let pretty = rustc_ast_pretty::pprust::nonterminal_to_string_no_extra_parens(&nt); - panic!("Missing tokens at {:?} for nt {:?}", span, pretty); + panic!("Missing tokens for nt {:?}", pretty); } } -pub fn fake_token_stream(sess: &ParseSess, nt: &Nonterminal, span: Span) -> TokenStream { +pub fn fake_token_stream(sess: &ParseSess, nt: &Nonterminal) -> TokenStream { let source = pprust::nonterminal_to_string(nt); let filename = FileName::macro_expansion_source_code(&source); - parse_stream_from_source_str(filename, source, sess, Some(span)) + parse_stream_from_source_str(filename, source, sess, Some(nt.span())) } fn prepend_attrs( sess: &ParseSess, attrs: &[ast::Attribute], nt: &Nonterminal, - span: Span, tokens: Option<&tokenstream::LazyTokenStream>, ) -> Option { if attrs.is_empty() { @@ -312,7 +308,7 @@ fn prepend_attrs( // FIXME: Correctly handle tokens for inner attributes. // For now, we fall back to reparsing the original AST node if attr.style == ast::AttrStyle::Inner { - return Some(fake_token_stream(sess, nt, span)); + return Some(fake_token_stream(sess, nt)); } builder.push(attr.tokens()); } diff --git a/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout b/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout index 4c0810217bf..5f513684cfa 100644 --- a/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout +++ b/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout @@ -1211,141 +1211,141 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "allow", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "dead_code", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '#', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "print_helper", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "b", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '#', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "print_helper", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "a", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "struct", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "Foo", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '<', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "B", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '>', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Brace, stream: TokenStream [ Ident { ident: "second", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ':', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "bool", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ',', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "third", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ':', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "u8", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Brace, @@ -1353,58 +1353,58 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "cfg", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "not", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "FALSE", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "struct", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "Inner", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "match", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "true", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Brace, @@ -1412,146 +1412,146 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "allow", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "warnings", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "false", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '=', spacing: Joint, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '>', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Brace, stream: TokenStream [], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "_", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '=', spacing: Joint, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '>', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Brace, stream: TokenStream [], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '#', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "print_helper", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "c", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '#', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "cfg", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "not", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "FALSE", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "fn", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "kept_fn", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Brace, @@ -1559,82 +1559,82 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Joint, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '!', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "cfg", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "not", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "FALSE", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "let", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "my_val", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '=', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "true", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "enum", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "TupleEnum", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Brace, stream: TokenStream [ Ident { ident: "Foo", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, @@ -1642,69 +1642,69 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "cfg", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "not", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "FALSE", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "i32", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ',', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "u8", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ',', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "struct", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "TupleStruct", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, @@ -1712,120 +1712,120 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "cfg", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "not", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "FALSE", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "i32", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ',', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "u8", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Literal { kind: Integer, symbol: "0", suffix: None, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ',', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: '#', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "print_helper", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "d", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "fourth", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ':', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Ident { ident: "B", - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, Punct { ch: ',', spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:1:1: 1:1 (#0), + span: $DIR/issue-75930-derive-cfg.rs:21:1: 64:2 (#0), }, ] diff --git a/src/test/ui/proc-macro/issue-78675-captured-inner-attrs.stdout b/src/test/ui/proc-macro/issue-78675-captured-inner-attrs.stdout index c4ee44f6541..40da5aa93bf 100644 --- a/src/test/ui/proc-macro/issue-78675-captured-inner-attrs.stdout +++ b/src/test/ui/proc-macro/issue-78675-captured-inner-attrs.stdout @@ -34,11 +34,11 @@ PRINT-BANG INPUT (DEBUG): TokenStream [ stream: TokenStream [ Ident { ident: "mod", - span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), + span: $DIR/issue-78675-captured-inner-attrs.rs:27:5: 29:6 (#0), }, Ident { ident: "bar", - span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), + span: $DIR/issue-78675-captured-inner-attrs.rs:27:5: 29:6 (#0), }, Group { delimiter: Brace, @@ -46,36 +46,36 @@ PRINT-BANG INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Joint, - span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), + span: $DIR/issue-78675-captured-inner-attrs.rs:27:5: 29:6 (#0), }, Punct { ch: '!', spacing: Alone, - span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), + span: $DIR/issue-78675-captured-inner-attrs.rs:27:5: 29:6 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "doc", - span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), + span: $DIR/issue-78675-captured-inner-attrs.rs:27:5: 29:6 (#0), }, Punct { ch: '=', spacing: Alone, - span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), + span: $DIR/issue-78675-captured-inner-attrs.rs:27:5: 29:6 (#0), }, Literal { kind: StrRaw(0), symbol: " Foo", suffix: None, - span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), + span: $DIR/issue-78675-captured-inner-attrs.rs:27:5: 29:6 (#0), }, ], - span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), + span: $DIR/issue-78675-captured-inner-attrs.rs:27:5: 29:6 (#0), }, ], - span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), + span: $DIR/issue-78675-captured-inner-attrs.rs:27:5: 29:6 (#0), }, ], span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4),