-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ensure arguments are included in count mismatch span #75023
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
r? @estebank |
note: function defined here | ||
--> $DIR/not-enough-arguments.rs:9:1 | ||
| | ||
LL | / fn bar( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead point at the ident instead of the full fn head?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supplied
--> $DIR/not-enough-arguments.rs:26:3
|
LL | foo(1, 2, 3);
| ^^^ - - - supplied 3 arguments
| |
| expected 4 arguments
|
note: function defined here
--> $DIR/not-enough-arguments.rs:5:4
|
LL | fn foo(a: isize, b: isize, c: isize, d:isize) {
| ^^^ ^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^
error[E0061]: this function takes 6 arguments but 1 argument was supplied
--> $DIR/not-enough-arguments.rs:28:3
|
LL | bar(1);
| ^^^ - supplied 1 argument
| |
| expected 6 arguments
|
note: function defined here
--> $DIR/not-enough-arguments.rs:9:4
|
LL | fn bar(
| ^^^
LL | a: i32,
| ^^^^^^^
LL | b: i32,
| ^^^^^^^
LL | c: i32,
| ^^^^^^^
LL | d: i32,
| ^^^^^^^
LL | e: i32,
| ^^^^^^^
LL | f: i32,
| ^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0061`.
Personally, I prefer pointing at the whole head since the missing paren in the multi-line case looks off-balance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does a bit, but it makes it less busy (fewer lines going around) and works much better when used by VSCode (overlapping spans look terrible there).
☔ The latest upstream changes (presumably #75465) made this pull request unmergeable. Please resolve the merge conflicts. |
There's merge conflicts now |
Yes, I'll try to get back to this this weekend. |
173f5b5
to
6bbc711
Compare
@rustbot modify labels: -S-waiting-on-author +S-waiting-on-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick
6bbc711
to
6b38eaa
Compare
6b38eaa
to
286b88f
Compare
☔ The latest upstream changes (presumably #77926) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
r=me fixing the merge conflict (sorry I didn't approve earlier!) |
Rebased. |
@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author |
@bors r+ |
📌 Commit 873cce7130eb1af94b4ca610b09ff929f2969121 has been approved by |
🌲 The tree is currently closed for pull requests below priority 100, this pull request will be tested once the tree is reopened |
⌛ Testing commit 873cce7130eb1af94b4ca610b09ff929f2969121 with merge 9b9c79afb73c9b07aae3e711b5b479bd92466210... |
💔 Test failed - checks-actions |
let mut spans: MultiSpan = node | ||
.ident() | ||
.map(|ident| ident.span) | ||
.unwrap_or_else(|| tcx.hir().span(node.hir_id().unwrap())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/rust-lang-ci/rust/runs/1256722042#step:24:22154
error[E0599]: no method named `hir_id` found for enum `rustc_hir::Node<'_>` in the current scope
--> compiler/rustc_typeck/src/check/fn_ctxt/checks.rs:180:64
|
180 | .unwrap_or_else(|| tcx.hir().span(node.hir_id().unwrap()))
| ^^^^^^ method not found in `rustc_hir::Node<'_>`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#77739 removed hir_id()
. Rebased and added it back.
@bors r+ |
📌 Commit 14b2d16 has been approved by |
ensure arguments are included in count mismatch span The current diagnostic isn't very helpful if the function header spans multiple lines. Lines comprising the function signature may be elided to keep the diagnostic short, but these lines are essential to fixing the error. This is made worse when the function has a body, because the last two lines of the span are then dedicated to showing the end of the body, which is irrelevant. This PR changes the span to be a multispan made up of the header and the the arguments, ensuring they won't be elided. It also discards the function body from the span. [Old](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f92d9f81a8c9416f0f04e4e09923b6d4): ``` error[E0061]: this function takes 6 arguments but 1 argument was supplied --> src/main.rs:18:5 | 1 | / fn bar( 2 | | a: i32, 3 | | b: i32, 4 | | c: i32, ... | 14 | | println!("{}", f); 15 | | } | |_- defined here ... 18 | bar(1); | ^^^ - supplied 1 argument | | | expected 6 arguments ``` New: ``` error[E0061]: this function takes 6 arguments but 1 argument was supplied --> $DIR/not-enough-arguments.rs:28:3 | LL | bar(1); | ^^^ - supplied 1 argument | | | expected 6 arguments | note: function defined here --> $DIR/not-enough-arguments.rs:9:1 | LL | / fn bar( LL | | a: i32, | | ^^^^^^^ LL | | b: i32, | | ^^^^^^^ LL | | c: i32, | | ^^^^^^^ LL | | d: i32, | | ^^^^^^^ LL | | e: i32, | | ^^^^^^^ LL | | f: i32, | | ^^^^^^^ LL | | ) { | |_^ ```
Rollup of 14 pull requests Successful merges: - rust-lang#75023 (ensure arguments are included in count mismatch span) - rust-lang#75265 (Add `str::{Split,RSplit,SplitN,RSplitN,SplitTerminator,RSplitTerminator,SplitInclusive}::as_str` methods) - rust-lang#75675 (mangling: mangle impl params w/ v0 scheme) - rust-lang#76084 (Refactor io/buffered.rs into submodules) - rust-lang#76119 (Stabilize move_ref_pattern) - rust-lang#77493 (ICEs should always print the top of the query stack) - rust-lang#77619 (Use futex-based thread-parker for Wasm32.) - rust-lang#77646 (For backtrace, use StaticMutex instead of a raw sys Mutex.) - rust-lang#77648 (Static mutex is static) - rust-lang#77657 (Cleanup cloudabi mutexes and condvars) - rust-lang#77672 (Simplify doc-cfg rendering based on the current context) - rust-lang#77780 (rustc_parse: fix spans on cast and range exprs with attrs) - rust-lang#77935 (BTreeMap: make PartialCmp/PartialEq explicit and tested) - rust-lang#77980 (Fix intra doc link for needs_drop) Failed merges: r? `@ghost`
The current diagnostic isn't very helpful if the function header spans multiple lines. Lines comprising the function signature may be elided to keep the diagnostic short, but these lines are essential to fixing the error. This is made worse when the function has a body, because the last two lines of the span are then dedicated to showing the end of the body, which is irrelevant.
This PR changes the span to be a multispan made up of the header and the the arguments, ensuring they won't be elided. It also discards the function body from the span.
Old:
New: