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

missing_transmute_annotations: No explanation for why missing input generic is bad #13339

Closed
tyilo opened this issue Sep 3, 2024 · 2 comments · Fixed by #13344
Closed

missing_transmute_annotations: No explanation for why missing input generic is bad #13339

tyilo opened this issue Sep 3, 2024 · 2 comments · Fixed by #13344
Assignees
Labels
A-documentation Area: Adding or improving documentation

Comments

@tyilo
Copy link

tyilo commented Sep 3, 2024

Description

I just ran clippy on an old project where I have some code like:

use std::mem::{transmute, MaybeUninit};

struct Foo<T> {
    array: Box<[T]>,
}

impl<T> Foo<MaybeUninit<T>> {
    unsafe fn assume_init(self) -> Foo<T> {
        Foo {
            array: unsafe { transmute::<_, Box<[T]>>(self.array) }
        }
    }
}

The "Why is this bad?" section states:

If not set, some unexpected output type could be retrieved instead of the expected one, potentially leading to invalid code.

This is particularly dangerous in case a seemingly innocent/unrelated change can cause type inference to start inferring a different type. E.g. the transmute is the tail expression of an if branch, and a different branches type changes, causing the transmute to silently have a different type, instead of a proper error.

This explanation doesn't cover the case where the output type is specified but not the input type.

Either the description should be updated to explain why transmute::<_, T> is also bad or the lint should only apply when the output type is missing.

Version

rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.7

Additional Labels

No response

@lukaslueg
Copy link
Contributor

@rustbot claim

@alex-semenyuk
Copy link
Member

@rustbot label A-documentation

@rustbot rustbot added the A-documentation Area: Adding or improving documentation label Sep 4, 2024
bors added a commit that referenced this issue Sep 11, 2024
Expand missing_transmute_annotations docs

Fixes #13339

changelog: [`missing_transmute_annotations `]: Expand docs, raison d'être
@bors bors closed this as completed in 7d2e6eb Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documentation Area: Adding or improving documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants