Skip to content

Commit 8038a9e

Browse files
authored
Rollup merge of #96379 - PrestonFrom:issue_96335, r=compiler-errors
delay bug when adjusting `NeverToAny` twice during diagnostic code Addresses Issue 96335 (#96335) by using `delay_span_bug` instead of an assert and returning an error type from `check_expr_meets_expectation_or_error`. Fixes #96335
2 parents 77031f3 + 5165295 commit 8038a9e

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

compiler/rustc_typeck/src/check/expr.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7878
// While we don't allow *arbitrary* coercions here, we *do* allow
7979
// coercions from ! to `expected`.
8080
if ty.is_never() {
81-
assert!(
82-
!self.typeck_results.borrow().adjustments().contains_key(expr.hir_id),
83-
"expression with never type wound up being adjusted"
84-
);
81+
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
82+
self.tcx().sess.delay_span_bug(
83+
expr.span,
84+
"expression with never type wound up being adjusted",
85+
);
86+
return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
87+
target.to_owned()
88+
} else {
89+
self.tcx().ty_error()
90+
};
91+
}
92+
8593
let adj_ty = self.next_ty_var(TypeVariableOrigin {
8694
kind: TypeVariableOriginKind::AdjustmentType,
8795
span: expr.span,

src/test/ui/never_type/issue-96335.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
0.....{loop{}1};
3+
//~^ ERROR unexpected token
4+
//~| ERROR mismatched types
5+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error: unexpected token: `...`
2+
--> $DIR/issue-96335.rs:2:6
3+
|
4+
LL | 0.....{loop{}1};
5+
| ^^^
6+
|
7+
help: use `..` for an exclusive range
8+
|
9+
LL | 0....{loop{}1};
10+
| ~~
11+
help: or `..=` for an inclusive range
12+
|
13+
LL | 0..=..{loop{}1};
14+
| ~~~
15+
16+
error[E0308]: mismatched types
17+
--> $DIR/issue-96335.rs:2:9
18+
|
19+
LL | 0.....{loop{}1};
20+
| ----^^^^^^^^^^^
21+
| | |
22+
| | expected integer, found struct `RangeTo`
23+
| arguments to this function are incorrect
24+
|
25+
= note: expected type `{integer}`
26+
found struct `RangeTo<{integer}>`
27+
note: associated function defined here
28+
--> $SRC_DIR/core/src/ops/range.rs:LL:COL
29+
|
30+
LL | pub const fn new(start: Idx, end: Idx) -> Self {
31+
| ^^^
32+
33+
error: aborting due to 2 previous errors
34+
35+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)