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 Jul 13, 2024
1 parent 44fb857 commit 3090b37
Show file tree
Hide file tree
Showing 50 changed files with 29 additions and 155 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 @@ -524,7 +524,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
6 changes: 6 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ declare_features! (
// feature-group-start: accepted features
// -------------------------------------------------------------------------

// Note that the version indicates when it got *stabilized*.
// When moving an unstable feature here, set the version number to
// `CURRENT-RUSTC-VERSION` with `-` replaced by `_`.

/// Allows `#[target_feature(...)]` on aarch64 platforms
(accepted, aarch64_target_feature, "1.61.0", Some(44839)),
/// Allows using the `efiapi` ABI.
Expand Down Expand Up @@ -310,6 +314,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
4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ declare_features! (
// feature-group-start: removed features
// -------------------------------------------------------------------------

// Note that the version indicates when it got *removed*.
// When moving an unstable feature here, set the version number to
// `CURRENT-RUSTC-VERSION` with `-` replaced by `_`.

/// Allows using the `amdgpu-kernel` ABI.
(removed, abi_amdgpu_kernel, "1.77.0", Some(51575), None),
(removed, advanced_slice_patterns, "1.0.0", Some(62254),
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 @@ -571,8 +571,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 @@ -846,7 +846,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 @@ -866,13 +866,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
2 changes: 1 addition & 1 deletion src/tools/cargo
Submodule cargo updated 55 files
+1 −1 Cargo.toml
+0 −11 crates/cargo-test-support/src/compare.rs
+26 −0 src/cargo/core/compiler/build_context/mod.rs
+9 −29 src/cargo/core/compiler/build_context/target_info.rs
+1 −1 src/cargo/core/compiler/build_runner/mod.rs
+4 −1 src/cargo/core/compiler/custom_build.rs
+4 −4 src/cargo/core/compiler/fingerprint/mod.rs
+2 −2 src/cargo/core/compiler/mod.rs
+0 −3 src/cargo/core/compiler/standard_lib.rs
+0 −29 src/cargo/core/compiler/unit.rs
+0 −2 src/cargo/core/compiler/unit_dependencies.rs
+1 −35 src/cargo/core/summary.rs
+0 −8 src/cargo/ops/cargo_compile/mod.rs
+2 −6 src/cargo/ops/cargo_compile/unit_generator.rs
+7 −10 src/cargo/util/context/mod.rs
+2 −6 src/cargo/util/lints.rs
+18 −118 src/cargo/util/toml/mod.rs
+3 −3 src/cargo/version.rs
+1 −1 src/doc/contrib/src/process/unstable.md
+1 −1 src/doc/src/reference/build-scripts.md
+1 −1 src/doc/src/reference/registry-index.md
+1 −1 src/doc/src/reference/resolver.md
+2 −2 src/doc/src/reference/semver.md
+2 −2 src/doc/src/reference/unstable.md
+124 −144 tests/testsuite/build_plan.rs
+732 −845 tests/testsuite/build_script.rs
+101 −139 tests/testsuite/cargo_command.rs
+16 −47 tests/testsuite/cargo_env_config.rs
+204 −172 tests/testsuite/cargo_features.rs
+18 −17 tests/testsuite/cargo_targets.rs
+82 −73 tests/testsuite/cfg.rs
+160 −249 tests/testsuite/check.rs
+0 −165 tests/testsuite/config_include.rs
+93 −75 tests/testsuite/directory.rs
+354 −464 tests/testsuite/doc.rs
+102 −113 tests/testsuite/docscrape.rs
+6 −12 tests/testsuite/features.rs
+496 −700 tests/testsuite/freshness.rs
+46 −92 tests/testsuite/git_auth.rs
+13 −10 tests/testsuite/https.rs
+274 −243 tests/testsuite/inheritable_workspace_fields.rs
+525 −628 tests/testsuite/install.rs
+225 −344 tests/testsuite/install_upgrade.rs
+20 −92 tests/testsuite/jobserver.rs
+50 −195 tests/testsuite/lints/unused_optional_dependencies.rs
+518 −541 tests/testsuite/patch.rs
+76 −75 tests/testsuite/pkgid.rs
+26 −71 tests/testsuite/proc_macro.rs
+21 −28 tests/testsuite/progress.rs
+72 −100 tests/testsuite/read_manifest.rs
+28 −60 tests/testsuite/rustdoc_extern_html.rs
+0 −53 tests/testsuite/rustflags.rs
+90 −103 tests/testsuite/ssh.rs
+109 −105 tests/testsuite/tool_paths.rs
+11 −10 tests/testsuite/warn_on_failure.rs
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.
//@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,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
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
#![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
2 changes: 0 additions & 2 deletions tests/ui/consts/const-address-of-interior-mut.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(raw_ref_op)]

use std::cell::Cell;

const A: () = { let x = Cell::new(2); &raw const x; }; //~ ERROR interior mutability
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/consts/const-address-of-mut.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(raw_ref_op)]

const A: () = { let mut x = 2; &raw mut x; }; //~ mutable pointer

static B: () = { let mut x = 2; &raw mut x; }; //~ mutable pointer
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/consts/const-address-of.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(raw_ref_op)]

const A: *const i32 = &raw const *&2;
static B: () = { &raw const *&2; };
static mut C: *const i32 = &raw const *&2;
Expand Down
1 change: 0 additions & 1 deletion tests/ui/consts/const-mut-refs/const_mut_address_of.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ check-pass
#![feature(const_mut_refs)]
#![feature(raw_ref_op)]

struct Foo {
x: usize
Expand Down
1 change: 0 additions & 1 deletion tests/ui/consts/const-mut-refs/mut_ref_in_final.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(const_mut_refs)]
#![feature(raw_ref_op)]

const NULL: *mut i32 = std::ptr::null_mut();
const A: *const i32 = &4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//@ normalize-stderr-test: "( 0x[0-9a-f][0-9a-f] │)? ([0-9a-f][0-9a-f] |__ |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> " HEX_DUMP"
//@ normalize-stderr-test: "HEX_DUMP\s*\n\s*HEX_DUMP" -> "HEX_DUMP"
#![feature(const_mut_refs, const_refs_to_static)]
#![feature(raw_ref_op)]

use std::sync::Mutex;

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/consts/min_const_fn/address_of.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(raw_ref_op)]

const fn mutable_address_of_in_const() {
let mut a = 0;
let b = &raw mut a; //~ ERROR mutable pointer
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/consts/min_const_fn/address_of_const.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(raw_ref_op)]

const fn const_address_of_in_const() {
let mut a = 0;
let b = &raw const a;
Expand Down
1 change: 0 additions & 1 deletion tests/ui/consts/qualif-indirect-mutation-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![feature(const_mut_refs)]
#![feature(const_precise_live_drops)]
#![feature(const_swap)]
#![feature(raw_ref_op)]

// Mutable borrow of a field with drop impl.
pub const fn f() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lint/unused/lint-unused-mut-variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Exercise the unused_mut attribute in some positive and negative cases

#![warn(unused_mut)]
#![feature(async_closure, raw_ref_op)]
#![feature(async_closure)]

async fn baz_async(
mut a: i32,
Expand Down
1 change: 0 additions & 1 deletion tests/ui/macros/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#![feature(let_chains)]
#![feature(more_qualified_paths)]
#![feature(never_patterns)]
#![feature(raw_ref_op)]
#![feature(trait_alias)]
#![feature(try_blocks)]
#![feature(type_ascription)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/mir/mir_raw_fat_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// check raw fat pointer ops in mir
// FIXME: please improve this when we get monomorphization support

#![feature(raw_ref_op)]
#![allow(ambiguous_wide_pointer_comparisons)]

use std::mem;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/mir/mir_raw_fat_ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: method `foo` is never used
--> $DIR/mir_raw_fat_ptr.rs:101:16
--> $DIR/mir_raw_fat_ptr.rs:100:16
|
LL | trait Foo { fn foo(&self) -> usize; }
| --- ^^^
Expand Down
Loading

0 comments on commit 3090b37

Please sign in to comment.