Skip to content

Commit 0d03d51

Browse files
committed
Auto merge of #38925 - petrochenkov:varass, r=jseyfried
Fix ICE when variant is used as a part of associated path Fixes #38862 r? @jseyfried
2 parents e57f061 + 7363674 commit 0d03d51

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Diff for: src/librustc_resolve/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2410,13 +2410,15 @@ impl<'a> Resolver<'a> {
24102410

24112411
match binding {
24122412
Ok(binding) => {
2413+
let def = binding.def();
2414+
let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(def);
24132415
if let Some(next_module) = binding.module() {
24142416
module = Some(next_module);
2415-
} else if binding.def() == Def::Err {
2417+
} else if def == Def::Err {
24162418
return PathResult::NonModule(err_path_resolution());
2417-
} else if opt_ns.is_some() && !(opt_ns == Some(MacroNS) && !is_last) {
2419+
} else if opt_ns.is_some() && (is_last || maybe_assoc) {
24182420
return PathResult::NonModule(PathResolution {
2419-
base_def: binding.def(),
2421+
base_def: def,
24202422
depth: path.len() - i - 1,
24212423
});
24222424
} else {

Diff for: src/test/compile-fail/resolve-variant-assoc-item.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum E { V }
12+
use E::V;
13+
14+
fn main() {
15+
E::V::associated_item; //~ ERROR failed to resolve. Not a module `V`
16+
V::associated_item; //~ ERROR failed to resolve. Not a module `V`
17+
}

Diff for: src/test/compile-fail/ufcs-partially-resolved.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ fn main() {
5555
<u8 as E::N>::NN; //~ ERROR unresolved method or associated constant `E::N::NN`
5656
<u8 as A::N>::NN; //~ ERROR unresolved method or associated constant `A::N::NN`
5757
let _: <u8 as Tr::Y>::NN; //~ ERROR unresolved associated type `Tr::Y::NN`
58-
let _: <u8 as E::Y>::NN; //~ ERROR unresolved associated type `E::Y::NN`
58+
let _: <u8 as E::Y>::NN; //~ ERROR failed to resolve. Not a module `Y`
5959
<u8 as Tr::Y>::NN; //~ ERROR unresolved method or associated constant `Tr::Y::NN`
60-
<u8 as E::Y>::NN; //~ ERROR unresolved method or associated constant `E::Y::NN`
60+
<u8 as E::Y>::NN; //~ ERROR failed to resolve. Not a module `Y`
6161

6262
let _: <u8 as Dr>::Z; //~ ERROR expected associated type, found method `Dr::Z`
6363
<u8 as Dr>::X; //~ ERROR expected method or associated constant, found associated type `Dr::X`

0 commit comments

Comments
 (0)