@@ -115,6 +115,7 @@ use syntax::attr::AttrMetaMethods;
115
115
use syntax:: ast:: { self , DefId , Visibility } ;
116
116
use syntax:: ast_util:: { self , local_def} ;
117
117
use syntax:: codemap:: { self , Span } ;
118
+ use syntax:: feature_gate:: emit_feature_err;
118
119
use syntax:: owned_slice:: OwnedSlice ;
119
120
use syntax:: parse:: token;
120
121
use syntax:: print:: pprust;
@@ -4009,9 +4010,7 @@ fn check_const_with_ty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
4009
4010
4010
4011
/// Checks whether a type can be represented in memory. In particular, it
4011
4012
/// 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.
4015
4014
pub fn check_representable ( tcx : & ty:: ctxt ,
4016
4015
sp : Span ,
4017
4016
item_id : ast:: NodeId ,
@@ -4036,31 +4035,19 @@ pub fn check_representable(tcx: &ty::ctxt,
4036
4035
return true
4037
4036
}
4038
4037
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.
4050
4040
pub fn check_instantiable ( tcx : & ty:: ctxt ,
4051
4041
sp : Span ,
4052
- item_id : ast:: NodeId )
4053
- -> bool {
4042
+ item_id : ast:: NodeId ) {
4054
4043
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") ;
4064
4051
}
4065
4052
}
4066
4053
@@ -4199,11 +4186,6 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
4199
4186
do_check ( ccx, vs, id, hint) ;
4200
4187
4201
4188
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.
4207
4189
check_instantiable ( ccx. tcx , sp, id) ;
4208
4190
}
4209
4191
0 commit comments