Skip to content

Unsafe checking skips pointer dereferences in unused places #80059

Closed
@scottmcm

Description

@scottmcm

Seen in #79735

I tried this code:

fn foo(ptr: *const bool) {
    let _ = *ptr;
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=44e42a069bc7601365f5f21a102178d9

Which, oddly, happily compiled despite the syntactic pointer dereference.

Back in 1.21, however, that gave the expected error:

error[E0133]: dereference of raw pointer requires unsafe function or block
 --> <source>:2:13
  |
2 |     let _ = *ptr;
  |             ^^^^ dereference of raw pointer

error: aborting due to previous error

https://rust.godbolt.org/z/rP93nf

The conversation in the 2020-12-15 lang team meeting implied that this was an unexpected regression, so opening and nomination for further discussion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-mediumMedium priorityT-langRelevant to the language team, which will review and decide on the PR/issue.fixed-by-thir-unsafeck`-Z thir-unsafeck` handles this correctly.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions