diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 6c7d0efbc0297..47f9ad5398bca 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -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) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 8454dbc3410c9..379ebe2399474 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -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 { diff --git a/src/test/ui/issues/issue-57198-pass.rs b/src/test/ui/issues/issue-57198-pass.rs new file mode 100644 index 0000000000000..3857def9824f8 --- /dev/null +++ b/src/test/ui/issues/issue-57198-pass.rs @@ -0,0 +1,9 @@ +// run-pass + +mod m { + pub fn r#for() {} +} + +fn main() { + m::r#for(); +} diff --git a/src/test/ui/issues/issue-57198.rs b/src/test/ui/issues/issue-57198.rs new file mode 100644 index 0000000000000..714a46cbc9f48 --- /dev/null +++ b/src/test/ui/issues/issue-57198.rs @@ -0,0 +1,8 @@ +mod m { + pub fn r#for() {} +} + +fn main() { + m::for(); + //~^ ERROR expected identifier, found keyword `for` +} diff --git a/src/test/ui/issues/issue-57198.stderr b/src/test/ui/issues/issue-57198.stderr new file mode 100644 index 0000000000000..c4d297b2d95eb --- /dev/null +++ b/src/test/ui/issues/issue-57198.stderr @@ -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 +