Skip to content

Commit 38fdd50

Browse files
committed
Remove *most* mentions of phantom fns and variance on traits. Leave some
comments and also leave the entries in the variance tables for now.
1 parent 628d715 commit 38fdd50

12 files changed

+174
-172
lines changed

src/libcore/marker.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,15 @@ macro_rules! impls{
276276
#[unstable(feature = "core", reason = "deprecated")]
277277
#[deprecated(since = "1.0.0", reason = "No longer needed")]
278278
#[allow(deprecated)]
279+
#[cfg(stage0)]
279280
pub trait MarkerTrait : PhantomFn<Self,Self> { }
280-
// ~~~~~ <-- FIXME(#22806)?
281-
//
282-
// Marker trait has been made invariant so as to avoid inf recursion,
283-
// but we should ideally solve the underlying problem. That's a bit
284-
// complicated.
281+
282+
/// `MarkerTrait` is deprecated and no longer needed.
283+
#[unstable(feature = "core", reason = "deprecated")]
284+
#[deprecated(since = "1.0.0", reason = "No longer needed")]
285+
#[allow(deprecated)]
286+
#[cfg(not(stage0))]
287+
pub trait MarkerTrait { }
285288

286289
#[allow(deprecated)]
287290
impl<T:?Sized> MarkerTrait for T { }
@@ -290,7 +293,20 @@ impl<T:?Sized> MarkerTrait for T { }
290293
#[lang="phantom_fn"]
291294
#[unstable(feature = "core", reason = "deprecated")]
292295
#[deprecated(since = "1.0.0", reason = "No longer needed")]
293-
pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
296+
#[cfg(stage0)]
297+
pub trait PhantomFn<A:?Sized,R:?Sized=()> {
298+
}
299+
300+
/// `PhantomFn` is a deprecated marker trait that is no longer needed.
301+
#[unstable(feature = "core", reason = "deprecated")]
302+
#[deprecated(since = "1.0.0", reason = "No longer needed")]
303+
#[cfg(not(stage0))]
304+
pub trait PhantomFn<A:?Sized,R:?Sized=()> {
305+
}
306+
307+
#[allow(deprecated)]
308+
#[cfg(not(stage0))]
309+
impl<A:?Sized,R:?Sized,T:?Sized> PhantomFn<A,R> for T { }
294310

295311
/// `PhantomData<T>` allows you to describe that a type acts as if it stores a value of type `T`,
296312
/// even though it does not. This allows you to inform the compiler about certain safety properties

src/librustc/middle/lang_items.rs

-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ lets_do_this! {
321321
ExchangeHeapLangItem, "exchange_heap", exchange_heap;
322322
OwnedBoxLangItem, "owned_box", owned_box;
323323

324-
PhantomFnItem, "phantom_fn", phantom_fn;
325324
PhantomDataItem, "phantom_data", phantom_data;
326325

327326
// Deprecated:

src/librustc/middle/traits/object_safety.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,10 @@ fn supertraits_reference_self<'tcx>(tcx: &ty::ctxt<'tcx>,
138138
match predicate {
139139
ty::Predicate::Trait(ref data) => {
140140
// In the case of a trait predicate, we can skip the "self" type.
141-
Some(data.def_id()) != tcx.lang_items.phantom_fn() &&
142-
data.0.trait_ref.substs.types.get_slice(TypeSpace)
143-
.iter()
144-
.cloned()
145-
.any(is_self)
141+
data.0.trait_ref.substs.types.get_slice(TypeSpace)
142+
.iter()
143+
.cloned()
144+
.any(is_self)
146145
}
147146
ty::Predicate::Projection(..) |
148147
ty::Predicate::TypeOutlives(..) |

src/librustc/middle/traits/select.rs

-8
Original file line numberDiff line numberDiff line change
@@ -836,14 +836,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
836836
ambiguous: false
837837
};
838838

839-
// Check for the `PhantomFn` trait. This is really just a
840-
// special annotation that is *always* considered to match, no
841-
// matter what the type parameters are etc.
842-
if self.tcx().lang_items.phantom_fn() == Some(obligation.predicate.def_id()) {
843-
candidates.vec.push(PhantomFnCandidate);
844-
return Ok(candidates);
845-
}
846-
847839
// Other bounds. Consider both in-scope bounds from fn decl
848840
// and applicable impls. There is a certain set of precedence rules here.
849841

src/librustc_typeck/check/wf.rs

+7-35
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,10 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
117117

118118
self.check_variances_for_type_defn(item, ast_generics);
119119
}
120-
ast::ItemTrait(_, ref ast_generics, _, ref items) => {
120+
ast::ItemTrait(_, _, _, ref items) => {
121121
let trait_predicates =
122122
ty::lookup_predicates(ccx.tcx, local_def(item.id));
123-
reject_non_type_param_bounds(
124-
ccx.tcx,
125-
item.span,
126-
&trait_predicates);
127-
self.check_variances(item, ast_generics, &trait_predicates,
128-
self.tcx().lang_items.phantom_fn());
123+
reject_non_type_param_bounds(ccx.tcx, item.span, &trait_predicates);
129124
if ty::trait_has_default_impl(ccx.tcx, local_def(item.id)) {
130125
if !items.is_empty() {
131126
ccx.tcx.sess.span_err(
@@ -287,30 +282,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
287282
ast_generics: &ast::Generics)
288283
{
289284
let item_def_id = local_def(item.id);
290-
let predicates = ty::lookup_predicates(self.tcx(), item_def_id);
291-
self.check_variances(item,
292-
ast_generics,
293-
&predicates,
294-
self.tcx().lang_items.phantom_data());
295-
}
296-
297-
fn check_variances(&self,
298-
item: &ast::Item,
299-
ast_generics: &ast::Generics,
300-
ty_predicates: &ty::GenericPredicates<'tcx>,
301-
suggested_marker_id: Option<ast::DefId>)
302-
{
303-
let variance_lang_items = &[
304-
self.tcx().lang_items.phantom_fn(),
305-
self.tcx().lang_items.phantom_data(),
306-
];
307-
308-
let item_def_id = local_def(item.id);
309-
let is_lang_item = variance_lang_items.iter().any(|n| *n == Some(item_def_id));
310-
if is_lang_item {
311-
return;
312-
}
313-
285+
let ty_predicates = ty::lookup_predicates(self.tcx(), item_def_id);
314286
let variances = ty::item_variances(self.tcx(), item_def_id);
315287

316288
let mut constrained_parameters: HashSet<_> =
@@ -331,7 +303,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
331303
continue;
332304
}
333305
let span = self.ty_param_span(ast_generics, item, space, index);
334-
self.report_bivariance(span, param_ty.name, suggested_marker_id);
306+
self.report_bivariance(span, param_ty.name);
335307
}
336308

337309
for (space, index, &variance) in variances.regions.iter_enumerated() {
@@ -342,7 +314,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
342314
assert_eq!(space, TypeSpace);
343315
let span = ast_generics.lifetimes[index].lifetime.span;
344316
let name = ast_generics.lifetimes[index].lifetime.name;
345-
self.report_bivariance(span, name, suggested_marker_id);
317+
self.report_bivariance(span, name);
346318
}
347319
}
348320

@@ -377,14 +349,14 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
377349

378350
fn report_bivariance(&self,
379351
span: Span,
380-
param_name: ast::Name,
381-
suggested_marker_id: Option<ast::DefId>)
352+
param_name: ast::Name)
382353
{
383354
self.tcx().sess.span_err(
384355
span,
385356
&format!("parameter `{}` is never used",
386357
param_name.user_string(self.tcx())));
387358

359+
let suggested_marker_id = self.tcx().lang_items.phantom_data();
388360
match suggested_marker_id {
389361
Some(def_id) => {
390362
self.tcx().sess.fileline_help(

0 commit comments

Comments
 (0)