Skip to content

Commit aeed63b

Browse files
committed
Auto merge of #57208 - estebank:issue-57198, r=petrochenkov
Do not complain about missing crate named as a keyword Fix #57198.
2 parents f39bd9b + cef919e commit aeed63b

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

src/librustc_resolve/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3925,8 +3925,11 @@ impl<'a> Resolver<'a> {
39253925
});
39263926
if let Some(candidate) = candidates.get(0) {
39273927
format!("did you mean `{}`?", candidate.path)
3928-
} else {
3928+
} else if !ident.is_reserved() {
39293929
format!("maybe a missing `extern crate {};`?", ident)
3930+
} else {
3931+
// the parser will already have complained about the keyword being used
3932+
return PathResult::NonModule(err_path_resolution());
39303933
}
39313934
} else if i == 0 {
39323935
format!("use of undeclared type or module `{}`", ident)

src/librustc_resolve/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ impl<'a> Resolver<'a> {
929929
let def = path_res.base_def();
930930
check_consistency(self, &path, path_span, kind, initial_def, def);
931931
}
932-
path_res @ PathResult::NonModule(..) | path_res @ PathResult::Failed(..) => {
932+
path_res @ PathResult::NonModule(..) | path_res @ PathResult::Failed(..) => {
933933
let (span, msg) = if let PathResult::Failed(span, msg, ..) = path_res {
934934
(span, msg)
935935
} else {
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-pass
2+
3+
mod m {
4+
pub fn r#for() {}
5+
}
6+
7+
fn main() {
8+
m::r#for();
9+
}

src/test/ui/issues/issue-57198.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mod m {
2+
pub fn r#for() {}
3+
}
4+
5+
fn main() {
6+
m::for();
7+
//~^ ERROR expected identifier, found keyword `for`
8+
}

src/test/ui/issues/issue-57198.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected identifier, found keyword `for`
2+
--> $DIR/issue-57198.rs:6:8
3+
|
4+
LL | m::for();
5+
| ^^^ expected identifier, found keyword
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)