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

Random musing on the library-level UB casting problem #139036

Closed
traviscross opened this issue Mar 27, 2025 · 3 comments
Closed

Random musing on the library-level UB casting problem #139036

traviscross opened this issue Mar 27, 2025 · 3 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@traviscross
Copy link
Contributor

traviscross commented Mar 27, 2025

Over in:

We're talking about how safe lifetime casts can allow library-level UB. It's interesting to think about other things that fit this pattern that also might be said to cause library-level UB under certain expectations.

steffahn described in #136702 (comment) a plan for using dyn Trait and nightly features for triggering library-level UB. It looks like this:

Playground link

Translating this to a non-dyn context, we get this, which has a similar shape to it:

Playground link

@rustbot labels +T-lang +T-types +C-discussion

@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-discussion Category: Discussion or questions that doesn't represent real issues. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. labels Mar 27, 2025
@traviscross traviscross changed the title Safe lifetime casts allow library-level UB Safe lifetime casts allow library-level UB? Mar 27, 2025
@traviscross traviscross removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 27, 2025
@traviscross traviscross changed the title Safe lifetime casts allow library-level UB? Many safe casts allow library-level UB? Mar 27, 2025
@traviscross

This comment has been minimized.

@Darksonn
Copy link
Contributor

You can call it like this:

fn main() {
    ub::<W<'static>>();
}

When it's a generic parameter, you can call it even if you can't construct it.

@traviscross
Copy link
Contributor Author

traviscross commented Mar 27, 2025

Yes, of course. It is interesting though how much this shares the shape of the other case about which we are worried.

@traviscross traviscross closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2025
@traviscross traviscross changed the title Many safe casts allow library-level UB? Random musing on the library-level UB casting problem Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants