Rollup merge of #96379 - PrestonFrom:issue_96335, r=compiler-errors
delay bug when adjusting `NeverToAny` twice during diagnostic code Addresses Issue 96335 (https://github.com/rust-lang/rust/issues/96335) by using `delay_span_bug` instead of an assert and returning an error type from `check_expr_meets_expectation_or_error`. Fixes #96335
This commit is contained in:
commit
8038a9ece3
3 changed files with 52 additions and 4 deletions
|
@ -78,10 +78,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// While we don't allow *arbitrary* coercions here, we *do* allow
|
// While we don't allow *arbitrary* coercions here, we *do* allow
|
||||||
// coercions from ! to `expected`.
|
// coercions from ! to `expected`.
|
||||||
if ty.is_never() {
|
if ty.is_never() {
|
||||||
assert!(
|
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
|
||||||
!self.typeck_results.borrow().adjustments().contains_key(expr.hir_id),
|
self.tcx().sess.delay_span_bug(
|
||||||
"expression with never type wound up being adjusted"
|
expr.span,
|
||||||
);
|
"expression with never type wound up being adjusted",
|
||||||
|
);
|
||||||
|
return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
|
||||||
|
target.to_owned()
|
||||||
|
} else {
|
||||||
|
self.tcx().ty_error()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let adj_ty = self.next_ty_var(TypeVariableOrigin {
|
let adj_ty = self.next_ty_var(TypeVariableOrigin {
|
||||||
kind: TypeVariableOriginKind::AdjustmentType,
|
kind: TypeVariableOriginKind::AdjustmentType,
|
||||||
span: expr.span,
|
span: expr.span,
|
||||||
|
|
5
src/test/ui/never_type/issue-96335.rs
Normal file
5
src/test/ui/never_type/issue-96335.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
fn main() {
|
||||||
|
0.....{loop{}1};
|
||||||
|
//~^ ERROR unexpected token
|
||||||
|
//~| ERROR mismatched types
|
||||||
|
}
|
35
src/test/ui/never_type/issue-96335.stderr
Normal file
35
src/test/ui/never_type/issue-96335.stderr
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
error: unexpected token: `...`
|
||||||
|
--> $DIR/issue-96335.rs:2:6
|
||||||
|
|
|
||||||
|
LL | 0.....{loop{}1};
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
help: use `..` for an exclusive range
|
||||||
|
|
|
||||||
|
LL | 0....{loop{}1};
|
||||||
|
| ~~
|
||||||
|
help: or `..=` for an inclusive range
|
||||||
|
|
|
||||||
|
LL | 0..=..{loop{}1};
|
||||||
|
| ~~~
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/issue-96335.rs:2:9
|
||||||
|
|
|
||||||
|
LL | 0.....{loop{}1};
|
||||||
|
| ----^^^^^^^^^^^
|
||||||
|
| | |
|
||||||
|
| | expected integer, found struct `RangeTo`
|
||||||
|
| arguments to this function are incorrect
|
||||||
|
|
|
||||||
|
= note: expected type `{integer}`
|
||||||
|
found struct `RangeTo<{integer}>`
|
||||||
|
note: associated function defined here
|
||||||
|
--> $SRC_DIR/core/src/ops/range.rs:LL:COL
|
||||||
|
|
|
||||||
|
LL | pub const fn new(start: Idx, end: Idx) -> Self {
|
||||||
|
| ^^^
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Add table
Add a link
Reference in a new issue