Skip to content

Commit 3b097f0

Browse files
committed
---
yaml --- r: 137207 b: refs/heads/release-prep c: a29df44 h: refs/heads/master i: 137205: ee3fa20 137203: dd813f1 137199: a1a0053 v: v3
1 parent a10990d commit 3b097f0

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
@@ -29,4 +29,4 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2929
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
3030
refs/heads/libuv-update-temp-branch: 6ed22c618766f1f2a2e108eef8ce3f51be0f70b7
3131
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
32-
refs/heads/release-prep: 88baca7486607bb9799ab338afdf088b4cf9e2bd
32+
refs/heads/release-prep: a29df44f51f950549957128ad1b65b2576a48383

branches/release-prep/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() {}

branches/release-prep/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)