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

Use subtyping for UnsafeFnPointer coercion, too #129288

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

compiler-errors
Copy link
Member

I overlooked this in #129059, which changed MIR typechecking to use subtyping for other fn pointer coercions.

Fixes #129285

@rustbot
Copy link
Collaborator

rustbot commented Aug 20, 2024

r? @cjgillot

rustbot has assigned @cjgillot.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 20, 2024
@cjgillot
Copy link
Contributor

I don't feel comfortable to review this.
r? lcnr

@rustbot rustbot assigned lcnr and unassigned cjgillot Aug 24, 2024
ty_fn_ptr_from,
*ty,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you flip the args and check whether there's an existing test which goes from fail to pass to make sure we check for that potential unsoundness?

r=me after that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, tests/ui/nll/mir_check_cast_unsafe_fn.rs checks this, which was added 7 years ago:

#![allow(dead_code)]

fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 {
    // Here the NLL checker must relate the types in `f` to the types
    // in `g`. These are related via the `UnsafeFnPointer` cast.
    let g: unsafe fn(_) -> _ = f;
    unsafe { g(input) }
    //~^ ERROR lifetime may not live long enough
}

fn main() {}

@compiler-errors
Copy link
Member Author

@bors r=lcnr rollup

@bors
Copy link
Contributor

bors commented Aug 25, 2024

📌 Commit a97b41f has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 25, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 25, 2024
…, r=lcnr

Use subtyping for `UnsafeFnPointer` coercion, too

I overlooked this in rust-lang#129059, which changed MIR typechecking to use subtyping for other fn pointer coercions.

Fixes rust-lang#129285
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 25, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#129207 (Lint that warns when an elided lifetime ends up being a named lifetime)
 - rust-lang#129288 (Use subtyping for `UnsafeFnPointer` coercion, too)
 - rust-lang#129405 (Fixing span manipulation and indentation of the suggestion introduced by rust-lang#126187)
 - rust-lang#129518 (gitignore: ignore ICE reports regardless of directory)
 - rust-lang#129519 (Remove redundant flags from `lower_ty_common` that can be inferred from the HIR)
 - rust-lang#129544 (Removes dead code from the compiler)
 - rust-lang#129553 (add back test for stable-const-can-only-call-stable-const)
 - rust-lang#129590 (Avoid taking reference of &TyKind)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 26, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#129288 (Use subtyping for `UnsafeFnPointer` coercion, too)
 - rust-lang#129405 (Fixing span manipulation and indentation of the suggestion introduced by rust-lang#126187)
 - rust-lang#129518 (gitignore: ignore ICE reports regardless of directory)
 - rust-lang#129519 (Remove redundant flags from `lower_ty_common` that can be inferred from the HIR)
 - rust-lang#129525 (rustdoc: clean up tuple <-> primitive conversion docs)
 - rust-lang#129526 (Use `FxHasher` on new solver unconditionally)
 - rust-lang#129544 (Removes dead code from the compiler)
 - rust-lang#129553 (add back test for stable-const-can-only-call-stable-const)
 - rust-lang#129590 (Avoid taking reference of &TyKind)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 26, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#129288 (Use subtyping for `UnsafeFnPointer` coercion, too)
 - rust-lang#129405 (Fixing span manipulation and indentation of the suggestion introduced by rust-lang#126187)
 - rust-lang#129518 (gitignore: ignore ICE reports regardless of directory)
 - rust-lang#129519 (Remove redundant flags from `lower_ty_common` that can be inferred from the HIR)
 - rust-lang#129525 (rustdoc: clean up tuple <-> primitive conversion docs)
 - rust-lang#129526 (Use `FxHasher` on new solver unconditionally)
 - rust-lang#129544 (Removes dead code from the compiler)
 - rust-lang#129553 (add back test for stable-const-can-only-call-stable-const)
 - rust-lang#129590 (Avoid taking reference of &TyKind)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 621f272 into rust-lang:master Aug 26, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 26, 2024
Rollup merge of rust-lang#129288 - compiler-errors:unsafe-fn-coercion, r=lcnr

Use subtyping for `UnsafeFnPointer` coercion, too

I overlooked this in rust-lang#129059, which changed MIR typechecking to use subtyping for other fn pointer coercions.

Fixes rust-lang#129285
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't cast higher-ranked safe fn to (not higher-ranked) unsafe fn ptr
5 participants