diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 0a6b55c79e85..dabb019ffdb8 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -32,7 +32,7 @@ use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edition::Edition; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::{SourceMap, Spanned}; -use rustc_span::{BytePos, Ident, Span, Symbol, SyntaxContext, kw, sym}; +use rustc_span::{BytePos, Ident, RemapPathScopeComponents, Span, Symbol, SyntaxContext, kw, sym}; use thin_vec::{ThinVec, thin_vec}; use tracing::{debug, instrument}; @@ -908,7 +908,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { err.help(msg); return err; } - err.multipart_suggestion(msg, suggestions, applicability); + err.multipart_suggestion_verbose(msg, suggestions, applicability); } let module = match module { @@ -2633,12 +2633,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // } // ``` Some(LateDecl::RibDef(Res::Local(id))) => { - Some(*self.pat_span_map.get(&id).unwrap()) + Some((*self.pat_span_map.get(&id).unwrap(), "a", "local binding")) } // Name matches item from a local name binding // created by `use` declaration. For example: // ``` - // pub Foo: &str = ""; + // pub const Foo: &str = ""; // // mod submod { // use super::Foo; @@ -2646,19 +2646,27 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // // binding `Foo`. // } // ``` - Some(LateDecl::Decl(name_binding)) => Some(name_binding.span), + Some(LateDecl::Decl(name_binding)) => Some(( + name_binding.span, + name_binding.res().article(), + name_binding.res().descr(), + )), _ => None, }; - let suggestion = match_span.map(|span| { - ( - vec![(span, String::from(""))], - format!("`{ident}` is defined here, but is not a type"), - Applicability::MaybeIncorrect, - ) - }); let message = format!("cannot find type `{ident}` in {scope}"); - (message, format!("use of undeclared type `{ident}`"), suggestion) + let label = if let Some((span, article, descr)) = match_span { + format!( + "`{ident}` is declared as {article} {descr} at `{}`, not a type", + self.tcx + .sess + .source_map() + .span_to_short_string(span, RemapPathScopeComponents::DIAGNOSTICS) + ) + } else { + format!("use of undeclared type `{ident}`") + }; + (message, label, None) } else { let mut suggestion = None; if ident.name == sym::alloc { diff --git a/tests/ui/resolve/issue-81508.stderr b/tests/ui/resolve/issue-81508.stderr index 4e8d98989c3c..49fe9fbf6211 100644 --- a/tests/ui/resolve/issue-81508.stderr +++ b/tests/ui/resolve/issue-81508.stderr @@ -1,20 +1,14 @@ error[E0433]: cannot find type `Baz` in this scope --> $DIR/issue-81508.rs:11:20 | -LL | let Baz: &str = ""; - | --- help: `Baz` is defined here, but is not a type -LL | LL | println!("{}", Baz::Bar); - | ^^^ use of undeclared type `Baz` + | ^^^ `Baz` is declared as a local binding at `issue-81508.rs:9:9`, not a type error[E0433]: cannot find type `Foo` in this scope --> $DIR/issue-81508.rs:20:24 | -LL | use super::Foo; - | ---------- help: `Foo` is defined here, but is not a type -LL | fn function() { LL | println!("{}", Foo::Bar); - | ^^^ use of undeclared type `Foo` + | ^^^ `Foo` is declared as a constant at `issue-81508.rs:18:9`, not a type error: aborting due to 2 previous errors diff --git a/tests/ui/simd/portable-intrinsics-arent-exposed.stderr b/tests/ui/simd/portable-intrinsics-arent-exposed.stderr index 21a6c3d65081..c7c36c841091 100644 --- a/tests/ui/simd/portable-intrinsics-arent-exposed.stderr +++ b/tests/ui/simd/portable-intrinsics-arent-exposed.stderr @@ -2,10 +2,13 @@ error[E0433]: cannot find `core` in the crate root --> $DIR/portable-intrinsics-arent-exposed.rs:5:5 | LL | use core::simd::intrinsics; - | ^^^^ - | | - | you might be missing crate `core` - | help: try using `std` instead of `core`: `std` + | ^^^^ you might be missing crate `core` + | +help: try using `std` instead of `core` + | +LL - use core::simd::intrinsics; +LL + use std::simd::intrinsics; + | error[E0432]: unresolved import `std::simd::intrinsics` --> $DIR/portable-intrinsics-arent-exposed.rs:6:5 diff --git a/tests/ui/traits/const-traits/issue-102156.stderr b/tests/ui/traits/const-traits/issue-102156.stderr index 22cd13527c6d..1fce5f1b18fe 100644 --- a/tests/ui/traits/const-traits/issue-102156.stderr +++ b/tests/ui/traits/const-traits/issue-102156.stderr @@ -2,21 +2,26 @@ error[E0433]: cannot find `core` in the crate root --> $DIR/issue-102156.rs:5:5 | LL | use core::convert::{From, TryFrom}; - | ^^^^ - | | - | you might be missing crate `core` - | help: try using `std` instead of `core`: `std` + | ^^^^ you might be missing crate `core` + | +help: try using `std` instead of `core` + | +LL - use core::convert::{From, TryFrom}; +LL + use std::convert::{From, TryFrom}; + | error[E0433]: cannot find `core` in the crate root --> $DIR/issue-102156.rs:5:5 | LL | use core::convert::{From, TryFrom}; - | ^^^^ - | | - | you might be missing crate `core` - | help: try using `std` instead of `core`: `std` + | ^^^^ you might be missing crate `core` | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: try using `std` instead of `core` + | +LL - use core::convert::{From, TryFrom}; +LL + use std::convert::{From, TryFrom}; + | error: aborting due to 2 previous errors