提交 7dcacf15 编写于 作者: J Jeffrey Seyfried

Don't `unused_qualifications`-check global paths.

上级 d3a2efa1
......@@ -2336,20 +2336,19 @@ fn resolve_qpath(&mut self,
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)
......
......@@ -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!();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册