Skip to content

Commit

Permalink
Auto merge of #38817 - jseyfried:improve_unused_qualification_lint, r…
Browse files Browse the repository at this point in the history
…=petrochenkov

resolve: don't `unused_qualifications`-check global paths

We started `unused_qualifications`-checking global paths in #38014, causing #38682.
Fixes #38682.
r? @nrc
  • Loading branch information
bors committed Jan 5, 2017
2 parents 74e5b7d + 7dcacf1 commit ea2d41e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
25 changes: 12 additions & 13 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2336,20 +2336,19 @@ impl<'a> Resolver<'a> {
PathResult::Indeterminate => bug!("indetermined path result in resolve_qpath"),
};

if path.len() == 1 || global_by_default || result.base_def == Def::Err {
return Some(result);
}

let unqualified_result = {
match self.resolve_path(&[*path.last().unwrap()], Some(ns), None) {
PathResult::NonModule(path_res) => path_res.base_def,
PathResult::Module(module) => module.def().unwrap(),
_ => return Some(result),
if path.len() > 1 && !global_by_default && result.base_def != Def::Err &&
path[0].name != keywords::CrateRoot.name() && path[0].name != "$crate" {
let unqualified_result = {
match self.resolve_path(&[*path.last().unwrap()], Some(ns), None) {
PathResult::NonModule(path_res) => path_res.base_def,
PathResult::Module(module) => module.def().unwrap(),
_ => return Some(result),
}
};
if result.base_def == unqualified_result {
let lint = lint::builtin::UNUSED_QUALIFICATIONS;
self.session.add_lint(lint, id, span, "unnecessary qualification".to_string());
}
};
if result.base_def == unqualified_result && path[0].name != "$crate" {
let lint = lint::builtin::UNUSED_QUALIFICATIONS;
self.session.add_lint(lint, id, span, "unnecessary qualification".to_string());
}

Some(result)
Expand Down
9 changes: 5 additions & 4 deletions src/test/compile-fail/lint-qualification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ fn main() {

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

macro_rules! m {
() => { $crate::foo::bar(); }
}
m!(); // issue #37357
macro_rules! m { () => {
$crate::foo::bar(); // issue #37357
::foo::bar(); // issue #38682
} }
m!();
}

0 comments on commit ea2d41e

Please sign in to comment.