Skip to content

Commit f50b56c

Browse files
committedOct 6, 2014
auto merge of #17414 : jakub-/rust/issue-17405, r=alexcrichton
Fixes #17405. Fixes #17518. Fixes #17800.
2 parents 6d15f28 + b9896cb commit f50b56c

File tree

7 files changed

+86
-14
lines changed

7 files changed

+86
-14
lines changed
 

‎src/librustc/diagnostics.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ register_diagnostics!(
3838
E0017,
3939
E0019,
4040
E0020,
41-
E0021,
4241
E0022,
4342
E0023,
4443
E0024,
@@ -62,7 +61,6 @@ register_diagnostics!(
6261
E0045,
6362
E0046,
6463
E0047,
65-
E0048,
6664
E0049,
6765
E0050,
6866
E0051,
@@ -117,8 +115,6 @@ register_diagnostics!(
117115
E0109,
118116
E0110,
119117
E0113,
120-
E0114,
121-
E0115,
122118
E0116,
123119
E0117,
124120
E0118,
@@ -152,5 +148,7 @@ register_diagnostics!(
152148
E0158,
153149
E0159,
154150
E0161,
155-
E0162
151+
E0162,
152+
E0163,
153+
E0164
156154
)

‎src/librustc/middle/typeck/check/_match.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -382,26 +382,43 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
382382

383383
// Find the variant that was specified.
384384
match tcx.def_map.borrow().find(&pat_id) {
385-
Some(&def::DefVariant(found_enum_id, variant_id, _))
385+
Some(&def::DefVariant(found_enum_id, variant_id, true))
386386
if found_enum_id == enum_id => {
387387
// Get the struct fields from this struct-like enum variant.
388-
let class_fields = ty::lookup_struct_fields(tcx, variant_id);
389-
390-
check_struct_pat_fields(pcx, span, fields, class_fields,
388+
let struct_fields = ty::lookup_struct_fields(tcx, variant_id);
389+
check_struct_pat_fields(pcx, span, fields, struct_fields,
391390
variant_id, substitutions, etc);
391+
fcx.write_ty(pat_id, expected);
392+
}
393+
Some(&def::DefVariant(_, _, false)) => {
394+
let name = pprust::path_to_string(path);
395+
span_err!(tcx.sess, span, E0163,
396+
"`{}` does not name a struct variant", name);
397+
fcx.write_error(pat_id);
398+
}
399+
Some(&def::DefVariant(_, _, true)) => {
400+
let name = pprust::path_to_string(path);
401+
span_err!(tcx.sess, span, E0164,
402+
"`{}` does not name a variant of the type being matched against", name);
403+
fcx.write_error(pat_id);
392404
}
393405
Some(&def::DefStruct(..)) |
394-
Some(&def::DefVariant(..)) |
395406
Some(&def::DefTy(..)) => {
396407
let name = pprust::path_to_string(path);
397408
span_err!(tcx.sess, span, E0028,
398-
"mismatched types: expected `{}`, found `{}`",
399-
fcx.infcx().ty_to_string(expected), name);
409+
"`{}` does not name a variant", name);
410+
fcx.write_error(pat_id);
400411
}
401412
_ => {
402413
tcx.sess.span_bug(span, "resolve didn't write in variant");
403414
}
404415
}
416+
417+
if ty::type_is_error(fcx.node_ty(pat_id)) {
418+
for field in fields.iter() {
419+
check_pat(pcx, &*field.pat, ty::mk_err());
420+
}
421+
}
405422
}
406423

407424
// Pattern checking is top-down rather than bottom-up so that bindings get

‎src/librustc/middle/typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4330,7 +4330,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
43304330
// Resolve the path.
43314331
let def = tcx.def_map.borrow().find(&id).map(|i| *i);
43324332
let struct_id = match def {
4333-
Some(def::DefVariant(enum_id, variant_id, _)) => {
4333+
Some(def::DefVariant(enum_id, variant_id, true)) => {
43344334
check_struct_enum_variant(fcx, id, expr.span, enum_id,
43354335
variant_id, fields.as_slice());
43364336
enum_id

‎src/test/compile-fail/issue-15896.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818
let e = B(REB(()), Tau { t: 3 });
1919
let u = match e {
2020
B(
21-
Tau{t: x}, //~ ERROR mismatched types
21+
Tau{t: x}, //~ ERROR `Tau` does not name a variant
2222
_) => x,
2323
};
2424
}

‎src/test/compile-fail/issue-17405.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 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 Foo {
12+
Bar(int)
13+
}
14+
15+
fn main() {
16+
match Bar(1i) {
17+
Foo { i } => () //~ ERROR `Foo` does not name a variant
18+
}
19+
}

‎src/test/compile-fail/issue-17518.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 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 SomeEnum {
12+
E
13+
}
14+
15+
fn main() {
16+
E { name: "foobar" }; //~ ERROR `E` does not name a structure
17+
}

‎src/test/compile-fail/issue-17800.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 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 MyOption<T> {
12+
MySome(T),
13+
MyNone,
14+
}
15+
16+
fn main() {
17+
match MySome(42i) {
18+
MySome { x: 42i } => (), //~ ERROR `MySome` does not name a struct variant
19+
_ => (),
20+
}
21+
}

0 commit comments

Comments
 (0)
Please sign in to comment.