From 683ebc2dec0a5b88eb3eaf146e6855ea299d17b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 5 Feb 2020 21:08:07 -0800 Subject: [PATCH 01/21] On mismatched argument count point at arguments --- src/librustc_typeck/check/mod.rs | 54 ++++++++++++++++--- src/test/ui/arg-count-mismatch.rs | 2 +- src/test/ui/arg-count-mismatch.stderr | 6 ++- src/test/ui/c-variadic/variadic-ffi-1.rs | 4 +- src/test/ui/c-variadic/variadic-ffi-1.stderr | 12 +++-- src/test/ui/error-codes/E0057.stderr | 12 +++-- src/test/ui/error-codes/E0060.rs | 2 +- src/test/ui/error-codes/E0060.stderr | 6 ++- src/test/ui/error-codes/E0061.rs | 4 +- src/test/ui/error-codes/E0061.stderr | 12 +++-- src/test/ui/hrtb/issue-58451.rs | 2 +- src/test/ui/hrtb/issue-58451.stderr | 6 ++- src/test/ui/issues/issue-16939.stderr | 6 ++- src/test/ui/issues/issue-18819.stderr | 6 ++- src/test/ui/issues/issue-26094.rs | 8 +-- src/test/ui/issues/issue-26094.stderr | 10 ++-- src/test/ui/issues/issue-3044.rs | 2 +- src/test/ui/issues/issue-3044.stderr | 10 ++-- src/test/ui/issues/issue-4935.rs | 2 +- src/test/ui/issues/issue-4935.stderr | 6 ++- src/test/ui/methods/method-call-err-msg.rs | 8 +-- .../ui/methods/method-call-err-msg.stderr | 39 ++++++++++---- .../mismatched_types/overloaded-calls-bad.rs | 4 +- .../overloaded-calls-bad.stderr | 12 +++-- src/test/ui/not-enough-arguments.rs | 2 +- src/test/ui/not-enough-arguments.stderr | 6 ++- .../ui/resolve/resolve-primitive-fallback.rs | 2 +- .../resolve/resolve-primitive-fallback.stderr | 6 ++- src/test/ui/span/E0057.stderr | 12 +++-- src/test/ui/span/issue-34264.stderr | 12 +++-- src/test/ui/span/missing-unit-argument.stderr | 28 +++++----- ...ant-priority-higher-than-other-inherent.rs | 2 +- ...priority-higher-than-other-inherent.stderr | 6 ++- .../type-ascription-instead-of-initializer.rs | 2 +- ...e-ascription-instead-of-initializer.stderr | 6 ++- 35 files changed, 214 insertions(+), 105 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 7e5d27d93b3..d2bef80ac36 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3761,17 +3761,58 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { error_code: &str, c_variadic: bool, sugg_unit: bool| { + let (span, start_span, args) = match &expr.kind { + hir::ExprKind::Call(hir::Expr { span, .. }, args) => (*span, *span, &args[..]), + hir::ExprKind::MethodCall(path_segment, span, args) => ( + *span, + // `sp` doesn't point at the whole `foo.bar()`, only at `bar`. + path_segment + .args + .and_then(|args| args.args.iter().last()) + // Account for `foo.bar::()`. + .map(|arg| { + // Skip the closing `>`. + tcx.sess + .source_map() + .next_point(tcx.sess.source_map().next_point(arg.span())) + }) + .unwrap_or(*span), + &args[1..], // Skip the receiver. + ), + k => span_bug!(sp, "checking argument types on a non-call: `{:?}`", k), + }; + let arg_spans = if args.is_empty() { + // foo() + // ^^^-- supplied 0 arguments + // | + // expected 2 arguments + vec![tcx.sess.source_map().next_point(start_span).with_hi(sp.hi())] + } else { + // foo(1, 2, 3) + // ^^^ - - - supplied 3 arguments + // | + // expected 2 arguments + args.iter().map(|arg| arg.span).collect::>() + }; + let mut err = tcx.sess.struct_span_err_with_code( - sp, + span, &format!( "this function takes {}{} but {} {} supplied", if c_variadic { "at least " } else { "" }, - potentially_plural_count(expected_count, "parameter"), - potentially_plural_count(arg_count, "parameter"), + potentially_plural_count(expected_count, "argument"), + potentially_plural_count(arg_count, "argument"), if arg_count == 1 { "was" } else { "were" } ), DiagnosticId::Error(error_code.to_owned()), ); + let label = format!("supplied {}", potentially_plural_count(arg_count, "argument")); + for (i, span) in arg_spans.into_iter().enumerate() { + err.span_label( + span, + if arg_count == 0 || i + 1 == arg_count { &label } else { "" }, + ); + } if let Some(def_s) = def_span.map(|sp| tcx.sess.source_map().def_span(sp)) { err.span_label(def_s, "defined here"); @@ -3788,11 +3829,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } else { err.span_label( - sp, + span, format!( "expected {}{}", if c_variadic { "at least " } else { "" }, - potentially_plural_count(expected_count, "parameter") + potentially_plural_count(expected_count, "argument") ), ); } @@ -5494,8 +5535,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx.sess.span_err( span, - "this function can only be invoked \ - directly, not through a function pointer", + "this function can only be invoked directly, not through a function pointer", ); } diff --git a/src/test/ui/arg-count-mismatch.rs b/src/test/ui/arg-count-mismatch.rs index cf7487069c1..18926f5daf7 100644 --- a/src/test/ui/arg-count-mismatch.rs +++ b/src/test/ui/arg-count-mismatch.rs @@ -1,4 +1,4 @@ -// error-pattern: parameters were supplied +// error-pattern: arguments were supplied fn f(x: isize) { } diff --git a/src/test/ui/arg-count-mismatch.stderr b/src/test/ui/arg-count-mismatch.stderr index 44f16041363..7bc06134a69 100644 --- a/src/test/ui/arg-count-mismatch.stderr +++ b/src/test/ui/arg-count-mismatch.stderr @@ -1,11 +1,13 @@ -error[E0061]: this function takes 1 parameter but 0 parameters were supplied +error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/arg-count-mismatch.rs:5:28 | LL | fn f(x: isize) { } | -------------- defined here LL | LL | fn main() { let i: (); i = f(); } - | ^^^ expected 1 parameter + | ^-- supplied 0 arguments + | | + | expected 1 argument error: aborting due to previous error diff --git a/src/test/ui/c-variadic/variadic-ffi-1.rs b/src/test/ui/c-variadic/variadic-ffi-1.rs index 6a3ff24b674..e7197a9d168 100644 --- a/src/test/ui/c-variadic/variadic-ffi-1.rs +++ b/src/test/ui/c-variadic/variadic-ffi-1.rs @@ -13,8 +13,8 @@ extern "C" fn bar(f: isize, x: u8) {} fn main() { unsafe { - foo(); //~ ERROR this function takes at least 2 parameters but 0 parameters were supplied - foo(1); //~ ERROR this function takes at least 2 parameters but 1 parameter was supplied + foo(); //~ ERROR this function takes at least 2 arguments but 0 arguments were supplied + foo(1); //~ ERROR this function takes at least 2 arguments but 1 argument was supplied let x: unsafe extern "C" fn(f: isize, x: u8) = foo; //~ ERROR mismatched types let y: extern "C" fn(f: isize, x: u8, ...) = bar; //~ ERROR mismatched types diff --git a/src/test/ui/c-variadic/variadic-ffi-1.stderr b/src/test/ui/c-variadic/variadic-ffi-1.stderr index 05d839a0c55..318b8aabafb 100644 --- a/src/test/ui/c-variadic/variadic-ffi-1.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-1.stderr @@ -4,23 +4,27 @@ error[E0045]: C-variadic function must have C or cdecl calling convention LL | fn printf(_: *const u8, ...); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadics require C or cdecl calling convention -error[E0060]: this function takes at least 2 parameters but 0 parameters were supplied +error[E0060]: this function takes at least 2 arguments but 0 arguments were supplied --> $DIR/variadic-ffi-1.rs:16:9 | LL | fn foo(f: isize, x: u8, ...); | ----------------------------- defined here ... LL | foo(); - | ^^^^^ expected at least 2 parameters + | ^^^-- supplied 0 arguments + | | + | expected at least 2 arguments -error[E0060]: this function takes at least 2 parameters but 1 parameter was supplied +error[E0060]: this function takes at least 2 arguments but 1 argument was supplied --> $DIR/variadic-ffi-1.rs:17:9 | LL | fn foo(f: isize, x: u8, ...); | ----------------------------- defined here ... LL | foo(1); - | ^^^^^^ expected at least 2 parameters + | ^^^ - supplied 1 argument + | | + | expected at least 2 arguments error[E0308]: mismatched types --> $DIR/variadic-ffi-1.rs:19:56 diff --git a/src/test/ui/error-codes/E0057.stderr b/src/test/ui/error-codes/E0057.stderr index 6b5890cac36..31579e28289 100644 --- a/src/test/ui/error-codes/E0057.stderr +++ b/src/test/ui/error-codes/E0057.stderr @@ -1,14 +1,18 @@ -error[E0057]: this function takes 1 parameter but 0 parameters were supplied +error[E0057]: this function takes 1 argument but 0 arguments were supplied --> $DIR/E0057.rs:3:13 | LL | let a = f(); - | ^^^ expected 1 parameter + | ^-- supplied 0 arguments + | | + | expected 1 argument -error[E0057]: this function takes 1 parameter but 2 parameters were supplied +error[E0057]: this function takes 1 argument but 2 arguments were supplied --> $DIR/E0057.rs:5:13 | LL | let c = f(2, 3); - | ^^^^^^^ expected 1 parameter + | ^ - - supplied 2 arguments + | | + | expected 1 argument error: aborting due to 2 previous errors diff --git a/src/test/ui/error-codes/E0060.rs b/src/test/ui/error-codes/E0060.rs index 2bb490fb3ea..941eb2a210b 100644 --- a/src/test/ui/error-codes/E0060.rs +++ b/src/test/ui/error-codes/E0060.rs @@ -5,5 +5,5 @@ extern "C" { fn main() { unsafe { printf(); } //~^ ERROR E0060 - //~| expected at least 1 parameter + //~| expected at least 1 argument } diff --git a/src/test/ui/error-codes/E0060.stderr b/src/test/ui/error-codes/E0060.stderr index 8a2e7d1a72c..a600592c6c2 100644 --- a/src/test/ui/error-codes/E0060.stderr +++ b/src/test/ui/error-codes/E0060.stderr @@ -1,11 +1,13 @@ -error[E0060]: this function takes at least 1 parameter but 0 parameters were supplied +error[E0060]: this function takes at least 1 argument but 0 arguments were supplied --> $DIR/E0060.rs:6:14 | LL | fn printf(_: *const u8, ...) -> u32; | ------------------------------------ defined here ... LL | unsafe { printf(); } - | ^^^^^^^^ expected at least 1 parameter + | ^^^^^^-- supplied 0 arguments + | | + | expected at least 1 argument error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0061.rs b/src/test/ui/error-codes/E0061.rs index e64ea36ac92..c7b5fe4310e 100644 --- a/src/test/ui/error-codes/E0061.rs +++ b/src/test/ui/error-codes/E0061.rs @@ -5,9 +5,9 @@ fn f2(a: u16) {} fn main() { f(0); //~^ ERROR E0061 - //~| expected 2 parameters + //~| expected 2 arguments f2(); //~^ ERROR E0061 - //~| expected 1 parameter + //~| expected 1 argument } diff --git a/src/test/ui/error-codes/E0061.stderr b/src/test/ui/error-codes/E0061.stderr index 73103241f7a..dfefa0df313 100644 --- a/src/test/ui/error-codes/E0061.stderr +++ b/src/test/ui/error-codes/E0061.stderr @@ -1,20 +1,24 @@ -error[E0061]: this function takes 2 parameters but 1 parameter was supplied +error[E0061]: this function takes 2 arguments but 1 argument was supplied --> $DIR/E0061.rs:6:5 | LL | fn f(a: u16, b: &str) {} | --------------------- defined here ... LL | f(0); - | ^^^^ expected 2 parameters + | ^ - supplied 1 argument + | | + | expected 2 arguments -error[E0061]: this function takes 1 parameter but 0 parameters were supplied +error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/E0061.rs:10:5 | LL | fn f2(a: u16) {} | ------------- defined here ... LL | f2(); - | ^^^^ expected 1 parameter + | ^^-- supplied 0 arguments + | | + | expected 1 argument error: aborting due to 2 previous errors diff --git a/src/test/ui/hrtb/issue-58451.rs b/src/test/ui/hrtb/issue-58451.rs index 229e5057678..f36d549e476 100644 --- a/src/test/ui/hrtb/issue-58451.rs +++ b/src/test/ui/hrtb/issue-58451.rs @@ -9,5 +9,5 @@ where {} fn main() { - f(&[f()]); //~ ERROR this function takes 1 parameter + f(&[f()]); //~ ERROR this function takes 1 argument } diff --git a/src/test/ui/hrtb/issue-58451.stderr b/src/test/ui/hrtb/issue-58451.stderr index 4648c0182b9..c0915808bf5 100644 --- a/src/test/ui/hrtb/issue-58451.stderr +++ b/src/test/ui/hrtb/issue-58451.stderr @@ -1,4 +1,4 @@ -error[E0061]: this function takes 1 parameter but 0 parameters were supplied +error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/issue-58451.rs:12:9 | LL | / fn f(i: I) @@ -9,7 +9,9 @@ LL | | {} | |__- defined here ... LL | f(&[f()]); - | ^^^ expected 1 parameter + | ^-- supplied 0 arguments + | | + | expected 1 argument error: aborting due to previous error diff --git a/src/test/ui/issues/issue-16939.stderr b/src/test/ui/issues/issue-16939.stderr index 5df2119c141..103f56fa04d 100644 --- a/src/test/ui/issues/issue-16939.stderr +++ b/src/test/ui/issues/issue-16939.stderr @@ -1,8 +1,10 @@ -error[E0057]: this function takes 0 parameters but 1 parameter was supplied +error[E0057]: this function takes 0 arguments but 1 argument was supplied --> $DIR/issue-16939.rs:5:9 | LL | |t| f(t); - | ^^^^ expected 0 parameters + | ^ - supplied 1 argument + | | + | expected 0 arguments error: aborting due to previous error diff --git a/src/test/ui/issues/issue-18819.stderr b/src/test/ui/issues/issue-18819.stderr index 41e8470ecd0..a952c9b46c9 100644 --- a/src/test/ui/issues/issue-18819.stderr +++ b/src/test/ui/issues/issue-18819.stderr @@ -1,11 +1,13 @@ -error[E0061]: this function takes 2 parameters but 1 parameter was supplied +error[E0061]: this function takes 2 arguments but 1 argument was supplied --> $DIR/issue-18819.rs:16:5 | LL | fn print_x(_: &dyn Foo, extra: &str) { | ----------------------------------------------- defined here ... LL | print_x(X); - | ^^^^^^^^^^ expected 2 parameters + | ^^^^^^^ - supplied 1 argument + | | + | expected 2 arguments error: aborting due to previous error diff --git a/src/test/ui/issues/issue-26094.rs b/src/test/ui/issues/issue-26094.rs index b9433849853..78fb0491d82 100644 --- a/src/test/ui/issues/issue-26094.rs +++ b/src/test/ui/issues/issue-26094.rs @@ -1,13 +1,13 @@ macro_rules! some_macro { ($other: expr) => ({ - $other(None) - //~^ this function takes 0 parameters but 1 parameter was supplied + $other(None) //~ NOTE supplied 1 argument }) } -fn some_function() {} +fn some_function() {} //~ NOTE defined here fn main() { some_macro!(some_function); - //~^ in this expansion of some_macro! + //~^ ERROR this function takes 0 arguments but 1 argument was supplied + //~| NOTE expected 0 arguments } diff --git a/src/test/ui/issues/issue-26094.stderr b/src/test/ui/issues/issue-26094.stderr index 0b5b6d5a750..2038d88bf46 100644 --- a/src/test/ui/issues/issue-26094.stderr +++ b/src/test/ui/issues/issue-26094.stderr @@ -1,16 +1,14 @@ -error[E0061]: this function takes 0 parameters but 1 parameter was supplied - --> $DIR/issue-26094.rs:3:9 +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/issue-26094.rs:10:17 | LL | $other(None) - | ^^^^^^^^^^^^ expected 0 parameters + | ---- supplied 1 argument ... LL | fn some_function() {} | ------------------ defined here ... LL | some_macro!(some_function); - | --------------------------- in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + | ^^^^^^^^^^^^^ expected 0 arguments error: aborting due to previous error diff --git a/src/test/ui/issues/issue-3044.rs b/src/test/ui/issues/issue-3044.rs index 26db04b69b4..81d76a90eb0 100644 --- a/src/test/ui/issues/issue-3044.rs +++ b/src/test/ui/issues/issue-3044.rs @@ -2,5 +2,5 @@ fn main() { let needlesArr: Vec = vec!['a', 'f']; needlesArr.iter().fold(|x, y| { }); - //~^^ ERROR this function takes 2 parameters but 1 parameter was supplied + //~^^ ERROR this function takes 2 arguments but 1 argument was supplied } diff --git a/src/test/ui/issues/issue-3044.stderr b/src/test/ui/issues/issue-3044.stderr index 35a85b604b2..d2c010659ed 100644 --- a/src/test/ui/issues/issue-3044.stderr +++ b/src/test/ui/issues/issue-3044.stderr @@ -1,8 +1,12 @@ -error[E0061]: this function takes 2 parameters but 1 parameter was supplied +error[E0061]: this function takes 2 arguments but 1 argument was supplied --> $DIR/issue-3044.rs:3:23 | -LL | needlesArr.iter().fold(|x, y| { - | ^^^^ expected 2 parameters +LL | needlesArr.iter().fold(|x, y| { + | _______________________^^^^_- + | | | + | | expected 2 arguments +LL | | }); + | |_____- supplied 1 argument error: aborting due to previous error diff --git a/src/test/ui/issues/issue-4935.rs b/src/test/ui/issues/issue-4935.rs index 3b258c35682..b342bbb1b8e 100644 --- a/src/test/ui/issues/issue-4935.rs +++ b/src/test/ui/issues/issue-4935.rs @@ -3,4 +3,4 @@ fn foo(a: usize) {} //~^ defined here fn main() { foo(5, 6) } -//~^ ERROR this function takes 1 parameter but 2 parameters were supplied +//~^ ERROR this function takes 1 argument but 2 arguments were supplied diff --git a/src/test/ui/issues/issue-4935.stderr b/src/test/ui/issues/issue-4935.stderr index a99581fdca1..0cc686e1cf8 100644 --- a/src/test/ui/issues/issue-4935.stderr +++ b/src/test/ui/issues/issue-4935.stderr @@ -1,11 +1,13 @@ -error[E0061]: this function takes 1 parameter but 2 parameters were supplied +error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/issue-4935.rs:5:13 | LL | fn foo(a: usize) {} | ---------------- defined here LL | LL | fn main() { foo(5, 6) } - | ^^^^^^^^^ expected 1 parameter + | ^^^ - - supplied 2 arguments + | | + | expected 1 argument error: aborting due to previous error diff --git a/src/test/ui/methods/method-call-err-msg.rs b/src/test/ui/methods/method-call-err-msg.rs index 5ff4b412667..9bfacc7babf 100644 --- a/src/test/ui/methods/method-call-err-msg.rs +++ b/src/test/ui/methods/method-call-err-msg.rs @@ -5,16 +5,18 @@ impl Foo { fn zero(self) -> Foo { self } fn one(self, _: isize) -> Foo { self } fn two(self, _: isize, _: isize) -> Foo { self } + fn three(self, _: T, _: T, _: T) -> Foo { self } } fn main() { let x = Foo; - x.zero(0) //~ ERROR this function takes 0 parameters but 1 parameter was supplied - .one() //~ ERROR this function takes 1 parameter but 0 parameters were supplied - .two(0); //~ ERROR this function takes 2 parameters but 1 parameter was supplied + x.zero(0) //~ ERROR this function takes 0 arguments but 1 argument was supplied + .one() //~ ERROR this function takes 1 argument but 0 arguments were supplied + .two(0); //~ ERROR this function takes 2 arguments but 1 argument was supplied let y = Foo; y.zero() .take() //~ ERROR no method named `take` found .one(0); + y.three::(); //~ ERROR this function takes 3 arguments but 0 arguments were supplied } diff --git a/src/test/ui/methods/method-call-err-msg.stderr b/src/test/ui/methods/method-call-err-msg.stderr index 7efdd91708a..ab1ef5b9d5a 100644 --- a/src/test/ui/methods/method-call-err-msg.stderr +++ b/src/test/ui/methods/method-call-err-msg.stderr @@ -1,32 +1,38 @@ -error[E0061]: this function takes 0 parameters but 1 parameter was supplied - --> $DIR/method-call-err-msg.rs:12:7 +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/method-call-err-msg.rs:13:7 | LL | fn zero(self) -> Foo { self } | -------------------- defined here ... LL | x.zero(0) - | ^^^^ expected 0 parameters + | ^^^^ - supplied 1 argument + | | + | expected 0 arguments -error[E0061]: this function takes 1 parameter but 0 parameters were supplied - --> $DIR/method-call-err-msg.rs:13:7 +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/method-call-err-msg.rs:14:7 | LL | fn one(self, _: isize) -> Foo { self } | ----------------------------- defined here ... LL | .one() - | ^^^ expected 1 parameter + | ^^^- supplied 0 arguments + | | + | expected 1 argument -error[E0061]: this function takes 2 parameters but 1 parameter was supplied - --> $DIR/method-call-err-msg.rs:14:7 +error[E0061]: this function takes 2 arguments but 1 argument was supplied + --> $DIR/method-call-err-msg.rs:15:7 | LL | fn two(self, _: isize, _: isize) -> Foo { self } | --------------------------------------- defined here ... LL | .two(0); - | ^^^ expected 2 parameters + | ^^^ - supplied 1 argument + | | + | expected 2 arguments error[E0599]: no method named `take` found for struct `Foo` in the current scope - --> $DIR/method-call-err-msg.rs:18:7 + --> $DIR/method-call-err-msg.rs:19:7 | LL | pub struct Foo; | --------------- method `take` not found for this @@ -41,7 +47,18 @@ LL | .take() candidate #1: `std::io::Read` candidate #2: `std::iter::Iterator` -error: aborting due to 4 previous errors +error[E0061]: this function takes 3 arguments but 0 arguments were supplied + --> $DIR/method-call-err-msg.rs:21:7 + | +LL | fn three(self, _: T, _: T, _: T) -> Foo { self } + | ------------------------------------------ defined here +... +LL | y.three::(); + | ^^^^^--------- supplied 0 arguments + | | + | expected 3 arguments + +error: aborting due to 5 previous errors Some errors have detailed explanations: E0061, E0599. For more information about an error, try `rustc --explain E0061`. diff --git a/src/test/ui/mismatched_types/overloaded-calls-bad.rs b/src/test/ui/mismatched_types/overloaded-calls-bad.rs index 73e74a97f06..902a6ec81d6 100644 --- a/src/test/ui/mismatched_types/overloaded-calls-bad.rs +++ b/src/test/ui/mismatched_types/overloaded-calls-bad.rs @@ -27,7 +27,7 @@ fn main() { }; let ans = s("what"); //~ ERROR mismatched types let ans = s(); - //~^ ERROR this function takes 1 parameter but 0 parameters were supplied + //~^ ERROR this function takes 1 argument but 0 arguments were supplied let ans = s("burma", "shave"); - //~^ ERROR this function takes 1 parameter but 2 parameters were supplied + //~^ ERROR this function takes 1 argument but 2 arguments were supplied } diff --git a/src/test/ui/mismatched_types/overloaded-calls-bad.stderr b/src/test/ui/mismatched_types/overloaded-calls-bad.stderr index 5a5dd056261..706e25529bf 100644 --- a/src/test/ui/mismatched_types/overloaded-calls-bad.stderr +++ b/src/test/ui/mismatched_types/overloaded-calls-bad.stderr @@ -4,17 +4,21 @@ error[E0308]: mismatched types LL | let ans = s("what"); | ^^^^^^ expected `isize`, found `&str` -error[E0057]: this function takes 1 parameter but 0 parameters were supplied +error[E0057]: this function takes 1 argument but 0 arguments were supplied --> $DIR/overloaded-calls-bad.rs:29:15 | LL | let ans = s(); - | ^^^ expected 1 parameter + | ^-- supplied 0 arguments + | | + | expected 1 argument -error[E0057]: this function takes 1 parameter but 2 parameters were supplied +error[E0057]: this function takes 1 argument but 2 arguments were supplied --> $DIR/overloaded-calls-bad.rs:31:15 | LL | let ans = s("burma", "shave"); - | ^^^^^^^^^^^^^^^^^^^ expected 1 parameter + | ^ ------- ------- supplied 2 arguments + | | + | expected 1 argument error: aborting due to 3 previous errors diff --git a/src/test/ui/not-enough-arguments.rs b/src/test/ui/not-enough-arguments.rs index 309283ed7f4..631bb1dd274 100644 --- a/src/test/ui/not-enough-arguments.rs +++ b/src/test/ui/not-enough-arguments.rs @@ -8,5 +8,5 @@ fn foo(a: isize, b: isize, c: isize, d:isize) { fn main() { foo(1, 2, 3); - //~^ ERROR this function takes 4 parameters but 3 + //~^ ERROR this function takes 4 arguments but 3 } diff --git a/src/test/ui/not-enough-arguments.stderr b/src/test/ui/not-enough-arguments.stderr index c1ee43ea904..f2b57f71400 100644 --- a/src/test/ui/not-enough-arguments.stderr +++ b/src/test/ui/not-enough-arguments.stderr @@ -1,11 +1,13 @@ -error[E0061]: this function takes 4 parameters but 3 parameters were supplied +error[E0061]: this function takes 4 arguments but 3 arguments were supplied --> $DIR/not-enough-arguments.rs:10:3 | LL | fn foo(a: isize, b: isize, c: isize, d:isize) { | --------------------------------------------- defined here ... LL | foo(1, 2, 3); - | ^^^^^^^^^^^^ expected 4 parameters + | ^^^ - - - supplied 3 arguments + | | + | expected 4 arguments error: aborting due to previous error diff --git a/src/test/ui/resolve/resolve-primitive-fallback.rs b/src/test/ui/resolve/resolve-primitive-fallback.rs index e5a3d689d23..992bcd7977f 100644 --- a/src/test/ui/resolve/resolve-primitive-fallback.rs +++ b/src/test/ui/resolve/resolve-primitive-fallback.rs @@ -2,7 +2,7 @@ fn main() { // Make sure primitive type fallback doesn't work in value namespace std::mem::size_of(u16); //~^ ERROR expected value, found builtin type `u16` - //~| ERROR this function takes 0 parameters but 1 parameter was supplied + //~| ERROR this function takes 0 arguments but 1 argument was supplied // Make sure primitive type fallback doesn't work with global paths let _: ::u8; diff --git a/src/test/ui/resolve/resolve-primitive-fallback.stderr b/src/test/ui/resolve/resolve-primitive-fallback.stderr index 92c2a032983..6d61d2f16ca 100644 --- a/src/test/ui/resolve/resolve-primitive-fallback.stderr +++ b/src/test/ui/resolve/resolve-primitive-fallback.stderr @@ -10,11 +10,13 @@ error[E0412]: cannot find type `u8` in the crate root LL | let _: ::u8; | ^^ not found in the crate root -error[E0061]: this function takes 0 parameters but 1 parameter was supplied +error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/resolve-primitive-fallback.rs:3:5 | LL | std::mem::size_of(u16); - | ^^^^^^^^^^^^^^^^^^^^^^ expected 0 parameters + | ^^^^^^^^^^^^^^^^^ --- supplied 1 argument + | | + | expected 0 arguments error: aborting due to 3 previous errors diff --git a/src/test/ui/span/E0057.stderr b/src/test/ui/span/E0057.stderr index 6b5890cac36..31579e28289 100644 --- a/src/test/ui/span/E0057.stderr +++ b/src/test/ui/span/E0057.stderr @@ -1,14 +1,18 @@ -error[E0057]: this function takes 1 parameter but 0 parameters were supplied +error[E0057]: this function takes 1 argument but 0 arguments were supplied --> $DIR/E0057.rs:3:13 | LL | let a = f(); - | ^^^ expected 1 parameter + | ^-- supplied 0 arguments + | | + | expected 1 argument -error[E0057]: this function takes 1 parameter but 2 parameters were supplied +error[E0057]: this function takes 1 argument but 2 arguments were supplied --> $DIR/E0057.rs:5:13 | LL | let c = f(2, 3); - | ^^^^^^^ expected 1 parameter + | ^ - - supplied 2 arguments + | | + | expected 1 argument error: aborting due to 2 previous errors diff --git a/src/test/ui/span/issue-34264.stderr b/src/test/ui/span/issue-34264.stderr index 80a237ac6aa..116f5ddd5b4 100644 --- a/src/test/ui/span/issue-34264.stderr +++ b/src/test/ui/span/issue-34264.stderr @@ -50,14 +50,16 @@ help: if this is a type, explicitly ignore the parameter name LL | fn bar(_: x, y: usize) {} | ^^^^ -error[E0061]: this function takes 2 parameters but 3 parameters were supplied +error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/issue-34264.rs:7:5 | LL | fn foo(Option, String) {} | --------------------------- defined here ... LL | foo(Some(42), 2, ""); - | ^^^^^^^^^^^^^^^^^^^^ expected 2 parameters + | ^^^ -------- - -- supplied 3 arguments + | | + | expected 2 arguments error[E0308]: mismatched types --> $DIR/issue-34264.rs:8:13 @@ -65,14 +67,16 @@ error[E0308]: mismatched types LL | bar("", ""); | ^^ expected `usize`, found `&str` -error[E0061]: this function takes 2 parameters but 3 parameters were supplied +error[E0061]: this function takes 2 arguments but 3 arguments were supplied --> $DIR/issue-34264.rs:10:5 | LL | fn bar(x, y: usize) {} | ------------------- defined here ... LL | bar(1, 2, 3); - | ^^^^^^^^^^^^ expected 2 parameters + | ^^^ - - - supplied 3 arguments + | | + | expected 2 arguments error: aborting due to 6 previous errors diff --git a/src/test/ui/span/missing-unit-argument.stderr b/src/test/ui/span/missing-unit-argument.stderr index 90a96e3f174..f6344fba3d3 100644 --- a/src/test/ui/span/missing-unit-argument.stderr +++ b/src/test/ui/span/missing-unit-argument.stderr @@ -1,68 +1,72 @@ -error[E0061]: this function takes 1 parameter but 0 parameters were supplied +error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/missing-unit-argument.rs:11:33 | LL | let _: Result<(), String> = Ok(); - | ^^^^ + | ^^-- supplied 0 arguments | help: expected the unit value `()`; create it with empty parentheses | LL | let _: Result<(), String> = Ok(()); | ^^ -error[E0061]: this function takes 2 parameters but 0 parameters were supplied +error[E0061]: this function takes 2 arguments but 0 arguments were supplied --> $DIR/missing-unit-argument.rs:12:5 | LL | fn foo(():(), ():()) {} | -------------------- defined here ... LL | foo(); - | ^^^^^ expected 2 parameters + | ^^^-- supplied 0 arguments + | | + | expected 2 arguments -error[E0061]: this function takes 2 parameters but 1 parameter was supplied +error[E0061]: this function takes 2 arguments but 1 argument was supplied --> $DIR/missing-unit-argument.rs:13:5 | LL | fn foo(():(), ():()) {} | -------------------- defined here ... LL | foo(()); - | ^^^^^^^ expected 2 parameters + | ^^^ -- supplied 1 argument + | | + | expected 2 arguments -error[E0061]: this function takes 1 parameter but 0 parameters were supplied +error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/missing-unit-argument.rs:14:5 | LL | fn bar(():()) {} | ------------- defined here ... LL | bar(); - | ^^^^^ + | ^^^-- supplied 0 arguments | help: expected the unit value `()`; create it with empty parentheses | LL | bar(()); | ^^ -error[E0061]: this function takes 1 parameter but 0 parameters were supplied +error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/missing-unit-argument.rs:15:7 | LL | fn baz(self, (): ()) { } | -------------------- defined here ... LL | S.baz(); - | ^^^ + | ^^^- supplied 0 arguments | help: expected the unit value `()`; create it with empty parentheses | LL | S.baz(()); | ^^ -error[E0061]: this function takes 1 parameter but 0 parameters were supplied +error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/missing-unit-argument.rs:16:7 | LL | fn generic(self, _: T) { } | ------------------------- defined here ... LL | S.generic::<()>(); - | ^^^^^^^ + | ^^^^^^^------ supplied 0 arguments | help: expected the unit value `()`; create it with empty parentheses | diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.rs b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.rs index fa3e1a35fc2..d012687533b 100644 --- a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.rs +++ b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.rs @@ -18,6 +18,6 @@ impl E2 { } fn main() { - ::V(); //~ ERROR this function takes 1 parameter but 0 parameters were supplied + ::V(); //~ ERROR this function takes 1 argument but 0 arguments were supplied let _: u8 = ::V; //~ ERROR mismatched types } diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr index 95c3a08c04a..46e7dd0c517 100644 --- a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr +++ b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr @@ -1,11 +1,13 @@ -error[E0061]: this function takes 1 parameter but 0 parameters were supplied +error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/enum-variant-priority-higher-than-other-inherent.rs:21:5 | LL | V(u8) | ----- defined here ... LL | ::V(); - | ^^^^^^^^ expected 1 parameter + | ^^^^^^-- supplied 0 arguments + | | + | expected 1 argument error[E0308]: mismatched types --> $DIR/enum-variant-priority-higher-than-other-inherent.rs:22:17 diff --git a/src/test/ui/type/type-ascription-instead-of-initializer.rs b/src/test/ui/type/type-ascription-instead-of-initializer.rs index aef25250b15..9f9b6f06bbc 100644 --- a/src/test/ui/type/type-ascription-instead-of-initializer.rs +++ b/src/test/ui/type/type-ascription-instead-of-initializer.rs @@ -1,4 +1,4 @@ fn main() { let x: Vec::with_capacity(10, 20); //~ ERROR expected type, found `10` - //~^ ERROR this function takes 1 parameter + //~^ ERROR this function takes 1 argument } diff --git a/src/test/ui/type/type-ascription-instead-of-initializer.stderr b/src/test/ui/type/type-ascription-instead-of-initializer.stderr index 3fe676de59d..530f77e5ae9 100644 --- a/src/test/ui/type/type-ascription-instead-of-initializer.stderr +++ b/src/test/ui/type/type-ascription-instead-of-initializer.stderr @@ -7,11 +7,13 @@ LL | let x: Vec::with_capacity(10, 20); | |help: use `=` if you meant to assign | while parsing the type for `x` -error[E0061]: this function takes 1 parameter but 2 parameters were supplied +error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/type-ascription-instead-of-initializer.rs:2:12 | LL | let x: Vec::with_capacity(10, 20); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 parameter + | ^^^^^^^^^^^^^^^^^^ -- -- supplied 2 arguments + | | + | expected 1 argument error: aborting due to 2 previous errors From ad4b3f3e175a1b5d9e532ed35a917cd47196e75b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 14 Feb 2020 22:49:01 +0100 Subject: [PATCH 02/21] const-prop: use one helper method for all lints; consistently lint overflow on BinOps and not on Assert --- src/librustc_mir/transform/const_prop.rs | 167 +++++++++++------------ src/librustc_session/lint/builtin.rs | 14 ++ 2 files changed, 94 insertions(+), 87 deletions(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 5729cda64f7..53acf1490bf 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -4,7 +4,8 @@ use std::borrow::Cow; use std::cell::Cell; -use rustc::mir::interpret::{InterpError, InterpResult, Scalar}; +use rustc::lint; +use rustc::mir::interpret::{InterpResult, Scalar}; use rustc::mir::visit::{ MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor, }; @@ -292,7 +293,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine { struct ConstPropagator<'mir, 'tcx> { ecx: InterpCx<'mir, 'tcx, ConstPropMachine>, tcx: TyCtxt<'tcx>, - source: MirSource<'tcx>, can_const_prop: IndexVec, param_env: ParamEnv<'tcx>, // FIXME(eddyb) avoid cloning these two fields more than once, @@ -372,7 +372,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ConstPropagator { ecx, tcx, - source, param_env, can_const_prop, // FIXME(eddyb) avoid cloning these two fields more than once, @@ -501,19 +500,20 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } } - fn report_panic_as_lint(&self, source_info: SourceInfo, panic: AssertKind) -> Option<()> { - // Somewhat convoluted way to re-use the CTFE error reporting code. + fn report_assert_as_lint( + &self, + lint: &'static lint::Lint, + source_info: SourceInfo, + message: &str, + panic: AssertKind, + ) -> Option<()> { let lint_root = self.lint_root(source_info)?; - let error = InterpError::MachineStop(Box::new(format!("{:?}", panic))); - let mut diagnostic = error_to_const_error(&self.ecx, error.into()); - diagnostic.span = source_info.span; // fix the span - diagnostic.report_as_lint( - self.tcx.at(source_info.span), - "this expression will panic at runtime", - lint_root, - None, - ); - None + self.tcx.struct_span_lint_hir(lint, lint_root, source_info.span, |lint| { + let mut err = lint.build(message); + err.span_label(source_info.span, format!("{:?}", panic)); + err.emit() + }); + return None; } fn check_unary_op( @@ -530,7 +530,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // `AssertKind` only has an `OverflowNeg` variant, so make sure that is // appropriate to use. assert_eq!(op, UnOp::Neg, "Neg is the only UnOp that can overflow"); - self.report_panic_as_lint(source_info, AssertKind::OverflowNeg)?; + self.report_assert_as_lint( + lint::builtin::OVERFLOW, + source_info, + "this arithmetic operation will overflow", + AssertKind::OverflowNeg, + )?; } Some(()) @@ -552,17 +557,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let right_size = r.layout.size; let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size)); if r_bits.map_or(false, |b| b >= left_bits as u128) { - let lint_root = self.lint_root(source_info)?; - self.tcx.struct_span_lint_hir( - ::rustc::lint::builtin::EXCEEDING_BITSHIFTS, - lint_root, - source_info.span, - |lint| { - let dir = if op == BinOp::Shr { "right" } else { "left" }; - lint.build(&format!("attempt to shift {} with overflow", dir)).emit() - }, - ); - return None; + self.report_assert_as_lint( + lint::builtin::EXCEEDING_BITSHIFTS, + source_info, + "this arithmetic operation will overflow", + AssertKind::Overflow(op), + )?; } } @@ -572,7 +572,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let (_res, overflow, _ty) = this.ecx.overflowing_binary_op(op, l, r)?; Ok(overflow) })? { - self.report_panic_as_lint(source_info, AssertKind::Overflow(op))?; + self.report_assert_as_lint( + lint::builtin::OVERFLOW, + source_info, + "this arithmetic operation will overflow", + AssertKind::Overflow(op), + )?; } Some(()) @@ -595,8 +600,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { return None; } - let overflow_check = self.tcx.sess.overflow_checks(); - // Perform any special handling for specific Rvalue types. // Generally, checks here fall into one of two categories: // 1. Additional checking to provide useful lints to the user @@ -606,21 +609,26 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // - In this case, we'll return `None` from this function to stop evaluation. match rvalue { // Additional checking: give lints to the user if an overflow would occur. - // If `overflow_check` is set, running const-prop on the `Assert` terminators - // will already generate the appropriate messages. - Rvalue::UnaryOp(op, arg) if !overflow_check => { + // We do this here and not in the `Assert` terminator as that terminator is + // only sometimes emitted (overflow checks can be disabled), but we want to always + // lint. + Rvalue::UnaryOp(op, arg) => { trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg); self.check_unary_op(*op, arg, source_info)?; } - - // Additional checking: check for overflows on integer binary operations and report - // them to the user as lints. - // If `overflow_check` is set, running const-prop on the `Assert` terminators - // will already generate the appropriate messages. - Rvalue::BinaryOp(op, left, right) if !overflow_check => { + Rvalue::BinaryOp(op, left, right) => { trace!("checking BinaryOp(op = {:?}, left = {:?}, right = {:?})", op, left, right); self.check_binary_op(*op, left, right, source_info, place_layout)?; } + Rvalue::CheckedBinaryOp(op, left, right) => { + trace!( + "checking CheckedBinaryOp(op = {:?}, left = {:?}, right = {:?})", + op, + left, + right + ); + self.check_binary_op(*op, left, right, source_info, place_layout)?; + } // Do not try creating references (#67862) Rvalue::Ref(_, _, place_ref) => { @@ -898,54 +906,39 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { } Operand::Constant(_) => {} } - let span = terminator.source_info.span; - let hir_id = self - .tcx - .hir() - .as_local_hir_id(self.source.def_id()) - .expect("some part of a failing const eval must be local"); - self.tcx.struct_span_lint_hir( - ::rustc::lint::builtin::CONST_ERR, - hir_id, - span, - |lint| { - let msg = match msg { - AssertKind::Overflow(_) - | AssertKind::OverflowNeg - | AssertKind::DivisionByZero - | AssertKind::RemainderByZero => msg.description().to_owned(), - AssertKind::BoundsCheck { ref len, ref index } => { - let len = self - .eval_operand(len, source_info) - .expect("len must be const"); - let len = match self.ecx.read_scalar(len) { - Ok(ScalarMaybeUndef::Scalar(Scalar::Raw { - data, - .. - })) => data, - other => bug!("const len not primitive: {:?}", other), - }; - let index = self - .eval_operand(index, source_info) - .expect("index must be const"); - let index = match self.ecx.read_scalar(index) { - Ok(ScalarMaybeUndef::Scalar(Scalar::Raw { - data, - .. - })) => data, - other => bug!("const index not primitive: {:?}", other), - }; - format!( - "index out of bounds: \ - the len is {} but the index is {}", - len, index, - ) - } - // Need proper const propagator for these - _ => return, - }; - lint.build(&msg).emit() - }, + let msg = match msg { + AssertKind::DivisionByZero => AssertKind::DivisionByZero, + AssertKind::RemainderByZero => AssertKind::RemainderByZero, + AssertKind::BoundsCheck { ref len, ref index } => { + let len = + self.eval_operand(len, source_info).expect("len must be const"); + let len = self + .ecx + .read_scalar(len) + .unwrap() + .to_machine_usize(&self.tcx) + .unwrap(); + let index = self + .eval_operand(index, source_info) + .expect("index must be const"); + let index = self + .ecx + .read_scalar(index) + .unwrap() + .to_machine_usize(&self.tcx) + .unwrap(); + AssertKind::BoundsCheck { len, index } + } + // Overflow is are already covered by checks on the binary operators. + AssertKind::Overflow(_) | AssertKind::OverflowNeg => return, + // Need proper const propagator for these. + _ => return, + }; + self.report_assert_as_lint( + lint::builtin::PANIC, + source_info, + "this operation will panic at runtime", + msg, ); } else { if self.should_const_prop(value) { diff --git a/src/librustc_session/lint/builtin.rs b/src/librustc_session/lint/builtin.rs index 5a360b40d61..992f8ab2617 100644 --- a/src/librustc_session/lint/builtin.rs +++ b/src/librustc_session/lint/builtin.rs @@ -46,6 +46,18 @@ declare_lint! { "shift exceeds the type's number of bits" } +declare_lint! { + pub OVERFLOW, + Deny, + "arithmetic operation overflows" +} + +declare_lint! { + pub PANIC, + Deny, + "operation will cause a panic at runtime" +} + declare_lint! { pub CONST_ERR, Deny, @@ -496,6 +508,8 @@ declare_lint_pass! { HardwiredLints => [ ILLEGAL_FLOATING_POINT_LITERAL_PATTERN, EXCEEDING_BITSHIFTS, + OVERFLOW, + PANIC, UNUSED_IMPORTS, UNUSED_EXTERN_CRATES, UNUSED_QUALIFICATIONS, From bd485223149e35c1c4e6b3ecf58653e38de4b6c9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 10:47:27 +0100 Subject: [PATCH 03/21] fix tests, and use variants to test debug and release builds together --- src/test/ui/consts/array-literal-index-oob.rs | 4 +- .../ui/consts/array-literal-index-oob.stderr | 16 +- ...st-err2.stderr => const-err2.debug.stderr} | 38 ++- src/test/ui/consts/const-err2.opt.stderr | 48 ++++ ...const-err2.opt_with_overflow_checks.stderr | 48 ++++ src/test/ui/consts/const-err2.rs | 23 +- src/test/ui/consts/const-err3.rs | 38 --- src/test/ui/consts/const-err3.stderr | 50 ---- .../index_out_of_bounds_propagated.rs | 2 +- .../index_out_of_bounds_propagated.stderr | 6 +- .../const-eval/promoted_errors.debug.stderr | 78 ++++++ .../const-eval/promoted_errors.opt.stderr | 72 ++++++ ...ted_errors.opt_with_overflow_checks.stderr | 78 ++++++ .../ui/consts/const-eval/promoted_errors.rs | 23 +- .../consts/const-eval/promoted_errors.stderr | 60 ----- .../ui/consts/const-eval/promoted_errors2.rs | 24 -- .../consts/const-eval/promoted_errors2.stderr | 66 ------ src/test/ui/consts/const-prop-ice.rs | 2 +- src/test/ui/consts/const-prop-ice.stderr | 6 +- src/test/ui/consts/const-prop-ice2.rs | 2 +- src/test/ui/consts/const-prop-ice2.stderr | 6 +- .../ui/issues/issue-8460-const.debug.stderr | 150 ++++++++++++ .../ui/issues/issue-8460-const.opt.stderr | 150 ++++++++++++ ...8460-const.opt_with_overflow_checks.stderr | 150 ++++++++++++ src/test/ui/issues/issue-8460-const.rs | 66 +++--- src/test/ui/issues/issue-8460-const.stderr | 224 ------------------ src/test/ui/issues/issue-8460-const2.rs | 58 ----- src/test/ui/issues/issue-8460-const2.stderr | 152 ------------ 28 files changed, 872 insertions(+), 768 deletions(-) rename src/test/ui/consts/{const-err2.stderr => const-err2.debug.stderr} (51%) create mode 100644 src/test/ui/consts/const-err2.opt.stderr create mode 100644 src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr delete mode 100644 src/test/ui/consts/const-err3.rs delete mode 100644 src/test/ui/consts/const-err3.stderr create mode 100644 src/test/ui/consts/const-eval/promoted_errors.debug.stderr create mode 100644 src/test/ui/consts/const-eval/promoted_errors.opt.stderr create mode 100644 src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr delete mode 100644 src/test/ui/consts/const-eval/promoted_errors.stderr delete mode 100644 src/test/ui/consts/const-eval/promoted_errors2.rs delete mode 100644 src/test/ui/consts/const-eval/promoted_errors2.stderr create mode 100644 src/test/ui/issues/issue-8460-const.debug.stderr create mode 100644 src/test/ui/issues/issue-8460-const.opt.stderr create mode 100644 src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr delete mode 100644 src/test/ui/issues/issue-8460-const.stderr delete mode 100644 src/test/ui/issues/issue-8460-const2.rs delete mode 100644 src/test/ui/issues/issue-8460-const2.stderr diff --git a/src/test/ui/consts/array-literal-index-oob.rs b/src/test/ui/consts/array-literal-index-oob.rs index af63d1f75a7..978f2333101 100644 --- a/src/test/ui/consts/array-literal-index-oob.rs +++ b/src/test/ui/consts/array-literal-index-oob.rs @@ -1,11 +1,11 @@ // build-pass // ignore-pass (emit codegen-time warnings and verify that they are indeed warnings and not errors) -#![warn(const_err)] +#![warn(const_err, panic)] fn main() { &{ [1, 2, 3][4] }; - //~^ WARN index out of bounds + //~^ WARN operation will panic //~| WARN reaching this expression at runtime will panic or abort //~| WARN erroneous constant used [const_err] } diff --git a/src/test/ui/consts/array-literal-index-oob.stderr b/src/test/ui/consts/array-literal-index-oob.stderr index 59e11697015..605cd73db1f 100644 --- a/src/test/ui/consts/array-literal-index-oob.stderr +++ b/src/test/ui/consts/array-literal-index-oob.stderr @@ -1,14 +1,14 @@ -warning: index out of bounds: the len is 3 but the index is 4 +warning: this operation will panic at runtime --> $DIR/array-literal-index-oob.rs:7:8 | LL | &{ [1, 2, 3][4] }; - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ index out of bounds: the len is 3 but the index is 4 | note: the lint level is defined here - --> $DIR/array-literal-index-oob.rs:4:9 + --> $DIR/array-literal-index-oob.rs:4:20 | -LL | #![warn(const_err)] - | ^^^^^^^^^ +LL | #![warn(const_err, panic)] + | ^^^^^ warning: reaching this expression at runtime will panic or abort --> $DIR/array-literal-index-oob.rs:7:8 @@ -17,6 +17,12 @@ LL | &{ [1, 2, 3][4] }; | ---^^^^^^^^^^^^-- | | | indexing out of bounds: the len is 3 but the index is 4 + | +note: the lint level is defined here + --> $DIR/array-literal-index-oob.rs:4:9 + | +LL | #![warn(const_err, panic)] + | ^^^^^^^^^ warning: erroneous constant used --> $DIR/array-literal-index-oob.rs:7:5 diff --git a/src/test/ui/consts/const-err2.stderr b/src/test/ui/consts/const-err2.debug.stderr similarity index 51% rename from src/test/ui/consts/const-err2.stderr rename to src/test/ui/consts/const-err2.debug.stderr index f135bf0b06c..226874c29da 100644 --- a/src/test/ui/consts/const-err2.stderr +++ b/src/test/ui/consts/const-err2.debug.stderr @@ -1,50 +1,48 @@ -error: this expression will panic at runtime - --> $DIR/const-err2.rs:18:13 +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:19:13 | LL | let a = -std::i8::MIN; | ^^^^^^^^^^^^^ attempt to negate with overflow | -note: the lint level is defined here - --> $DIR/const-err2.rs:11:9 - | -LL | #![deny(const_err)] - | ^^^^^^^^^ + = note: `#[deny(overflow)]` on by default -error: this expression will panic at runtime - --> $DIR/const-err2.rs:20:18 +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:21:18 | LL | let a_i128 = -std::i128::MIN; | ^^^^^^^^^^^^^^^ attempt to negate with overflow -error: this expression will panic at runtime - --> $DIR/const-err2.rs:22:13 +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:23:13 | LL | let b = 200u8 + 200u8 + 200u8; | ^^^^^^^^^^^^^ attempt to add with overflow -error: this expression will panic at runtime - --> $DIR/const-err2.rs:24:18 +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:25:18 | LL | let b_i128 = std::i128::MIN - std::i128::MAX; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow -error: this expression will panic at runtime - --> $DIR/const-err2.rs:26:13 +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:27:13 | LL | let c = 200u8 * 4; | ^^^^^^^^^ attempt to multiply with overflow -error: this expression will panic at runtime - --> $DIR/const-err2.rs:28:13 +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:29:13 | LL | let d = 42u8 - (42u8 + 1); | ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow -error: index out of bounds: the len is 1 but the index is 1 - --> $DIR/const-err2.rs:30:14 +error: this operation will panic at runtime + --> $DIR/const-err2.rs:31:14 | LL | let _e = [5u8][1]; - | ^^^^^^^^ + | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 + | + = note: `#[deny(panic)]` on by default error: aborting due to 7 previous errors diff --git a/src/test/ui/consts/const-err2.opt.stderr b/src/test/ui/consts/const-err2.opt.stderr new file mode 100644 index 00000000000..226874c29da --- /dev/null +++ b/src/test/ui/consts/const-err2.opt.stderr @@ -0,0 +1,48 @@ +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:19:13 + | +LL | let a = -std::i8::MIN; + | ^^^^^^^^^^^^^ attempt to negate with overflow + | + = note: `#[deny(overflow)]` on by default + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:21:18 + | +LL | let a_i128 = -std::i128::MIN; + | ^^^^^^^^^^^^^^^ attempt to negate with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:23:13 + | +LL | let b = 200u8 + 200u8 + 200u8; + | ^^^^^^^^^^^^^ attempt to add with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:25:18 + | +LL | let b_i128 = std::i128::MIN - std::i128::MAX; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:27:13 + | +LL | let c = 200u8 * 4; + | ^^^^^^^^^ attempt to multiply with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:29:13 + | +LL | let d = 42u8 - (42u8 + 1); + | ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + +error: this operation will panic at runtime + --> $DIR/const-err2.rs:31:14 + | +LL | let _e = [5u8][1]; + | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 + | + = note: `#[deny(panic)]` on by default + +error: aborting due to 7 previous errors + diff --git a/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr b/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr new file mode 100644 index 00000000000..226874c29da --- /dev/null +++ b/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr @@ -0,0 +1,48 @@ +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:19:13 + | +LL | let a = -std::i8::MIN; + | ^^^^^^^^^^^^^ attempt to negate with overflow + | + = note: `#[deny(overflow)]` on by default + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:21:18 + | +LL | let a_i128 = -std::i128::MIN; + | ^^^^^^^^^^^^^^^ attempt to negate with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:23:13 + | +LL | let b = 200u8 + 200u8 + 200u8; + | ^^^^^^^^^^^^^ attempt to add with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:25:18 + | +LL | let b_i128 = std::i128::MIN - std::i128::MAX; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:27:13 + | +LL | let c = 200u8 * 4; + | ^^^^^^^^^ attempt to multiply with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:29:13 + | +LL | let d = 42u8 - (42u8 + 1); + | ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + +error: this operation will panic at runtime + --> $DIR/const-err2.rs:31:14 + | +LL | let _e = [5u8][1]; + | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 + | + = note: `#[deny(panic)]` on by default + +error: aborting due to 7 previous errors + diff --git a/src/test/ui/consts/const-err2.rs b/src/test/ui/consts/const-err2.rs index 7c5aaedda35..6ef4e17df83 100644 --- a/src/test/ui/consts/const-err2.rs +++ b/src/test/ui/consts/const-err2.rs @@ -2,13 +2,14 @@ // optimized compilation and unoptimized compilation and thus would // lead to different lints being emitted +// revisions: debug opt opt_with_overflow_checks +//[debug]compile-flags: -C opt-level=0 +//[opt]compile-flags: -O +//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O + // build-fail -// compile-flags: -O #![feature(rustc_attrs)] -#![allow(exceeding_bitshifts)] - -#![deny(const_err)] fn black_box(_: T) { unimplemented!() @@ -16,19 +17,19 @@ fn black_box(_: T) { fn main() { let a = -std::i8::MIN; - //~^ ERROR const_err + //~^ ERROR arithmetic operation will overflow let a_i128 = -std::i128::MIN; - //~^ ERROR const_err + //~^ ERROR arithmetic operation will overflow let b = 200u8 + 200u8 + 200u8; - //~^ ERROR const_err + //~^ ERROR arithmetic operation will overflow let b_i128 = std::i128::MIN - std::i128::MAX; - //~^ ERROR const_err + //~^ ERROR arithmetic operation will overflow let c = 200u8 * 4; - //~^ ERROR const_err + //~^ ERROR arithmetic operation will overflow let d = 42u8 - (42u8 + 1); - //~^ ERROR const_err + //~^ ERROR arithmetic operation will overflow let _e = [5u8][1]; - //~^ ERROR const_err + //~^ ERROR operation will panic black_box(a); black_box(a_i128); black_box(b); diff --git a/src/test/ui/consts/const-err3.rs b/src/test/ui/consts/const-err3.rs deleted file mode 100644 index 43aba4a8b01..00000000000 --- a/src/test/ui/consts/const-err3.rs +++ /dev/null @@ -1,38 +0,0 @@ -// needed because negating int::MIN will behave differently between -// optimized compilation and unoptimized compilation and thus would -// lead to different lints being emitted - -// build-fail -// compile-flags: -C overflow-checks=on -O - -#![feature(rustc_attrs)] -#![allow(exceeding_bitshifts)] - -#![deny(const_err)] - -fn black_box(_: T) { - unimplemented!() -} - -fn main() { - let a = -std::i8::MIN; - //~^ ERROR const_err - let a_i128 = -std::i128::MIN; - //~^ ERROR const_err - let b = 200u8 + 200u8 + 200u8; - //~^ ERROR const_err - let b_i128 = std::i128::MIN - std::i128::MAX; - //~^ ERROR const_err - let c = 200u8 * 4; - //~^ ERROR const_err - let d = 42u8 - (42u8 + 1); - //~^ ERROR const_err - let _e = [5u8][1]; - //~^ ERROR const_err - black_box(a); - black_box(a_i128); - black_box(b); - black_box(b_i128); - black_box(c); - black_box(d); -} diff --git a/src/test/ui/consts/const-err3.stderr b/src/test/ui/consts/const-err3.stderr deleted file mode 100644 index 05f64b87fcc..00000000000 --- a/src/test/ui/consts/const-err3.stderr +++ /dev/null @@ -1,50 +0,0 @@ -error: attempt to negate with overflow - --> $DIR/const-err3.rs:18:13 - | -LL | let a = -std::i8::MIN; - | ^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/const-err3.rs:11:9 - | -LL | #![deny(const_err)] - | ^^^^^^^^^ - -error: attempt to negate with overflow - --> $DIR/const-err3.rs:20:18 - | -LL | let a_i128 = -std::i128::MIN; - | ^^^^^^^^^^^^^^^ - -error: attempt to add with overflow - --> $DIR/const-err3.rs:22:13 - | -LL | let b = 200u8 + 200u8 + 200u8; - | ^^^^^^^^^^^^^ - -error: attempt to subtract with overflow - --> $DIR/const-err3.rs:24:18 - | -LL | let b_i128 = std::i128::MIN - std::i128::MAX; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: attempt to multiply with overflow - --> $DIR/const-err3.rs:26:13 - | -LL | let c = 200u8 * 4; - | ^^^^^^^^^ - -error: attempt to subtract with overflow - --> $DIR/const-err3.rs:28:13 - | -LL | let d = 42u8 - (42u8 + 1); - | ^^^^^^^^^^^^^^^^^ - -error: index out of bounds: the len is 1 but the index is 1 - --> $DIR/const-err3.rs:30:14 - | -LL | let _e = [5u8][1]; - | ^^^^^^^^ - -error: aborting due to 7 previous errors - diff --git a/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.rs b/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.rs index 6d6bb94d4df..608e6e112a1 100644 --- a/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.rs +++ b/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.rs @@ -2,5 +2,5 @@ fn main() { let array = [std::env::args().len()]; - array[1]; //~ ERROR index out of bounds + array[1]; //~ ERROR operation will panic } diff --git a/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.stderr b/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.stderr index 9519ccd3c24..5da802d30f5 100644 --- a/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.stderr +++ b/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.stderr @@ -1,10 +1,10 @@ -error: index out of bounds: the len is 1 but the index is 1 +error: this operation will panic at runtime --> $DIR/index_out_of_bounds_propagated.rs:5:5 | LL | array[1]; - | ^^^^^^^^ + | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 | - = note: `#[deny(const_err)]` on by default + = note: `#[deny(panic)]` on by default error: aborting due to previous error diff --git a/src/test/ui/consts/const-eval/promoted_errors.debug.stderr b/src/test/ui/consts/const-eval/promoted_errors.debug.stderr new file mode 100644 index 00000000000..1ed60c1f96e --- /dev/null +++ b/src/test/ui/consts/const-eval/promoted_errors.debug.stderr @@ -0,0 +1,78 @@ +warning: this arithmetic operation will overflow + --> $DIR/promoted_errors.rs:12:20 + | +LL | println!("{}", 0u32 - 1); + | ^^^^^^^^ attempt to subtract with overflow + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:20 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^^^^ + +warning: this arithmetic operation will overflow + --> $DIR/promoted_errors.rs:14:14 + | +LL | let _x = 0u32 - 1; + | ^^^^^^^^ attempt to subtract with overflow + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ attempt to divide by zero + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:30 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^ + +warning: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ dividing by zero + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:9 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^^^^^ + +warning: erroneous constant used + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ referenced constant has errors + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:20:14 + | +LL | let _x = 1 / (1 - 1); + | ^^^^^^^^^^^ attempt to divide by zero + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + +warning: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ dividing by zero + +warning: erroneous constant used + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ referenced constant has errors + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:26:14 + | +LL | let _x = 1 / (false as u32); + | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + diff --git a/src/test/ui/consts/const-eval/promoted_errors.opt.stderr b/src/test/ui/consts/const-eval/promoted_errors.opt.stderr new file mode 100644 index 00000000000..8f21ce53715 --- /dev/null +++ b/src/test/ui/consts/const-eval/promoted_errors.opt.stderr @@ -0,0 +1,72 @@ +warning: this arithmetic operation will overflow + --> $DIR/promoted_errors.rs:14:14 + | +LL | let _x = 0u32 - 1; + | ^^^^^^^^ attempt to subtract with overflow + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:20 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^^^^ + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ attempt to divide by zero + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:30 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^ + +warning: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ dividing by zero + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:9 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^^^^^ + +warning: erroneous constant used + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ referenced constant has errors + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:20:14 + | +LL | let _x = 1 / (1 - 1); + | ^^^^^^^^^^^ attempt to divide by zero + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + +warning: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ dividing by zero + +warning: erroneous constant used + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ referenced constant has errors + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:26:14 + | +LL | let _x = 1 / (false as u32); + | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + diff --git a/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr b/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr new file mode 100644 index 00000000000..1ed60c1f96e --- /dev/null +++ b/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr @@ -0,0 +1,78 @@ +warning: this arithmetic operation will overflow + --> $DIR/promoted_errors.rs:12:20 + | +LL | println!("{}", 0u32 - 1); + | ^^^^^^^^ attempt to subtract with overflow + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:20 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^^^^ + +warning: this arithmetic operation will overflow + --> $DIR/promoted_errors.rs:14:14 + | +LL | let _x = 0u32 - 1; + | ^^^^^^^^ attempt to subtract with overflow + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ attempt to divide by zero + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:30 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^ + +warning: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ dividing by zero + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:9 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^^^^^ + +warning: erroneous constant used + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ referenced constant has errors + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:20:14 + | +LL | let _x = 1 / (1 - 1); + | ^^^^^^^^^^^ attempt to divide by zero + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + +warning: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ dividing by zero + +warning: erroneous constant used + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ referenced constant has errors + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:26:14 + | +LL | let _x = 1 / (false as u32); + | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + diff --git a/src/test/ui/consts/const-eval/promoted_errors.rs b/src/test/ui/consts/const-eval/promoted_errors.rs index 22f863fb15a..5a4c7a66bf5 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.rs +++ b/src/test/ui/consts/const-eval/promoted_errors.rs @@ -1,23 +1,28 @@ +// revisions: debug opt opt_with_overflow_checks +//[debug]compile-flags: -C opt-level=0 +//[opt]compile-flags: -O +//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O + // build-pass // ignore-pass (emit codegen-time warnings and verify that they are indeed warnings and not errors) -// compile-flags: -O -#![warn(const_err)] +#![warn(const_err, overflow, panic)] fn main() { println!("{}", 0u32 - 1); + //[opt_with_overflow_checks,debug]~^ WARN [overflow] let _x = 0u32 - 1; - //~^ WARN const_err + //~^ WARN [overflow] println!("{}", 1 / (1 - 1)); - //~^ WARN attempt to divide by zero [const_err] - //~| WARN const_err + //~^ WARN [panic] + //~| WARN panic or abort [const_err] //~| WARN erroneous constant used [const_err] let _x = 1 / (1 - 1); - //~^ WARN const_err + //~^ WARN [panic] println!("{}", 1 / (false as u32)); - //~^ WARN attempt to divide by zero [const_err] - //~| WARN const_err + //~^ WARN [panic] + //~| WARN panic or abort [const_err] //~| WARN erroneous constant used [const_err] let _x = 1 / (false as u32); - //~^ WARN const_err + //~^ WARN [panic] } diff --git a/src/test/ui/consts/const-eval/promoted_errors.stderr b/src/test/ui/consts/const-eval/promoted_errors.stderr deleted file mode 100644 index 08ae5c7a32b..00000000000 --- a/src/test/ui/consts/const-eval/promoted_errors.stderr +++ /dev/null @@ -1,60 +0,0 @@ -warning: this expression will panic at runtime - --> $DIR/promoted_errors.rs:9:14 - | -LL | let _x = 0u32 - 1; - | ^^^^^^^^ attempt to subtract with overflow - | -note: the lint level is defined here - --> $DIR/promoted_errors.rs:5:9 - | -LL | #![warn(const_err)] - | ^^^^^^^^^ - -warning: attempt to divide by zero - --> $DIR/promoted_errors.rs:11:20 - | -LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ - -warning: reaching this expression at runtime will panic or abort - --> $DIR/promoted_errors.rs:11:20 - | -LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ dividing by zero - -warning: erroneous constant used - --> $DIR/promoted_errors.rs:11:20 - | -LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ referenced constant has errors - -warning: attempt to divide by zero - --> $DIR/promoted_errors.rs:15:14 - | -LL | let _x = 1 / (1 - 1); - | ^^^^^^^^^^^ - -warning: attempt to divide by zero - --> $DIR/promoted_errors.rs:17:20 - | -LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ - -warning: reaching this expression at runtime will panic or abort - --> $DIR/promoted_errors.rs:17:20 - | -LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ dividing by zero - -warning: erroneous constant used - --> $DIR/promoted_errors.rs:17:20 - | -LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ referenced constant has errors - -warning: attempt to divide by zero - --> $DIR/promoted_errors.rs:21:14 - | -LL | let _x = 1 / (false as u32); - | ^^^^^^^^^^^^^^^^^^ - diff --git a/src/test/ui/consts/const-eval/promoted_errors2.rs b/src/test/ui/consts/const-eval/promoted_errors2.rs deleted file mode 100644 index 62c77f76d90..00000000000 --- a/src/test/ui/consts/const-eval/promoted_errors2.rs +++ /dev/null @@ -1,24 +0,0 @@ -// build-pass -// ignore-pass (emit codegen-time warnings and verify that they are indeed warnings and not errors) -// compile-flags: -C overflow-checks=on -O - -#![warn(const_err)] - -fn main() { - println!("{}", 0u32 - 1); - //~^ WARN attempt to subtract with overflow - let _x = 0u32 - 1; - //~^ WARN attempt to subtract with overflow - println!("{}", 1 / (1 - 1)); - //~^ WARN attempt to divide by zero [const_err] - //~| WARN const_err - //~| WARN erroneous constant used [const_err] - let _x = 1 / (1 - 1); - //~^ WARN const_err - println!("{}", 1 / (false as u32)); - //~^ WARN attempt to divide by zero [const_err] - //~| WARN const_err - //~| WARN erroneous constant used [const_err] - let _x = 1 / (false as u32); - //~^ WARN const_err -} diff --git a/src/test/ui/consts/const-eval/promoted_errors2.stderr b/src/test/ui/consts/const-eval/promoted_errors2.stderr deleted file mode 100644 index d1a9cb958e1..00000000000 --- a/src/test/ui/consts/const-eval/promoted_errors2.stderr +++ /dev/null @@ -1,66 +0,0 @@ -warning: attempt to subtract with overflow - --> $DIR/promoted_errors2.rs:8:20 - | -LL | println!("{}", 0u32 - 1); - | ^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/promoted_errors2.rs:5:9 - | -LL | #![warn(const_err)] - | ^^^^^^^^^ - -warning: attempt to subtract with overflow - --> $DIR/promoted_errors2.rs:10:14 - | -LL | let _x = 0u32 - 1; - | ^^^^^^^^ - -warning: attempt to divide by zero - --> $DIR/promoted_errors2.rs:12:20 - | -LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ - -warning: reaching this expression at runtime will panic or abort - --> $DIR/promoted_errors2.rs:12:20 - | -LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ dividing by zero - -warning: erroneous constant used - --> $DIR/promoted_errors2.rs:12:20 - | -LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ referenced constant has errors - -warning: attempt to divide by zero - --> $DIR/promoted_errors2.rs:16:14 - | -LL | let _x = 1 / (1 - 1); - | ^^^^^^^^^^^ - -warning: attempt to divide by zero - --> $DIR/promoted_errors2.rs:18:20 - | -LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ - -warning: reaching this expression at runtime will panic or abort - --> $DIR/promoted_errors2.rs:18:20 - | -LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ dividing by zero - -warning: erroneous constant used - --> $DIR/promoted_errors2.rs:18:20 - | -LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ referenced constant has errors - -warning: attempt to divide by zero - --> $DIR/promoted_errors2.rs:22:14 - | -LL | let _x = 1 / (false as u32); - | ^^^^^^^^^^^^^^^^^^ - diff --git a/src/test/ui/consts/const-prop-ice.rs b/src/test/ui/consts/const-prop-ice.rs index 8682d2ee901..5bffe020629 100644 --- a/src/test/ui/consts/const-prop-ice.rs +++ b/src/test/ui/consts/const-prop-ice.rs @@ -1,5 +1,5 @@ // build-fail fn main() { - [0; 3][3u64 as usize]; //~ ERROR the len is 3 but the index is 3 + [0; 3][3u64 as usize]; //~ ERROR this operation will panic at runtime } diff --git a/src/test/ui/consts/const-prop-ice.stderr b/src/test/ui/consts/const-prop-ice.stderr index 65502a4ff71..855b9e6b64b 100644 --- a/src/test/ui/consts/const-prop-ice.stderr +++ b/src/test/ui/consts/const-prop-ice.stderr @@ -1,10 +1,10 @@ -error: index out of bounds: the len is 3 but the index is 3 +error: this operation will panic at runtime --> $DIR/const-prop-ice.rs:4:5 | LL | [0; 3][3u64 as usize]; - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the len is 3 but the index is 3 | - = note: `#[deny(const_err)]` on by default + = note: `#[deny(panic)]` on by default error: aborting due to previous error diff --git a/src/test/ui/consts/const-prop-ice2.rs b/src/test/ui/consts/const-prop-ice2.rs index 6a73483026f..d533e394c06 100644 --- a/src/test/ui/consts/const-prop-ice2.rs +++ b/src/test/ui/consts/const-prop-ice2.rs @@ -3,5 +3,5 @@ fn main() { enum Enum { One=1 } let xs=[0;1 as usize]; - println!("{}", xs[Enum::One as usize]); //~ ERROR the len is 1 but the index is 1 + println!("{}", xs[Enum::One as usize]); //~ ERROR this operation will panic at runtime } diff --git a/src/test/ui/consts/const-prop-ice2.stderr b/src/test/ui/consts/const-prop-ice2.stderr index cbb8fde80f9..07faa39edc2 100644 --- a/src/test/ui/consts/const-prop-ice2.stderr +++ b/src/test/ui/consts/const-prop-ice2.stderr @@ -1,10 +1,10 @@ -error: index out of bounds: the len is 1 but the index is 1 +error: this operation will panic at runtime --> $DIR/const-prop-ice2.rs:6:20 | LL | println!("{}", xs[Enum::One as usize]); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the len is 1 but the index is 1 | - = note: `#[deny(const_err)]` on by default + = note: `#[deny(panic)]` on by default error: aborting due to previous error diff --git a/src/test/ui/issues/issue-8460-const.debug.stderr b/src/test/ui/issues/issue-8460-const.debug.stderr new file mode 100644 index 00000000000..33d846e3e91 --- /dev/null +++ b/src/test/ui/issues/issue-8460-const.debug.stderr @@ -0,0 +1,150 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:14:36 + | +LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^^ attempt to divide with overflow + | + = note: `#[deny(overflow)]` on by default + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:16:36 + | +LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:18:36 + | +LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:20:36 + | +LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:22:36 + | +LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:24:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ attempt to divide with overflow + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:26:36 + | +LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); + | ^^^^^^^^^^ attempt to divide by zero + | + = note: `#[deny(panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:28:36 + | +LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); + | ^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:30:36 + | +LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:32:36 + | +LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:34:36 + | +LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:36:36 + | +LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); + | ^^^^^^^^^ attempt to divide by zero + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:38:36 + | +LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:40:36 + | +LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:42:36 + | +LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:44:36 + | +LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:46:36 + | +LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:48:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:50:36 + | +LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); + | ^^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:52:36 + | +LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); + | ^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:54:36 + | +LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:56:36 + | +LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:58:36 + | +LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:60:36 + | +LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); + | ^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: aborting due to 24 previous errors + diff --git a/src/test/ui/issues/issue-8460-const.opt.stderr b/src/test/ui/issues/issue-8460-const.opt.stderr new file mode 100644 index 00000000000..33d846e3e91 --- /dev/null +++ b/src/test/ui/issues/issue-8460-const.opt.stderr @@ -0,0 +1,150 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:14:36 + | +LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^^ attempt to divide with overflow + | + = note: `#[deny(overflow)]` on by default + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:16:36 + | +LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:18:36 + | +LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:20:36 + | +LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:22:36 + | +LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:24:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ attempt to divide with overflow + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:26:36 + | +LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); + | ^^^^^^^^^^ attempt to divide by zero + | + = note: `#[deny(panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:28:36 + | +LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); + | ^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:30:36 + | +LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:32:36 + | +LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:34:36 + | +LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:36:36 + | +LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); + | ^^^^^^^^^ attempt to divide by zero + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:38:36 + | +LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:40:36 + | +LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:42:36 + | +LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:44:36 + | +LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:46:36 + | +LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:48:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:50:36 + | +LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); + | ^^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:52:36 + | +LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); + | ^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:54:36 + | +LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:56:36 + | +LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:58:36 + | +LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:60:36 + | +LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); + | ^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: aborting due to 24 previous errors + diff --git a/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr b/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr new file mode 100644 index 00000000000..33d846e3e91 --- /dev/null +++ b/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr @@ -0,0 +1,150 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:14:36 + | +LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^^ attempt to divide with overflow + | + = note: `#[deny(overflow)]` on by default + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:16:36 + | +LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:18:36 + | +LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:20:36 + | +LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:22:36 + | +LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:24:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ attempt to divide with overflow + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:26:36 + | +LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); + | ^^^^^^^^^^ attempt to divide by zero + | + = note: `#[deny(panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:28:36 + | +LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); + | ^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:30:36 + | +LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:32:36 + | +LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:34:36 + | +LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:36:36 + | +LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); + | ^^^^^^^^^ attempt to divide by zero + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:38:36 + | +LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:40:36 + | +LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:42:36 + | +LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:44:36 + | +LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:46:36 + | +LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:48:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:50:36 + | +LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); + | ^^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:52:36 + | +LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); + | ^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:54:36 + | +LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:56:36 + | +LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:58:36 + | +LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:60:36 + | +LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); + | ^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: aborting due to 24 previous errors + diff --git a/src/test/ui/issues/issue-8460-const.rs b/src/test/ui/issues/issue-8460-const.rs index 5866cef2d2c..3ab873952e2 100644 --- a/src/test/ui/issues/issue-8460-const.rs +++ b/src/test/ui/issues/issue-8460-const.rs @@ -1,5 +1,9 @@ +// revisions: debug opt opt_with_overflow_checks +//[debug]compile-flags: -C opt-level=0 +//[opt]compile-flags: -O +//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O + // build-fail -// compile-flags: -O #![deny(const_err)] @@ -8,63 +12,51 @@ use std::thread; fn main() { assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - //~| ERROR this expression will panic at runtime + //~^ ERROR arithmetic operation will overflow assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero + //~^ ERROR operation will panic assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero + //~^ ERROR operation will panic } diff --git a/src/test/ui/issues/issue-8460-const.stderr b/src/test/ui/issues/issue-8460-const.stderr deleted file mode 100644 index d7373948cb9..00000000000 --- a/src/test/ui/issues/issue-8460-const.stderr +++ /dev/null @@ -1,224 +0,0 @@ -error: attempt to divide with overflow - --> $DIR/issue-8460-const.rs:10:36 - | -LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/issue-8460-const.rs:4:9 - | -LL | #![deny(const_err)] - | ^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:10:36 - | -LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ attempt to divide with overflow - -error: attempt to divide with overflow - --> $DIR/issue-8460-const.rs:13:36 - | -LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:13:36 - | -LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^ attempt to divide with overflow - -error: attempt to divide with overflow - --> $DIR/issue-8460-const.rs:16:36 - | -LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:16:36 - | -LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow - -error: attempt to divide with overflow - --> $DIR/issue-8460-const.rs:19:36 - | -LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:19:36 - | -LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow - -error: attempt to divide with overflow - --> $DIR/issue-8460-const.rs:22:36 - | -LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:22:36 - | -LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow - -error: attempt to divide with overflow - --> $DIR/issue-8460-const.rs:25:36 - | -LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:25:36 - | -LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ attempt to divide with overflow - -error: attempt to divide by zero - --> $DIR/issue-8460-const.rs:28:36 - | -LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); - | ^^^^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const.rs:30:36 - | -LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); - | ^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const.rs:32:36 - | -LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const.rs:34:36 - | -LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const.rs:36:36 - | -LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const.rs:38:36 - | -LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); - | ^^^^^^^^^ - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:40:36 - | -LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:40:36 - | -LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:43:36 - | -LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:43:36 - | -LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:46:36 - | -LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:46:36 - | -LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:49:36 - | -LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:49:36 - | -LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:52:36 - | -LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:52:36 - | -LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const.rs:55:36 - | -LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ - -error: this expression will panic at runtime - --> $DIR/issue-8460-const.rs:55:36 - | -LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:58:36 - | -LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); - | ^^^^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:60:36 - | -LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); - | ^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:62:36 - | -LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:64:36 - | -LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:66:36 - | -LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const.rs:68:36 - | -LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); - | ^^^^^^^^^ - -error: aborting due to 36 previous errors - diff --git a/src/test/ui/issues/issue-8460-const2.rs b/src/test/ui/issues/issue-8460-const2.rs deleted file mode 100644 index afea859bb65..00000000000 --- a/src/test/ui/issues/issue-8460-const2.rs +++ /dev/null @@ -1,58 +0,0 @@ -// build-fail -// compile-flags: -C overflow-checks=on -O - -#![deny(const_err)] - -use std::{isize, i8, i16, i32, i64, i128}; -use std::thread; - -fn main() { - assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); - //~^ ERROR attempt to divide with overflow - assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero - assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero - assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero - assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero - assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero - assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); - //~^ ERROR attempt to divide by zero - assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with overflow - assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero - assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero - assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero - assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero - assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero - assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); - //~^ ERROR attempt to calculate the remainder with a divisor of zero -} diff --git a/src/test/ui/issues/issue-8460-const2.stderr b/src/test/ui/issues/issue-8460-const2.stderr deleted file mode 100644 index e25d560fe0c..00000000000 --- a/src/test/ui/issues/issue-8460-const2.stderr +++ /dev/null @@ -1,152 +0,0 @@ -error: attempt to divide with overflow - --> $DIR/issue-8460-const2.rs:10:36 - | -LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/issue-8460-const2.rs:4:9 - | -LL | #![deny(const_err)] - | ^^^^^^^^^ - -error: attempt to divide with overflow - --> $DIR/issue-8460-const2.rs:12:36 - | -LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^ - -error: attempt to divide with overflow - --> $DIR/issue-8460-const2.rs:14:36 - | -LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: attempt to divide with overflow - --> $DIR/issue-8460-const2.rs:16:36 - | -LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: attempt to divide with overflow - --> $DIR/issue-8460-const2.rs:18:36 - | -LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: attempt to divide with overflow - --> $DIR/issue-8460-const2.rs:20:36 - | -LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const2.rs:22:36 - | -LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); - | ^^^^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const2.rs:24:36 - | -LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); - | ^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const2.rs:26:36 - | -LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const2.rs:28:36 - | -LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const2.rs:30:36 - | -LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to divide by zero - --> $DIR/issue-8460-const2.rs:32:36 - | -LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); - | ^^^^^^^^^ - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:34:36 - | -LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:36:36 - | -LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^ - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:38:36 - | -LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:40:36 - | -LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:42:36 - | -LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ - -error: attempt to calculate the remainder with overflow - --> $DIR/issue-8460-const2.rs:44:36 - | -LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:46:36 - | -LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); - | ^^^^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:48:36 - | -LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); - | ^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:50:36 - | -LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:52:36 - | -LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:54:36 - | -LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); - | ^^^^^^^^ - -error: attempt to calculate the remainder with a divisor of zero - --> $DIR/issue-8460-const2.rs:56:36 - | -LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); - | ^^^^^^^^^ - -error: aborting due to 24 previous errors - From 9c7639492ff4b3f6b812f355d4b8fe08cc81571d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 10:51:51 +0100 Subject: [PATCH 04/21] more revisions and use them for another test --- ...debug.stderr => const-err2.default.stderr} | 0 src/test/ui/consts/const-err2.noopt.stderr | 48 ++++++ src/test/ui/consts/const-err2.rs | 4 +- .../const-eval/promoted_errors.default.stderr | 72 +++++++++ ...ug.stderr => promoted_errors.noopt.stderr} | 0 .../ui/consts/const-eval/promoted_errors.rs | 6 +- src/test/ui/consts/issue-64059-2.rs | 6 - src/test/ui/consts/issue-64059.rs | 5 + ...stderr => issue-8460-const.default.stderr} | 0 .../ui/issues/issue-8460-const.noopt.stderr | 150 ++++++++++++++++++ src/test/ui/issues/issue-8460-const.rs | 4 +- 11 files changed, 282 insertions(+), 13 deletions(-) rename src/test/ui/consts/{const-err2.debug.stderr => const-err2.default.stderr} (100%) create mode 100644 src/test/ui/consts/const-err2.noopt.stderr create mode 100644 src/test/ui/consts/const-eval/promoted_errors.default.stderr rename src/test/ui/consts/const-eval/{promoted_errors.debug.stderr => promoted_errors.noopt.stderr} (100%) delete mode 100644 src/test/ui/consts/issue-64059-2.rs rename src/test/ui/issues/{issue-8460-const.debug.stderr => issue-8460-const.default.stderr} (100%) create mode 100644 src/test/ui/issues/issue-8460-const.noopt.stderr diff --git a/src/test/ui/consts/const-err2.debug.stderr b/src/test/ui/consts/const-err2.default.stderr similarity index 100% rename from src/test/ui/consts/const-err2.debug.stderr rename to src/test/ui/consts/const-err2.default.stderr diff --git a/src/test/ui/consts/const-err2.noopt.stderr b/src/test/ui/consts/const-err2.noopt.stderr new file mode 100644 index 00000000000..226874c29da --- /dev/null +++ b/src/test/ui/consts/const-err2.noopt.stderr @@ -0,0 +1,48 @@ +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:19:13 + | +LL | let a = -std::i8::MIN; + | ^^^^^^^^^^^^^ attempt to negate with overflow + | + = note: `#[deny(overflow)]` on by default + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:21:18 + | +LL | let a_i128 = -std::i128::MIN; + | ^^^^^^^^^^^^^^^ attempt to negate with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:23:13 + | +LL | let b = 200u8 + 200u8 + 200u8; + | ^^^^^^^^^^^^^ attempt to add with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:25:18 + | +LL | let b_i128 = std::i128::MIN - std::i128::MAX; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:27:13 + | +LL | let c = 200u8 * 4; + | ^^^^^^^^^ attempt to multiply with overflow + +error: this arithmetic operation will overflow + --> $DIR/const-err2.rs:29:13 + | +LL | let d = 42u8 - (42u8 + 1); + | ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow + +error: this operation will panic at runtime + --> $DIR/const-err2.rs:31:14 + | +LL | let _e = [5u8][1]; + | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 + | + = note: `#[deny(panic)]` on by default + +error: aborting due to 7 previous errors + diff --git a/src/test/ui/consts/const-err2.rs b/src/test/ui/consts/const-err2.rs index 6ef4e17df83..2c0cae0e451 100644 --- a/src/test/ui/consts/const-err2.rs +++ b/src/test/ui/consts/const-err2.rs @@ -2,8 +2,8 @@ // optimized compilation and unoptimized compilation and thus would // lead to different lints being emitted -// revisions: debug opt opt_with_overflow_checks -//[debug]compile-flags: -C opt-level=0 +// revisions: default noopt opt opt_with_overflow_checks +//[noopt]compile-flags: -C opt-level=0 //[opt]compile-flags: -O //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O diff --git a/src/test/ui/consts/const-eval/promoted_errors.default.stderr b/src/test/ui/consts/const-eval/promoted_errors.default.stderr new file mode 100644 index 00000000000..8f21ce53715 --- /dev/null +++ b/src/test/ui/consts/const-eval/promoted_errors.default.stderr @@ -0,0 +1,72 @@ +warning: this arithmetic operation will overflow + --> $DIR/promoted_errors.rs:14:14 + | +LL | let _x = 0u32 - 1; + | ^^^^^^^^ attempt to subtract with overflow + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:20 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^^^^ + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ attempt to divide by zero + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:30 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^ + +warning: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ dividing by zero + | +note: the lint level is defined here + --> $DIR/promoted_errors.rs:9:9 + | +LL | #![warn(const_err, overflow, panic)] + | ^^^^^^^^^ + +warning: erroneous constant used + --> $DIR/promoted_errors.rs:16:20 + | +LL | println!("{}", 1 / (1 - 1)); + | ^^^^^^^^^^^ referenced constant has errors + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:20:14 + | +LL | let _x = 1 / (1 - 1); + | ^^^^^^^^^^^ attempt to divide by zero + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + +warning: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ dividing by zero + +warning: erroneous constant used + --> $DIR/promoted_errors.rs:22:20 + | +LL | println!("{}", 1 / (false as u32)); + | ^^^^^^^^^^^^^^^^^^ referenced constant has errors + +warning: this operation will panic at runtime + --> $DIR/promoted_errors.rs:26:14 + | +LL | let _x = 1 / (false as u32); + | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero + diff --git a/src/test/ui/consts/const-eval/promoted_errors.debug.stderr b/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr similarity index 100% rename from src/test/ui/consts/const-eval/promoted_errors.debug.stderr rename to src/test/ui/consts/const-eval/promoted_errors.noopt.stderr diff --git a/src/test/ui/consts/const-eval/promoted_errors.rs b/src/test/ui/consts/const-eval/promoted_errors.rs index 5a4c7a66bf5..3133e9b380b 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.rs +++ b/src/test/ui/consts/const-eval/promoted_errors.rs @@ -1,5 +1,5 @@ -// revisions: debug opt opt_with_overflow_checks -//[debug]compile-flags: -C opt-level=0 +// revisions: default noopt opt opt_with_overflow_checks +//[noopt]compile-flags: -C opt-level=0 //[opt]compile-flags: -O //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O @@ -10,7 +10,7 @@ fn main() { println!("{}", 0u32 - 1); - //[opt_with_overflow_checks,debug]~^ WARN [overflow] + //[opt_with_overflow_checks,noopt]~^ WARN [overflow] let _x = 0u32 - 1; //~^ WARN [overflow] println!("{}", 1 / (1 - 1)); diff --git a/src/test/ui/consts/issue-64059-2.rs b/src/test/ui/consts/issue-64059-2.rs deleted file mode 100644 index 38911c3dcf6..00000000000 --- a/src/test/ui/consts/issue-64059-2.rs +++ /dev/null @@ -1,6 +0,0 @@ -// compile-flags: -C overflow-checks=on -O -// run-pass - -fn main() { - let _ = -(-0.0); -} diff --git a/src/test/ui/consts/issue-64059.rs b/src/test/ui/consts/issue-64059.rs index c4c895fef66..16bfda3b961 100644 --- a/src/test/ui/consts/issue-64059.rs +++ b/src/test/ui/consts/issue-64059.rs @@ -1,3 +1,8 @@ +// revisions: default noopt opt opt_with_overflow_checks +//[noopt]compile-flags: -C opt-level=0 +//[opt]compile-flags: -O +//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O + // run-pass fn main() { diff --git a/src/test/ui/issues/issue-8460-const.debug.stderr b/src/test/ui/issues/issue-8460-const.default.stderr similarity index 100% rename from src/test/ui/issues/issue-8460-const.debug.stderr rename to src/test/ui/issues/issue-8460-const.default.stderr diff --git a/src/test/ui/issues/issue-8460-const.noopt.stderr b/src/test/ui/issues/issue-8460-const.noopt.stderr new file mode 100644 index 00000000000..33d846e3e91 --- /dev/null +++ b/src/test/ui/issues/issue-8460-const.noopt.stderr @@ -0,0 +1,150 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:14:36 + | +LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^^ attempt to divide with overflow + | + = note: `#[deny(overflow)]` on by default + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:16:36 + | +LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:18:36 + | +LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:20:36 + | +LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:22:36 + | +LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to divide with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:24:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ attempt to divide with overflow + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:26:36 + | +LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); + | ^^^^^^^^^^ attempt to divide by zero + | + = note: `#[deny(panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:28:36 + | +LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); + | ^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:30:36 + | +LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:32:36 + | +LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:34:36 + | +LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); + | ^^^^^^^^ attempt to divide by zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:36:36 + | +LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); + | ^^^^^^^^^ attempt to divide by zero + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:38:36 + | +LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:40:36 + | +LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:42:36 + | +LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:44:36 + | +LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:46:36 + | +LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this arithmetic operation will overflow + --> $DIR/issue-8460-const.rs:48:36 + | +LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); + | ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:50:36 + | +LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); + | ^^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:52:36 + | +LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); + | ^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:54:36 + | +LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:56:36 + | +LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:58:36 + | +LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); + | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: this operation will panic at runtime + --> $DIR/issue-8460-const.rs:60:36 + | +LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); + | ^^^^^^^^^ attempt to calculate the remainder with a divisor of zero + +error: aborting due to 24 previous errors + diff --git a/src/test/ui/issues/issue-8460-const.rs b/src/test/ui/issues/issue-8460-const.rs index 3ab873952e2..d7276af40a7 100644 --- a/src/test/ui/issues/issue-8460-const.rs +++ b/src/test/ui/issues/issue-8460-const.rs @@ -1,5 +1,5 @@ -// revisions: debug opt opt_with_overflow_checks -//[debug]compile-flags: -C opt-level=0 +// revisions: default noopt opt opt_with_overflow_checks +//[noopt]compile-flags: -C opt-level=0 //[opt]compile-flags: -O //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O From 4b8c78496815e22652fdf0da216659fe06936b50 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 11:00:14 +0100 Subject: [PATCH 05/21] add test for issue 69020 --- src/test/ui/consts/issue-69020.default.stderr | 10 ++++++++++ src/test/ui/consts/issue-69020.noopt.stderr | 10 ++++++++++ src/test/ui/consts/issue-69020.opt.stderr | 10 ++++++++++ .../issue-69020.opt_with_overflow_checks.stderr | 10 ++++++++++ src/test/ui/consts/issue-69020.rs | 17 +++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 src/test/ui/consts/issue-69020.default.stderr create mode 100644 src/test/ui/consts/issue-69020.noopt.stderr create mode 100644 src/test/ui/consts/issue-69020.opt.stderr create mode 100644 src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr create mode 100644 src/test/ui/consts/issue-69020.rs diff --git a/src/test/ui/consts/issue-69020.default.stderr b/src/test/ui/consts/issue-69020.default.stderr new file mode 100644 index 00000000000..0bf40ce4b31 --- /dev/null +++ b/src/test/ui/consts/issue-69020.default.stderr @@ -0,0 +1,10 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-69020.rs:15:20 + | +LL | const N: i32 = -i32::MIN + T::N; + | ^^^^^^^^^ attempt to negate with overflow + | + = note: `#[deny(overflow)]` on by default + +error: aborting due to previous error + diff --git a/src/test/ui/consts/issue-69020.noopt.stderr b/src/test/ui/consts/issue-69020.noopt.stderr new file mode 100644 index 00000000000..0bf40ce4b31 --- /dev/null +++ b/src/test/ui/consts/issue-69020.noopt.stderr @@ -0,0 +1,10 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-69020.rs:15:20 + | +LL | const N: i32 = -i32::MIN + T::N; + | ^^^^^^^^^ attempt to negate with overflow + | + = note: `#[deny(overflow)]` on by default + +error: aborting due to previous error + diff --git a/src/test/ui/consts/issue-69020.opt.stderr b/src/test/ui/consts/issue-69020.opt.stderr new file mode 100644 index 00000000000..0bf40ce4b31 --- /dev/null +++ b/src/test/ui/consts/issue-69020.opt.stderr @@ -0,0 +1,10 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-69020.rs:15:20 + | +LL | const N: i32 = -i32::MIN + T::N; + | ^^^^^^^^^ attempt to negate with overflow + | + = note: `#[deny(overflow)]` on by default + +error: aborting due to previous error + diff --git a/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr b/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr new file mode 100644 index 00000000000..0bf40ce4b31 --- /dev/null +++ b/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr @@ -0,0 +1,10 @@ +error: this arithmetic operation will overflow + --> $DIR/issue-69020.rs:15:20 + | +LL | const N: i32 = -i32::MIN + T::N; + | ^^^^^^^^^ attempt to negate with overflow + | + = note: `#[deny(overflow)]` on by default + +error: aborting due to previous error + diff --git a/src/test/ui/consts/issue-69020.rs b/src/test/ui/consts/issue-69020.rs new file mode 100644 index 00000000000..9f1ed862c7b --- /dev/null +++ b/src/test/ui/consts/issue-69020.rs @@ -0,0 +1,17 @@ +// revisions: default noopt opt opt_with_overflow_checks +//[noopt]compile-flags: -C opt-level=0 +//[opt]compile-flags: -O +//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O + +#![crate_type="lib"] + +use std::i32; + +pub trait Foo { + const N: i32; +} + +impl Foo for Vec { + const N: i32 = -i32::MIN + T::N; + //~^ ERROR arithmetic operation will overflow +} From 2107e73d2f0605e916d7b17b1cc0dbb5a1353765 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 11:43:54 +0100 Subject: [PATCH 06/21] fix exceeding_bitshift lint and test --- src/librustc_mir/transform/const_prop.rs | 12 +- .../lint-exceeding-bitshifts.default.stderr | 146 ++++++++++++++++++ .../lint-exceeding-bitshifts.noopt.stderr | 146 ++++++++++++++++++ .../lint/lint-exceeding-bitshifts.opt.stderr | 146 ++++++++++++++++++ ...-bitshifts.opt_with_overflow_checks.stderr | 146 ++++++++++++++++++ src/test/ui/lint/lint-exceeding-bitshifts.rs | 71 ++++++--- .../ui/lint/lint-exceeding-bitshifts.stderr | 116 -------------- src/test/ui/lint/lint-exceeding-bitshifts2.rs | 20 --- .../ui/lint/lint-exceeding-bitshifts2.stderr | 32 ---- 9 files changed, 641 insertions(+), 194 deletions(-) create mode 100644 src/test/ui/lint/lint-exceeding-bitshifts.default.stderr create mode 100644 src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr create mode 100644 src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr create mode 100644 src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr delete mode 100644 src/test/ui/lint/lint-exceeding-bitshifts.stderr delete mode 100644 src/test/ui/lint/lint-exceeding-bitshifts2.rs delete mode 100644 src/test/ui/lint/lint-exceeding-bitshifts2.stderr diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 53acf1490bf..05e70ed217a 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -547,16 +547,18 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { left: &Operand<'tcx>, right: &Operand<'tcx>, source_info: SourceInfo, - place_layout: TyLayout<'tcx>, ) -> Option<()> { let r = self.use_ecx(|this| this.ecx.read_immediate(this.ecx.eval_operand(right, None)?))?; // Check for exceeding shifts *even if* we cannot evaluate the LHS. if op == BinOp::Shr || op == BinOp::Shl { - let left_bits = place_layout.size.bits(); + // We need the type of the LHS. We cannot use `place_layout` as that is the type + // of the result, which for checked binops is not the same! + let left_ty = left.ty(&self.local_decls, self.tcx); + let left_size_bits = self.ecx.layout_of(left_ty).ok()?.size.bits(); let right_size = r.layout.size; let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size)); - if r_bits.map_or(false, |b| b >= left_bits as u128) { + if r_bits.map_or(false, |b| b >= left_size_bits as u128) { self.report_assert_as_lint( lint::builtin::EXCEEDING_BITSHIFTS, source_info, @@ -618,7 +620,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } Rvalue::BinaryOp(op, left, right) => { trace!("checking BinaryOp(op = {:?}, left = {:?}, right = {:?})", op, left, right); - self.check_binary_op(*op, left, right, source_info, place_layout)?; + self.check_binary_op(*op, left, right, source_info)?; } Rvalue::CheckedBinaryOp(op, left, right) => { trace!( @@ -627,7 +629,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { left, right ); - self.check_binary_op(*op, left, right, source_info, place_layout)?; + self.check_binary_op(*op, left, right, source_info)?; } // Do not try creating references (#67862) diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.default.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.default.stderr new file mode 100644 index 00000000000..5e32466c4e0 --- /dev/null +++ b/src/test/ui/lint/lint-exceeding-bitshifts.default.stderr @@ -0,0 +1,146 @@ +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:22:13 + | +LL | let _ = x << 42; + | ^^^^^^^ attempt to shift left with overflow + | +note: the lint level is defined here + --> $DIR/lint-exceeding-bitshifts.rs:9:9 + | +LL | #![deny(exceeding_bitshifts, const_err)] + | ^^^^^^^^^^^^^^^^^^^ + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:27:15 + | +LL | let n = 1u8 << 8; + | ^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:29:15 + | +LL | let n = 1u16 << 16; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:31:15 + | +LL | let n = 1u32 << 32; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:33:15 + | +LL | let n = 1u64 << 64; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:35:15 + | +LL | let n = 1i8 << 8; + | ^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:37:15 + | +LL | let n = 1i16 << 16; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:39:15 + | +LL | let n = 1i32 << 32; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:41:15 + | +LL | let n = 1i64 << 64; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:44:15 + | +LL | let n = 1u8 >> 8; + | ^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:46:15 + | +LL | let n = 1u16 >> 16; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:48:15 + | +LL | let n = 1u32 >> 32; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:50:15 + | +LL | let n = 1u64 >> 64; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:52:15 + | +LL | let n = 1i8 >> 8; + | ^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:54:15 + | +LL | let n = 1i16 >> 16; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:56:15 + | +LL | let n = 1i32 >> 32; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:58:15 + | +LL | let n = 1i64 >> 64; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:62:15 + | +LL | let n = n << 8; + | ^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:64:15 + | +LL | let n = 1u8 << -8; + | ^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:69:15 + | +LL | let n = 1u8 << (4+4); + | ^^^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:71:15 + | +LL | let n = 1i64 >> [64][0]; + | ^^^^^^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:77:15 + | +LL | let n = 1_isize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:78:15 + | +LL | let n = 1_usize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + +error: aborting due to 23 previous errors + diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr new file mode 100644 index 00000000000..5e32466c4e0 --- /dev/null +++ b/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr @@ -0,0 +1,146 @@ +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:22:13 + | +LL | let _ = x << 42; + | ^^^^^^^ attempt to shift left with overflow + | +note: the lint level is defined here + --> $DIR/lint-exceeding-bitshifts.rs:9:9 + | +LL | #![deny(exceeding_bitshifts, const_err)] + | ^^^^^^^^^^^^^^^^^^^ + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:27:15 + | +LL | let n = 1u8 << 8; + | ^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:29:15 + | +LL | let n = 1u16 << 16; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:31:15 + | +LL | let n = 1u32 << 32; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:33:15 + | +LL | let n = 1u64 << 64; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:35:15 + | +LL | let n = 1i8 << 8; + | ^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:37:15 + | +LL | let n = 1i16 << 16; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:39:15 + | +LL | let n = 1i32 << 32; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:41:15 + | +LL | let n = 1i64 << 64; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:44:15 + | +LL | let n = 1u8 >> 8; + | ^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:46:15 + | +LL | let n = 1u16 >> 16; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:48:15 + | +LL | let n = 1u32 >> 32; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:50:15 + | +LL | let n = 1u64 >> 64; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:52:15 + | +LL | let n = 1i8 >> 8; + | ^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:54:15 + | +LL | let n = 1i16 >> 16; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:56:15 + | +LL | let n = 1i32 >> 32; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:58:15 + | +LL | let n = 1i64 >> 64; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:62:15 + | +LL | let n = n << 8; + | ^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:64:15 + | +LL | let n = 1u8 << -8; + | ^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:69:15 + | +LL | let n = 1u8 << (4+4); + | ^^^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:71:15 + | +LL | let n = 1i64 >> [64][0]; + | ^^^^^^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:77:15 + | +LL | let n = 1_isize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:78:15 + | +LL | let n = 1_usize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + +error: aborting due to 23 previous errors + diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr new file mode 100644 index 00000000000..5e32466c4e0 --- /dev/null +++ b/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr @@ -0,0 +1,146 @@ +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:22:13 + | +LL | let _ = x << 42; + | ^^^^^^^ attempt to shift left with overflow + | +note: the lint level is defined here + --> $DIR/lint-exceeding-bitshifts.rs:9:9 + | +LL | #![deny(exceeding_bitshifts, const_err)] + | ^^^^^^^^^^^^^^^^^^^ + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:27:15 + | +LL | let n = 1u8 << 8; + | ^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:29:15 + | +LL | let n = 1u16 << 16; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:31:15 + | +LL | let n = 1u32 << 32; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:33:15 + | +LL | let n = 1u64 << 64; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:35:15 + | +LL | let n = 1i8 << 8; + | ^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:37:15 + | +LL | let n = 1i16 << 16; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:39:15 + | +LL | let n = 1i32 << 32; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:41:15 + | +LL | let n = 1i64 << 64; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:44:15 + | +LL | let n = 1u8 >> 8; + | ^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:46:15 + | +LL | let n = 1u16 >> 16; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:48:15 + | +LL | let n = 1u32 >> 32; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:50:15 + | +LL | let n = 1u64 >> 64; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:52:15 + | +LL | let n = 1i8 >> 8; + | ^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:54:15 + | +LL | let n = 1i16 >> 16; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:56:15 + | +LL | let n = 1i32 >> 32; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:58:15 + | +LL | let n = 1i64 >> 64; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:62:15 + | +LL | let n = n << 8; + | ^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:64:15 + | +LL | let n = 1u8 << -8; + | ^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:69:15 + | +LL | let n = 1u8 << (4+4); + | ^^^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:71:15 + | +LL | let n = 1i64 >> [64][0]; + | ^^^^^^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:77:15 + | +LL | let n = 1_isize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:78:15 + | +LL | let n = 1_usize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + +error: aborting due to 23 previous errors + diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr new file mode 100644 index 00000000000..5e32466c4e0 --- /dev/null +++ b/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr @@ -0,0 +1,146 @@ +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:22:13 + | +LL | let _ = x << 42; + | ^^^^^^^ attempt to shift left with overflow + | +note: the lint level is defined here + --> $DIR/lint-exceeding-bitshifts.rs:9:9 + | +LL | #![deny(exceeding_bitshifts, const_err)] + | ^^^^^^^^^^^^^^^^^^^ + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:27:15 + | +LL | let n = 1u8 << 8; + | ^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:29:15 + | +LL | let n = 1u16 << 16; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:31:15 + | +LL | let n = 1u32 << 32; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:33:15 + | +LL | let n = 1u64 << 64; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:35:15 + | +LL | let n = 1i8 << 8; + | ^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:37:15 + | +LL | let n = 1i16 << 16; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:39:15 + | +LL | let n = 1i32 << 32; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:41:15 + | +LL | let n = 1i64 << 64; + | ^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:44:15 + | +LL | let n = 1u8 >> 8; + | ^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:46:15 + | +LL | let n = 1u16 >> 16; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:48:15 + | +LL | let n = 1u32 >> 32; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:50:15 + | +LL | let n = 1u64 >> 64; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:52:15 + | +LL | let n = 1i8 >> 8; + | ^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:54:15 + | +LL | let n = 1i16 >> 16; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:56:15 + | +LL | let n = 1i32 >> 32; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:58:15 + | +LL | let n = 1i64 >> 64; + | ^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:62:15 + | +LL | let n = n << 8; + | ^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:64:15 + | +LL | let n = 1u8 << -8; + | ^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:69:15 + | +LL | let n = 1u8 << (4+4); + | ^^^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:71:15 + | +LL | let n = 1i64 >> [64][0]; + | ^^^^^^^^^^^^^^^ attempt to shift right with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:77:15 + | +LL | let n = 1_isize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + +error: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:78:15 + | +LL | let n = 1_usize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left with overflow + +error: aborting due to 23 previous errors + diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.rs b/src/test/ui/lint/lint-exceeding-bitshifts.rs index 121e5b796bb..3c6d70e7a6f 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.rs +++ b/src/test/ui/lint/lint-exceeding-bitshifts.rs @@ -1,50 +1,79 @@ -// build-fail -// compile-flags: -O +// revisions: default noopt opt opt_with_overflow_checks +//[noopt]compile-flags: -C opt-level=0 +//[opt]compile-flags: -O +//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O +// build-fail + +#![crate_type="lib"] #![deny(exceeding_bitshifts, const_err)] #![allow(unused_variables)] #![allow(dead_code)] -fn main() { +pub trait Foo { + const N: i32; +} + +impl Foo for Vec { + const N: i32 = T::N << 42; // FIXME this should warn +} + +pub fn foo(x: i32) { + let _ = x << 42; //~ ERROR: arithmetic operation will overflow +} + +pub fn main() { let n = 1u8 << 7; - let n = 1u8 << 8; //~ ERROR: attempt to shift left with overflow + let n = 1u8 << 8; //~ ERROR: arithmetic operation will overflow let n = 1u16 << 15; - let n = 1u16 << 16; //~ ERROR: attempt to shift left with overflow + let n = 1u16 << 16; //~ ERROR: arithmetic operation will overflow let n = 1u32 << 31; - let n = 1u32 << 32; //~ ERROR: attempt to shift left with overflow + let n = 1u32 << 32; //~ ERROR: arithmetic operation will overflow let n = 1u64 << 63; - let n = 1u64 << 64; //~ ERROR: attempt to shift left with overflow + let n = 1u64 << 64; //~ ERROR: arithmetic operation will overflow let n = 1i8 << 7; - let n = 1i8 << 8; //~ ERROR: attempt to shift left with overflow + let n = 1i8 << 8; //~ ERROR: arithmetic operation will overflow let n = 1i16 << 15; - let n = 1i16 << 16; //~ ERROR: attempt to shift left with overflow + let n = 1i16 << 16; //~ ERROR: arithmetic operation will overflow let n = 1i32 << 31; - let n = 1i32 << 32; //~ ERROR: attempt to shift left with overflow + let n = 1i32 << 32; //~ ERROR: arithmetic operation will overflow let n = 1i64 << 63; - let n = 1i64 << 64; //~ ERROR: attempt to shift left with overflow + let n = 1i64 << 64; //~ ERROR: arithmetic operation will overflow let n = 1u8 >> 7; - let n = 1u8 >> 8; //~ ERROR: attempt to shift right with overflow + let n = 1u8 >> 8; //~ ERROR: arithmetic operation will overflow let n = 1u16 >> 15; - let n = 1u16 >> 16; //~ ERROR: attempt to shift right with overflow + let n = 1u16 >> 16; //~ ERROR: arithmetic operation will overflow let n = 1u32 >> 31; - let n = 1u32 >> 32; //~ ERROR: attempt to shift right with overflow + let n = 1u32 >> 32; //~ ERROR: arithmetic operation will overflow let n = 1u64 >> 63; - let n = 1u64 >> 64; //~ ERROR: attempt to shift right with overflow + let n = 1u64 >> 64; //~ ERROR: arithmetic operation will overflow let n = 1i8 >> 7; - let n = 1i8 >> 8; //~ ERROR: attempt to shift right with overflow + let n = 1i8 >> 8; //~ ERROR: arithmetic operation will overflow let n = 1i16 >> 15; - let n = 1i16 >> 16; //~ ERROR: attempt to shift right with overflow + let n = 1i16 >> 16; //~ ERROR: arithmetic operation will overflow let n = 1i32 >> 31; - let n = 1i32 >> 32; //~ ERROR: attempt to shift right with overflow + let n = 1i32 >> 32; //~ ERROR: arithmetic operation will overflow let n = 1i64 >> 63; - let n = 1i64 >> 64; //~ ERROR: attempt to shift right with overflow + let n = 1i64 >> 64; //~ ERROR: arithmetic operation will overflow let n = 1u8; let n = n << 7; - let n = n << 8; //~ ERROR: attempt to shift left with overflow + let n = n << 8; //~ ERROR: arithmetic operation will overflow - let n = 1u8 << -8; //~ ERROR: attempt to shift left with overflow + let n = 1u8 << -8; //~ ERROR: arithmetic operation will overflow let n = 1i8<<(1isize+-1); + + let n = 1u8 << (4+3); + let n = 1u8 << (4+4); //~ ERROR: arithmetic operation will overflow + let n = 1i64 >> [63][0]; + let n = 1i64 >> [64][0]; //~ ERROR: arithmetic operation will overflow + + #[cfg(target_pointer_width = "32")] + const BITS: usize = 32; + #[cfg(target_pointer_width = "64")] + const BITS: usize = 64; + let n = 1_isize << BITS; //~ ERROR: arithmetic operation will overflow + let n = 1_usize << BITS; //~ ERROR: arithmetic operation will overflow } diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.stderr deleted file mode 100644 index 658577213b3..00000000000 --- a/src/test/ui/lint/lint-exceeding-bitshifts.stderr +++ /dev/null @@ -1,116 +0,0 @@ -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts.rs:10:15 - | -LL | let n = 1u8 << 8; - | ^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/lint-exceeding-bitshifts.rs:4:9 - | -LL | #![deny(exceeding_bitshifts, const_err)] - | ^^^^^^^^^^^^^^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts.rs:12:15 - | -LL | let n = 1u16 << 16; - | ^^^^^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts.rs:14:15 - | -LL | let n = 1u32 << 32; - | ^^^^^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts.rs:16:15 - | -LL | let n = 1u64 << 64; - | ^^^^^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts.rs:18:15 - | -LL | let n = 1i8 << 8; - | ^^^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts.rs:20:15 - | -LL | let n = 1i16 << 16; - | ^^^^^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts.rs:22:15 - | -LL | let n = 1i32 << 32; - | ^^^^^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts.rs:24:15 - | -LL | let n = 1i64 << 64; - | ^^^^^^^^^^ - -error: attempt to shift right with overflow - --> $DIR/lint-exceeding-bitshifts.rs:27:15 - | -LL | let n = 1u8 >> 8; - | ^^^^^^^^ - -error: attempt to shift right with overflow - --> $DIR/lint-exceeding-bitshifts.rs:29:15 - | -LL | let n = 1u16 >> 16; - | ^^^^^^^^^^ - -error: attempt to shift right with overflow - --> $DIR/lint-exceeding-bitshifts.rs:31:15 - | -LL | let n = 1u32 >> 32; - | ^^^^^^^^^^ - -error: attempt to shift right with overflow - --> $DIR/lint-exceeding-bitshifts.rs:33:15 - | -LL | let n = 1u64 >> 64; - | ^^^^^^^^^^ - -error: attempt to shift right with overflow - --> $DIR/lint-exceeding-bitshifts.rs:35:15 - | -LL | let n = 1i8 >> 8; - | ^^^^^^^^ - -error: attempt to shift right with overflow - --> $DIR/lint-exceeding-bitshifts.rs:37:15 - | -LL | let n = 1i16 >> 16; - | ^^^^^^^^^^ - -error: attempt to shift right with overflow - --> $DIR/lint-exceeding-bitshifts.rs:39:15 - | -LL | let n = 1i32 >> 32; - | ^^^^^^^^^^ - -error: attempt to shift right with overflow - --> $DIR/lint-exceeding-bitshifts.rs:41:15 - | -LL | let n = 1i64 >> 64; - | ^^^^^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts.rs:45:15 - | -LL | let n = n << 8; - | ^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts.rs:47:15 - | -LL | let n = 1u8 << -8; - | ^^^^^^^^^ - -error: aborting due to 18 previous errors - diff --git a/src/test/ui/lint/lint-exceeding-bitshifts2.rs b/src/test/ui/lint/lint-exceeding-bitshifts2.rs deleted file mode 100644 index 2a7cbc10f77..00000000000 --- a/src/test/ui/lint/lint-exceeding-bitshifts2.rs +++ /dev/null @@ -1,20 +0,0 @@ -// build-fail -// compile-flags: -O - -#![deny(exceeding_bitshifts, const_err)] -#![allow(unused_variables)] -#![allow(dead_code)] - -fn main() { - let n = 1u8 << (4+3); - let n = 1u8 << (4+4); //~ ERROR: attempt to shift left with overflow - let n = 1i64 >> [63][0]; - let n = 1i64 >> [64][0]; //~ ERROR: attempt to shift right with overflow - - #[cfg(target_pointer_width = "32")] - const BITS: usize = 32; - #[cfg(target_pointer_width = "64")] - const BITS: usize = 64; - let n = 1_isize << BITS; //~ ERROR: attempt to shift left with overflow - let n = 1_usize << BITS; //~ ERROR: attempt to shift left with overflow -} diff --git a/src/test/ui/lint/lint-exceeding-bitshifts2.stderr b/src/test/ui/lint/lint-exceeding-bitshifts2.stderr deleted file mode 100644 index ac9f3b1e56b..00000000000 --- a/src/test/ui/lint/lint-exceeding-bitshifts2.stderr +++ /dev/null @@ -1,32 +0,0 @@ -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts2.rs:10:15 - | -LL | let n = 1u8 << (4+4); - | ^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/lint-exceeding-bitshifts2.rs:4:9 - | -LL | #![deny(exceeding_bitshifts, const_err)] - | ^^^^^^^^^^^^^^^^^^^ - -error: attempt to shift right with overflow - --> $DIR/lint-exceeding-bitshifts2.rs:12:15 - | -LL | let n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts2.rs:18:15 - | -LL | let n = 1_isize << BITS; - | ^^^^^^^^^^^^^^^ - -error: attempt to shift left with overflow - --> $DIR/lint-exceeding-bitshifts2.rs:19:15 - | -LL | let n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors - From 415218fc8d590063a8c5cd403ff890fb91c0bd2c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 11:47:11 +0100 Subject: [PATCH 07/21] expand assoc-const test a bit, just to be sure --- src/test/ui/consts/issue-69020.default.stderr | 28 ++++++++++++++++--- src/test/ui/consts/issue-69020.noopt.stderr | 28 ++++++++++++++++--- src/test/ui/consts/issue-69020.opt.stderr | 28 ++++++++++++++++--- ...ssue-69020.opt_with_overflow_checks.stderr | 28 ++++++++++++++++--- src/test/ui/consts/issue-69020.rs | 16 +++++++++-- 5 files changed, 110 insertions(+), 18 deletions(-) diff --git a/src/test/ui/consts/issue-69020.default.stderr b/src/test/ui/consts/issue-69020.default.stderr index 0bf40ce4b31..1b1987f4dc3 100644 --- a/src/test/ui/consts/issue-69020.default.stderr +++ b/src/test/ui/consts/issue-69020.default.stderr @@ -1,10 +1,30 @@ error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:15:20 + --> $DIR/issue-69020.rs:21:22 | -LL | const N: i32 = -i32::MIN + T::N; - | ^^^^^^^^^ attempt to negate with overflow +LL | const NEG: i32 = -i32::MIN + T::NEG; + | ^^^^^^^^^ attempt to negate with overflow | = note: `#[deny(overflow)]` on by default -error: aborting due to previous error +error: this arithmetic operation will overflow + --> $DIR/issue-69020.rs:23:22 + | +LL | const ADD: i32 = (i32::MAX+1) + T::ADD; + | ^^^^^^^^^^^^ attempt to add with overflow + +error: this operation will panic at runtime + --> $DIR/issue-69020.rs:25:22 + | +LL | const DIV: i32 = (1/0) + T::DIV; + | ^^^^^ attempt to divide by zero + | + = note: `#[deny(panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-69020.rs:27:22 + | +LL | const OOB: i32 = [1][1] + T::OOB; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 + +error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/issue-69020.noopt.stderr b/src/test/ui/consts/issue-69020.noopt.stderr index 0bf40ce4b31..1b1987f4dc3 100644 --- a/src/test/ui/consts/issue-69020.noopt.stderr +++ b/src/test/ui/consts/issue-69020.noopt.stderr @@ -1,10 +1,30 @@ error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:15:20 + --> $DIR/issue-69020.rs:21:22 | -LL | const N: i32 = -i32::MIN + T::N; - | ^^^^^^^^^ attempt to negate with overflow +LL | const NEG: i32 = -i32::MIN + T::NEG; + | ^^^^^^^^^ attempt to negate with overflow | = note: `#[deny(overflow)]` on by default -error: aborting due to previous error +error: this arithmetic operation will overflow + --> $DIR/issue-69020.rs:23:22 + | +LL | const ADD: i32 = (i32::MAX+1) + T::ADD; + | ^^^^^^^^^^^^ attempt to add with overflow + +error: this operation will panic at runtime + --> $DIR/issue-69020.rs:25:22 + | +LL | const DIV: i32 = (1/0) + T::DIV; + | ^^^^^ attempt to divide by zero + | + = note: `#[deny(panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-69020.rs:27:22 + | +LL | const OOB: i32 = [1][1] + T::OOB; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 + +error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/issue-69020.opt.stderr b/src/test/ui/consts/issue-69020.opt.stderr index 0bf40ce4b31..1b1987f4dc3 100644 --- a/src/test/ui/consts/issue-69020.opt.stderr +++ b/src/test/ui/consts/issue-69020.opt.stderr @@ -1,10 +1,30 @@ error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:15:20 + --> $DIR/issue-69020.rs:21:22 | -LL | const N: i32 = -i32::MIN + T::N; - | ^^^^^^^^^ attempt to negate with overflow +LL | const NEG: i32 = -i32::MIN + T::NEG; + | ^^^^^^^^^ attempt to negate with overflow | = note: `#[deny(overflow)]` on by default -error: aborting due to previous error +error: this arithmetic operation will overflow + --> $DIR/issue-69020.rs:23:22 + | +LL | const ADD: i32 = (i32::MAX+1) + T::ADD; + | ^^^^^^^^^^^^ attempt to add with overflow + +error: this operation will panic at runtime + --> $DIR/issue-69020.rs:25:22 + | +LL | const DIV: i32 = (1/0) + T::DIV; + | ^^^^^ attempt to divide by zero + | + = note: `#[deny(panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-69020.rs:27:22 + | +LL | const OOB: i32 = [1][1] + T::OOB; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 + +error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr b/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr index 0bf40ce4b31..1b1987f4dc3 100644 --- a/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr +++ b/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr @@ -1,10 +1,30 @@ error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:15:20 + --> $DIR/issue-69020.rs:21:22 | -LL | const N: i32 = -i32::MIN + T::N; - | ^^^^^^^^^ attempt to negate with overflow +LL | const NEG: i32 = -i32::MIN + T::NEG; + | ^^^^^^^^^ attempt to negate with overflow | = note: `#[deny(overflow)]` on by default -error: aborting due to previous error +error: this arithmetic operation will overflow + --> $DIR/issue-69020.rs:23:22 + | +LL | const ADD: i32 = (i32::MAX+1) + T::ADD; + | ^^^^^^^^^^^^ attempt to add with overflow + +error: this operation will panic at runtime + --> $DIR/issue-69020.rs:25:22 + | +LL | const DIV: i32 = (1/0) + T::DIV; + | ^^^^^ attempt to divide by zero + | + = note: `#[deny(panic)]` on by default + +error: this operation will panic at runtime + --> $DIR/issue-69020.rs:27:22 + | +LL | const OOB: i32 = [1][1] + T::OOB; + | ^^^^^^ index out of bounds: the len is 1 but the index is 1 + +error: aborting due to 4 previous errors diff --git a/src/test/ui/consts/issue-69020.rs b/src/test/ui/consts/issue-69020.rs index 9f1ed862c7b..963ab01a33c 100644 --- a/src/test/ui/consts/issue-69020.rs +++ b/src/test/ui/consts/issue-69020.rs @@ -8,10 +8,22 @@ use std::i32; pub trait Foo { - const N: i32; + const NEG: i32; + const ADD: i32; + const DIV: i32; + const OOB: i32; } +// These constants cannot be evaluated already (they depend on `T::N`), so +// they can just be linted like normal run-time code. But codegen works +// a bit different in const context, so this test makes sure that we still catch overflow. impl Foo for Vec { - const N: i32 = -i32::MIN + T::N; + const NEG: i32 = -i32::MIN + T::NEG; //~^ ERROR arithmetic operation will overflow + const ADD: i32 = (i32::MAX+1) + T::ADD; + //~^ ERROR arithmetic operation will overflow + const DIV: i32 = (1/0) + T::DIV; + //~^ ERROR operation will panic + const OOB: i32 = [1][1] + T::OOB; + //~^ ERROR operation will panic } From 25870a0b77e8d0e37aecce17f1b37fc5bf630b56 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 13:15:15 +0100 Subject: [PATCH 08/21] fix another test --- src/test/ui/issues/issue-54348.rs | 4 ++-- src/test/ui/issues/issue-54348.stderr | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/ui/issues/issue-54348.rs b/src/test/ui/issues/issue-54348.rs index fd9a9e024aa..5c38d7c42f6 100644 --- a/src/test/ui/issues/issue-54348.rs +++ b/src/test/ui/issues/issue-54348.rs @@ -2,6 +2,6 @@ fn main() { [1][0u64 as usize]; - [1][1.5 as usize]; //~ ERROR index out of bounds - [1][1u64 as usize]; //~ ERROR index out of bounds + [1][1.5 as usize]; //~ ERROR operation will panic + [1][1u64 as usize]; //~ ERROR operation will panic } diff --git a/src/test/ui/issues/issue-54348.stderr b/src/test/ui/issues/issue-54348.stderr index 7619cd7437e..f2156a35f2a 100644 --- a/src/test/ui/issues/issue-54348.stderr +++ b/src/test/ui/issues/issue-54348.stderr @@ -1,16 +1,16 @@ -error: index out of bounds: the len is 1 but the index is 1 +error: this operation will panic at runtime --> $DIR/issue-54348.rs:5:5 | LL | [1][1.5 as usize]; - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ index out of bounds: the len is 1 but the index is 1 | - = note: `#[deny(const_err)]` on by default + = note: `#[deny(panic)]` on by default -error: index out of bounds: the len is 1 but the index is 1 +error: this operation will panic at runtime --> $DIR/issue-54348.rs:6:5 | LL | [1][1u64 as usize]; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ index out of bounds: the len is 1 but the index is 1 error: aborting due to 2 previous errors From c4a6f84b8065fb0aae240f820b007a22fbaf7a87 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 14:57:13 +0100 Subject: [PATCH 09/21] fix compile-fail --- src/test/compile-fail/consts/const-err3.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/compile-fail/consts/const-err3.rs b/src/test/compile-fail/consts/const-err3.rs index fc10824f0c0..efd51f40224 100644 --- a/src/test/compile-fail/consts/const-err3.rs +++ b/src/test/compile-fail/consts/const-err3.rs @@ -7,13 +7,13 @@ fn black_box(_: T) { fn main() { let b = 200u8 + 200u8 + 200u8; - //~^ ERROR const_err + //~^ ERROR overflow let c = 200u8 * 4; - //~^ ERROR const_err + //~^ ERROR overflow let d = 42u8 - (42u8 + 1); - //~^ ERROR const_err + //~^ ERROR overflow let _e = [5u8][1]; - //~^ ERROR const_err + //~^ ERROR panic black_box(b); black_box(c); black_box(d); From 0c8c800f21e00c7db39084e6b8087706a816fba7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 15:42:13 +0100 Subject: [PATCH 10/21] Tighter type bounds for messages Co-Authored-By: Mazdak Farrokhzad --- src/librustc_mir/transform/const_prop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 05e70ed217a..eec4bbc720d 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -504,7 +504,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { &self, lint: &'static lint::Lint, source_info: SourceInfo, - message: &str, + message: &'static str, panic: AssertKind, ) -> Option<()> { let lint_root = self.lint_root(source_info)?; From 3134df22143a9d9304e2b835957db6f40f8950da Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 19:02:36 +0100 Subject: [PATCH 11/21] adjust run-fail tests --- src/test/run-fail/mir_indexing_oob_1.rs | 2 +- src/test/run-fail/mir_indexing_oob_2.rs | 2 +- src/test/run-fail/mir_indexing_oob_3.rs | 2 +- src/test/run-fail/overflowing-add.rs | 2 +- src/test/run-fail/overflowing-mul.rs | 2 +- src/test/run-fail/overflowing-neg.rs | 2 +- src/test/run-fail/overflowing-sub.rs | 2 +- src/test/run-fail/promoted_div_by_zero.rs | 2 +- src/test/run-fail/promoted_overflow.rs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/run-fail/mir_indexing_oob_1.rs b/src/test/run-fail/mir_indexing_oob_1.rs index 0ae0320b124..6aaf46cfb1b 100644 --- a/src/test/run-fail/mir_indexing_oob_1.rs +++ b/src/test/run-fail/mir_indexing_oob_1.rs @@ -2,7 +2,7 @@ const C: [u32; 5] = [0; 5]; -#[allow(const_err)] +#[allow(panic, const_err)] fn test() -> u32 { C[10] } diff --git a/src/test/run-fail/mir_indexing_oob_2.rs b/src/test/run-fail/mir_indexing_oob_2.rs index a7a1177260c..1bf8459a068 100644 --- a/src/test/run-fail/mir_indexing_oob_2.rs +++ b/src/test/run-fail/mir_indexing_oob_2.rs @@ -2,7 +2,7 @@ const C: &'static [u8; 5] = b"hello"; -#[allow(const_err)] +#[allow(panic, const_err)] fn test() -> u8 { C[10] } diff --git a/src/test/run-fail/mir_indexing_oob_3.rs b/src/test/run-fail/mir_indexing_oob_3.rs index 188460fff78..c13ca721ea8 100644 --- a/src/test/run-fail/mir_indexing_oob_3.rs +++ b/src/test/run-fail/mir_indexing_oob_3.rs @@ -2,7 +2,7 @@ const C: &'static [u8; 5] = b"hello"; -#[allow(const_err)] +#[allow(panic, const_err)] fn mir() -> u8 { C[10] } diff --git a/src/test/run-fail/overflowing-add.rs b/src/test/run-fail/overflowing-add.rs index 24602aced9e..69d7779e13e 100644 --- a/src/test/run-fail/overflowing-add.rs +++ b/src/test/run-fail/overflowing-add.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to add with overflow' // compile-flags: -C debug-assertions -#![allow(const_err)] +#![allow(overflow)] fn main() { let _x = 200u8 + 200u8 + 200u8; diff --git a/src/test/run-fail/overflowing-mul.rs b/src/test/run-fail/overflowing-mul.rs index 48110365a81..ef191c01586 100644 --- a/src/test/run-fail/overflowing-mul.rs +++ b/src/test/run-fail/overflowing-mul.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to multiply with overflow' // compile-flags: -C debug-assertions -#![allow(const_err)] +#![allow(overflow)] fn main() { let x = 200u8 * 4; diff --git a/src/test/run-fail/overflowing-neg.rs b/src/test/run-fail/overflowing-neg.rs index c4afd74241e..443cddf53fb 100644 --- a/src/test/run-fail/overflowing-neg.rs +++ b/src/test/run-fail/overflowing-neg.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to negate with overflow' // compile-flags: -C debug-assertions -#![allow(const_err)] +#![allow(overflow)] fn main() { let _x = -std::i8::MIN; diff --git a/src/test/run-fail/overflowing-sub.rs b/src/test/run-fail/overflowing-sub.rs index e3b111dd2bb..4f4a3eed8cc 100644 --- a/src/test/run-fail/overflowing-sub.rs +++ b/src/test/run-fail/overflowing-sub.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to subtract with overflow' // compile-flags: -C debug-assertions -#![allow(const_err)] +#![allow(overflow)] fn main() { let _x = 42u8 - (42u8 + 1); diff --git a/src/test/run-fail/promoted_div_by_zero.rs b/src/test/run-fail/promoted_div_by_zero.rs index 3fe51a19c20..0ad081f0314 100644 --- a/src/test/run-fail/promoted_div_by_zero.rs +++ b/src/test/run-fail/promoted_div_by_zero.rs @@ -1,4 +1,4 @@ -#![allow(const_err)] +#![allow(panic, const_err)] // error-pattern: attempt to divide by zero diff --git a/src/test/run-fail/promoted_overflow.rs b/src/test/run-fail/promoted_overflow.rs index 139bf540959..a90f832ddd0 100644 --- a/src/test/run-fail/promoted_overflow.rs +++ b/src/test/run-fail/promoted_overflow.rs @@ -1,4 +1,4 @@ -#![allow(const_err)] +#![allow(overflow)] // error-pattern: overflow // compile-flags: -C overflow-checks=yes From 94047f18c2681be6aca4a0f4de4947fe47b8f8b2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 19:40:33 +0100 Subject: [PATCH 12/21] remove no-longer-needed test --- src/test/compile-fail/consts/const-err3.rs | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 src/test/compile-fail/consts/const-err3.rs diff --git a/src/test/compile-fail/consts/const-err3.rs b/src/test/compile-fail/consts/const-err3.rs deleted file mode 100644 index efd51f40224..00000000000 --- a/src/test/compile-fail/consts/const-err3.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![feature(rustc_attrs)] -#![deny(const_err)] - -fn black_box(_: T) { - unimplemented!() -} - -fn main() { - let b = 200u8 + 200u8 + 200u8; - //~^ ERROR overflow - let c = 200u8 * 4; - //~^ ERROR overflow - let d = 42u8 - (42u8 + 1); - //~^ ERROR overflow - let _e = [5u8][1]; - //~^ ERROR panic - black_box(b); - black_box(c); - black_box(d); -} From b6aaacd9914a98d91f0abb8d727bbba14d82957c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 21:37:53 +0100 Subject: [PATCH 13/21] fix codegen tests --- src/test/codegen/issue-56927.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/codegen/issue-56927.rs b/src/test/codegen/issue-56927.rs index 0544ff86aac..5ba17d3499b 100644 --- a/src/test/codegen/issue-56927.rs +++ b/src/test/codegen/issue-56927.rs @@ -23,7 +23,7 @@ pub fn test1(s: &mut S) { // CHECK-LABEL: @test2 // CHECK: store i32 4, i32* %{{.+}}, align 4 -#[allow(const_err)] +#[allow(panic)] #[no_mangle] pub fn test2(s: &mut S) { s.arr[usize::MAX / 4 + 1] = 4; From 97cc3a229bfe44d387a458fc6e25e58ee11acee3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 15 Feb 2020 23:02:58 +0100 Subject: [PATCH 14/21] fix incremental tests --- src/test/incremental/warnings-reemitted.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/incremental/warnings-reemitted.rs b/src/test/incremental/warnings-reemitted.rs index 5fc89395827..657bc30c088 100644 --- a/src/test/incremental/warnings-reemitted.rs +++ b/src/test/incremental/warnings-reemitted.rs @@ -2,8 +2,8 @@ // compile-flags: -Coverflow-checks=on // build-pass (FIXME(62277): could be check-pass?) -#![warn(const_err)] +#![warn(overflow)] fn main() { - let _ = 255u8 + 1; //~ WARNING attempt to add with overflow + let _ = 255u8 + 1; //~ WARNING operation will overflow } From 5e19350a4c858bd98b0864d55e8ce1efc370e33d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 18 Feb 2020 22:49:47 +0100 Subject: [PATCH 15/21] better lint names --- src/librustc_lint/lib.rs | 1 + src/librustc_mir/transform/const_prop.rs | 8 ++++---- src/librustc_session/lint/builtin.rs | 15 ++++----------- src/test/codegen/issue-56927.rs | 2 +- src/test/incremental/warnings-reemitted.rs | 2 +- src/test/run-fail/mir_indexing_oob_1.rs | 2 +- src/test/run-fail/mir_indexing_oob_2.rs | 2 +- src/test/run-fail/mir_indexing_oob_3.rs | 2 +- src/test/run-fail/overflowing-add.rs | 2 +- src/test/run-fail/overflowing-lsh-1.rs | 2 +- src/test/run-fail/overflowing-lsh-2.rs | 2 +- src/test/run-fail/overflowing-lsh-3.rs | 2 +- src/test/run-fail/overflowing-lsh-4.rs | 2 +- src/test/run-fail/overflowing-mul.rs | 2 +- src/test/run-fail/overflowing-neg.rs | 2 +- src/test/run-fail/overflowing-rsh-1.rs | 2 +- src/test/run-fail/overflowing-rsh-2.rs | 2 +- src/test/run-fail/overflowing-rsh-3.rs | 2 +- src/test/run-fail/overflowing-rsh-4.rs | 2 +- src/test/run-fail/overflowing-rsh-5.rs | 2 +- src/test/run-fail/overflowing-rsh-6.rs | 2 +- src/test/run-fail/overflowing-sub.rs | 2 +- src/test/run-fail/promoted_div_by_zero.rs | 2 +- src/test/run-fail/promoted_overflow.rs | 2 +- src/test/ui/consts/array-literal-index-oob.rs | 2 +- src/test/ui/consts/array-literal-index-oob.stderr | 6 +++--- src/test/ui/consts/const-err.rs | 2 +- src/test/ui/consts/const-err2.default.stderr | 4 ++-- src/test/ui/consts/const-err2.noopt.stderr | 4 ++-- src/test/ui/consts/const-err2.opt.stderr | 4 ++-- .../const-err2.opt_with_overflow_checks.stderr | 4 ++-- .../index_out_of_bounds_propagated.stderr | 2 +- .../const-eval/promoted_errors.default.stderr | 12 ++++++------ .../const-eval/promoted_errors.noopt.stderr | 12 ++++++------ .../consts/const-eval/promoted_errors.opt.stderr | 12 ++++++------ ...romoted_errors.opt_with_overflow_checks.stderr | 12 ++++++------ src/test/ui/consts/const-eval/promoted_errors.rs | 14 +++++++------- src/test/ui/consts/const-prop-ice.stderr | 2 +- src/test/ui/consts/const-prop-ice2.stderr | 2 +- src/test/ui/consts/issue-69020.default.stderr | 4 ++-- src/test/ui/consts/issue-69020.noopt.stderr | 4 ++-- src/test/ui/consts/issue-69020.opt.stderr | 4 ++-- .../issue-69020.opt_with_overflow_checks.stderr | 4 ++-- src/test/ui/huge-array-simple-64.rs | 2 +- src/test/ui/issues/issue-54348.stderr | 2 +- .../ui/issues/issue-8460-const.default.stderr | 4 ++-- src/test/ui/issues/issue-8460-const.noopt.stderr | 4 ++-- src/test/ui/issues/issue-8460-const.opt.stderr | 4 ++-- ...sue-8460-const.opt_with_overflow_checks.stderr | 4 ++-- .../lint/lint-exceeding-bitshifts.default.stderr | 2 +- .../ui/lint/lint-exceeding-bitshifts.noopt.stderr | 2 +- .../ui/lint/lint-exceeding-bitshifts.opt.stderr | 2 +- ...ding-bitshifts.opt_with_overflow_checks.stderr | 2 +- src/test/ui/lint/lint-exceeding-bitshifts.rs | 2 +- 54 files changed, 100 insertions(+), 106 deletions(-) diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 2204e104803..0e7625da30a 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -305,6 +305,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { store.register_renamed("unstable_name_collision", "unstable_name_collisions"); store.register_renamed("unused_doc_comment", "unused_doc_comments"); store.register_renamed("async_idents", "keyword_idents"); + store.register_renamed("exceeding_bitshifts", "arithmetic_overflow"); store.register_removed("unknown_features", "replaced by an error"); store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate"); store.register_removed("negate_unsigned", "cast a signed value instead"); diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index eec4bbc720d..8ccfcecdbe3 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -531,7 +531,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // appropriate to use. assert_eq!(op, UnOp::Neg, "Neg is the only UnOp that can overflow"); self.report_assert_as_lint( - lint::builtin::OVERFLOW, + lint::builtin::ARITHMETIC_OVERFLOW, source_info, "this arithmetic operation will overflow", AssertKind::OverflowNeg, @@ -560,7 +560,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size)); if r_bits.map_or(false, |b| b >= left_size_bits as u128) { self.report_assert_as_lint( - lint::builtin::EXCEEDING_BITSHIFTS, + lint::builtin::ARITHMETIC_OVERFLOW, source_info, "this arithmetic operation will overflow", AssertKind::Overflow(op), @@ -575,7 +575,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { Ok(overflow) })? { self.report_assert_as_lint( - lint::builtin::OVERFLOW, + lint::builtin::ARITHMETIC_OVERFLOW, source_info, "this arithmetic operation will overflow", AssertKind::Overflow(op), @@ -937,7 +937,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { _ => return, }; self.report_assert_as_lint( - lint::builtin::PANIC, + lint::builtin::UNCONDITIONAL_PANIC, source_info, "this operation will panic at runtime", msg, diff --git a/src/librustc_session/lint/builtin.rs b/src/librustc_session/lint/builtin.rs index 992f8ab2617..603ed4640a0 100644 --- a/src/librustc_session/lint/builtin.rs +++ b/src/librustc_session/lint/builtin.rs @@ -41,19 +41,13 @@ declare_lint! { } declare_lint! { - pub EXCEEDING_BITSHIFTS, - Deny, - "shift exceeds the type's number of bits" -} - -declare_lint! { - pub OVERFLOW, + pub ARITHMETIC_OVERFLOW, Deny, "arithmetic operation overflows" } declare_lint! { - pub PANIC, + pub UNCONDITIONAL_PANIC, Deny, "operation will cause a panic at runtime" } @@ -507,9 +501,8 @@ declare_lint_pass! { /// that are used by other parts of the compiler. HardwiredLints => [ ILLEGAL_FLOATING_POINT_LITERAL_PATTERN, - EXCEEDING_BITSHIFTS, - OVERFLOW, - PANIC, + ARITHMETIC_OVERFLOW, + UNCONDITIONAL_PANIC, UNUSED_IMPORTS, UNUSED_EXTERN_CRATES, UNUSED_QUALIFICATIONS, diff --git a/src/test/codegen/issue-56927.rs b/src/test/codegen/issue-56927.rs index 5ba17d3499b..d502673e2f8 100644 --- a/src/test/codegen/issue-56927.rs +++ b/src/test/codegen/issue-56927.rs @@ -23,7 +23,7 @@ pub fn test1(s: &mut S) { // CHECK-LABEL: @test2 // CHECK: store i32 4, i32* %{{.+}}, align 4 -#[allow(panic)] +#[allow(unconditional_panic)] #[no_mangle] pub fn test2(s: &mut S) { s.arr[usize::MAX / 4 + 1] = 4; diff --git a/src/test/incremental/warnings-reemitted.rs b/src/test/incremental/warnings-reemitted.rs index 657bc30c088..0eac2a1d57f 100644 --- a/src/test/incremental/warnings-reemitted.rs +++ b/src/test/incremental/warnings-reemitted.rs @@ -2,7 +2,7 @@ // compile-flags: -Coverflow-checks=on // build-pass (FIXME(62277): could be check-pass?) -#![warn(overflow)] +#![warn(arithmetic_overflow)] fn main() { let _ = 255u8 + 1; //~ WARNING operation will overflow diff --git a/src/test/run-fail/mir_indexing_oob_1.rs b/src/test/run-fail/mir_indexing_oob_1.rs index 6aaf46cfb1b..1cd53e309eb 100644 --- a/src/test/run-fail/mir_indexing_oob_1.rs +++ b/src/test/run-fail/mir_indexing_oob_1.rs @@ -2,7 +2,7 @@ const C: [u32; 5] = [0; 5]; -#[allow(panic, const_err)] +#[allow(unconditional_panic)] fn test() -> u32 { C[10] } diff --git a/src/test/run-fail/mir_indexing_oob_2.rs b/src/test/run-fail/mir_indexing_oob_2.rs index 1bf8459a068..64b260993c9 100644 --- a/src/test/run-fail/mir_indexing_oob_2.rs +++ b/src/test/run-fail/mir_indexing_oob_2.rs @@ -2,7 +2,7 @@ const C: &'static [u8; 5] = b"hello"; -#[allow(panic, const_err)] +#[allow(unconditional_panic)] fn test() -> u8 { C[10] } diff --git a/src/test/run-fail/mir_indexing_oob_3.rs b/src/test/run-fail/mir_indexing_oob_3.rs index c13ca721ea8..3688088439b 100644 --- a/src/test/run-fail/mir_indexing_oob_3.rs +++ b/src/test/run-fail/mir_indexing_oob_3.rs @@ -2,7 +2,7 @@ const C: &'static [u8; 5] = b"hello"; -#[allow(panic, const_err)] +#[allow(unconditional_panic)] fn mir() -> u8 { C[10] } diff --git a/src/test/run-fail/overflowing-add.rs b/src/test/run-fail/overflowing-add.rs index 69d7779e13e..5ca91314d95 100644 --- a/src/test/run-fail/overflowing-add.rs +++ b/src/test/run-fail/overflowing-add.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to add with overflow' // compile-flags: -C debug-assertions -#![allow(overflow)] +#![allow(arithmetic_overflow)] fn main() { let _x = 200u8 + 200u8 + 200u8; diff --git a/src/test/run-fail/overflowing-lsh-1.rs b/src/test/run-fail/overflowing-lsh-1.rs index 37fbf01e487..977cfea0fe0 100644 --- a/src/test/run-fail/overflowing-lsh-1.rs +++ b/src/test/run-fail/overflowing-lsh-1.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to shift left with overflow' // compile-flags: -C debug-assertions -#![warn(exceeding_bitshifts)] +#![warn(arithmetic_overflow)] #![warn(const_err)] fn main() { diff --git a/src/test/run-fail/overflowing-lsh-2.rs b/src/test/run-fail/overflowing-lsh-2.rs index 7b0b37dfed0..3517dacde3a 100644 --- a/src/test/run-fail/overflowing-lsh-2.rs +++ b/src/test/run-fail/overflowing-lsh-2.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to shift left with overflow' // compile-flags: -C debug-assertions -#![warn(exceeding_bitshifts)] +#![warn(arithmetic_overflow)] #![warn(const_err)] fn main() { diff --git a/src/test/run-fail/overflowing-lsh-3.rs b/src/test/run-fail/overflowing-lsh-3.rs index 1768a8e6d31..4a575c3fa7f 100644 --- a/src/test/run-fail/overflowing-lsh-3.rs +++ b/src/test/run-fail/overflowing-lsh-3.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to shift left with overflow' // compile-flags: -C debug-assertions -#![warn(exceeding_bitshifts)] +#![warn(arithmetic_overflow)] #![warn(const_err)] fn main() { diff --git a/src/test/run-fail/overflowing-lsh-4.rs b/src/test/run-fail/overflowing-lsh-4.rs index ec304b4144e..0d3912ce13f 100644 --- a/src/test/run-fail/overflowing-lsh-4.rs +++ b/src/test/run-fail/overflowing-lsh-4.rs @@ -4,7 +4,7 @@ // This function is checking that our automatic truncation does not // sidestep the overflow checking. -#![warn(exceeding_bitshifts)] +#![warn(arithmetic_overflow)] #![warn(const_err)] fn main() { diff --git a/src/test/run-fail/overflowing-mul.rs b/src/test/run-fail/overflowing-mul.rs index ef191c01586..2dfc9bb5ae4 100644 --- a/src/test/run-fail/overflowing-mul.rs +++ b/src/test/run-fail/overflowing-mul.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to multiply with overflow' // compile-flags: -C debug-assertions -#![allow(overflow)] +#![allow(arithmetic_overflow)] fn main() { let x = 200u8 * 4; diff --git a/src/test/run-fail/overflowing-neg.rs b/src/test/run-fail/overflowing-neg.rs index 443cddf53fb..f512aa35bed 100644 --- a/src/test/run-fail/overflowing-neg.rs +++ b/src/test/run-fail/overflowing-neg.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to negate with overflow' // compile-flags: -C debug-assertions -#![allow(overflow)] +#![allow(arithmetic_overflow)] fn main() { let _x = -std::i8::MIN; diff --git a/src/test/run-fail/overflowing-rsh-1.rs b/src/test/run-fail/overflowing-rsh-1.rs index 14514540c06..4592b2b6260 100644 --- a/src/test/run-fail/overflowing-rsh-1.rs +++ b/src/test/run-fail/overflowing-rsh-1.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to shift right with overflow' // compile-flags: -C debug-assertions -#![warn(exceeding_bitshifts)] +#![warn(arithmetic_overflow)] #![warn(const_err)] fn main() { diff --git a/src/test/run-fail/overflowing-rsh-2.rs b/src/test/run-fail/overflowing-rsh-2.rs index 83dcbd13d2a..066267b770d 100644 --- a/src/test/run-fail/overflowing-rsh-2.rs +++ b/src/test/run-fail/overflowing-rsh-2.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to shift right with overflow' // compile-flags: -C debug-assertions -#![warn(exceeding_bitshifts)] +#![warn(arithmetic_overflow)] #![warn(const_err)] fn main() { diff --git a/src/test/run-fail/overflowing-rsh-3.rs b/src/test/run-fail/overflowing-rsh-3.rs index 3521c050659..67e78482866 100644 --- a/src/test/run-fail/overflowing-rsh-3.rs +++ b/src/test/run-fail/overflowing-rsh-3.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to shift right with overflow' // compile-flags: -C debug-assertions -#![warn(exceeding_bitshifts)] +#![warn(arithmetic_overflow)] #![warn(const_err)] fn main() { diff --git a/src/test/run-fail/overflowing-rsh-4.rs b/src/test/run-fail/overflowing-rsh-4.rs index ed1191849e5..1877d5c9685 100644 --- a/src/test/run-fail/overflowing-rsh-4.rs +++ b/src/test/run-fail/overflowing-rsh-4.rs @@ -4,7 +4,7 @@ // This function is checking that our (type-based) automatic // truncation does not sidestep the overflow checking. -#![warn(exceeding_bitshifts)] +#![warn(arithmetic_overflow)] #![warn(const_err)] fn main() { diff --git a/src/test/run-fail/overflowing-rsh-5.rs b/src/test/run-fail/overflowing-rsh-5.rs index 58dfc5710ae..20ef324a82a 100644 --- a/src/test/run-fail/overflowing-rsh-5.rs +++ b/src/test/run-fail/overflowing-rsh-5.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to shift right with overflow' // compile-flags: -C debug-assertions -#![warn(exceeding_bitshifts)] +#![warn(arithmetic_overflow)] #![warn(const_err)] fn main() { diff --git a/src/test/run-fail/overflowing-rsh-6.rs b/src/test/run-fail/overflowing-rsh-6.rs index c2fec5e4860..589a98bab04 100644 --- a/src/test/run-fail/overflowing-rsh-6.rs +++ b/src/test/run-fail/overflowing-rsh-6.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to shift right with overflow' // compile-flags: -C debug-assertions -#![warn(exceeding_bitshifts)] +#![warn(arithmetic_overflow)] #![warn(const_err)] #![feature(const_indexing)] diff --git a/src/test/run-fail/overflowing-sub.rs b/src/test/run-fail/overflowing-sub.rs index 4f4a3eed8cc..fb096c31957 100644 --- a/src/test/run-fail/overflowing-sub.rs +++ b/src/test/run-fail/overflowing-sub.rs @@ -1,7 +1,7 @@ // error-pattern:thread 'main' panicked at 'attempt to subtract with overflow' // compile-flags: -C debug-assertions -#![allow(overflow)] +#![allow(arithmetic_overflow)] fn main() { let _x = 42u8 - (42u8 + 1); diff --git a/src/test/run-fail/promoted_div_by_zero.rs b/src/test/run-fail/promoted_div_by_zero.rs index 0ad081f0314..dc6719ce025 100644 --- a/src/test/run-fail/promoted_div_by_zero.rs +++ b/src/test/run-fail/promoted_div_by_zero.rs @@ -1,4 +1,4 @@ -#![allow(panic, const_err)] +#![allow(unconditional_panic, const_err)] // error-pattern: attempt to divide by zero diff --git a/src/test/run-fail/promoted_overflow.rs b/src/test/run-fail/promoted_overflow.rs index a90f832ddd0..3c42da4b1d8 100644 --- a/src/test/run-fail/promoted_overflow.rs +++ b/src/test/run-fail/promoted_overflow.rs @@ -1,4 +1,4 @@ -#![allow(overflow)] +#![allow(arithmetic_overflow)] // error-pattern: overflow // compile-flags: -C overflow-checks=yes diff --git a/src/test/ui/consts/array-literal-index-oob.rs b/src/test/ui/consts/array-literal-index-oob.rs index 978f2333101..492afa9372c 100644 --- a/src/test/ui/consts/array-literal-index-oob.rs +++ b/src/test/ui/consts/array-literal-index-oob.rs @@ -1,7 +1,7 @@ // build-pass // ignore-pass (emit codegen-time warnings and verify that they are indeed warnings and not errors) -#![warn(const_err, panic)] +#![warn(const_err, unconditional_panic)] fn main() { &{ [1, 2, 3][4] }; diff --git a/src/test/ui/consts/array-literal-index-oob.stderr b/src/test/ui/consts/array-literal-index-oob.stderr index 605cd73db1f..6e0e7fedb7b 100644 --- a/src/test/ui/consts/array-literal-index-oob.stderr +++ b/src/test/ui/consts/array-literal-index-oob.stderr @@ -7,8 +7,8 @@ LL | &{ [1, 2, 3][4] }; note: the lint level is defined here --> $DIR/array-literal-index-oob.rs:4:20 | -LL | #![warn(const_err, panic)] - | ^^^^^ +LL | #![warn(const_err, unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ warning: reaching this expression at runtime will panic or abort --> $DIR/array-literal-index-oob.rs:7:8 @@ -21,7 +21,7 @@ LL | &{ [1, 2, 3][4] }; note: the lint level is defined here --> $DIR/array-literal-index-oob.rs:4:9 | -LL | #![warn(const_err, panic)] +LL | #![warn(const_err, unconditional_panic)] | ^^^^^^^^^ warning: erroneous constant used diff --git a/src/test/ui/consts/const-err.rs b/src/test/ui/consts/const-err.rs index b204f705a96..d1c5f4f3f32 100644 --- a/src/test/ui/consts/const-err.rs +++ b/src/test/ui/consts/const-err.rs @@ -1,7 +1,7 @@ // build-fail // compile-flags: -Zforce-overflow-checks=on -#![allow(exceeding_bitshifts)] +#![allow(arithmetic_overflow)] #![warn(const_err)] fn black_box(_: T) { diff --git a/src/test/ui/consts/const-err2.default.stderr b/src/test/ui/consts/const-err2.default.stderr index 226874c29da..5aeeec4bd14 100644 --- a/src/test/ui/consts/const-err2.default.stderr +++ b/src/test/ui/consts/const-err2.default.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | let a = -std::i8::MIN; | ^^^^^^^^^^^^^ attempt to negate with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/const-err2.rs:21:18 @@ -42,7 +42,7 @@ error: this operation will panic at runtime LL | let _e = [5u8][1]; | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: aborting due to 7 previous errors diff --git a/src/test/ui/consts/const-err2.noopt.stderr b/src/test/ui/consts/const-err2.noopt.stderr index 226874c29da..5aeeec4bd14 100644 --- a/src/test/ui/consts/const-err2.noopt.stderr +++ b/src/test/ui/consts/const-err2.noopt.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | let a = -std::i8::MIN; | ^^^^^^^^^^^^^ attempt to negate with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/const-err2.rs:21:18 @@ -42,7 +42,7 @@ error: this operation will panic at runtime LL | let _e = [5u8][1]; | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: aborting due to 7 previous errors diff --git a/src/test/ui/consts/const-err2.opt.stderr b/src/test/ui/consts/const-err2.opt.stderr index 226874c29da..5aeeec4bd14 100644 --- a/src/test/ui/consts/const-err2.opt.stderr +++ b/src/test/ui/consts/const-err2.opt.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | let a = -std::i8::MIN; | ^^^^^^^^^^^^^ attempt to negate with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/const-err2.rs:21:18 @@ -42,7 +42,7 @@ error: this operation will panic at runtime LL | let _e = [5u8][1]; | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: aborting due to 7 previous errors diff --git a/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr b/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr index 226874c29da..5aeeec4bd14 100644 --- a/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr +++ b/src/test/ui/consts/const-err2.opt_with_overflow_checks.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | let a = -std::i8::MIN; | ^^^^^^^^^^^^^ attempt to negate with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/const-err2.rs:21:18 @@ -42,7 +42,7 @@ error: this operation will panic at runtime LL | let _e = [5u8][1]; | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: aborting due to 7 previous errors diff --git a/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.stderr b/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.stderr index 5da802d30f5..4188efd021d 100644 --- a/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.stderr +++ b/src/test/ui/consts/const-eval/index_out_of_bounds_propagated.stderr @@ -4,7 +4,7 @@ error: this operation will panic at runtime LL | array[1]; | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: aborting due to previous error diff --git a/src/test/ui/consts/const-eval/promoted_errors.default.stderr b/src/test/ui/consts/const-eval/promoted_errors.default.stderr index 8f21ce53715..034dea06568 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.default.stderr +++ b/src/test/ui/consts/const-eval/promoted_errors.default.stderr @@ -7,8 +7,8 @@ LL | let _x = 0u32 - 1; note: the lint level is defined here --> $DIR/promoted_errors.rs:9:20 | -LL | #![warn(const_err, overflow, panic)] - | ^^^^^^^^ +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:16:20 @@ -17,10 +17,10 @@ LL | println!("{}", 1 / (1 - 1)); | ^^^^^^^^^^^ attempt to divide by zero | note: the lint level is defined here - --> $DIR/promoted_errors.rs:9:30 + --> $DIR/promoted_errors.rs:9:41 | -LL | #![warn(const_err, overflow, panic)] - | ^^^^^ +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ warning: reaching this expression at runtime will panic or abort --> $DIR/promoted_errors.rs:16:20 @@ -31,7 +31,7 @@ LL | println!("{}", 1 / (1 - 1)); note: the lint level is defined here --> $DIR/promoted_errors.rs:9:9 | -LL | #![warn(const_err, overflow, panic)] +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] | ^^^^^^^^^ warning: erroneous constant used diff --git a/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr b/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr index 1ed60c1f96e..94c1593240b 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr +++ b/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr @@ -7,8 +7,8 @@ LL | println!("{}", 0u32 - 1); note: the lint level is defined here --> $DIR/promoted_errors.rs:9:20 | -LL | #![warn(const_err, overflow, panic)] - | ^^^^^^^^ +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ warning: this arithmetic operation will overflow --> $DIR/promoted_errors.rs:14:14 @@ -23,10 +23,10 @@ LL | println!("{}", 1 / (1 - 1)); | ^^^^^^^^^^^ attempt to divide by zero | note: the lint level is defined here - --> $DIR/promoted_errors.rs:9:30 + --> $DIR/promoted_errors.rs:9:41 | -LL | #![warn(const_err, overflow, panic)] - | ^^^^^ +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ warning: reaching this expression at runtime will panic or abort --> $DIR/promoted_errors.rs:16:20 @@ -37,7 +37,7 @@ LL | println!("{}", 1 / (1 - 1)); note: the lint level is defined here --> $DIR/promoted_errors.rs:9:9 | -LL | #![warn(const_err, overflow, panic)] +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] | ^^^^^^^^^ warning: erroneous constant used diff --git a/src/test/ui/consts/const-eval/promoted_errors.opt.stderr b/src/test/ui/consts/const-eval/promoted_errors.opt.stderr index 8f21ce53715..034dea06568 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.opt.stderr +++ b/src/test/ui/consts/const-eval/promoted_errors.opt.stderr @@ -7,8 +7,8 @@ LL | let _x = 0u32 - 1; note: the lint level is defined here --> $DIR/promoted_errors.rs:9:20 | -LL | #![warn(const_err, overflow, panic)] - | ^^^^^^^^ +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ warning: this operation will panic at runtime --> $DIR/promoted_errors.rs:16:20 @@ -17,10 +17,10 @@ LL | println!("{}", 1 / (1 - 1)); | ^^^^^^^^^^^ attempt to divide by zero | note: the lint level is defined here - --> $DIR/promoted_errors.rs:9:30 + --> $DIR/promoted_errors.rs:9:41 | -LL | #![warn(const_err, overflow, panic)] - | ^^^^^ +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ warning: reaching this expression at runtime will panic or abort --> $DIR/promoted_errors.rs:16:20 @@ -31,7 +31,7 @@ LL | println!("{}", 1 / (1 - 1)); note: the lint level is defined here --> $DIR/promoted_errors.rs:9:9 | -LL | #![warn(const_err, overflow, panic)] +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] | ^^^^^^^^^ warning: erroneous constant used diff --git a/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr b/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr index 1ed60c1f96e..94c1593240b 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr +++ b/src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr @@ -7,8 +7,8 @@ LL | println!("{}", 0u32 - 1); note: the lint level is defined here --> $DIR/promoted_errors.rs:9:20 | -LL | #![warn(const_err, overflow, panic)] - | ^^^^^^^^ +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ warning: this arithmetic operation will overflow --> $DIR/promoted_errors.rs:14:14 @@ -23,10 +23,10 @@ LL | println!("{}", 1 / (1 - 1)); | ^^^^^^^^^^^ attempt to divide by zero | note: the lint level is defined here - --> $DIR/promoted_errors.rs:9:30 + --> $DIR/promoted_errors.rs:9:41 | -LL | #![warn(const_err, overflow, panic)] - | ^^^^^ +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ warning: reaching this expression at runtime will panic or abort --> $DIR/promoted_errors.rs:16:20 @@ -37,7 +37,7 @@ LL | println!("{}", 1 / (1 - 1)); note: the lint level is defined here --> $DIR/promoted_errors.rs:9:9 | -LL | #![warn(const_err, overflow, panic)] +LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] | ^^^^^^^^^ warning: erroneous constant used diff --git a/src/test/ui/consts/const-eval/promoted_errors.rs b/src/test/ui/consts/const-eval/promoted_errors.rs index 3133e9b380b..b734f70f9f0 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.rs +++ b/src/test/ui/consts/const-eval/promoted_errors.rs @@ -6,23 +6,23 @@ // build-pass // ignore-pass (emit codegen-time warnings and verify that they are indeed warnings and not errors) -#![warn(const_err, overflow, panic)] +#![warn(const_err, arithmetic_overflow, unconditional_panic)] fn main() { println!("{}", 0u32 - 1); - //[opt_with_overflow_checks,noopt]~^ WARN [overflow] + //[opt_with_overflow_checks,noopt]~^ WARN [arithmetic_overflow] let _x = 0u32 - 1; - //~^ WARN [overflow] + //~^ WARN [arithmetic_overflow] println!("{}", 1 / (1 - 1)); - //~^ WARN [panic] + //~^ WARN [unconditional_panic] //~| WARN panic or abort [const_err] //~| WARN erroneous constant used [const_err] let _x = 1 / (1 - 1); - //~^ WARN [panic] + //~^ WARN [unconditional_panic] println!("{}", 1 / (false as u32)); - //~^ WARN [panic] + //~^ WARN [unconditional_panic] //~| WARN panic or abort [const_err] //~| WARN erroneous constant used [const_err] let _x = 1 / (false as u32); - //~^ WARN [panic] + //~^ WARN [unconditional_panic] } diff --git a/src/test/ui/consts/const-prop-ice.stderr b/src/test/ui/consts/const-prop-ice.stderr index 855b9e6b64b..7bb4acb235a 100644 --- a/src/test/ui/consts/const-prop-ice.stderr +++ b/src/test/ui/consts/const-prop-ice.stderr @@ -4,7 +4,7 @@ error: this operation will panic at runtime LL | [0; 3][3u64 as usize]; | ^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the len is 3 but the index is 3 | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: aborting due to previous error diff --git a/src/test/ui/consts/const-prop-ice2.stderr b/src/test/ui/consts/const-prop-ice2.stderr index 07faa39edc2..73405eca340 100644 --- a/src/test/ui/consts/const-prop-ice2.stderr +++ b/src/test/ui/consts/const-prop-ice2.stderr @@ -4,7 +4,7 @@ error: this operation will panic at runtime LL | println!("{}", xs[Enum::One as usize]); | ^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the len is 1 but the index is 1 | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: aborting due to previous error diff --git a/src/test/ui/consts/issue-69020.default.stderr b/src/test/ui/consts/issue-69020.default.stderr index 1b1987f4dc3..c48a106ef46 100644 --- a/src/test/ui/consts/issue-69020.default.stderr +++ b/src/test/ui/consts/issue-69020.default.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | const NEG: i32 = -i32::MIN + T::NEG; | ^^^^^^^^^ attempt to negate with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/issue-69020.rs:23:22 @@ -18,7 +18,7 @@ error: this operation will panic at runtime LL | const DIV: i32 = (1/0) + T::DIV; | ^^^^^ attempt to divide by zero | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime --> $DIR/issue-69020.rs:27:22 diff --git a/src/test/ui/consts/issue-69020.noopt.stderr b/src/test/ui/consts/issue-69020.noopt.stderr index 1b1987f4dc3..c48a106ef46 100644 --- a/src/test/ui/consts/issue-69020.noopt.stderr +++ b/src/test/ui/consts/issue-69020.noopt.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | const NEG: i32 = -i32::MIN + T::NEG; | ^^^^^^^^^ attempt to negate with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/issue-69020.rs:23:22 @@ -18,7 +18,7 @@ error: this operation will panic at runtime LL | const DIV: i32 = (1/0) + T::DIV; | ^^^^^ attempt to divide by zero | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime --> $DIR/issue-69020.rs:27:22 diff --git a/src/test/ui/consts/issue-69020.opt.stderr b/src/test/ui/consts/issue-69020.opt.stderr index 1b1987f4dc3..c48a106ef46 100644 --- a/src/test/ui/consts/issue-69020.opt.stderr +++ b/src/test/ui/consts/issue-69020.opt.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | const NEG: i32 = -i32::MIN + T::NEG; | ^^^^^^^^^ attempt to negate with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/issue-69020.rs:23:22 @@ -18,7 +18,7 @@ error: this operation will panic at runtime LL | const DIV: i32 = (1/0) + T::DIV; | ^^^^^ attempt to divide by zero | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime --> $DIR/issue-69020.rs:27:22 diff --git a/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr b/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr index 1b1987f4dc3..c48a106ef46 100644 --- a/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr +++ b/src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | const NEG: i32 = -i32::MIN + T::NEG; | ^^^^^^^^^ attempt to negate with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/issue-69020.rs:23:22 @@ -18,7 +18,7 @@ error: this operation will panic at runtime LL | const DIV: i32 = (1/0) + T::DIV; | ^^^^^ attempt to divide by zero | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime --> $DIR/issue-69020.rs:27:22 diff --git a/src/test/ui/huge-array-simple-64.rs b/src/test/ui/huge-array-simple-64.rs index d4c93301283..02c961fc5fa 100644 --- a/src/test/ui/huge-array-simple-64.rs +++ b/src/test/ui/huge-array-simple-64.rs @@ -4,7 +4,7 @@ // FIXME https://github.com/rust-lang/rust/issues/59774 // normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" // normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" -#![allow(exceeding_bitshifts)] +#![allow(arithmetic_overflow)] fn main() { let _fat: [u8; (1<<61)+(1<<31)] = //~ ERROR too big for the current architecture diff --git a/src/test/ui/issues/issue-54348.stderr b/src/test/ui/issues/issue-54348.stderr index f2156a35f2a..6b67125e36c 100644 --- a/src/test/ui/issues/issue-54348.stderr +++ b/src/test/ui/issues/issue-54348.stderr @@ -4,7 +4,7 @@ error: this operation will panic at runtime LL | [1][1.5 as usize]; | ^^^^^^^^^^^^^^^^^ index out of bounds: the len is 1 but the index is 1 | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime --> $DIR/issue-54348.rs:6:5 diff --git a/src/test/ui/issues/issue-8460-const.default.stderr b/src/test/ui/issues/issue-8460-const.default.stderr index 33d846e3e91..3556ec08247 100644 --- a/src/test/ui/issues/issue-8460-const.default.stderr +++ b/src/test/ui/issues/issue-8460-const.default.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); | ^^^^^^^^^^^^^^^ attempt to divide with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:16:36 @@ -42,7 +42,7 @@ error: this operation will panic at runtime LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); | ^^^^^^^^^^ attempt to divide by zero | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:28:36 diff --git a/src/test/ui/issues/issue-8460-const.noopt.stderr b/src/test/ui/issues/issue-8460-const.noopt.stderr index 33d846e3e91..3556ec08247 100644 --- a/src/test/ui/issues/issue-8460-const.noopt.stderr +++ b/src/test/ui/issues/issue-8460-const.noopt.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); | ^^^^^^^^^^^^^^^ attempt to divide with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:16:36 @@ -42,7 +42,7 @@ error: this operation will panic at runtime LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); | ^^^^^^^^^^ attempt to divide by zero | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:28:36 diff --git a/src/test/ui/issues/issue-8460-const.opt.stderr b/src/test/ui/issues/issue-8460-const.opt.stderr index 33d846e3e91..3556ec08247 100644 --- a/src/test/ui/issues/issue-8460-const.opt.stderr +++ b/src/test/ui/issues/issue-8460-const.opt.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); | ^^^^^^^^^^^^^^^ attempt to divide with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:16:36 @@ -42,7 +42,7 @@ error: this operation will panic at runtime LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); | ^^^^^^^^^^ attempt to divide by zero | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:28:36 diff --git a/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr b/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr index 33d846e3e91..3556ec08247 100644 --- a/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr +++ b/src/test/ui/issues/issue-8460-const.opt_with_overflow_checks.stderr @@ -4,7 +4,7 @@ error: this arithmetic operation will overflow LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); | ^^^^^^^^^^^^^^^ attempt to divide with overflow | - = note: `#[deny(overflow)]` on by default + = note: `#[deny(arithmetic_overflow)]` on by default error: this arithmetic operation will overflow --> $DIR/issue-8460-const.rs:16:36 @@ -42,7 +42,7 @@ error: this operation will panic at runtime LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); | ^^^^^^^^^^ attempt to divide by zero | - = note: `#[deny(panic)]` on by default + = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime --> $DIR/issue-8460-const.rs:28:36 diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.default.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.default.stderr index 5e32466c4e0..ce9b02b6d82 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.default.stderr +++ b/src/test/ui/lint/lint-exceeding-bitshifts.default.stderr @@ -7,7 +7,7 @@ LL | let _ = x << 42; note: the lint level is defined here --> $DIR/lint-exceeding-bitshifts.rs:9:9 | -LL | #![deny(exceeding_bitshifts, const_err)] +LL | #![deny(arithmetic_overflow, const_err)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr index 5e32466c4e0..ce9b02b6d82 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr +++ b/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr @@ -7,7 +7,7 @@ LL | let _ = x << 42; note: the lint level is defined here --> $DIR/lint-exceeding-bitshifts.rs:9:9 | -LL | #![deny(exceeding_bitshifts, const_err)] +LL | #![deny(arithmetic_overflow, const_err)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr index 5e32466c4e0..ce9b02b6d82 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr +++ b/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr @@ -7,7 +7,7 @@ LL | let _ = x << 42; note: the lint level is defined here --> $DIR/lint-exceeding-bitshifts.rs:9:9 | -LL | #![deny(exceeding_bitshifts, const_err)] +LL | #![deny(arithmetic_overflow, const_err)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr index 5e32466c4e0..ce9b02b6d82 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr +++ b/src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr @@ -7,7 +7,7 @@ LL | let _ = x << 42; note: the lint level is defined here --> $DIR/lint-exceeding-bitshifts.rs:9:9 | -LL | #![deny(exceeding_bitshifts, const_err)] +LL | #![deny(arithmetic_overflow, const_err)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.rs b/src/test/ui/lint/lint-exceeding-bitshifts.rs index 3c6d70e7a6f..04996e41bb3 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.rs +++ b/src/test/ui/lint/lint-exceeding-bitshifts.rs @@ -6,7 +6,7 @@ // build-fail #![crate_type="lib"] -#![deny(exceeding_bitshifts, const_err)] +#![deny(arithmetic_overflow, const_err)] #![allow(unused_variables)] #![allow(dead_code)] From 58bb47ebe5db54f54f5a45134110f73ff216bb36 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Feb 2020 11:25:41 +0100 Subject: [PATCH 16/21] avoid excessive number of revisions --- src/test/ui/consts/const-err2.default.stderr | 48 ------ src/test/ui/consts/const-err2.rs | 2 +- .../const-eval/promoted_errors.default.stderr | 72 --------- .../ui/consts/const-eval/promoted_errors.rs | 2 +- src/test/ui/consts/issue-64059.rs | 2 +- src/test/ui/consts/issue-69020.default.stderr | 30 ---- src/test/ui/consts/issue-69020.rs | 2 +- .../ui/issues/issue-8460-const.default.stderr | 150 ------------------ src/test/ui/issues/issue-8460-const.rs | 2 +- .../lint-exceeding-bitshifts.default.stderr | 146 ----------------- src/test/ui/lint/lint-exceeding-bitshifts.rs | 2 +- 11 files changed, 6 insertions(+), 452 deletions(-) delete mode 100644 src/test/ui/consts/const-err2.default.stderr delete mode 100644 src/test/ui/consts/const-eval/promoted_errors.default.stderr delete mode 100644 src/test/ui/consts/issue-69020.default.stderr delete mode 100644 src/test/ui/issues/issue-8460-const.default.stderr delete mode 100644 src/test/ui/lint/lint-exceeding-bitshifts.default.stderr diff --git a/src/test/ui/consts/const-err2.default.stderr b/src/test/ui/consts/const-err2.default.stderr deleted file mode 100644 index 5aeeec4bd14..00000000000 --- a/src/test/ui/consts/const-err2.default.stderr +++ /dev/null @@ -1,48 +0,0 @@ -error: this arithmetic operation will overflow - --> $DIR/const-err2.rs:19:13 - | -LL | let a = -std::i8::MIN; - | ^^^^^^^^^^^^^ attempt to negate with overflow - | - = note: `#[deny(arithmetic_overflow)]` on by default - -error: this arithmetic operation will overflow - --> $DIR/const-err2.rs:21:18 - | -LL | let a_i128 = -std::i128::MIN; - | ^^^^^^^^^^^^^^^ attempt to negate with overflow - -error: this arithmetic operation will overflow - --> $DIR/const-err2.rs:23:13 - | -LL | let b = 200u8 + 200u8 + 200u8; - | ^^^^^^^^^^^^^ attempt to add with overflow - -error: this arithmetic operation will overflow - --> $DIR/const-err2.rs:25:18 - | -LL | let b_i128 = std::i128::MIN - std::i128::MAX; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to subtract with overflow - -error: this arithmetic operation will overflow - --> $DIR/const-err2.rs:27:13 - | -LL | let c = 200u8 * 4; - | ^^^^^^^^^ attempt to multiply with overflow - -error: this arithmetic operation will overflow - --> $DIR/const-err2.rs:29:13 - | -LL | let d = 42u8 - (42u8 + 1); - | ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow - -error: this operation will panic at runtime - --> $DIR/const-err2.rs:31:14 - | -LL | let _e = [5u8][1]; - | ^^^^^^^^ index out of bounds: the len is 1 but the index is 1 - | - = note: `#[deny(unconditional_panic)]` on by default - -error: aborting due to 7 previous errors - diff --git a/src/test/ui/consts/const-err2.rs b/src/test/ui/consts/const-err2.rs index 2c0cae0e451..2c6a987180b 100644 --- a/src/test/ui/consts/const-err2.rs +++ b/src/test/ui/consts/const-err2.rs @@ -2,7 +2,7 @@ // optimized compilation and unoptimized compilation and thus would // lead to different lints being emitted -// revisions: default noopt opt opt_with_overflow_checks +// revisions: noopt opt opt_with_overflow_checks //[noopt]compile-flags: -C opt-level=0 //[opt]compile-flags: -O //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O diff --git a/src/test/ui/consts/const-eval/promoted_errors.default.stderr b/src/test/ui/consts/const-eval/promoted_errors.default.stderr deleted file mode 100644 index 034dea06568..00000000000 --- a/src/test/ui/consts/const-eval/promoted_errors.default.stderr +++ /dev/null @@ -1,72 +0,0 @@ -warning: this arithmetic operation will overflow - --> $DIR/promoted_errors.rs:14:14 - | -LL | let _x = 0u32 - 1; - | ^^^^^^^^ attempt to subtract with overflow - | -note: the lint level is defined here - --> $DIR/promoted_errors.rs:9:20 - | -LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] - | ^^^^^^^^^^^^^^^^^^^ - -warning: this operation will panic at runtime - --> $DIR/promoted_errors.rs:16:20 - | -LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ attempt to divide by zero - | -note: the lint level is defined here - --> $DIR/promoted_errors.rs:9:41 - | -LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] - | ^^^^^^^^^^^^^^^^^^^ - -warning: reaching this expression at runtime will panic or abort - --> $DIR/promoted_errors.rs:16:20 - | -LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ dividing by zero - | -note: the lint level is defined here - --> $DIR/promoted_errors.rs:9:9 - | -LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)] - | ^^^^^^^^^ - -warning: erroneous constant used - --> $DIR/promoted_errors.rs:16:20 - | -LL | println!("{}", 1 / (1 - 1)); - | ^^^^^^^^^^^ referenced constant has errors - -warning: this operation will panic at runtime - --> $DIR/promoted_errors.rs:20:14 - | -LL | let _x = 1 / (1 - 1); - | ^^^^^^^^^^^ attempt to divide by zero - -warning: this operation will panic at runtime - --> $DIR/promoted_errors.rs:22:20 - | -LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero - -warning: reaching this expression at runtime will panic or abort - --> $DIR/promoted_errors.rs:22:20 - | -LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ dividing by zero - -warning: erroneous constant used - --> $DIR/promoted_errors.rs:22:20 - | -LL | println!("{}", 1 / (false as u32)); - | ^^^^^^^^^^^^^^^^^^ referenced constant has errors - -warning: this operation will panic at runtime - --> $DIR/promoted_errors.rs:26:14 - | -LL | let _x = 1 / (false as u32); - | ^^^^^^^^^^^^^^^^^^ attempt to divide by zero - diff --git a/src/test/ui/consts/const-eval/promoted_errors.rs b/src/test/ui/consts/const-eval/promoted_errors.rs index b734f70f9f0..3ab6ce28478 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.rs +++ b/src/test/ui/consts/const-eval/promoted_errors.rs @@ -1,4 +1,4 @@ -// revisions: default noopt opt opt_with_overflow_checks +// revisions: noopt opt opt_with_overflow_checks //[noopt]compile-flags: -C opt-level=0 //[opt]compile-flags: -O //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O diff --git a/src/test/ui/consts/issue-64059.rs b/src/test/ui/consts/issue-64059.rs index 16bfda3b961..02c8b725032 100644 --- a/src/test/ui/consts/issue-64059.rs +++ b/src/test/ui/consts/issue-64059.rs @@ -1,4 +1,4 @@ -// revisions: default noopt opt opt_with_overflow_checks +// revisions: noopt opt opt_with_overflow_checks //[noopt]compile-flags: -C opt-level=0 //[opt]compile-flags: -O //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O diff --git a/src/test/ui/consts/issue-69020.default.stderr b/src/test/ui/consts/issue-69020.default.stderr deleted file mode 100644 index c48a106ef46..00000000000 --- a/src/test/ui/consts/issue-69020.default.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:21:22 - | -LL | const NEG: i32 = -i32::MIN + T::NEG; - | ^^^^^^^^^ attempt to negate with overflow - | - = note: `#[deny(arithmetic_overflow)]` on by default - -error: this arithmetic operation will overflow - --> $DIR/issue-69020.rs:23:22 - | -LL | const ADD: i32 = (i32::MAX+1) + T::ADD; - | ^^^^^^^^^^^^ attempt to add with overflow - -error: this operation will panic at runtime - --> $DIR/issue-69020.rs:25:22 - | -LL | const DIV: i32 = (1/0) + T::DIV; - | ^^^^^ attempt to divide by zero - | - = note: `#[deny(unconditional_panic)]` on by default - -error: this operation will panic at runtime - --> $DIR/issue-69020.rs:27:22 - | -LL | const OOB: i32 = [1][1] + T::OOB; - | ^^^^^^ index out of bounds: the len is 1 but the index is 1 - -error: aborting due to 4 previous errors - diff --git a/src/test/ui/consts/issue-69020.rs b/src/test/ui/consts/issue-69020.rs index 963ab01a33c..e079feb04d4 100644 --- a/src/test/ui/consts/issue-69020.rs +++ b/src/test/ui/consts/issue-69020.rs @@ -1,4 +1,4 @@ -// revisions: default noopt opt opt_with_overflow_checks +// revisions: noopt opt opt_with_overflow_checks //[noopt]compile-flags: -C opt-level=0 //[opt]compile-flags: -O //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O diff --git a/src/test/ui/issues/issue-8460-const.default.stderr b/src/test/ui/issues/issue-8460-const.default.stderr deleted file mode 100644 index 3556ec08247..00000000000 --- a/src/test/ui/issues/issue-8460-const.default.stderr +++ /dev/null @@ -1,150 +0,0 @@ -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:14:36 - | -LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ attempt to divide with overflow - | - = note: `#[deny(arithmetic_overflow)]` on by default - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:16:36 - | -LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^ attempt to divide with overflow - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:18:36 - | -LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:20:36 - | -LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:22:36 - | -LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to divide with overflow - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:24:36 - | -LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ attempt to divide with overflow - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:26:36 - | -LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err()); - | ^^^^^^^^^^ attempt to divide by zero - | - = note: `#[deny(unconditional_panic)]` on by default - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:28:36 - | -LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); - | ^^^^^^^ attempt to divide by zero - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:30:36 - | -LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:32:36 - | -LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:34:36 - | -LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); - | ^^^^^^^^ attempt to divide by zero - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:36:36 - | -LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err()); - | ^^^^^^^^^ attempt to divide by zero - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:38:36 - | -LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:40:36 - | -LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:42:36 - | -LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:44:36 - | -LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:46:36 - | -LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: this arithmetic operation will overflow - --> $DIR/issue-8460-const.rs:48:36 - | -LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err()); - | ^^^^^^^^^^^^^^ attempt to calculate the remainder with overflow - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:50:36 - | -LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err()); - | ^^^^^^^^^^ attempt to calculate the remainder with a divisor of zero - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:52:36 - | -LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); - | ^^^^^^^ attempt to calculate the remainder with a divisor of zero - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:54:36 - | -LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:56:36 - | -LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:58:36 - | -LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); - | ^^^^^^^^ attempt to calculate the remainder with a divisor of zero - -error: this operation will panic at runtime - --> $DIR/issue-8460-const.rs:60:36 - | -LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err()); - | ^^^^^^^^^ attempt to calculate the remainder with a divisor of zero - -error: aborting due to 24 previous errors - diff --git a/src/test/ui/issues/issue-8460-const.rs b/src/test/ui/issues/issue-8460-const.rs index d7276af40a7..53005e46d2f 100644 --- a/src/test/ui/issues/issue-8460-const.rs +++ b/src/test/ui/issues/issue-8460-const.rs @@ -1,4 +1,4 @@ -// revisions: default noopt opt opt_with_overflow_checks +// revisions: noopt opt opt_with_overflow_checks //[noopt]compile-flags: -C opt-level=0 //[opt]compile-flags: -O //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.default.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.default.stderr deleted file mode 100644 index ce9b02b6d82..00000000000 --- a/src/test/ui/lint/lint-exceeding-bitshifts.default.stderr +++ /dev/null @@ -1,146 +0,0 @@ -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:22:13 - | -LL | let _ = x << 42; - | ^^^^^^^ attempt to shift left with overflow - | -note: the lint level is defined here - --> $DIR/lint-exceeding-bitshifts.rs:9:9 - | -LL | #![deny(arithmetic_overflow, const_err)] - | ^^^^^^^^^^^^^^^^^^^ - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:27:15 - | -LL | let n = 1u8 << 8; - | ^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:29:15 - | -LL | let n = 1u16 << 16; - | ^^^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:31:15 - | -LL | let n = 1u32 << 32; - | ^^^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:33:15 - | -LL | let n = 1u64 << 64; - | ^^^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:35:15 - | -LL | let n = 1i8 << 8; - | ^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:37:15 - | -LL | let n = 1i16 << 16; - | ^^^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:39:15 - | -LL | let n = 1i32 << 32; - | ^^^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:41:15 - | -LL | let n = 1i64 << 64; - | ^^^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:44:15 - | -LL | let n = 1u8 >> 8; - | ^^^^^^^^ attempt to shift right with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:46:15 - | -LL | let n = 1u16 >> 16; - | ^^^^^^^^^^ attempt to shift right with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:48:15 - | -LL | let n = 1u32 >> 32; - | ^^^^^^^^^^ attempt to shift right with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:50:15 - | -LL | let n = 1u64 >> 64; - | ^^^^^^^^^^ attempt to shift right with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:52:15 - | -LL | let n = 1i8 >> 8; - | ^^^^^^^^ attempt to shift right with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:54:15 - | -LL | let n = 1i16 >> 16; - | ^^^^^^^^^^ attempt to shift right with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:56:15 - | -LL | let n = 1i32 >> 32; - | ^^^^^^^^^^ attempt to shift right with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:58:15 - | -LL | let n = 1i64 >> 64; - | ^^^^^^^^^^ attempt to shift right with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:62:15 - | -LL | let n = n << 8; - | ^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:64:15 - | -LL | let n = 1u8 << -8; - | ^^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:69:15 - | -LL | let n = 1u8 << (4+4); - | ^^^^^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:71:15 - | -LL | let n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:77:15 - | -LL | let n = 1_isize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left with overflow - -error: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:78:15 - | -LL | let n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left with overflow - -error: aborting due to 23 previous errors - diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.rs b/src/test/ui/lint/lint-exceeding-bitshifts.rs index 04996e41bb3..7deee5320a8 100644 --- a/src/test/ui/lint/lint-exceeding-bitshifts.rs +++ b/src/test/ui/lint/lint-exceeding-bitshifts.rs @@ -1,4 +1,4 @@ -// revisions: default noopt opt opt_with_overflow_checks +// revisions: noopt opt opt_with_overflow_checks //[noopt]compile-flags: -C opt-level=0 //[opt]compile-flags: -O //[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O From 88d14bfbc986802601d2414ea5d6322e0056917b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 19 Feb 2020 20:12:01 +0100 Subject: [PATCH 17/21] fix 32bit-only test --- src/test/ui/huge-array-simple-32.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/huge-array-simple-32.rs b/src/test/ui/huge-array-simple-32.rs index 3e574dfa07b..2290e3d5e76 100644 --- a/src/test/ui/huge-array-simple-32.rs +++ b/src/test/ui/huge-array-simple-32.rs @@ -4,7 +4,7 @@ // FIXME https://github.com/rust-lang/rust/issues/59774 // normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" // normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" -#![allow(exceeding_bitshifts)] +#![allow(arithmetic_overflow)] fn main() { let _fat: [u8; (1<<31)+(1<<15)] = //~ ERROR too big for the current architecture From c816430f9901b93aa7895a789685f012d7043697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 19 Feb 2020 18:04:03 -0800 Subject: [PATCH 18/21] Tweak binding lifetime suggestion text We already have a structured suggestion, but the wording made it seem like that wasn't the case. Fix #65286. r? @varkor --- .../infer/error_reporting/mod.rs | 22 ++++++++++--------- .../builtin-superkinds-self-type.stderr | 2 +- ...-infer_static_outlives_requirements.stderr | 2 +- .../must_outlive_least_region_or_bound.stderr | 2 +- .../type_parameters_captured.stderr | 2 +- .../lifetime-doesnt-live-long-enough.stderr | 10 ++++----- .../regions-close-object-into-object-5.stderr | 14 ++++++------ ...regions-close-over-type-parameter-1.stderr | 8 +++---- .../regions-close-param-into-object.stderr | 8 +++---- .../ui/regions/regions-enum-not-wf.stderr | 8 +++---- ...ons-implied-bounds-projection-gap-1.stderr | 2 +- .../regions-infer-bound-from-trait.stderr | 4 ++-- .../dont-infer-static.stderr | 2 +- .../regions-enum-not-wf.stderr | 8 +++---- .../regions-struct-not-wf.stderr | 4 ++-- .../suggest-impl-trait-lifetime.fixed | 2 +- .../suggest-impl-trait-lifetime.rs | 2 +- .../suggest-impl-trait-lifetime.stderr | 7 +++--- ...eric_type_does_not_live_long_enough.stderr | 2 +- .../wf/wf-impl-associated-type-region.stderr | 2 +- src/test/ui/wf/wf-in-fn-type-static.stderr | 4 ++-- src/test/ui/wf/wf-in-obj-type-static.stderr | 2 +- .../wf/wf-outlives-ty-in-fn-or-trait.stderr | 4 ++-- 23 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/librustc_infer/infer/error_reporting/mod.rs b/src/librustc_infer/infer/error_reporting/mod.rs index 77119b8618f..1ed890962da 100644 --- a/src/librustc_infer/infer/error_reporting/mod.rs +++ b/src/librustc_infer/infer/error_reporting/mod.rs @@ -1781,14 +1781,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { bound_kind: GenericKind<'tcx>, sub: S, ) { - let consider = format!( - "consider adding an explicit lifetime bound {}", - if type_param_span.map(|(_, _, is_impl_trait)| is_impl_trait).unwrap_or(false) { - format!(" `{}` to `{}`...", sub, bound_kind) - } else { - format!("`{}: {}`...", bound_kind, sub) - }, - ); + let msg = "consider adding an explicit lifetime bound"; if let Some((sp, has_lifetimes, is_impl_trait)) = type_param_span { let suggestion = if is_impl_trait { format!("{} + {}", bound_kind, sub) @@ -1796,13 +1789,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let tail = if has_lifetimes { " + " } else { "" }; format!("{}: {}{}", bound_kind, sub, tail) }; - err.span_suggestion_short( + err.span_suggestion( sp, - &consider, + &format!("{}...", msg), suggestion, Applicability::MaybeIncorrect, // Issue #41966 ); } else { + let consider = format!( + "{} {}...", + msg, + if type_param_span.map(|(_, _, is_impl_trait)| is_impl_trait).unwrap_or(false) { + format!(" `{}` to `{}`", sub, bound_kind) + } else { + format!("`{}: {}`", bound_kind, sub) + }, + ); err.help(&consider); } } diff --git a/src/test/ui/builtin-superkinds/builtin-superkinds-self-type.stderr b/src/test/ui/builtin-superkinds/builtin-superkinds-self-type.stderr index 2fdb3836dd9..999a5839ba6 100644 --- a/src/test/ui/builtin-superkinds/builtin-superkinds-self-type.stderr +++ b/src/test/ui/builtin-superkinds/builtin-superkinds-self-type.stderr @@ -4,7 +4,7 @@ error[E0310]: the parameter type `T` may not live long enough LL | impl Foo for T { } | -- ^^^ | | - | help: consider adding an explicit lifetime bound `T: 'static`... + | help: consider adding an explicit lifetime bound...: `T: 'static +` | note: ...so that the type `T` will meet its required lifetime bounds --> $DIR/builtin-superkinds-self-type.rs:10:16 diff --git a/src/test/ui/feature-gates/feature-gate-infer_static_outlives_requirements.stderr b/src/test/ui/feature-gates/feature-gate-infer_static_outlives_requirements.stderr index 689a3757343..fbc4e8abc42 100644 --- a/src/test/ui/feature-gates/feature-gate-infer_static_outlives_requirements.stderr +++ b/src/test/ui/feature-gates/feature-gate-infer_static_outlives_requirements.stderr @@ -2,7 +2,7 @@ error[E0310]: the parameter type `U` may not live long enough --> $DIR/feature-gate-infer_static_outlives_requirements.rs:5:5 | LL | struct Foo { - | - help: consider adding an explicit lifetime bound `U: 'static`... + | - help: consider adding an explicit lifetime bound...: `U: 'static` LL | bar: Bar | ^^^^^^^^^^^ | diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr index 7f92e709af5..cffa5ee8f14 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr @@ -67,7 +67,7 @@ error[E0310]: the parameter type `T` may not live long enough LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { | -- ^^^^^^^^^^^^^^^^^^^^ | | - | help: consider adding an explicit lifetime bound `T: 'static`... + | help: consider adding an explicit lifetime bound...: `T: 'static +` | note: ...so that the type `T` will meet its required lifetime bounds --> $DIR/must_outlive_least_region_or_bound.rs:22:51 diff --git a/src/test/ui/impl-trait/type_parameters_captured.stderr b/src/test/ui/impl-trait/type_parameters_captured.stderr index 708b479ab17..34f0f7f1d73 100644 --- a/src/test/ui/impl-trait/type_parameters_captured.stderr +++ b/src/test/ui/impl-trait/type_parameters_captured.stderr @@ -4,7 +4,7 @@ error[E0310]: the parameter type `T` may not live long enough LL | fn foo(x: T) -> impl Any + 'static { | - ^^^^^^^^^^^^^^^^^^ | | - | help: consider adding an explicit lifetime bound `T: 'static`... + | help: consider adding an explicit lifetime bound...: `T: 'static` | note: ...so that the type `T` will meet its required lifetime bounds --> $DIR/type_parameters_captured.rs:7:20 diff --git a/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr b/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr index 4e50064efb4..e60c461743c 100644 --- a/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr +++ b/src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.stderr @@ -2,7 +2,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/lifetime-doesnt-live-long-enough.rs:19:5 | LL | struct Foo { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | foo: &'static T | ^^^^^^^^^^^^^^^ | @@ -16,7 +16,7 @@ error[E0309]: the parameter type `K` may not live long enough --> $DIR/lifetime-doesnt-live-long-enough.rs:24:19 | LL | trait X: Sized { - | - help: consider adding an explicit lifetime bound `K: 'a`... + | - help: consider adding an explicit lifetime bound...: `K: 'a` LL | fn foo<'a, L: X<&'a Nested>>(); | ^^^^^^^^^^^^^^^^ | @@ -45,7 +45,7 @@ error[E0309]: the parameter type `L` may not live long enough LL | fn baz<'a, L, M: X<&'a Nested>>() { | - ^^^^^^^^^^^^^^^^ | | - | help: consider adding an explicit lifetime bound `L: 'a`... + | help: consider adding an explicit lifetime bound...: `L: 'a` | note: ...so that the reference type `&'a Nested` does not outlive the data it points at --> $DIR/lifetime-doesnt-live-long-enough.rs:32:22 @@ -57,7 +57,7 @@ error[E0309]: the parameter type `K` may not live long enough --> $DIR/lifetime-doesnt-live-long-enough.rs:41:33 | LL | impl Nested { - | - help: consider adding an explicit lifetime bound `K: 'a`... + | - help: consider adding an explicit lifetime bound...: `K: 'a` LL | fn generic_in_parent<'a, L: X<&'a Nested>>() { | ^^^^^^^^^^^^^^^^ | @@ -71,7 +71,7 @@ error[E0309]: the parameter type `M` may not live long enough --> $DIR/lifetime-doesnt-live-long-enough.rs:44:36 | LL | fn generic_in_child<'a, 'b, L: X<&'a Nested>, M: 'b>() { - | ^^^^^^^^^^^^^^^^ -- help: consider adding an explicit lifetime bound `M: 'a`... + | ^^^^^^^^^^^^^^^^ -- help: consider adding an explicit lifetime bound...: `M: 'a +` | note: ...so that the reference type `&'a Nested` does not outlive the data it points at --> $DIR/lifetime-doesnt-live-long-enough.rs:44:36 diff --git a/src/test/ui/regions/regions-close-object-into-object-5.stderr b/src/test/ui/regions/regions-close-object-into-object-5.stderr index 7c530cec7c3..14727000b2c 100644 --- a/src/test/ui/regions/regions-close-object-into-object-5.stderr +++ b/src/test/ui/regions/regions-close-object-into-object-5.stderr @@ -2,7 +2,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:5 | LL | fn f<'a, T, U>(v: Box+'static>) -> Box { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | // oh dear! LL | box B(&*v) as Box | ^^^^^^^^^^ @@ -17,7 +17,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:5 | LL | fn f<'a, T, U>(v: Box+'static>) -> Box { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | // oh dear! LL | box B(&*v) as Box | ^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:9 | LL | fn f<'a, T, U>(v: Box+'static>) -> Box { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | // oh dear! LL | box B(&*v) as Box | ^ @@ -47,7 +47,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:9 | LL | fn f<'a, T, U>(v: Box+'static>) -> Box { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | // oh dear! LL | box B(&*v) as Box | ^^^^^^ @@ -62,7 +62,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:11 | LL | fn f<'a, T, U>(v: Box+'static>) -> Box { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | // oh dear! LL | box B(&*v) as Box | ^^^ @@ -77,7 +77,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:11 | LL | fn f<'a, T, U>(v: Box+'static>) -> Box { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | // oh dear! LL | box B(&*v) as Box | ^^^ @@ -92,7 +92,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-object-into-object-5.rs:17:11 | LL | fn f<'a, T, U>(v: Box+'static>) -> Box { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | // oh dear! LL | box B(&*v) as Box | ^^^ diff --git a/src/test/ui/regions/regions-close-over-type-parameter-1.stderr b/src/test/ui/regions/regions-close-over-type-parameter-1.stderr index 81534b7b770..ed9a604e717 100644 --- a/src/test/ui/regions/regions-close-over-type-parameter-1.stderr +++ b/src/test/ui/regions/regions-close-over-type-parameter-1.stderr @@ -2,7 +2,7 @@ error[E0310]: the parameter type `A` may not live long enough --> $DIR/regions-close-over-type-parameter-1.rs:10:5 | LL | fn make_object1(v: A) -> Box { - | -- help: consider adding an explicit lifetime bound `A: 'static`... + | -- help: consider adding an explicit lifetime bound...: `A: 'static +` LL | box v as Box | ^^^^^ | @@ -16,7 +16,7 @@ error[E0310]: the parameter type `A` may not live long enough --> $DIR/regions-close-over-type-parameter-1.rs:10:5 | LL | fn make_object1(v: A) -> Box { - | -- help: consider adding an explicit lifetime bound `A: 'static`... + | -- help: consider adding an explicit lifetime bound...: `A: 'static +` LL | box v as Box | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | @@ -30,7 +30,7 @@ error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-close-over-type-parameter-1.rs:20:5 | LL | fn make_object3<'a,'b,A:SomeTrait+'a>(v: A) -> Box { - | -- help: consider adding an explicit lifetime bound `A: 'b`... + | -- help: consider adding an explicit lifetime bound...: `A: 'b +` LL | box v as Box | ^^^^^ | @@ -44,7 +44,7 @@ error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-close-over-type-parameter-1.rs:20:5 | LL | fn make_object3<'a,'b,A:SomeTrait+'a>(v: A) -> Box { - | -- help: consider adding an explicit lifetime bound `A: 'b`... + | -- help: consider adding an explicit lifetime bound...: `A: 'b +` LL | box v as Box | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | diff --git a/src/test/ui/regions/regions-close-param-into-object.stderr b/src/test/ui/regions/regions-close-param-into-object.stderr index 7f2c646c121..3b1a89d9ced 100644 --- a/src/test/ui/regions/regions-close-param-into-object.stderr +++ b/src/test/ui/regions/regions-close-param-into-object.stderr @@ -2,7 +2,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:6:5 | LL | fn p1(v: T) -> Box - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` ... LL | Box::new(v) | ^^^^^^^^^^^ @@ -17,7 +17,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:12:5 | LL | fn p2(v: Box) -> Box - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` ... LL | Box::new(v) | ^^^^^^^^^^^ @@ -32,7 +32,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:18:5 | LL | fn p3<'a,T>(v: T) -> Box - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` ... LL | Box::new(v) | ^^^^^^^^^^^ @@ -47,7 +47,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-close-param-into-object.rs:24:5 | LL | fn p4<'a,T>(v: Box) -> Box - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` ... LL | Box::new(v) | ^^^^^^^^^^^ diff --git a/src/test/ui/regions/regions-enum-not-wf.stderr b/src/test/ui/regions/regions-enum-not-wf.stderr index 87014085667..297fcb088d2 100644 --- a/src/test/ui/regions/regions-enum-not-wf.stderr +++ b/src/test/ui/regions/regions-enum-not-wf.stderr @@ -2,7 +2,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-enum-not-wf.rs:18:18 | LL | enum Ref1<'a, T> { - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | Ref1Variant1(RequireOutlives<'a, T>) | ^^^^^^^^^^^^^^^^^^^^^^ | @@ -16,7 +16,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-enum-not-wf.rs:23:25 | LL | enum Ref2<'a, T> { - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | Ref2Variant1, LL | Ref2Variant2(isize, RequireOutlives<'a, T>), | ^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-enum-not-wf.rs:35:1 | LL | enum RefDouble<'a, 'b, T> { - | ^ - help: consider adding an explicit lifetime bound `T: 'b`... + | ^ - help: consider adding an explicit lifetime bound...: `T: 'b` | _| | | LL | | RefDoubleVariant1(&'a RequireOutlives<'b, T>) @@ -52,7 +52,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-enum-not-wf.rs:36:23 | LL | enum RefDouble<'a, 'b, T> { - | - help: consider adding an explicit lifetime bound `T: 'b`... + | - help: consider adding an explicit lifetime bound...: `T: 'b` LL | RefDoubleVariant1(&'a RequireOutlives<'b, T>) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | diff --git a/src/test/ui/regions/regions-implied-bounds-projection-gap-1.stderr b/src/test/ui/regions/regions-implied-bounds-projection-gap-1.stderr index 7fbc1622c3a..2f1a4cea8e9 100644 --- a/src/test/ui/regions/regions-implied-bounds-projection-gap-1.stderr +++ b/src/test/ui/regions/regions-implied-bounds-projection-gap-1.stderr @@ -2,7 +2,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-implied-bounds-projection-gap-1.rs:16:10 | LL | fn func<'x, T:Trait1<'x>>(t: &'x T::Foo) - | -- help: consider adding an explicit lifetime bound `T: 'x`... + | -- help: consider adding an explicit lifetime bound...: `T: 'x +` LL | { LL | wf::<&'x T>(); | ^^^^^ diff --git a/src/test/ui/regions/regions-infer-bound-from-trait.stderr b/src/test/ui/regions/regions-infer-bound-from-trait.stderr index 382d932e81a..a5a0ff52fac 100644 --- a/src/test/ui/regions/regions-infer-bound-from-trait.stderr +++ b/src/test/ui/regions/regions-infer-bound-from-trait.stderr @@ -2,7 +2,7 @@ error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-infer-bound-from-trait.rs:33:5 | LL | fn bar1<'a,A>(x: Inv<'a>, a: A) { - | - help: consider adding an explicit lifetime bound `A: 'a`... + | - help: consider adding an explicit lifetime bound...: `A: 'a` LL | check_bound(x, a) | ^^^^^^^^^^^ | @@ -16,7 +16,7 @@ error[E0309]: the parameter type `A` may not live long enough --> $DIR/regions-infer-bound-from-trait.rs:37:5 | LL | fn bar2<'a,'b,A:Is<'b>>(x: Inv<'a>, y: Inv<'b>, a: A) { - | -- help: consider adding an explicit lifetime bound `A: 'a`... + | -- help: consider adding an explicit lifetime bound...: `A: 'a +` LL | check_bound(x, a) | ^^^^^^^^^^^ | diff --git a/src/test/ui/rfc-2093-infer-outlives/dont-infer-static.stderr b/src/test/ui/rfc-2093-infer-outlives/dont-infer-static.stderr index b049d8a4ab3..c3cfc5a4d97 100644 --- a/src/test/ui/rfc-2093-infer-outlives/dont-infer-static.stderr +++ b/src/test/ui/rfc-2093-infer-outlives/dont-infer-static.stderr @@ -2,7 +2,7 @@ error[E0310]: the parameter type `U` may not live long enough --> $DIR/dont-infer-static.rs:8:5 | LL | struct Foo { - | - help: consider adding an explicit lifetime bound `U: 'static`... + | - help: consider adding an explicit lifetime bound...: `U: 'static` LL | bar: Bar | ^^^^^^^^^^^ | diff --git a/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.stderr b/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.stderr index 87014085667..297fcb088d2 100644 --- a/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.stderr +++ b/src/test/ui/rfc-2093-infer-outlives/regions-enum-not-wf.stderr @@ -2,7 +2,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-enum-not-wf.rs:18:18 | LL | enum Ref1<'a, T> { - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | Ref1Variant1(RequireOutlives<'a, T>) | ^^^^^^^^^^^^^^^^^^^^^^ | @@ -16,7 +16,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-enum-not-wf.rs:23:25 | LL | enum Ref2<'a, T> { - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | Ref2Variant1, LL | Ref2Variant2(isize, RequireOutlives<'a, T>), | ^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-enum-not-wf.rs:35:1 | LL | enum RefDouble<'a, 'b, T> { - | ^ - help: consider adding an explicit lifetime bound `T: 'b`... + | ^ - help: consider adding an explicit lifetime bound...: `T: 'b` | _| | | LL | | RefDoubleVariant1(&'a RequireOutlives<'b, T>) @@ -52,7 +52,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-enum-not-wf.rs:36:23 | LL | enum RefDouble<'a, 'b, T> { - | - help: consider adding an explicit lifetime bound `T: 'b`... + | - help: consider adding an explicit lifetime bound...: `T: 'b` LL | RefDoubleVariant1(&'a RequireOutlives<'b, T>) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | diff --git a/src/test/ui/rfc-2093-infer-outlives/regions-struct-not-wf.stderr b/src/test/ui/rfc-2093-infer-outlives/regions-struct-not-wf.stderr index 825c1015c51..f6658891fa6 100644 --- a/src/test/ui/rfc-2093-infer-outlives/regions-struct-not-wf.stderr +++ b/src/test/ui/rfc-2093-infer-outlives/regions-struct-not-wf.stderr @@ -2,7 +2,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-struct-not-wf.rs:13:5 | LL | impl<'a, T> Trait<'a, T> for usize { - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | type Out = &'a T; | ^^^^^^^^^^^^^^^^^ | @@ -16,7 +16,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/regions-struct-not-wf.rs:21:5 | LL | impl<'a, T> Trait<'a, T> for u32 { - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | type Out = RefOk<'a, T>; | ^^^^^^^^^^^^^^^^^^^^^^^^ | diff --git a/src/test/ui/suggestions/suggest-impl-trait-lifetime.fixed b/src/test/ui/suggestions/suggest-impl-trait-lifetime.fixed index 8592af1262e..589ee1a474a 100644 --- a/src/test/ui/suggestions/suggest-impl-trait-lifetime.fixed +++ b/src/test/ui/suggestions/suggest-impl-trait-lifetime.fixed @@ -3,7 +3,7 @@ use std::fmt::Debug; fn foo(d: impl Debug + 'static) { -//~^ HELP consider adding an explicit lifetime bound `'static` to `impl Debug` +//~^ HELP consider adding an explicit lifetime bound... bar(d); //~^ ERROR the parameter type `impl Debug` may not live long enough //~| NOTE ...so that the type `impl Debug` will meet its required lifetime bounds diff --git a/src/test/ui/suggestions/suggest-impl-trait-lifetime.rs b/src/test/ui/suggestions/suggest-impl-trait-lifetime.rs index c67d78ea4c7..9a87129fbf2 100644 --- a/src/test/ui/suggestions/suggest-impl-trait-lifetime.rs +++ b/src/test/ui/suggestions/suggest-impl-trait-lifetime.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; fn foo(d: impl Debug) { -//~^ HELP consider adding an explicit lifetime bound `'static` to `impl Debug` +//~^ HELP consider adding an explicit lifetime bound... bar(d); //~^ ERROR the parameter type `impl Debug` may not live long enough //~| NOTE ...so that the type `impl Debug` will meet its required lifetime bounds diff --git a/src/test/ui/suggestions/suggest-impl-trait-lifetime.stderr b/src/test/ui/suggestions/suggest-impl-trait-lifetime.stderr index cba231d0e86..b6e6c0bbf32 100644 --- a/src/test/ui/suggestions/suggest-impl-trait-lifetime.stderr +++ b/src/test/ui/suggestions/suggest-impl-trait-lifetime.stderr @@ -1,6 +1,9 @@ error[E0310]: the parameter type `impl Debug` may not live long enough --> $DIR/suggest-impl-trait-lifetime.rs:7:5 | +LL | fn foo(d: impl Debug) { + | ---------- help: consider adding an explicit lifetime bound...: `impl Debug + 'static` +LL | LL | bar(d); | ^^^ | @@ -9,10 +12,6 @@ note: ...so that the type `impl Debug` will meet its required lifetime bounds | LL | bar(d); | ^^^ -help: consider adding an explicit lifetime bound `'static` to `impl Debug`... - | -LL | fn foo(d: impl Debug + 'static) { - | ^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr index 5a7f9d74eba..22e2391f838 100644 --- a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr @@ -25,7 +25,7 @@ LL | type WrongGeneric = impl 'static; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | fn wrong_generic(t: T) -> WrongGeneric { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` | note: ...so that the type `T` will meet its required lifetime bounds --> $DIR/generic_type_does_not_live_long_enough.rs:9:1 diff --git a/src/test/ui/wf/wf-impl-associated-type-region.stderr b/src/test/ui/wf/wf-impl-associated-type-region.stderr index 9cc36025305..9942c80effe 100644 --- a/src/test/ui/wf/wf-impl-associated-type-region.stderr +++ b/src/test/ui/wf/wf-impl-associated-type-region.stderr @@ -2,7 +2,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/wf-impl-associated-type-region.rs:10:5 | LL | impl<'a, T> Foo<'a> for T { - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | type Bar = &'a T; | ^^^^^^^^^^^^^^^^^ | diff --git a/src/test/ui/wf/wf-in-fn-type-static.stderr b/src/test/ui/wf/wf-in-fn-type-static.stderr index 8952c78aacd..7dc8f5a9661 100644 --- a/src/test/ui/wf/wf-in-fn-type-static.stderr +++ b/src/test/ui/wf/wf-in-fn-type-static.stderr @@ -2,7 +2,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/wf-in-fn-type-static.rs:13:5 | LL | struct Foo { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | // needs T: 'static LL | x: fn() -> &'static T | ^^^^^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/wf-in-fn-type-static.rs:18:5 | LL | struct Bar { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | // needs T: Copy LL | x: fn(&'static T) | ^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/wf/wf-in-obj-type-static.stderr b/src/test/ui/wf/wf-in-obj-type-static.stderr index c461da76a25..32c3198d55b 100644 --- a/src/test/ui/wf/wf-in-obj-type-static.stderr +++ b/src/test/ui/wf/wf-in-obj-type-static.stderr @@ -2,7 +2,7 @@ error[E0310]: the parameter type `T` may not live long enough --> $DIR/wf-in-obj-type-static.rs:14:5 | LL | struct Foo { - | - help: consider adding an explicit lifetime bound `T: 'static`... + | - help: consider adding an explicit lifetime bound...: `T: 'static` LL | // needs T: 'static LL | x: dyn Object<&'static T> | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/wf/wf-outlives-ty-in-fn-or-trait.stderr b/src/test/ui/wf/wf-outlives-ty-in-fn-or-trait.stderr index f1cf514e6b2..52786fb3bca 100644 --- a/src/test/ui/wf/wf-outlives-ty-in-fn-or-trait.stderr +++ b/src/test/ui/wf/wf-outlives-ty-in-fn-or-trait.stderr @@ -2,7 +2,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/wf-outlives-ty-in-fn-or-trait.rs:9:5 | LL | impl<'a, T> Trait<'a, T> for usize { - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | type Out = &'a fn(T); | ^^^^^^^^^^^^^^^^^^^^^ | @@ -16,7 +16,7 @@ error[E0309]: the parameter type `T` may not live long enough --> $DIR/wf-outlives-ty-in-fn-or-trait.rs:19:5 | LL | impl<'a, T> Trait<'a, T> for u32 { - | - help: consider adding an explicit lifetime bound `T: 'a`... + | - help: consider adding an explicit lifetime bound...: `T: 'a` LL | type Out = &'a dyn Baz; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | From a6b5f875c1cb3a77200c6f3da3d7df0601f90173 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 20 Feb 2020 14:26:43 +0100 Subject: [PATCH 19/21] clean up E0321 explanation --- src/librustc_error_codes/error_codes/E0321.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_error_codes/error_codes/E0321.md b/src/librustc_error_codes/error_codes/E0321.md index 49cec94430b..bfcdabfe9de 100644 --- a/src/librustc_error_codes/error_codes/E0321.md +++ b/src/librustc_error_codes/error_codes/E0321.md @@ -1,5 +1,7 @@ A cross-crate opt-out trait was implemented on something which wasn't a struct -or enum type. Erroneous code example: +or enum type. + +Erroneous code example: ```compile_fail,E0321 #![feature(optin_builtin_traits)] From 90ebf93bdfe2acdaeb504a24dea27fbfd74e3218 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 20 Feb 2020 14:26:56 +0100 Subject: [PATCH 20/21] Greatly improve E0322 explanation --- src/librustc_error_codes/error_codes/E0322.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/librustc_error_codes/error_codes/E0322.md b/src/librustc_error_codes/error_codes/E0322.md index d2ee426763e..ccef8681dd6 100644 --- a/src/librustc_error_codes/error_codes/E0322.md +++ b/src/librustc_error_codes/error_codes/E0322.md @@ -1,3 +1,13 @@ +The `Sized` trait was implemented explicitly. + +Erroneous code example: + +```compile_fail,E0322 +struct Foo; + +impl Sized for Foo {} // error! +``` + The `Sized` trait is a special trait built-in to the compiler for types with a constant size known at compile-time. This trait is automatically implemented for types as needed by the compiler, and it is currently disallowed to From 8e793ed649a2770211f1a61e7bc6c9119decc991 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 20 Feb 2020 17:20:31 +0100 Subject: [PATCH 21/21] Fix broken link to the rustc guide --- src/librustc_passes/region.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_passes/region.rs b/src/librustc_passes/region.rs index e79ca5c78d6..d0f49fdcc75 100644 --- a/src/librustc_passes/region.rs +++ b/src/librustc_passes/region.rs @@ -4,7 +4,7 @@ //! For more information about how MIR-based region-checking works, //! see the [rustc guide]. //! -//! [rustc guide]: https://rust-lang.github.io/rustc-guide/mir/borrowck.html +//! [rustc guide]: https://rust-lang.github.io/rustc-guide/borrow_check.html use rustc::hir::map::Map; use rustc::middle::region::*;