add a suggestion about undeclared alloc
module
This commit is contained in:
parent
ff0e14829e
commit
acb9f9ba38
4 changed files with 39 additions and 9 deletions
|
@ -420,6 +420,10 @@ impl<'a> Resolver<'a> {
|
||||||
err.span_label(span, label);
|
err.span_label(span, label);
|
||||||
|
|
||||||
if let Some((suggestions, msg, applicability)) = suggestion {
|
if let Some((suggestions, msg, applicability)) = suggestion {
|
||||||
|
if suggestions.is_empty() {
|
||||||
|
err.help(&msg);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
err.multipart_suggestion(&msg, suggestions, applicability);
|
err.multipart_suggestion(&msg, suggestions, applicability);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2523,19 +2523,29 @@ impl<'a> Resolver<'a> {
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
format!("use of undeclared crate or module `{}`", ident),
|
format!("use of undeclared crate or module `{}`", ident),
|
||||||
self.find_similarly_named_module_or_crate(
|
if ident.name == sym::alloc {
|
||||||
ident.name,
|
Some((
|
||||||
&parent_scope.module,
|
vec![],
|
||||||
)
|
|
||||||
.map(|sugg| {
|
|
||||||
(
|
|
||||||
vec![(ident.span, sugg.to_string())],
|
|
||||||
String::from(
|
String::from(
|
||||||
"there is a crate or module with a similar name",
|
"add `extern crate alloc` to use the builtin `alloc` module",
|
||||||
),
|
),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
self.find_similarly_named_module_or_crate(
|
||||||
|
ident.name,
|
||||||
|
&parent_scope.module,
|
||||||
)
|
)
|
||||||
}),
|
.map(|sugg| {
|
||||||
|
(
|
||||||
|
vec![(ident.span, sugg.to_string())],
|
||||||
|
String::from(
|
||||||
|
"there is a crate or module with a similar name",
|
||||||
|
),
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
5
src/test/ui/suggestions/undeclared-module-alloc.rs
Normal file
5
src/test/ui/suggestions/undeclared-module-alloc.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
// edition:2018
|
||||||
|
|
||||||
|
use alloc::rc::Rc; //~ ERROR failed to resolve: use of undeclared crate or module `alloc`
|
||||||
|
|
||||||
|
fn main() {}
|
11
src/test/ui/suggestions/undeclared-module-alloc.stderr
Normal file
11
src/test/ui/suggestions/undeclared-module-alloc.stderr
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
error[E0433]: failed to resolve: use of undeclared crate or module `alloc`
|
||||||
|
--> $DIR/undeclared-module-alloc.rs:3:5
|
||||||
|
|
|
||||||
|
LL | use alloc::rc::Rc;
|
||||||
|
| ^^^^^ use of undeclared crate or module `alloc`
|
||||||
|
|
|
||||||
|
= help: add `extern crate alloc` to use the builtin `alloc` module
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0433`.
|
Loading…
Add table
Add a link
Reference in a new issue