Skip to content

Commit 29e1ddd

Browse files
authored
Rollup merge of #136497 - Jarcho:fn_ctxt, r=compiler-errors
Report generic mismatches when calling bodyless trait functions Don't know if there's an open issue for this. Just happened to notice this when working in that area. The awkward extra spans added to the diagnostics of some tests (e.g. `trait-with-missing-associated-type-restriction`) is consistent with what happens for normal functions. Should probably be removed since that span doesn't seem to note anything useful. First and third commit are both cleanups removing some unnecessary work. Second commit has the actual fix. fixes #135124
2 parents 46b18a9 + 8b1c28f commit 29e1ddd

9 files changed

+243
-124
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+141-112
Large diffs are not rendered by default.

tests/crashes/135124.rs

-9
This file was deleted.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Used to ICE due to a size mismatch between the actual fake signature of `fold` and the
2+
// generated signature used reporting the parameter mismatch at the call site.
3+
// See issue #135124
4+
5+
trait A {
6+
fn y(&self)
7+
{
8+
fn call() -> impl Sized {}
9+
self.fold(call(), call());
10+
}
11+
fn fold<T>(&self, _: T, &self._) {}
12+
//~^ ERROR unexpected `self` parameter in function
13+
//~| ERROR expected one of `)` or `,`, found `.`
14+
//~| ERROR identifier `self` is bound more than once in this parameter list
15+
//~| WARNING anonymous parameters are deprecated
16+
//~| WARNING this is accepted in the current edition
17+
//~| ERROR the placeholder `_` is not allowed within types
18+
}
19+
20+
fn main() {}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error: unexpected `self` parameter in function
2+
--> $DIR/error-recovery-mismatch.rs:11:29
3+
|
4+
LL | fn fold<T>(&self, _: T, &self._) {}
5+
| ^^^^^ must be the first parameter of an associated function
6+
7+
error: expected one of `)` or `,`, found `.`
8+
--> $DIR/error-recovery-mismatch.rs:11:34
9+
|
10+
LL | fn fold<T>(&self, _: T, &self._) {}
11+
| ^
12+
| |
13+
| expected one of `)` or `,`
14+
| help: missing `,`
15+
16+
error[E0415]: identifier `self` is bound more than once in this parameter list
17+
--> $DIR/error-recovery-mismatch.rs:11:30
18+
|
19+
LL | fn fold<T>(&self, _: T, &self._) {}
20+
| ^^^^ used as parameter more than once
21+
22+
warning: anonymous parameters are deprecated and will be removed in the next edition
23+
--> $DIR/error-recovery-mismatch.rs:11:35
24+
|
25+
LL | fn fold<T>(&self, _: T, &self._) {}
26+
| ^ help: try naming the parameter or explicitly ignoring it: `_: _`
27+
|
28+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
29+
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
30+
= note: `#[warn(anonymous_parameters)]` on by default
31+
32+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
33+
--> $DIR/error-recovery-mismatch.rs:11:35
34+
|
35+
LL | fn fold<T>(&self, _: T, &self._) {}
36+
| ^ not allowed in type signatures
37+
|
38+
help: use type parameters instead
39+
|
40+
LL | fn fold<T, U>(&self, _: T, &self.U) {}
41+
| +++ ~
42+
43+
error: aborting due to 4 previous errors; 1 warning emitted
44+
45+
Some errors have detailed explanations: E0121, E0415.
46+
For more information about an error, try `rustc --explain E0121`.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trait Foo {
2+
fn same_type<T>(_: T, _: T);
3+
}
4+
5+
fn f<T: Foo, X, Y>(x: X, y: Y) {
6+
T::same_type([x], Some(y));
7+
//~^ ERROR mismatched types
8+
}
9+
10+
fn main() {}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/param-mismatch-trait-fn.rs:6:23
3+
|
4+
LL | T::same_type([x], Some(y));
5+
| ------------ --- ^^^^^^^ expected `[X; 1]`, found `Option<Y>`
6+
| | |
7+
| | expected all arguments to be this `[X; 1]` type because they need to match the type of this parameter
8+
| arguments to this function are incorrect
9+
|
10+
= note: expected array `[X; 1]`
11+
found enum `Option<Y>`
12+
note: associated function defined here
13+
--> $DIR/param-mismatch-trait-fn.rs:2:8
14+
|
15+
LL | fn same_type<T>(_: T, _: T);
16+
| ^^^^^^^^^ - - - this parameter needs to match the `[X; 1]` type of parameter #1
17+
| | |
18+
| | parameter #2 needs to match the `[X; 1]` type of this parameter
19+
| parameter #1 and parameter #2 both reference this parameter `T`
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0308`.

tests/ui/methods/issues/issue-61525.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ note: method defined here
3232
--> $DIR/issue-61525.rs:2:8
3333
|
3434
LL | fn query<Q>(self, q: Q);
35-
| ^^^^^
35+
| ^^^^^ -
3636

3737
error: aborting due to 2 previous errors
3838

tests/ui/suggestions/trait-with-missing-associated-type-restriction.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ note: method defined here
9494
--> $DIR/trait-with-missing-associated-type-restriction.rs:9:8
9595
|
9696
LL | fn funk(&self, _: Self::A);
97-
| ^^^^
97+
| ^^^^ -
9898
help: consider constraining the associated type `<T as Trait<i32>>::A` to `{integer}`
9999
|
100100
LL | fn bar2<T: Trait<i32, A = {integer}>>(x: T) {

tests/ui/traits/issue-52893.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ note: method defined here
2222
--> $DIR/issue-52893.rs:11:8
2323
|
2424
LL | fn push(self, other: T) -> Self::PushRes;
25-
| ^^^^
25+
| ^^^^ -----
2626

2727
error: aborting due to 1 previous error
2828

0 commit comments

Comments
 (0)