From f83793c259331e1567cfb720e080a507d98b0234 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Thu, 18 Apr 2024 10:15:24 +0530 Subject: [PATCH 1/4] Fix ICE when ADT tail has type error --- compiler/rustc_middle/src/ty/layout.rs | 4 ++++ .../layout/ice-type-error-in-tail-124031.rs | 20 +++++++++++++++++++ .../ice-type-error-in-tail-124031.stderr | 12 +++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/ui/layout/ice-type-error-in-tail-124031.rs create mode 100644 tests/ui/layout/ice-type-error-in-tail-124031.stderr diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 50e68bfdbe7eb..d9a05062e8ce0 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -336,6 +336,10 @@ impl<'tcx> SizeSkeleton<'tcx> { debug_assert!(tail.has_non_region_param()); Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) }) } + ty::Error(guar) => { + // Fixes ICE #124031 + return Err(tcx.arena.alloc(LayoutError::ReferencesError(*guar))); + } _ => bug!( "SizeSkeleton::compute({ty}): layout errored ({err:?}), yet \ tail `{tail}` is not a type parameter or a projection", diff --git a/tests/ui/layout/ice-type-error-in-tail-124031.rs b/tests/ui/layout/ice-type-error-in-tail-124031.rs new file mode 100644 index 0000000000000..0a2be11740358 --- /dev/null +++ b/tests/ui/layout/ice-type-error-in-tail-124031.rs @@ -0,0 +1,20 @@ +// Regression test for issue #124031 +// Checks that we don't ICE when the tail +// of an ADT has a type error + +trait Trait { + type RefTarget; +} + +impl Trait for () {} +//~^ ERROR not all trait items implemented, missing: `RefTarget` + +struct Other { + data: <() as Trait>::RefTarget, +} + +fn main() { + unsafe { + std::mem::transmute::, Option<&Other>>(None); + } +} diff --git a/tests/ui/layout/ice-type-error-in-tail-124031.stderr b/tests/ui/layout/ice-type-error-in-tail-124031.stderr new file mode 100644 index 0000000000000..57dc83f92dfda --- /dev/null +++ b/tests/ui/layout/ice-type-error-in-tail-124031.stderr @@ -0,0 +1,12 @@ +error[E0046]: not all trait items implemented, missing: `RefTarget` + --> $DIR/ice-type-error-in-tail-124031.rs:9:1 + | +LL | type RefTarget; + | -------------- `RefTarget` from trait +... +LL | impl Trait for () {} + | ^^^^^^^^^^^^^^^^^ missing `RefTarget` in implementation + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0046`. From 2d5a226f8f5a36c10c7863026f39d9d10bd38fa4 Mon Sep 17 00:00:00 2001 From: bohan Date: Sun, 21 Apr 2024 20:40:44 +0800 Subject: [PATCH 2/4] cleanup: unnecessary clone during lower generics args --- compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs index d340a08ee79b1..dd76862451c6f 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs @@ -228,8 +228,8 @@ pub fn lower_generic_args<'tcx: 'a, 'a>( // Check whether this segment takes generic arguments and the user has provided any. let (generic_args, infer_args) = ctx.args_for_def_id(def_id); - let args_iter = generic_args.iter().flat_map(|generic_args| generic_args.args.iter()); - let mut args_iter = args_iter.clone().peekable(); + let mut args_iter = + generic_args.iter().flat_map(|generic_args| generic_args.args.iter()).peekable(); // If we encounter a type or const when we expect a lifetime, we infer the lifetimes. // If we later encounter a lifetime, we know that the arguments were provided in the From 6ae761cd40c7fc9a69bee946a6e96bc06ca8575f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Sun, 21 Apr 2024 17:41:42 +0200 Subject: [PATCH 3/4] Add gnullvm targets to manifest --- src/tools/build-manifest/src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index c223b9f43240f..f3972346bb5be 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -56,6 +56,7 @@ static TARGETS: &[&str] = &[ "aarch64-apple-ios-sim", "aarch64-unknown-fuchsia", "aarch64-linux-android", + "aarch64-pc-windows-gnullvm", "aarch64-pc-windows-msvc", "aarch64-unknown-hermit", "aarch64-unknown-linux-gnu", @@ -96,6 +97,7 @@ static TARGETS: &[&str] = &[ "i686-apple-darwin", "i686-linux-android", "i686-pc-windows-gnu", + "i686-pc-windows-gnullvm", "i686-pc-windows-msvc", "i686-unknown-freebsd", "i686-unknown-linux-gnu", @@ -157,6 +159,7 @@ static TARGETS: &[&str] = &[ "x86_64-unknown-fuchsia", "x86_64-linux-android", "x86_64-pc-windows-gnu", + "x86_64-pc-windows-gnullvm", "x86_64-pc-windows-msvc", "x86_64-pc-solaris", "x86_64-unikraft-linux-musl", From e1d12ffb6c7ed29c4d0525d2e1e7e4347d8c2372 Mon Sep 17 00:00:00 2001 From: Boxy Date: Sun, 21 Apr 2024 18:41:32 +0100 Subject: [PATCH 4/4] removal --- triagebot.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/triagebot.toml b/triagebot.toml index 66b8f44d68898..903569bf44549 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -851,7 +851,6 @@ compiler-team-contributors = [ "@nnethercote", "@fmease", "@fee1-dead", - "@BoxyUwU", "@jieyouxu", ] compiler = [