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

Better diagnostics for binary operators #59458

Closed
tumdum opened this issue Mar 27, 2019 · 2 comments
Closed

Better diagnostics for binary operators #59458

tumdum opened this issue Mar 27, 2019 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tumdum
Copy link

tumdum commented Mar 27, 2019

use std::ops::Mul;

struct BoxedValue<T: Mul> {
    value: T
}

impl<T: Mul<Output=T>> Mul for BoxedValue<T> {
    type Output = Self;

    fn mul(self, rhs: Self) -> Self {
        BoxedValue{value: self.value*rhs.value}
    }
}

fn width<T: Mul>(value: T) -> BoxedValue<T> {
    BoxedValue{value}
}

fn height<T: Mul>(value: T) -> BoxedValue<T> {
    BoxedValue{value}
}

fn foo(s1: f64, s2: f64) -> BoxedValue<f64> {
    (width(s1) * height(s1)) + (width(s2) * height(s2))
}

fn main() {
}

(Playground)

When compiled produces error which only highlights whole expression - offending operator is not marked in any way.
Newest gcc is capable of much nicer diagnostics in similar situation: https://developers.redhat.com/blog/2019/03/08/usability-improvements-in-gcc-9/ - similar diagnostics should be added to rustc.

@jonas-schievink jonas-schievink added C-enhancement Category: An issue proposing an enhancement or a PR with one. 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 Mar 27, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Mar 27, 2019

I think the following steps should be able to address this

  1. Change
    let mut err = struct_span_err!(self.tcx.sess, expr.span, E0369,
    to use op.span instead of expr.span
  2. add a call to err.span_label(lhs_expr.span, lhs_ty.to_string())
  3. do 2. for rhs_*, too
  4. run ./x.py test --stage 1 src/test/ui --bless

@oli-obk oli-obk added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Mar 27, 2019
@hgallagher1993
Copy link
Contributor

Ya I'll take this on 👍

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants