Closes #15524.
};
// Check for duplicate discriminant values
- if disr_vals.contains(¤t_disr_val) {
- span_err!(ccx.tcx.sess, v.span, E0081,
- "discriminant value already exists");
+ match disr_vals.iter().position(|&x| x == current_disr_val) {
+ Some(i) => {
+ span_err!(ccx.tcx.sess, v.span, E0081,
+ "discriminant value `{}` already exists", disr_vals[i]);
+ span_note!(ccx.tcx.sess, ccx.tcx().map.span(variants[i].id.node),
+ "conflicting discriminant here")
+ }
+ None => {}
}
// Check for unrepresentable discriminant values
match hint {
--- /dev/null
+// 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 <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.
+
+static N: int = 1;
+
+enum Foo {
+ A = 1,
+ B = 1, //~ ERROR discriminant value `1` already exists
+ //~^^ NOTE conflicting
+ C = 0,
+ D, //~ ERROR discriminant value `1` already exists
+ //~^^^^^ NOTE conflicting
+ E = N, //~ ERROR discriminant value `1` already exists
+ //~^^^^^^^ NOTE conflicting
+}
+
+fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-//error-pattern:discriminant value already exists
+//error-pattern:discriminant value
// black and white have the same discriminator value ...