Skip to content

Don't emit same goal as input during wf::unnormalized_obligations #112965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}

ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty)) => {
let ty = self.resolve_vars_if_possible(ty);
match self.tcx.sess.opts.unstable_opts.trait_solver {
TraitSolver::Classic => {
// WF predicates cannot themselves make
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ pub fn unnormalized_obligations<'tcx>(
param_env: ty::ParamEnv<'tcx>,
arg: GenericArg<'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() {
return Some(vec![]);
}

debug_assert_eq!(arg, infcx.resolve_vars_if_possible(arg));

let mut wf = WfPredicates {
infcx,
param_env,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/for/issue-20605.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LL | for item in *things { *item = 0 }
= note: all local variables must have a statically known size
= 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
|
LL | for item in *things { *item = 0 }
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/for/issue-20605.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
fn changer<'a>(mut things: Box<dyn Iterator<Item=&'a mut u8>>) {
for item in *things { *item = 0 }
//~^ 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
}

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/traits/new-solver/alias-bound-unsound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ fn main() {
drop(<() as Foo>::copy_me(&x));
//~^ 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
println!("{x}");
}
14 changes: 13 additions & 1 deletion tests/ui/traits/new-solver/alias-bound-unsound.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ error: the type `<() as Foo>::Item` is not well-formed
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`.