Do not complain about missing crate named as a keyword
This commit is contained in:
parent
59183180f7
commit
5a2c301106
@ -1034,6 +1034,8 @@ enum PathResult<'a> {
|
||||
NonModule(PathResolution),
|
||||
Indeterminate,
|
||||
Failed(Span, String, bool /* is the error from the last segment? */),
|
||||
/// Encountered an error that is reported elsewhere
|
||||
Ignore,
|
||||
}
|
||||
|
||||
enum ModuleKind {
|
||||
@ -1766,6 +1768,7 @@ impl<'a> Resolver<'a> {
|
||||
error_callback(self, span, ResolutionError::FailedToResolve(&msg));
|
||||
Def::Err
|
||||
}
|
||||
PathResult::Ignore => Def::Err,
|
||||
};
|
||||
|
||||
let segments: Vec<_> = segments.iter().map(|seg| {
|
||||
@ -3693,7 +3696,7 @@ impl<'a> Resolver<'a> {
|
||||
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
|
||||
err_path_resolution()
|
||||
}
|
||||
PathResult::Module(..) | PathResult::Failed(..) => return None,
|
||||
PathResult::Module(..) | PathResult::Failed(..) | PathResult::Ignore => return None,
|
||||
PathResult::Indeterminate => bug!("indetermined path result in resolve_qpath"),
|
||||
};
|
||||
|
||||
@ -3925,8 +3928,11 @@ impl<'a> Resolver<'a> {
|
||||
});
|
||||
if let Some(candidate) = candidates.get(0) {
|
||||
format!("did you mean `{}`?", candidate.path)
|
||||
} else {
|
||||
} else if !ident.is_used_keyword() {
|
||||
format!("maybe a missing `extern crate {};`?", ident)
|
||||
} else {
|
||||
// the parser will already have complained about the keyword being used
|
||||
return PathResult::Ignore;
|
||||
}
|
||||
} else if i == 0 {
|
||||
format!("use of undeclared type or module `{}`", ident)
|
||||
|
@ -364,7 +364,8 @@ impl<'a> Resolver<'a> {
|
||||
Ok(path_res.base_def())
|
||||
}
|
||||
PathResult::Indeterminate if !force => return Err(Determinacy::Undetermined),
|
||||
PathResult::NonModule(..) | PathResult::Indeterminate | PathResult::Failed(..) => {
|
||||
PathResult::NonModule(..) | PathResult::Indeterminate |
|
||||
PathResult::Failed(..) | PathResult::Ignore => {
|
||||
Err(Determinacy::Determined)
|
||||
}
|
||||
PathResult::Module(..) => unreachable!(),
|
||||
@ -929,7 +930,8 @@ 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(..) |
|
||||
path_res @ PathResult::Ignore => {
|
||||
let (span, msg) = if let PathResult::Failed(span, msg, ..) = path_res {
|
||||
(span, msg)
|
||||
} else {
|
||||
|
@ -767,7 +767,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
match path_res {
|
||||
PathResult::Module(module) => module,
|
||||
PathResult::Indeterminate => return false,
|
||||
PathResult::NonModule(..) | PathResult::Failed(..) => return true,
|
||||
PathResult::NonModule(..) | PathResult::Failed(..) |
|
||||
PathResult::Ignore => return true,
|
||||
}
|
||||
};
|
||||
|
||||
@ -861,6 +862,9 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
|
||||
module
|
||||
}
|
||||
PathResult::Ignore => {
|
||||
return None;
|
||||
}
|
||||
PathResult::Failed(span, msg, false) => {
|
||||
if no_ambiguity {
|
||||
assert!(directive.imported_module.get().is_none());
|
||||
|
9
src/test/ui/issues/issue-57198-pass.rs
Normal file
9
src/test/ui/issues/issue-57198-pass.rs
Normal file
@ -0,0 +1,9 @@
|
||||
// run-pass
|
||||
|
||||
mod m {
|
||||
pub fn r#for() {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
m::r#for();
|
||||
}
|
8
src/test/ui/issues/issue-57198.rs
Normal file
8
src/test/ui/issues/issue-57198.rs
Normal file
@ -0,0 +1,8 @@
|
||||
mod m {
|
||||
pub fn r#for() {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
m::for();
|
||||
//~^ ERROR expected identifier, found keyword `for`
|
||||
}
|
8
src/test/ui/issues/issue-57198.stderr
Normal file
8
src/test/ui/issues/issue-57198.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user