@@ -10,6 +10,7 @@ use rustc_hashes::Hash64;
1010use rustc_index:: IndexVec ;
1111use rustc_middle:: bug;
1212use rustc_middle:: query:: Providers ;
13+ use rustc_middle:: traits:: ObligationCause ;
1314use rustc_middle:: ty:: layout:: {
1415 FloatExt , HasTyCtxt , IntegerExt , LayoutCx , LayoutError , LayoutOf , TyAndLayout ,
1516} ;
@@ -390,30 +391,31 @@ fn layout_of_uncached<'tcx>(
390391
391392 let metadata = if let Some ( metadata_def_id) = tcx. lang_items ( ) . metadata_type ( ) {
392393 let pointee_metadata = Ty :: new_projection ( tcx, metadata_def_id, [ pointee] ) ;
393- let metadata_ty =
394- match tcx . try_normalize_erasing_regions ( cx. typing_env , pointee_metadata) {
395- Ok ( metadata_ty ) => metadata_ty ,
396- Err ( mut err ) => {
397- // Usually `<Ty as Pointee>::Metadata` can't be normalized because
398- // its struct tail cannot be normalized either, so try to get a
399- // more descriptive layout error here, which will lead to less confusing
400- // diagnostics.
401- //
402- // We use the raw struct tail function here to get the first tail
403- // that is an alias, which is likely the cause of the normalization
404- // error.
405- match tcx . try_normalize_erasing_regions (
406- cx . typing_env ,
407- tcx . struct_tail_raw ( pointee , |ty| ty , || { } ) ,
408- ) {
409- Ok ( _ ) => { }
410- Err ( better_err ) => {
411- err = better_err ;
412- }
394+ let metadata_ty = match tcx
395+ . try_normalize_erasing_regions ( cx. typing_env , pointee_metadata)
396+ {
397+ Ok ( metadata_ty ) => metadata_ty ,
398+ Err ( mut err ) => {
399+ // Usually `<Ty as Pointee>::Metadata` can't be normalized because
400+ // its struct tail cannot be normalized either, so try to get a
401+ // more descriptive layout error here, which will lead to less confusing
402+ // diagnostics.
403+ //
404+ // We use the raw struct tail function here to get the first tail
405+ // that is an alias, which is likely the cause of the normalization
406+ // error.
407+ match tcx . try_normalize_erasing_regions (
408+ cx . typing_env ,
409+ tcx . struct_tail_raw ( pointee , & ObligationCause :: dummy ( ) , |ty| ty , || { } ) ,
410+ ) {
411+ Ok ( _ ) => { }
412+ Err ( better_err ) => {
413+ err = better_err ;
413414 }
414- return Err ( error ( cx, LayoutError :: NormalizationFailure ( pointee, err) ) ) ;
415415 }
416- } ;
416+ return Err ( error ( cx, LayoutError :: NormalizationFailure ( pointee, err) ) ) ;
417+ }
418+ } ;
417419
418420 let metadata_layout = cx. layout_of ( metadata_ty) ?;
419421 // If the metadata is a 1-zst, then the pointer is thin.
0 commit comments