Skip to content

Commit 766db81

Browse files
Rollup merge of #112965 - compiler-errors:circular-wf, r=aliemjay
Don't emit same goal as input during `wf::unnormalized_obligations` r? `@aliemjay` cc `@lcnr` I accidentally pruned the logic to handle `WF(?0)` when writing `wf::unnormalized_obligations`. idk if you wanted to construct a test first, but this is an obvious fix. Copied the comment from above. Fixes rust-lang/trait-system-refactor-initiative#36
2 parents fdce450 + 2eb7d69 commit 766db81

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10491049
}
10501050

10511051
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty)) => {
1052+
let ty = self.resolve_vars_if_possible(ty);
10521053
match self.tcx.sess.opts.unstable_opts.trait_solver {
10531054
TraitSolver::Classic => {
10541055
// WF predicates cannot themselves make

compiler/rustc_trait_selection/src/traits/wf.rs

+9-2
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/for/issue-20605.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | for item in *things { *item = 0 }
1414
= note: all local variables must have a statically known size
1515
= help: unsized locals are gated as an unstable feature
1616

17-
error: the type `<_ as IntoIterator>::IntoIter` is not well-formed
17+
error: the type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
1818
--> $DIR/issue-20605.rs:5:17
1919
|
2020
LL | for item in *things { *item = 0 }

tests/ui/for/issue-20605.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
fn changer<'a>(mut things: Box<dyn Iterator<Item=&'a mut u8>>) {
55
for item in *things { *item = 0 }
66
//~^ ERROR the size for values of type
7-
//[next]~^^ ERROR the type `<_ as IntoIterator>::IntoIter` is not well-formed
7+
//[next]~^^ ERROR the type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
88
//[next]~| ERROR the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
99
}
1010

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

+2
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 `<() as Foo>::Item` is not well-formed
27+
//~| ERROR `<() as Foo>::Item` is not well-formed
2628
println!("{x}");
2729
}

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

+13-1
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 `<() as Foo>::Item` 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 `<() as Foo>::Item` 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)