From a0bf36cb93fbd83a8d422084714bb4e74d0b95e3 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 2 Jun 2022 09:04:27 +0000 Subject: [PATCH] Revert "Check that closures satisfy their where bounds" This reverts commit 253408b4090bc15b88bb5faecaf1e9765be80587. --- .../rustc_trait_selection/src/traits/wf.rs | 8 +++--- .../generic_const_exprs/closures.rs | 2 +- .../generic_const_exprs/closures.stderr | 25 +++++-------------- .../issue-59311.nll.stderr | 10 +------- .../higher-rank-trait-bounds/issue-59311.rs | 2 +- .../issue-59311.stderr | 13 +++------- .../ui/type-alias-impl-trait/issue-53092.rs | 5 +++- .../type-alias-impl-trait/issue-53092.stderr | 19 -------------- .../wf_check_closures.rs | 4 ++- .../wf_check_closures.stderr | 19 -------------- 10 files changed, 25 insertions(+), 82 deletions(-) delete mode 100644 src/test/ui/type-alias-impl-trait/issue-53092.stderr delete mode 100644 src/test/ui/type-alias-impl-trait/wf_check_closures.stderr diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index ca40c3452e25b..9eea02b26026e 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -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 @@ -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(_) => { diff --git a/src/test/ui/const-generics/generic_const_exprs/closures.rs b/src/test/ui/const-generics/generic_const_exprs/closures.rs index 1ea310d063b82..847843fe1a63e 100644 --- a/src/test/ui/const-generics/generic_const_exprs/closures.rs +++ b/src/test/ui/const-generics/generic_const_exprs/closures.rs @@ -1,6 +1,6 @@ #![feature(generic_const_exprs)] #![allow(incomplete_features)] fn test() -> [u8; N + (|| 42)()] {} -//~^ ERROR cycle detected when building an abstract representation +//~^ ERROR overly complex generic constant fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/closures.stderr b/src/test/ui/const-generics/generic_const_exprs/closures.stderr index a15dd2016e9e4..18010413b9394 100644 --- a/src/test/ui/const-generics/generic_const_exprs/closures.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/closures.stderr @@ -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() -> [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() -> [u8; N + (|| 42)()] {} - | ^^^^^^^^^^^^^ -note: ...which requires type-checking `test::{constant#0}`... - --> $DIR/closures.rs:3:35 - | -LL | fn test() -> [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() -> [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`. diff --git a/src/test/ui/higher-rank-trait-bounds/issue-59311.nll.stderr b/src/test/ui/higher-rank-trait-bounds/issue-59311.nll.stderr index 15e83ab5a347d..c16c820615324 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-59311.nll.stderr +++ b/src/test/ui/higher-rank-trait-bounds/issue-59311.nll.stderr @@ -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 | @@ -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 diff --git a/src/test/ui/higher-rank-trait-bounds/issue-59311.rs b/src/test/ui/higher-rank-trait-bounds/issue-59311.rs index 6970857728560..d617571753c1d 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-59311.rs +++ b/src/test/ui/higher-rank-trait-bounds/issue-59311.rs @@ -14,7 +14,7 @@ pub fn crash(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() {} diff --git a/src/test/ui/higher-rank-trait-bounds/issue-59311.stderr b/src/test/ui/higher-rank-trait-bounds/issue-59311.stderr index 3dd05bba5c0a1..c16c820615324 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-59311.stderr +++ b/src/test/ui/higher-rank-trait-bounds/issue-59311.stderr @@ -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`. diff --git a/src/test/ui/type-alias-impl-trait/issue-53092.rs b/src/test/ui/type-alias-impl-trait/issue-53092.rs index 45792ba97a7a0..e7a8bf19a1b9b 100644 --- a/src/test/ui/type-alias-impl-trait/issue-53092.rs +++ b/src/test/ui/type-alias-impl-trait/issue-53092.rs @@ -1,12 +1,15 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] +// check-pass +// known-bug #53092 #90409 + type Bug = impl Fn(T) -> U + Copy; const CONST_BUG: Bug = unsafe { std::mem::transmute(|_: u8| ()) }; fn make_bug>() -> Bug { - |x| x.into() //~ ERROR the trait bound `U: From` is not satisfied + |x| x.into() } fn main() { diff --git a/src/test/ui/type-alias-impl-trait/issue-53092.stderr b/src/test/ui/type-alias-impl-trait/issue-53092.stderr deleted file mode 100644 index 2d423a0c0dff5..0000000000000 --- a/src/test/ui/type-alias-impl-trait/issue-53092.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0277]: the trait bound `U: From` is not satisfied - --> $DIR/issue-53092.rs:9:5 - | -LL | |x| x.into() - | ^^^^^^^^^^^^ the trait `From` is not implemented for `U` - | -note: required by a bound in `make_bug` - --> $DIR/issue-53092.rs:8:19 - | -LL | fn make_bug>() -> Bug { - | ^^^^^^^ required by this bound in `make_bug` -help: consider restricting type parameter `U` - | -LL | type Bug> = impl Fn(T) -> U + Copy; - | +++++++++++++++++++++++ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/wf_check_closures.rs b/src/test/ui/type-alias-impl-trait/wf_check_closures.rs index 2c70696ffcf48..2c3604ff200a7 100644 --- a/src/test/ui/type-alias-impl-trait/wf_check_closures.rs +++ b/src/test/ui/type-alias-impl-trait/wf_check_closures.rs @@ -1,5 +1,8 @@ #![feature(type_alias_impl_trait)] +// check-pass +// known-bug #53092 #90409 + trait Bar { fn bar(&self); } @@ -8,7 +11,6 @@ type FooFn = impl FnOnce(); fn foo(bar: B) -> FooFn { move || { bar.bar() } - //~^ ERROR the trait bound `B: Bar` is not satisfied } fn main() { diff --git a/src/test/ui/type-alias-impl-trait/wf_check_closures.stderr b/src/test/ui/type-alias-impl-trait/wf_check_closures.stderr deleted file mode 100644 index 58ae8617b9bd9..0000000000000 --- a/src/test/ui/type-alias-impl-trait/wf_check_closures.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0277]: the trait bound `B: Bar` is not satisfied - --> $DIR/wf_check_closures.rs:10:5 - | -LL | move || { bar.bar() } - | ^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` - | -note: required by a bound in `foo` - --> $DIR/wf_check_closures.rs:9:11 - | -LL | fn foo(bar: B) -> FooFn { - | ^^^ required by this bound in `foo` -help: consider restricting type parameter `B` - | -LL | type FooFn = impl FnOnce(); - | +++++ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`.