Skip to content

Commit d622235

Browse files
committed
Add deprecated versions of the old markers and integrate them back into the variance analysis.
1 parent a2393e6 commit d622235

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

src/libcore/marker.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,40 @@ mod impls {
383383
unsafe impl<'a, T: Sync + ?Sized> Send for &'a T {}
384384
unsafe impl<'a, T: Send + ?Sized> Send for &'a mut T {}
385385
}
386+
387+
/// Old-style marker trait. Deprecated.
388+
#[unstable(feature = "core", reason = "deprecated")]
389+
#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<&'a ()>`")]
390+
#[lang="contravariant_lifetime"]
391+
pub struct ContravariantLifetime<'a>;
392+
393+
/// Old-style marker trait. Deprecated.
394+
#[unstable(feature = "core", reason = "deprecated")]
395+
#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<fn(&'a ())>`")]
396+
#[lang="covariant_lifetime"]
397+
pub struct CovariantLifetime<'a>;
398+
399+
/// Old-style marker trait. Deprecated.
400+
#[unstable(feature = "core", reason = "deprecated")]
401+
#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<Cell<&'a ()>>`")]
402+
#[lang="invariant_lifetime"]
403+
pub struct InvariantLifetime<'a>;
404+
405+
/// Old-style marker trait. Deprecated.
406+
#[unstable(feature = "core", reason = "deprecated")]
407+
#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<fn(T)>`")]
408+
#[lang="contravariant_type"]
409+
pub struct ContravariantType<T>;
410+
411+
/// Old-style marker trait. Deprecated.
412+
#[unstable(feature = "core", reason = "deprecated")]
413+
#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<T>`")]
414+
#[lang="covariant_type"]
415+
#[cfg(not(stage0))]
416+
pub struct CovariantType<T>;
417+
418+
/// Old-style marker trait. Deprecated.
419+
#[unstable(feature = "core", reason = "deprecated")]
420+
#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<Cell<T>>`")]
421+
#[lang="invariant_type"]
422+
pub struct InvariantType<T>;

src/librustc/middle/lang_items.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ lets_do_this! {
315315
PhantomFnItem, "phantom_fn", phantom_fn;
316316
PhantomDataItem, "phantom_data", phantom_data;
317317

318+
// Deprecated:
319+
CovariantTypeItem, "covariant_type", covariant_type;
320+
ContravariantTypeItem, "contravariant_type", contravariant_type;
321+
InvariantTypeItem, "invariant_type", invariant_type;
322+
CovariantLifetimeItem, "covariant_lifetime", covariant_lifetime;
323+
ContravariantLifetimeItem, "contravariant_lifetime", contravariant_lifetime;
324+
InvariantLifetimeItem, "invariant_lifetime", invariant_lifetime;
325+
318326
NoCopyItem, "no_copy_bound", no_copy_bound;
319327
ManagedItem, "managed_bound", managed_bound;
320328

src/librustc_typeck/variance.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,17 @@ fn lang_items(tcx: &ty::ctxt) -> Vec<(ast::NodeId,Vec<ty::Variance>)> {
335335
let all = vec![
336336
(tcx.lang_items.phantom_fn(), vec![ty::Contravariant, ty::Covariant]),
337337
(tcx.lang_items.phantom_data(), vec![ty::Covariant]),
338-
(tcx.lang_items.unsafe_cell_type(), vec![ty::Invariant])];
338+
(tcx.lang_items.unsafe_cell_type(), vec![ty::Invariant]),
339+
340+
// Deprecated:
341+
(tcx.lang_items.covariant_type(), vec![ty::Covariant]),
342+
(tcx.lang_items.contravariant_type(), vec![ty::Contravariant]),
343+
(tcx.lang_items.invariant_type(), vec![ty::Invariant]),
344+
(tcx.lang_items.covariant_lifetime(), vec![ty::Covariant]),
345+
(tcx.lang_items.contravariant_lifetime(), vec![ty::Contravariant]),
346+
(tcx.lang_items.invariant_lifetime(), vec![ty::Invariant]),
347+
348+
];
339349

340350
all.into_iter()
341351
.filter(|&(ref d,_)| d.is_some())
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that the deprecated markers still have their old effect.
12+
13+
#![feature(rustc_attrs)]
14+
15+
use std::marker;
16+
17+
#[rustc_variance]
18+
struct A<T>(marker::CovariantType<T>); //~ ERROR types=[[+];[];[]]
19+
20+
#[rustc_variance]
21+
struct B<T>(marker::ContravariantType<T>); //~ ERROR types=[[-];[];[]]
22+
23+
#[rustc_variance]
24+
struct C<T>(marker::InvariantType<T>); //~ ERROR types=[[o];[];[]]
25+
26+
#[rustc_variance]
27+
struct D<'a>(marker::CovariantLifetime<'a>); //~ ERROR regions=[[+];[];[]]
28+
29+
#[rustc_variance]
30+
struct E<'a>(marker::ContravariantLifetime<'a>); //~ ERROR regions=[[-];[];[]]
31+
32+
#[rustc_variance]
33+
struct F<'a>(marker::InvariantLifetime<'a>); //~ ERROR regions=[[o];[];[]]
34+
35+
fn main() { }

0 commit comments

Comments
 (0)