@@ -115,6 +115,7 @@ use syntax::attr::AttrMetaMethods;
115115use syntax:: ast:: { self , DefId , Visibility } ;
116116use syntax:: ast_util:: { self , local_def} ;
117117use syntax:: codemap:: { self , Span } ;
118+ use syntax:: feature_gate:: emit_feature_err;
118119use syntax:: owned_slice:: OwnedSlice ;
119120use syntax:: parse:: token;
120121use syntax:: print:: pprust;
@@ -4009,9 +4010,7 @@ fn check_const_with_ty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
40094010
40104011/// Checks whether a type can be represented in memory. In particular, it
40114012/// identifies types that contain themselves without indirection through a
4012- /// pointer, which would mean their size is unbounded. This is different from
4013- /// the question of whether a type can be instantiated. See the definition of
4014- /// `check_instantiable`.
4013+ /// pointer, which would mean their size is unbounded.
40154014pub fn check_representable ( tcx : & ty:: ctxt ,
40164015 sp : Span ,
40174016 item_id : ast:: NodeId ,
@@ -4036,31 +4035,19 @@ pub fn check_representable(tcx: &ty::ctxt,
40364035 return true
40374036}
40384037
4039- /// Checks whether a type can be created without an instance of itself.
4040- /// This is similar but different from the question of whether a type
4041- /// can be represented. For example, the following type:
4042- ///
4043- /// enum foo { None, Some(foo) }
4044- ///
4045- /// is instantiable but is not representable. Similarly, the type
4046- ///
4047- /// enum foo { Some(@foo) }
4048- ///
4049- /// is representable, but not instantiable.
4038+ /// Checks whether a type can be constructed at runtime without
4039+ /// an existing instance of that type.
40504040pub fn check_instantiable ( tcx : & ty:: ctxt ,
40514041 sp : Span ,
4052- item_id : ast:: NodeId )
4053- -> bool {
4042+ item_id : ast:: NodeId ) {
40544043 let item_ty = tcx. node_id_to_type ( item_id) ;
4055- if !item_ty. is_instantiable ( tcx) {
4056- span_err ! ( tcx. sess, sp, E0073 ,
4057- "this type cannot be instantiated without an \
4058- instance of itself") ;
4059- fileline_help ! ( tcx. sess, sp, "consider using `Option<{:?}>`" ,
4060- item_ty) ;
4061- false
4062- } else {
4063- true
4044+ if !item_ty. is_instantiable ( tcx) &&
4045+ !tcx. sess . features . borrow ( ) . static_recursion {
4046+ emit_feature_err ( & tcx. sess . parse_sess . span_diagnostic ,
4047+ "static_recursion" ,
4048+ sp,
4049+ "this type cannot be instantiated at runtime \
4050+ without an instance of itself") ;
40644051 }
40654052}
40664053
@@ -4199,11 +4186,6 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
41994186 do_check ( ccx, vs, id, hint) ;
42004187
42014188 check_representable ( ccx. tcx , sp, id, "enum" ) ;
4202-
4203- // Check that it is possible to instantiate this enum:
4204- //
4205- // This *sounds* like the same that as representable, but it's
4206- // not. See def'n of `check_instantiable()` for details.
42074189 check_instantiable ( ccx. tcx , sp, id) ;
42084190}
42094191
0 commit comments