From 0b0744ae8093eeeb9cf9627320ca0d4649c9ffaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sat, 14 Dec 2024 02:51:15 +0800 Subject: [PATCH 1/2] Add a regression test for #134162 --- tests/crashes/134162.rs | 8 -------- .../ui/typeck/rhs-ty-hint-134162.e2018.stderr | 11 +++++++++++ .../ui/typeck/rhs-ty-hint-134162.e2021.stderr | 11 +++++++++++ .../ui/typeck/rhs-ty-hint-134162.e2024.stderr | 11 +++++++++++ tests/ui/typeck/rhs-ty-hint-134162.rs | 18 ++++++++++++++++++ 5 files changed, 51 insertions(+), 8 deletions(-) delete mode 100644 tests/crashes/134162.rs create mode 100644 tests/ui/typeck/rhs-ty-hint-134162.e2018.stderr create mode 100644 tests/ui/typeck/rhs-ty-hint-134162.e2021.stderr create mode 100644 tests/ui/typeck/rhs-ty-hint-134162.e2024.stderr create mode 100644 tests/ui/typeck/rhs-ty-hint-134162.rs diff --git a/tests/crashes/134162.rs b/tests/crashes/134162.rs deleted file mode 100644 index 9e5a4a1cb0bf3..0000000000000 --- a/tests/crashes/134162.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ known-bug: #134162 - -fn main() { - struct X; - - let xs = [X, X, X]; - let eq = xs == [panic!("panic evaluated"); 2]; -} diff --git a/tests/ui/typeck/rhs-ty-hint-134162.e2018.stderr b/tests/ui/typeck/rhs-ty-hint-134162.e2018.stderr new file mode 100644 index 0000000000000..ff189e36ba04f --- /dev/null +++ b/tests/ui/typeck/rhs-ty-hint-134162.e2018.stderr @@ -0,0 +1,11 @@ +error[E0369]: binary operation `==` cannot be applied to type `[X; 1]` + --> $DIR/rhs-ty-hint-134162.rs:16:17 + | +LL | let _ = [X] == [panic!(); 2]; + | --- ^^ ------------- [_; 2] + | | + | [X; 1] + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0369`. diff --git a/tests/ui/typeck/rhs-ty-hint-134162.e2021.stderr b/tests/ui/typeck/rhs-ty-hint-134162.e2021.stderr new file mode 100644 index 0000000000000..ff189e36ba04f --- /dev/null +++ b/tests/ui/typeck/rhs-ty-hint-134162.e2021.stderr @@ -0,0 +1,11 @@ +error[E0369]: binary operation `==` cannot be applied to type `[X; 1]` + --> $DIR/rhs-ty-hint-134162.rs:16:17 + | +LL | let _ = [X] == [panic!(); 2]; + | --- ^^ ------------- [_; 2] + | | + | [X; 1] + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0369`. diff --git a/tests/ui/typeck/rhs-ty-hint-134162.e2024.stderr b/tests/ui/typeck/rhs-ty-hint-134162.e2024.stderr new file mode 100644 index 0000000000000..ff189e36ba04f --- /dev/null +++ b/tests/ui/typeck/rhs-ty-hint-134162.e2024.stderr @@ -0,0 +1,11 @@ +error[E0369]: binary operation `==` cannot be applied to type `[X; 1]` + --> $DIR/rhs-ty-hint-134162.rs:16:17 + | +LL | let _ = [X] == [panic!(); 2]; + | --- ^^ ------------- [_; 2] + | | + | [X; 1] + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0369`. diff --git a/tests/ui/typeck/rhs-ty-hint-134162.rs b/tests/ui/typeck/rhs-ty-hint-134162.rs new file mode 100644 index 0000000000000..a14b4bcfd26a5 --- /dev/null +++ b/tests/ui/typeck/rhs-ty-hint-134162.rs @@ -0,0 +1,18 @@ +//! Regression test for . +//! +//! introduced RHS type hints for when a ty doesn't +//! support a bin op. In the suggestion path, there was a `delay_bug`. +//! converted this `delay_bug` to `bug`, which did +//! not trigger any test failures as we did not have test coverage for this particular case. This +//! manifested in an ICE as reported in . + +//@ revisions: e2018 e2021 e2024 +//@[e2018] edition: 2018 +//@[e2021] edition: 2021 +//@[e2024] edition: 2024 + +fn main() { + struct X; + let _ = [X] == [panic!(); 2]; + //[e2018,e2021,e2024]~^ ERROR binary operation `==` cannot be applied to type `[X; 1]` +} From d15315cf9d2fbe3c2d348267567feacaddf89c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sat, 14 Dec 2024 02:52:29 +0800 Subject: [PATCH 2/2] Return adjustment target if adjust kind is never-to-any Without doing so, we'll run into a series of delayed bugs then find that we have a `TyKind::Error` constructed yet fail to emit an error. This partially reverts a change in related to never type adjustments in expr typecheck errors. --- compiler/rustc_hir_typeck/src/expr.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 65345048bfc2e..66978399efb53 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -72,12 +72,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if self.try_structurally_resolve_type(expr.span, ty).is_never() && self.expr_guaranteed_to_constitute_read_for_never(expr) { - if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) { + if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) { let reported = self.dcx().span_delayed_bug( expr.span, "expression with never type wound up being adjusted", ); - return Ty::new_error(self.tcx(), reported); + + return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] { + target.to_owned() + } else { + Ty::new_error(self.tcx(), reported) + }; } let adj_ty = self.next_ty_var(expr.span);