Skip to content

Commit 6f5d855

Browse files
committed
Handle inherent associated types fallout
1 parent 263a0de commit 6f5d855

15 files changed

+117
-72
lines changed

tests/rustdoc-json/type/inherent_associated_type_bound.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
// @set Carrier = '$.index[*][?(@.name=="Carrier")].id'
66
pub struct Carrier<'a>(&'a ());
77

8-
// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.generic_params[*].name' \""'b"\"
9-
// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.decl.inputs[0][1].qualified_path.self_type.resolved_path.id' $Carrier
10-
// @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"\"
11-
// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.decl.inputs[0][1].qualified_path.name' '"Focus"'
12-
// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.decl.inputs[0][1].qualified_path.trait' null
13-
// @is '$.index[*][?(@.name=="User")].inner.typedef.type.function_pointer.decl.inputs[0][1].qualified_path.args.angle_bracketed.args[0].type.primitive' '"i32"'
14-
15-
pub type User = for<'b> fn(Carrier<'b>::Focus<i32>);
8+
// @count "$.index[*][?(@.name=='user')].inner.function.decl.inputs[*]" 1
9+
// @is "$.index[*][?(@.name=='user')].inner.function.decl.inputs[0][0]" '"_"'
10+
// @is '$.index[*][?(@.name=="user")].inner.function.decl.inputs[0][1].function_pointer.generic_params[*].name' \""'b"\"
11+
// @is '$.index[*][?(@.name=="user")].inner.function.decl.inputs[0][1].function_pointer.decl.inputs[0][1].qualified_path.self_type.resolved_path.id' $Carrier
12+
// @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"\"
13+
// @is '$.index[*][?(@.name=="user")].inner.function.decl.inputs[0][1].function_pointer.decl.inputs[0][1].qualified_path.name' '"Focus"'
14+
// @is '$.index[*][?(@.name=="user")].inner.function.decl.inputs[0][1].function_pointer.decl.inputs[0][1].qualified_path.trait' null
15+
// @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"'
16+
pub fn user(_: for<'b> fn(Carrier<'b>::Focus<i32>)) {}
1617

1718
impl<'a> Carrier<'a> {
1819
pub type Focus<T> = &'a mut T;

tests/rustdoc-json/type/inherent_associated_type_projections.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
// @set Parametrized = '$.index[*][?(@.name=="Parametrized")].id'
66
pub struct Parametrized<T>(T);
77

8-
// @is '$.index[*][?(@.name=="Test")].inner.typedef.type.qualified_path.self_type.resolved_path.id' $Parametrized
9-
// @is '$.index[*][?(@.name=="Test")].inner.typedef.type.qualified_path.self_type.resolved_path.args.angle_bracketed.args[0].type.primitive' \"i32\"
10-
// @is '$.index[*][?(@.name=="Test")].inner.typedef.type.qualified_path.name' '"Proj"'
11-
// @is '$.index[*][?(@.name=="Test")].inner.typedef.type.qualified_path.trait' null
12-
pub type Test = Parametrized<i32>::Proj;
8+
// @count "$.index[*][?(@.name=='test')].inner.function.decl.inputs[*]" 1
9+
// @is "$.index[*][?(@.name=='test')].inner.function.decl.inputs[0][0]" '"_"'
10+
// @is '$.index[*][?(@.name=="test")].inner.function.decl.inputs[0][1].qualified_path.self_type.resolved_path.id' $Parametrized
11+
// @is '$.index[*][?(@.name=="test")].inner.function.decl.inputs[0][1].qualified_path.self_type.resolved_path.args.angle_bracketed.args[0].type.primitive' \"i32\"
12+
// @is '$.index[*][?(@.name=="test")].inner.function.decl.inputs[0][1].qualified_path.name' '"Proj"'
13+
// @is '$.index[*][?(@.name=="test")].inner.function.decl.inputs[0][1].qualified_path.trait' null
14+
pub fn test(_: Parametrized<i32>::Proj) {}
1315

1416
/// param_bool
1517
impl Parametrized<bool> {

tests/rustdoc/inherent-projections.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ impl Owner {
1313
}
1414

1515
// Make sure we handle bound vars correctly.
16-
// @has 'inherent_projections/type.User.html' '//pre[@class="rust item-decl"]' "for<'a> fn(_: Carrier<'a>::Focus)"
17-
pub type User = for<'a> fn(Carrier<'a>::Focus);
16+
// @has 'inherent_projections/fn.user.html' '//pre[@class="rust item-decl"]' "user(_: for<'a> fn(_: Carrier<'a>::Focus))"
17+
pub fn user(_: for<'a> fn(Carrier<'a>::Focus)) {}
1818

