From 6f5d8556ca79473df091466306f69633877bdcd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Thu, 3 Aug 2023 01:04:17 +0200 Subject: [PATCH] Handle inherent associated types fallout --- .../type/inherent_associated_type_bound.rs | 17 +++--- .../inherent_associated_type_projections.rs | 12 ++-- tests/rustdoc/inherent-projections.rs | 10 ++-- .../issue-111879-0.rs | 4 +- .../issue-111879-0.stderr | 6 +- .../late-bound-regions.rs | 4 +- .../late-bound-regions.stderr | 2 +- .../not-found-self-type-differs.alias.stderr | 16 ------ .../not-found-self-type-differs.local.stderr | 16 ------ .../not-found-self-type-differs.rs | 9 +-- .../not-found-self-type-differs.stderr | 29 ++++++++++ .../substitute-params-bad.rs | 2 +- .../substitute-params.rs | 3 +- .../type-alias-bounds-are-enforced.rs | 4 +- .../type-alias-bounds-are-enforced.stderr | 55 +++++++++++++++++++ 15 files changed, 117 insertions(+), 72 deletions(-) delete mode 100644 tests/ui/associated-inherent-types/not-found-self-type-differs.alias.stderr delete mode 100644 tests/ui/associated-inherent-types/not-found-self-type-differs.local.stderr create mode 100644 tests/ui/associated-inherent-types/not-found-self-type-differs.stderr create mode 100644 tests/ui/associated-inherent-types/type-alias-bounds-are-enforced.stderr diff --git a/tests/rustdoc-json/type/inherent_associated_type_bound.rs b/tests/rustdoc-json/type/inherent_associated_type_bound.rs index 2e9b13d0cac..8e39f471824 100644 --- a/tests/rustdoc-json/type/inherent_associated_type_bound.rs +++ b/tests/rustdoc-json/type/inherent_associated_type_bound.rs @@ -5,14 +5,15 @@ // @set Carrier = '$.index[*][?(@.name=="Carrier")].id' pub struct Carrier<'a>(&'a ()); -// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.generic_params[*].name' \""'b"\" -// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.decl.inputs[0][1].qualified_path.self_type.resolved_path.id' $Carrier -// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.decl.inputs[0][1].qualified_path.self_type.resolved_path.args.angle_bracketed.args[0].lifetime' \""'b"\" -// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.decl.inputs[0][1].qualified_path.name' '"Focus"' -// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.decl.inputs[0][1].qualified_path.trait' null -// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.decl.inputs[0][1].qualified_path.args.angle_bracketed.args[0].type.primitive' '"i32"' - -pub type User = for<'b> fn(Carrier<'b>::Focus); +// @count "$.index[*][?(@.name=='user')].inner.function.decl.inputs[*]" 1 +// @is "$.index[*][?(@.name=='user')].inner.function.decl.inputs[0][0]" '"_"' +// @is '$.index[*][?(@.name=="user")].inner.function.decl.inputs[0][1].function_pointer.generic_params[*].name' \""'b"\" +// @is '$.index[*][?(@.name=="user")].inner.function.decl.inputs[0][1].function_pointer.decl.inputs[0][1].qualified_path.self_type.resolved_path.id' $Carrier +// @is '$.index[*][?(@.name=="user")].inner.function.decl.inputs[0][1].function_pointer.decl.inputs[0][1].qualified_path.self_type.resolved_path.args.angle_bracketed.args[0].lifetime' \""'b"\" +// @is '$.index[*][?(@.name=="user")].inner.function.decl.inputs[0][1].function_pointer.decl.inputs[0][1].qualified_path.name' '"Focus"' +// @is '$.index[*][?(@.name=="user")].inner.function.decl.inputs[0][1].function_pointer.decl.inputs[0][1].qualified_path.trait' null +// @is '$.index[*][?(@.name=="user")].inner.function.decl.inputs[0][1].function_pointer.decl.inputs[0][1].qualified_path.args.angle_bracketed.args[0].type.primitive' '"i32"' +pub fn user(_: for<'b> fn(Carrier<'b>::Focus)) {} impl<'a> Carrier<'a> { pub type Focus = &'a mut T; diff --git a/tests/rustdoc-json/type/inherent_associated_type_projections.rs b/tests/rustdoc-json/type/inherent_associated_type_projections.rs index 942e323efca..d12e5f4a784 100644 --- a/tests/rustdoc-json/type/inherent_associated_type_projections.rs +++ b/tests/rustdoc-json/type/inherent_associated_type_projections.rs @@ -5,11 +5,13 @@ // @set Parametrized = '$.index[*][?(@.name=="Parametrized")].id' pub struct Parametrized(T); -// @is '$.index[*][?(@.name=="Test")].inner.typedef.type.qualified_path.self_type.resolved_path.id' $Parametrized -// @is '$.index[*][?(@.name=="Test")].inner.typedef.type.qualified_path.self_type.resolved_path.args.angle_bracketed.args[0].type.primitive' \"i32\" -// @is '$.index[*][?(@.name=="Test")].inner.typedef.type.qualified_path.name' '"Proj"' -// @is '$.index[*][?(@.name=="Test")].inner.typedef.type.qualified_path.trait' null -pub type Test = Parametrized::Proj; +// @count "$.index[*][?(@.name=='test')].inner.function.decl.inputs[*]" 1 +// @is "$.index[*][?(@.name=='test')].inner.function.decl.inputs[0][0]" '"_"' +// @is '$.index[*][?(@.name=="test")].inner.function.decl.inputs[0][1].qualified_path.self_type.resolved_path.id' $Parametrized +// @is '$.index[*][?(@.name=="test")].inner.function.decl.inputs[0][1].qualified_path.self_type.resolved_path.args.angle_bracketed.args[0].type.primitive' \"i32\" +// @is '$.index[*][?(@.name=="test")].inner.function.decl.inputs[0][1].qualified_path.name' '"Proj"' +// @is '$.index[*][?(@.name=="test")].inner.function.decl.inputs[0][1].qualified_path.trait' null +pub fn test(_: Parametrized::Proj) {} /// param_bool impl Parametrized { diff --git a/tests/rustdoc/inherent-projections.rs b/tests/rustdoc/inherent-projections.rs index 9bda0acaf83..25f51282617 100644 --- a/tests/rustdoc/inherent-projections.rs +++ b/tests/rustdoc/inherent-projections.rs @@ -13,8 +13,8 @@ impl Owner { } // Make sure we handle bound vars correctly. -// @has 'inherent_projections/type.User.html' '//pre[@class="rust item-decl"]' "for<'a> fn(_: Carrier<'a>::Focus)" -pub type User = for<'a> fn(Carrier<'a>::Focus); +// @has 'inherent_projections/fn.user.html' '//pre[@class="rust item-decl"]' "user(_: for<'a> fn(_: Carrier<'a>::Focus))" +pub fn user(_: for<'a> fn(Carrier<'a>::Focus)) {} pub struct Carrier<'a>(&'a ()); @@ -27,11 +27,11 @@ impl<'a> Carrier<'a> { // FIXME(inherent_associated_types): Below we link to `Proj` but we should link to `Proj-1`. // The current test checks for the buggy behavior for demonstration purposes. -// @has 'inherent_projections/type.Test.html' -// @has - '//pre[@class="rust item-decl"]' "Parametrized" +// @has 'inherent_projections/fn.test.html' +// @has - '//pre[@class="rust item-decl"]' "test(_: Parametrized::Proj)" // @has - '//pre[@class="rust item-decl"]//a[@class="associatedtype"]/@href' 'struct.Parametrized.html#associatedtype.Proj' // @!has - '//pre[@class="rust item-decl"]//a[@class="associatedtype"]/@href' 'struct.Parametrized.html#associatedtype.Proj-1' -pub type Test = Parametrized::Proj; +pub fn test(_: Parametrized::Proj) {} pub struct Parametrized(T); diff --git a/tests/ui/associated-inherent-types/issue-111879-0.rs b/tests/ui/associated-inherent-types/issue-111879-0.rs index e37f7d34ab5..d01354465df 100644 --- a/tests/ui/associated-inherent-types/issue-111879-0.rs +++ b/tests/ui/associated-inherent-types/issue-111879-0.rs @@ -5,10 +5,8 @@ pub struct Carrier<'a>(&'a ()); -pub type User = for<'b> fn(Carrier<'b>::Focus); - impl<'a> Carrier<'a> { - pub type Focus = &'a mut User; //~ ERROR overflow evaluating associated type + pub type Focus = &'a mut for<'b> fn(Carrier<'b>::Focus); //~ ERROR overflow evaluating associated type } fn main() {} diff --git a/tests/ui/associated-inherent-types/issue-111879-0.stderr b/tests/ui/associated-inherent-types/issue-111879-0.stderr index 7bdbad44017..f6367c88aea 100644 --- a/tests/ui/associated-inherent-types/issue-111879-0.stderr +++ b/tests/ui/associated-inherent-types/issue-111879-0.stderr @@ -1,8 +1,8 @@ error: overflow evaluating associated type `Carrier<'b>::Focus` - --> $DIR/issue-111879-0.rs:11:25 + --> $DIR/issue-111879-0.rs:9:25 | -LL | pub type Focus = &'a mut User; - | ^^^^^^^^^^^^ +LL | pub type Focus = &'a mut for<'b> fn(Carrier<'b>::Focus); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/associated-inherent-types/late-bound-regions.rs b/tests/ui/associated-inherent-types/late-bound-regions.rs index 488a2cda649..1dbeb00d495 100644 --- a/tests/ui/associated-inherent-types/late-bound-regions.rs +++ b/tests/ui/associated-inherent-types/late-bound-regions.rs @@ -3,8 +3,6 @@ // Test if we correctly normalize `S<'a>::P` with respect to late-bound regions. -type Function = for<'a> fn(&'a i32) -> S<'a>::P; - struct S<'a>(&'a ()); trait Inter { @@ -16,7 +14,7 @@ impl<'a> S<'a> { } fn ret_ref_local<'e>() -> &'e i32 { - let f: Function = |x| x; + let f: for<'a> fn(&'a i32) -> S<'a>::P = |x| x; let local = 0; f(&local) //~ ERROR cannot return value referencing local variable `local` diff --git a/tests/ui/associated-inherent-types/late-bound-regions.stderr b/tests/ui/associated-inherent-types/late-bound-regions.stderr index 4706fcca91d..0dd17b05cd0 100644 --- a/tests/ui/associated-inherent-types/late-bound-regions.stderr +++ b/tests/ui/associated-inherent-types/late-bound-regions.stderr @@ -1,5 +1,5 @@ error[E0515]: cannot return value referencing local variable `local` - --> $DIR/late-bound-regions.rs:22:5 + --> $DIR/late-bound-regions.rs:20:5 | LL | f(&local) | ^^------^ diff --git a/tests/ui/associated-inherent-types/not-found-self-type-differs.alias.stderr b/tests/ui/associated-inherent-types/not-found-self-type-differs.alias.stderr deleted file mode 100644 index 4396435a6dd..00000000000 --- a/tests/ui/associated-inherent-types/not-found-self-type-differs.alias.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0220]: associated type `Proj` not found for `Family>` in the current scope - --> $DIR/not-found-self-type-differs.rs:17:34 - | -LL | struct Family(T); - | ---------------- associated item `Proj` not found for this struct -... -LL | type Alias = Family>::Proj; - | ^^^^ associated item not found in `Family>` - | - = note: the associated type was found for - - `Family<()>` - - `Family>` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0220`. diff --git a/tests/ui/associated-inherent-types/not-found-self-type-differs.local.stderr b/tests/ui/associated-inherent-types/not-found-self-type-differs.local.stderr deleted file mode 100644 index d527db02217..00000000000 --- a/tests/ui/associated-inherent-types/not-found-self-type-differs.local.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0220]: associated type `Proj` not found for `Family` in the current scope - --> $DIR/not-found-self-type-differs.rs:21:40 - | -LL | struct Family(T); - | ---------------- associated item `Proj` not found for this struct -... -LL | let _: Family::Proj = (); - | ^^^^ associated item not found in `Family` - | - = note: the associated type was found for - - `Family<()>` - - `Family>` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0220`. diff --git a/tests/ui/associated-inherent-types/not-found-self-type-differs.rs b/tests/ui/associated-inherent-types/not-found-self-type-differs.rs index 93f58dcb6e6..76c5d4e7f69 100644 --- a/tests/ui/associated-inherent-types/not-found-self-type-differs.rs +++ b/tests/ui/associated-inherent-types/not-found-self-type-differs.rs @@ -1,5 +1,3 @@ -// revisions: local alias - #![feature(inherent_associated_types)] #![allow(incomplete_features)] @@ -13,10 +11,7 @@ impl Family> { type Proj = Self; } -#[cfg(alias)] -type Alias = Family>::Proj; //[alias]~ ERROR associated type `Proj` not found for `Family>` - fn main() { - #[cfg(local)] - let _: Family::Proj = (); //[local]~ ERROR associated type `Proj` not found for `Family` + let _: Family>::Proj; //~ ERROR associated type `Proj` not found for `Family>` + let _: Family::Proj = (); //~ ERROR associated type `Proj` not found for `Family` } diff --git a/tests/ui/associated-inherent-types/not-found-self-type-differs.stderr b/tests/ui/associated-inherent-types/not-found-self-type-differs.stderr new file mode 100644 index 00000000000..1871407c64f --- /dev/null +++ b/tests/ui/associated-inherent-types/not-found-self-type-differs.stderr @@ -0,0 +1,29 @@ +error[E0220]: associated type `Proj` not found for `Family>` in the current scope + --> $DIR/not-found-self-type-differs.rs:15:32 + | +LL | struct Family(T); + | ---------------- associated item `Proj` not found for this struct +... +LL | let _: Family>::Proj; + | ^^^^ associated item not found in `Family>` + | + = note: the associated type was found for + - `Family<()>` + - `Family>` + +error[E0220]: associated type `Proj` not found for `Family` in the current scope + --> $DIR/not-found-self-type-differs.rs:16:40 + | +LL | struct Family(T); + | ---------------- associated item `Proj` not found for this struct +... +LL | let _: Family::Proj = (); + | ^^^^ associated item not found in `Family` + | + = note: the associated type was found for + - `Family<()>` + - `Family>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0220`. diff --git a/tests/ui/associated-inherent-types/substitute-params-bad.rs b/tests/ui/associated-inherent-types/substitute-params-bad.rs index 00eb1a14da4..a5d73c7b49f 100644 --- a/tests/ui/associated-inherent-types/substitute-params-bad.rs +++ b/tests/ui/associated-inherent-types/substitute-params-bad.rs @@ -17,7 +17,7 @@ impl Subj<(T, S)> { } fn main() { - type A = S<()>::P; + let _: S<()>::P; let _: Subj<(i32, i32)>::Un = 0i32; //~ ERROR mismatched types } diff --git a/tests/ui/associated-inherent-types/substitute-params.rs b/tests/ui/associated-inherent-types/substitute-params.rs index e94d6833159..631340b2b4d 100644 --- a/tests/ui/associated-inherent-types/substitute-params.rs +++ b/tests/ui/associated-inherent-types/substitute-params.rs @@ -15,8 +15,7 @@ impl S<(T,)> { fn main() { // Regression test for issue #104240. - type A = S<()>::P; - let _: A = (); + let _: S<()>::P = (); // Regression test for issue #107468. let _: S<(i32,)>::Un = 0i32; diff --git a/tests/ui/associated-inherent-types/type-alias-bounds-are-enforced.rs b/tests/ui/associated-inherent-types/type-alias-bounds-are-enforced.rs index b32b4288ac9..5c59f217be6 100644 --- a/tests/ui/associated-inherent-types/type-alias-bounds-are-enforced.rs +++ b/tests/ui/associated-inherent-types/type-alias-bounds-are-enforced.rs @@ -1,4 +1,5 @@ -// check-pass +// FIXME(inherent_associated_types): This should be `check-pass` +// known-bug: #108491 // compile-flags: --crate-type=lib #![feature(inherent_associated_types)] @@ -17,7 +18,6 @@ pub type Alias = (Source::Assoc,); - pub struct Source(T); pub trait Bound {} diff --git a/tests/ui/associated-inherent-types/type-alias-bounds-are-enforced.stderr b/tests/ui/associated-inherent-types/type-alias-bounds-are-enforced.stderr new file mode 100644 index 00000000000..5e18543fc90 --- /dev/null +++ b/tests/ui/associated-inherent-types/type-alias-bounds-are-enforced.stderr @@ -0,0 +1,55 @@ +error[E0391]: cycle detected when expanding type alias `Alias` + --> $DIR/type-alias-bounds-are-enforced.rs:19:1 + | +LL | pub type Alias = (Source::Assoc,); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: ...which requires computing the variances of `Source`... + --> $DIR/type-alias-bounds-are-enforced.rs:21:1 + | +LL | pub struct Source(T); + | ^^^^^^^^^^^^^^^^^^^^ + = note: ...which requires computing the variances for items in this crate... + = note: ...which again requires expanding type alias `Alias`, completing the cycle +note: cycle used when collecting item types in top-level module + --> $DIR/type-alias-bounds-are-enforced.rs:5:1 + | +LL | / #![feature(inherent_associated_types)] +LL | | #![allow(incomplete_features)] +LL | | +LL | | // Bounds on the self type play a major role in the resolution of inherent associated types (*). +... | +LL | | pub type Assoc = (); +LL | | } + | |_^ + = 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 expanding type alias `Alias` + --> $DIR/type-alias-bounds-are-enforced.rs:19:1 + | +LL | pub type Alias = (Source::Assoc,); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: ...which requires computing the variances of `Source`... + --> $DIR/type-alias-bounds-are-enforced.rs:21:1 + | +LL | pub struct Source(T); + | ^^^^^^^^^^^^^^^^^^^^ + = note: ...which requires computing the variances for items in this crate... + = note: ...which again requires expanding type alias `Alias`, completing the cycle +note: cycle used when collecting item types in top-level module + --> $DIR/type-alias-bounds-are-enforced.rs:5:1 + | +LL | / #![feature(inherent_associated_types)] +LL | | #![allow(incomplete_features)] +LL | | +LL | | // Bounds on the self type play a major role in the resolution of inherent associated types (*). +... | +LL | | pub type Assoc = (); +LL | | } + | |_^ + = 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 2 previous errors + +For more information about this error, try `rustc --explain E0391`.