Skip to content

Commit

Permalink
stabilize raw_ref_op
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 18, 2024
1 parent f04f6ca commit 79503dd
Show file tree
Hide file tree
Showing 63 changed files with 106 additions and 246 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
}
}
gate_all!(gen_blocks, "gen blocks are experimental");
gate_all!(raw_ref_op, "raw address of syntax is experimental");
gate_all!(const_trait_impl, "const trait impls are experimental");
gate_all!(
half_open_range_patterns_in_slices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
extern_types,
naked_functions,
thread_local,
repr_simd,
raw_ref_op
repr_simd
)]
#![no_core]
#![allow(dead_code, non_camel_case_types, internal_features)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![feature(
no_core, unboxed_closures, start, lang_items, never_type, linkage,
extern_types, thread_local, raw_ref_op
extern_types, thread_local
)]
#![no_core]
#![allow(dead_code, internal_features, non_camel_case_types)]
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0745.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ The address of temporary value was taken.
Erroneous code example:

```compile_fail,E0745
# #![feature(raw_ref_op)]
fn temp_address() {
let ptr = &raw const 2; // error!
}
Expand All @@ -15,7 +14,6 @@ In this example, `2` is destroyed right after the assignment, which means that
To avoid this error, first bind the temporary to a named local variable:

```
# #![feature(raw_ref_op)]
fn temp_address() {
let val = 2;
let ptr = &raw const val; // ok!
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ declare_features! (
(accepted, raw_dylib, "1.71.0", Some(58713)),
/// Allows keywords to be escaped for use as identifiers.
(accepted, raw_identifiers, "1.30.0", Some(48589)),
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
(accepted, raw_ref_op, "CURRENT_RUSTC_VERSION", Some(64490)),
/// Allows relaxing the coherence rules such that
/// `impl<T> ForeignTrait<LocalType> for ForeignType<T>` is permitted.
(accepted, re_rebalance_coherence, "1.41.0", Some(55437)),
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,6 @@ declare_features! (
(unstable, precise_capturing, "1.79.0", Some(123432)),
/// Allows macro attributes on expressions, statements and non-inline modules.
(unstable, proc_macro_hygiene, "1.30.0", Some(54727)),
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
(unstable, raw_ref_op, "1.41.0", Some(64490)),
/// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024.
(incomplete, ref_pat_eat_one_layer_2024, "1.79.0", Some(123076)),
/// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024—structural variant
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ impl<'a> Parser<'a> {
self.expect_and()?;
let has_lifetime = self.token.is_lifetime() && self.look_ahead(1, |t| t != &token::Colon);
let lifetime = has_lifetime.then(|| self.expect_lifetime()); // For recovery, see below.
let (borrow_kind, mutbl) = self.parse_borrow_modifiers(lo);
let (borrow_kind, mutbl) = self.parse_borrow_modifiers();
let attrs = self.parse_outer_attributes()?;
let expr = if self.token.is_range_separator() {
self.parse_expr_prefix_range(attrs)
Expand All @@ -871,13 +871,12 @@ impl<'a> Parser<'a> {
}

/// Parse `mut?` or `raw [ const | mut ]`.
fn parse_borrow_modifiers(&mut self, lo: Span) -> (ast::BorrowKind, ast::Mutability) {
fn parse_borrow_modifiers(&mut self) -> (ast::BorrowKind, ast::Mutability) {
if self.check_keyword(kw::Raw) && self.look_ahead(1, Token::is_mutability) {
// `raw [ const | mut ]`.
let found_raw = self.eat_keyword(kw::Raw);
assert!(found_raw);
let mutability = self.parse_const_or_mut().unwrap();
self.psess.gated_spans.gate(sym::raw_ref_op, lo.to(self.prev_token.span));
(ast::BorrowKind::Raw, mutability)
} else {
// `mut?`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(raw_ref_op)]
#![feature(strict_provenance)]
use std::ptr;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@revisions: stack tree none
//@[tree]compile-flags: -Zmiri-tree-borrows
//@[none]compile-flags: -Zmiri-disable-stacked-borrows
#![feature(raw_ref_op)]
#![feature(core_intrinsics)]
#![feature(custom_mir)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// This does need an aliasing model and protectors.
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows
#![feature(raw_ref_op)]
#![feature(core_intrinsics)]
#![feature(custom_mir)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// This does need an aliasing model and protectors.
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows
#![feature(raw_ref_op)]
#![feature(core_intrinsics)]
#![feature(custom_mir)]
#![feature(explicit_tail_calls)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Doesn't need an aliasing model.
//@compile-flags: -Zmiri-disable-stacked-borrows
#![feature(raw_ref_op)]
#![feature(core_intrinsics)]
#![feature(custom_mir)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(raw_ref_op)]
#![feature(core_intrinsics)]
#![feature(custom_mir)]

Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/const_prop/indirect_mutation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ test-mir-pass: GVN
// Check that we do not propagate past an indirect mutation.
#![feature(raw_ref_op)]

// EMIT_MIR indirect_mutation.foo.GVN.diff
fn foo() {
Expand Down
2 changes: 0 additions & 2 deletions tests/mir-opt/copy-prop/reborrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Check that CopyProp considers reborrows as not mutating the pointer.
//@ test-mir-pass: CopyProp

#![feature(raw_ref_op)]

#[inline(never)]
fn opaque(_: impl Sized) {}

Expand Down
18 changes: 9 additions & 9 deletions tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
let mut _3: fn(u8) -> u8;
let _5: ();
let mut _6: fn(u8) -> u8;
let mut _9: {closure@$DIR/gvn.rs:615:19: 615:21};
let mut _9: {closure@$DIR/gvn.rs:614:19: 614:21};
let _10: ();
let mut _11: fn();
let mut _13: {closure@$DIR/gvn.rs:615:19: 615:21};
let mut _13: {closure@$DIR/gvn.rs:614:19: 614:21};
let _14: ();
let mut _15: fn();
scope 1 {
debug f => _1;
let _4: fn(u8) -> u8;
scope 2 {
debug g => _4;
let _7: {closure@$DIR/gvn.rs:615:19: 615:21};
let _7: {closure@$DIR/gvn.rs:614:19: 614:21};
scope 3 {
debug closure => _7;
let _8: fn();
Expand Down Expand Up @@ -62,16 +62,16 @@
StorageDead(_6);
StorageDead(_5);
- StorageLive(_7);
- _7 = {closure@$DIR/gvn.rs:615:19: 615:21};
- _7 = {closure@$DIR/gvn.rs:614:19: 614:21};
- StorageLive(_8);
+ nop;
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
+ nop;
StorageLive(_9);
- _9 = _7;
- _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Safe)));
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe)));
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} as fn() (PointerCoercion(ClosureFnPointer(Safe)));
StorageDead(_9);
StorageLive(_10);
StorageLive(_11);
Expand All @@ -88,8 +88,8 @@
StorageLive(_13);
- _13 = _7;
- _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Safe)));
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe)));
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} as fn() (PointerCoercion(ClosureFnPointer(Safe)));
StorageDead(_13);
StorageLive(_14);
StorageLive(_15);
Expand Down
18 changes: 9 additions & 9 deletions tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
let mut _3: fn(u8) -> u8;
let _5: ();
let mut _6: fn(u8) -> u8;
let mut _9: {closure@$DIR/gvn.rs:615:19: 615:21};
let mut _9: {closure@$DIR/gvn.rs:614:19: 614:21};
let _10: ();
let mut _11: fn();
let mut _13: {closure@$DIR/gvn.rs:615:19: 615:21};
let mut _13: {closure@$DIR/gvn.rs:614:19: 614:21};
let _14: ();
let mut _15: fn();
scope 1 {
debug f => _1;
let _4: fn(u8) -> u8;
scope 2 {
debug g => _4;
let _7: {closure@$DIR/gvn.rs:615:19: 615:21};
let _7: {closure@$DIR/gvn.rs:614:19: 614:21};
scope 3 {
debug closure => _7;
let _8: fn();
Expand Down Expand Up @@ -62,16 +62,16 @@
StorageDead(_6);
StorageDead(_5);
- StorageLive(_7);
- _7 = {closure@$DIR/gvn.rs:615:19: 615:21};
- _7 = {closure@$DIR/gvn.rs:614:19: 614:21};
- StorageLive(_8);
+ nop;
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
+ nop;
StorageLive(_9);
- _9 = _7;
- _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Safe)));
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe)));
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} as fn() (PointerCoercion(ClosureFnPointer(Safe)));
StorageDead(_9);
StorageLive(_10);
StorageLive(_11);
Expand All @@ -88,8 +88,8 @@
StorageLive(_13);
- _13 = _7;
- _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Safe)));
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe)));
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} as fn() (PointerCoercion(ClosureFnPointer(Safe)));
StorageDead(_13);
StorageLive(_14);
StorageLive(_15);
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/gvn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ only-64bit

