Auto merge of #133154 - estebank:issue-133137, r=wesleywiser
Reword resolve errors caused by likely missing crate in dep tree Reword label and add `help`: ``` error[E0432]: unresolved import `some_novel_crate` --> f704.rs:1:5 | 1 | use some_novel_crate::Type; | ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate` | = help: if you wanted to use a crate named `some_novel_crate`, use `cargo add some_novel_crate` to add it to your `Cargo.toml` ``` Fix #133137.
This commit is contained in:
commit
203e6c127c
108 changed files with 414 additions and 294 deletions
|
@ -24,6 +24,7 @@ use rustc_session::lint::builtin::{
|
|||
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
|
||||
};
|
||||
use rustc_session::lint::{AmbiguityErrorDiag, BuiltinLintDiag};
|
||||
use rustc_session::utils::was_invoked_from_cargo;
|
||||
use rustc_span::edit_distance::find_best_match_for_name;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
|
@ -800,7 +801,6 @@ 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
|
||||
|
@ -2034,13 +2034,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
(format!("`_` is not a valid crate or module name"), None)
|
||||
} else if self.tcx.sess.is_rust_2015() {
|
||||
(
|
||||
format!("you might be missing crate `{ident}`"),
|
||||
format!("use of unresolved module or unlinked crate `{ident}`"),
|
||||
Some((
|
||||
vec![(
|
||||
self.current_crate_outer_attr_insert_span,
|
||||
format!("extern crate {ident};\n"),
|
||||
)],
|
||||
format!("consider importing the `{ident}` crate"),
|
||||
if was_invoked_from_cargo() {
|
||||
format!(
|
||||
"if you wanted to use a crate named `{ident}`, use `cargo add {ident}` \
|
||||
to add it to your `Cargo.toml` and import it in your code",
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"you might be missing a crate named `{ident}`, add it to your \
|
||||
project and import it in your code",
|
||||
)
|
||||
},
|
||||
Applicability::MaybeIncorrect,
|
||||
)),
|
||||
)
|
||||
|
@ -2219,7 +2229,25 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
let descr = binding.res().descr();
|
||||
(format!("{descr} `{ident}` is not a crate or module"), suggestion)
|
||||
} else {
|
||||
(format!("use of undeclared crate or module `{ident}`"), suggestion)
|
||||
let suggestion = if suggestion.is_some() {
|
||||
suggestion
|
||||
} else if was_invoked_from_cargo() {
|
||||
Some((
|
||||
vec![],
|
||||
format!(
|
||||
"if you wanted to use a crate named `{ident}`, use `cargo add {ident}` \
|
||||
to add it to your `Cargo.toml`",
|
||||
),
|
||||
Applicability::MaybeIncorrect,
|
||||
))
|
||||
} else {
|
||||
Some((
|
||||
vec![],
|
||||
format!("you might be missing a crate named `{ident}`",),
|
||||
Applicability::MaybeIncorrect,
|
||||
))
|
||||
};
|
||||
(format!("use of unresolved module or unlinked crate `{ident}`"), suggestion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue