Make suggestion verbose and fix incorrect suggestion usage

This commit is contained in:
Esteban Küber 2026-02-13 23:15:09 +00:00
parent c73b3d20c6
commit 257a415e05
4 changed files with 43 additions and 33 deletions

View file

@ -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 {

View file

@ -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

View file

@ -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

View file

@ -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