From 7faf6cf1c128726473968b1726426c03ea2087d6 Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 17 Jul 2025 09:10:37 +0000 Subject: [PATCH 1/3] revert: PR144016 - `MetaSized` does not always hold --- .../rustc_trait_selection/src/traits/util.rs | 7 --- ...st-size_of_val-align_of_val-extern-type.rs | 4 +- ...ize_of_val-align_of_val-extern-type.stderr | 38 +++++++++++--- tests/ui/extern/extern-types-size_of_val.rs | 3 +- .../ui/extern/extern-types-size_of_val.stderr | 39 ++++++++++++++ tests/ui/extern/extern-types-unsized.rs | 2 + tests/ui/extern/extern-types-unsized.stderr | 30 ++++++++++- tests/ui/extern/unsized-extern-derefmove.rs | 4 ++ .../ui/extern/unsized-extern-derefmove.stderr | 52 ++++++++++++++++++- .../layout/unconstrained-param-ice-137308.rs | 1 + .../unconstrained-param-ice-137308.stderr | 11 +++- tests/ui/nll/issue-50716.rs | 2 +- tests/ui/nll/issue-50716.stderr | 18 ++++++- ...lete-inference-issue-143992.current.stderr | 17 ++++++ .../incomplete-inference-issue-143992.rs | 4 +- .../sized-hierarchy/overflow.current.stderr | 45 ++++++++++++++++ tests/ui/sized-hierarchy/overflow.rs | 7 ++- .../resolve-impl-before-constrain-check.rs | 1 + ...resolve-impl-before-constrain-check.stderr | 11 +++- 19 files changed, 263 insertions(+), 33 deletions(-) create mode 100644 tests/ui/extern/extern-types-size_of_val.stderr create mode 100644 tests/ui/sized-hierarchy/incomplete-inference-issue-143992.current.stderr create mode 100644 tests/ui/sized-hierarchy/overflow.current.stderr diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 0c14b124e25c2..25cd7787a3496 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -379,13 +379,6 @@ pub fn sizedness_fast_path<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc _ => return false, }; - // FIXME(sized_hierarchy): this temporarily reverts the `sized_hierarchy` feature - // while a proper fix for `tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs` - // is pending a proper fix - if !tcx.features().sized_hierarchy() && matches!(sizedness, SizedTraitKind::MetaSized) { - return true; - } - if trait_pred.self_ty().has_trivial_sizedness(tcx, sizedness) { debug!("fast path -- trivial sizedness"); return true; diff --git a/tests/ui/consts/const-size_of_val-align_of_val-extern-type.rs b/tests/ui/consts/const-size_of_val-align_of_val-extern-type.rs index fd3ed8f18265e..55d430a08aadb 100644 --- a/tests/ui/consts/const-size_of_val-align_of_val-extern-type.rs +++ b/tests/ui/consts/const-size_of_val-align_of_val-extern-type.rs @@ -8,8 +8,8 @@ extern "C" { } const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) }; -//~^ ERROR `extern type` does not have known layout +//~^ ERROR: the size for values of type `Opaque` cannot be known const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) }; -//~^ ERROR `extern type` does not have known layout +//~^ ERROR: the size for values of type `Opaque` cannot be known fn main() {} diff --git a/tests/ui/consts/const-size_of_val-align_of_val-extern-type.stderr b/tests/ui/consts/const-size_of_val-align_of_val-extern-type.stderr index 23f7aaf538edc..825b9e941584c 100644 --- a/tests/ui/consts/const-size_of_val-align_of_val-extern-type.stderr +++ b/tests/ui/consts/const-size_of_val-align_of_val-extern-type.stderr @@ -1,15 +1,39 @@ -error[E0080]: `extern type` does not have known layout - --> $DIR/const-size_of_val-align_of_val-extern-type.rs:10:31 +error[E0277]: the size for values of type `Opaque` cannot be known + --> $DIR/const-size_of_val-align_of_val-extern-type.rs:10:43 | LL | const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_SIZE` failed here + | ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MetaSized` is not implemented for `Opaque` + | | + | required by a bound introduced by this call + | + = note: the trait bound `Opaque: MetaSized` is not satisfied +note: required by a bound in `std::intrinsics::size_of_val` + --> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL +help: consider borrowing here + | +LL | const _SIZE: usize = unsafe { size_of_val(&(&4 as *const i32 as *const Opaque)) }; + | ++ + +LL | const _SIZE: usize = unsafe { size_of_val(&mut (&4 as *const i32 as *const Opaque)) }; + | ++++++ + -error[E0080]: `extern type` does not have known layout - --> $DIR/const-size_of_val-align_of_val-extern-type.rs:12:32 +error[E0277]: the size for values of type `Opaque` cannot be known + --> $DIR/const-size_of_val-align_of_val-extern-type.rs:12:45 | LL | const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_ALIGN` failed here + | ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MetaSized` is not implemented for `Opaque` + | | + | required by a bound introduced by this call + | + = note: the trait bound `Opaque: MetaSized` is not satisfied +note: required by a bound in `std::intrinsics::align_of_val` + --> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL +help: consider borrowing here + | +LL | const _ALIGN: usize = unsafe { align_of_val(&(&4 as *const i32 as *const Opaque)) }; + | ++ + +LL | const _ALIGN: usize = unsafe { align_of_val(&mut (&4 as *const i32 as *const Opaque)) }; + | ++++++ + error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0080`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/extern/extern-types-size_of_val.rs b/tests/ui/extern/extern-types-size_of_val.rs index 875ae9a535a7a..d30bf5fc90578 100644 --- a/tests/ui/extern/extern-types-size_of_val.rs +++ b/tests/ui/extern/extern-types-size_of_val.rs @@ -1,4 +1,3 @@ -//@ check-pass #![feature(extern_types)] use std::mem::{align_of_val, size_of_val}; @@ -11,5 +10,7 @@ fn main() { let x: &A = unsafe { &*(1usize as *const A) }; size_of_val(x); +//~^ ERROR: the size for values of type `A` cannot be known align_of_val(x); +//~^ ERROR: the size for values of type `A` cannot be known } diff --git a/tests/ui/extern/extern-types-size_of_val.stderr b/tests/ui/extern/extern-types-size_of_val.stderr new file mode 100644 index 0000000000000..cb0a6ae5903c7 --- /dev/null +++ b/tests/ui/extern/extern-types-size_of_val.stderr @@ -0,0 +1,39 @@ +error[E0277]: the size for values of type `A` cannot be known + --> $DIR/extern-types-size_of_val.rs:12:17 + | +LL | size_of_val(x); + | ----------- ^ the trait `MetaSized` is not implemented for `A` + | | + | required by a bound introduced by this call + | + = note: the trait bound `A: MetaSized` is not satisfied +note: required by a bound in `std::mem::size_of_val` + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL +help: consider borrowing here + | +LL | size_of_val(&x); + | + +LL | size_of_val(&mut x); + | ++++ + +error[E0277]: the size for values of type `A` cannot be known + --> $DIR/extern-types-size_of_val.rs:14:18 + | +LL | align_of_val(x); + | ------------ ^ the trait `MetaSized` is not implemented for `A` + | | + | required by a bound introduced by this call + | + = note: the trait bound `A: MetaSized` is not satisfied +note: required by a bound in `std::mem::align_of_val` + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL +help: consider borrowing here + | +LL | align_of_val(&x); + | + +LL | align_of_val(&mut x); + | ++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/extern/extern-types-unsized.rs b/tests/ui/extern/extern-types-unsized.rs index 94a222a7e7e01..6d6407fb0661c 100644 --- a/tests/ui/extern/extern-types-unsized.rs +++ b/tests/ui/extern/extern-types-unsized.rs @@ -27,7 +27,9 @@ fn main() { assert_sized::>(); //~^ ERROR the size for values of type + //~| ERROR the size for values of type `A` cannot be known assert_sized::>>(); //~^ ERROR the size for values of type + //~| ERROR the size for values of type `A` cannot be known } diff --git a/tests/ui/extern/extern-types-unsized.stderr b/tests/ui/extern/extern-types-unsized.stderr index a587d4dda55c8..43dd9800d6d30 100644 --- a/tests/ui/extern/extern-types-unsized.stderr +++ b/tests/ui/extern/extern-types-unsized.stderr @@ -59,8 +59,21 @@ help: consider relaxing the implicit `Sized` restriction LL | fn assert_sized() {} | ++++++++ +error[E0277]: the size for values of type `A` cannot be known + --> $DIR/extern-types-unsized.rs:28:20 + | +LL | assert_sized::>(); + | ^^^^^^ doesn't have a known size + | + = help: the trait `MetaSized` is not implemented for `A` +note: required by a bound in `Bar` + --> $DIR/extern-types-unsized.rs:14:12 + | +LL | struct Bar { + | ^ required by this bound in `Bar` + error[E0277]: the size for values of type `A` cannot be known at compilation time - --> $DIR/extern-types-unsized.rs:31:20 + --> $DIR/extern-types-unsized.rs:32:20 | LL | assert_sized::>>(); | ^^^^^^^^^^^ doesn't have a size known at compile-time @@ -81,6 +94,19 @@ help: consider relaxing the implicit `Sized` restriction LL | fn assert_sized() {} | ++++++++ -error: aborting due to 4 previous errors +error[E0277]: the size for values of type `A` cannot be known + --> $DIR/extern-types-unsized.rs:32:20 + | +LL | assert_sized::>>(); + | ^^^^^^^^^^^ doesn't have a known size + | + = help: the trait `MetaSized` is not implemented for `A` +note: required by a bound in `Bar` + --> $DIR/extern-types-unsized.rs:14:12 + | +LL | struct Bar { + | ^ required by this bound in `Bar` + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/extern/unsized-extern-derefmove.rs b/tests/ui/extern/unsized-extern-derefmove.rs index 39597a12fe117..c02375266ab47 100644 --- a/tests/ui/extern/unsized-extern-derefmove.rs +++ b/tests/ui/extern/unsized-extern-derefmove.rs @@ -7,10 +7,14 @@ extern "C" { } unsafe fn make_device() -> Box { +//~^ ERROR the size for values of type `Device` cannot be known Box::from_raw(0 as *mut _) +//~^ ERROR the size for values of type `Device` cannot be known +//~| ERROR the size for values of type `Device` cannot be known } fn main() { let d: Device = unsafe { *make_device() }; //~^ ERROR the size for values of type `Device` cannot be known +//~| ERROR the size for values of type `Device` cannot be known } diff --git a/tests/ui/extern/unsized-extern-derefmove.stderr b/tests/ui/extern/unsized-extern-derefmove.stderr index c43184d94e177..a9efc2e66e3b0 100644 --- a/tests/ui/extern/unsized-extern-derefmove.stderr +++ b/tests/ui/extern/unsized-extern-derefmove.stderr @@ -1,5 +1,43 @@ +error[E0277]: the size for values of type `Device` cannot be known + --> $DIR/unsized-extern-derefmove.rs:9:28 + | +LL | unsafe fn make_device() -> Box { + | ^^^^^^^^^^^ doesn't have a known size + | + = help: the trait `MetaSized` is not implemented for `Device` +note: required by a bound in `Box` + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + +error[E0277]: the size for values of type `Device` cannot be known + --> $DIR/unsized-extern-derefmove.rs:11:19 + | +LL | Box::from_raw(0 as *mut _) + | ------------- ^^^^^^^^^^^ the trait `MetaSized` is not implemented for `Device` + | | + | required by a bound introduced by this call + | + = note: the trait bound `Device: MetaSized` is not satisfied +note: required by a bound in `Box::::from_raw` + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL +help: consider borrowing here + | +LL | Box::from_raw(&(0 as *mut _)) + | ++ + +LL | Box::from_raw(&mut (0 as *mut _)) + | ++++++ + + +error[E0277]: the size for values of type `Device` cannot be known + --> $DIR/unsized-extern-derefmove.rs:11:5 + | +LL | Box::from_raw(0 as *mut _) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a known size + | + = help: the trait `MetaSized` is not implemented for `Device` +note: required by a bound in `Box` + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + error[E0277]: the size for values of type `Device` cannot be known at compilation time - --> $DIR/unsized-extern-derefmove.rs:14:9 + --> $DIR/unsized-extern-derefmove.rs:17:9 | LL | let d: Device = unsafe { *make_device() }; | ^ doesn't have a size known at compile-time @@ -11,6 +49,16 @@ help: consider borrowing here LL | let d: &Device = unsafe { *make_device() }; | + -error: aborting due to 1 previous error +error[E0277]: the size for values of type `Device` cannot be known + --> $DIR/unsized-extern-derefmove.rs:17:31 + | +LL | let d: Device = unsafe { *make_device() }; + | ^^^^^^^^^^^^^ doesn't have a known size + | + = help: the trait `MetaSized` is not implemented for `Device` +note: required by a bound in `Box` + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/layout/unconstrained-param-ice-137308.rs b/tests/ui/layout/unconstrained-param-ice-137308.rs index d05e6e1fd3f33..03b7e7599601a 100644 --- a/tests/ui/layout/unconstrained-param-ice-137308.rs +++ b/tests/ui/layout/unconstrained-param-ice-137308.rs @@ -17,3 +17,4 @@ impl A for u8 { //~ ERROR: the type parameter `C` is not constrained #[rustc_layout(debug)] struct S([u8; ::B]); //~^ ERROR: the type has an unknown layout +//~| ERROR: type annotations needed diff --git a/tests/ui/layout/unconstrained-param-ice-137308.stderr b/tests/ui/layout/unconstrained-param-ice-137308.stderr index 615c131eb9045..82cd1217c4903 100644 --- a/tests/ui/layout/unconstrained-param-ice-137308.stderr +++ b/tests/ui/layout/unconstrained-param-ice-137308.stderr @@ -4,12 +4,19 @@ error[E0207]: the type parameter `C` is not constrained by the impl trait, self LL | impl A for u8 { | ^ unconstrained type parameter +error[E0282]: type annotations needed + --> $DIR/unconstrained-param-ice-137308.rs:18:16 + | +LL | struct S([u8; ::B]); + | ^^ cannot infer type for type parameter `C` + error: the type has an unknown layout --> $DIR/unconstrained-param-ice-137308.rs:18:1 | LL | struct S([u8; ::B]); | ^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0207`. +Some errors have detailed explanations: E0207, E0282. +For more information about an error, try `rustc --explain E0207`. diff --git a/tests/ui/nll/issue-50716.rs b/tests/ui/nll/issue-50716.rs index 96168ebeaa165..76c6fc5e7b925 100644 --- a/tests/ui/nll/issue-50716.rs +++ b/tests/ui/nll/issue-50716.rs @@ -5,7 +5,7 @@ trait A { type X: ?Sized; } -fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) +fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) //~ ERROR where for<'b> &'b T: A, <&'static T as A>::X: Sized diff --git a/tests/ui/nll/issue-50716.stderr b/tests/ui/nll/issue-50716.stderr index 536f88085ded3..edd7fd765dade 100644 --- a/tests/ui/nll/issue-50716.stderr +++ b/tests/ui/nll/issue-50716.stderr @@ -1,3 +1,18 @@ +error[E0308]: mismatched types + --> $DIR/issue-50716.rs:8:27 + | +LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) + | ^^^^^^^^^^^^^^^^^^^^ lifetime mismatch + | + = note: expected trait `<<&'a T as A>::X as MetaSized>` + found trait `<<&'static T as A>::X as MetaSized>` +note: the lifetime `'a` as defined here... + --> $DIR/issue-50716.rs:8:8 + | +LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) + | ^^ + = note: ...does not necessarily outlive the static lifetime + error: lifetime may not live long enough --> $DIR/issue-50716.rs:13:14 | @@ -7,5 +22,6 @@ LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) LL | let _x = *s; | ^^ proving this value is `Sized` requires that `'a` must outlive `'static` -error: aborting due to 1 previous error +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.current.stderr b/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.current.stderr new file mode 100644 index 0000000000000..cf56f42afc8a3 --- /dev/null +++ b/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.current.stderr @@ -0,0 +1,17 @@ +error[E0308]: mismatched types + --> $DIR/incomplete-inference-issue-143992.rs:27:28 + | +LL | let _x = T::Assoc::new(()); + | ------------- ^^ expected `[u32; 1]`, found `()` + | | + | arguments to this function are incorrect + | +note: associated function defined here + --> $DIR/incomplete-inference-issue-143992.rs:18:8 + | +LL | fn new(r: R) -> R { + | ^^^ ---- + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs b/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs index 3e3e1dc50e58b..bb3942966e726 100644 --- a/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs +++ b/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs @@ -1,7 +1,7 @@ //@ compile-flags: --crate-type=lib //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) -//@[current] check-pass +//@[current] check-fail //@[next] compile-flags: -Znext-solver //@[next] check-fail @@ -25,5 +25,5 @@ where T::Assoc<[u32; 1]>: Clone, { let _x = T::Assoc::new(()); -//[next]~^ ERROR mismatched types +//~^ ERROR: mismatched types } diff --git a/tests/ui/sized-hierarchy/overflow.current.stderr b/tests/ui/sized-hierarchy/overflow.current.stderr new file mode 100644 index 0000000000000..da58a6d2f7bf6 --- /dev/null +++ b/tests/ui/sized-hierarchy/overflow.current.stderr @@ -0,0 +1,45 @@ +error[E0275]: overflow evaluating the requirement `Element: MetaSized` + --> $DIR/overflow.rs:17:16 + | +LL | struct Element(> as ParseTokens>::Output); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: required for `Box` to implement `ParseTokens` + --> $DIR/overflow.rs:13:31 + | +LL | impl ParseTokens for Box { + | - ^^^^^^^^^^^ ^^^^^^ + | | + | unsatisfied trait bound introduced here + = note: 1 redundant requirement hidden + = note: required for `Box>` to implement `ParseTokens` + +error[E0275]: overflow evaluating the requirement `Box: ParseTokens` + --> $DIR/overflow.rs:19:22 + | +LL | impl ParseTokens for Element { + | ^^^^^^^ + | +note: required for `Box>` to implement `ParseTokens` + --> $DIR/overflow.rs:13:31 + | +LL | impl ParseTokens for Box { + | ----------- ^^^^^^^^^^^ ^^^^^^ + | | + | unsatisfied trait bound introduced here +note: required because it appears within the type `Element` + --> $DIR/overflow.rs:17:8 + | +LL | struct Element(> as ParseTokens>::Output); + | ^^^^^^^ +note: required by a bound in `ParseTokens` + --> $DIR/overflow.rs:10:1 + | +LL | / trait ParseTokens { +LL | | type Output; +LL | | } + | |_^ required by this bound in `ParseTokens` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/sized-hierarchy/overflow.rs b/tests/ui/sized-hierarchy/overflow.rs index f8e5dd5d4029b..31c2ca8a49171 100644 --- a/tests/ui/sized-hierarchy/overflow.rs +++ b/tests/ui/sized-hierarchy/overflow.rs @@ -1,13 +1,10 @@ //@ compile-flags: --crate-type=lib //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) -//@[current] check-pass +//@[current] check-fail //@[next] check-pass //@[next] compile-flags: -Znext-solver -// FIXME(sized_hierarchy): this is expected to fail in the old solver when there -// isn't a temporary revert of the `sized_hierarchy` feature - use std::marker::PhantomData; trait ParseTokens { @@ -18,6 +15,8 @@ impl ParseTokens for Box { } struct Element(> as ParseTokens>::Output); +//[current]~^ ERROR: overflow impl ParseTokens for Element { +//[current]~^ ERROR: overflow type Output = (); } diff --git a/tests/ui/traits/resolve-impl-before-constrain-check.rs b/tests/ui/traits/resolve-impl-before-constrain-check.rs index 87f9c241e402b..00005a7209363 100644 --- a/tests/ui/traits/resolve-impl-before-constrain-check.rs +++ b/tests/ui/traits/resolve-impl-before-constrain-check.rs @@ -15,6 +15,7 @@ use foo::*; fn test() -> impl Sized { <() as Callable>::call() +//~^ ERROR type annotations needed } fn main() {} diff --git a/tests/ui/traits/resolve-impl-before-constrain-check.stderr b/tests/ui/traits/resolve-impl-before-constrain-check.stderr index e8e569ba625ee..13fbfdb855cbf 100644 --- a/tests/ui/traits/resolve-impl-before-constrain-check.stderr +++ b/tests/ui/traits/resolve-impl-before-constrain-check.stderr @@ -4,6 +4,13 @@ error[E0207]: the type parameter `V` is not constrained by the impl trait, self LL | impl Callable for () { | ^ unconstrained type parameter -error: aborting due to 1 previous error +error[E0282]: type annotations needed + --> $DIR/resolve-impl-before-constrain-check.rs:17:6 + | +LL | <() as Callable>::call() + | ^^ cannot infer type for type parameter `V` + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0207`. +Some errors have detailed explanations: E0207, E0282. +For more information about an error, try `rustc --explain E0207`. From fe4aaffc22f6c05d19d03dc5b07d76383b624e9f Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 17 Jul 2025 09:21:51 +0000 Subject: [PATCH 2/3] trait_sel: sizedness goals prefer alias candidates For sizedness, default and auto trait predicates, now prefer non-param candidates if any exist. As these traits do not have generic parameters, it never makes sense to prefer an non-alias candidate, as there can never be a more permissive candidate. --- compiler/rustc_middle/src/ty/context.rs | 8 + compiler/rustc_middle/src/ty/mod.rs | 2 +- .../src/solve/trait_goals.rs | 41 ++- .../src/traits/select/mod.rs | 29 +- compiler/rustc_type_ir/src/interner.rs | 2 + compiler/rustc_type_ir/src/solve/mod.rs | 24 ++ ...her-ranked-auto-trait-3.assumptions.stderr | 292 +++++++++++++++++ ...-ranked-auto-trait-3.no_assumptions.stderr | 304 +++++++++++++++++- .../async-await/higher-ranked-auto-trait-3.rs | 3 +- .../generic-associated-types/issue-93262.rs | 4 +- .../issue-93262.stderr | 19 ++ ...-method-resolution-opaque-type.next.stderr | 14 + ...e-method-resolution-opaque-type.old.stderr | 2 +- ...rm-before-method-resolution-opaque-type.rs | 2 +- tests/ui/nll/issue-50716.rs | 2 +- tests/ui/nll/issue-50716.stderr | 18 +- ...lete-inference-issue-143992.current.stderr | 17 - ...omplete-inference-issue-143992.next.stderr | 17 - .../incomplete-inference-issue-143992.rs | 5 +- 19 files changed, 722 insertions(+), 83 deletions(-) create mode 100644 tests/ui/async-await/higher-ranked-auto-trait-3.assumptions.stderr create mode 100644 tests/ui/generic-associated-types/issue-93262.stderr create mode 100644 tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr delete mode 100644 tests/ui/sized-hierarchy/incomplete-inference-issue-143992.current.stderr delete mode 100644 tests/ui/sized-hierarchy/incomplete-inference-issue-143992.next.stderr diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 81c13e55dd8c5..f8043453d3b14 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -495,6 +495,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> { self.is_default_trait(def_id) } + fn is_sizedness_trait(self, def_id: DefId) -> bool { + self.is_sizedness_trait(def_id) + } + fn as_lang_item(self, def_id: DefId) -> Option { lang_item_to_trait_lang_item(self.lang_items().from_def_id(def_id)?) } @@ -1652,6 +1656,10 @@ impl<'tcx> TyCtxt<'tcx> { .any(|&default_trait| self.lang_items().get(default_trait) == Some(def_id)) } + pub fn is_sizedness_trait(self, def_id: DefId) -> bool { + matches!(self.as_lang_item(def_id), Some(LangItem::Sized | LangItem::MetaSized)) + } + /// Returns a range of the start/end indices specified with the /// `rustc_layout_scalar_valid_range` attribute. // FIXME(eddyb) this is an awkward spot for this method, maybe move it? diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index a7cde2ad48547..9848271dbfa4a 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -59,7 +59,7 @@ pub use rustc_type_ir::fast_reject::DeepRejectCtxt; )] use rustc_type_ir::inherent; pub use rustc_type_ir::relate::VarianceDiagInfo; -pub use rustc_type_ir::solve::SizedTraitKind; +pub use rustc_type_ir::solve::{CandidatePreferenceMode, SizedTraitKind}; pub use rustc_type_ir::*; #[allow(hidden_glob_reexports, unused_imports)] use rustc_type_ir::{InferCtxtLike, Interner}; diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 098dc9dbaf0c9..20bf819462157 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -4,7 +4,7 @@ use rustc_type_ir::data_structures::IndexSet; use rustc_type_ir::fast_reject::DeepRejectCtxt; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::TraitSolverLangItem; -use rustc_type_ir::solve::{CanonicalResponse, SizedTraitKind}; +use rustc_type_ir::solve::{CandidatePreferenceMode, CanonicalResponse, SizedTraitKind}; use rustc_type_ir::{ self as ty, Interner, Movability, TraitPredicate, TraitRef, TypeVisitableExt as _, TypingMode, Upcast as _, elaborate, @@ -1343,6 +1343,7 @@ where #[instrument(level = "debug", skip(self), ret)] pub(super) fn merge_trait_candidates( &mut self, + candidate_preference_mode: CandidatePreferenceMode, mut candidates: Vec>, ) -> Result<(CanonicalResponse, Option), NoSolution> { if let TypingMode::Coherence = self.typing_mode() { @@ -1368,6 +1369,26 @@ where return Ok((candidate.result, Some(TraitGoalProvenVia::Misc))); } + let potential_alias_bound_response = + candidates.iter().any(|c| matches!(c.source, CandidateSource::AliasBound)).then(|| { + let alias_bounds: Vec<_> = candidates + .iter() + .filter(|c| matches!(c.source, CandidateSource::AliasBound)) + .map(|c| c.result) + .collect(); + if let Some(response) = self.try_merge_responses(&alias_bounds) { + (response, Some(TraitGoalProvenVia::AliasBound)) + } else { + (self.bail_with_ambiguity(&alias_bounds), None) + } + }); + + if matches!(candidate_preference_mode, CandidatePreferenceMode::Marker) + && let Some(alias_bound_response) = potential_alias_bound_response + { + return Ok(alias_bound_response); + } + // If there are non-global where-bounds, prefer where-bounds // (including global ones) over everything else. let has_non_global_where_bounds = candidates @@ -1386,17 +1407,8 @@ where }; } - if candidates.iter().any(|c| matches!(c.source, CandidateSource::AliasBound)) { - let alias_bounds: Vec<_> = candidates - .iter() - .filter(|c| matches!(c.source, CandidateSource::AliasBound)) - .map(|c| c.result) - .collect(); - return if let Some(response) = self.try_merge_responses(&alias_bounds) { - Ok((response, Some(TraitGoalProvenVia::AliasBound))) - } else { - Ok((self.bail_with_ambiguity(&alias_bounds), None)) - }; + if let Some(response) = potential_alias_bound_response { + return Ok(response); } self.filter_specialized_impls(AllowInferenceConstraints::No, &mut candidates); @@ -1431,7 +1443,10 @@ where goal: Goal>, ) -> Result<(CanonicalResponse, Option), NoSolution> { let candidates = self.assemble_and_evaluate_candidates(goal, AssembleCandidatesFrom::All); - self.merge_trait_candidates(candidates) + + let candidate_preference_mode = + CandidatePreferenceMode::compute(self.cx(), goal.predicate.def_id()); + self.merge_trait_candidates(candidate_preference_mode, candidates) } fn try_stall_coroutine_witness( diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 2b563c5b8d5fa..277926a383167 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -28,8 +28,9 @@ use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::error::TypeErrorToStringExt; use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths}; use rustc_middle::ty::{ - self, DeepRejectCtxt, GenericArgsRef, PolyProjectionPredicate, SizedTraitKind, Ty, TyCtxt, - TypeFoldable, TypeVisitableExt, TypingMode, Upcast, elaborate, may_use_unstable_feature, + self, CandidatePreferenceMode, DeepRejectCtxt, GenericArgsRef, PolyProjectionPredicate, + SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingMode, Upcast, elaborate, + may_use_unstable_feature, }; use rustc_span::{Symbol, sym}; use tracing::{debug, instrument, trace}; @@ -474,7 +475,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } else { let has_non_region_infer = stack.obligation.predicate.has_non_region_infer(); - if let Some(candidate) = self.winnow_candidates(has_non_region_infer, candidates) { + let candidate_preference_mode = + CandidatePreferenceMode::compute(self.tcx(), stack.obligation.predicate.def_id()); + if let Some(candidate) = + self.winnow_candidates(has_non_region_infer, candidate_preference_mode, candidates) + { self.filter_reservation_impls(candidate) } else { Ok(None) @@ -1824,6 +1829,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { fn winnow_candidates( &mut self, has_non_region_infer: bool, + candidate_preference_mode: CandidatePreferenceMode, mut candidates: Vec>, ) -> Option> { if candidates.len() == 1 { @@ -1877,6 +1883,19 @@ impl<'tcx> SelectionContext<'_, 'tcx> { break; } + let alias_bound = candidates + .iter() + .filter_map(|c| if let ProjectionCandidate(i) = c.candidate { Some(i) } else { None }) + .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) }); + + if matches!(candidate_preference_mode, CandidatePreferenceMode::Marker) { + match alias_bound { + Some(Some(index)) => return Some(ProjectionCandidate(index)), + Some(None) => {} + None => return None, + } + } + // The next highest priority is for non-global where-bounds. However, while we don't // prefer global where-clauses here, we do bail with ambiguity when encountering both // a global and a non-global where-clause. @@ -1910,10 +1929,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> { // fairly arbitrary but once again necessary for backwards compatibility. // If there are multiple applicable candidates which don't affect type inference, // choose the one with the lowest index. - let alias_bound = candidates - .iter() - .filter_map(|c| if let ProjectionCandidate(i) = c.candidate { Some(i) } else { None }) - .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) }); match alias_bound { Some(Some(index)) => return Some(ProjectionCandidate(index)), Some(None) => {} diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index e3231244577f6..3a40a07acb042 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -308,6 +308,8 @@ pub trait Interner: fn is_default_trait(self, def_id: Self::DefId) -> bool; + fn is_sizedness_trait(self, def_id: Self::DefId) -> bool; + fn as_lang_item(self, def_id: Self::DefId) -> Option; fn associated_type_def_ids(self, def_id: Self::DefId) -> impl IntoIterator; diff --git a/compiler/rustc_type_ir/src/solve/mod.rs b/compiler/rustc_type_ir/src/solve/mod.rs index a6571ef261a16..9925698d62f37 100644 --- a/compiler/rustc_type_ir/src/solve/mod.rs +++ b/compiler/rustc_type_ir/src/solve/mod.rs @@ -125,6 +125,30 @@ pub struct PredefinedOpaquesData { pub opaque_types: Vec<(ty::OpaqueTypeKey, I::Ty)>, } +/// Which trait candidates should be preferred over other candidates? By default, prefer where +/// bounds over alias bounds. For marker traits, prefer alias bounds over where bounds. +#[derive(Clone, Copy, Debug)] +pub enum CandidatePreferenceMode { + /// Prefers where bounds over alias bounds + Default, + /// Prefers alias bounds over where bounds + Marker, +} + +impl CandidatePreferenceMode { + /// Given `trait_def_id`, which candidate preference mode should be used? + pub fn compute(cx: I, trait_def_id: I::DefId) -> CandidatePreferenceMode { + let is_sizedness_or_auto_or_default_goal = cx.is_sizedness_trait(trait_def_id) + || cx.trait_is_auto(trait_def_id) + || cx.is_default_trait(trait_def_id); + if is_sizedness_or_auto_or_default_goal { + CandidatePreferenceMode::Marker + } else { + CandidatePreferenceMode::Default + } + } +} + /// Possible ways the given goal can be proven. #[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] pub enum CandidateSource { diff --git a/tests/ui/async-await/higher-ranked-auto-trait-3.assumptions.stderr b/tests/ui/async-await/higher-ranked-auto-trait-3.assumptions.stderr new file mode 100644 index 0000000000000..be978f19d7ee5 --- /dev/null +++ b/tests/ui/async-await/higher-ranked-auto-trait-3.assumptions.stderr @@ -0,0 +1,292 @@ +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:54:5 + | +LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:54:5 + | +LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:63:5 + | +LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:63:5 + | +LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:40:31 + | +LL | impl IterCaller for UseIter + | ^^^^^^^^^^^^^^^^^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:46:5 + | +LL | type Future1<'cx> = impl Future + Send + 'cx + | ^^^^^^^^^^^^^^^^^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:50:5 + | +LL | type Future2<'cx> = impl Future + Send + 'cx + | ^^^^^^^^^^^^^^^^^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:54:50 + | +LL | fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> + | ^^^^^^^^^^^^^^^^^^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:63:50 + | +LL | fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> + | ^^^^^^^^^^^^^^^^^^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: higher-ranked subtype error + --> $DIR/higher-ranked-auto-trait-3.rs:54:5 + | +LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + +error: higher-ranked subtype error + --> $DIR/higher-ranked-auto-trait-3.rs:54:5 + | +LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:58:9 + | +LL | / async { +LL | | self.fi_1.get_iter(cx).await; +LL | | } + | |_________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:58:9 + | +LL | / async { +LL | | self.fi_1.get_iter(cx).await; +LL | | } + | |_________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: higher-ranked subtype error + --> $DIR/higher-ranked-auto-trait-3.rs:63:5 + | +LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + +error: higher-ranked subtype error + --> $DIR/higher-ranked-auto-trait-3.rs:63:5 + | +LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:67:9 + | +LL | / async { +LL | | self.fi_2.get_iter(cx).await; +LL | | } + | |_________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:67:9 + | +LL | / async { +LL | | self.fi_2.get_iter(cx).await; +LL | | } + | |_________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 17 previous errors + diff --git a/tests/ui/async-await/higher-ranked-auto-trait-3.no_assumptions.stderr b/tests/ui/async-await/higher-ranked-auto-trait-3.no_assumptions.stderr index c5c98ac807ea9..1c5aa3af7d1e5 100644 --- a/tests/ui/async-await/higher-ranked-auto-trait-3.no_assumptions.stderr +++ b/tests/ui/async-await/higher-ranked-auto-trait-3.no_assumptions.stderr @@ -1,5 +1,305 @@ error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:66:9 + --> $DIR/higher-ranked-auto-trait-3.rs:54:5 + | +LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:54:5 + | +LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:63:5 + | +LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:63:5 + | +LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:40:31 + | +LL | impl IterCaller for UseIter + | ^^^^^^^^^^^^^^^^^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:46:5 + | +LL | type Future1<'cx> = impl Future + Send + 'cx + | ^^^^^^^^^^^^^^^^^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:50:5 + | +LL | type Future2<'cx> = impl Future + Send + 'cx + | ^^^^^^^^^^^^^^^^^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:54:50 + | +LL | fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> + | ^^^^^^^^^^^^^^^^^^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:63:50 + | +LL | fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> + | ^^^^^^^^^^^^^^^^^^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: higher-ranked subtype error + --> $DIR/higher-ranked-auto-trait-3.rs:54:5 + | +LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + +error: higher-ranked subtype error + --> $DIR/higher-ranked-auto-trait-3.rs:54:5 + | +LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:58:9 + | +LL | / async { +LL | | self.fi_1.get_iter(cx).await; +LL | | } + | |_________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:58:9 + | +LL | / async { +LL | | self.fi_1.get_iter(cx).await; +LL | | } + | |_________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:58:9 + | +LL | / async { +LL | | self.fi_1.get_iter(cx).await; +LL | | } + | |_________^ + | + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: higher-ranked subtype error + --> $DIR/higher-ranked-auto-trait-3.rs:63:5 + | +LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + +error: higher-ranked subtype error + --> $DIR/higher-ranked-auto-trait-3.rs:63:5 + | +LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> +LL | | where +LL | | 's: 'cx, + | |________________^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:67:9 + | +LL | / async { +LL | | self.fi_2.get_iter(cx).await; +LL | | } + | |_________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:67:9 + | +LL | / async { +LL | | self.fi_2.get_iter(cx).await; +LL | | } + | |_________^ + | +note: the lifetime `'cx` defined here... + --> $DIR/higher-ranked-auto-trait-3.rs:43:13 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^^ +note: ...must outlive the lifetime `'s` defined here + --> $DIR/higher-ranked-auto-trait-3.rs:43:9 + | +LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, + | ^^ + = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: lifetime bound not satisfied + --> $DIR/higher-ranked-auto-trait-3.rs:67:9 | LL | / async { LL | | self.fi_2.get_iter(cx).await; @@ -8,5 +308,5 @@ LL | | } | = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) -error: aborting due to 1 previous error +error: aborting due to 19 previous errors diff --git a/tests/ui/async-await/higher-ranked-auto-trait-3.rs b/tests/ui/async-await/higher-ranked-auto-trait-3.rs index d42d423668051..2ab986a097a62 100644 --- a/tests/ui/async-await/higher-ranked-auto-trait-3.rs +++ b/tests/ui/async-await/higher-ranked-auto-trait-3.rs @@ -2,7 +2,8 @@ //@ edition: 2021 //@ revisions: assumptions no_assumptions //@[assumptions] compile-flags: -Zhigher-ranked-assumptions -//@[assumptions] check-pass +//@[assumptions] check-fail +//@[assumptions] known-bug: #110338 //@[no_assumptions] known-bug: #110338 #![feature(impl_trait_in_assoc_type)] diff --git a/tests/ui/generic-associated-types/issue-93262.rs b/tests/ui/generic-associated-types/issue-93262.rs index c4a6f0dbaa073..c964606fef0ba 100644 --- a/tests/ui/generic-associated-types/issue-93262.rs +++ b/tests/ui/generic-associated-types/issue-93262.rs @@ -1,4 +1,4 @@ -//@ check-pass +//@ check-fail pub trait Trait { type Assoc<'a> where Self: 'a; @@ -11,7 +11,7 @@ where pub struct Type; -impl Foo for Type +impl Foo for Type //~ ERROR: the parameter type `T` may not live long enough where for<'a> T::Assoc<'a>: Clone {} diff --git a/tests/ui/generic-associated-types/issue-93262.stderr b/tests/ui/generic-associated-types/issue-93262.stderr new file mode 100644 index 0000000000000..91d3e65f3de8e --- /dev/null +++ b/tests/ui/generic-associated-types/issue-93262.stderr @@ -0,0 +1,19 @@ +error[E0311]: the parameter type `T` may not live long enough + --> $DIR/issue-93262.rs:14:16 + | +LL | impl Foo for Type + | ^^^^^^ + | | + | the parameter type `T` must be valid for lifetime `'a`... + | ...so that the type `T` will meet its required lifetime bounds... + | +note: ...that is required by this bound + --> $DIR/issue-93262.rs:9:27 + | +LL | for<'a> T::Assoc<'a>: Clone + | ^^^^^ + = help: consider adding an explicit lifetime bound `T: 'a`... + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0311`. diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr new file mode 100644 index 0000000000000..6b05457f07080 --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed for `>::Out<_>` + --> $DIR/norm-before-method-resolution-opaque-type.rs:21:9 + | +LL | let x = *x; + | ^ + | +help: consider giving `x` an explicit type, where the placeholders `_` are specified + | +LL | let x: <_ as Trait<'static>>::Out<_> = *x; + | +++++++++++++++++++++++++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr index 79ded34d9cd9e..7fff7f1b404a4 100644 --- a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr @@ -1,5 +1,5 @@ error[E0507]: cannot move out of `*x` which is behind a shared reference - --> $DIR/norm-before-method-resolution-opaque-type.rs:22:13 + --> $DIR/norm-before-method-resolution-opaque-type.rs:21:13 | LL | let x = *x; | ^^ move occurs because `*x` has type `>::Out`, which does not implement the `Copy` trait diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs index f881fcb779fa8..05446c7e25f03 100644 --- a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs @@ -1,6 +1,5 @@ //@ revisions: old next //@[next] compile-flags: -Znext-solver -//@[next] check-pass #![feature(type_alias_impl_trait)] trait Trait<'a> { @@ -20,6 +19,7 @@ where for<'a> >::Out<()>: Copy, { let x = *x; //[old]~ ERROR: cannot move out of `*x` +//[next]~^ ERROR: type annotations needed todo!(); } diff --git a/tests/ui/nll/issue-50716.rs b/tests/ui/nll/issue-50716.rs index 76c6fc5e7b925..96168ebeaa165 100644 --- a/tests/ui/nll/issue-50716.rs +++ b/tests/ui/nll/issue-50716.rs @@ -5,7 +5,7 @@ trait A { type X: ?Sized; } -fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) //~ ERROR +fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) where for<'b> &'b T: A, <&'static T as A>::X: Sized diff --git a/tests/ui/nll/issue-50716.stderr b/tests/ui/nll/issue-50716.stderr index edd7fd765dade..536f88085ded3 100644 --- a/tests/ui/nll/issue-50716.stderr +++ b/tests/ui/nll/issue-50716.stderr @@ -1,18 +1,3 @@ -error[E0308]: mismatched types - --> $DIR/issue-50716.rs:8:27 - | -LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) - | ^^^^^^^^^^^^^^^^^^^^ lifetime mismatch - | - = note: expected trait `<<&'a T as A>::X as MetaSized>` - found trait `<<&'static T as A>::X as MetaSized>` -note: the lifetime `'a` as defined here... - --> $DIR/issue-50716.rs:8:8 - | -LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) - | ^^ - = note: ...does not necessarily outlive the static lifetime - error: lifetime may not live long enough --> $DIR/issue-50716.rs:13:14 | @@ -22,6 +7,5 @@ LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) LL | let _x = *s; | ^^ proving this value is `Sized` requires that `'a` must outlive `'static` -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.current.stderr b/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.current.stderr deleted file mode 100644 index cf56f42afc8a3..0000000000000 --- a/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.current.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/incomplete-inference-issue-143992.rs:27:28 - | -LL | let _x = T::Assoc::new(()); - | ------------- ^^ expected `[u32; 1]`, found `()` - | | - | arguments to this function are incorrect - | -note: associated function defined here - --> $DIR/incomplete-inference-issue-143992.rs:18:8 - | -LL | fn new(r: R) -> R { - | ^^^ ---- - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.next.stderr b/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.next.stderr deleted file mode 100644 index cf56f42afc8a3..0000000000000 --- a/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.next.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/incomplete-inference-issue-143992.rs:27:28 - | -LL | let _x = T::Assoc::new(()); - | ------------- ^^ expected `[u32; 1]`, found `()` - | | - | arguments to this function are incorrect - | -note: associated function defined here - --> $DIR/incomplete-inference-issue-143992.rs:18:8 - | -LL | fn new(r: R) -> R { - | ^^^ ---- - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs b/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs index bb3942966e726..7fcb10ccb2b2a 100644 --- a/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs +++ b/tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs @@ -1,9 +1,9 @@ //@ compile-flags: --crate-type=lib //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) -//@[current] check-fail +//@[current] check-pass //@[next] compile-flags: -Znext-solver -//@[next] check-fail +//@[next] check-pass // Test that we avoid incomplete inference when normalizing. Without this, // `Trait`'s implicit `MetaSized` supertrait requires proving `T::Assoc<_>: MetaSized` @@ -25,5 +25,4 @@ where T::Assoc<[u32; 1]>: Clone, { let _x = T::Assoc::new(()); -//~^ ERROR: mismatched types } From fa46ce04ff9325114acda783cf955043880ac155 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 27 Jun 2025 10:11:28 +0000 Subject: [PATCH 3/3] trait_sel: don't require predicates of aliases hold No longer require that we prove that the predicates of aliases hold when checking the well-formedness of the alias. This permits more uses of GATs and changes the output of yet more tests. --- .../src/traits/select/confirmation.rs | 24 -- ...ranked-auto-trait-14.no_assumptions.stderr | 33 -- .../higher-ranked-auto-trait-14.rs | 2 +- ...-ranked-auto-trait-2.no_assumptions.stderr | 49 --- .../async-await/higher-ranked-auto-trait-2.rs | 2 +- ...her-ranked-auto-trait-3.assumptions.stderr | 292 ---------------- ...-ranked-auto-trait-3.no_assumptions.stderr | 312 ------------------ .../async-await/higher-ranked-auto-trait-3.rs | 5 +- ...-ranked-auto-trait-7.no_assumptions.stderr | 8 - .../async-await/higher-ranked-auto-trait-7.rs | 2 +- .../assoc_type_bounds_sized_used.rs | 3 +- .../assoc_type_bounds_sized_used.stderr | 61 +++- ...ine-param-outlives-2.no_assumptions.stderr | 24 -- ...igher-ranked-coroutine-param-outlives-2.rs | 2 +- ...utine-param-outlives.no_assumptions.stderr | 8 - .../higher-ranked-coroutine-param-outlives.rs | 2 +- .../generic-associated-types/issue-93262.rs | 4 +- .../issue-93262.stderr | 19 -- .../bound-on-assoc-type-projection-1.rs | 21 ++ 19 files changed, 81 insertions(+), 792 deletions(-) delete mode 100644 tests/ui/async-await/higher-ranked-auto-trait-14.no_assumptions.stderr delete mode 100644 tests/ui/async-await/higher-ranked-auto-trait-2.no_assumptions.stderr delete mode 100644 tests/ui/async-await/higher-ranked-auto-trait-3.assumptions.stderr delete mode 100644 tests/ui/async-await/higher-ranked-auto-trait-3.no_assumptions.stderr delete mode 100644 tests/ui/async-await/higher-ranked-auto-trait-7.no_assumptions.stderr delete mode 100644 tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives-2.no_assumptions.stderr delete mode 100644 tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives.no_assumptions.stderr delete mode 100644 tests/ui/generic-associated-types/issue-93262.stderr create mode 100644 tests/ui/sized-hierarchy/bound-on-assoc-type-projection-1.rs diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 488094b15ac60..fe3c296c4071a 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -144,8 +144,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation: &PolyTraitObligation<'tcx>, idx: usize, ) -> Result, SelectionError<'tcx>> { - let tcx = self.tcx(); - let placeholder_trait_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate).trait_ref; let placeholder_self_ty = self.infcx.shallow_resolve(placeholder_trait_predicate.self_ty()); @@ -194,28 +192,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map_err(|_| SelectionError::Unimplemented)?, ); - // FIXME(compiler-errors): I don't think this is needed. - if let ty::Alias(ty::Projection, alias_ty) = placeholder_self_ty.kind() { - let predicates = tcx.predicates_of(alias_ty.def_id).instantiate_own(tcx, alias_ty.args); - for (predicate, _) in predicates { - let normalized = normalize_with_depth_to( - self, - obligation.param_env, - obligation.cause.clone(), - obligation.recursion_depth + 1, - predicate, - &mut obligations, - ); - obligations.push(Obligation::with_depth( - self.tcx(), - obligation.cause.clone(), - obligation.recursion_depth + 1, - obligation.param_env, - normalized, - )); - } - } - Ok(obligations) } diff --git a/tests/ui/async-await/higher-ranked-auto-trait-14.no_assumptions.stderr b/tests/ui/async-await/higher-ranked-auto-trait-14.no_assumptions.stderr deleted file mode 100644 index b47db2b19ffe2..0000000000000 --- a/tests/ui/async-await/higher-ranked-auto-trait-14.no_assumptions.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error: implementation of `FnOnce` is not general enough - --> $DIR/higher-ranked-auto-trait-14.rs:20:5 - | -LL | / async move { -LL | | let xs = unique_x.union(&cached) -LL | | // .copied() // works -LL | | .map(|x| *x) // error -LL | | ; -LL | | let blah = val.blah(xs.into_iter()).await; -LL | | } - | |_____^ implementation of `FnOnce` is not general enough - | - = note: closure with signature `fn(&'0 u32) -> u32` must implement `FnOnce<(&'1 u32,)>`, for any two lifetimes `'0` and `'1`... - = note: ...but it actually implements `FnOnce<(&u32,)>` - -error: implementation of `FnOnce` is not general enough - --> $DIR/higher-ranked-auto-trait-14.rs:20:5 - | -LL | / async move { -LL | | let xs = unique_x.union(&cached) -LL | | // .copied() // works -LL | | .map(|x| *x) // error -LL | | ; -LL | | let blah = val.blah(xs.into_iter()).await; -LL | | } - | |_____^ implementation of `FnOnce` is not general enough - | - = note: closure with signature `fn(&'0 u32) -> u32` must implement `FnOnce<(&'1 u32,)>`, for any two lifetimes `'0` and `'1`... - = note: ...but it actually implements `FnOnce<(&u32,)>` - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors - diff --git a/tests/ui/async-await/higher-ranked-auto-trait-14.rs b/tests/ui/async-await/higher-ranked-auto-trait-14.rs index 5ed12cd6e38cb..ad6aa34166330 100644 --- a/tests/ui/async-await/higher-ranked-auto-trait-14.rs +++ b/tests/ui/async-await/higher-ranked-auto-trait-14.rs @@ -3,7 +3,7 @@ //@ revisions: assumptions no_assumptions //@[assumptions] compile-flags: -Zhigher-ranked-assumptions //@[assumptions] check-pass -//@[no_assumptions] known-bug: #110338 +//@[no_assumptions] check-pass use std::collections::HashSet; use std::future::Future; diff --git a/tests/ui/async-await/higher-ranked-auto-trait-2.no_assumptions.stderr b/tests/ui/async-await/higher-ranked-auto-trait-2.no_assumptions.stderr deleted file mode 100644 index 2fc44412b9dae..0000000000000 --- a/tests/ui/async-await/higher-ranked-auto-trait-2.no_assumptions.stderr +++ /dev/null @@ -1,49 +0,0 @@ -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-2.rs:16:9 - | -LL | / async move { -LL | | // asks for an unspecified lifetime to outlive itself? weird diagnostics -LL | | self.run(t).await; -LL | | } - | |_________^ - | - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-2.rs:16:9 - | -LL | / async move { -LL | | // asks for an unspecified lifetime to outlive itself? weird diagnostics -LL | | self.run(t).await; -LL | | } - | |_________^ - | - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-2.rs:16:9 - | -LL | / async move { -LL | | // asks for an unspecified lifetime to outlive itself? weird diagnostics -LL | | self.run(t).await; -LL | | } - | |_________^ - | - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-2.rs:16:9 - | -LL | / async move { -LL | | // asks for an unspecified lifetime to outlive itself? weird diagnostics -LL | | self.run(t).await; -LL | | } - | |_________^ - | - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 4 previous errors - diff --git a/tests/ui/async-await/higher-ranked-auto-trait-2.rs b/tests/ui/async-await/higher-ranked-auto-trait-2.rs index 6c75597265bc2..664df9cc85e00 100644 --- a/tests/ui/async-await/higher-ranked-auto-trait-2.rs +++ b/tests/ui/async-await/higher-ranked-auto-trait-2.rs @@ -3,7 +3,7 @@ //@ revisions: assumptions no_assumptions //@[assumptions] compile-flags: -Zhigher-ranked-assumptions //@[assumptions] check-pass -//@[no_assumptions] known-bug: #110338 +//@[no_assumptions] check-pass use std::future::Future; diff --git a/tests/ui/async-await/higher-ranked-auto-trait-3.assumptions.stderr b/tests/ui/async-await/higher-ranked-auto-trait-3.assumptions.stderr deleted file mode 100644 index be978f19d7ee5..0000000000000 --- a/tests/ui/async-await/higher-ranked-auto-trait-3.assumptions.stderr +++ /dev/null @@ -1,292 +0,0 @@ -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:54:5 - | -LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:54:5 - | -LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:63:5 - | -LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:63:5 - | -LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:40:31 - | -LL | impl IterCaller for UseIter - | ^^^^^^^^^^^^^^^^^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:46:5 - | -LL | type Future1<'cx> = impl Future + Send + 'cx - | ^^^^^^^^^^^^^^^^^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:50:5 - | -LL | type Future2<'cx> = impl Future + Send + 'cx - | ^^^^^^^^^^^^^^^^^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:54:50 - | -LL | fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> - | ^^^^^^^^^^^^^^^^^^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:63:50 - | -LL | fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> - | ^^^^^^^^^^^^^^^^^^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: higher-ranked subtype error - --> $DIR/higher-ranked-auto-trait-3.rs:54:5 - | -LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - -error: higher-ranked subtype error - --> $DIR/higher-ranked-auto-trait-3.rs:54:5 - | -LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:58:9 - | -LL | / async { -LL | | self.fi_1.get_iter(cx).await; -LL | | } - | |_________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:58:9 - | -LL | / async { -LL | | self.fi_1.get_iter(cx).await; -LL | | } - | |_________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: higher-ranked subtype error - --> $DIR/higher-ranked-auto-trait-3.rs:63:5 - | -LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - -error: higher-ranked subtype error - --> $DIR/higher-ranked-auto-trait-3.rs:63:5 - | -LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:67:9 - | -LL | / async { -LL | | self.fi_2.get_iter(cx).await; -LL | | } - | |_________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:67:9 - | -LL | / async { -LL | | self.fi_2.get_iter(cx).await; -LL | | } - | |_________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 17 previous errors - diff --git a/tests/ui/async-await/higher-ranked-auto-trait-3.no_assumptions.stderr b/tests/ui/async-await/higher-ranked-auto-trait-3.no_assumptions.stderr deleted file mode 100644 index 1c5aa3af7d1e5..0000000000000 --- a/tests/ui/async-await/higher-ranked-auto-trait-3.no_assumptions.stderr +++ /dev/null @@ -1,312 +0,0 @@ -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:54:5 - | -LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:54:5 - | -LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:63:5 - | -LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:63:5 - | -LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:40:31 - | -LL | impl IterCaller for UseIter - | ^^^^^^^^^^^^^^^^^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:46:5 - | -LL | type Future1<'cx> = impl Future + Send + 'cx - | ^^^^^^^^^^^^^^^^^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:50:5 - | -LL | type Future2<'cx> = impl Future + Send + 'cx - | ^^^^^^^^^^^^^^^^^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:54:50 - | -LL | fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> - | ^^^^^^^^^^^^^^^^^^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:63:50 - | -LL | fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> - | ^^^^^^^^^^^^^^^^^^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: higher-ranked subtype error - --> $DIR/higher-ranked-auto-trait-3.rs:54:5 - | -LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - -error: higher-ranked subtype error - --> $DIR/higher-ranked-auto-trait-3.rs:54:5 - | -LL | / fn call_1<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future1<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:58:9 - | -LL | / async { -LL | | self.fi_1.get_iter(cx).await; -LL | | } - | |_________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:58:9 - | -LL | / async { -LL | | self.fi_1.get_iter(cx).await; -LL | | } - | |_________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:58:9 - | -LL | / async { -LL | | self.fi_1.get_iter(cx).await; -LL | | } - | |_________^ - | - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: higher-ranked subtype error - --> $DIR/higher-ranked-auto-trait-3.rs:63:5 - | -LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - -error: higher-ranked subtype error - --> $DIR/higher-ranked-auto-trait-3.rs:63:5 - | -LL | / fn call_2<'s, 'cx>(&'s self, cx: &'cx ()) -> Self::Future2<'cx> -LL | | where -LL | | 's: 'cx, - | |________________^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:67:9 - | -LL | / async { -LL | | self.fi_2.get_iter(cx).await; -LL | | } - | |_________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:67:9 - | -LL | / async { -LL | | self.fi_2.get_iter(cx).await; -LL | | } - | |_________^ - | -note: the lifetime `'cx` defined here... - --> $DIR/higher-ranked-auto-trait-3.rs:43:13 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^^ -note: ...must outlive the lifetime `'s` defined here - --> $DIR/higher-ranked-auto-trait-3.rs:43:9 - | -LL | for<'s, 'cx> FI1::Future<'s, 'cx>: Send, - | ^^ - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-auto-trait-3.rs:67:9 - | -LL | / async { -LL | | self.fi_2.get_iter(cx).await; -LL | | } - | |_________^ - | - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: aborting due to 19 previous errors - diff --git a/tests/ui/async-await/higher-ranked-auto-trait-3.rs b/tests/ui/async-await/higher-ranked-auto-trait-3.rs index 2ab986a097a62..5d85a405ec4ac 100644 --- a/tests/ui/async-await/higher-ranked-auto-trait-3.rs +++ b/tests/ui/async-await/higher-ranked-auto-trait-3.rs @@ -2,9 +2,8 @@ //@ edition: 2021 //@ revisions: assumptions no_assumptions //@[assumptions] compile-flags: -Zhigher-ranked-assumptions -//@[assumptions] check-fail -//@[assumptions] known-bug: #110338 -//@[no_assumptions] known-bug: #110338 +//@[assumptions] check-pass +//@[no_assumptions] check-pass #![feature(impl_trait_in_assoc_type)] diff --git a/tests/ui/async-await/higher-ranked-auto-trait-7.no_assumptions.stderr b/tests/ui/async-await/higher-ranked-auto-trait-7.no_assumptions.stderr deleted file mode 100644 index dcb8075566e6d..0000000000000 --- a/tests/ui/async-await/higher-ranked-auto-trait-7.no_assumptions.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: `S` does not live long enough - --> $DIR/higher-ranked-auto-trait-7.rs:26:5 - | -LL | future::<'a, S, _>(async move { - | ^^^^^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/async-await/higher-ranked-auto-trait-7.rs b/tests/ui/async-await/higher-ranked-auto-trait-7.rs index abded5a88d3ae..c90d575679519 100644 --- a/tests/ui/async-await/higher-ranked-auto-trait-7.rs +++ b/tests/ui/async-await/higher-ranked-auto-trait-7.rs @@ -3,7 +3,7 @@ //@ revisions: assumptions no_assumptions //@[assumptions] compile-flags: -Zhigher-ranked-assumptions //@[assumptions] check-pass -//@[no_assumptions] known-bug: #110338 +//@[no_assumptions] check-pass #![allow(dropping_copy_types)] diff --git a/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs index d59fc1712ea7e..8243803c86d70 100644 --- a/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs +++ b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs @@ -9,7 +9,8 @@ trait Bop { fn bop() { let _ = ::Bar::default(); - //~^ ERROR: trait bounds were not satisfied + //~^ ERROR: the size for values of type `T` cannot be known at compilation time + //~| ERROR: the size for values of type `T` cannot be known at compilation time //~| ERROR: the size for values of type `T` cannot be known at compilation time } diff --git a/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr index 7b152adea4925..fe048c87775a9 100644 --- a/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr +++ b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr @@ -24,21 +24,58 @@ help: consider relaxing the implicit `Sized` restriction LL | type Bar: Default + ?Sized | ++++++++ -error[E0599]: the function or associated item `default` exists for associated type `::Bar`, but its trait bounds were not satisfied - --> $DIR/assoc_type_bounds_sized_used.rs:11:30 +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/assoc_type_bounds_sized_used.rs:11:13 | +LL | fn bop() { + | - this type parameter needs to be `Sized` LL | let _ = ::Bar::default(); - | ^^^^^^^ function or associated item cannot be called on `::Bar` due to unsatisfied trait bounds + | ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | +note: required by a bound in `Bop::Bar` + --> $DIR/assoc_type_bounds_sized_used.rs:7:15 + | +LL | type Bar: Default + | --- required by a bound in this associated type +LL | where +LL | Self: Sized; + | ^^^^^ required by this bound in `Bop::Bar` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL - fn bop() { +LL + fn bop() { | - = note: the following trait bounds were not satisfied: - `T: Sized` - which is required by `::Bar: Default` -help: consider restricting the type parameter to satisfy the trait bound +help: consider relaxing the implicit `Sized` restriction + | +LL | type Bar: Default + ?Sized + | ++++++++ + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/assoc_type_bounds_sized_used.rs:11:13 | -LL | fn bop() where T: Sized { - | ++++++++++++++ +LL | fn bop() { + | - this type parameter needs to be `Sized` +LL | let _ = ::Bar::default(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | +note: required by a bound in `Bop::Bar` + --> $DIR/assoc_type_bounds_sized_used.rs:7:15 + | +LL | type Bar: Default + | --- required by a bound in this associated type +LL | where +LL | Self: Sized; + | ^^^^^ required by this bound in `Bop::Bar` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL - fn bop() { +LL + fn bop() { + | +help: consider relaxing the implicit `Sized` restriction + | +LL | type Bar: Default + ?Sized + | ++++++++ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0277, E0599. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives-2.no_assumptions.stderr b/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives-2.no_assumptions.stderr deleted file mode 100644 index 8b62fb6a25473..0000000000000 --- a/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives-2.no_assumptions.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error: lifetime bound not satisfied - --> $DIR/higher-ranked-coroutine-param-outlives-2.rs:14:5 - | -LL | / async { // a coroutine checked for autotrait impl `Send` -LL | | let x = None::>; // a type referencing GAT -LL | | async {}.await; // a yield point -LL | | } - | |_____^ - | - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: lifetime bound not satisfied - --> $DIR/higher-ranked-coroutine-param-outlives-2.rs:21:5 - | -LL | / async { // a coroutine checked for autotrait impl `Send` -LL | | let x = None::>; // a type referencing GAT -LL | | async {}.await; // a yield point -LL | | } - | |_____^ - | - = note: this is a known limitation that will be removed in the future (see issue #100013 for more information) - -error: aborting due to 2 previous errors - diff --git a/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives-2.rs b/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives-2.rs index a5ed162d62c90..7495d2fd97963 100644 --- a/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives-2.rs +++ b/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives-2.rs @@ -2,7 +2,7 @@ //@ revisions: assumptions no_assumptions //@[assumptions] compile-flags: -Zhigher-ranked-assumptions //@[assumptions] check-pass -//@[no_assumptions] known-bug: #110338 +//@[no_assumptions] check-pass pub trait FutureIterator { type Future<'s, 'cx>: Send diff --git a/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives.no_assumptions.stderr b/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives.no_assumptions.stderr deleted file mode 100644 index f747ba9a73341..0000000000000 --- a/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives.no_assumptions.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: `C` does not live long enough - --> $DIR/higher-ranked-coroutine-param-outlives.rs:21:5 - | -LL | async move { c.connect().await } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives.rs b/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives.rs index 5f683bd82fa46..9b08a549bc27c 100644 --- a/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives.rs +++ b/tests/ui/generic-associated-types/higher-ranked-coroutine-param-outlives.rs @@ -2,7 +2,7 @@ //@ revisions: assumptions no_assumptions //@[assumptions] compile-flags: -Zhigher-ranked-assumptions //@[assumptions] check-pass -//@[no_assumptions] known-bug: #110338 +//@[no_assumptions] check-pass use std::future::Future; diff --git a/tests/ui/generic-associated-types/issue-93262.rs b/tests/ui/generic-associated-types/issue-93262.rs index c964606fef0ba..c4a6f0dbaa073 100644 --- a/tests/ui/generic-associated-types/issue-93262.rs +++ b/tests/ui/generic-associated-types/issue-93262.rs @@ -1,4 +1,4 @@ -//@ check-fail +//@ check-pass pub trait Trait { type Assoc<'a> where Self: 'a; @@ -11,7 +11,7 @@ where pub struct Type; -impl Foo for Type //~ ERROR: the parameter type `T` may not live long enough +impl Foo for Type where for<'a> T::Assoc<'a>: Clone {} diff --git a/tests/ui/generic-associated-types/issue-93262.stderr b/tests/ui/generic-associated-types/issue-93262.stderr deleted file mode 100644 index 91d3e65f3de8e..0000000000000 --- a/tests/ui/generic-associated-types/issue-93262.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0311]: the parameter type `T` may not live long enough - --> $DIR/issue-93262.rs:14:16 - | -LL | impl Foo for Type - | ^^^^^^ - | | - | the parameter type `T` must be valid for lifetime `'a`... - | ...so that the type `T` will meet its required lifetime bounds... - | -note: ...that is required by this bound - --> $DIR/issue-93262.rs:9:27 - | -LL | for<'a> T::Assoc<'a>: Clone - | ^^^^^ - = help: consider adding an explicit lifetime bound `T: 'a`... - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0311`. diff --git a/tests/ui/sized-hierarchy/bound-on-assoc-type-projection-1.rs b/tests/ui/sized-hierarchy/bound-on-assoc-type-projection-1.rs new file mode 100644 index 0000000000000..4a20ed2cafb16 --- /dev/null +++ b/tests/ui/sized-hierarchy/bound-on-assoc-type-projection-1.rs @@ -0,0 +1,21 @@ +//@ check-pass +//@ compile-flags: --crate-type=lib +//@ revisions: old next +//@[next] compile-flags: -Znext-solver + +use std::marker::PhantomData; + +pub trait ZeroMapKV<'a> { + type Container; +} + +pub trait ZeroFrom<'zf, C: ?Sized> {} + +pub struct ZeroMap<'a, K: ZeroMapKV<'a>>(PhantomData<&'a K>); + +impl<'zf, 's, K> ZeroFrom<'zf, ZeroMap<'s, K>> for ZeroMap<'zf, K> +where + K: for<'b> ZeroMapKV<'b>, + >::Container: ZeroFrom<'zf, >::Container>, +{ +}