Skip to content

Commit af46d69

Browse files
committed
Remove Reflect
* Remove the Reflect trait * Remove the "reflect" lang feature
1 parent d2d8ae6 commit af46d69

File tree

8 files changed

+5
-247
lines changed

8 files changed

+5
-247
lines changed

src/libcore/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
#![feature(no_core)]
8383
#![feature(on_unimplemented)]
8484
#![feature(optin_builtin_traits)]
85-
#![feature(reflect)]
8685
#![feature(unwind_attributes)]
8786
#![feature(repr_simd, platform_intrinsics)]
8887
#![feature(rustc_attrs)]

src/libcore/marker.rs

-56
Original file line numberDiff line numberDiff line change
@@ -553,59 +553,3 @@ mod impls {
553553
#[stable(feature = "rust1", since = "1.0.0")]
554554
unsafe impl<'a, T: Send + ?Sized> Send for &'a mut T {}
555555
}
556-
557-
/// Types that can be reflected over.
558-
///
559-
/// By "reflection" we mean use of the [`Any`][any] trait, or related
560-
/// machinery such as [`TypeId`][typeid].
561-
///
562-
/// `Reflect` is implemented for all types. Its purpose is to ensure
563-
/// that when you write a generic function that will employ reflection,
564-
/// that must be reflected (no pun intended) in the generic bounds of
565-
/// that function.
566-
///
567-
/// ```
568-
/// #![feature(reflect_marker)]
569-
/// use std::marker::Reflect;
570-
/// use std::any::Any;
571-
///
572-
/// # #[allow(dead_code)]
573-
/// fn foo<T: Reflect + 'static>(x: &T) {
574-
/// let any: &Any = x;
575-
/// if any.is::<u32>() { println!("u32"); }
576-
/// }
577-
/// ```
578-
///
579-
/// Without the bound `T: Reflect`, `foo` would not typecheck. (As
580-
/// a matter of style, it would be preferable to write `T: Any`,
581-
/// because `T: Any` implies `T: Reflect` and `T: 'static`, but we
582-
/// use `Reflect` here for illustrative purposes.)
583-
///
584-
/// The `Reflect` bound serves to alert `foo`'s caller to the
585-
/// fact that `foo` may behave differently depending on whether
586-
/// `T` is `u32` or not. The ability for a caller to reason about what
587-
/// a function may do based solely on what generic bounds are declared
588-
/// is often called the "[parametricity property][param]". Despite the
589-
/// use of `Reflect`, Rust lacks true parametricity because a generic
590-
/// function can, at the very least, call [`mem::size_of`][size_of]
591-
/// without employing any trait bounds whatsoever.
592-
///
593-
/// [any]: ../any/trait.Any.html
594-
/// [typeid]: ../any/struct.TypeId.html
595-
/// [param]: http://en.wikipedia.org/wiki/Parametricity
596-
/// [size_of]: ../mem/fn.size_of.html
597-
#[rustc_reflect_like]
598-
#[unstable(feature = "reflect_marker",
599-
reason = "requires RFC and more experience",
600-
issue = "27749")]
601-
#[rustc_deprecated(since = "1.14.0", reason = "Specialization makes parametricity impossible")]
602-
#[rustc_on_unimplemented = "`{Self}` does not implement `Any`; \
603-
ensure all type parameters are bounded by `Any`"]
604-
pub trait Reflect {}
605-
606-
#[unstable(feature = "reflect_marker",
607-
reason = "requires RFC and more experience",
608-
issue = "27749")]
609-
#[rustc_deprecated(since = "1.14.0", reason = "Specialization makes parametricity impossible")]
610-
#[allow(deprecated)]
611-
impl Reflect for .. { }

src/librustc/traits/select.rs

