Don't emit same goal as input during wf obligations

This commit is contained in:
Michael Goulet 2023-06-23 15:58:09 +00:00
parent 04075b3202
commit f12695b53b
3 changed files with 24 additions and 3 deletions

View File

@ -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,

View File

@ -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 `_` is not well-formed
//~| ERROR `_` is not well-formed
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));
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
error: the type `_` is not well-formed
--> $DIR/alias-bound-unsound.rs:23:5
|
LL | drop(<() as Foo>::copy_me(&x));
| ^^^^
error: the type `_` 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`.