From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- .../type-alias-impl-trait/auto-trait-leakage3.rs | 4 +- .../auto-trait-leakage3.stderr | 24 ++++---- .../auxiliary/drop-shim-relates-opaque-aux.rs | 21 +++++++ .../cross_inference_pattern_bug.rs | 2 +- .../destructure_tait-ice-113594.rs | 19 ++++++ .../destructure_tait-layout_of-ice-113594.rs | 23 ++++++++ .../different_lifetimes_defining_uses.rs | 6 +- .../different_lifetimes_defining_uses.stderr | 4 +- .../drop-shim-relates-opaque-issue-114375.rs | 10 ++++ .../ui/type-alias-impl-trait/escaping-bound-var.rs | 22 +++++++ .../escaping-bound-var.stderr | 8 +++ .../generic_duplicate_lifetime_param.rs | 6 +- .../generic_duplicate_lifetime_param.stderr | 14 ++--- .../generic_duplicate_param_use.rs | 6 +- .../generic_duplicate_param_use.stderr | 26 ++++----- .../generic_lifetime_param.rs | 5 +- .../implied_lifetime_wf_check3.rs | 4 +- .../imply_bounds_from_bounds.rs | 20 ++++--- .../indirect-recursion-issue-112047.rs | 29 +++++++++ .../indirect-recursion-issue-112047.stderr | 19 ++++++ .../type-alias-impl-trait/inference-cycle.stderr | 24 ++++---- .../ui/type-alias-impl-trait/issue-53092-2.stderr | 5 ++ tests/ui/type-alias-impl-trait/issue-63279.stderr | 4 +- tests/ui/type-alias-impl-trait/issue-89686.rs | 2 +- tests/ui/type-alias-impl-trait/issue-89686.stderr | 2 +- tests/ui/type-alias-impl-trait/issue-94429.stderr | 2 +- .../missing_lifetime_bound.rs | 5 +- .../missing_lifetime_bound.stderr | 9 +-- .../multiple-def-uses-in-one-fn-lifetimes.rs | 6 +- .../multiple-def-uses-in-one-fn-lifetimes.stderr | 2 +- .../multiple-def-uses-in-one-fn-pass.rs | 6 +- .../mututally-recursive-overflow.rs | 40 +++++++++++++ .../mututally-recursive-overflow.stderr | 5 ++ .../nested-impl-trait-in-tait.rs | 9 +++ .../nested-impl-trait-in-tait.stderr | 47 +++++++++++++++ .../type-alias-impl-trait/normalize-alias-type.rs | 32 ++++++++++ tests/ui/type-alias-impl-trait/privacy.rs | 4 +- tests/ui/type-alias-impl-trait/privacy.stderr | 18 +++--- tests/ui/type-alias-impl-trait/reveal_local.stderr | 60 +++++++------------ ...tait_equality_in_canonical_query.current.stderr | 29 +++++++++ .../rpit_tait_equality_in_canonical_query.rs | 32 ++++++++++ .../rpit_tait_equality_in_canonical_query_2.rs | 18 ++++++ tests/ui/type-alias-impl-trait/self_implication.rs | 4 +- tests/ui/type-alias-impl-trait/tait-normalize.rs | 14 +++++ tests/ui/type-alias-impl-trait/variance.rs | 44 ++++++++++++++ tests/ui/type-alias-impl-trait/variance.stderr | 68 ++++++++++++++++++++++ 46 files changed, 615 insertions(+), 148 deletions(-) create mode 100644 tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs create mode 100644 tests/ui/type-alias-impl-trait/destructure_tait-ice-113594.rs create mode 100644 tests/ui/type-alias-impl-trait/destructure_tait-layout_of-ice-113594.rs create mode 100644 tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs create mode 100644 tests/ui/type-alias-impl-trait/escaping-bound-var.rs create mode 100644 tests/ui/type-alias-impl-trait/escaping-bound-var.stderr create mode 100644 tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.rs create mode 100644 tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.stderr create mode 100644 tests/ui/type-alias-impl-trait/mututally-recursive-overflow.rs create mode 100644 tests/ui/type-alias-impl-trait/mututally-recursive-overflow.stderr create mode 100644 tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.rs create mode 100644 tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.stderr create mode 100644 tests/ui/type-alias-impl-trait/normalize-alias-type.rs create mode 100644 tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.current.stderr create mode 100644 tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs create mode 100644 tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs create mode 100644 tests/ui/type-alias-impl-trait/tait-normalize.rs create mode 100644 tests/ui/type-alias-impl-trait/variance.rs create mode 100644 tests/ui/type-alias-impl-trait/variance.stderr (limited to 'tests/ui/type-alias-impl-trait') diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs index fd3f9c614..660950d59 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs @@ -5,8 +5,8 @@ mod m { pub type Foo = impl std::fmt::Debug; - //~^ ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391] - //~| ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391] + //~^ ERROR: cycle detected when computing type of opaque `m::Foo::{opaque#0}` [E0391] + //~| ERROR: cycle detected when computing type of opaque `m::Foo::{opaque#0}` [E0391] pub fn foo() -> Foo { 22_u32 diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr index 5bd0f76c3..d86988266 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr @@ -1,4 +1,4 @@ -error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `m::Foo::{opaque#0}` --> $DIR/auto-trait-leakage3.rs:7:20 | LL | pub type Foo = impl std::fmt::Debug; @@ -10,15 +10,15 @@ note: ...which requires type-checking `m::bar`... LL | is_send(foo()); | ^^^^^^^ = note: ...which requires evaluating trait selection obligation `m::Foo: core::marker::Send`... - = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in module `m` - --> $DIR/auto-trait-leakage3.rs:6:1 + = note: ...which again requires computing type of opaque `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `m::Foo::{opaque#0}` + --> $DIR/auto-trait-leakage3.rs:7:20 | -LL | mod m { - | ^^^^^ +LL | pub type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `m::Foo::{opaque#0}` --> $DIR/auto-trait-leakage3.rs:7:20 | LL | pub type Foo = impl std::fmt::Debug; @@ -29,12 +29,12 @@ note: ...which requires type-checking `m::bar`... | LL | pub fn bar() { | ^^^^^^^^^^^^ - = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in module `m` - --> $DIR/auto-trait-leakage3.rs:6:1 + = note: ...which again requires computing type of opaque `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `m::Foo::{opaque#0}` + --> $DIR/auto-trait-leakage3.rs:7:20 | -LL | mod m { - | ^^^^^ +LL | pub type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: cannot check whether the hidden type of `auto_trait_leakage3[211d]::m::Foo::{opaque#0}` satisfies auto traits diff --git a/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs b/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs new file mode 100644 index 000000000..54a225100 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs @@ -0,0 +1,21 @@ +// crate foo + +#![feature(type_alias_impl_trait)] + +type Tait = impl Sized; +fn _constrain() -> Tait {} + +struct WrapperWithDrop(T); +impl Drop for WrapperWithDrop { + fn drop(&mut self) {} +} + +pub struct Foo(WrapperWithDrop); + +trait Id { + type Id: ?Sized; +} +impl Id for T { + type Id = T; +} +pub struct Bar(WrapperWithDrop<::Id>); diff --git a/tests/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs b/tests/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs index 9a50c0f98..31fea42fa 100644 --- a/tests/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs +++ b/tests/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs @@ -1,5 +1,5 @@ // compile-flags: --edition=2021 -// check-pass +// build-pass #![feature(type_alias_impl_trait)] fn main() { diff --git a/tests/ui/type-alias-impl-trait/destructure_tait-ice-113594.rs b/tests/ui/type-alias-impl-trait/destructure_tait-ice-113594.rs new file mode 100644 index 000000000..7c2d68cce --- /dev/null +++ b/tests/ui/type-alias-impl-trait/destructure_tait-ice-113594.rs @@ -0,0 +1,19 @@ +// build-pass +// edition: 2021 + +#![feature(type_alias_impl_trait)] + +pub struct Foo { + /// This type must have nontrivial drop glue + field: String, +} + +pub type Tait = impl Sized; + +pub async fn ice_cold(beverage: Tait) { + // Must destructure at least one field of `Foo` + let Foo { field } = beverage; + _ = field; +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/destructure_tait-layout_of-ice-113594.rs b/tests/ui/type-alias-impl-trait/destructure_tait-layout_of-ice-113594.rs new file mode 100644 index 000000000..8568b26be --- /dev/null +++ b/tests/ui/type-alias-impl-trait/destructure_tait-layout_of-ice-113594.rs @@ -0,0 +1,23 @@ +// build-pass +// edition: 2021 + +#![feature(type_alias_impl_trait)] + +fn foo(x: T) { + type Opaque = impl Sized; + let foo: Opaque = (x,); + let (a,): (T,) = foo; +} + +const fn bar(x: T) { + type Opaque = impl Copy; + let foo: Opaque = (x, 2u32); + let (a, b): (T, u32) = foo; +} + +fn main() { + foo::(1); + bar::(1); + const CONST: () = bar::(42u32); + CONST +} diff --git a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs index 5f75fdc71..4f424b8c6 100644 --- a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs +++ b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs @@ -1,11 +1,7 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type OneLifetime<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +type OneLifetime<'a, 'b> = impl std::fmt::Debug; fn foo<'a, 'b>(a: &'a u32, b: &'b u32) -> OneLifetime<'a, 'b> { a diff --git a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr index 546598e8a..0c50a84e8 100644 --- a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr +++ b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/different_lifetimes_defining_uses.rs:15:5 + --> $DIR/different_lifetimes_defining_uses.rs:11:5 | LL | b | ^ expected `&'a u32`, got `&'b u32` | note: previous use here - --> $DIR/different_lifetimes_defining_uses.rs:11:5 + --> $DIR/different_lifetimes_defining_uses.rs:7:5 | LL | a | ^ diff --git a/tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs b/tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs new file mode 100644 index 000000000..51d287049 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs @@ -0,0 +1,10 @@ +// aux-build:drop-shim-relates-opaque-aux.rs +// compile-flags: -Zvalidate-mir --crate-type=lib +// build-pass + +extern crate drop_shim_relates_opaque_aux; + +pub fn drop_foo(_: drop_shim_relates_opaque_aux::Foo) {} +pub fn drop_bar(_: drop_shim_relates_opaque_aux::Bar) {} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/escaping-bound-var.rs b/tests/ui/type-alias-impl-trait/escaping-bound-var.rs new file mode 100644 index 000000000..bf27e76db --- /dev/null +++ b/tests/ui/type-alias-impl-trait/escaping-bound-var.rs @@ -0,0 +1,22 @@ +#![feature(type_alias_impl_trait)] + +pub trait Trait<'a> { + type Assoc; +} + +trait Test<'a> {} + +pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>; +//~^ ERROR cannot capture late-bound lifetime in type alias impl trait + +impl Trait<'_> for () { + type Assoc = (); +} + +impl Test<'_> for () {} + +fn constrain() -> Foo { + () +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr b/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr new file mode 100644 index 000000000..8205a60cc --- /dev/null +++ b/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr @@ -0,0 +1,8 @@ +error: cannot capture late-bound lifetime in type alias impl trait + --> $DIR/escaping-bound-var.rs:9:57 + | +LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>; + | -- lifetime defined here ^^ + +error: aborting due to previous error + diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs index 14ced3418..169d4f8d5 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs @@ -2,11 +2,7 @@ fn main() {} -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +type Two<'a, 'b> = impl std::fmt::Debug; fn one<'a>(t: &'a ()) -> Two<'a, 'a> { //~^ ERROR non-defining opaque type use diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr index 4da69a705..b03bf2466 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr @@ -1,25 +1,25 @@ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_lifetime_param.rs:11:26 + --> $DIR/generic_duplicate_lifetime_param.rs:7:26 | LL | fn one<'a>(t: &'a ()) -> Two<'a, 'a> { | ^^^^^^^^^^^ generic argument `'a` used twice | note: for this opaque type - --> $DIR/generic_duplicate_lifetime_param.rs:9:20 + --> $DIR/generic_duplicate_lifetime_param.rs:5:20 | -LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | type Two<'a, 'b> = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_lifetime_param.rs:13:5 + --> $DIR/generic_duplicate_lifetime_param.rs:9:5 | LL | t | ^ | note: lifetime used multiple times - --> $DIR/generic_duplicate_lifetime_param.rs:9:10 + --> $DIR/generic_duplicate_lifetime_param.rs:5:10 | -LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +LL | type Two<'a, 'b> = impl std::fmt::Debug; | ^^ ^^ error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs index 1e391b55a..e3c6f4d87 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs @@ -14,11 +14,7 @@ fn main() {} // test that unused generic parameters are ok type TwoTys = impl Debug; -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>; +type TwoLifetimes<'a, 'b> = impl Debug; type TwoConsts = impl Debug; diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr index d8330771d..495308a6c 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr @@ -1,5 +1,5 @@ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:25:30 + --> $DIR/generic_duplicate_param_use.rs:21:30 | LL | fn one_ty(t: T) -> TwoTys { | ^^^^^^^^^^^^ generic argument `T` used twice @@ -11,7 +11,7 @@ LL | type TwoTys = impl Debug; | ^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:27:5 + --> $DIR/generic_duplicate_param_use.rs:23:5 | LL | t | ^ @@ -23,49 +23,49 @@ LL | type TwoTys = impl Debug; | ^ ^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:31:36 + --> $DIR/generic_duplicate_param_use.rs:27:36 | LL | fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> { | ^^^^^^^^^^^^^^^^^^^^ generic argument `'a` used twice | note: for this opaque type - --> $DIR/generic_duplicate_param_use.rs:21:29 + --> $DIR/generic_duplicate_param_use.rs:17:29 | -LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | type TwoLifetimes<'a, 'b> = impl Debug; + | ^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:33:5 + --> $DIR/generic_duplicate_param_use.rs:29:5 | LL | t | ^ | note: lifetime used multiple times - --> $DIR/generic_duplicate_param_use.rs:21:19 + --> $DIR/generic_duplicate_param_use.rs:17:19 | -LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>; +LL | type TwoLifetimes<'a, 'b> = impl Debug; | ^^ ^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:37:50 + --> $DIR/generic_duplicate_param_use.rs:33:50 | LL | fn one_const(t: *mut [u8; N]) -> TwoConsts { | ^^^^^^^^^^^^^^^ generic argument `N` used twice | note: for this opaque type - --> $DIR/generic_duplicate_param_use.rs:23:50 + --> $DIR/generic_duplicate_param_use.rs:19:50 | LL | type TwoConsts = impl Debug; | ^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:39:5 + --> $DIR/generic_duplicate_param_use.rs:35:5 | LL | t | ^ | note: constant used multiple times - --> $DIR/generic_duplicate_param_use.rs:23:16 + --> $DIR/generic_duplicate_param_use.rs:19:16 | LL | type TwoConsts = impl Debug; | ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs b/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs index 106efefba..e109c38c9 100644 --- a/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs +++ b/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs @@ -1,11 +1,10 @@ -// check-pass +// build-pass (FIXME(62277): could be check-pass?) #![feature(type_alias_impl_trait)] fn main() {} -type Region<'a> = impl std::fmt::Debug + 'a; - +type Region<'a> = impl std::fmt::Debug; fn region<'b>(a: &'b ()) -> Region<'b> { a diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs index 6f9434255..469a493b0 100644 --- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs +++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs @@ -1,7 +1,7 @@ #![feature(type_alias_impl_trait)] mod test_lifetime_param { - type Ty<'a> = impl Sized + 'a; + type Ty<'a> = impl Sized; fn defining(a: &str) -> Ty<'_> { a } fn assert_static<'a: 'static>() {} fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() } @@ -9,7 +9,7 @@ mod test_lifetime_param { } mod test_higher_kinded_lifetime_param { - type Ty<'a> = impl Sized + 'a; + type Ty<'a> = impl Sized; fn defining(a: &str) -> Ty<'_> { a } fn assert_static<'a: 'static>() {} fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() } diff --git a/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs b/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs index 4f99236f4..06c119287 100644 --- a/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs +++ b/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs @@ -1,16 +1,20 @@ // check-pass -#![feature(impl_trait_in_assoc_type)] +#![feature(impl_trait_in_assoc_type, type_alias_impl_trait)] -trait Callable { - type Output; - fn call() -> Self::Output; -} +mod foo { + pub trait Callable { + type Output; + fn call() -> Self::Output; + } -impl<'a> Callable for &'a () { - type Output = impl Sized; - fn call() -> Self::Output {} + pub type OutputHelper = impl Sized; + impl<'a> Callable for &'a () { + type Output = OutputHelper; + fn call() -> Self::Output {} + } } +use foo::*; fn test<'a>() -> impl Sized { <&'a () as Callable>::call() diff --git a/tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.rs b/tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.rs new file mode 100644 index 000000000..f6cbbf04d --- /dev/null +++ b/tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.rs @@ -0,0 +1,29 @@ +// edition: 2021 +// build-fail +//~^^ ERROR cycle detected when computing layout of + +#![feature(impl_trait_in_assoc_type)] + +use core::future::Future; + +trait Recur { + type Recur: Future; + + fn recur(self) -> Self::Recur; +} + +async fn recur(t: impl Recur) { + t.recur().await; +} + +impl Recur for () { + type Recur = impl Future; + + fn recur(self) -> Self::Recur { + async move { recur(self).await; } + } +} + +fn main() { + recur(()); +} diff --git a/tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.stderr b/tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.stderr new file mode 100644 index 000000000..2063becdb --- /dev/null +++ b/tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.stderr @@ -0,0 +1,19 @@ +error[E0391]: cycle detected when computing layout of `{async block@$DIR/indirect-recursion-issue-112047.rs:23:9: 23:42}` + | + = note: ...which requires computing layout of `core::mem::maybe_uninit::MaybeUninit<{async fn body@$DIR/indirect-recursion-issue-112047.rs:15:31: 17:2}>`... + = note: ...which requires computing layout of `core::mem::manually_drop::ManuallyDrop<{async fn body@$DIR/indirect-recursion-issue-112047.rs:15:31: 17:2}>`... + = note: ...which requires computing layout of `{async fn body@$DIR/indirect-recursion-issue-112047.rs:15:31: 17:2}`... + = note: ...which requires computing layout of `core::mem::maybe_uninit::MaybeUninit<<() as Recur>::Recur>`... + = note: ...which requires computing layout of `core::mem::maybe_uninit::MaybeUninit<{async block@$DIR/indirect-recursion-issue-112047.rs:23:9: 23:42}>`... + = note: ...which requires computing layout of `core::mem::manually_drop::ManuallyDrop<{async block@$DIR/indirect-recursion-issue-112047.rs:23:9: 23:42}>`... + = note: ...which again requires computing layout of `{async block@$DIR/indirect-recursion-issue-112047.rs:23:9: 23:42}`, completing the cycle +note: cycle used when elaborating drops for `::recur` + --> $DIR/indirect-recursion-issue-112047.rs:22:5 + | +LL | fn recur(self) -> Self::Recur { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/type-alias-impl-trait/inference-cycle.stderr b/tests/ui/type-alias-impl-trait/inference-cycle.stderr index 41530dda9..4ab059d05 100644 --- a/tests/ui/type-alias-impl-trait/inference-cycle.stderr +++ b/tests/ui/type-alias-impl-trait/inference-cycle.stderr @@ -1,4 +1,4 @@ -error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `m::Foo::{opaque#0}` --> $DIR/inference-cycle.rs:5:20 | LL | pub type Foo = impl std::fmt::Debug; @@ -10,15 +10,15 @@ note: ...which requires type-checking `m::bar`... LL | is_send(foo()); // Today: error | ^^^^^^^ = note: ...which requires evaluating trait selection obligation `m::Foo: core::marker::Send`... - = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in module `m` - --> $DIR/inference-cycle.rs:4:1 + = note: ...which again requires computing type of opaque `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `m::Foo::{opaque#0}` + --> $DIR/inference-cycle.rs:5:20 | -LL | mod m { - | ^^^^^ +LL | pub type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `m::Foo::{opaque#0}` --> $DIR/inference-cycle.rs:5:20 | LL | pub type Foo = impl std::fmt::Debug; @@ -29,12 +29,12 @@ note: ...which requires type-checking `m::bar`... | LL | pub fn bar() { | ^^^^^^^^^^^^ - = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in module `m` - --> $DIR/inference-cycle.rs:4:1 + = note: ...which again requires computing type of opaque `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `m::Foo::{opaque#0}` + --> $DIR/inference-cycle.rs:5:20 | -LL | mod m { - | ^^^^^ +LL | pub type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: cannot check whether the hidden type of `inference_cycle[4ecc]::m::Foo::{opaque#0}` satisfies auto traits diff --git a/tests/ui/type-alias-impl-trait/issue-53092-2.stderr b/tests/ui/type-alias-impl-trait/issue-53092-2.stderr index 6148131b4..e4054e14a 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092-2.stderr +++ b/tests/ui/type-alias-impl-trait/issue-53092-2.stderr @@ -4,6 +4,11 @@ error[E0391]: cycle detected when computing type of `Bug::{opaque#0}` LL | type Bug = impl Fn(T) -> U + Copy; | ^^^^^^^^^^^^^^^^^^^^^^ | +note: ...which requires computing type of opaque `Bug::{opaque#0}`... + --> $DIR/issue-53092-2.rs:4:18 + | +LL | type Bug = impl Fn(T) -> U + Copy; + | ^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires type-checking `CONST_BUG`... --> $DIR/issue-53092-2.rs:6:1 | diff --git a/tests/ui/type-alias-impl-trait/issue-63279.stderr b/tests/ui/type-alias-impl-trait/issue-63279.stderr index a4f6359b9..a86856247 100644 --- a/tests/ui/type-alias-impl-trait/issue-63279.stderr +++ b/tests/ui/type-alias-impl-trait/issue-63279.stderr @@ -23,7 +23,7 @@ LL | || -> Closure { || () } | ^^^^^ expected `()`, found closure | = note: expected unit type `()` - found closure `[closure@$DIR/issue-63279.rs:7:21: 7:23]` + found closure `{closure@$DIR/issue-63279.rs:7:21: 7:23}` help: use parentheses to call this closure | LL | || -> Closure { (|| ())() } @@ -36,7 +36,7 @@ LL | || -> Closure { || () } | ^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found closure | = note: expected unit type `()` - found closure `[closure@$DIR/issue-63279.rs:7:5: 7:18]` + found closure `{closure@$DIR/issue-63279.rs:7:5: 7:18}` help: use parentheses to call this closure | LL | (|| -> Closure { || () })() diff --git a/tests/ui/type-alias-impl-trait/issue-89686.rs b/tests/ui/type-alias-impl-trait/issue-89686.rs index 058417bdb..de070fc9d 100644 --- a/tests/ui/type-alias-impl-trait/issue-89686.rs +++ b/tests/ui/type-alias-impl-trait/issue-89686.rs @@ -4,7 +4,7 @@ use std::future::Future; -type G<'a, T> = impl Future + 'a; +type G<'a, T> = impl Future; trait Trait { type F: Future; diff --git a/tests/ui/type-alias-impl-trait/issue-89686.stderr b/tests/ui/type-alias-impl-trait/issue-89686.stderr index 3b95a575a..b636ada8b 100644 --- a/tests/ui/type-alias-impl-trait/issue-89686.stderr +++ b/tests/ui/type-alias-impl-trait/issue-89686.stderr @@ -6,7 +6,7 @@ LL | async move { self.f().await } | help: consider restricting type parameter `T` | -LL | type G<'a, T: Trait> = impl Future + 'a; +LL | type G<'a, T: Trait> = impl Future; | +++++++ error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/issue-94429.stderr b/tests/ui/type-alias-impl-trait/issue-94429.stderr index 8d7f7a07b..26605cdd2 100644 --- a/tests/ui/type-alias-impl-trait/issue-94429.stderr +++ b/tests/ui/type-alias-impl-trait/issue-94429.stderr @@ -1,4 +1,4 @@ -error[E0271]: type mismatch resolving `<[generator@$DIR/issue-94429.rs:17:9: 17:16] as Generator>::Yield == ()` +error[E0271]: type mismatch resolving `<{generator@$DIR/issue-94429.rs:17:9: 17:16} as Generator>::Yield == ()` --> $DIR/issue-94429.rs:15:26 | LL | fn run(&mut self) -> Self::Gen { diff --git a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs index 01d1f5db1..c584a58cb 100644 --- a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs +++ b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs @@ -1,7 +1,8 @@ #![feature(type_alias_impl_trait)] -type Opaque<'a, T> = impl Sized; +type Opaque2 = impl Sized; +type Opaque<'a, T> = Opaque2; fn defining<'a, T>(x: &'a i32) -> Opaque { x } -//~^ ERROR: hidden type for `Opaque<'a, T>` captures lifetime that does not appear in bounds +//~^ ERROR: hidden type for `Opaque2` captures lifetime that does not appear in bounds fn main() {} diff --git a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr index d666e668d..6bcae6e53 100644 --- a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr +++ b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr @@ -1,8 +1,9 @@ -error[E0700]: hidden type for `Opaque<'a, T>` captures lifetime that does not appear in bounds - --> $DIR/missing_lifetime_bound.rs:4:47 +error[E0700]: hidden type for `Opaque2` captures lifetime that does not appear in bounds + --> $DIR/missing_lifetime_bound.rs:5:47 | -LL | type Opaque<'a, T> = impl Sized; - | ---------- opaque type defined here +LL | type Opaque2 = impl Sized; + | ---------- opaque type defined here +LL | type Opaque<'a, T> = Opaque2; LL | fn defining<'a, T>(x: &'a i32) -> Opaque { x } | -- ^ | | diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs index 65eb2952e..3f122f106 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs @@ -1,10 +1,6 @@ #![feature(type_alias_impl_trait)] -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type Foo<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +type Foo<'a, 'b> = impl std::fmt::Debug; fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) { (i, i) //~ ERROR concrete type differs from previous diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr index d7676b8e9..81e603e23 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr @@ -1,5 +1,5 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:10:5 + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 | LL | (i, i) | ^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs index 21fca047a..83fd9a1da 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs @@ -7,11 +7,7 @@ fn f(a: A, b: B) -> (X, X) (a.clone(), a) } -pub trait Captures<'a> {} - -impl<'a, T: ?Sized> Captures<'a> for T {} - -type Foo<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +type Foo<'a, 'b> = impl std::fmt::Debug; fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) { (i, j) diff --git a/tests/ui/type-alias-impl-trait/mututally-recursive-overflow.rs b/tests/ui/type-alias-impl-trait/mututally-recursive-overflow.rs new file mode 100644 index 000000000..1ccd1b0cb --- /dev/null +++ b/tests/ui/type-alias-impl-trait/mututally-recursive-overflow.rs @@ -0,0 +1,40 @@ +// edition: 2021 +// build-fail +//~^^ ERROR overflow evaluating the requirement `<() as B>::Assoc == _` + +#![feature(rustc_attrs)] +#![feature(impl_trait_in_assoc_type)] + +#[rustc_coinductive] +trait A { + type Assoc; + + fn test() -> Self::Assoc; +} + +#[rustc_coinductive] +trait B { + type Assoc; + + fn test() -> Self::Assoc; +} + +impl B for T { + type Assoc = impl Sized; + + fn test() -> ::Assoc { + ::test() + } +} + +fn main() { + <() as A>::test(); +} + +impl A for T { + type Assoc = impl Sized; + + fn test() -> ::Assoc { + ::test() + } +} diff --git a/tests/ui/type-alias-impl-trait/mututally-recursive-overflow.stderr b/tests/ui/type-alias-impl-trait/mututally-recursive-overflow.stderr new file mode 100644 index 000000000..49c59f7eb --- /dev/null +++ b/tests/ui/type-alias-impl-trait/mututally-recursive-overflow.stderr @@ -0,0 +1,5 @@ +error[E0275]: overflow evaluating the requirement `<() as B>::Assoc == _` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.rs b/tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.rs new file mode 100644 index 000000000..fec0fdc46 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.rs @@ -0,0 +1,9 @@ +#![feature(type_alias_impl_trait)] + +pub type Tait = impl Iterator; +//~^ ERROR use of undeclared lifetime name `'db` +//~| ERROR cannot find type `Key` in this scope +//~| ERROR unconstrained opaque type +//~| ERROR unconstrained opaque type + +pub fn main() {} diff --git a/tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.stderr b/tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.stderr new file mode 100644 index 000000000..d4aeace4a --- /dev/null +++ b/tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.stderr @@ -0,0 +1,47 @@ +error[E0261]: use of undeclared lifetime name `'db` + --> $DIR/nested-impl-trait-in-tait.rs:3:40 + | +LL | pub type Tait = impl Iterator; + | ^^^ undeclared lifetime + | + = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html +help: consider making the bound lifetime-generic with a new `'db` lifetime + | +LL | pub type Tait = impl for<'db> Iterator; + | ++++++++ +help: consider introducing lifetime `'db` here + | +LL | pub type Tait<'db> = impl Iterator; + | +++++ + +error[E0412]: cannot find type `Key` in this scope + --> $DIR/nested-impl-trait-in-tait.rs:3:44 + | +LL | pub type Tait = impl Iterator; + | ^^^ not found in this scope + | +help: consider importing this struct + | +LL + use std::thread::local_impl::Key; + | + +error: unconstrained opaque type + --> $DIR/nested-impl-trait-in-tait.rs:3:17 + | +LL | pub type Tait = impl Iterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `Tait` must be used in combination with a concrete type within the same module + +error: unconstrained opaque type + --> $DIR/nested-impl-trait-in-tait.rs:3:49 + | +LL | pub type Tait = impl Iterator; + | ^^^^^^^^^^^^^ + | + = note: `Tait` must be used in combination with a concrete type within the same module + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0261, E0412. +For more information about an error, try `rustc --explain E0261`. diff --git a/tests/ui/type-alias-impl-trait/normalize-alias-type.rs b/tests/ui/type-alias-impl-trait/normalize-alias-type.rs new file mode 100644 index 000000000..7c62002b9 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/normalize-alias-type.rs @@ -0,0 +1,32 @@ +// check-pass +// compile-flags: -Z mir-opt-level=3 +#![feature(type_alias_impl_trait)] +#![crate_type = "lib"] +pub trait Tr { + fn get(&self) -> u32; +} + +impl Tr for (u32,) { + #[inline] + fn get(&self) -> u32 { self.0 } +} + +pub fn tr1() -> impl Tr { + (32,) +} + +pub fn tr2() -> impl Tr { + struct Inner { + x: X, + } + type X = impl Tr; + impl Tr for Inner { + fn get(&self) -> u32 { + self.x.get() + } + } + + Inner { + x: tr1(), + } +} diff --git a/tests/ui/type-alias-impl-trait/privacy.rs b/tests/ui/type-alias-impl-trait/privacy.rs index aa092f6f8..3efbfaf09 100644 --- a/tests/ui/type-alias-impl-trait/privacy.rs +++ b/tests/ui/type-alias-impl-trait/privacy.rs @@ -1,8 +1,10 @@ +// check-pass + #![feature(type_alias_impl_trait)] type Foo = (impl Sized, u8); pub fn foo() -> Foo { - //~^ ERROR private type alias `Foo` in public interface + //~^ WARNING type alias `Foo` is more private than the item `foo` (42, 42) } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/privacy.stderr b/tests/ui/type-alias-impl-trait/privacy.stderr index e8c6039cd..50870905c 100644 --- a/tests/ui/type-alias-impl-trait/privacy.stderr +++ b/tests/ui/type-alias-impl-trait/privacy.stderr @@ -1,11 +1,15 @@ -error[E0446]: private type alias `Foo` in public interface - --> $DIR/privacy.rs:4:1 +warning: type alias `Foo` is more private than the item `foo` + --> $DIR/privacy.rs:6:1 | -LL | type Foo = (impl Sized, u8); - | -------- `Foo` declared as private LL | pub fn foo() -> Foo { - | ^^^^^^^^^^^^^^^^^^^ can't leak private type alias + | ^^^^^^^^^^^^^^^^^^^ function `foo` is reachable at visibility `pub` + | +note: but type alias `Foo` is only usable at visibility `pub(crate)` + --> $DIR/privacy.rs:5:1 + | +LL | type Foo = (impl Sized, u8); + | ^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default -error: aborting due to previous error +warning: 1 warning emitted -For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/type-alias-impl-trait/reveal_local.stderr b/tests/ui/type-alias-impl-trait/reveal_local.stderr index 813185c13..c62fd88f4 100644 --- a/tests/ui/type-alias-impl-trait/reveal_local.stderr +++ b/tests/ui/type-alias-impl-trait/reveal_local.stderr @@ -1,4 +1,4 @@ -error[E0391]: cycle detected when computing type of `Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `Foo::{opaque#0}` --> $DIR/reveal_local.rs:5:12 | LL | type Foo = impl Debug; @@ -10,21 +10,15 @@ note: ...which requires type-checking `not_good`... LL | is_send::(); | ^^^^^^^^^^^^^^ = note: ...which requires evaluating trait selection obligation `Foo: core::marker::Send`... - = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in top-level module - --> $DIR/reveal_local.rs:1:1 - | -LL | / #![feature(type_alias_impl_trait)] -LL | | -LL | | use std::fmt::Debug; -LL | | -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: ...which again requires computing type of opaque `Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `Foo::{opaque#0}` + --> $DIR/reveal_local.rs:5:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error[E0391]: cycle detected when computing type of `Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `Foo::{opaque#0}` --> $DIR/reveal_local.rs:5:12 | LL | type Foo = impl Debug; @@ -35,18 +29,12 @@ note: ...which requires type-checking `not_good`... | LL | fn not_good() { | ^^^^^^^^^^^^^ - = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in top-level module - --> $DIR/reveal_local.rs:1:1 - | -LL | / #![feature(type_alias_impl_trait)] -LL | | -LL | | use std::fmt::Debug; -LL | | -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: ...which again requires computing type of opaque `Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `Foo::{opaque#0}` + --> $DIR/reveal_local.rs:5:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits @@ -71,7 +59,7 @@ note: required by a bound in `is_send` LL | fn is_send() {} | ^^^^ required by this bound in `is_send` -error[E0391]: cycle detected when computing type of `Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `Foo::{opaque#0}` --> $DIR/reveal_local.rs:5:12 | LL | type Foo = impl Debug; @@ -82,18 +70,12 @@ note: ...which requires type-checking `not_gooder`... | LL | fn not_gooder() -> Foo { | ^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in top-level module - --> $DIR/reveal_local.rs:1:1 - | -LL | / #![feature(type_alias_impl_trait)] -LL | | -LL | | use std::fmt::Debug; -LL | | -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: ...which again requires computing type of opaque `Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `Foo::{opaque#0}` + --> $DIR/reveal_local.rs:5:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.current.stderr b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.current.stderr new file mode 100644 index 000000000..844103d77 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.current.stderr @@ -0,0 +1,29 @@ +error: internal compiler error: no errors encountered even though `delay_span_bug` issued + +error: internal compiler error: {OpaqueTypeKey { def_id: DefId(get_rpit::{opaque#0}), args: [] }: OpaqueTypeDecl { hidden_type: OpaqueHiddenType { span: no-location (#0), ty: Alias(Opaque, AliasTy { args: [], def_id: DefId(Opaque::{opaque#0}) }) } }} + | + = + + +error: internal compiler error: error performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: ProjectionPredicate(AliasTy { args: [FnDef(DefId(get_rpit), []), ()], def_id: DefId(ops::function::FnOnce::Output) }, Term::Ty(Alias(Opaque, AliasTy { args: [], def_id: DefId(Opaque::{opaque#0}) }))), bound_vars: [] } } } + --> $DIR/rpit_tait_equality_in_canonical_query.rs:28:5 + | +LL | query(get_rpit); + | ^^^^^^^^^^^^^^^ + | + + --> $DIR/rpit_tait_equality_in_canonical_query.rs:28:5 + | +LL | query(get_rpit); + | ^^^^^^^^^^^^^^^ + + + + + + + +query stack during panic: +end of query stack +error: aborting due to 3 previous errors + diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs new file mode 100644 index 000000000..0f0002f77 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs @@ -0,0 +1,32 @@ +//! This tries to prove the APIT's bounds in a canonical query, +//! which doesn't know anything about the defining scope of either +//! opaque type and thus makes a random choice as to which opaque type +//! becomes the hidden type of the other. When we leave the canonical +//! query, we attempt to actually check the defining anchor, but now we +//! have a situation where the RPIT gets constrained outside its anchor. + +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next +//[next] check-pass + +//[current] known-bug: #108498 +//[current] failure-status: 101 +//[current] normalize-stderr-test: "DefId\(.*?\]::" -> "DefId(" +//[current] normalize-stderr-test: "(?m)note: .*$" -> "" +//[current] normalize-stderr-test: "(?m)^ *\d+: .*\n" -> "" +//[current] normalize-stderr-test: "(?m)^ *at .*\n" -> "" + +#![feature(type_alias_impl_trait)] + +type Opaque = impl Sized; + +fn get_rpit() -> impl Clone {} + +fn query(_: impl FnOnce() -> Opaque) {} + +fn test() -> Opaque { + query(get_rpit); + get_rpit() +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs new file mode 100644 index 000000000..9d7e647dd --- /dev/null +++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs @@ -0,0 +1,18 @@ +// The canonical query `Projection(::Output = Opaque)` +// is the *only* site that defines `Opaque` in MIR typeck. +// +// check-pass + +#![feature(type_alias_impl_trait)] + +type Opaque = impl Sized; + +fn get_rpit() -> impl Sized {} + +fn query(_: impl FnOnce() -> Opaque) {} + +fn test(_: Opaque) { + query(get_rpit); +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/self_implication.rs b/tests/ui/type-alias-impl-trait/self_implication.rs index 4e805ee30..65659a0f3 100644 --- a/tests/ui/type-alias-impl-trait/self_implication.rs +++ b/tests/ui/type-alias-impl-trait/self_implication.rs @@ -22,9 +22,9 @@ fn bar() { } // desugared - type FooX<'a> = impl Sized; + type FooX = impl Sized; impl<'a> Foo<'a> { - fn foo(&self) -> FooX<'a> {} + fn foo(&self) -> FooX {} } // use site diff --git a/tests/ui/type-alias-impl-trait/tait-normalize.rs b/tests/ui/type-alias-impl-trait/tait-normalize.rs new file mode 100644 index 000000000..26d94dbb4 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/tait-normalize.rs @@ -0,0 +1,14 @@ +// check-pass + +#![feature(type_alias_impl_trait)] + +fn enum_upvar() { + type T = impl Copy; + let foo: T = Some((1u32, 2u32)); + let x = move || match foo { + None => (), + Some((a, b)) => (), + }; +} + +fn main(){} diff --git a/tests/ui/type-alias-impl-trait/variance.rs b/tests/ui/type-alias-impl-trait/variance.rs new file mode 100644 index 000000000..e92cf2513 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/variance.rs @@ -0,0 +1,44 @@ +#![feature(rustc_attrs, type_alias_impl_trait, impl_trait_in_assoc_type)] +#![allow(internal_features)] +#![rustc_variance_of_opaques] + +trait Captures<'a> {} +impl Captures<'_> for T {} + +type NotCapturedEarly<'a> = impl Sized; //~ [o] + +type CapturedEarly<'a> = impl Sized + Captures<'a>; //~ [o] + +// TAIT does *not* capture `'b` +type NotCapturedLate<'a> = dyn for<'b> Iterator; //~ [o] + +// TAIT does *not* capture `'b` +type Captured<'a> = dyn for<'b> Iterator>; //~ [o] + +type Bar<'a, 'b: 'b, T> = impl Sized; //~ ERROR [o, o, o] + +trait Foo<'i> { + type ImplicitCapture<'a>; + + type ExplicitCaptureFromHeader<'a>; + + type ExplicitCaptureFromGat<'a>; +} + +impl<'i> Foo<'i> for &'i () { + type ImplicitCapture<'a> = impl Sized; //~ [o, o] + + type ExplicitCaptureFromHeader<'a> = impl Sized + Captures<'i>; //~ [o, o] + + type ExplicitCaptureFromGat<'a> = impl Sized + Captures<'a>; //~ [o, o] +} + +impl<'i> Foo<'i> for () { + type ImplicitCapture<'a> = impl Sized; //~ [o, o] + + type ExplicitCaptureFromHeader<'a> = impl Sized + Captures<'i>; //~ [o, o] + + type ExplicitCaptureFromGat<'a> = impl Sized + Captures<'a>; //~ [o, o] +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/variance.stderr b/tests/ui/type-alias-impl-trait/variance.stderr new file mode 100644 index 000000000..1794447c8 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/variance.stderr @@ -0,0 +1,68 @@ +error: [o] + --> $DIR/variance.rs:8:29 + | +LL | type NotCapturedEarly<'a> = impl Sized; + | ^^^^^^^^^^ + +error: [o] + --> $DIR/variance.rs:10:26 + | +LL | type CapturedEarly<'a> = impl Sized + Captures<'a>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o] + --> $DIR/variance.rs:13:56 + | +LL | type NotCapturedLate<'a> = dyn for<'b> Iterator; + | ^^^^^^^^^^ + +error: [o] + --> $DIR/variance.rs:16:49 + | +LL | type Captured<'a> = dyn for<'b> Iterator>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o, o, o] + --> $DIR/variance.rs:18:27 + | +LL | type Bar<'a, 'b: 'b, T> = impl Sized; + | ^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:29:32 + | +LL | type ImplicitCapture<'a> = impl Sized; + | ^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:31:42 + | +LL | type ExplicitCaptureFromHeader<'a> = impl Sized + Captures<'i>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:33:39 + | +LL | type ExplicitCaptureFromGat<'a> = impl Sized + Captures<'a>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:37:32 + | +LL | type ImplicitCapture<'a> = impl Sized; + | ^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:39:42 + | +LL | type ExplicitCaptureFromHeader<'a> = impl Sized + Captures<'i>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [o, o] + --> $DIR/variance.rs:41:39 + | +LL | type ExplicitCaptureFromGat<'a> = impl Sized + Captures<'a>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 11 previous errors + -- cgit v1.2.3