diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-10-22 22:08:08 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-10-25 20:25:59 +0000 |
| commit | 199ed20aa6aa64ca58b4a924395bf9e1e71cf8a8 (patch) | |
| tree | 5771d5cf0d2982179dd1d27deca587eab655a070 | |
| parent | 67f26f7e0c23b6dcd00f21eae66d7a302cfa17bf (diff) | |
| download | rust-199ed20aa6aa64ca58b4a924395bf9e1e71cf8a8.tar.gz rust-199ed20aa6aa64ca58b4a924395bf9e1e71cf8a8.zip | |
Fix `$crate`-related regressions.
| -rw-r--r-- | src/librustc_resolve/lib.rs | 10 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-qualification.rs | 7 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index c6f73b804e3..210cabdd8ec 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -845,6 +845,10 @@ impl<'a> ModuleS<'a> { _ => false, } } + + fn is_local(&self) -> bool { + self.normal_ancestor_id.is_some() + } } impl<'a> fmt::Debug for ModuleS<'a> { @@ -1585,8 +1589,7 @@ impl<'a> Resolver<'a> { ctxt = ctxt.source().0; } let module = self.invocations[&ctxt.source().1].module.get(); - let crate_root = - if module.def_id().unwrap().is_local() { self.graph_root } else { module }; + let crate_root = if module.is_local() { self.graph_root } else { module }; return Success(PrefixFound(crate_root, 1)) } @@ -2569,7 +2572,8 @@ impl<'a> Resolver<'a> { let unqualified_def = resolve_identifier_with_fallback(self, None); let qualified_binding = self.resolve_module_relative_path(span, segments, namespace); match (qualified_binding, unqualified_def) { - (Ok(binding), Some(ref ud)) if binding.def() == ud.def => { + (Ok(binding), Some(ref ud)) if binding.def() == ud.def && + segments[0].identifier.name.as_str() != "$crate" => { self.session .add_lint(lint::builtin::UNUSED_QUALIFICATIONS, id, diff --git a/src/test/compile-fail/lint-qualification.rs b/src/test/compile-fail/lint-qualification.rs index 0ad3d2c5e73..af9b21dadd1 100644 --- a/src/test/compile-fail/lint-qualification.rs +++ b/src/test/compile-fail/lint-qualification.rs @@ -18,4 +18,11 @@ fn main() { use foo::bar; foo::bar(); //~ ERROR: unnecessary qualification bar(); + + let _ = || -> Result<(), ()> { try!(Ok(())); Ok(()) }; // issue #37345 + + macro_rules! m { + () => { $crate::foo::bar(); } + } + m!(); // issue #37357 } |