#![feature(raw_ref_op)]
#![feature(rustc_attrs)]
#![feature(custom_mir)]
#![feature(core_intrinsics)]
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/instsimplify/ref_of_deref.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ test-mir-pass: InstSimplify-after-simplifycfg
#![crate_type = "lib"]
#![feature(raw_ref_op)]

// For each of these, only 2 of the 6 should simplify,
// as the others have the wrong types.
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/reference_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//@ test-mir-pass: ReferencePropagation
//@ needs-unwind

#![feature(raw_ref_op)]
#![feature(core_intrinsics, custom_mir)]

#[inline(never)]
Expand Down
1 change: 0 additions & 1 deletion tests/pretty/raw-address-of.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ pp-exact
#![feature(raw_ref_op)]

const C_PTR: () = { let a = 1; &raw const a; };
static S_PTR: () = { let b = false; &raw const b; };
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/borrowck/borrow-raw-address-of-borrowed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(raw_ref_op)]

fn address_of_shared() {
let mut x = 0;
let y = &x;
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/borrowck/borrow-raw-address-of-borrowed.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
--> $DIR/borrow-raw-address-of-borrowed.rs:7:13
--> $DIR/borrow-raw-address-of-borrowed.rs:5:13
|
LL | let y = &x;
| -- immutable borrow occurs here
Expand All @@ -11,7 +11,7 @@ LL | drop(y);
| - immutable borrow later used here

error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
--> $DIR/borrow-raw-address-of-borrowed.rs:16:13
--> $DIR/borrow-raw-address-of-borrowed.rs:14:13
|
LL | let y = &mut x;
| ------ mutable borrow occurs here
Expand All @@ -23,7 +23,7 @@ LL | drop(y);
| - mutable borrow later used here

error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrow-raw-address-of-borrowed.rs:17:13
--> $DIR/borrow-raw-address-of-borrowed.rs:15:13
|
LL | let y = &mut x;
| ------ first mutable borrow occurs here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(raw_ref_op)]

