@@ -359,56 +359,6 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
359359 }
360360}
361361
362- // FIXME: Per https://doc.rust-lang.org/nightly/nightly-rustc/rustc_trait_selection/infer/at/struct.At.html#method.normalize
363- // this function can be removed once the `normalize` method does not panic when normalization does
364- // not succeed
365- /// Checks if `Ty` is normalizable. This function is useful
366- /// to avoid crashes on `layout_of`.
367- pub fn is_normalizable < ' tcx > ( cx : & LateContext < ' tcx > , param_env : ParamEnv < ' tcx > , ty : Ty < ' tcx > ) -> bool {
368- is_normalizable_helper ( cx, param_env, ty, 0 , & mut FxHashMap :: default ( ) )
369- }
370-
371- fn is_normalizable_helper < ' tcx > (
372- cx : & LateContext < ' tcx > ,
373- param_env : ParamEnv < ' tcx > ,
374- ty : Ty < ' tcx > ,
375- depth : usize ,
376- cache : & mut FxHashMap < Ty < ' tcx > , bool > ,
377- ) -> bool {
378- if let Some ( & cached_result) = cache. get ( & ty) {
379- return cached_result;
380- }
381- if !cx. tcx . recursion_limit ( ) . value_within_limit ( depth) {
382- return false ;
383- }
384- // Prevent recursive loops by answering `true` to recursive requests with the same
385- // type. This will be adjusted when the outermost call analyzes all the type
386- // components.
387- cache. insert ( ty, true ) ;
388- let infcx = cx. tcx . infer_ctxt ( ) . build ( cx. typing_mode ( ) ) ;
389- let cause = ObligationCause :: dummy ( ) ;
390- let result = if infcx. at ( & cause, param_env) . query_normalize ( ty) . is_ok ( ) {
391- match ty. kind ( ) {
392- ty:: Adt ( def, args) => def. variants ( ) . iter ( ) . all ( |variant| {
393- variant
394- . fields
395- . iter ( )
396- . all ( |field| is_normalizable_helper ( cx, param_env, field. ty ( cx. tcx , args) , depth + 1 , cache) )
397- } ) ,
398- _ => ty. walk ( ) . all ( |generic_arg| match generic_arg. unpack ( ) {
399- GenericArgKind :: Type ( inner_ty) if inner_ty != ty => {
400- is_normalizable_helper ( cx, param_env, inner_ty, depth + 1 , cache)
401- } ,
402- _ => true , // if inner_ty == ty, we've already checked it
403- } ) ,
404- }
405- } else {
406- false
407- } ;
408- cache. insert ( ty, result) ;
409- result
410- }
411-
412362/// Returns `true` if the given type is a non aggregate primitive (a `bool` or `char`, any
413363/// integer or floating-point number type).
414364///
@@ -993,9 +943,6 @@ pub fn adt_and_variant_of_res<'tcx>(cx: &LateContext<'tcx>, res: Res) -> Option<
993943/// account the layout of type parameters.
994944pub fn approx_ty_size < ' tcx > ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> u64 {
995945 use rustc_middle:: ty:: layout:: LayoutOf ;
996- if !is_normalizable ( cx, cx. param_env , ty) {
997- return 0 ;
998- }
999946 match ( cx. layout_of ( ty) . map ( |layout| layout. size . bytes ( ) ) , ty. kind ( ) ) {
1000947 ( Ok ( size) , _) => size,
1001948 ( Err ( _) , ty:: Tuple ( list) ) => list. iter ( ) . map ( |t| approx_ty_size ( cx, t) ) . sum ( ) ,
0 commit comments