Skip to content

Commit 8b1c28f

Browse files
committed
Fix ICE when function argument mismatches.
1 parent 6378fbc commit 8b1c28f

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
126126
Err(guar) => Err(guar),
127127
};
128128
if let Err(guar) = has_error {
129-
let err_inputs = self.err_args(args_no_rcvr.len(), guar);
129+
let err_inputs = self.err_args(
130+
method.map_or(args_no_rcvr.len(), |method| method.sig.inputs().len() - 1),
131+
guar,
132+
);
130133
let err_output = Ty::new_error(self.tcx, guar);
131134

132135
let err_inputs = match tuple_arguments {

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`.

0 commit comments

Comments
 (0)