-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Report generic mismatches when calling bodyless trait functions #136497
Conversation
rustbot has assigned @petrochenkov. Use |
This comment has been minimized.
This comment has been minimized.
LGTM. I'll approve when it's green. |
| ^^^^^^^^^ - - - this parameter needs to match the `[X; 1]` type of `` | ||
| | | | ||
| | `` needs to match the `[X; 1]` type of this parameter | ||
| `` and `` both reference this parameter `T` |
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.
btw, are all these empty `` names expected?
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.
Whoops, yeah we should definitely be returning None
if the param names are empty.
13ee415
to
1a886cf
Compare
@@ -2484,7 +2485,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
} | |||
generics_with_unmatched_params.push(generic_param); | |||
} else { | |||
spans.push_span_label(param.span, ""); | |||
spans.push_span_label(param.span(), ""); |
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.
This is the line adding all the extra spans to the diagnostic. It looks like it's just a catch-all for parameters that aren't otherwise matched.
Given that the final commit already affects a pile of tests should I just go ahead and remove it?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -97,7 +97,7 @@ note: function defined here | |||
--> $DIR/extra_arguments.rs:3:4 | |||
| | |||
LL | fn two_arg_same(_a: i32, _b: i32) {} | |||
| ^^^^^^^^^^^^ ------- ------- |
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.
Where did this span go? This seems wrong lol.
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.
The code marking those spans just marks the span of all arguments that aren't generics used in multiple positions. It's also not applied to anything without a body (e.g. foreign functions).
The message as a whole is:
rust/tests/ui/argument-suggestions/extra_arguments.stderr
Lines 90 to 105 in f027438
error[E0061]: this function takes 2 arguments but 3 arguments were supplied | |
--> $DIR/extra_arguments.rs:26:3 | |
| | |
LL | two_arg_same(1, 1, 1); | |
| ^^^^^^^^^^^^ - unexpected argument #3 of type `{integer}` | |
| | |
note: function defined here | |
--> $DIR/extra_arguments.rs:3:4 | |
| | |
LL | fn two_arg_same(_a: i32, _b: i32) {} | |
| ^^^^^^^^^^^^ ------- ------- | |
help: remove the extra argument | |
| | |
LL - two_arg_same(1, 1, 1); | |
LL + two_arg_same(1, 1); | |
| |
Why are the arguments even being given spans here? The message is noting where the definition is and it's a pile of spans.
I can remove the third commit. It wasn't really the main point anyways and is the cause of the hundred files worth of changes.
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.
Labeling parameters that correspond to mismatched arguments at a call site is something that has existed since #92364, way before #121595 refined this logic to have better error messages for generics, so these spans were never intended to only highlight generic args. I think these spans are particularly useful in general even if it can be excessive in some UI tests.
The choice of example (argument-suggestions/extra_arguments.rs
) is kinda an outlier; the fact that "too many arguments" type errors underline all of the argument spans is possibly excessive, but this also regresses cases where highlighting the spans of the arguments is useful, like when arguments are permuted or there are missing arguments.
I think it's kinda unwarranted to be changing this behavior anyways with basically no explanation or justification, so yes, I'd probably prefer if we'd it.
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.
Going back looks like df93364 actually broke the span marking here. It used to mark only relevant parameters before the generic arg matching code was added.
Given that fixing this is going to be a whole bunch of extra work I'll just revert the change for now.
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.
If you want to author a fix, I'm happy to review that too in a separate PR. But I think removing all non-generic spans is kinda orthogonal and unnecessary here.
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.
Reverted now.
This PR seems to remove a lot more than just "useless spans", now 🤔 . Since this PR has now ballooned to way more than what it was doing when I first approved it, I'm gonna pass it back to you to both refine the implementation and also explain what you're changing here in the PR description and why. @rustbot author |
/// unavailable (eg is an instrinsic). | ||
/// type of that parameter. | ||
/// | ||
/// Returns `None` if the function has no parameters taking generic type, or the function is |
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.
This doesn't really make sense...? I think it's meaningful to return spans for functions if they don't have generics... like, people can still make argument mismatch errors if the function is not generic 🤔
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.
This is specifically for, and only used for, generic mismatches. It doesn't really make sense to gather the generic parameters outside that context.
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.
We still definitely want to label mismatched parameters even if those parameters are not associated with generic parameters, though.
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.
Reverted as part of the other issue.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Why is tidy complaining about the test name? There are other tests with exactly the same naming scheme right next to it. |
They're grandfathered in, and we no longer permit adding new |
Ah. The crashtest message should probably be changed then since it said just to move the file. |
Do you want the ICE fix moved into it's own PR? It's basically a one line fix. |
The crashtest suite actually says to give it a meaningful name:
|
Apparently I just cant read then. Should be ready now assuming CI works. @rustbot ready |
This comment has been minimized.
This comment has been minimized.
@bors r+ rollup |
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 rust-lang#135124
Rollup of 9 pull requests Successful merges: - rust-lang#128045 (#[contracts::requires(...)] + #[contracts::ensures(...)]) - rust-lang#136263 (rustdoc: clean up a bunch of ts-expected-error declarations in main) - rust-lang#136375 (cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 1)) - rust-lang#136392 (bootstrap: add wrapper macros for `feature = "tracing"`-gated `tracing` macros) - rust-lang#136405 (rustdoc-book: Clean up section on `--output-format`) - rust-lang#136497 (Report generic mismatches when calling bodyless trait functions) - rust-lang#136502 (Mark `std::fmt::from_fn` as `#[must_use]`) - rust-lang#136509 (Add tests for nested macro_rules edition behavior) - rust-lang#136526 (mir_build: Rename `thir::cx::Cx` to `ThirBuildCx` and remove `UserAnnotatedTyHelpers`) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#136242 (Remove `LateContext::match_def_path()`) - rust-lang#136274 (Check Sizedness of return type in WF) - rust-lang#136284 (Allow using named consts in pattern types) - rust-lang#136477 (Fix a couple NLL TLS spans ) - rust-lang#136497 (Report generic mismatches when calling bodyless trait functions) - rust-lang#136520 (Remove unnecessary layout assertions for object-safe receivers) - rust-lang#136526 (mir_build: Rename `thir::cx::Cx` to `ThirBuildCx` and remove `UserAnnotatedTyHelpers`) Failed merges: - rust-lang#136304 (Reject negative literals for unsigned or char types in pattern ranges and literals) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#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 rust-lang#135124
Only highlight unmatchable parameters at the definition site Followup to rust-lang#136497 This generally results more focused messages in the same vein as rust-lang#99635 (see `test/ui/argument-suggestions/complex.rs`). There are still some cases (e.g. `test/ui/argument-suggestions/permuted_arguments.rs`) where it might be worth highlighting the arguments. This is mitigated by the fact that a suggestion with a suggested rearrangement is given. r? `@compiler-errors`
Rollup merge of rust-lang#136583 - Jarcho:fn_ctxt2, r=compiler-errors Only highlight unmatchable parameters at the definition site Followup to rust-lang#136497 This generally results more focused messages in the same vein as rust-lang#99635 (see `test/ui/argument-suggestions/complex.rs`). There are still some cases (e.g. `test/ui/argument-suggestions/permuted_arguments.rs`) where it might be worth highlighting the arguments. This is mitigated by the fact that a suggestion with a suggested rearrangement is given. r? `@compiler-errors`
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