Skip to content

Commit f12695b

Browse files
Don't emit same goal as input during wf obligations
1 parent 04075b3 commit f12695b

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,19 @@ pub fn unnormalized_obligations<'tcx>(
7777
param_env: ty::ParamEnv<'tcx>,
7878
arg: GenericArg<'tcx>,
7979
) -> Option<Vec<traits::PredicateObligation<'tcx>>> {
80+
debug_assert_eq!(arg, infcx.resolve_vars_if_possible(arg));
81+
82+
// However, if `arg` IS an unresolved inference variable, returns `None`,
83+
// because we are not able to make any progress at all. This is to prevent
84+
// "livelock" where we say "$0 is WF if $0 is WF".
85+
if arg.is_non_region_infer() {
86+
return None;
87+
}
88+
8089
if let ty::GenericArgKind::Lifetime(..) = arg.unpack() {
8190
return Some(vec![]);
8291
}
8392

84-
debug_assert_eq!(arg, infcx.resolve_vars_if_possible(arg));
85-
8693
let mut wf = WfPredicates {
8794
infcx,
8895
param_env,

tests/ui/traits/new-solver/alias-bound-unsound.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ fn main() {
2323
drop(<() as Foo>::copy_me(&x));
2424
//~^ ERROR `<() as Foo>::Item: Copy` is not satisfied
2525
//~| ERROR `<() as Foo>::Item` is not well-formed
26+
//~| ERROR `_` is not well-formed
27+
//~| ERROR `_` is not well-formed
2628
println!("{x}");
2729
}

tests/ui/traits/new-solver/alias-bound-unsound.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ error: the type `<() as Foo>::Item` is not well-formed
1919
LL | drop(<() as Foo>::copy_me(&x));
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^
2121

22-
error: aborting due to 2 previous errors
22+
error: the type `_` is not well-formed
23+
--> $DIR/alias-bound-unsound.rs:23:5
24+
|
25+
LL | drop(<() as Foo>::copy_me(&x));
26+
| ^^^^
27+
28+
error: the type `_` is not well-formed
29+
--> $DIR/alias-bound-unsound.rs:23:10
30+
|
31+
LL | drop(<() as Foo>::copy_me(&x));
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^
33+
34+
error: aborting due to 4 previous errors
2335

2436
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)