diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-09-18 04:42:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-18 04:42:32 +0200 |
| commit | c52d58dce1044c896153082272522a1d499e95b0 (patch) | |
| tree | a23a21ff3645d76b482b46c98296541c24ff1da7 /tests | |
| parent | 862f3e768574e39686b768bf34f11b9e4bfe829e (diff) | |
| parent | 3cb1f334b8c74f7c8c5860e2c84b317fbc86165d (diff) | |
| download | rust-c52d58dce1044c896153082272522a1d499e95b0.tar.gz rust-c52d58dce1044c896153082272522a1d499e95b0.zip | |
Rollup merge of #130496 - jder:issue-130400, r=compiler-errors
Fix circular fn_sig queries to correct number of args for methods
Fixes #130400. This was a [debug assert](https://github.com/rust-lang/rust/blob/28e8f01c2a2f33fb4214925a704e3223b372cad5/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs#L2557) added to some argument error reporting code in #129320 which verified that the number of params (from the HIR) matched the `matched_inputs` which ultimately come from ty::FnSig. In the reduced test case:
```
fn foo(&mut self) -> _ {
foo()
}
```
There is a circular dependency computing the ty::FnSig -- when trying to compute it, we try to figure out the return value, which again depends on this ty::FnSig. In #105162, this was supported by short-circuiting the cycle by synthesizing a FnSig with error types for parameters. The [code in question](https://github.com/rust-lang/rust/pull/105162/files#diff-a65feec6bfffb19fbdc60a80becd1030c82a56c16b177182cd277478fdb04592R44) computes the number of parameters by taking the number of parameters from the hir::FnDecl and adding 1 if there is an implicit self parameter.
I might be missing a subtlety here, but AFAICT the adjustment for implicit self args is unnecessary and results in one too many args. For example, for this non-errorful code:
```
trait Foo {
fn bar(&self) {}
}
```
The resulting hir::FnDecl and ty::FnSig both have the same number of inputs -- 1. So, this PR removes that adjustment and adds a test for the debug ICE.
r? `@compiler-errors`
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/mismatched_types/mismatch-args-crash-issue-130400.rs | 8 | ||||
| -rw-r--r-- | tests/ui/mismatched_types/mismatch-args-crash-issue-130400.stderr | 26 |
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/ui/mismatched_types/mismatch-args-crash-issue-130400.rs b/tests/ui/mismatched_types/mismatch-args-crash-issue-130400.rs new file mode 100644 index 00000000000..16c4e639c29 --- /dev/null +++ b/tests/ui/mismatched_types/mismatch-args-crash-issue-130400.rs @@ -0,0 +1,8 @@ +trait Bar { + fn foo(&mut self) -> _ { + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + Self::foo() //~ ERROR this function takes 1 argument but 0 arguments were supplied + } +} + +fn main() {} diff --git a/tests/ui/mismatched_types/mismatch-args-crash-issue-130400.stderr b/tests/ui/mismatched_types/mismatch-args-crash-issue-130400.stderr new file mode 100644 index 00000000000..0e4b94b98e2 --- /dev/null +++ b/tests/ui/mismatched_types/mismatch-args-crash-issue-130400.stderr @@ -0,0 +1,26 @@ +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/mismatch-args-crash-issue-130400.rs:4:9 + | +LL | Self::foo() + | ^^^^^^^^^-- argument #1 is missing + | +note: method defined here + --> $DIR/mismatch-args-crash-issue-130400.rs:2:8 + | +LL | fn foo(&mut self) -> _ { + | ^^^ --------- +help: provide the argument + | +LL | Self::foo(/* value */) + | ~~~~~~~~~~~~~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/mismatch-args-crash-issue-130400.rs:2:26 + | +LL | fn foo(&mut self) -> _ { + | ^ not allowed in type signatures + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0061, E0121. +For more information about an error, try `rustc --explain E0061`. |
