From 062e1e5225f0750ef776f11d0ea75bbf29e3a82c Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 14 Feb 2024 14:17:27 +0000 Subject: [PATCH 1/2] errors: only eagerly translate subdiagnostics Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). Signed-off-by: David Wood --- src/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 7f91af59d5..ed401d5751 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -504,7 +504,7 @@ pub fn report_msg<'tcx>( let is_local = machine.is_local(frame_info); // No span for non-local frames and the first frame (which is the error site). if is_local && idx > 0 { - err.eager_subdiagnostic(err.dcx, frame_info.as_note(machine.tcx)); + err.subdiagnostic(err.dcx, frame_info.as_note(machine.tcx)); } else { let sm = sess.source_map(); let span = sm.span_to_embeddable_string(frame_info.span); From 5b1a186c38381818c870c9c88964565a0e9d4f5b Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Sat, 17 Feb 2024 10:44:46 +0530 Subject: [PATCH 2/2] Enable `ConstPropLint` for promoteds This fixes the issue wherein the lint didn't fire for promoteds in the case of SHL/SHR operators in non-optimized builds and all arithmetic operators in optimized builds --- tests/pass/overflow_checks_off.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/pass/overflow_checks_off.rs b/tests/pass/overflow_checks_off.rs index 79aa510ef9..7b9d4f8fff 100644 --- a/tests/pass/overflow_checks_off.rs +++ b/tests/pass/overflow_checks_off.rs @@ -1,12 +1,17 @@ //@compile-flags: -C overflow-checks=off // Check that we correctly implement the intended behavior of these operators -// when they are not being overflow-checked. +// when they are not being overflow-checked at runtime. // FIXME: if we call the functions in `std::ops`, we still get the panics. // Miri does not implement the codegen-time hack that backs `#[rustc_inherit_overflow_checks]`. // use std::ops::*; + +// Disable _compile-time_ overflow linting +// so that we can test runtime overflow checks + #![allow(arithmetic_overflow)] + fn main() { assert_eq!(-{ -0x80i8 }, -0x80);