Structured suggestion for extern crate foo
when foo
isn't resolved in import
When encountering a name in an import that could have come from a crate that wasn't imported, use a structured suggestion to suggest `extern crate foo;` pointing at the right place in the crate. When encountering `_` in an import, do not suggest `extern crate _;`. ``` error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-3.rs:2:9 | LL | use spam::*; | ^^^^ maybe a missing crate `spam`? | help: consider importing the `spam` crate | LL + extern crate spam; | ```
This commit is contained in:
parent
4db3d12e6f
commit
b61570ac11
33 changed files with 192 additions and 64 deletions
|
@ -2026,14 +2026,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
Applicability::MaybeIncorrect,
|
||||
)),
|
||||
)
|
||||
} else if ident.name == kw::Underscore {
|
||||
(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}`"),
|
||||
Some((
|
||||
vec![],
|
||||
format!(
|
||||
"consider adding `extern crate {ident}` to use the `{ident}` crate"
|
||||
),
|
||||
vec![(
|
||||
self.current_crate_outer_attr_insert_span,
|
||||
format!("extern crate {ident};\n"),
|
||||
)],
|
||||
format!("consider importing the `{ident}` crate"),
|
||||
Applicability::MaybeIncorrect,
|
||||
)),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue