Skip to content

Commit f7d21ef

Browse files
committed
---
yaml --- r: 136040 b: refs/heads/master c: a29df44 h: refs/heads/master v: v3
1 parent ffde64b commit f7d21ef

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 88baca7486607bb9799ab338afdf088b4cf9e2bd
2+
refs/heads/master: a29df44f51f950549957128ad1b65b2576a48383
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 749ff5e76a0d08837964e44c66654679a3a88bb8
55
refs/heads/try: ca87704735687dad44b26788c773df2d87b3b710

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5004,9 +5004,14 @@ pub fn check_enum_variants(ccx: &CrateCtxt,
50045004
};
50055005

50065006
// Check for duplicate discriminant values
5007-
if disr_vals.contains(&current_disr_val) {
5008-
span_err!(ccx.tcx.sess, v.span, E0081,
5009-
"discriminant value already exists");
5007+
match disr_vals.iter().position(|&x| x == current_disr_val) {
5008+
Some(i) => {
5009+
span_err!(ccx.tcx.sess, v.span, E0081,
5010+
"discriminant value `{}` already exists", disr_vals[i]);
5011+
span_note!(ccx.tcx.sess, ccx.tcx().map.span(variants[i].id.node),
5012+
"conflicting discriminant here")
5013+
}
5014+
None => {}
50105015
}
50115016
// Check for unrepresentable discriminant values
50125017
match hint {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
static N: int = 1;
12+
13+
enum Foo {
14+
A = 1,
15+
B = 1, //~ ERROR discriminant value `1` already exists
16+
//~^^ NOTE conflicting
17+
C = 0,
18+
D, //~ ERROR discriminant value `1` already exists
19+
//~^^^^^ NOTE conflicting
20+
E = N, //~ ERROR discriminant value `1` already exists
21+
//~^^^^^^^ NOTE conflicting
22+
}
23+
24+
fn main() {}

trunk/src/test/compile-fail/tag-variant-disr-dup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//error-pattern:discriminant value already exists
11+
//error-pattern:discriminant value
1212

1313
// black and white have the same discriminator value ...
1414

0 commit comments

Comments
 (0)