From cde0374d9301090c9b6b93bb033c07b04b55ab73 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 31 Jul 2025 19:17:51 +0300 Subject: resolve: Clarify extern prelude insertion for `extern crate` items --- compiler/rustc_resolve/src/build_reduced_graph.rs | 42 +++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'compiler/rustc_resolve/src') diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 7912345ec56..a665dd97899 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -968,7 +968,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { } self.r.potentially_unused_imports.push(import); let imported_binding = self.r.import(binding, import); - if parent == self.r.graph_root { + if ident.name != kw::Underscore && parent == self.r.graph_root { let ident = ident.normalize_to_macros_2_0(); if let Some(entry) = self.r.extern_prelude.get(&ident) && expansion != LocalExpnId::ROOT @@ -984,23 +984,29 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { // more details: https://github.com/rust-lang/rust/pull/111761 return; } - let entry = self.r.extern_prelude.entry(ident).or_insert(ExternPreludeEntry { - binding: Cell::new(None), - introduced_by_item: true, - }); - if orig_name.is_some() { - entry.introduced_by_item = true; - } - // Binding from `extern crate` item in source code can replace - // a binding from `--extern` on command line here. - if !entry.is_import() { - entry.binding.set(Some(imported_binding)); - } else if ident.name != kw::Underscore { - self.r.dcx().span_delayed_bug( - item.span, - format!("it had been define the external module '{ident}' multiple times"), - ); - } + + use indexmap::map::Entry; + match self.r.extern_prelude.entry(ident) { + Entry::Occupied(mut occupied) => { + let entry = occupied.get_mut(); + if let Some(old_binding) = entry.binding.get() + && old_binding.is_import() + { + let msg = format!("extern crate `{ident}` already in extern prelude"); + self.r.tcx.dcx().span_delayed_bug(item.span, msg); + } else { + // Binding from `extern crate` item in source code can replace + // a binding from `--extern` on command line here. + entry.binding.set(Some(imported_binding)); + entry.introduced_by_item = orig_name.is_some(); + } + entry + } + Entry::Vacant(vacant) => vacant.insert(ExternPreludeEntry { + binding: Cell::new(Some(imported_binding)), + introduced_by_item: true, + }), + }; } self.r.define_binding_local(parent, ident, TypeNS, imported_binding); } -- cgit 1.4.1-3-g733a5 From 2f7a2fa00fd06f9a1dcd51891b11a255cbf9d32b Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 31 Jul 2025 19:33:12 +0300 Subject: resolve: Do not add erroneous names to extern prelude --- compiler/rustc_resolve/src/lib.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'compiler/rustc_resolve/src') diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index a70ae4fd57a..17ca2ef7743 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1487,13 +1487,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let mut invocation_parents = FxHashMap::default(); invocation_parents.insert(LocalExpnId::ROOT, InvocationParent::ROOT); - let mut extern_prelude: FxIndexMap> = tcx + let mut extern_prelude: FxIndexMap<_, _> = tcx .sess .opts .externs .iter() - .filter(|(_, entry)| entry.add_prelude) - .map(|(name, _)| (Ident::from_str(name), Default::default())) + .filter_map(|(name, entry)| { + // Make sure `self`, `super`, `_` etc do not get into extern prelude. + // FIXME: reject `--extern self` and similar in option parsing instead. + if entry.add_prelude + && let name = Symbol::intern(name) + && name.can_be_raw() + { + Some((Ident::with_dummy_span(name), Default::default())) + } else { + None + } + }) .collect(); if !attr::contains_name(attrs, sym::no_core) { @@ -2168,11 +2178,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } fn extern_prelude_get(&mut self, ident: Ident, finalize: bool) -> Option> { - if ident.is_path_segment_keyword() { - // Make sure `self`, `super` etc produce an error when passed to here. - return None; - } - let norm_ident = ident.normalize_to_macros_2_0(); let binding = self.extern_prelude.get(&norm_ident).cloned().and_then(|entry| { Some(if let Some(binding) = entry.binding.get() { -- cgit 1.4.1-3-g733a5 From 73096965fbac485a83033516cf61645889700a71 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 31 Jul 2025 19:51:51 +0300 Subject: resolve: Avoid double table lookup in `extern_prelude_get` Do not write dummy bindings to extern prelude. Use more precise `Used::Scope` while recording use and remove now redundant `introduced_by_item` check. --- compiler/rustc_resolve/src/lib.rs | 51 ++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'compiler/rustc_resolve/src') diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 17ca2ef7743..bdac1b4675a 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -2178,35 +2178,42 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } fn extern_prelude_get(&mut self, ident: Ident, finalize: bool) -> Option> { - let norm_ident = ident.normalize_to_macros_2_0(); - let binding = self.extern_prelude.get(&norm_ident).cloned().and_then(|entry| { - Some(if let Some(binding) = entry.binding.get() { + let mut record_use = None; + let entry = self.extern_prelude.get(&ident.normalize_to_macros_2_0()); + let binding = entry.and_then(|entry| match entry.binding.get() { + Some(binding) if binding.is_import() => { if finalize { - if !entry.is_import() { - self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span); - } else if entry.introduced_by_item { - self.record_use(ident, binding, Used::Other); - } + record_use = Some(binding); } - binding - } else { + Some(binding) + } + Some(binding) => { + if finalize { + self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span); + } + Some(binding) + } + None => { let crate_id = if finalize { - let Some(crate_id) = - self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span) - else { - return Some(self.dummy_binding); - }; - crate_id + self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span) } else { - self.cstore_mut().maybe_process_path_extern(self.tcx, ident.name)? + self.cstore_mut().maybe_process_path_extern(self.tcx, ident.name) }; - let res = Res::Def(DefKind::Mod, crate_id.as_def_id()); - self.arenas.new_pub_res_binding(res, DUMMY_SP, LocalExpnId::ROOT) - }) + match crate_id { + Some(crate_id) => { + let res = Res::Def(DefKind::Mod, crate_id.as_def_id()); + let binding = + self.arenas.new_pub_res_binding(res, DUMMY_SP, LocalExpnId::ROOT); + entry.binding.set(Some(binding)); + Some(binding) + } + None => finalize.then_some(self.dummy_binding), + } + } }); - if let Some(entry) = self.extern_prelude.get(&norm_ident) { - entry.binding.set(binding); + if let Some(binding) = record_use { + self.record_use(ident, binding, Used::Scope); } binding -- cgit 1.4.1-3-g733a5 From e58e6f857f1335ef2436cb7bf3a4a55ddfc79387 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 31 Jul 2025 20:33:33 +0300 Subject: resolve: Cleanup some uses of extern prelude in diagnostics --- compiler/rustc_resolve/src/diagnostics.rs | 4 ++-- compiler/rustc_resolve/src/late/diagnostics.rs | 17 ++++------------- 2 files changed, 6 insertions(+), 15 deletions(-) (limited to 'compiler/rustc_resolve/src') diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 3af69b28780..c80f8106049 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1098,7 +1098,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } } Scope::ExternPrelude => { - suggestions.extend(this.extern_prelude.iter().filter_map(|(ident, _)| { + suggestions.extend(this.extern_prelude.keys().filter_map(|ident| { let res = Res::Def(DefKind::Mod, CRATE_DEF_ID.to_def_id()); filter_fn(res).then_some(TypoSuggestion::typo_from_ident(*ident, res)) })); @@ -1411,7 +1411,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ); if lookup_ident.span.at_least_rust_2018() { - for ident in self.extern_prelude.clone().into_keys() { + for &ident in self.extern_prelude.keys() { if ident.span.from_expansion() { // Idents are adjusted to the root context before being // resolved in the extern prelude, so reporting this to the diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 98e48664e68..efafb2494c2 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -2477,19 +2477,10 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { } else { // Items from the prelude if !module.no_implicit_prelude { - let extern_prelude = self.r.extern_prelude.clone(); - names.extend(extern_prelude.iter().flat_map(|(ident, _)| { - self.r - .cstore_mut() - .maybe_process_path_extern(self.r.tcx, ident.name) - .and_then(|crate_id| { - let crate_mod = - Res::Def(DefKind::Mod, crate_id.as_def_id()); - - filter_fn(crate_mod).then(|| { - TypoSuggestion::typo_from_ident(*ident, crate_mod) - }) - }) + names.extend(self.r.extern_prelude.keys().flat_map(|ident| { + let res = Res::Def(DefKind::Mod, CRATE_DEF_ID.to_def_id()); + filter_fn(res) + .then_some(TypoSuggestion::typo_from_ident(*ident, res)) })); if let Some(prelude) = self.r.prelude { -- cgit 1.4.1-3-g733a5 From adcda6ca9a6d27c04399e3efe1c67fc6ff04d997 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sat, 17 Aug 2024 05:45:10 +0000 Subject: Detect more `cfg`d out items in resolution errors Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition. ``` error[E0425]: cannot find function `f` in this scope --> $DIR/nested-cfg-attrs.rs:4:13 | LL | fn main() { f() } | ^ not found in this scope | note: found an item that was configured out --> $DIR/nested-cfg-attrs.rs:2:4 | LL | fn f() {} | ^ note: the item is gated here --> $DIR/nested-cfg-attrs.rs:1:35 | LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))] | ^^^^^^^^^^ ``` --- compiler/rustc_expand/src/expand.rs | 38 ++++--- compiler/rustc_resolve/src/diagnostics.rs | 15 ++- compiler/rustc_resolve/src/late.rs | 10 +- compiler/rustc_resolve/src/late/diagnostics.rs | 5 +- tests/ui/cfg/both-true-false.stderr | 21 ++++ tests/ui/cfg/cfg-version/syntax.stderr | 110 +++++++++++++++++++++ tests/ui/cfg/cmdline-false.stderr | 11 +++ tests/ui/cfg/diagnostics-reexport.rs | 6 +- tests/ui/cfg/diagnostics-reexport.stderr | 10 ++ tests/ui/cfg/diagnostics-same-crate.rs | 12 +-- tests/ui/cfg/diagnostics-same-crate.stderr | 17 +++- .../cfg/nested-cfg-attr-conditional-compilation.rs | 5 +- .../nested-cfg-attr-conditional-compilation.stderr | 11 +++ tests/ui/conditional-compilation/test-cfg.rs | 4 +- tests/ui/conditional-compilation/test-cfg.stderr | 13 ++- tests/ui/macros/macro-inner-attributes.stderr | 10 ++ tests/ui/rustdoc/cfg-rustdoc.rs | 7 +- tests/ui/rustdoc/cfg-rustdoc.stderr | 11 +++ 18 files changed, 273 insertions(+), 43 deletions(-) (limited to 'compiler/rustc_resolve/src') diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 0517fd0419d..6174984e3be 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1399,25 +1399,35 @@ impl InvocationCollectorNode for P { } fn declared_idents(&self) -> Vec { - if let ItemKind::Use(ut) = &self.kind { - fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec) { - match &ut.kind { - ast::UseTreeKind::Glob => {} - ast::UseTreeKind::Simple(_) => idents.push(ut.ident()), - ast::UseTreeKind::Nested { items, .. } => { - for (ut, _) in items { - collect_use_tree_leaves(ut, idents); + struct ItemNameVisitor(Vec); + impl Visitor<'_> for ItemNameVisitor { + fn visit_item(&mut self, i: &ast::Item) { + if let ItemKind::Use(ut) = &i.kind { + fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec) { + match &ut.kind { + ast::UseTreeKind::Glob => {} + ast::UseTreeKind::Simple(_) => idents.push(ut.ident()), + ast::UseTreeKind::Nested { items, .. } => { + for (ut, _) in items { + collect_use_tree_leaves(ut, idents); + } + } } } + + collect_use_tree_leaves(ut, &mut self.0); + } else { + if let Some(ident) = i.kind.ident() { + self.0.push(ident); + } } + visit::walk_item(self, i); } - - let mut idents = Vec::new(); - collect_use_tree_leaves(ut, &mut idents); - idents - } else { - self.kind.ident().into_iter().collect() } + + let mut v = ItemNameVisitor(vec![]); + v.visit_item(self); + v.0 } } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 3af69b28780..d0a95e6b2ad 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -803,11 +803,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } err.multipart_suggestion(msg, suggestions, applicability); } - if let Some(ModuleOrUniformRoot::Module(module)) = module - && let Some(module) = module.opt_def_id() - && let Some(segment) = segment - { - self.find_cfg_stripped(&mut err, &segment, module); + + if let Some(segment) = segment { + if let Some(ModuleOrUniformRoot::Module(module)) = module { + let module = + module.opt_def_id().unwrap_or_else(|| CRATE_DEF_ID.to_def_id()); + self.find_cfg_stripped(&mut err, &segment, module); + } else { + let module = CRATE_DEF_ID.to_def_id(); + self.find_cfg_stripped(&mut err, &segment, module); + } } err diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 261d099abdc..163e4b5b7a9 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -4231,13 +4231,21 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // // And that's what happens below - we're just mixing both messages // into a single one. + let failed_to_resolve = match parent_err.node { + ResolutionError::FailedToResolve { .. } => true, + _ => false, + }; let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node); // overwrite all properties with the parent's error message err.messages = take(&mut parent_err.messages); err.code = take(&mut parent_err.code); swap(&mut err.span, &mut parent_err.span); - err.children = take(&mut parent_err.children); + if failed_to_resolve { + err.children = take(&mut parent_err.children); + } else { + err.children.append(&mut parent_err.children); + } err.sort_span = parent_err.sort_span; err.is_lint = parent_err.is_lint.clone(); diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 98e48664e68..236b1404eeb 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -525,9 +525,8 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { } self.err_code_special_cases(&mut err, source, path, span); - if let Some(module) = base_error.module { - self.r.find_cfg_stripped(&mut err, &path.last().unwrap().ident.name, module); - } + let module = base_error.module.unwrap_or_else(|| CRATE_DEF_ID.to_def_id()); + self.r.find_cfg_stripped(&mut err, &path.last().unwrap().ident.name, module); (err, candidates) } diff --git a/tests/ui/cfg/both-true-false.stderr b/tests/ui/cfg/both-true-false.stderr index 1526cc2b707..8550444d179 100644 --- a/tests/ui/cfg/both-true-false.stderr +++ b/tests/ui/cfg/both-true-false.stderr @@ -3,6 +3,27 @@ error[E0425]: cannot find function `foo` in this scope | LL | foo(); | ^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/both-true-false.rs:6:4 + | +LL | fn foo() {} + | ^^^ +note: the item is gated here + --> $DIR/both-true-false.rs:4:7 + | +LL | #[cfg(false)] + | ^^^^^ +note: found an item that was configured out + --> $DIR/both-true-false.rs:10:4 + | +LL | fn foo() {} + | ^^^ +note: the item is gated here + --> $DIR/both-true-false.rs:9:7 + | +LL | #[cfg(false)] + | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/cfg/cfg-version/syntax.stderr b/tests/ui/cfg/cfg-version/syntax.stderr index 188f6d7aa5d..4ec3e2de797 100644 --- a/tests/ui/cfg/cfg-version/syntax.stderr +++ b/tests/ui/cfg/cfg-version/syntax.stderr @@ -128,60 +128,170 @@ error[E0425]: cannot find function `key_value_form` in this scope | LL | key_value_form(); | ^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:32:4 + | +LL | fn key_value_form() {} + | ^^^^^^^^^^^^^^ +note: the item is gated behind the `1.43` feature + --> $DIR/syntax.rs:30:7 + | +LL | #[cfg(version = "1.43")] + | ^^^^^^^^^^^^^^^^ error[E0425]: cannot find function `not_numbers_or_periods` in this scope --> $DIR/syntax.rs:143:5 | LL | not_numbers_or_periods(); | ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:53:4 + | +LL | fn not_numbers_or_periods() {} + | ^^^^^^^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:51:14 + | +LL | #[cfg(version("foo"))] + | ^^^^^^^ error[E0425]: cannot find function `complex_semver_with_metadata` in this scope --> $DIR/syntax.rs:144:5 | LL | complex_semver_with_metadata(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:57:4 + | +LL | fn complex_semver_with_metadata() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:55:14 + | +LL | #[cfg(version("1.20.0-stable"))] + | ^^^^^^^^^^^^^^^^^ error[E0425]: cannot find function `invalid_major_only` in this scope --> $DIR/syntax.rs:145:5 | LL | invalid_major_only(); | ^^^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:80:4 + | +LL | fn invalid_major_only() {} + | ^^^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:78:14 + | +LL | #[cfg(version("1"))] + | ^^^^^ error[E0425]: cannot find function `invalid_major_only_zero` in this scope --> $DIR/syntax.rs:146:5 | LL | invalid_major_only_zero(); | ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:84:4 + | +LL | fn invalid_major_only_zero() {} + | ^^^^^^^^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:82:14 + | +LL | #[cfg(version("0"))] + | ^^^^^ error[E0425]: cannot find function `invalid_major_only_negative` in this scope --> $DIR/syntax.rs:147:5 | LL | invalid_major_only_negative(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:97:4 + | +LL | fn invalid_major_only_negative() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:95:14 + | +LL | #[cfg(version("-1"))] + | ^^^^^^ error[E0425]: cannot find function `exceed_u16_major` in this scope --> $DIR/syntax.rs:148:5 | LL | exceed_u16_major(); | ^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:103:4 + | +LL | fn exceed_u16_major() {} + | ^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:101:14 + | +LL | #[cfg(version("65536"))] + | ^^^^^^^^^ error[E0425]: cannot find function `exceed_u16_minor` in this scope --> $DIR/syntax.rs:149:5 | LL | exceed_u16_minor(); | ^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:107:4 + | +LL | fn exceed_u16_minor() {} + | ^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:105:14 + | +LL | #[cfg(version("1.65536.0"))] + | ^^^^^^^^^^^^^ error[E0425]: cannot find function `exceed_u16_patch` in this scope --> $DIR/syntax.rs:150:5 | LL | exceed_u16_patch(); | ^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:111:4 + | +LL | fn exceed_u16_patch() {} + | ^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:109:14 + | +LL | #[cfg(version("1.0.65536"))] + | ^^^^^^^^^^^^^ error[E0425]: cannot find function `exceed_u16_mixed` in this scope --> $DIR/syntax.rs:151:5 | LL | exceed_u16_mixed(); | ^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:115:4 + | +LL | fn exceed_u16_mixed() {} + | ^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:113:14 + | +LL | #[cfg(version("65536.0.65536"))] + | ^^^^^^^^^^^^^^^^^ error: aborting due to 14 previous errors; 14 warnings emitted diff --git a/tests/ui/cfg/cmdline-false.stderr b/tests/ui/cfg/cmdline-false.stderr index 5f57c754c40..da5eb0c892a 100644 --- a/tests/ui/cfg/cmdline-false.stderr +++ b/tests/ui/cfg/cmdline-false.stderr @@ -3,6 +3,17 @@ error[E0425]: cannot find function `foo` in this scope | LL | foo(); | ^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/cmdline-false.rs:5:4 + | +LL | fn foo() {} + | ^^^ +note: the item is gated here + --> $DIR/cmdline-false.rs:4:7 + | +LL | #[cfg(false)] + | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/cfg/diagnostics-reexport.rs b/tests/ui/cfg/diagnostics-reexport.rs index 56fac562238..bdb57df2f25 100644 --- a/tests/ui/cfg/diagnostics-reexport.rs +++ b/tests/ui/cfg/diagnostics-reexport.rs @@ -1,7 +1,7 @@ pub mod inner { - #[cfg(false)] + #[cfg(false)] //~ NOTE the item is gated here mod gone { - pub fn uwu() {} + pub fn uwu() {} //~ NOTE found an item that was configured out } #[cfg(false)] //~ NOTE the item is gated here @@ -34,7 +34,7 @@ mod b { } fn main() { - // There is no uwu at this path - no diagnostic. + // There is no uwu at this path, but there's one in a cgfd out sub-module, so we mention it. inner::uwu(); //~ ERROR cannot find function //~^ NOTE not found in `inner` } diff --git a/tests/ui/cfg/diagnostics-reexport.stderr b/tests/ui/cfg/diagnostics-reexport.stderr index bf1bbcba7e4..82412ed49c5 100644 --- a/tests/ui/cfg/diagnostics-reexport.stderr +++ b/tests/ui/cfg/diagnostics-reexport.stderr @@ -50,6 +50,16 @@ error[E0425]: cannot find function `uwu` in module `inner` LL | inner::uwu(); | ^^^ not found in `inner` | +note: found an item that was configured out + --> $DIR/diagnostics-reexport.rs:4:16 + | +LL | pub fn uwu() {} + | ^^^ +note: the item is gated here + --> $DIR/diagnostics-reexport.rs:2:11 + | +LL | #[cfg(false)] + | ^^^^^ note: found an item that was configured out --> $DIR/diagnostics-reexport.rs:8:20 | diff --git a/tests/ui/cfg/diagnostics-same-crate.rs b/tests/ui/cfg/diagnostics-same-crate.rs index 9153f20b296..29209d5f3ea 100644 --- a/tests/ui/cfg/diagnostics-same-crate.rs +++ b/tests/ui/cfg/diagnostics-same-crate.rs @@ -37,8 +37,8 @@ mod placeholder { //~| NOTE could not find `doesnt_exist` in `inner` } -#[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] -pub fn vanished() {} +#[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] //~ NOTE the item is gated here +pub fn vanished() {} //~ NOTE found an item that was configured out fn main() { // There is no uwu at this path - no diagnostic. @@ -49,8 +49,7 @@ fn main() { inner::uwu(); //~ ERROR cannot find function //~| NOTE not found in `inner` - // The module isn't found - we would like to get a diagnostic, but currently don't due to - // the awkward way the resolver diagnostics are currently implemented. + // The module isn't found - we get a diagnostic. inner::doesnt_exist::hello(); //~ ERROR failed to resolve //~| NOTE could not find `doesnt_exist` in `inner` @@ -58,9 +57,8 @@ fn main() { inner::right::meow(); //~ ERROR cannot find function //~| NOTE not found in `inner::right - // Exists in the crate root - we would generally want a diagnostic, - // but currently don't have one. - // Not that it matters much though, this is highly unlikely to confuse anyone. + // Exists in the crate root - we show a diagnostic because we treat "no module DefId" as "crate + // root DefId". vanished(); //~ ERROR cannot find function //~^ NOTE not found in this scope } diff --git a/tests/ui/cfg/diagnostics-same-crate.stderr b/tests/ui/cfg/diagnostics-same-crate.stderr index 121f25ca090..f6a6fe388c5 100644 --- a/tests/ui/cfg/diagnostics-same-crate.stderr +++ b/tests/ui/cfg/diagnostics-same-crate.stderr @@ -33,7 +33,7 @@ LL | #[cfg(false)] | ^^^^^ error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner` - --> $DIR/diagnostics-same-crate.rs:54:12 + --> $DIR/diagnostics-same-crate.rs:53:12 | LL | inner::doesnt_exist::hello(); | ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner` @@ -67,7 +67,7 @@ LL | #[cfg(false)] | ^^^^^ error[E0425]: cannot find function `meow` in module `inner::right` - --> $DIR/diagnostics-same-crate.rs:58:19 + --> $DIR/diagnostics-same-crate.rs:57:19 | LL | inner::right::meow(); | ^^^^ not found in `inner::right` @@ -90,10 +90,21 @@ LL | uwu(); | ^^^ not found in this scope error[E0425]: cannot find function `vanished` in this scope - --> $DIR/diagnostics-same-crate.rs:64:5 + --> $DIR/diagnostics-same-crate.rs:62:5 | LL | vanished(); | ^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/diagnostics-same-crate.rs:41:8 + | +LL | pub fn vanished() {} + | ^^^^^^^^ +note: the item is gated here + --> $DIR/diagnostics-same-crate.rs:40:7 + | +LL | #[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 7 previous errors diff --git a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs index 7618e83a642..c5d86a27d52 100644 --- a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs +++ b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs @@ -10,9 +10,10 @@ //! //! Added in . -#[cfg_attr(all(), cfg_attr(all(), cfg(false)))] -fn f() {} +#[cfg_attr(all(), cfg_attr(all(), cfg(false)))] //~ NOTE the item is gated here +fn f() {} //~ NOTE found an item that was configured out fn main() { f() //~ ERROR cannot find function `f` in this scope + //~^ NOTE not found in this scope } diff --git a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr index ddb8ea1e13a..44a33adbc47 100644 --- a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr +++ b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr @@ -3,6 +3,17 @@ error[E0425]: cannot find function `f` in this scope | LL | f() | ^ not found in this scope + | +note: found an item that was configured out + --> $DIR/nested-cfg-attr-conditional-compilation.rs:14:4 + | +LL | fn f() {} + | ^ +note: the item is gated here + --> $DIR/nested-cfg-attr-conditional-compilation.rs:13:39 + | +LL | #[cfg_attr(all(), cfg_attr(all(), cfg(false)))] + | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/conditional-compilation/test-cfg.rs b/tests/ui/conditional-compilation/test-cfg.rs index adbbc309be4..b3fff26a8fd 100644 --- a/tests/ui/conditional-compilation/test-cfg.rs +++ b/tests/ui/conditional-compilation/test-cfg.rs @@ -1,8 +1,10 @@ //@ compile-flags: --cfg foo --check-cfg=cfg(foo,bar) #[cfg(all(foo, bar))] // foo AND bar -fn foo() {} +//~^ NOTE the item is gated here +fn foo() {} //~ NOTE found an item that was configured out fn main() { foo(); //~ ERROR cannot find function `foo` in this scope + //~^ NOTE not found in this scope } diff --git a/tests/ui/conditional-compilation/test-cfg.stderr b/tests/ui/conditional-compilation/test-cfg.stderr index 9715f16acc2..1212074e417 100644 --- a/tests/ui/conditional-compilation/test-cfg.stderr +++ b/tests/ui/conditional-compilation/test-cfg.stderr @@ -1,8 +1,19 @@ error[E0425]: cannot find function `foo` in this scope - --> $DIR/test-cfg.rs:7:5 + --> $DIR/test-cfg.rs:8:5 | LL | foo(); | ^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/test-cfg.rs:5:4 + | +LL | fn foo() {} + | ^^^ +note: the item is gated here + --> $DIR/test-cfg.rs:3:16 + | +LL | #[cfg(all(foo, bar))] // foo AND bar + | ^^^ error: aborting due to 1 previous error diff --git a/tests/ui/macros/macro-inner-attributes.stderr b/tests/ui/macros/macro-inner-attributes.stderr index d74b64db5ac..cda53497f39 100644 --- a/tests/ui/macros/macro-inner-attributes.stderr +++ b/tests/ui/macros/macro-inner-attributes.stderr @@ -4,6 +4,16 @@ error[E0433]: failed to resolve: use of unresolved module or unlinked crate `a` LL | a::bar(); | ^ use of unresolved module or unlinked crate `a` | +note: found an item that was configured out + --> $DIR/macro-inner-attributes.rs:7:7 + | +LL | test!(a, + | ^ +note: the item is gated here + --> $DIR/macro-inner-attributes.rs:8:13 + | +LL | #[cfg(false)], + | ^^^^^ help: there is a crate or module with a similar name | LL - a::bar(); diff --git a/tests/ui/rustdoc/cfg-rustdoc.rs b/tests/ui/rustdoc/cfg-rustdoc.rs index dd8e1ed97c4..11c48d07552 100644 --- a/tests/ui/rustdoc/cfg-rustdoc.rs +++ b/tests/ui/rustdoc/cfg-rustdoc.rs @@ -1,6 +1,7 @@ -#[cfg(doc)] -pub struct Foo; +#[cfg(doc)] //~ NOTE the item is gated here +pub struct Foo; //~ NOTE found an item that was configured out fn main() { - let f = Foo; //~ ERROR + let f = Foo; //~ ERROR cannot find value `Foo` in this scope + //~^ NOTE not found in this scope } diff --git a/tests/ui/rustdoc/cfg-rustdoc.stderr b/tests/ui/rustdoc/cfg-rustdoc.stderr index 340a8e22482..fd0fcfd01aa 100644 --- a/tests/ui/rustdoc/cfg-rustdoc.stderr +++ b/tests/ui/rustdoc/cfg-rustdoc.stderr @@ -3,6 +3,17 @@ error[E0425]: cannot find value `Foo` in this scope | LL | let f = Foo; | ^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/cfg-rustdoc.rs:2:12 + | +LL | pub struct Foo; + | ^^^ +note: the item is gated here + --> $DIR/cfg-rustdoc.rs:1:7 + | +LL | #[cfg(doc)] + | ^^^ error: aborting due to 1 previous error -- cgit 1.4.1-3-g733a5 From 77f75f91c5822c3c83f55317b76330153859a12a Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Fri, 1 Aug 2025 22:11:45 +0000 Subject: tiny cleanup --- compiler/rustc_expand/src/expand.rs | 6 ++---- compiler/rustc_resolve/src/diagnostics.rs | 13 +++++-------- 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'compiler/rustc_resolve/src') diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 609e93a685c..f02aa6c120f 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1411,13 +1411,11 @@ impl InvocationCollectorNode for P { } } } - let mut idents = vec![]; + let mut idents = Vec::new(); collect_use_tree_leaves(&ut, &mut idents); idents - } else if let Some(ident) = self.kind.ident() { - vec![ident] } else { - vec![] + self.kind.ident().into_iter().collect() } } } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index d0a95e6b2ad..e09fbcc8245 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -805,14 +805,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } if let Some(segment) = segment { - if let Some(ModuleOrUniformRoot::Module(module)) = module { - let module = - module.opt_def_id().unwrap_or_else(|| CRATE_DEF_ID.to_def_id()); - self.find_cfg_stripped(&mut err, &segment, module); - } else { - let module = CRATE_DEF_ID.to_def_id(); - self.find_cfg_stripped(&mut err, &segment, module); - } + let module = match module { + Some(ModuleOrUniformRoot::Module(m)) if let Some(id) = m.opt_def_id() => id, + _ => CRATE_DEF_ID.to_def_id(), + }; + self.find_cfg_stripped(&mut err, &segment, module); } err -- cgit 1.4.1-3-g733a5 From 4b24c4bf23df8ae5c53669e3209b9f3074769b69 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Fri, 1 Aug 2025 23:58:15 +0000 Subject: Tweak rendering of cfg'd out item ``` error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner` --> $DIR/diagnostics-cross-crate.rs:18:23 | LL | cfged_out::inner::doesnt_exist::hello(); | ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner` | note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:6:13 | LL | #[cfg(false)] | ----- the item is gated here LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ ``` --- compiler/rustc_resolve/src/diagnostics.rs | 15 ++-- compiler/rustc_resolve/src/errors.rs | 52 ++++++++------ tests/ui/cfg/both-true-false.stderr | 15 ++-- tests/ui/cfg/cfg-version/syntax.stderr | 80 ++++++++-------------- tests/ui/cfg/cmdline-false.stderr | 7 +- tests/ui/cfg/diagnostics-cross-crate.rs | 4 -- tests/ui/cfg/diagnostics-cross-crate.stderr | 34 +++------ tests/ui/cfg/diagnostics-reexport-2.stderr | 40 ++++------- tests/ui/cfg/diagnostics-reexport.stderr | 28 +++----- tests/ui/cfg/diagnostics-same-crate.stderr | 45 ++++-------- .../nested-cfg-attr-conditional-compilation.stderr | 7 +- tests/ui/conditional-compilation/test-cfg.stderr | 8 +-- tests/ui/macros/builtin-std-paths-fail.stderr | 4 +- tests/ui/macros/macro-inner-attributes.stderr | 5 +- tests/ui/macros/macro-outer-attributes.stderr | 7 +- tests/ui/rustdoc/cfg-rustdoc.stderr | 7 +- 16 files changed, 136 insertions(+), 222 deletions(-) (limited to 'compiler/rustc_resolve/src') diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index e09fbcc8245..11def7e4876 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -2845,16 +2845,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { continue; } - let note = errors::FoundItemConfigureOut { span: ident.span }; - err.subdiagnostic(note); - - if let CfgEntry::NameValue { value: Some((feature, _)), .. } = cfg.0 { - let note = errors::ItemWasBehindFeature { feature, span: cfg.1 }; - err.subdiagnostic(note); + let item_was = if let CfgEntry::NameValue { value: Some((feature, _)), .. } = cfg.0 { + errors::ItemWas::BehindFeature { feature, span: cfg.1 } } else { - let note = errors::ItemWasCfgOut { span: cfg.1 }; - err.subdiagnostic(note); - } + errors::ItemWas::CfgOut { span: cfg.1 } + }; + let note = errors::FoundItemConfigureOut { span: ident.span, item_was }; + err.subdiagnostic(note); } } } diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index d6b1e4de6ea..2747ba135ed 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -1,10 +1,13 @@ use rustc_errors::codes::*; -use rustc_errors::{Applicability, ElidedLifetimeInPathSubdiag, MultiSpan}; +use rustc_errors::{ + Applicability, Diag, ElidedLifetimeInPathSubdiag, EmissionGuarantee, IntoDiagArg, MultiSpan, + Subdiagnostic, +}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{Ident, Span, Symbol}; -use crate::Res; use crate::late::PatternSource; +use crate::{Res, fluent_generated as fluent}; #[derive(Diagnostic)] #[diag(resolve_generic_params_from_outer_item, code = E0401)] @@ -1201,26 +1204,35 @@ pub(crate) struct IdentInScopeButItIsDesc<'a> { pub(crate) imported_ident_desc: &'a str, } -#[derive(Subdiagnostic)] -#[note(resolve_found_an_item_configured_out)] pub(crate) struct FoundItemConfigureOut { - #[primary_span] - pub(crate) span: Span, -} - -#[derive(Subdiagnostic)] -#[note(resolve_item_was_behind_feature)] -pub(crate) struct ItemWasBehindFeature { - pub(crate) feature: Symbol, - #[primary_span] - pub(crate) span: Span, -} - -#[derive(Subdiagnostic)] -#[note(resolve_item_was_cfg_out)] -pub(crate) struct ItemWasCfgOut { - #[primary_span] pub(crate) span: Span, + pub(crate) item_was: ItemWas, +} + +pub(crate) enum ItemWas { + BehindFeature { feature: Symbol, span: Span }, + CfgOut { span: Span }, +} + +impl Subdiagnostic for FoundItemConfigureOut { + fn add_to_diag(self, diag: &mut Diag<'_, G>) { + let mut multispan: MultiSpan = self.span.into(); + match self.item_was { + ItemWas::BehindFeature { feature, span } => { + let key = "feature".into(); + let value = feature.into_diag_arg(&mut None); + let msg = diag.dcx.eagerly_translate_to_string( + fluent::resolve_item_was_behind_feature, + [(&key, &value)].into_iter(), + ); + multispan.push_span_label(span, msg); + } + ItemWas::CfgOut { span } => { + multispan.push_span_label(span, fluent::resolve_item_was_cfg_out); + } + } + diag.span_note(multispan, fluent::resolve_found_an_item_configured_out); + } } #[derive(Diagnostic)] diff --git a/tests/ui/cfg/both-true-false.stderr b/tests/ui/cfg/both-true-false.stderr index 8550444d179..1a7c509aec0 100644 --- a/tests/ui/cfg/both-true-false.stderr +++ b/tests/ui/cfg/both-true-false.stderr @@ -7,23 +7,18 @@ LL | foo(); note: found an item that was configured out --> $DIR/both-true-false.rs:6:4 | +LL | #[cfg(false)] + | ----- the item is gated here +LL | #[cfg(true)] LL | fn foo() {} | ^^^ -note: the item is gated here - --> $DIR/both-true-false.rs:4:7 - | -LL | #[cfg(false)] - | ^^^^^ note: found an item that was configured out --> $DIR/both-true-false.rs:10:4 | +LL | #[cfg(false)] + | ----- the item is gated here LL | fn foo() {} | ^^^ -note: the item is gated here - --> $DIR/both-true-false.rs:9:7 - | -LL | #[cfg(false)] - | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/cfg/cfg-version/syntax.stderr b/tests/ui/cfg/cfg-version/syntax.stderr index 4ec3e2de797..34ddfff3e8e 100644 --- a/tests/ui/cfg/cfg-version/syntax.stderr +++ b/tests/ui/cfg/cfg-version/syntax.stderr @@ -132,13 +132,11 @@ LL | key_value_form(); note: found an item that was configured out --> $DIR/syntax.rs:32:4 | +LL | #[cfg(version = "1.43")] + | ---------------- the item is gated behind the `1.43` feature +LL | LL | fn key_value_form() {} | ^^^^^^^^^^^^^^ -note: the item is gated behind the `1.43` feature - --> $DIR/syntax.rs:30:7 - | -LL | #[cfg(version = "1.43")] - | ^^^^^^^^^^^^^^^^ error[E0425]: cannot find function `not_numbers_or_periods` in this scope --> $DIR/syntax.rs:143:5 @@ -149,13 +147,11 @@ LL | not_numbers_or_periods(); note: found an item that was configured out --> $DIR/syntax.rs:53:4 | +LL | #[cfg(version("foo"))] + | ------- the item is gated here +LL | LL | fn not_numbers_or_periods() {} | ^^^^^^^^^^^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/syntax.rs:51:14 - | -LL | #[cfg(version("foo"))] - | ^^^^^^^ error[E0425]: cannot find function `complex_semver_with_metadata` in this scope --> $DIR/syntax.rs:144:5 @@ -166,13 +162,11 @@ LL | complex_semver_with_metadata(); note: found an item that was configured out --> $DIR/syntax.rs:57:4 | +LL | #[cfg(version("1.20.0-stable"))] + | ----------------- the item is gated here +LL | LL | fn complex_semver_with_metadata() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/syntax.rs:55:14 - | -LL | #[cfg(version("1.20.0-stable"))] - | ^^^^^^^^^^^^^^^^^ error[E0425]: cannot find function `invalid_major_only` in this scope --> $DIR/syntax.rs:145:5 @@ -183,13 +177,11 @@ LL | invalid_major_only(); note: found an item that was configured out --> $DIR/syntax.rs:80:4 | +LL | #[cfg(version("1"))] + | ----- the item is gated here +LL | LL | fn invalid_major_only() {} | ^^^^^^^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/syntax.rs:78:14 - | -LL | #[cfg(version("1"))] - | ^^^^^ error[E0425]: cannot find function `invalid_major_only_zero` in this scope --> $DIR/syntax.rs:146:5 @@ -200,13 +192,11 @@ LL | invalid_major_only_zero(); note: found an item that was configured out --> $DIR/syntax.rs:84:4 | +LL | #[cfg(version("0"))] + | ----- the item is gated here +LL | LL | fn invalid_major_only_zero() {} | ^^^^^^^^^^^^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/syntax.rs:82:14 - | -LL | #[cfg(version("0"))] - | ^^^^^ error[E0425]: cannot find function `invalid_major_only_negative` in this scope --> $DIR/syntax.rs:147:5 @@ -217,13 +207,11 @@ LL | invalid_major_only_negative(); note: found an item that was configured out --> $DIR/syntax.rs:97:4 | +LL | #[cfg(version("-1"))] + | ------ the item is gated here +LL | LL | fn invalid_major_only_negative() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/syntax.rs:95:14 - | -LL | #[cfg(version("-1"))] - | ^^^^^^ error[E0425]: cannot find function `exceed_u16_major` in this scope --> $DIR/syntax.rs:148:5 @@ -234,13 +222,11 @@ LL | exceed_u16_major(); note: found an item that was configured out --> $DIR/syntax.rs:103:4 | +LL | #[cfg(version("65536"))] + | --------- the item is gated here +LL | LL | fn exceed_u16_major() {} | ^^^^^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/syntax.rs:101:14 - | -LL | #[cfg(version("65536"))] - | ^^^^^^^^^ error[E0425]: cannot find function `exceed_u16_minor` in this scope --> $DIR/syntax.rs:149:5 @@ -251,13 +237,11 @@ LL | exceed_u16_minor(); note: found an item that was configured out --> $DIR/syntax.rs:107:4 | +LL | #[cfg(version("1.65536.0"))] + | ------------- the item is gated here +LL | LL | fn exceed_u16_minor() {} | ^^^^^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/syntax.rs:105:14 - | -LL | #[cfg(version("1.65536.0"))] - | ^^^^^^^^^^^^^ error[E0425]: cannot find function `exceed_u16_patch` in this scope --> $DIR/syntax.rs:150:5 @@ -268,13 +252,11 @@ LL | exceed_u16_patch(); note: found an item that was configured out --> $DIR/syntax.rs:111:4 | +LL | #[cfg(version("1.0.65536"))] + | ------------- the item is gated here +LL | LL | fn exceed_u16_patch() {} | ^^^^^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/syntax.rs:109:14 - | -LL | #[cfg(version("1.0.65536"))] - | ^^^^^^^^^^^^^ error[E0425]: cannot find function `exceed_u16_mixed` in this scope --> $DIR/syntax.rs:151:5 @@ -285,13 +267,11 @@ LL | exceed_u16_mixed(); note: found an item that was configured out --> $DIR/syntax.rs:115:4 | +LL | #[cfg(version("65536.0.65536"))] + | ----------------- the item is gated here +LL | LL | fn exceed_u16_mixed() {} | ^^^^^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/syntax.rs:113:14 - | -LL | #[cfg(version("65536.0.65536"))] - | ^^^^^^^^^^^^^^^^^ error: aborting due to 14 previous errors; 14 warnings emitted diff --git a/tests/ui/cfg/cmdline-false.stderr b/tests/ui/cfg/cmdline-false.stderr index da5eb0c892a..3d486803821 100644 --- a/tests/ui/cfg/cmdline-false.stderr +++ b/tests/ui/cfg/cmdline-false.stderr @@ -7,13 +7,10 @@ LL | foo(); note: found an item that was configured out --> $DIR/cmdline-false.rs:5:4 | +LL | #[cfg(false)] + | ----- the item is gated here LL | fn foo() {} | ^^^ -note: the item is gated here - --> $DIR/cmdline-false.rs:4:7 - | -LL | #[cfg(false)] - | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/cfg/diagnostics-cross-crate.rs b/tests/ui/cfg/diagnostics-cross-crate.rs index 00ac7e2fd08..f959332c817 100644 --- a/tests/ui/cfg/diagnostics-cross-crate.rs +++ b/tests/ui/cfg/diagnostics-cross-crate.rs @@ -11,24 +11,20 @@ fn main() { cfged_out::inner::uwu(); //~ ERROR cannot find function //~^ NOTE found an item that was configured out //~| NOTE not found in `cfged_out::inner` - //~| NOTE the item is gated here // The module isn't found - we would like to get a diagnostic, but currently don't due to // the awkward way the resolver diagnostics are currently implemented. cfged_out::inner::doesnt_exist::hello(); //~ ERROR failed to resolve //~^ NOTE could not find `doesnt_exist` in `inner` //~| NOTE found an item that was configured out - //~| NOTE the item is gated here // It should find the one in the right module, not the wrong one. cfged_out::inner::right::meow(); //~ ERROR cannot find function //~^ NOTE found an item that was configured out //~| NOTE not found in `cfged_out::inner::right - //~| NOTE the item is gated behind the `what-a-cool-feature` feature // Exists in the crate root - diagnostic. cfged_out::vanished(); //~ ERROR cannot find function //~^ NOTE found an item that was configured out //~| NOTE not found in `cfged_out` - //~| NOTE the item is gated here } diff --git a/tests/ui/cfg/diagnostics-cross-crate.stderr b/tests/ui/cfg/diagnostics-cross-crate.stderr index 155b3db2f42..658e5a442bd 100644 --- a/tests/ui/cfg/diagnostics-cross-crate.stderr +++ b/tests/ui/cfg/diagnostics-cross-crate.stderr @@ -1,5 +1,5 @@ error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner` - --> $DIR/diagnostics-cross-crate.rs:18:23 + --> $DIR/diagnostics-cross-crate.rs:17:23 | LL | cfged_out::inner::doesnt_exist::hello(); | ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner` @@ -7,13 +7,10 @@ LL | cfged_out::inner::doesnt_exist::hello(); note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:6:13 | +LL | #[cfg(false)] + | ----- the item is gated here LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/auxiliary/cfged_out.rs:5:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0425]: cannot find function `uwu` in crate `cfged_out` --> $DIR/diagnostics-cross-crate.rs:7:16 @@ -30,16 +27,13 @@ LL | cfged_out::inner::uwu(); note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:3:12 | +LL | #[cfg(false)] + | ----- the item is gated here LL | pub fn uwu() {} | ^^^ -note: the item is gated here - --> $DIR/auxiliary/cfged_out.rs:2:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0425]: cannot find function `meow` in module `cfged_out::inner::right` - --> $DIR/diagnostics-cross-crate.rs:24:30 + --> $DIR/diagnostics-cross-crate.rs:22:30 | LL | cfged_out::inner::right::meow(); | ^^^^ not found in `cfged_out::inner::right` @@ -47,16 +41,13 @@ LL | cfged_out::inner::right::meow(); note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:17:16 | +LL | #[cfg(feature = "what-a-cool-feature")] + | ------------------------------- the item is gated behind the `what-a-cool-feature` feature LL | pub fn meow() {} | ^^^^ -note: the item is gated behind the `what-a-cool-feature` feature - --> $DIR/auxiliary/cfged_out.rs:16:15 - | -LL | #[cfg(feature = "what-a-cool-feature")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0425]: cannot find function `vanished` in crate `cfged_out` - --> $DIR/diagnostics-cross-crate.rs:30:16 + --> $DIR/diagnostics-cross-crate.rs:27:16 | LL | cfged_out::vanished(); | ^^^^^^^^ not found in `cfged_out` @@ -64,13 +55,10 @@ LL | cfged_out::vanished(); note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:22:8 | +LL | #[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] + | -------------------------------------------- the item is gated here LL | pub fn vanished() {} | ^^^^^^^^ -note: the item is gated here - --> $DIR/auxiliary/cfged_out.rs:21:7 - | -LL | #[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 5 previous errors diff --git a/tests/ui/cfg/diagnostics-reexport-2.stderr b/tests/ui/cfg/diagnostics-reexport-2.stderr index e1f91fcc5d1..713cffce65b 100644 --- a/tests/ui/cfg/diagnostics-reexport-2.stderr +++ b/tests/ui/cfg/diagnostics-reexport-2.stderr @@ -7,13 +7,11 @@ LL | reexport::gated::foo(); note: found an item that was configured out --> $DIR/diagnostics-reexport-2.rs:10:13 | +LL | #[cfg(false)] + | ----- the item is gated here +... LL | pub mod gated { | ^^^^^ -note: the item is gated here - --> $DIR/diagnostics-reexport-2.rs:4:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0433]: failed to resolve: could not find `gated` in `reexport2` --> $DIR/diagnostics-reexport-2.rs:46:16 @@ -24,13 +22,11 @@ LL | reexport2::gated::foo(); note: found an item that was configured out --> $DIR/diagnostics-reexport-2.rs:10:13 | +LL | #[cfg(false)] + | ----- the item is gated here +... LL | pub mod gated { | ^^^^^ -note: the item is gated here - --> $DIR/diagnostics-reexport-2.rs:4:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0433]: failed to resolve: could not find `gated` in `reexport30` --> $DIR/diagnostics-reexport-2.rs:50:17 @@ -41,13 +37,11 @@ LL | reexport30::gated::foo(); note: found an item that was configured out --> $DIR/diagnostics-reexport-2.rs:10:13 | +LL | #[cfg(false)] + | ----- the item is gated here +... LL | pub mod gated { | ^^^^^ -note: the item is gated here - --> $DIR/diagnostics-reexport-2.rs:4:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0433]: failed to resolve: could not find `gated` in `reexport31` --> $DIR/diagnostics-reexport-2.rs:54:17 @@ -58,13 +52,11 @@ LL | reexport31::gated::foo(); note: found an item that was configured out --> $DIR/diagnostics-reexport-2.rs:10:13 | +LL | #[cfg(false)] + | ----- the item is gated here +... LL | pub mod gated { | ^^^^^ -note: the item is gated here - --> $DIR/diagnostics-reexport-2.rs:4:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0433]: failed to resolve: could not find `gated` in `reexport32` --> $DIR/diagnostics-reexport-2.rs:58:17 @@ -75,13 +67,11 @@ LL | reexport32::gated::foo(); note: found an item that was configured out --> $DIR/diagnostics-reexport-2.rs:10:13 | +LL | #[cfg(false)] + | ----- the item is gated here +... LL | pub mod gated { | ^^^^^ -note: the item is gated here - --> $DIR/diagnostics-reexport-2.rs:4:11 - | -LL | #[cfg(false)] - | ^^^^^ error: aborting due to 5 previous errors diff --git a/tests/ui/cfg/diagnostics-reexport.stderr b/tests/ui/cfg/diagnostics-reexport.stderr index bf1bbcba7e4..a3a6e13f475 100644 --- a/tests/ui/cfg/diagnostics-reexport.stderr +++ b/tests/ui/cfg/diagnostics-reexport.stderr @@ -7,13 +7,10 @@ LL | pub use a::x; note: found an item that was configured out --> $DIR/diagnostics-reexport.rs:18:12 | +LL | #[cfg(false)] + | ----- the item is gated here LL | pub fn x() {} | ^ -note: the item is gated here - --> $DIR/diagnostics-reexport.rs:17:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0432]: unresolved imports `b::x`, `b::y` --> $DIR/diagnostics-reexport.rs:22:13 @@ -26,23 +23,17 @@ LL | pub use b::{x, y}; note: found an item that was configured out --> $DIR/diagnostics-reexport.rs:29:12 | +LL | #[cfg(false)] + | ----- the item is gated here LL | pub fn x() {} | ^ -note: the item is gated here - --> $DIR/diagnostics-reexport.rs:28:11 - | -LL | #[cfg(false)] - | ^^^^^ note: found an item that was configured out --> $DIR/diagnostics-reexport.rs:32:12 | +LL | #[cfg(false)] + | ----- the item is gated here LL | pub fn y() {} | ^ -note: the item is gated here - --> $DIR/diagnostics-reexport.rs:31:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0425]: cannot find function `uwu` in module `inner` --> $DIR/diagnostics-reexport.rs:38:12 @@ -53,13 +44,10 @@ LL | inner::uwu(); note: found an item that was configured out --> $DIR/diagnostics-reexport.rs:8:20 | +LL | #[cfg(false)] + | ----- the item is gated here LL | pub use super::uwu; | ^^^ -note: the item is gated here - --> $DIR/diagnostics-reexport.rs:7:11 - | -LL | #[cfg(false)] - | ^^^^^ error: aborting due to 3 previous errors diff --git a/tests/ui/cfg/diagnostics-same-crate.stderr b/tests/ui/cfg/diagnostics-same-crate.stderr index f6a6fe388c5..a8d789e61d1 100644 --- a/tests/ui/cfg/diagnostics-same-crate.stderr +++ b/tests/ui/cfg/diagnostics-same-crate.stderr @@ -7,13 +7,11 @@ LL | use super::inner::doesnt_exist; note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:11:13 | +LL | #[cfg(false)] + | ----- the item is gated here +... LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/diagnostics-same-crate.rs:8:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0432]: unresolved import `super::inner::doesnt_exist` --> $DIR/diagnostics-same-crate.rs:35:23 @@ -24,13 +22,11 @@ LL | use super::inner::doesnt_exist::hi; note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:11:13 | +LL | #[cfg(false)] + | ----- the item is gated here +... LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/diagnostics-same-crate.rs:8:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner` --> $DIR/diagnostics-same-crate.rs:53:12 @@ -41,13 +37,11 @@ LL | inner::doesnt_exist::hello(); note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:11:13 | +LL | #[cfg(false)] + | ----- the item is gated here +... LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ -note: the item is gated here - --> $DIR/diagnostics-same-crate.rs:8:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0425]: cannot find function `uwu` in module `inner` --> $DIR/diagnostics-same-crate.rs:49:12 @@ -58,13 +52,10 @@ LL | inner::uwu(); note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:5:12 | +LL | #[cfg(false)] + | ----- the item is gated here LL | pub fn uwu() {} | ^^^ -note: the item is gated here - --> $DIR/diagnostics-same-crate.rs:4:11 - | -LL | #[cfg(false)] - | ^^^^^ error[E0425]: cannot find function `meow` in module `inner::right` --> $DIR/diagnostics-same-crate.rs:57:19 @@ -75,13 +66,10 @@ LL | inner::right::meow(); note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:26:16 | +LL | #[cfg(feature = "what-a-cool-feature")] + | ------------------------------- the item is gated behind the `what-a-cool-feature` feature LL | pub fn meow() {} | ^^^^ -note: the item is gated behind the `what-a-cool-feature` feature - --> $DIR/diagnostics-same-crate.rs:25:15 - | -LL | #[cfg(feature = "what-a-cool-feature")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0425]: cannot find function `uwu` in this scope --> $DIR/diagnostics-same-crate.rs:45:5 @@ -98,13 +86,10 @@ LL | vanished(); note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:41:8 | +LL | #[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] + | -------------------------------------------- the item is gated here LL | pub fn vanished() {} | ^^^^^^^^ -note: the item is gated here - --> $DIR/diagnostics-same-crate.rs:40:7 - | -LL | #[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 7 previous errors diff --git a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr index 44a33adbc47..3f833bd558b 100644 --- a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr +++ b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr @@ -7,13 +7,10 @@ LL | f() note: found an item that was configured out --> $DIR/nested-cfg-attr-conditional-compilation.rs:14:4 | +LL | #[cfg_attr(all(), cfg_attr(all(), cfg(false)))] + | ----- the item is gated here LL | fn f() {} | ^ -note: the item is gated here - --> $DIR/nested-cfg-attr-conditional-compilation.rs:13:39 - | -LL | #[cfg_attr(all(), cfg_attr(all(), cfg(false)))] - | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/conditional-compilation/test-cfg.stderr b/tests/ui/conditional-compilation/test-cfg.stderr index 1212074e417..379456f74b1 100644 --- a/tests/ui/conditional-compilation/test-cfg.stderr +++ b/tests/ui/conditional-compilation/test-cfg.stderr @@ -7,13 +7,11 @@ LL | foo(); note: found an item that was configured out --> $DIR/test-cfg.rs:5:4 | +LL | #[cfg(all(foo, bar))] // foo AND bar + | --- the item is gated here +LL | LL | fn foo() {} | ^^^ -note: the item is gated here - --> $DIR/test-cfg.rs:3:16 - | -LL | #[cfg(all(foo, bar))] // foo AND bar - | ^^^ error: aborting due to 1 previous error diff --git a/tests/ui/macros/builtin-std-paths-fail.stderr b/tests/ui/macros/builtin-std-paths-fail.stderr index 49034c3987b..85d2bd2132f 100644 --- a/tests/ui/macros/builtin-std-paths-fail.stderr +++ b/tests/ui/macros/builtin-std-paths-fail.stderr @@ -104,8 +104,8 @@ LL | #[std::test] | note: found an item that was configured out --> $SRC_DIR/std/src/lib.rs:LL:COL -note: the item is gated here - --> $SRC_DIR/std/src/lib.rs:LL:COL + | + = note: the item is gated here error: aborting due to 16 previous errors diff --git a/tests/ui/macros/macro-inner-attributes.stderr b/tests/ui/macros/macro-inner-attributes.stderr index cda53497f39..3c043c38abb 100644 --- a/tests/ui/macros/macro-inner-attributes.stderr +++ b/tests/ui/macros/macro-inner-attributes.stderr @@ -9,11 +9,8 @@ note: found an item that was configured out | LL | test!(a, | ^ -note: the item is gated here - --> $DIR/macro-inner-attributes.rs:8:13 - | LL | #[cfg(false)], - | ^^^^^ + | ----- the item is gated here help: there is a crate or module with a similar name | LL - a::bar(); diff --git a/tests/ui/macros/macro-outer-attributes.stderr b/tests/ui/macros/macro-outer-attributes.stderr index 9215754d4bb..4696bb774e3 100644 --- a/tests/ui/macros/macro-outer-attributes.stderr +++ b/tests/ui/macros/macro-outer-attributes.stderr @@ -7,13 +7,10 @@ LL | a::bar(); note: found an item that was configured out --> $DIR/macro-outer-attributes.rs:9:14 | +LL | #[cfg(false)], + | ----- the item is gated here LL | pub fn bar() { }); | ^^^ -note: the item is gated here - --> $DIR/macro-outer-attributes.rs:8:13 - | -LL | #[cfg(false)], - | ^^^^^ help: consider importing this function | LL + use b::bar; diff --git a/tests/ui/rustdoc/cfg-rustdoc.stderr b/tests/ui/rustdoc/cfg-rustdoc.stderr index fd0fcfd01aa..0e8a5dfea61 100644 --- a/tests/ui/rustdoc/cfg-rustdoc.stderr +++ b/tests/ui/rustdoc/cfg-rustdoc.stderr @@ -7,13 +7,10 @@ LL | let f = Foo; note: found an item that was configured out --> $DIR/cfg-rustdoc.rs:2:12 | +LL | #[cfg(doc)] + | --- the item is gated here LL | pub struct Foo; | ^^^ -note: the item is gated here - --> $DIR/cfg-rustdoc.rs:1:7 - | -LL | #[cfg(doc)] - | ^^^ error: aborting due to 1 previous error -- cgit 1.4.1-3-g733a5