Skip to content

Commit a23297f

Browse files
Bless mut tests
1 parent b518ccb commit a23297f

16 files changed

+173
-107
lines changed

compiler/rustc_mir/src/transform/check_consts/ops.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,6 @@ pub mod ty {
515515
#[derive(Debug)]
516516
pub struct MutRef;
517517
impl NonConstOp for MutRef {
518-
const STOPS_CONST_CHECKING: bool = true;
519-
520518
fn status_in_item(&self, _ccx: &ConstCx<'_, '_>) -> Status {
521519
Status::Unstable(sym::const_mut_refs)
522520
}

src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// New test for #53818: modifying static memory at compile-time is not allowed.
22
// The test should never compile successfully
33

4-
#![feature(const_raw_ptr_deref)]
4+
#![feature(const_raw_ptr_deref, const_mut_refs)]
55

66
use std::cell::UnsafeCell;
77

@@ -13,7 +13,7 @@ unsafe impl Sync for Foo {}
1313
static FOO: Foo = Foo(UnsafeCell::new(42));
1414

1515
static BAR: () = unsafe {
16-
*FOO.0.get() = 5; //~ ERROR contains unimplemented expression type
16+
*FOO.0.get() = 5; //~ ERROR
1717
};
1818

1919
fn main() {}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
error[E0019]: static contains unimplemented expression type
1+
error[E0080]: could not evaluate static initializer
22
--> $DIR/assign-to-static-within-other-static-2.rs:16:5
33
|
44
LL | *FOO.0.get() = 5;
5-
| ^^^^^^^^^^^^^^^^
6-
|
7-
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
5+
| ^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
86

97
error: aborting due to previous error
108

11-
For more information about this error, try `rustc --explain E0019`.
9+
For more information about this error, try `rustc --explain E0080`.

src/test/ui/consts/const-eval/mod-static-with-const-fn.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ unsafe impl Sync for Foo {}
1212

1313
static FOO: Foo = Foo(UnsafeCell::new(42));
1414

15-
fn foo() {}
16-
1715
static BAR: () = unsafe {
1816
*FOO.0.get() = 5;
19-
//~^ contains unimplemented expression
20-
21-
foo();
22-
//~^ ERROR calls in statics are limited to constant functions, tuple structs and tuple variants
17+
//~^ mutation through a reference
2318
};
2419

2520
fn main() {
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
error[E0019]: static contains unimplemented expression type
2-
--> $DIR/mod-static-with-const-fn.rs:18:5
1+
error[E0658]: mutation through a reference is not allowed in statics
2+
--> $DIR/mod-static-with-const-fn.rs:15:5
33
|
44
LL | *FOO.0.get() = 5;
55
| ^^^^^^^^^^^^^^^^
66
|
7+
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
78
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
89

9-
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
10-
--> $DIR/mod-static-with-const-fn.rs:21:5
11-
|
12-
LL | foo();
13-
| ^^^^^
14-
15-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
1611

17-
Some errors have detailed explanations: E0015, E0019.
18-
For more information about an error, try `rustc --explain E0015`.
12+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/consts/const_let_assign3.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ struct S {
66

77
impl S {
88
const fn foo(&mut self, x: u32) {
9-
//~^ ERROR mutable references
9+
//~^ ERROR mutable reference
1010
self.state = x;
1111
}
1212
}
1313

1414
const FOO: S = {
1515
let mut s = S { state: 42 };
16-
s.foo(3); //~ ERROR mutable references are not allowed in constants
16+
s.foo(3); //~ ERROR mutable reference
1717
s
1818
};
1919

2020
type Array = [u32; {
2121
let mut x = 2;
22-
let y = &mut x;
23-
//~^ ERROR mutable references are not allowed in constants
22+
let y = &mut x; //~ ERROR mutable reference
2423
*y = 42;
25-
//~^ ERROR constant contains unimplemented expression type
2624
*y
2725
}];
2826

src/test/ui/consts/const_let_assign3.stderr

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,7 @@ error[E0764]: mutable references are not allowed in constants
1919
LL | let y = &mut x;
2020
| ^^^^^^ `&mut` is only allowed in `const fn`
2121

22-
error[E0019]: constant contains unimplemented expression type
23-
--> $DIR/const_let_assign3.rs:24:5
24-
|
25-
LL | *y = 42;
26-
| ^^^^^^^
27-
|
28-
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
29-
30-
error: aborting due to 4 previous errors
22+
error: aborting due to 3 previous errors
3123

32-
Some errors have detailed explanations: E0019, E0658, E0764.
33-
For more information about an error, try `rustc --explain E0019`.
24+
Some errors have detailed explanations: E0658, E0764.
25+
For more information about an error, try `rustc --explain E0658`.

src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fn foo(a: i32) -> Vec<i32> {
22
vec![1, 2, 3]
33
//~^ ERROR allocations are not allowed
4-
//~| ERROR unimplemented expression type
54
//~| ERROR calls in constant functions
65
}
76

src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ LL | vec![1, 2, 3]
66
|
77
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
88

9-
error[E0019]: constant function contains unimplemented expression type
10-
--> $DIR/bad_const_fn_body_ice.rs:2:5
11-
|
12-
LL | vec![1, 2, 3]
13-
| ^^^^^^^^^^^^^
14-
|
15-
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
16-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
17-
189
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1910
--> $DIR/bad_const_fn_body_ice.rs:2:5
2011
|
@@ -23,7 +14,7 @@ LL | vec![1, 2, 3]
2314
|
2415
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2516

26-
error: aborting due to 3 previous errors
17+
error: aborting due to 2 previous errors
2718

28-
Some errors have detailed explanations: E0010, E0015, E0019.
19+
Some errors have detailed explanations: E0010, E0015.
2920
For more information about an error, try `rustc --explain E0010`.

src/test/ui/consts/min_const_fn/min_const_fn.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,37 @@ impl<T> Foo<T> {
3838
const fn get(&self) -> &T { &self.0 }
3939
const fn get_mut(&mut self) -> &mut T { &mut self.0 }
4040
//~^ mutable references
41+
//~| mutable references
42+
//~| mutable references
43+
//~| mutable references
4144
}
4245
impl<'a, T> Foo<T> {
4346
const fn new_lt(t: T) -> Self { Foo(t) }
4447
const fn into_inner_lt(self) -> T { self.0 } //~ destructors cannot be evaluated
4548
const fn get_lt(&'a self) -> &T { &self.0 }
4649
const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
4750
//~^ mutable references
51+
//~| mutable references
52+
//~| mutable references
53+
//~| mutable references
4854
}
4955
impl<T: Sized> Foo<T> {
5056
const fn new_s(t: T) -> Self { Foo(t) }
5157
const fn into_inner_s(self) -> T { self.0 } //~ ERROR destructors
5258
const fn get_s(&self) -> &T { &self.0 }
5359
const fn get_mut_s(&mut self) -> &mut T { &mut self.0 }
5460
//~^ mutable references
61+
//~| mutable references
62+
//~| mutable references
63+
//~| mutable references
5564
}
5665
impl<T: ?Sized> Foo<T> {
5766
const fn get_sq(&self) -> &T { &self.0 }
5867
const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 }
5968
//~^ mutable references
69+
//~| mutable references
70+
//~| mutable references
71+
//~| mutable references
6072
}
6173

6274

0 commit comments

Comments
 (0)