Skip to content

Commit

Permalink
Merge pull request rust-lang#34964 from petrochenkov/beta
Browse files Browse the repository at this point in the history
Backport fix for rust-lang#34209 to beta
  • Loading branch information
alexcrichton authored Jul 21, 2016
2 parents 019bee2 + 91f9e30 commit bca1473
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
27 changes: 27 additions & 0 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ty<'tcx>>,
Expand Down
23 changes: 23 additions & 0 deletions src/test/compile-fail/issue-34209.rs
Original file line number Diff line number Diff line change
@@ -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 <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 S {
A,
}

fn bug(l: S) {
match l {
S::B{ } => { },
//~^ ERROR ambiguous associated type; specify the type using the syntax `<S as Trait>::B`
//~| ERROR `S::B` does not name a struct or a struct variant
}
}

fn main () {}

0 comments on commit bca1473

Please sign in to comment.