Skip to content

Commit ea2d41e

Browse files
committed
Auto merge of #38817 - jseyfried:improve_unused_qualification_lint, r=petrochenkov
resolve: don't `unused_qualifications`-check global paths We started `unused_qualifications`-checking global paths in #38014, causing #38682. Fixes #38682. r? @nrc
2 parents 74e5b7d + 7dcacf1 commit ea2d41e

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/librustc_resolve/lib.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -2336,20 +2336,19 @@ impl<'a> Resolver<'a> {
23362336
PathResult::Indeterminate => bug!("indetermined path result in resolve_qpath"),
23372337
};
23382338

2339-
if path.len() == 1 || global_by_default || result.base_def == Def::Err {
2340-
return Some(result);
2341-
}
2342-
2343-
let unqualified_result = {
2344-
match self.resolve_path(&[*path.last().unwrap()], Some(ns), None) {
2345-
PathResult::NonModule(path_res) => path_res.base_def,
2346-
PathResult::Module(module) => module.def().unwrap(),
2347-
_ => return Some(result),
2339+
if path.len() > 1 && !global_by_default && result.base_def != Def::Err &&
2340+
path[0].name != keywords::CrateRoot.name() && path[0].name != "$crate" {
2341+
let unqualified_result = {
2342+
match self.resolve_path(&[*path.last().unwrap()], Some(ns), None) {
2343+
PathResult::NonModule(path_res) => path_res.base_def,
2344+
PathResult::Module(module) => module.def().unwrap(),
2345+
_ => return Some(result),
2346+
}
2347+
};
2348+
if result.base_def == unqualified_result {
2349+
let lint = lint::builtin::UNUSED_QUALIFICATIONS;
2350+
self.session.add_lint(lint, id, span, "unnecessary qualification".to_string());
23482351
}
2349-
};
2350-
if result.base_def == unqualified_result && path[0].name != "$crate" {
2351-
let lint = lint::builtin::UNUSED_QUALIFICATIONS;
2352-
self.session.add_lint(lint, id, span, "unnecessary qualification".to_string());
23532352
}
23542353

23552354
Some(result)

src/test/compile-fail/lint-qualification.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ fn main() {
2121

2222
let _ = || -> Result<(), ()> { try!(Ok(())); Ok(()) }; // issue #37345
2323

24-
macro_rules! m {
25-
() => { $crate::foo::bar(); }
26-
}
27-
m!(); // issue #37357
24+
macro_rules! m { () => {
25+
$crate::foo::bar(); // issue #37357
26+
::foo::bar(); // issue #38682
27+
} }
28+
m!();
2829
}

0 commit comments

Comments
 (0)