Skip to content

Commit bca1473

Browse files
authored
Merge pull request rust-lang#34964 from petrochenkov/beta
Backport fix for rust-lang#34209 to beta
2 parents 019bee2 + 91f9e30 commit bca1473

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/librustc_typeck/check/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
559559
etc: bool, expected: Ty<'tcx>) {
560560
let tcx = self.tcx;
561561

562-
let def = tcx.expect_def(pat.id);
562+
let def = self.finish_resolving_struct_path(path, pat.id, path.span);
563563
let variant = match self.def_struct_variant(def, path.span) {
564564
Some((_, variant)) => variant,
565565
None => {

src/librustc_typeck/check/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -3704,6 +3704,33 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
37043704
expected);
37053705
}
37063706

3707+
// Finish resolving a path in a struct expression or pattern `S::A { .. }` if necessary.
3708+
// The newly resolved definition is written into `def_map`.
3709+
pub fn finish_resolving_struct_path(&self,
3710+
path: &hir::Path,
3711+
node_id: ast::NodeId,
3712+
span: Span)
3713+
-> Def
3714+
{
3715+
let path_res = self.tcx().expect_resolution(node_id);
3716+
if path_res.depth == 0 {
3717+
// If fully resolved already, we don't have to do anything.
3718+
path_res.base_def
3719+
} else {
3720+
let base_ty_end = path.segments.len() - path_res.depth;
3721+
let (_ty, def) = AstConv::finish_resolving_def_to_ty(self, self, span,
3722+
PathParamMode::Optional,
3723+
path_res.base_def,
3724+
None,
3725+
node_id,
3726+
&path.segments[..base_ty_end],
3727+
&path.segments[base_ty_end..]);
3728+
// Write back the new resolution.
3729+
self.tcx().def_map.borrow_mut().insert(node_id, def::PathResolution::new(def));
3730+
def
3731+
}
3732+
}
3733+
37073734
pub fn resolve_ty_and_def_ufcs<'b>(&self,
37083735
path_res: def::PathResolution,
37093736
opt_self_ty: Option<Ty<'tcx>>,

src/test/compile-fail/issue-34209.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 S {
12+
A,
13+
}
14+
15+
fn bug(l: S) {
16+
match l {
17+
S::B{ } => { },
18+
//~^ ERROR ambiguous associated type; specify the type using the syntax `<S as Trait>::B`
19+
//~| ERROR `S::B` does not name a struct or a struct variant
20+
}
21+
}
22+
23+
fn main () {}

0 commit comments

Comments
 (0)