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

Rustc beta/nightly appears to ignore unsafe blocks inside closure in some cases #85435

Closed
inrustwetrust opened this issue May 18, 2021 · 5 comments
Assignees
Labels
C-bug Category: This is a bug. P-critical Critical priority regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Milestone

Comments

@inrustwetrust
Copy link
Contributor

The code below compiles with stable rustc (1.52.1), but fails to compile on beta (1.53) and nightly (1.54):

fn main() {
    let val: u8 = 5;
    let u8_ptr: *const u8 = &val;
    let _closure = || {
        unsafe {
            // Fails compilation with:
            // error[E0133]: dereference of raw pointer is unsafe and
            //               requires unsafe function or block
            let tmp = *u8_ptr;
            tmp

            // Just dereferencing and returning directly compiles fine:
            // *u8_ptr
        }
    };
}

On beta and nightly, there is a compilation error due to a missing unsafe block, even though there clearly is one in the code:

error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
 --> unsafe_deref_test.rs:9:23
  |
9 |             let tmp = *u8_ptr;
  |                       ^^^^^^^ dereference of raw pointer
  |
  = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior

error: aborting due to previous error

For more information about this error, try `rustc --explain E0133`.

Meta

Compilation error:
rustup run beta rustc --version --verbose:

rustc 1.53.0-beta.2 (4bac69dd2 2021-05-07)
binary: rustc
commit-hash: 4bac69dd25089dd2f803f24de2225d84449b6220
commit-date: 2021-05-07
host: x86_64-apple-darwin
release: 1.53.0-beta.2
LLVM version: 12.0.0

Compilation error:
rustup run nightly rustc --version --verbose:

rustc 1.54.0-nightly (fe72845f7 2021-05-16)
binary: rustc
commit-hash: fe72845f7bb6a77b9e671e6a4f32fe714962cec4
commit-date: 2021-05-16
host: x86_64-apple-darwin
release: 1.54.0-nightly
LLVM version: 12.0.1

Successful compilation:
rustup run stable rustc --version --verbose:

rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-apple-darwin
release: 1.52.1
LLVM version: 12.0.0

@inrustwetrust inrustwetrust added the C-bug Category: This is a bug. label May 18, 2021
@jonas-schievink jonas-schievink added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label May 18, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 18, 2021
@hameerabbasi
Copy link
Contributor

hameerabbasi commented May 18, 2021

Assigning a priority as discussed in WG-prioritization discussion on Zulip and removing I-prioritize.

@rustbot modify labels -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 18, 2021
@LeSeulArtichaut LeSeulArtichaut added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label May 18, 2021
@Mark-Simulacrum Mark-Simulacrum added this to the 1.53.0 milestone May 18, 2021
@ehuss
Copy link
Contributor

ehuss commented May 18, 2021

Bisected to #83855, I strongly suspect it is #83521. cc @roxelo

@pnkfelix pnkfelix added the P-critical Critical priority label May 20, 2021
@pnkfelix pnkfelix self-assigned this May 20, 2021
@pnkfelix pnkfelix removed the P-high High priority label May 20, 2021
@pnkfelix
Copy link
Member

discussed in compiler triage. Heightening priority and self-assigning.

pnkfelix added a commit to pnkfelix/rust that referenced this issue May 21, 2021
@pnkfelix pnkfelix removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label May 21, 2021
@pnkfelix
Copy link
Member

some discussion in zulip.

I have confirmed this was injected by PR #83521. I have filed issue #85561 for the root cause, and put up PR #85564 as a targeted fix suitable for a beta-backport.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 26, 2021
…disjoint-fields-gate, r=nikomatsakis

 readd capture disjoint fields gate

This readds a feature gate guard that was added in PR rust-lang#83521. (Basically, there were unintended consequences to the code exposed by removing the feature gate guard.)

The root bug still remains to be resolved, as discussed in issue rust-lang#85561. This is just a band-aid suitable for a beta backport.

Cc issue rust-lang#85435

Note that the latter issue is unfixed until we backport this (or another fix) to 1.53 beta
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 27, 2021
…disjoint-fields-gate, r=nikomatsakis

 readd capture disjoint fields gate

This readds a feature gate guard that was added in PR rust-lang#83521. (Basically, there were unintended consequences to the code exposed by removing the feature gate guard.)

The root bug still remains to be resolved, as discussed in issue rust-lang#85561. This is just a band-aid suitable for a beta backport.

Cc issue rust-lang#85435

Note that the latter issue is unfixed until we backport this (or another fix) to 1.53 beta
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 27, 2021
…disjoint-fields-gate, r=nikomatsakis

 readd capture disjoint fields gate

This readds a feature gate guard that was added in PR rust-lang#83521. (Basically, there were unintended consequences to the code exposed by removing the feature gate guard.)

The root bug still remains to be resolved, as discussed in issue rust-lang#85561. This is just a band-aid suitable for a beta backport.

Cc issue rust-lang#85435

Note that the latter issue is unfixed until we backport this (or another fix) to 1.53 beta
pnkfelix added a commit to pnkfelix/rust that referenced this issue Jun 1, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jun 3, 2021
…nikomatsakis

Fix issue 85435 by restricting Fake Read precision

This PR fixes the root bug of issue rust-lang#85435 by restricting Fake Read precision in closures and removing the feature gate introduced in PR rust-lang#85564. More info [here](rust-lang#85561 (comment)) and [here](rust-lang#85561 (comment)).

Closes rust-lang#85561

r? `@nikomatsakis`
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jun 3, 2021
…nikomatsakis

Fix issue 85435 by restricting Fake Read precision

This PR fixes the root bug of issue rust-lang#85435 by restricting Fake Read precision in closures and removing the feature gate introduced in PR rust-lang#85564. More info [here](rust-lang#85561 (comment)) and [here](rust-lang#85561 (comment)).

Closes rust-lang#85561

r? ``@nikomatsakis``
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 8, 2021
…acrum

[beta] backport of readd capture disjoint fields gate

Beta backport of "readd capture disjoint fields gate", PR rust-lang#85564

Fix issue rust-lang#85435
@pietroalbini
Copy link
Member

Fixed in 1.54 by #85564 and fixed in 1.53 by #85893. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. P-critical Critical priority regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Projects
None yet
Development

No branches or pull requests

9 participants