-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #94438 - compiler-errors:check-method-inputs-once, r=…
…davidtwco Check method input expressions once If the user mistakenly forgets to wrap their method args in a tuple, then the compiler tries to check that types within the tuple match the expression args. This means we call `check_expr` once within this diagnostic code, so when we check the expr once again in `demand_compatible`, we attempt to apply expr adjustments twice, leading to ICEs. This PR attempts to fix this by skipping the expression type check in `demand_compatible` if we have detected an method arg mismatch at all. This does lead to a single UI test regressing slightly, due to a diagnostic disappearing, though I don't know if it is generally meaningful to even raise an type error after noting that the argument count is incorrect in a function call, since the user might be providing (in-context) meaningless expressions to the wrong method. I can adjust this to be a bit more targeted (to just skip checking exprs in `demand_compatible` in the tuple case) if this UI test regression is a problem. fixes #94334 cc #94291 Also drive-by fixup of `.node_type(expr.hir_id)` to `.expr_ty(expr)`, since that method exists.
- Loading branch information
Showing
8 changed files
with
53 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
fn test(t: (i32, i32)) {} | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
fn qux(&self) -> i32 { | ||
0 | ||
} | ||
} | ||
|
||
fn bar() { | ||
let x = Foo; | ||
test(x.qux(), x.qux()); | ||
//~^ ERROR this function takes 1 argument but 2 arguments were supplied | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0061]: this function takes 1 argument but 2 arguments were supplied | ||
--> $DIR/wrong_argument_ice-2.rs:13:5 | ||
| | ||
LL | test(x.qux(), x.qux()); | ||
| ^^^^ ------- ------- supplied 2 arguments | ||
| | ||
note: function defined here | ||
--> $DIR/wrong_argument_ice-2.rs:1:4 | ||
| | ||
LL | fn test(t: (i32, i32)) {} | ||
| ^^^^ ------------- | ||
help: use parentheses to construct a tuple | ||
| | ||
LL | test((x.qux(), x.qux())); | ||
| + + | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0061`. |