1919
pub struct Carrier<'a>(&'a ());
2020

@@ -27,11 +27,11 @@ impl<'a> Carrier<'a> {
2727
// FIXME(inherent_associated_types): Below we link to `Proj` but we should link to `Proj-1`.
2828
// The current test checks for the buggy behavior for demonstration purposes.
2929

30-
// @has 'inherent_projections/type.Test.html'
31-
// @has - '//pre[@class="rust item-decl"]' "Parametrized<i32>"
30+
// @has 'inherent_projections/fn.test.html'
31+
// @has - '//pre[@class="rust item-decl"]' "test(_: Parametrized<i32>::Proj)"
3232
// @has - '//pre[@class="rust item-decl"]//a[@class="associatedtype"]/@href' 'struct.Parametrized.html#associatedtype.Proj'
3333
// @!has - '//pre[@class="rust item-decl"]//a[@class="associatedtype"]/@href' 'struct.Parametrized.html#associatedtype.Proj-1'
34-
pub type Test = Parametrized<i32>::Proj;
34+
pub fn test(_: Parametrized<i32>::Proj) {}
3535

3636
pub struct Parametrized<T>(T);
3737

tests/ui/associated-inherent-types/issue-111879-0.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
pub struct Carrier<'a>(&'a ());
77

8-
pub type User = for<'b> fn(Carrier<'b>::Focus<i32>);
9-
108
impl<'a> Carrier<'a> {
11-
pub type Focus<T> = &'a mut User; //~ ERROR overflow evaluating associated type
9+
pub type Focus<T> = &'a mut for<'b> fn(Carrier<'b>::Focus<i32>); //~ ERROR overflow evaluating associated type
1210
}
1311

1412
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: overflow evaluating associated type `Carrier<'b>::Focus<i32>`
2-
--> $DIR/issue-111879-0.rs:11:25
2+
--> $DIR/issue-111879-0.rs:9:25
33
|
4-
LL | pub type Focus<T> = &'a mut User;
5-
| ^^^^^^^^^^^^
4+
LL | pub type Focus<T> = &'a mut for<'b> fn(Carrier<'b>::Focus<i32>);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error: aborting due to previous error
88

tests/ui/associated-inherent-types/late-bound-regions.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
// Test if we correctly normalize `S<'a>::P` with respect to late-bound regions.
55

6-
type Function = for<'a> fn(&'a i32) -> S<'a>::P;
7-
86
struct S<'a>(&'a ());
97

108
trait Inter {
@@ -16,7 +14,7 @@ impl<'a> S<'a> {
1614
}
1715

1816
fn ret_ref_local<'e>() -> &'e i32 {
19-
let f: Function = |x| x;
17+
let f: for<'a> fn(&'a i32) -> S<'a>::P = |x| x;
2018

2119
let local = 0;
2220
f(&local) //~ ERROR cannot return value referencing local variable `local`

tests/ui/associated-inherent-types/late-bound-regions.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0515]: cannot return value referencing local variable `local`
2-
--> $DIR/late-bound-regions.rs:22:5
2+
--> $DIR/late-bound-regions.rs:20:5
33
|
44
LL | f(&local)
55
| ^^------^

tests/ui/associated-inherent-types/not-found-self-type-differs.alias.stderr

-16
This file was deleted.

tests/ui/associated-inherent-types/not-found-self-type-differs.local.stderr

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// revisions: local alias
2-
31
#![feature(inherent_associated_types)]
42
#![allow(incomplete_features)]
53

@@ -13,10 +11,7 @@ impl<T> Family<Result<T, ()>> {
1311
type Proj = Self;
1412
}
1513

