Skip to content
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

Function signature probably shouldn't be reported if an argument type mismatch is 'trivial' #99635

Closed
zesterer opened this issue Jul 23, 2022 · 2 comments · Fixed by #99646
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zesterer
Copy link
Contributor

zesterer commented Jul 23, 2022

I've been recently doing a large amount of refactoring on my compiler. Although this has broadly been a pleasant experience, recent diagnostic changes have put a little pressure on my scroll wheel. Diagnostics that I (and I think many others, even newcomers) would consider trivial can sometimes take up many dozens of lines of compiler output. I definitely appreciate the verbosity, but I don't think it's always called for (at least, by default). As an example, I recently encountered the following error message:

error[E0308]: mismatched types
    --> analysis/src/infer.rs:1959:66
     |
1959 | ...                   .for_each(|(x, y)| self.derive_links(x, y, self_ty, ty_links, eff_links)),
     |                                               ------------ ^ expected struct `tao_util::index::Id`, found reference
     |                                               |
     |                                               arguments to this function are incorrect
     |
     = note: expected struct `tao_util::index::Id<(tao_syntax::Span, ty::Ty)>`
             found reference `&tao_util::index::Id<(tao_syntax::Span, ty::Ty)>`
note: associated function defined here
    --> analysis/src/infer.rs:1866:8
     |
1866 |     fn derive_links(
     |        ^^^^^^^^^^^^
1867 |         &mut self,
     |         ---------
1868 |         member: TyId,
     |         ------------
1869 |         ty: TyVar,
     |         ---------
1870 |         self_ty: Option<TyVar>,
     |         ----------------------
1871 |         ty_links: &mut HashMap<usize, TyVar>,
     |         ------------------------------------
1872 |         eff_links: &mut HashMap<usize, EffectVar>,
     |         -----------------------------------------
help: consider dereferencing the borrow
     |
1959 |                             .for_each(|(x, y)| self.derive_links(*x, y, self_ty, ty_links, eff_links)),
     |                                                                  +

That's 31 lines of terminal output to inform me that I forgot a *. As I say, I do appreciate the verbosity! But in cases like this, where the compiler can determine that the mismatch is trivial and the intended result is obvious (i.e: dereference the reference), I feel that the compiler should omit some of the more verbose parts of the message, such as the signature of the function.

I realise that this is, to some extent, bikeshedding: but there is a very real trade-off between the assistance provided by a compiler error and redundant information in the error message that makes the cycle of fixing error messages slower and more inconvenient.

In my view, an output like the following where the original signature has been omitted has a much better tradeoff between verbosity and the time required to read the message and get to the heart of what the compiler is suggesting:

error[E0308]: mismatched types
    --> analysis/src/infer.rs:1959:66
     |
1959 | ...                   .for_each(|(x, y)| self.derive_links(x, y, self_ty, ty_links, eff_links)),
     |                                               ------------ ^ expected struct `tao_util::index::Id`, found reference
     |                                               |
     |                                               arguments to this function are incorrect
     |
     = note: expected struct `tao_util::index::Id<(tao_syntax::Span, ty::Ty)>`
             found reference `&tao_util::index::Id<(tao_syntax::Span, ty::Ty)>`
help: consider dereferencing the borrow
     |
1959 |                             .for_each(|(x, y)| self.derive_links(*x, y, self_ty, ty_links, eff_links)),
     |                                                                  +

I am happy to make a PR for this myself, but I've not worked on rustc diagnostics before and may need pointing to the relevant code.

@zesterer zesterer added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 23, 2022
@compiler-errors
Copy link
Member

I took a stab at this in #99646, let me know what you think. Specifically, we now only highlight the single mismatched parameter: https://github.com/rust-lang/rust/pull/99646/files#diff-e60ae3276b7c8ae96680b146101fe6e91f5bd3240aac50d11f88fdf110daa4ae

@zesterer
Copy link
Contributor Author

I took a stab at this in #99646, let me know what you think.

Based on the changes in the diff, this seems like it would be a big improvement, much appreciated! I also like that only the parameter in question is mentioned now.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Aug 13, 2022
…-arg-label, r=estebank

Only point out a single function parameter if we have a single arg incompatibility

Fixes rust-lang#99635
@bors bors closed this as completed in 2af3445 Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants