Skip to content

Generic Mul Bound Error #82046

Open
Open
@pacmanmati

Description

@pacmanmati

I tried this code:

use cgmath::{Vector3, Point3};
use std::ops::Mul;

#[derive(Debug)]
pub struct Ray<S> {
    pub origin: Point3<S>,
    pub direction: Vector3<S>,
}

impl <S> Ray<S> {
    pub fn new(origin: Point3<S>, direction: Vector3<S>) -> Self {
	Self { origin, direction }
    }

    pub fn at(&self, t: S) -> Self {
	let aaa = self.direction * t;
	Self { origin: self.origin, direction: aaa }
    }
}

I expected to see this happen: Compiler suggests the following bound

where
    Vector3<S>: Mul<S, Output = Vector3<S>>

Instead, this happened: Compiler suggests the following bound

where
    S: Mul<Output = Vector3<S>>

the above bound doesn't constrain the generic correctly and the compiler will keep requesting you add it despite it already being present.

Meta

The bug also occurs when I use nightly.

rustc --version --verbose:

rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: aarch64-apple-darwin
release: 1.50.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.S-has-bisectionStatus: A bisection has been found for this issueT-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