Skip to content

Commit

Permalink
Update E0370 to new error format
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 30, 2016
1 parent 4d5e81d commit 8ea426a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
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
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 8ea426a

Please sign in to comment.