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

Implement as operator overload trait #6016

Closed
brendanzab opened this issue Apr 23, 2013 · 2 comments
Closed

Implement as operator overload trait #6016

brendanzab opened this issue Apr 23, 2013 · 2 comments

Comments

@brendanzab
Copy link
Member

Proposed trait for inclusion in core::ops:

#[lang="cast"]
trait Cast<T> {
    fn cast(&self) -> T;
}

Example implementation:

impl Cast<f32> for float { fn cast(&self) -> f32 { self as f32 } }
impl Cast<int> for f32   { fn cast(&self) -> int { self as int } }

impl<T: Cast<U>, U> Cast<Vec3<U>> for Vec3<T> {
    fn cast(&self) -> Vec3<U> {
        Vec3 { x: self.x as U, y: self.y as U, z: self.z as U }
    }
}

type Vec3f   = Vec3<float>;
type Vec3f32 = Vec3<f32>;
type Vec3i   = Vec3<int>;

fn main() {
    let a = Vec3 { x: 1f, y: 1f, z: 1f };
    let b = a as Vec3f32;
    let c = b as Vec3i;
}

Perhaps there could be a deriving attribute as well:

#[deriving(Cast)]
struct Vec3<T> { x: T, y: T, z: T }
@emberian
Copy link
Member

See #7080

@emberian
Copy link
Member

(closing as dup)

flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 10, 2020
…broto

Restrict `same_item_push` to suppress false positives

It only emits a lint when the pushed item is a literal, a constant and an immutable binding that are initialized with those, as discussed in rust-lang/rust-clippy#5997 (review).

Fix rust-lang/rust-clippy#5985

changelog: Restrict `same_item_push` to literals, constants and immutable bindings that are initialized with those.

r? `@ebroto`
flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 9, 2020
Add changelog for 1.48 beta

[Rendered](https://github.com/ebroto/rust-clippy/blob/changelog_1_48/CHANGELOG.md)

I've not added the PRs fixing `same_item_push` because those were backported, namely:
* [rust-lang#5908](rust-lang/rust-clippy#5908)
* [rust-lang#5997](rust-lang/rust-clippy#5997)
* [rust-lang#6016](rust-lang/rust-clippy#6016)

The following PR was reverted, so I've ignored it too:
* [rust-lang#5984](rust-lang/rust-clippy#5984)

~~Also, I took the liberty of adding a "Thanks" section, naming all the contributors to this release. I think they deserve visibility in the changelog. Please tell me if we want to add this or maybe it's redundant given we link to the PRs?~~

changelog: none

r? `@flip1995`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants