Skip to content

Commit c22ee1a

Browse files
estebankJohnHeitmann
authored andcommitted
Do not complain about missing crate named as a keyword
1 parent faaae93 commit c22ee1a

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

src/librustc_resolve/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,8 @@ enum PathResult<'a> {
10341034
NonModule(PathResolution),
10351035
Indeterminate,
10361036
Failed(Span, String, bool /* is the error from the last segment? */),
1037+
/// Encountered an error that is reported elsewhere
1038+
Ignore,
10371039
}
10381040

10391041
enum ModuleKind {
@@ -1759,6 +1761,7 @@ impl<'a> Resolver<'a> {
17591761
error_callback(self, span, ResolutionError::FailedToResolve(&msg));
17601762
Def::Err
17611763
}
1764+
PathResult::Ignore => Def::Err,
17621765
};
17631766

17641767
let segments: Vec<_> = segments.iter().map(|seg| {
@@ -3684,7 +3687,7 @@ impl<'a> Resolver<'a> {
36843687
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
36853688
err_path_resolution()
36863689
}
3687-
PathResult::Module(..) | PathResult::Failed(..) => return None,
3690+
PathResult::Module(..) | PathResult::Failed(..) | PathResult::Ignore => return None,
36883691
PathResult::Indeterminate => bug!("indetermined path result in resolve_qpath"),
36893692
};
36903693

@@ -3916,8 +3919,11 @@ impl<'a> Resolver<'a> {
39163919
});
39173920
if let Some(candidate) = candidates.get(0) {
39183921
format!("did you mean `{}`?", candidate.path)
3919-
} else {
3922+
} else if !ident.is_used_keyword() {
39203923
format!("maybe a missing `extern crate {};`?", ident)
3924+
} else {
3925+
// the parser will already have complained about the keyword being used
3926+
return PathResult::Ignore;
39213927
}
39223928
} else if i == 0 {
39233929
format!("use of undeclared type or module `{}`", ident)

src/librustc_resolve/macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ impl<'a> Resolver<'a> {
365365
Ok(path_res.base_def())
366366
}
367367
PathResult::Indeterminate if !force => return Err(Determinacy::Undetermined),
368-
PathResult::NonModule(..) | PathResult::Indeterminate | PathResult::Failed(..) => {
368+
PathResult::NonModule(..) | PathResult::Indeterminate |
369+
PathResult::Failed(..) | PathResult::Ignore => {
369370
Err(Determinacy::Determined)
370371
}
371372
PathResult::Module(..) => unreachable!(),
@@ -930,7 +931,8 @@ impl<'a> Resolver<'a> {
930931
let def = path_res.base_def();
931932
check_consistency(self, &path, path_span, kind, initial_def, def);
932933
}
933-
path_res @ PathResult::NonModule(..) | path_res @ PathResult::Failed(..) => {
934+
path_res @ PathResult::NonModule(..) | path_res @ PathResult::Failed(..) |
935+
path_res @ PathResult::Ignore => {
934936
let (span, msg) = if let PathResult::Failed(span, msg, ..) = path_res {
935937
(span, msg)
936938
} else {

src/librustc_resolve/resolve_imports.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
774774
match path_res {
775775
PathResult::Module(module) => module,
776776
PathResult::Indeterminate => return false,
777-
PathResult::NonModule(..) | PathResult::Failed(..) => return true,
777+
PathResult::NonModule(..) | PathResult::Failed(..) |
778+
PathResult::Ignore => return true,
778779
}
779780
};
780781

@@ -868,6 +869,9 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
868869

869870
module
870871
}
872+
PathResult::Ignore => {
873+
return None;
874+
}
871875
PathResult::Failed(span, msg, false) => {
872876
if no_ambiguity {
873877
assert!(directive.imported_module.get().is_none());
Lines changed: 9 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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)