diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index b1b6f10e0fe2c..d7690a96e10de 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -254,8 +254,9 @@ where always_export_generics, ); - // We can't differentiate something that got inlined. + // We can't differentiate a function that got inlined. let autodiff_active = cfg!(llvm_enzyme) + && matches!(mono_item, MonoItem::Fn(_)) && cx .tcx .codegen_fn_attrs(mono_item.def_id()) diff --git a/compiler/rustc_session/src/code_stats.rs b/compiler/rustc_session/src/code_stats.rs index 6b18d450e9e5e..80603b4a1567f 100644 --- a/compiler/rustc_session/src/code_stats.rs +++ b/compiler/rustc_session/src/code_stats.rs @@ -72,6 +72,8 @@ pub struct TypeSizeInfo { #[derive(Default)] pub struct CodeStats { + /// The hash set that actually holds all the type size information. + /// The field is public for use in external tools. See #139876. pub type_sizes: Lock>, } diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 4ac45172a0e1c..7551ac5aa9735 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -77,7 +77,15 @@ impl<'tcx> At<'_, 'tcx> { .into_value_registering_obligations(self.infcx, &mut *fulfill_cx); let errors = fulfill_cx.select_all_or_error(self.infcx); let value = self.infcx.resolve_vars_if_possible(value); - if errors.is_empty() { Ok(value) } else { Err(errors) } + if errors.is_empty() { + Ok(value) + } else { + // Drop pending obligations, since deep normalization may happen + // in a loop and we don't want to trigger the assertion on the next + // iteration due to pending ambiguous obligations we've left over. + let _ = fulfill_cx.collect_remaining_errors(self.infcx); + Err(errors) + } } } } diff --git a/library/core/src/any.rs b/library/core/src/any.rs index 10f2a11d558be..7aa3f3c6d7434 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -772,8 +772,8 @@ impl hash::Hash for TypeId { // (especially given the previous point about the lower 64 bits being // high quality on their own). // - It is correct to do so -- only hashing a subset of `self` is still - // with an `Eq` implementation that considers the entire value, as - // ours does. + // compatible with an `Eq` implementation that considers the entire + // value, as ours does. self.t.1.hash(state); } } diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index 3a22a16cb165e..9737b2f5bfe60 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -46,7 +46,7 @@ macro_rules! rtprintpanic { macro_rules! rtabort { ($($t:tt)*) => { { - rtprintpanic!("fatal runtime error: {}\n", format_args!($($t)*)); + rtprintpanic!("fatal runtime error: {}, aborting\n", format_args!($($t)*)); crate::sys::abort_internal(); } } diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs index d5a5d10205dd8..7cd448733130d 100644 --- a/library/std/src/thread/local.rs +++ b/library/std/src/thread/local.rs @@ -22,12 +22,16 @@ use crate::fmt; /// /// Initialization is dynamically performed on the first call to a setter (e.g. /// [`with`]) within a thread, and values that implement [`Drop`] get -/// destructed when a thread exits. Some caveats apply, which are explained below. +/// destructed when a thread exits. Some platform-specific caveats apply, which +/// are explained below. +/// Note that, should the destructor panics, the whole process will be [aborted]. /// /// A `LocalKey`'s initializer cannot recursively depend on itself. Using a /// `LocalKey` in this way may cause panics, aborts or infinite recursion on /// the first call to `with`. /// +/// [aborted]: crate::process::abort +/// /// # Single-thread Synchronization /// /// Though there is no potential race with other threads, it is still possible to diff --git a/library/std/src/time.rs b/library/std/src/time.rs index 5ab71413586dc..03af35e809c91 100644 --- a/library/std/src/time.rs +++ b/library/std/src/time.rs @@ -205,8 +205,8 @@ pub struct Instant(time::Instant); /// println!("{}", elapsed.as_secs()); /// } /// Err(e) => { -/// // an error occurred! -/// println!("Error: {e:?}"); +/// // the system clock went backwards! +/// println!("Great Scott! {e:?}"); /// } /// } /// } @@ -245,6 +245,7 @@ pub struct Instant(time::Instant); /// > structure cannot represent the new point in time. /// /// [`add`]: SystemTime::add +/// [`UNIX_EPOCH`]: SystemTime::UNIX_EPOCH #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[stable(feature = "time2", since = "1.8.0")] pub struct SystemTime(time::SystemTime); diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index d11f5c1a3a6f4..cc09463c358a7 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1395,14 +1395,6 @@ impl<'test> TestCx<'test> { matches!(self.config.suite.as_str(), "rustdoc-ui" | "rustdoc-js" | "rustdoc-json") } - fn get_mir_dump_dir(&self) -> Utf8PathBuf { - let mut mir_dump_dir = self.config.build_test_suite_root.clone(); - debug!("input_file: {}", self.testpaths.file); - mir_dump_dir.push(&self.testpaths.relative_dir); - mir_dump_dir.push(self.testpaths.file.file_stem().unwrap()); - mir_dump_dir - } - fn make_compile_args( &self, input_file: &Utf8Path, @@ -1511,10 +1503,7 @@ impl<'test> TestCx<'test> { } let set_mir_dump_dir = |rustc: &mut Command| { - let mir_dump_dir = self.get_mir_dump_dir(); - remove_and_create_dir_all(&mir_dump_dir).unwrap_or_else(|e| { - panic!("failed to remove and recreate output directory `{mir_dump_dir}`: {e}") - }); + let mir_dump_dir = self.output_base_dir(); let mut dir_opt = "-Zdump-mir-dir=".to_string(); dir_opt.push_str(mir_dump_dir.as_str()); debug!("dir_opt: {:?}", dir_opt); diff --git a/src/tools/compiletest/src/runtest/mir_opt.rs b/src/tools/compiletest/src/runtest/mir_opt.rs index ded6a68fe5876..efdb131bf14a8 100644 --- a/src/tools/compiletest/src/runtest/mir_opt.rs +++ b/src/tools/compiletest/src/runtest/mir_opt.rs @@ -56,7 +56,7 @@ impl TestCx<'_> { self.diff_mir_files(from_file.into(), after.into()) } else { let mut output_file = Utf8PathBuf::new(); - output_file.push(self.get_mir_dump_dir()); + output_file.push(self.output_base_dir()); output_file.push(&from_file); debug!("comparing the contents of: {} with {:?}", output_file, expected_file); if !output_file.exists() { @@ -100,7 +100,7 @@ impl TestCx<'_> { fn diff_mir_files(&self, before: Utf8PathBuf, after: Utf8PathBuf) -> String { let to_full_path = |path: Utf8PathBuf| { - let full = self.get_mir_dump_dir().join(&path); + let full = self.output_base_dir().join(&path); if !full.exists() { panic!( "the mir dump file for {} does not exist (requested in {})", diff --git a/src/tools/miri/tests/fail/panic/tls_macro_const_drop_panic.stderr b/src/tools/miri/tests/fail/panic/tls_macro_const_drop_panic.stderr index aadb9976609c3..1dcdb4a399680 100644 --- a/src/tools/miri/tests/fail/panic/tls_macro_const_drop_panic.stderr +++ b/src/tools/miri/tests/fail/panic/tls_macro_const_drop_panic.stderr @@ -1,7 +1,7 @@ thread $NAME panicked at tests/fail/panic/tls_macro_const_drop_panic.rs:LL:CC: ow -fatal runtime error: thread local panicked on drop +fatal runtime error: thread local panicked on drop, aborting error: abnormal termination: the program aborted execution error: aborting due to 1 previous error diff --git a/src/tools/miri/tests/fail/panic/tls_macro_drop_panic.stderr b/src/tools/miri/tests/fail/panic/tls_macro_drop_panic.stderr index 546ee7e1ed214..7e4907abd9336 100644 --- a/src/tools/miri/tests/fail/panic/tls_macro_drop_panic.stderr +++ b/src/tools/miri/tests/fail/panic/tls_macro_drop_panic.stderr @@ -1,7 +1,7 @@ thread $NAME panicked at tests/fail/panic/tls_macro_drop_panic.rs:LL:CC: ow -fatal runtime error: thread local panicked on drop +fatal runtime error: thread local panicked on drop, aborting error: abnormal termination: the program aborted execution error: aborting due to 1 previous error diff --git a/tests/crashes/133868.rs b/tests/crashes/133868.rs deleted file mode 100644 index dc25cb9df288e..0000000000000 --- a/tests/crashes/133868.rs +++ /dev/null @@ -1,13 +0,0 @@ -//@ known-bug: #133868 - -trait Foo { - type Assoc; -} - -trait Bar { - fn method() -> impl Sized; -} -impl Bar for T where ::Assoc: Sized -{ - fn method() {} -} diff --git a/tests/ui/writing-to-immutable-vec.rs b/tests/ui/borrowck/writing-to-immutable-vec.rs similarity index 100% rename from tests/ui/writing-to-immutable-vec.rs rename to tests/ui/borrowck/writing-to-immutable-vec.rs diff --git a/tests/ui/writing-to-immutable-vec.stderr b/tests/ui/borrowck/writing-to-immutable-vec.stderr similarity index 100% rename from tests/ui/writing-to-immutable-vec.stderr rename to tests/ui/borrowck/writing-to-immutable-vec.stderr diff --git a/tests/ui/deref-non-pointer.rs b/tests/ui/deref-patterns/deref-non-pointer.rs similarity index 100% rename from tests/ui/deref-non-pointer.rs rename to tests/ui/deref-patterns/deref-non-pointer.rs diff --git a/tests/ui/deref-non-pointer.stderr b/tests/ui/deref-patterns/deref-non-pointer.stderr similarity index 100% rename from tests/ui/deref-non-pointer.stderr rename to tests/ui/deref-patterns/deref-non-pointer.stderr diff --git a/tests/ui/lazy-and-or.rs b/tests/ui/lazy-and-or.rs deleted file mode 100644 index f9dbeb68959a3..0000000000000 --- a/tests/ui/lazy-and-or.rs +++ /dev/null @@ -1,12 +0,0 @@ -//@ run-pass - -fn incr(x: &mut isize) -> bool { *x += 1; assert!((false)); return false; } - -pub fn main() { - let x = 1 == 2 || 3 == 3; - assert!((x)); - let mut y: isize = 10; - println!("{}", x || incr(&mut y)); - assert_eq!(y, 10); - if true && x { assert!((true)); } else { assert!((false)); } -} diff --git a/tests/ui/list.rs b/tests/ui/list.rs deleted file mode 100644 index 443c4c9f28f88..0000000000000 --- a/tests/ui/list.rs +++ /dev/null @@ -1,9 +0,0 @@ -//@ run-pass - -#![allow(non_camel_case_types)] - -enum list { #[allow(dead_code)] cons(isize, Box), nil, } - -pub fn main() { - list::cons(10, Box::new(list::cons(11, Box::new(list::cons(12, Box::new(list::nil)))))); -} diff --git a/tests/ui/minus-string.rs b/tests/ui/minus-string.rs deleted file mode 100644 index b83347b937edf..0000000000000 --- a/tests/ui/minus-string.rs +++ /dev/null @@ -1 +0,0 @@ -fn main() { -"foo".to_string(); } //~ ERROR cannot apply unary operator `-` to type `String` diff --git a/tests/ui/or-patterns/lazy-and-or.rs b/tests/ui/or-patterns/lazy-and-or.rs new file mode 100644 index 0000000000000..3d69553132b98 --- /dev/null +++ b/tests/ui/or-patterns/lazy-and-or.rs @@ -0,0 +1,25 @@ +//@ run-pass +// This test verifies the short-circuiting behavior of logical operators `||` and `&&`. +// It ensures that the right-hand expression is not evaluated when the left-hand +// expression is sufficient to determine the result. + +fn would_panic_if_called(x: &mut isize) -> bool { + *x += 1; + assert!(false, "This function should never be called due to short-circuiting"); + false +} + +fn main() { + let x = 1 == 2 || 3 == 3; + assert!(x); + + let mut y: isize = 10; + println!("Result of short-circuit: {}", x || would_panic_if_called(&mut y)); + assert_eq!(y, 10, "y should remain 10 if short-circuiting works correctly"); + + if true && x { + assert!(true); + } else { + assert!(false, "This branch should not be reached"); + } +} diff --git a/tests/ui/recursion/recursive-enum-box.rs b/tests/ui/recursion/recursive-enum-box.rs new file mode 100644 index 0000000000000..540b0c553603c --- /dev/null +++ b/tests/ui/recursion/recursive-enum-box.rs @@ -0,0 +1,21 @@ +//@ run-pass +// A smoke test for recursive enum structures using Box. +// This test constructs a linked list-like structure to exercise memory allocation and ownership. +// Originally introduced in 2010, this is one of Rust’s earliest test cases. + +#![allow(dead_code)] + +enum List { + Cons(isize, Box), + Nil, +} + +fn main() { + List::Cons( + 10, + Box::new(List::Cons( + 11, + Box::new(List::Cons(12, Box::new(List::Nil))), + )), + ); +} diff --git a/tests/ui/runtime/rt-explody-panic-payloads.rs b/tests/ui/runtime/rt-explody-panic-payloads.rs index c177fd260ed4f..d564a26ca7374 100644 --- a/tests/ui/runtime/rt-explody-panic-payloads.rs +++ b/tests/ui/runtime/rt-explody-panic-payloads.rs @@ -27,6 +27,6 @@ fn main() { // by QEMU in the stderr whenever a core dump happens. Remove it before the check. v.strip_suffix("qemu: uncaught target signal 6 (Aborted) - core dumped\n").unwrap_or(v) }) - .map(|v| { v.ends_with("fatal runtime error: drop of the panic payload panicked\n") }) + .map(|v| v.ends_with("fatal runtime error: drop of the panic payload panicked, aborting\n")) .unwrap_or(false)); } diff --git a/tests/ui/traits/deep-norm-pending.rs b/tests/ui/traits/deep-norm-pending.rs new file mode 100644 index 0000000000000..f56c3cfa3eab4 --- /dev/null +++ b/tests/ui/traits/deep-norm-pending.rs @@ -0,0 +1,24 @@ +trait Foo { + type Assoc; +} + +trait Bar { + fn method() -> impl Sized; + //~^ ERROR the trait bound `T: Foo` is not satisfied +} +impl Bar for T +//~^ ERROR the trait bound `T: Foo` is not satisfied +//~| ERROR the trait bound `T: Foo` is not satisfied +where + ::Assoc: Sized, +{ + fn method() {} + //~^ ERROR the trait bound `T: Foo` is not satisfied + //~| ERROR the trait bound `T: Foo` is not satisfied + //~| ERROR the trait bound `T: Foo` is not satisfied + //~| ERROR the trait bound `T: Foo` is not satisfied + //~| ERROR the trait bound `T: Foo` is not satisfied + //~| ERROR the trait bound `T: Foo` is not satisfied +} + +fn main() {} diff --git a/tests/ui/traits/deep-norm-pending.stderr b/tests/ui/traits/deep-norm-pending.stderr new file mode 100644 index 0000000000000..b95b9d7f4aec7 --- /dev/null +++ b/tests/ui/traits/deep-norm-pending.stderr @@ -0,0 +1,130 @@ +error[E0277]: the trait bound `T: Foo` is not satisfied + --> $DIR/deep-norm-pending.rs:15:5 + | +LL | fn method() {} + | ^^^^^^^^^^^ the trait `Foo` is not implemented for `T` + | +help: consider further restricting type parameter `T` with trait `Foo` + | +LL | ::Assoc: Sized, T: Foo + | ++++++ + +error[E0277]: the trait bound `T: Foo` is not satisfied + --> $DIR/deep-norm-pending.rs:9:1 + | +LL | / impl Bar for T +LL | | +LL | | +LL | | where +LL | | ::Assoc: Sized, + | |_____________________________^ the trait `Foo` is not implemented for `T` + | +help: consider further restricting type parameter `T` with trait `Foo` + | +LL | ::Assoc: Sized, T: Foo + | ++++++ + +error[E0277]: the trait bound `T: Foo` is not satisfied + --> $DIR/deep-norm-pending.rs:9:1 + | +LL | / impl Bar for T +LL | | +LL | | +LL | | where +... | +LL | | } + | |_^ the trait `Foo` is not implemented for `T` + | +help: consider further restricting type parameter `T` with trait `Foo` + | +LL | ::Assoc: Sized, T: Foo + | ++++++ + +error[E0277]: the trait bound `T: Foo` is not satisfied + --> $DIR/deep-norm-pending.rs:15:5 + | +LL | fn method() {} + | ^^^^^^^^^^^ the trait `Foo` is not implemented for `T` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: consider further restricting type parameter `T` with trait `Foo` + | +LL | ::Assoc: Sized, T: Foo + | ++++++ + +error[E0277]: the trait bound `T: Foo` is not satisfied + --> $DIR/deep-norm-pending.rs:15:5 + | +LL | fn method() {} + | ^^^^^^^^^^^ the trait `Foo` is not implemented for `T` + | +note: required for `T` to implement `Bar` + --> $DIR/deep-norm-pending.rs:9:9 + | +LL | impl Bar for T + | ^^^ ^ +... +LL | ::Assoc: Sized, + | ----- unsatisfied trait bound introduced here +help: consider further restricting type parameter `T` with trait `Foo` + | +LL | ::Assoc: Sized, T: Foo + | ++++++ + +error[E0277]: the trait bound `T: Foo` is not satisfied + --> $DIR/deep-norm-pending.rs:15:5 + | +LL | fn method() {} + | ^^^^^^^^^^^ the trait `Foo` is not implemented for `T` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: consider further restricting type parameter `T` with trait `Foo` + | +LL | ::Assoc: Sized, T: Foo + | ++++++ + +error[E0277]: the trait bound `T: Foo` is not satisfied + --> $DIR/deep-norm-pending.rs:6:20 + | +LL | fn method() -> impl Sized; + | ^^^^^^^^^^ the trait `Foo` is not implemented for `T` + | +note: required for `T` to implement `Bar` + --> $DIR/deep-norm-pending.rs:9:9 + | +LL | impl Bar for T + | ^^^ ^ +... +LL | ::Assoc: Sized, + | ----- unsatisfied trait bound introduced here +help: consider further restricting type parameter `T` with trait `Foo` + | +LL | ::Assoc: Sized, T: Foo + | ++++++ + +error[E0277]: the trait bound `T: Foo` is not satisfied + --> $DIR/deep-norm-pending.rs:15:5 + | +LL | fn method() {} + | ^^^^^^^^^^^ the trait `Foo` is not implemented for `T` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: consider further restricting type parameter `T` with trait `Foo` + | +LL | ::Assoc: Sized, T: Foo + | ++++++ + +error[E0277]: the trait bound `T: Foo` is not satisfied + --> $DIR/deep-norm-pending.rs:15:8 + | +LL | fn method() {} + | ^^^^^^ the trait `Foo` is not implemented for `T` + | +help: consider further restricting type parameter `T` with trait `Foo` + | +LL | ::Assoc: Sized, T: Foo + | ++++++ + +error: aborting due to 9 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/minus-string.rs b/tests/ui/typeck/minus-string.rs new file mode 100644 index 0000000000000..1c0f73a37132c --- /dev/null +++ b/tests/ui/typeck/minus-string.rs @@ -0,0 +1,7 @@ +// Regression test for issue #813. +// This ensures that the unary negation operator `-` cannot be applied to an owned `String`. +// Previously, due to a type-checking bug, this was mistakenly accepted by the compiler. + +fn main() { + -"foo".to_string(); //~ ERROR cannot apply unary operator `-` to type `String` +} diff --git a/tests/ui/minus-string.stderr b/tests/ui/typeck/minus-string.stderr similarity index 69% rename from tests/ui/minus-string.stderr rename to tests/ui/typeck/minus-string.stderr index 153965c810ea7..d2ebcd01ff9c1 100644 --- a/tests/ui/minus-string.stderr +++ b/tests/ui/typeck/minus-string.stderr @@ -1,8 +1,8 @@ error[E0600]: cannot apply unary operator `-` to type `String` - --> $DIR/minus-string.rs:1:13 + --> $DIR/minus-string.rs:6:5 | -LL | fn main() { -"foo".to_string(); } - | ^^^^^^^^^^^^^^^^^^ cannot apply unary operator `-` +LL | -"foo".to_string(); + | ^^^^^^^^^^^^^^^^^^ cannot apply unary operator `-` | note: the foreign item type `String` doesn't implement `Neg` --> $SRC_DIR/alloc/src/string.rs:LL:COL