Skip to content

Commit 72cef11

Browse files
authored
Rollup merge of #148525 - chenyukang:yukang-fix-148515, r=wesleywiser
Fix ICE from lit_to_mir_constant caused by type error Fixes #148515 we still need to mark that there were errors to prevent later phases (like MIR building) from proceeding.
2 parents 5ed4faf + eaf979e commit 72cef11

File tree

3 files changed

+63
-20
lines changed

3 files changed

+63
-20
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -250,29 +250,30 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
250250
}
251251

252252
let mut reported = None;
253-
254253
for from_expansion in [false, true] {
255254
for (error, suppressed) in iter::zip(&errors, &is_suppressed) {
256-
if !suppressed
257-
&& error.obligation.cause.span.from_expansion() == from_expansion
258-
&& !error.references_error()
259-
{
260-
let guar = self.report_fulfillment_error(error);
261-
self.infcx.set_tainted_by_errors(guar);
262-
reported = Some(guar);
263-
// We want to ignore desugarings here: spans are equivalent even
264-
// if one is the result of a desugaring and the other is not.
265-
let mut span = error.obligation.cause.span;
266-
let expn_data = span.ctxt().outer_expn_data();
267-
if let ExpnKind::Desugaring(_) = expn_data.kind {
268-
span = expn_data.call_site;
255+
if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion {
256+
if !error.references_error() {
257+
let guar = self.report_fulfillment_error(error);
258+
self.infcx.set_tainted_by_errors(guar);
259+
reported = Some(guar);
260+
// We want to ignore desugarings here: spans are equivalent even
261+
// if one is the result of a desugaring and the other is not.
262+
let mut span = error.obligation.cause.span;
263+
let expn_data = span.ctxt().outer_expn_data();
264+
if let ExpnKind::Desugaring(_) = expn_data.kind {
265+
span = expn_data.call_site;
266+
}
267+
self.reported_trait_errors
268+
.borrow_mut()
269+
.entry(span)
270+
.or_insert_with(|| (vec![], guar))
271+
.0
272+
.push(error.obligation.as_goal());
273+
}
274+
if let Some(guar) = self.dcx().has_errors() {
275+
self.infcx.set_tainted_by_errors(guar);
269276
}
270-
self.reported_trait_errors
271-
.borrow_mut()
272-
.entry(span)
273-
.or_insert_with(|| (vec![], guar))
274-
.0
275-
.push(error.obligation.as_goal());
276277
}
277278
}
278279
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ edition: 2024
2+
3+
enum Test {
4+
Value = -5 >> 1_usize,
5+
}
6+
7+
fn test1(x: impl Iterator<Item = Foo>) {
8+
//~^ ERROR cannot find type `Foo` in this scope
9+
assert_eq!(Test::Value as u8, -3);
10+
}
11+
12+
fn test2(_: impl Iterator<Item = Foo>) {
13+
//~^ ERROR cannot find type `Foo` in this scope
14+
0u8 == -3;
15+
//~^ ERROR cannot apply unary operator `-` to type `u8`
16+
}
17+
18+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0412]: cannot find type `Foo` in this scope
2+
--> $DIR/ice-from-type-error-issue-148515.rs:7:34
3+
|
4+
LL | fn test1(x: impl Iterator<Item = Foo>) {
5+
| ^^^ not found in this scope
6+
7+
error[E0412]: cannot find type `Foo` in this scope
8+
--> $DIR/ice-from-type-error-issue-148515.rs:12:34
9+
|
10+
LL | fn test2(_: impl Iterator<Item = Foo>) {
11+
| ^^^ not found in this scope
12+
13+
error[E0600]: cannot apply unary operator `-` to type `u8`
14+
--> $DIR/ice-from-type-error-issue-148515.rs:14:12
15+
|
16+
LL | 0u8 == -3;
17+
| ^^ cannot apply unary operator `-`
18+
|
19+
= note: unsigned values cannot be negated
20+
21+
error: aborting due to 3 previous errors
22+
23+
Some errors have detailed explanations: E0412, E0600.
24+
For more information about an error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)