16-
#[cfg(alias)]
17-
type Alias = Family<Option<()>>::Proj; //[alias]~ ERROR associated type `Proj` not found for `Family<Option<()>>`
18-
1914
fn main() {
20-
#[cfg(local)]
21-
let _: Family<std::path::PathBuf>::Proj = (); //[local]~ ERROR associated type `Proj` not found for `Family<PathBuf>`
15+
let _: Family<Option<()>>::Proj; //~ ERROR associated type `Proj` not found for `Family<Option<()>>`
16+
let _: Family<std::path::PathBuf>::Proj = (); //~ ERROR associated type `Proj` not found for `Family<PathBuf>`
2217
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0220]: associated type `Proj` not found for `Family<Option<()>>` in the current scope
2+
--> $DIR/not-found-self-type-differs.rs:15:32
3+
|
4+
LL | struct Family<T>(T);
5+
| ---------------- associated item `Proj` not found for this struct
6+
...
7+
LL | let _: Family<Option<()>>::Proj;
8+
| ^^^^ associated item not found in `Family<Option<()>>`
9+
|
10+
= note: the associated type was found for
11+
- `Family<()>`
12+
- `Family<Result<T, ()>>`
13+
14+
error[E0220]: associated type `Proj` not found for `Family<PathBuf>` in the current scope
15+
--> $DIR/not-found-self-type-differs.rs:16:40
16+
|
17+
LL | struct Family<T>(T);
18+
| ---------------- associated item `Proj` not found for this struct
19+
...
20+
LL | let _: Family<std::path::PathBuf>::Proj = ();
21+
| ^^^^ associated item not found in `Family<PathBuf>`
22+
|
23+
= note: the associated type was found for
24+
- `Family<()>`
25+
- `Family<Result<T, ()>>`
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0220`.

tests/ui/associated-inherent-types/substitute-params-bad.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<T, S> Subj<(T, S)> {
1717
}
1818

1919
fn main() {
20-
type A = S<()>::P;
20+
let _: S<()>::P;
2121

2222
let _: Subj<(i32, i32)>::Un = 0i32; //~ ERROR mismatched types
2323
}

tests/ui/associated-inherent-types/substitute-params.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ impl<T> S<(T,)> {
1515

1616
fn main() {
1717
// Regression test for issue #104240.
18-
type A = S<()>::P;
19-
let _: A = ();
18+
let _: S<()>::P = ();
2019

2120
// Regression test for issue #107468.
2221
let _: S<(i32,)>::Un = 0i32;

tests/ui/associated-inherent-types/type-alias-bounds-are-enforced.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// check-pass
1+
// FIXME(inherent_associated_types): This should be `check-pass`
2+
// known-bug: #108491
23
// compile-flags: --crate-type=lib
34

45
#![feature(inherent_associated_types)]
@@ -17,7 +18,6 @@
1718

1819
pub type Alias<T: Bound> = (Source<T>::Assoc,);
1920

20-
2121
pub struct Source<T>(T);
2222
pub trait Bound {}
2323

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error[E0391]: cycle detected when expanding type alias `Alias`
2+
--> $DIR/type-alias-bounds-are-enforced.rs:19:1
3+
|
4+
LL | pub type Alias<T: Bound> = (Source<T>::Assoc,);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: ...which requires computing the variances of `Source`...
8+
--> $DIR/type-alias-bounds-are-enforced.rs:21:1
9+
|
10+
LL | pub struct Source<T>(T);
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
= note: ...which requires computing the variances for items in this crate...
13+
= note: ...which again requires expanding type alias `Alias`, completing the cycle
14+
note: cycle used when collecting item types in top-level module
15+
--> $DIR/type-alias-bounds-are-enforced.rs:5:1
16+
|
17+
LL | / #![feature(inherent_associated_types)]
18+
LL | | #![allow(incomplete_features)]
19+
LL | |
20+
LL | | // Bounds on the self type play a major role in the resolution of inherent associated types (*).
21+
... |
22+
LL | | pub type Assoc = ();
23+
LL | | }
24+
| |_^
25+
= 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
26+
27+
error[E0391]: cycle detected when expanding type alias `Alias`
28+
--> $DIR/type-alias-bounds-are-enforced.rs:19:1
29+
|
30+
LL | pub type Alias<T: Bound> = (Source<T>::Assoc,);
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^
32+
|
33+
note: ...which requires computing the variances of `Source`...
34+
--> $DIR/type-alias-bounds-are-enforced.rs:21:1
35+
|
36+
LL | pub struct Source<T>(T);
37+
| ^^^^^^^^^^^^^^^^^^^^
38+
= note: ...which requires computing the variances for items in this crate...
39+
= note: ...which again requires expanding type alias `Alias`, completing the cycle
40+
note: cycle used when collecting item types in top-level module
41+
--> $DIR/type-alias-bounds-are-enforced.rs:5:1
42+
|
43+
LL | / #![feature(inherent_associated_types)]
44+
LL | | #![allow(incomplete_features)]
45+
LL | |
46+
LL | | // Bounds on the self type play a major role in the resolution of inherent associated types (*).
47+
... |
48+
LL | | pub type Assoc = ();
49+
LL | | }
50+
| |_^
51+
= 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
52+
53+
error: aborting due to 2 previous errors
54+
55+
For more information about this error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)