fn raw_reborrow() {
let x = &0;
let y = &mut 0;
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/borrowck/borrow-raw-address-of-deref-mutability.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Check that `&raw mut` cannot be used to turn a `&T` into a `*mut T`.

#![feature(raw_ref_op)]

fn raw_reborrow() {
let x = &0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
--> $DIR/borrow-raw-address-of-deref-mutability.rs:8:13
--> $DIR/borrow-raw-address-of-deref-mutability.rs:6:13
|
LL | let q = &raw mut *x;
| ^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
Expand All @@ -10,7 +10,7 @@ LL | let x = &mut 0;
| +++

error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer
--> $DIR/borrow-raw-address-of-deref-mutability.rs:14:13
--> $DIR/borrow-raw-address-of-deref-mutability.rs:12:13
|
LL | let q = &raw mut *x;
| ^^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/borrowck/borrow-raw-address-of-mutability-ok.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(raw_ref_op)]

fn mutable_address_of() {
let mut x = 0;
let y = &raw mut x;
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/borrowck/borrow-raw-address-of-mutability.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(raw_ref_op)]

fn mutable_address_of() {
let x = 0;
let y = &raw mut x; //~ ERROR cannot borrow
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/borrowck/borrow-raw-address-of-mutability.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/borrow-raw-address-of-mutability.rs:5:13
--> $DIR/borrow-raw-address-of-mutability.rs:3:13
|
LL | let y = &raw mut x;
| ^^^^^^^^^^ cannot borrow as mutable
Expand All @@ -10,7 +10,7 @@ LL | let mut x = 0;
| +++

error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/borrow-raw-address-of-mutability.rs:11:17
--> $DIR/borrow-raw-address-of-mutability.rs:9:17
|
LL | let y = &raw mut x;
| ^^^^^^^^^^ cannot borrow as mutable
Expand All @@ -21,7 +21,7 @@ LL | let mut x = 0;
| +++

error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
--> $DIR/borrow-raw-address-of-mutability.rs:21:5
--> $DIR/borrow-raw-address-of-mutability.rs:19:5
|
LL | let y = &raw mut x;
| - calling `f` requires mutable binding due to mutable borrow of `x`
Expand All @@ -35,7 +35,7 @@ LL | let mut f = || {
| +++

error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-raw-address-of-mutability.rs:29:17
--> $DIR/borrow-raw-address-of-mutability.rs:27:17
|
LL | fn make_fn<F: Fn()>(f: F) -> F { f }
| - change this to accept `FnMut` instead of `Fn`
Expand All @@ -48,7 +48,7 @@ LL | let y = &raw mut x;
| ^^^^^^^^^^ cannot borrow as mutable

error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-raw-address-of-mutability.rs:37:17
--> $DIR/borrow-raw-address-of-mutability.rs:35:17
|
LL | fn make_fn<F: Fn()>(f: F) -> F { f }
| - change this to accept `FnMut` instead of `Fn`
Expand Down
Loading

0 comments on commit 79503dd

Please sign in to comment.