diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index ab59fafb65209..e81bca3c17183 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -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]; } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index e5d4d4a9dae2c..cdd7bef2c7fb9 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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); diff --git a/src/test/compile-fail/E0035.rs b/src/test/compile-fail/E0035.rs index 43f46e3578c20..9322d21d2a88d 100644 --- a/src/test/compile-fail/E0035.rs +++ b/src/test/compile-fail/E0035.rs @@ -17,4 +17,5 @@ impl Test { fn main() { let x = Test; x.method::(); //~ ERROR E0035 + //~| NOTE called with unneeded type parameters } diff --git a/src/test/compile-fail/E0036.rs b/src/test/compile-fail/E0036.rs index 35fd6e8942fe7..ecb6dac66f218 100644 --- a/src/test/compile-fail/E0036.rs +++ b/src/test/compile-fail/E0036.rs @@ -20,4 +20,5 @@ fn main() { let x = Test; let v = &[0]; x.method::(v); //~ ERROR E0036 + //~| NOTE Passed 2 type arguments, expected 1 } diff --git a/src/test/compile-fail/discrim-overflow-2.rs b/src/test/compile-fail/discrim-overflow-2.rs index 0ff740212e8fa..213683b580883 100644 --- a/src/test/compile-fail/discrim-overflow-2.rs +++ b/src/test/compile-fail/discrim-overflow-2.rs @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } diff --git a/src/test/compile-fail/discrim-overflow.rs b/src/test/compile-fail/discrim-overflow.rs index 7316e737b6da8..a3039b8d9573a 100644 --- a/src/test/compile-fail/discrim-overflow.rs +++ b/src/test/compile-fail/discrim-overflow.rs @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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;