Skip to content
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

Revert "Check that closures satisfy their where bounds" #97642

Merged
merged 1 commit into from
Jun 13, 2022
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
8 changes: 5 additions & 3 deletions compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
// generators don't take arguments.
}

ty::Closure(did, substs) => {
ty::Closure(_, substs) => {
// Only check the upvar types for WF, not the rest
// of the types within. This is needed because we
// capture the signature and it may not be WF
Expand Down Expand Up @@ -614,8 +614,10 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
// can cause compiler crashes when the user abuses unsafe
// code to procure such a closure.
// See src/test/ui/type-alias-impl-trait/wf_check_closures.rs
let obligations = self.nominal_obligations(did, substs);
self.out.extend(obligations);
// We should be checking the nominal_obligations here, but that caused
// a regression in https://github.com/rust-lang/rust/issues/97607
// The regression will be fixed on nightly, but the fix is too large
// to be backported.
}

ty::FnPtr(_) => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/generic_const_exprs/closures.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
//~^ ERROR cycle detected when building an abstract representation
//~^ ERROR overly complex generic constant

fn main() {}
25 changes: 6 additions & 19 deletions src/test/ui/const-generics/generic_const_exprs/closures.stderr
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
error[E0391]: cycle detected when building an abstract representation for test::{constant#0}
error: overly complex generic constant
--> $DIR/closures.rs:3:35
|
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
| ^^^^^^^^^^^^^
| ^^^^-------^^
| |
| borrowing is not supported in generic constants
|
note: ...which requires building THIR for `test::{constant#0}`...
--> $DIR/closures.rs:3:35
|
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
| ^^^^^^^^^^^^^
note: ...which requires type-checking `test::{constant#0}`...
--> $DIR/closures.rs:3:35
|
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
| ^^^^^^^^^^^^^
= note: ...which again requires building an abstract representation for test::{constant#0}, completing the cycle
note: cycle used when checking that `test` is well-formed
--> $DIR/closures.rs:3:1
|
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: consider moving this anonymous constant into a `const` function
= note: this operation may be supported in the future

error: aborting due to previous error

For more information about this error, try `rustc --explain E0391`.
10 changes: 1 addition & 9 deletions src/test/ui/higher-rank-trait-bounds/issue-59311.nll.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
error: higher-ranked lifetime error
--> $DIR/issue-59311.rs:17:5
|
LL | v.t(|| {});
| ^^^^^^^^^^
|
= note: could not prove [closure@$DIR/issue-59311.rs:17:9: 17:14] well-formed

error: higher-ranked lifetime error
--> $DIR/issue-59311.rs:17:9
|
Expand All @@ -14,5 +6,5 @@ LL | v.t(|| {});
|
= note: could not prove for<'a> &'a V: 'static

error: aborting due to 2 previous errors
error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/higher-rank-trait-bounds/issue-59311.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn crash<V>(v: &V)
where
for<'a> &'a V: T + 'static,
{
v.t(|| {}); //~ ERROR: `&'a V` does not fulfill the required lifetime
v.t(|| {}); //~ ERROR: higher-ranked lifetime error
}

fn main() {}
13 changes: 4 additions & 9 deletions src/test/ui/higher-rank-trait-bounds/issue-59311.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
error[E0477]: the type `&'a V` does not fulfill the required lifetime
--> $DIR/issue-59311.rs:17:5
error: higher-ranked lifetime error
--> $DIR/issue-59311.rs:17:9
|
LL | v.t(|| {});
| ^^^^^^^^^^
| ^^^^^
|
note: type must satisfy the static lifetime as required by this binding
--> $DIR/issue-59311.rs:15:24
|
LL | for<'a> &'a V: T + 'static,
| ^^^^^^^
= note: could not prove for<'a> &'a V: 'static

error: aborting due to previous error

For more information about this error, try `rustc --explain E0477`.
5 changes: 4 additions & 1 deletion src/test/ui/type-alias-impl-trait/issue-53092.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#![feature(type_alias_impl_trait)]
#![allow(dead_code)]

// check-pass
// known-bug #53092 #90409

type Bug<T, U> = impl Fn(T) -> U + Copy;

const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };

fn make_bug<T, U: From<T>>() -> Bug<T, U> {
|x| x.into() //~ ERROR the trait bound `U: From<T>` is not satisfied
|x| x.into()
}

fn main() {
Expand Down
19 changes: 0 additions & 19 deletions src/test/ui/type-alias-impl-trait/issue-53092.stderr

This file was deleted.

4 changes: 3 additions & 1 deletion src/test/ui/type-alias-impl-trait/wf_check_closures.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![feature(type_alias_impl_trait)]

// check-pass
// known-bug #53092 #90409

trait Bar {
fn bar(&self);
}
Expand All @@ -8,7 +11,6 @@ type FooFn<B> = impl FnOnce();

fn foo<B: Bar>(bar: B) -> FooFn<B> {
move || { bar.bar() }
//~^ ERROR the trait bound `B: Bar` is not satisfied
}

fn main() {
Expand Down
19 changes: 0 additions & 19 deletions src/test/ui/type-alias-impl-trait/wf_check_closures.stderr

This file was deleted.