-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.S-has-bisectionStatus: A bisection has been found for this issueStatus: A bisection has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.S-has-bisectionStatus: A bisection has been found for this issueStatus: A bisection has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.