Skip to content

Better diagnostics for binary operators #59458

Closed
@tumdum

Description

@tumdum
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions