Skip to content

Commit

Permalink
Rollup merge of rust-lang#36873 - GuillaumeGomez:e0035_e0036, r=jonat…
Browse files Browse the repository at this point in the history
…handturner

Update E0035, E0036 and E0370 to new error format

Fixes rust-lang#35634.
Fixes rust-lang#35206.
Fixes rust-lang#35207.

r? @jonathandturner
  • Loading branch information
Manishearth authored Oct 1, 2016
2 parents 2e5837a + 8ea426a commit e506bfa
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 24 deletions.
20 changes: 16 additions & 4 deletions src/librustc_typeck/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,25 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {

if num_supplied_types > 0 && num_supplied_types != num_method_types {
if num_method_types == 0 {
span_err!(self.tcx.sess, self.span, E0035,
"does not take type parameters");
struct_span_err!(self.tcx.sess, self.span, E0035,
"does not take type parameters")
.span_label(self.span, &"called with unneeded type parameters")
.emit();
} else {
span_err!(self.tcx.sess, self.span, E0036,
struct_span_err!(self.tcx.sess, self.span, E0036,
"incorrect number of type parameters given for this method: \
expected {}, found {}",
num_method_types, num_supplied_types);
num_method_types, num_supplied_types)
.span_label(self.span,
&format!("Passed {} type argument{}, expected {}",
num_supplied_types,
if num_supplied_types != 1 {
"s"
} else {
""
},
num_method_types))
.emit();
}
supplied_method_types = vec![self.tcx.types.err; num_method_types];
}
Expand Down
10 changes: 6 additions & 4 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,10 +1164,12 @@ fn convert_enum_def<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
} else if let Some(disr) = repr_type.disr_incr(tcx, prev_disr) {
Some(disr)
} else {
span_err!(tcx.sess, v.span, E0370,
"enum discriminant overflowed on value after {}; \
set explicitly via {} = {} if that is desired outcome",
prev_disr.unwrap(), v.node.name, wrapped_disr);
struct_span_err!(tcx.sess, v.span, E0370,
"enum discriminant overflowed")
.span_label(v.span, &format!("overflowed on value after {}", prev_disr.unwrap()))
.note(&format!("explicitly set `{} = {}` if that is desired outcome",
v.node.name, wrapped_disr))
.emit();
None
}.unwrap_or(wrapped_disr);
prev_disr = Some(disr);
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/E0035.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ impl Test {
fn main() {
let x = Test;
x.method::<i32>(); //~ ERROR E0035
//~| NOTE called with unneeded type parameters
}
1 change: 1 addition & 0 deletions src/test/compile-fail/E0036.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ fn main() {
let x = Test;
let v = &[0];
x.method::<i32, i32>(v); //~ ERROR E0036
//~| NOTE Passed 2 type arguments, expected 1
}
32 changes: 24 additions & 8 deletions src/test/compile-fail/discrim-overflow-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ fn f_i8() {
enum A {
Ok = i8::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed on value after 127i8; set explicitly via OhNo = -128i8 if that is desired outcome
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 127i8
//~| NOTE explicitly set `OhNo = -128i8` if that is desired outcome
}
}

Expand All @@ -33,7 +35,9 @@ fn f_u8() {
enum A {
Ok = u8::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed on value after 255u8; set explicitly via OhNo = 0u8 if that is desired outcome
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 255u8
//~| NOTE explicitly set `OhNo = 0u8` if that is desired outcome
}
}

Expand All @@ -42,7 +46,9 @@ fn f_i16() {
enum A {
Ok = i16::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 32767i16
//~| NOTE explicitly set `OhNo = -32768i16` if that is desired outcome
}
}

Expand All @@ -51,7 +57,9 @@ fn f_u16() {
enum A {
Ok = u16::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 65535u16
//~| NOTE explicitly set `OhNo = 0u16` if that is desired outcome
}
}

Expand All @@ -60,7 +68,9 @@ fn f_i32() {
enum A {
Ok = i32::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 2147483647i32
//~| NOTE explicitly set `OhNo = -2147483648i32` if that is desired outcome
}
}

Expand All @@ -69,7 +79,9 @@ fn f_u32() {
enum A {
Ok = u32::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 4294967295u32
//~| NOTE explicitly set `OhNo = 0u32` if that is desired outcome
}
}

Expand All @@ -78,7 +90,9 @@ fn f_i64() {
enum A {
Ok = i64::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 9223372036854775807i64
//~| NOTE explicitly set `OhNo = -9223372036854775808i64` if that is desired outcome
}
}

Expand All @@ -87,7 +101,9 @@ fn f_u64() {
enum A {
Ok = u64::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 18446744073709551615u64
//~| NOTE explicitly set `OhNo = 0u64` if that is desired outcome
}
}

Expand Down
32 changes: 24 additions & 8 deletions src/test/compile-fail/discrim-overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ fn f_i8() {
enum A {
Ok = i8::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed on value after 127i8; set explicitly via OhNo = -128i8 if that is desired outcome
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 127i8
//~| NOTE explicitly set `OhNo = -128i8` if that is desired outcome
}

let x = A::Ok;
Expand All @@ -33,7 +35,9 @@ fn f_u8() {
enum A {
Ok = u8::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed on value after 255u8; set explicitly via OhNo = 0u8 if that is desired outcome
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 255u8
//~| NOTE explicitly set `OhNo = 0u8` if that is desired outcome
}

let x = A::Ok;
Expand All @@ -44,7 +48,9 @@ fn f_i16() {
enum A {
Ok = i16::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| NOTE overflowed on value after 32767i16
//~| NOTE explicitly set `OhNo = -32768i16` if that is desired outcome
}

let x = A::Ok;
Expand All @@ -55,7 +61,9 @@ fn f_u16() {
enum A {
Ok = u16::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| overflowed on value after 65535u16
//~| NOTE explicitly set `OhNo = 0u16` if that is desired outcome
}

let x = A::Ok;
Expand All @@ -66,7 +74,9 @@ fn f_i32() {
enum A {
Ok = i32::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| overflowed on value after 2147483647i32
//~| NOTE explicitly set `OhNo = -2147483648i32` if that is desired outcome
}

let x = A::Ok;
Expand All @@ -77,7 +87,9 @@ fn f_u32() {
enum A {
Ok = u32::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| overflowed on value after 4294967295u32
//~| NOTE explicitly set `OhNo = 0u32` if that is desired outcome
}

let x = A::Ok;
Expand All @@ -88,7 +100,9 @@ fn f_i64() {
enum A {
Ok = i64::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| overflowed on value after 9223372036854775807i64
//~| NOTE explicitly set `OhNo = -9223372036854775808i64` if that is desired outcome
}

let x = A::Ok;
Expand All @@ -99,7 +113,9 @@ fn f_u64() {
enum A {
Ok = u64::MAX - 1,
Ok2,
OhNo, //~ ERROR enum discriminant overflowed
OhNo, //~ ERROR enum discriminant overflowed [E0370]
//~| overflowed on value after 18446744073709551615u64
//~| NOTE explicitly set `OhNo = 0u64` if that is desired outcome
}

let x = A::Ok;
Expand Down

0 comments on commit e506bfa

Please sign in to comment.