Skip to content

Commit

Permalink
auto merge of #6121 : luqmana/rust/newtype-cc, r=graydon
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Apr 30, 2013
2 parents 84e22f2 + 10f290e commit c081ffb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librustc/middle/check_match.rs
Expand Up @@ -551,6 +551,8 @@ pub fn specialize(cx: @MatchCheckCtxt,
Some(vec::append(args, vec::from_slice(r.tail())))
}
def_variant(_, _) => None,

def_fn(*) |
def_struct(*) => {
// FIXME #4731: Is this right? --pcw
let new_args;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -912,6 +912,7 @@ pub impl mem_categorization_ctxt {
self.cat_pattern(subcmt, *subpat, op);
}
}
Some(&ast::def_fn(*)) |
Some(&ast::def_struct(*)) => {
for subpats.each |subpat| {
let cmt_field = self.cat_anon_struct_field(*subpat,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/resolve.rs
Expand Up @@ -4277,6 +4277,7 @@ pub impl Resolver {
pat_enum(path, _) => {
// This must be an enum variant, struct or const.
match self.resolve_path(path, ValueNS, false, visitor) {
Some(def @ def_fn(*)) |
Some(def @ def_variant(*)) |
Some(def @ def_struct(*)) |
Some(def @ def_const(*)) => {
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/middle/trans/_match.rs
Expand Up @@ -291,6 +291,7 @@ pub fn variant_opt(bcx: block, pat_id: ast::node_id)
}
::core::util::unreachable();
}
ast::def_fn(*) |
ast::def_struct(_) => {
return lit(UnitLikeStructLit(pat_id));
}
Expand Down Expand Up @@ -818,6 +819,7 @@ pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] {
// This could be one of: a tuple-like enum variant, a
// struct-like enum variant, or a struct.
match ccx.tcx.def_map.find(&cur.id) {
Some(&ast::def_fn(*)) |
Some(&ast::def_variant(*)) => {
add_to_set(ccx.tcx, &mut found,
variant_opt(bcx, cur.id));
Expand Down Expand Up @@ -1011,6 +1013,7 @@ pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool {
match pat.node {
ast::pat_enum(_, Some(_)) => {
match bcx.tcx().def_map.find(&pat.id) {
Some(&ast::def_fn(*)) |
Some(&ast::def_struct(*)) => true,
_ => false
}
Expand Down Expand Up @@ -1780,6 +1783,7 @@ pub fn bind_irrefutable_pat(bcx: block,
}
}
}
Some(&ast::def_fn(*)) |
Some(&ast::def_struct(*)) => {
match *sub_pats {
None => {
Expand Down
21 changes: 21 additions & 0 deletions src/test/run-pass/cross-crate-newtype-struct-pat.rs
@@ -0,0 +1,21 @@
// Copyright 2013 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.

// xfail-fast
// aux-build:newtype_struct_xc.rs

extern mod newtype_struct_xc;

fn main() {
let x = newtype_struct_xc::Au(21);
match x {
newtype_struct_xc::Au(n) => assert_eq!(n, 21)
}
}

0 comments on commit c081ffb

Please sign in to comment.