diff --git a/src/librustc/middle/borrowck/fragments.rs b/src/librustc/middle/borrowck/fragments.rs index 5785972c484..056d4f9d732 100644 --- a/src/librustc/middle/borrowck/fragments.rs +++ b/src/librustc/middle/borrowck/fragments.rs @@ -346,9 +346,10 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>, Rc>)>) { let parent_ty = parent_lp.to_type(); - let add_fragment_sibling_local = |field_name| { + let add_fragment_sibling_local = |field_name, variant_did| { add_fragment_sibling_core( - this, tcx, gathered_fragments, parent_lp.clone(), mc, field_name, origin_lp); + this, tcx, gathered_fragments, parent_lp.clone(), mc, field_name, origin_lp, + variant_did); }; match (&parent_ty.sty, enum_variant_info) { @@ -363,7 +364,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>, for i in range(0, tuple_len) { if i == tuple_idx { continue } let field_name = mc::PositionalField(i); - add_fragment_sibling_local(field_name); + add_fragment_sibling_local(field_name, None); } } @@ -376,7 +377,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>, continue; } let field_name = mc::NamedField(f.name); - add_fragment_sibling_local(field_name); + add_fragment_sibling_local(field_name, None); } } mc::PositionalField(tuple_idx) => { @@ -385,7 +386,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>, continue } let field_name = mc::PositionalField(i); - add_fragment_sibling_local(field_name); + add_fragment_sibling_local(field_name, None); } } } @@ -414,7 +415,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>, continue; } let field_name = mc::NamedField(variant_arg_ident.name); - add_fragment_sibling_local(field_name); + add_fragment_sibling_local(field_name, Some(variant_info.id)); } } mc::PositionalField(tuple_idx) => { @@ -424,7 +425,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>, continue; } let field_name = mc::PositionalField(i); - add_fragment_sibling_local(field_name); + add_fragment_sibling_local(field_name, None); } } } @@ -447,10 +448,11 @@ fn add_fragment_sibling_core<'tcx>(this: &MoveData<'tcx>, parent: Rc>, mc: mc::MutabilityCategory, new_field_name: mc::FieldName, - origin_lp: &Rc>) -> MovePathIndex { + origin_lp: &Rc>, + enum_variant_did: Option) -> MovePathIndex { let opt_variant_did = match parent.kind { LpDowncast(_, variant_did) => Some(variant_did), - LpVar(..) | LpUpvar(..) | LpExtend(..) => None, + LpVar(..) | LpUpvar(..) | LpExtend(..) => enum_variant_did, }; let loan_path_elem = LpInterior(mc::InteriorField(new_field_name)); diff --git a/src/test/run-pass/issue-19340-2.rs b/src/test/run-pass/issue-19340-2.rs new file mode 100644 index 00000000000..5179c1e2acb --- /dev/null +++ b/src/test/run-pass/issue-19340-2.rs @@ -0,0 +1,30 @@ +// Copyright 2014 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 Homura { + Madoka { + name: String, + age: u32, + }, +} + +fn main() { + let homura = Homura::Madoka { + name: "Akemi".into_string(), + age: 14, + }; + + match homura { + Homura::Madoka { + name, + age, + } => (), + }; +}