Skip to content

Commit 7b92f0c

Browse files
authored
Unrolled build for rust-lang#141362
Rollup merge of rust-lang#141362 - BoxyUwU:correct_error_term_kind, r=lcnr Normalize aliases to correct kind of error term Fixes rust-lang#140642 When normalizing an alias to an error in the old solver, normalize to the same term kind as the alias being normalized instead of always to a type error. r? lcnr
2 parents d423c81 + bc9cdc9 commit 7b92f0c

File tree

4 files changed

+81
-12
lines changed

4 files changed

+81
-12
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ pub(super) fn opt_normalize_projection_term<'a, 'b, 'tcx>(
378378
term: projected_term,
379379
obligations: mut projected_obligations,
380380
})) => {
381+
debug!("opt_normalize_projection_type: progress");
381382
// if projection succeeded, then what we get out of this
382383
// is also non-normalized (consider: it was derived from
383384
// an impl, where-clause etc) and hence we must
@@ -408,6 +409,7 @@ pub(super) fn opt_normalize_projection_term<'a, 'b, 'tcx>(
408409
Ok(Some(result.value))
409410
}
410411
Ok(Projected::NoProgress(projected_ty)) => {
412+
debug!("opt_normalize_projection_type: no progress");
411413
let result =
412414
Normalized { value: projected_ty, obligations: PredicateObligations::new() };
413415
infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
@@ -621,8 +623,17 @@ struct Progress<'tcx> {
621623
}
622624

623625
impl<'tcx> Progress<'tcx> {
624-
fn error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Self {
625-
Progress { term: Ty::new_error(tcx, guar).into(), obligations: PredicateObligations::new() }
626+
fn error_for_term(
627+
tcx: TyCtxt<'tcx>,
628+
alias_term: ty::AliasTerm<'tcx>,
629+
guar: ErrorGuaranteed,
630+
) -> Self {
631+
let err_term = if alias_term.kind(tcx).is_type() {
632+
Ty::new_error(tcx, guar).into()
633+
} else {
634+
ty::Const::new_error(tcx, guar).into()
635+
};
636+
Progress { term: err_term, obligations: PredicateObligations::new() }
626637
}
627638

628639
fn with_addl_obligations(mut self, mut obligations: PredicateObligations<'tcx>) -> Self {
@@ -650,7 +661,11 @@ fn project<'cx, 'tcx>(
650661
}
651662

652663
if let Err(guar) = obligation.predicate.error_reported() {
653-
return Ok(Projected::Progress(Progress::error(selcx.tcx(), guar)));
664+
return Ok(Projected::Progress(Progress::error_for_term(
665+
selcx.tcx(),
666+
obligation.predicate,
667+
guar,
668+
)));
654669
}
655670

656671
let mut candidates = ProjectionCandidateSet::None;
@@ -1965,7 +1980,13 @@ fn confirm_impl_candidate<'cx, 'tcx>(
19651980
let param_env = obligation.param_env;
19661981
let assoc_term = match specialization_graph::assoc_def(tcx, impl_def_id, assoc_item_id) {
19671982
Ok(assoc_term) => assoc_term,
1968-
Err(guar) => return Ok(Projected::Progress(Progress::error(tcx, guar))),
1983+
Err(guar) => {
1984+
return Ok(Projected::Progress(Progress::error_for_term(
1985+
tcx,
1986+
obligation.predicate,
1987+
guar,
1988+
)));
1989+
}
19691990
};
19701991

19711992
// This means that the impl is missing a definition for the

tests/crashes/140642.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(min_generic_const_args)]
2+
#![expect(incomplete_features)]
3+
4+
// Regression test for #140642. Test that normalizing const aliases
5+
// containing erroneous types normalizes to a const error instead of
6+
// a type error.
7+
8+
9+
pub trait Tr<A> {
10+
const SIZE: usize;
11+
}
12+
13+
fn mk_array(_x: T) -> [(); <T as Tr<bool>>::SIZE] {}
14+
//~^ ERROR: cannot find type `T` in this scope
15+
//~| ERROR: cannot find type `T` in this scope
16+
17+
fn main() {}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0412]: cannot find type `T` in this scope
2+
--> $DIR/projection-error.rs:13:17
3+
|
4+
LL | pub trait Tr<A> {
5+
| --------------- similarly named trait `Tr` defined here
6+
...
7+
LL | fn mk_array(_x: T) -> [(); <T as Tr<bool>>::SIZE] {}
8+
| ^
9+
|
10+
help: a trait with a similar name exists
11+
|
12+
LL | fn mk_array(_x: Tr) -> [(); <T as Tr<bool>>::SIZE] {}
13+
| +
14+
help: you might be missing a type parameter
15+
|
16+
LL | fn mk_array<T>(_x: T) -> [(); <T as Tr<bool>>::SIZE] {}
17+
| +++
18+
19+
error[E0412]: cannot find type `T` in this scope
20+
--> $DIR/projection-error.rs:13:29
21+
|
22+
LL | pub trait Tr<A> {
23+
| --------------- similarly named trait `Tr` defined here
24+
...
25+
LL | fn mk_array(_x: T) -> [(); <T as Tr<bool>>::SIZE] {}
26+
| ^
27+
|
28+
help: a trait with a similar name exists
29+
|
30+
LL | fn mk_array(_x: T) -> [(); <Tr as Tr<bool>>::SIZE] {}
31+
| +
32+
help: you might be missing a type parameter
33+
|
34+
LL | fn mk_array<T>(_x: T) -> [(); <T as Tr<bool>>::SIZE] {}
35+
| +++
36+
37+
error: aborting due to 2 previous errors
38+
39+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)