diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 069a09183a738..6d27021832caa 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -559,7 +559,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { etc: bool, expected: Ty<'tcx>) { let tcx = self.tcx; - let def = tcx.expect_def(pat.id); + let def = self.finish_resolving_struct_path(path, pat.id, path.span); let variant = match self.def_struct_variant(def, path.span) { Some((_, variant)) => variant, None => { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 3bc90f05d2536..e966e201bdbed 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3704,6 +3704,33 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expected); } + // Finish resolving a path in a struct expression or pattern `S::A { .. }` if necessary. + // The newly resolved definition is written into `def_map`. + pub fn finish_resolving_struct_path(&self, + path: &hir::Path, + node_id: ast::NodeId, + span: Span) + -> Def + { + let path_res = self.tcx().expect_resolution(node_id); + if path_res.depth == 0 { + // If fully resolved already, we don't have to do anything. + path_res.base_def + } else { + let base_ty_end = path.segments.len() - path_res.depth; + let (_ty, def) = AstConv::finish_resolving_def_to_ty(self, self, span, + PathParamMode::Optional, + path_res.base_def, + None, + node_id, + &path.segments[..base_ty_end], + &path.segments[base_ty_end..]); + // Write back the new resolution. + self.tcx().def_map.borrow_mut().insert(node_id, def::PathResolution::new(def)); + def + } + } + pub fn resolve_ty_and_def_ufcs<'b>(&self, path_res: def::PathResolution, opt_self_ty: Option>, diff --git a/src/test/compile-fail/issue-34209.rs b/src/test/compile-fail/issue-34209.rs new file mode 100644 index 0000000000000..a7879700b5494 --- /dev/null +++ b/src/test/compile-fail/issue-34209.rs @@ -0,0 +1,23 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum S { + A, +} + +fn bug(l: S) { + match l { + S::B{ } => { }, + //~^ ERROR ambiguous associated type; specify the type using the syntax `::B` + //~| ERROR `S::B` does not name a struct or a struct variant + } +} + +fn main () {}