133
133
#[ doc( alias = "&*" ) ]
134
134
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
135
135
#[ rustc_diagnostic_item = "Deref" ]
136
+ #[ cfg_attr( not( bootstrap) , const_trait) ]
136
137
pub trait Deref {
137
138
/// The resulting type after dereferencing.
138
139
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -147,6 +148,7 @@ pub trait Deref {
147
148
fn deref ( & self ) -> & Self :: Target ;
148
149
}
149
150
151
+ #[ cfg( bootstrap) ]
150
152
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
151
153
impl < T : ?Sized > Deref for & T {
152
154
type Target = T ;
@@ -157,9 +159,21 @@ impl<T: ?Sized> Deref for &T {
157
159
}
158
160
}
159
161
162
+ #[ cfg( not( bootstrap) ) ]
163
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
164
+ impl < T : ?Sized > const Deref for & T {
165
+ type Target = T ;
166
+
167
+ #[ rustc_diagnostic_item = "noop_method_deref" ]
168
+ fn deref ( & self ) -> & T {
169
+ * self
170
+ }
171
+ }
172
+
160
173
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
161
174
impl < T : ?Sized > !DerefMut for & T { }
162
175
176
+ #[ cfg( bootstrap) ]
163
177
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
164
178
impl < T : ?Sized > Deref for & mut T {
165
179
type Target = T ;
@@ -169,6 +183,16 @@ impl<T: ?Sized> Deref for &mut T {
169
183
}
170
184
}
171
185
186
+ #[ cfg( not( bootstrap) ) ]
187
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
188
+ impl < T : ?Sized > const Deref for & mut T {
189
+ type Target = T ;
190
+
191
+ fn deref ( & self ) -> & T {
192
+ * self
193
+ }
194
+ }
195
+
172
196
/// Used for mutable dereferencing operations, like in `*v = 1;`.
173
197
///
174
198
/// In addition to being used for explicit dereferencing operations with the
@@ -258,23 +282,46 @@ impl<T: ?Sized> Deref for &mut T {
258
282
/// *x = 'b';
259
283
/// assert_eq!('b', x.value);
260
284
/// ```
285
+ #[ cfg( not( bootstrap) ) ]
286
+ #[ lang = "deref_mut" ]
287
+ #[ doc( alias = "*" ) ]
288
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
289
+ #[ const_trait]
290
+ pub trait DerefMut : ~const Deref {
291
+ /// Mutably dereferences the value.
292
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
293
+ #[ rustc_diagnostic_item = "deref_mut_method" ]
294
+ fn deref_mut ( & mut self ) -> & mut Self :: Target ;
295
+ }
296
+
297
+ /// Bootstrap
261
298
#[ lang = "deref_mut" ]
262
299
#[ doc( alias = "*" ) ]
263
300
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
301
+ #[ cfg( bootstrap) ]
264
302
pub trait DerefMut : Deref {
265
303
/// Mutably dereferences the value.
266
304
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
267
305
#[ rustc_diagnostic_item = "deref_mut_method" ]
268
306
fn deref_mut ( & mut self ) -> & mut Self :: Target ;
269
307
}
270
308
309
+ #[ cfg( bootstrap) ]
271
310
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
272
311
impl < T : ?Sized > DerefMut for & mut T {
273
312
fn deref_mut ( & mut self ) -> & mut T {
274
313
* self
275
314
}
276
315
}
277
316
317
+ #[ cfg( not( bootstrap) ) ]
318
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
319
+ impl < T : ?Sized > const DerefMut for & mut T {
320
+ fn deref_mut ( & mut self ) -> & mut T {
321
+ * self
322
+ }
323
+ }
324
+
278
325
/// Perma-unstable marker trait. Indicates that the type has a well-behaved [`Deref`]
279
326
/// (and, if applicable, [`DerefMut`]) implementation. This is relied on for soundness
280
327
/// of deref patterns.
0 commit comments