1
Fork 0

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
This commit is contained in:
Michael Goulet 2023-06-23 19:47:21 -07:00 committed by GitHub
commit 766db8161b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 5 deletions

View file

@ -1049,6 +1049,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty)) => { ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty)) => {
let ty = self.resolve_vars_if_possible(ty);
match self.tcx.sess.opts.unstable_opts.trait_solver { match self.tcx.sess.opts.unstable_opts.trait_solver {
TraitSolver::Classic => { TraitSolver::Classic => {
// WF predicates cannot themselves make // WF predicates cannot themselves make

View file

@ -77,12 +77,19 @@ pub fn unnormalized_obligations<'tcx>(
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
arg: GenericArg<'tcx>, arg: GenericArg<'tcx>,
) -> Option<Vec<traits::PredicateObligation<'tcx>>> { ) -> Option<Vec<traits::PredicateObligation<'tcx>>> {
debug_assert_eq!(arg, infcx.resolve_vars_if_possible(arg));
// However, if `arg` IS an unresolved inference variable, returns `None`,
// because we are not able to make any progress at all. This is to prevent
// "livelock" where we say "$0 is WF if $0 is WF".
if arg.is_non_region_infer() {
return None;
}
if let ty::GenericArgKind::Lifetime(..) = arg.unpack() { if let ty::GenericArgKind::Lifetime(..) = arg.unpack() {
return Some(vec![]); return Some(vec![]);
} }
debug_assert_eq!(arg, infcx.resolve_vars_if_possible(arg));
let mut wf = WfPredicates { let mut wf = WfPredicates {
infcx, infcx,
param_env, param_env,

View file

@ -14,7 +14,7 @@ LL | for item in *things { *item = 0 }
= note: all local variables must have a statically known size = note: all local variables must have a statically known size
= help: unsized locals are gated as an unstable feature = help: unsized locals are gated as an unstable feature
error: the type `<_ as IntoIterator>::IntoIter` is not well-formed error: the type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
--> $DIR/issue-20605.rs:5:17 --> $DIR/issue-20605.rs:5:17
| |
LL | for item in *things { *item = 0 } LL | for item in *things { *item = 0 }

View file

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

View file

@ -23,5 +23,7 @@ fn main() {
drop(<() as Foo>::copy_me(&x)); drop(<() as Foo>::copy_me(&x));
//~^ ERROR `<() as Foo>::Item: Copy` is not satisfied //~^ ERROR `<() as Foo>::Item: Copy` is not satisfied
//~| ERROR `<() as Foo>::Item` is not well-formed //~| ERROR `<() as Foo>::Item` is not well-formed
//~| ERROR `<() as Foo>::Item` is not well-formed
//~| ERROR `<() as Foo>::Item` is not well-formed
println!("{x}"); println!("{x}");
} }

View file

@ -19,6 +19,18 @@ error: the type `<() as Foo>::Item` is not well-formed
LL | drop(<() as Foo>::copy_me(&x)); LL | drop(<() as Foo>::copy_me(&x));
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors error: the type `<() as Foo>::Item` is not well-formed
--> $DIR/alias-bound-unsound.rs:23:5
|
LL | drop(<() as Foo>::copy_me(&x));
| ^^^^
error: the type `<() as Foo>::Item` is not well-formed
--> $DIR/alias-bound-unsound.rs:23:10
|
LL | drop(<() as Foo>::copy_me(&x));
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0277`. For more information about this error, try `rustc --explain E0277`.