Skip to content

Commit 18763cb

Browse files
Rollup merge of rust-lang#112223 - compiler-errors:new-solver-auto-proj, r=BoxyUwU
Don't ICE in new solver when auto traits have associated types People can write malformed auto traits, and that shouldn't cause the new solver to ICE
2 parents 163ce68 + ecd7809 commit 18763cb

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

compiler/rustc_trait_selection/src/solve/project_goals.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
226226
}
227227

228228
fn consider_auto_trait_candidate(
229-
_ecx: &mut EvalCtxt<'_, 'tcx>,
229+
ecx: &mut EvalCtxt<'_, 'tcx>,
230230
goal: Goal<'tcx, Self>,
231231
) -> QueryResult<'tcx> {
232-
bug!("auto traits do not have associated types: {:?}", goal);
232+
ecx.tcx().sess.delay_span_bug(
233+
ecx.tcx().def_span(goal.predicate.def_id()),
234+
"associated types not allowed on auto traits",
235+
);
236+
Err(NoSolution)
233237
}
234238

235239
fn consider_trait_alias_candidate(

tests/ui/auto-traits/issue-23080-2.stderr tests/ui/auto-traits/issue-23080-2.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0380]: auto traits cannot have associated items
2-
--> $DIR/issue-23080-2.rs:5:10
2+
--> $DIR/issue-23080-2.rs:8:10
33
|
44
LL | unsafe auto trait Trait {
55
| ----- auto traits cannot have associated items
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0380]: auto traits cannot have associated items
2+
--> $DIR/issue-23080-2.rs:8:10
3+
|
4+
LL | unsafe auto trait Trait {
5+
| ----- auto traits cannot have associated items
6+
LL | type Output;
7+
| -----^^^^^^- help: remove these associated items
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0380`.

tests/ui/auto-traits/issue-23080-2.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
#![feature(auto_traits)]
25
#![feature(negative_impls)]
36

0 commit comments

Comments
 (0)