@@ -23,7 +23,6 @@ use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
2323use crate :: infer:: { BoundRegionConversionTime , InferOk } ;
2424use crate :: traits:: normalize:: normalize_with_depth;
2525use crate :: traits:: normalize:: normalize_with_depth_to;
26- use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
2726use crate :: traits:: select:: ProjectionMatchesProjection ;
2827use rustc_data_structures:: sso:: SsoHashSet ;
2928use rustc_data_structures:: stack:: ensure_sufficient_stack;
@@ -975,9 +974,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
975974 //
976975 // NOTE: This should be kept in sync with the similar code in
977976 // `rustc_ty_utils::instance::resolve_associated_item()`.
978- let node_item =
979- specialization_graph:: assoc_def ( selcx. tcx ( ) , impl_data. impl_def_id , obligation. predicate . def_id )
980- . map_err ( |ErrorGuaranteed { .. } | ( ) ) ?;
977+ let node_item = specialization_graph:: assoc_def (
978+ selcx. tcx ( ) ,
979+ impl_data. impl_def_id ,
980+ obligation. predicate . def_id ,
981+ )
982+ . map_err ( |ErrorGuaranteed { .. } | ( ) ) ?;
981983
982984 if node_item. is_final ( ) {
983985 // Non-specializable items are always projectable.
@@ -1020,7 +1022,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
10201022 lang_items. async_fn_trait ( ) ,
10211023 lang_items. async_fn_mut_trait ( ) ,
10221024 lang_items. async_fn_once_trait ( ) ,
1023- ] . contains ( & Some ( trait_ref. def_id ) )
1025+ ]
1026+ . contains ( & Some ( trait_ref. def_id ) )
10241027 {
10251028 true
10261029 } else if lang_items. async_fn_kind_helper ( ) == Some ( trait_ref. def_id ) {
@@ -1033,7 +1036,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
10331036 true
10341037 } else {
10351038 obligation. predicate . args . type_at ( 0 ) . to_opt_closure_kind ( ) . is_some ( )
1036- && obligation. predicate . args . type_at ( 1 ) . to_opt_closure_kind ( ) . is_some ( )
1039+ && obligation. predicate . args . type_at ( 1 ) . to_opt_closure_kind ( ) . is_some ( )
10371040 }
10381041 } else if lang_items. discriminant_kind_trait ( ) == Some ( trait_ref. def_id ) {
10391042 match self_ty. kind ( ) {
@@ -1116,34 +1119,28 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
11161119 // If returned by `struct_tail_without_normalization` this is the empty tuple.
11171120 | ty:: Tuple ( ..)
11181121 // Integers and floats are always Sized, and so have unit type metadata.
1119- | ty:: Infer ( ty:: InferTy :: IntVar ( _) | ty:: InferTy :: FloatVar ( ..) ) => true ,
1122+ | ty:: Infer ( ty:: InferTy :: IntVar ( _) | ty:: InferTy :: FloatVar ( ..) )
1123+ // `{type error}` is sized, so its metadata must be the unit type.
1124+ | ty:: Error ( _) => true ,
11201125
1121- // We normalize from `Wrapper<Tail>::Metadata` to `Tail::Metadata` if able.
1122- // Otherwise, type parameters, opaques, and unnormalized projections have
1123- // unit metadata if they're known (e.g. by the param_env) to be sized.
1124- ty:: Param ( _) | ty:: Alias ( ..)
1125- if self_ty != tail || selcx. infcx . predicate_must_hold_modulo_regions (
1126- & obligation. with (
1127- selcx. tcx ( ) ,
1128- ty:: TraitRef :: from_lang_item ( selcx. tcx ( ) , LangItem :: Sized , obligation. cause . span ( ) , [ self_ty] ) ,
1129- ) ,
1130- ) =>
1131- {
1132- true
1133- }
1126+ // We normalize from `Wrapper<Tail>::Metadata` to `Tail::Metadata`.
1127+ ty:: Param ( _) | ty:: Alias ( ..) => self_ty != tail,
11341128
1135- // FIXME(compiler-errors): are Bound and Placeholder types ever known sized?
1136- ty:: Param ( _)
1137- | ty:: Alias ( ..)
1138- | ty:: Bound ( ..)
1139- | ty:: Placeholder ( ..)
1140- | ty:: Infer ( ..)
1141- | ty:: Error ( _) => {
1142- if tail. has_infer_types ( ) {
1143- candidate_set. mark_ambiguous ( ) ;
1144- }
1129+ // FIXME: These should probably project to the tail as well.
1130+ ty:: Bound ( ..) | ty:: Placeholder ( ..) => false ,
1131+
1132+ ty:: Infer ( ty:: TyVar ( _) ) => {
1133+ candidate_set. mark_ambiguous ( ) ;
11451134 false
11461135 }
1136+
1137+ ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
1138+ span_bug ! (
1139+ obligation. cause. span,
1140+ "unexpected self ty `{self_ty:?}` when normalizing \
1141+ `<T as Pointee>::Metadata`",
1142+ )
1143+ }
11471144 }
11481145 } else {
11491146 bug ! ( "unexpected builtin trait with associated type: {trait_ref:?}" )
@@ -1190,7 +1187,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
11901187 obligation. cause . span ,
11911188 format ! ( "Cannot project an associated type from `{impl_source:?}`" ) ,
11921189 ) ;
1193- return Err ( ( ) )
1190+ return Err ( ( ) ) ;
11941191 }
11951192 } ;
11961193
@@ -1510,23 +1507,15 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
15101507 } ;
15111508 let metadata_ty = self_ty. ptr_metadata_ty_or_tail ( tcx, normalize) . unwrap_or_else ( |tail| {
15121509 if tail == self_ty {
1513- // This is the "fallback impl" for type parameters, unnormalizable projections
1514- // and opaque types: If the `self_ty` is `Sized`, then the metadata is `()`.
1515- // FIXME(ptr_metadata): This impl overlaps with the other impls and shouldn't
1516- // exist. Instead, `Pointee<Metadata = ()>` should be a supertrait of `Sized`.
1517- let sized_predicate = ty:: TraitRef :: from_lang_item (
1518- tcx,
1519- LangItem :: Sized ,
1520- obligation. cause . span ( ) ,
1521- [ self_ty] ,
1510+ span_bug ! (
1511+ obligation. cause. span,
1512+ "`<{self_ty:?} as Pointee>::Metadata` projection candidate assembled, \
1513+ but we cannot project further",
15221514 ) ;
1523- obligations. push ( obligation. with ( tcx, sized_predicate) ) ;
1524- tcx. types . unit
1525- } else {
1526- // We know that `self_ty` has the same metadata as `tail`. This allows us
1527- // to prove predicates like `Wrapper<Tail>::Metadata == Tail::Metadata`.
1528- Ty :: new_projection ( tcx, metadata_def_id, [ tail] )
15291515 }
1516+ // We know that `self_ty` has the same metadata as `tail`. This allows us
1517+ // to prove predicates like `Wrapper<Tail>::Metadata == Tail::Metadata`.
1518+ Ty :: new_projection ( tcx, metadata_def_id, [ tail] )
15301519 } ) ;
15311520 ( metadata_ty. into ( ) , obligations)
15321521 } else {
0 commit comments