diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2017-01-08 16:38:40 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2017-01-08 16:40:50 +0300 |
| commit | 7363674f2e7a7f1eaf31ac0a2cdc53ee3409017c (patch) | |
| tree | d454389cc132050490b0704f3c035681e9f20d9e | |
| parent | 7ac9d337dcc544b4b1959997cdd36f1ba0c8d3e1 (diff) | |
| download | rust-7363674f2e7a7f1eaf31ac0a2cdc53ee3409017c.tar.gz rust-7363674f2e7a7f1eaf31ac0a2cdc53ee3409017c.zip | |
Fix ICE when variant is used as a part of associated type
| -rw-r--r-- | src/librustc_resolve/lib.rs | 8 | ||||
| -rw-r--r-- | src/test/compile-fail/resolve-variant-assoc-item.rs | 17 | ||||
| -rw-r--r-- | src/test/compile-fail/ufcs-partially-resolved.rs | 4 |
3 files changed, 24 insertions, 5 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 39a9194cf5e..74df14e881d 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2410,13 +2410,15 @@ impl<'a> Resolver<'a> { match binding { Ok(binding) => { + let def = binding.def(); + let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(def); if let Some(next_module) = binding.module() { module = Some(next_module); - } else if binding.def() == Def::Err { + } else if def == Def::Err { return PathResult::NonModule(err_path_resolution()); - } else if opt_ns.is_some() && !(opt_ns == Some(MacroNS) && !is_last) { + } else if opt_ns.is_some() && (is_last || maybe_assoc) { return PathResult::NonModule(PathResolution { - base_def: binding.def(), + base_def: def, depth: path.len() - i - 1, }); } else { diff --git a/src/test/compile-fail/resolve-variant-assoc-item.rs b/src/test/compile-fail/resolve-variant-assoc-item.rs new file mode 100644 index 00000000000..869eed5a8d7 --- /dev/null +++ b/src/test/compile-fail/resolve-variant-assoc-item.rs @@ -0,0 +1,17 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum E { V } +use E::V; + +fn main() { + E::V::associated_item; //~ ERROR failed to resolve. Not a module `V` + V::associated_item; //~ ERROR failed to resolve. Not a module `V` +} diff --git a/src/test/compile-fail/ufcs-partially-resolved.rs b/src/test/compile-fail/ufcs-partially-resolved.rs index 5337272343b..7e2c9771180 100644 --- a/src/test/compile-fail/ufcs-partially-resolved.rs +++ b/src/test/compile-fail/ufcs-partially-resolved.rs @@ -55,9 +55,9 @@ fn main() { <u8 as E::N>::NN; //~ ERROR unresolved method or associated constant `E::N::NN` <u8 as A::N>::NN; //~ ERROR unresolved method or associated constant `A::N::NN` let _: <u8 as Tr::Y>::NN; //~ ERROR unresolved associated type `Tr::Y::NN` - let _: <u8 as E::Y>::NN; //~ ERROR unresolved associated type `E::Y::NN` + let _: <u8 as E::Y>::NN; //~ ERROR failed to resolve. Not a module `Y` <u8 as Tr::Y>::NN; //~ ERROR unresolved method or associated constant `Tr::Y::NN` - <u8 as E::Y>::NN; //~ ERROR unresolved method or associated constant `E::Y::NN` + <u8 as E::Y>::NN; //~ ERROR failed to resolve. Not a module `Y` let _: <u8 as Dr>::Z; //~ ERROR expected associated type, found method `Dr::Z` <u8 as Dr>::X; //~ ERROR expected method or associated constant, found associated type `Dr::X` |
