Skip to content

Commit 0105692

Browse files
authored
Unrolled build for rust-lang#134279
Rollup merge of rust-lang#134279 - jieyouxu:return-adjustment-target, r=compiler-errors (Re-)return adjustment target if adjust kind is never-to-any This PR fixes rust-lang#134162 where we ICE'd on ```rs fn main() { struct X; let _ = [X] == [panic!(); 2]; } ``` In rust-lang#121208 (comment), there was a change ```diff - 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 if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] { - target.to_owned() - } else { - Ty::new_error(self.tcx(), reported) - }; - } + if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) { + self.dcx() + .span_bug(expr.span, "expression with never type wound up being adjusted"); + } ``` It turned out returning the adjustment target if the adjustment kind is `NeverToAny` is necessary, as otherwise we will go through a series of `delay_bug`s and eventually find that we constructed a `TyKind::Error` without having actually emitted an error. This PR addresses that by re-returning the adjustment target if the adjustment kind is `NeverToAny`, partially reverting this change from rust-lang#121208. This PR has two commits: 1. The first commit adds a regression test for rust-lang#134162, which will ICE (on stable 1.83.0, beta and nightly 2024-12-13). 2. The second commit is the partial revert, which will fix the ICE. cc `@nnethercote` FYI as this is related to rust-lang#121208 changes. The changes from rust-lang#121208 exposed that we lacked test coverage for the code pattern reported in rust-lang#134162.
2 parents 85641f7 + d15315c commit 0105692

File tree

6 files changed

+58
-10
lines changed

6 files changed

+58
-10
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7272
if self.try_structurally_resolve_type(expr.span, ty).is_never()
7373
&& self.expr_guaranteed_to_constitute_read_for_never(expr)
7474
{
75-
if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
75+
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
7676
let reported = self.dcx().span_delayed_bug(
7777
expr.span,
7878
"expression with never type wound up being adjusted",
7979
);
80-
return Ty::new_error(self.tcx(), reported);
80+
81+
return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
82+
target.to_owned()
83+
} else {
84+
Ty::new_error(self.tcx(), reported)
85+
};
8186
}
8287

8388
let adj_ty = self.next_ty_var(expr.span);

tests/crashes/134162.rs

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0369]: binary operation `==` cannot be applied to type `[X; 1]`
2+
--> $DIR/rhs-ty-hint-134162.rs:16:17
3+
|
4+
LL | let _ = [X] == [panic!(); 2];
5+
| --- ^^ ------------- [_; 2]
6+
| |
7+
| [X; 1]
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0369`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0369]: binary operation `==` cannot be applied to type `[X; 1]`
2+
--> $DIR/rhs-ty-hint-134162.rs:16:17
3+
|
4+
LL | let _ = [X] == [panic!(); 2];
5+
| --- ^^ ------------- [_; 2]
6+
| |
7+
| [X; 1]
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0369`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0369]: binary operation `==` cannot be applied to type `[X; 1]`
2+
--> $DIR/rhs-ty-hint-134162.rs:16:17
3+
|
4+
LL | let _ = [X] == [panic!(); 2];
5+
| --- ^^ ------------- [_; 2]
6+
| |
7+
| [X; 1]
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0369`.

tests/ui/typeck/rhs-ty-hint-134162.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/134162>.
2+
//!
3+
//! <https://github.com/rust-lang/rust/pull/110877> introduced RHS type hints for when a ty doesn't
4+
//! support a bin op. In the suggestion path, there was a `delay_bug`.
5+
//! <https://github.com/rust-lang/rust/pull/121208> converted this `delay_bug` to `bug`, which did
6+
//! not trigger any test failures as we did not have test coverage for this particular case. This
7+
//! manifested in an ICE as reported in <https://github.com/rust-lang/rust/issues/134162>.
8+
9+
//@ revisions: e2018 e2021 e2024
10+
//@[e2018] edition: 2018
11+
//@[e2021] edition: 2021
12+
//@[e2024] edition: 2024
13+
14+
fn main() {
15+
struct X;
16+
let _ = [X] == [panic!(); 2];
17+
//[e2018,e2021,e2024]~^ ERROR binary operation `==` cannot be applied to type `[X; 1]`
18+
}

0 commit comments

Comments
 (0)