Skip to content

Do not complain about missing crate named as a keyword #57208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3925,8 +3925,11 @@ impl<'a> Resolver<'a> {
});
if let Some(candidate) = candidates.get(0) {
format!("did you mean `{}`?", candidate.path)
} else {
} else if !ident.is_reserved() {
format!("maybe a missing `extern crate {};`?", ident)
} else {
// the parser will already have complained about the keyword being used
return PathResult::NonModule(err_path_resolution());
}
} else if i == 0 {
format!("use of undeclared type or module `{}`", ident)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ impl<'a> Resolver<'a> {
let def = path_res.base_def();
check_consistency(self, &path, path_span, kind, initial_def, def);
}
path_res @ PathResult::NonModule(..) | path_res @ PathResult::Failed(..) => {
path_res @ PathResult::NonModule(..) | path_res @ PathResult::Failed(..) => {
let (span, msg) = if let PathResult::Failed(span, msg, ..) = path_res {
(span, msg)
} else {
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/issues/issue-57198-pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// run-pass

mod m {
pub fn r#for() {}
}

fn main() {
m::r#for();
}
8 changes: 8 additions & 0 deletions src/test/ui/issues/issue-57198.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod m {
pub fn r#for() {}
}

fn main() {
m::for();
//~^ ERROR expected identifier, found keyword `for`
}
8 changes: 8 additions & 0 deletions src/test/ui/issues/issue-57198.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: expected identifier, found keyword `for`
--> $DIR/issue-57198.rs:6:8
|
LL | m::for();
| ^^^ expected identifier, found keyword

error: aborting due to previous error