Skip to content

Commit 628d715

Browse files
committed
Deprecate MarkerTrait and PhantomFn.
1 parent 9b5acca commit 628d715

File tree

3 files changed

+17
-68
lines changed

3 files changed

+17
-68
lines changed

src/libarena/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,16 @@ struct TyDesc {
192192
align: usize
193193
}
194194

195+
trait AllTypes { fn dummy(&self) { } }
196+
impl<T:?Sized> AllTypes for T { }
197+
195198
unsafe fn get_tydesc<T>() -> *const TyDesc {
196199
use std::raw::TraitObject;
197200

198201
let ptr = &*(1 as *const T);
199202

200203
// Can use any trait that is implemented for all types.
201-
let obj = mem::transmute::<&marker::MarkerTrait, TraitObject>(ptr);
204+
let obj = mem::transmute::<&AllTypes, TraitObject>(ptr);
202205
obj.vtable as *const TyDesc
203206
}
204207

src/libcore/marker.rs

+12-67
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use hash::Hasher;
3535
#[stable(feature = "rust1", since = "1.0.0")]
3636
#[lang="send"]
3737
#[rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely"]
38+
#[allow(deprecated)]
3839
pub unsafe trait Send : MarkerTrait {
3940
// empty.
4041
}
@@ -50,6 +51,7 @@ impl !Send for Managed { }
5051
#[lang="sized"]
5152
#[rustc_on_unimplemented = "`{Self}` does not have a constant size known at compile-time"]
5253
#[fundamental] // for Default, for example, which requires that `[T]: !Default` be evaluatable
54+
#[allow(deprecated)]
5355
pub trait Sized : MarkerTrait {
5456
// Empty.
5557
}
@@ -203,6 +205,7 @@ pub trait Copy : Clone {
203205
#[stable(feature = "rust1", since = "1.0.0")]
204206
#[lang="sync"]
205207
#[rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely"]
208+
#[allow(deprecated)]
206209
pub unsafe trait Sync : MarkerTrait {
207210
// Empty
208211
}
@@ -269,83 +272,24 @@ macro_rules! impls{
269272
)
270273
}
271274

272-
/// `MarkerTrait` is intended to be used as the supertrait for traits
273-
/// that don't have any methods but instead serve just to designate
274-
/// categories of types. An example would be the `Send` trait, which
275-
/// indicates types that are sendable: `Send` does not itself offer
276-
/// any methods, but instead is used to gate access to data.
277-
///
278-
/// FIXME. Better documentation needed here!
279-
#[stable(feature = "rust1", since = "1.0.0")]
275+
/// `MarkerTrait` is deprecated and no longer needed.
276+
#[unstable(feature = "core", reason = "deprecated")]
277+
#[deprecated(since = "1.0.0", reason = "No longer needed")]
278+
#[allow(deprecated)]
280279
pub trait MarkerTrait : PhantomFn<Self,Self> { }
281280
// ~~~~~ <-- FIXME(#22806)?
282281
//
283282
// Marker trait has been made invariant so as to avoid inf recursion,
284283
// but we should ideally solve the underlying problem. That's a bit
285284
// complicated.
286285

286+
#[allow(deprecated)]
287287
impl<T:?Sized> MarkerTrait for T { }
288288

289-
/// `PhantomFn` is a marker trait for use with traits that contain
290-
/// type or lifetime parameters that do not appear in any of their
291-
/// methods. In that case, you can either remove those parameters, or
292-
/// add a `PhantomFn` supertrait that reflects the signature of
293-
/// methods that compiler should "pretend" exists. This most commonly
294-
/// occurs for traits with no methods: in that particular case, you
295-
/// can extend `MarkerTrait`, which is equivalent to
296-
/// `PhantomFn<Self>`.
297-
///
298-
/// # Examples
299-
///
300-
/// As an example, consider a trait with no methods like `Even`, meant
301-
/// to represent types that are "even":
302-
///
303-
/// ```rust,ignore
304-
/// trait Even { }
305-
/// ```
306-
///
307-
/// In this case, because the implicit parameter `Self` is unused, the
308-
/// compiler will issue an error. The only purpose of this trait is to
309-
/// categorize types (and hence instances of those types) as "even" or
310-
/// not, so if we *were* going to have a method, it might look like:
311-
///
312-
/// ```rust,ignore
313-
/// trait Even {
314-
/// fn is_even(self) -> bool { true }
315-
/// }
316-
/// ```
317-
///
318-
/// Therefore, we can model a method like this as follows:
319-
///
320-
/// ```
321-
/// use std::marker::PhantomFn;
322-
/// trait Even : PhantomFn<Self> { }
323-
/// ```
324-
///
325-
/// Another equivalent, but clearer, option would be to use
326-
/// `MarkerTrait`:
327-
///
328-
/// ```
329-
/// # #![feature(core)]
330-
/// use std::marker::MarkerTrait;
331-
/// trait Even : MarkerTrait { }
332-
/// ```
333-
///
334-
/// # Parameters
335-
///
336-
/// - `A` represents the type of the method's argument. You can use a
337-
/// tuple to represent "multiple" arguments. Any types appearing here
338-
/// will be considered "contravariant".
339-
/// - `R`, if supplied, represents the method's return type. This defaults
340-
/// to `()` as it is rarely needed.
341-
///
342-
/// # Additional reading
343-
///
344-
/// More details and background can be found in [RFC 738][738].
345-
///
346-
/// [738]: https://github.com/rust-lang/rfcs/blob/master/text/0738-variance.md
289+
/// `PhantomFn` is a deprecated marker trait that is no longer needed.
347290
#[lang="phantom_fn"]
348-
#[stable(feature = "rust1", since = "1.0.0")]
291+
#[unstable(feature = "core", reason = "deprecated")]
292+
#[deprecated(since = "1.0.0", reason = "No longer needed")]
349293
pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
350294

351295
/// `PhantomData<T>` allows you to describe that a type acts as if it stores a value of type `T`,
@@ -444,6 +388,7 @@ mod impls {
444388
/// [1]: http://en.wikipedia.org/wiki/Parametricity
445389
#[rustc_reflect_like]
446390
#[unstable(feature = "core", reason = "requires RFC and more experience")]
391+
#[allow(deprecated)]
447392
pub trait Reflect : MarkerTrait {
448393
}
449394

src/libcore/nonzero.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use marker::{Sized, MarkerTrait};
1414
use ops::Deref;
1515

1616
/// Unsafe trait to indicate what types are usable with the NonZero struct
17+
#[allow(deprecated)]
1718
pub unsafe trait Zeroable : MarkerTrait {}
1819

1920
unsafe impl<T:?Sized> Zeroable for *const T {}

0 commit comments

Comments
 (0)