Skip to content

Commit d5af360

Browse files
committed
add WRAPPED_SELF: Option<Self> in the test
1 parent 2fc9064 commit d5af360

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

tests/ui/declare_interior_mutable_const.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,24 @@ where
121121
const BOUNDED: T::ToBeBounded = AtomicUsize::new(15);
122122
}
123123

124-
trait SelfType {
124+
// a constant whose type is `Self` should be linted at the implementation site as well.
125+
// (`Option` requires `Sized` bound.)
126+
trait SelfType: Sized {
125127
const SELF: Self;
128+
// this was the one in the original issue (#5050).
129+
const WRAPPED_SELF: Option<Self>;
126130
}
127131

128132
impl SelfType for u64 {
129133
const SELF: Self = 16;
134+
const WRAPPED_SELF: Option<Self> = Some(20);
130135
}
131136

132137
impl SelfType for AtomicUsize {
133138
// this (interior mutable `Self` const) exists in `parking_lot`.
134139
// `const_trait_impl` will replace it in the future, hopefully.
135140
const SELF: Self = AtomicUsize::new(17); //~ ERROR interior mutable
141+
const WRAPPED_SELF: Option<Self> = Some(AtomicUsize::new(21)); //~ ERROR interior mutable
136142
}
137143

138144
// Even though a constant contains a generic type, if it also have a interior mutable type,

tests/ui/declare_interior_mutable_const.stderr

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,34 @@ LL | const BOUNDED: T::ToBeBounded; //~ ERROR interior mutable
7777
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7878

7979
error: a `const` item should never be interior mutable
80-
--> $DIR/declare_interior_mutable_const.rs:135:5
80+
--> $DIR/declare_interior_mutable_const.rs:140:5
8181
|
8282
LL | const SELF: Self = AtomicUsize::new(17); //~ ERROR interior mutable
8383
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8484

8585
error: a `const` item should never be interior mutable
86-
--> $DIR/declare_interior_mutable_const.rs:143:5
86+
--> $DIR/declare_interior_mutable_const.rs:141:5
87+
|
88+
LL | const WRAPPED_SELF: Option<Self> = Some(AtomicUsize::new(21)); //~ ERROR interior mutable
89+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
90+
91+
error: a `const` item should never be interior mutable
92+
--> $DIR/declare_interior_mutable_const.rs:149:5
8793
|
8894
LL | const INDIRECT: Cell<*const T>; //~ ERROR interior mutable
8995
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9096

9197
error: a `const` item should never be interior mutable
92-
--> $DIR/declare_interior_mutable_const.rs:159:5
98+
--> $DIR/declare_interior_mutable_const.rs:165:5
9399
|
94100
LL | const ATOMIC: AtomicUsize = AtomicUsize::new(18); //~ ERROR interior mutable
95101
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
96102

97103
error: a `const` item should never be interior mutable
98-
--> $DIR/declare_interior_mutable_const.rs:165:5
104+
--> $DIR/declare_interior_mutable_const.rs:171:5
99105
|
100106
LL | const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); //~ ERROR interior mutable
101107
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102108

103-
error: aborting due to 14 previous errors
109+
error: aborting due to 15 previous errors
104110

0 commit comments

Comments
 (0)