Skip to content

Commit 31a4131

Browse files
Rollup merge of #114831 - compiler-errors:next-solver-projection-subst-compat, r=lcnr
Check projection args before substitution in new solver Don't ICE when an impl has the wrong kind of GAT arguments r? lcnr
2 parents 81efd47 + 77c6c38 commit 31a4131

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

compiler/rustc_trait_selection/src/solve/project_goals.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::traits::specialization_graph;
1+
use crate::traits::{check_args_compatible, specialization_graph};
22

33
use super::assembly::{self, structural_traits};
44
use super::EvalCtxt;
@@ -190,11 +190,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
190190
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
191191
};
192192

193-
if !assoc_def.item.defaultness(tcx).has_value() {
194-
let guar = tcx.sess.delay_span_bug(
195-
tcx.def_span(assoc_def.item.def_id),
196-
"missing value for assoc item in impl",
197-
);
193+
let error_response = |ecx: &mut EvalCtxt<'_, 'tcx>, reason| {
194+
let guar = tcx.sess.delay_span_bug(tcx.def_span(assoc_def.item.def_id), reason);
198195
let error_term = match assoc_def.item.kind {
199196
ty::AssocKind::Const => ty::Const::new_error(
200197
tcx,
@@ -208,7 +205,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
208205
};
209206
ecx.eq(goal.param_env, goal.predicate.term, error_term)
210207
.expect("expected goal term to be fully unconstrained");
211-
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
208+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
209+
};
210+
211+
if !assoc_def.item.defaultness(tcx).has_value() {
212+
return error_response(ecx, "missing value for assoc item in impl");
212213
}
213214

214215
// Getting the right args here is complex, e.g. given:
@@ -233,6 +234,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
233234
assoc_def.defining_node,
234235
);
235236

237+
if !check_args_compatible(tcx, assoc_def.item, args) {
238+
return error_response(
239+
ecx,
240+
"associated item has mismatched generic item arguments",
241+
);
242+
}
243+
236244
// Finally we construct the actual value of the associated type.
237245
let term = match assoc_def.item.kind {
238246
ty::AssocKind::Type => tcx.type_of(assoc_def.item.def_id).map_bound(|ty| ty.into()),

tests/ui/generic-associated-types/issue-102114.stderr tests/ui/generic-associated-types/issue-102114.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0049]: type `B` has 1 type parameter but its trait declaration has 0 type parameters
2-
--> $DIR/issue-102114.rs:11:12
2+
--> $DIR/issue-102114.rs:14:12
33
|
44
LL | type B<'b>;
55
| -- expected 0 type parameters
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0049]: type `B` has 1 type parameter but its trait declaration has 0 type parameters
2+
--> $DIR/issue-102114.rs:14:12
3+
|
4+
LL | type B<'b>;
5+
| -- expected 0 type parameters
6+
...
7+
LL | type B<T> = Wrapper<T>;
8+
| ^ found 1 type parameter
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0049`.

tests/ui/generic-associated-types/issue-102114.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// revisions: current next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
14
trait A {
25
type B<'b>;
36
fn a() -> Self::B<'static>;

0 commit comments

Comments
 (0)