+3-57
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ enum SelectionCandidate<'tcx> {
204204
ParamCandidate(ty::PolyTraitRef<'tcx>),
205205
ImplCandidate(DefId),
206206
DefaultImplCandidate(DefId),
207-
DefaultImplObjectCandidate(DefId),
208207

209208
/// This is a trait matching with a projected type as `Self`, and
210209
/// we found an applicable bound in the trait definition.
@@ -237,9 +236,6 @@ impl<'a, 'tcx> ty::Lift<'tcx> for SelectionCandidate<'a> {
237236
}
238237
ImplCandidate(def_id) => ImplCandidate(def_id),
239238
DefaultImplCandidate(def_id) => DefaultImplCandidate(def_id),
240-
DefaultImplObjectCandidate(def_id) => {
241-
DefaultImplObjectCandidate(def_id)
242-
}
243239
ProjectionCandidate => ProjectionCandidate,
244240
FnPointerCandidate => FnPointerCandidate,
245241
ObjectCandidate => ObjectCandidate,
@@ -1431,17 +1427,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
14311427
match self_ty.sty {
14321428
ty::TyDynamic(..) => {
14331429
// For object types, we don't know what the closed
1434-
// over types are. For most traits, this means we
1435-
// conservatively say nothing; a candidate may be
1436-
// added by `assemble_candidates_from_object_ty`.
1437-
// However, for the kind of magic reflect trait,
1438-
// we consider it to be implemented even for
1439-
// object types, because it just lets you reflect
1440-
// onto the object type, not into the object's
1441-
// interior.
1442-
if self.tcx().has_attr(def_id, "rustc_reflect_like") {
1443-
candidates.vec.push(DefaultImplObjectCandidate(def_id));
1444-
}
1430+
// over types are. This means we conservatively
1431+
// say nothing; a candidate may be added by
1432+
// `assemble_candidates_from_object_ty`.
14451433
}
14461434
ty::TyParam(..) |
14471435
ty::TyProjection(..) |
@@ -1671,7 +1659,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
16711659
FnPointerCandidate |
16721660
BuiltinObjectCandidate |
16731661
BuiltinUnsizeCandidate |
1674-
DefaultImplObjectCandidate(..) |
16751662
BuiltinCandidate { .. } => {
16761663
// We have a where-clause so don't go around looking
16771664
// for impls.
@@ -1998,11 +1985,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
19981985
Ok(VtableDefaultImpl(data))
19991986
}
20001987

2001-
DefaultImplObjectCandidate(trait_def_id) => {
2002-
let data = self.confirm_default_impl_object_candidate(obligation, trait_def_id);
2003-
Ok(VtableDefaultImpl(data))
2004-
}
2005-
20061988
ImplCandidate(impl_def_id) => {
20071989
Ok(VtableImpl(self.confirm_impl_candidate(obligation, impl_def_id)))
20081990
}
@@ -2138,42 +2120,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21382120
self.vtable_default_impl(obligation, trait_def_id, ty::Binder(types))
21392121
}
21402122

2141-
fn confirm_default_impl_object_candidate(&mut self,
2142-
obligation: &TraitObligation<'tcx>,
2143-
trait_def_id: DefId)
2144-
-> VtableDefaultImplData<PredicateObligation<'tcx>>
2145-
{
2146-
debug!("confirm_default_impl_object_candidate({:?}, {:?})",
2147-
obligation,
2148-
trait_def_id);
2149-
2150-
assert!(self.tcx().has_attr(trait_def_id, "rustc_reflect_like"));
2151-
2152-
// OK to skip binder, it is reintroduced below
2153-
let self_ty = self.infcx.shallow_resolve(obligation.predicate.skip_binder().self_ty());
2154-
match self_ty.sty {
2155-
ty::TyDynamic(ref data, ..) => {
2156-
// OK to skip the binder, it is reintroduced below
2157-
let principal = data.principal().unwrap();
2158-
let input_types = principal.input_types();
2159-
let assoc_types = data.projection_bounds()
2160-
.map(|pb| pb.skip_binder().ty);
2161-
let all_types: Vec<_> = input_types.chain(assoc_types)
2162-
.collect();
2163-
2164-
// reintroduce the two binding levels we skipped, then flatten into one
2165-
let all_types = ty::Binder(ty::Binder(all_types));
2166-
let all_types = self.tcx().flatten_late_bound_regions(&all_types);
2167-
2168-
self.vtable_default_impl(obligation, trait_def_id, all_types)
2169-
}
2170-
_ => {
2171-
bug!("asked to confirm default object implementation for non-object type: {:?}",
2172-
self_ty);
2173-
}
2174-
}
2175-
}
2176-
21772123
/// See `confirm_default_impl_candidate`
21782124
fn vtable_default_impl(&mut self,
21792125
obligation: &TraitObligation<'tcx>,

src/libsyntax/feature_gate.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ declare_features! (
124124
(active, advanced_slice_patterns, "1.0.0", Some(23121)),
125125
(active, box_syntax, "1.0.0", Some(27779)),
126126
(active, placement_in_syntax, "1.0.0", Some(27779)),
127-
(active, reflect, "1.0.0", Some(27749)),
128127
(active, unboxed_closures, "1.0.0", Some(29625)),
129128

130129
(active, allocator, "1.0.0", Some(27389)),
@@ -334,6 +333,7 @@ declare_features! (
334333
(removed, managed_boxes, "1.0.0", None),
335334
// Allows use of unary negate on unsigned integers, e.g. -e for e: u8
336335
(removed, negate_unsigned, "1.0.0", Some(29645)),
336+
(removed, reflect, "1.0.0", Some(27749)),
337337
// A way to temporarily opt out of opt in copy. This will *never* be accepted.
338338
(removed, opt_out_copy, "1.0.0", None),
339339
(removed, quad_precision_float, "1.0.0", None),
@@ -731,10 +731,6 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
731731
"unboxed_closures",
732732
"unboxed_closures are still evolving",
733733
cfg_fn!(unboxed_closures))),
734-
("rustc_reflect_like", Whitelisted, Gated(Stability::Unstable,
735-
"reflect",
736-
"defining reflective traits is still evolving",
737-
cfg_fn!(reflect))),
738734

739735
("windows_subsystem", Whitelisted, Gated(Stability::Unstable,
740736
"windows_subsystem",

src/test/compile-fail/reflect-assoc.rs

-37
This file was deleted.

src/test/compile-fail/reflect-object-param.rs

-49
This file was deleted.

src/test/compile-fail/reflect.rs

-41
This file was deleted.

src/tools/tidy/src/features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn check(path: &Path, bad: &mut bool) {
167167
// FIXME get this whitelist empty.
168168
let whitelist = vec![
169169
"abi_ptx", "simd", "macro_reexport",
170-
"static_recursion", "reflect", "quote",
170+
"static_recursion", "quote",
171171
"cfg_target_has_atomic", "staged_api", "const_indexing",
172172
"unboxed_closures", "stmt_expr_attributes",
173173
"cfg_target_thread_local", "unwind_attributes",

0 commit comments

Comments
 (0)