@@ -23,7 +23,6 @@ use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
23
23
use crate :: infer:: { BoundRegionConversionTime , InferOk } ;
24
24
use crate :: traits:: normalize:: normalize_with_depth;
25
25
use crate :: traits:: normalize:: normalize_with_depth_to;
26
- use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
27
26
use crate :: traits:: select:: ProjectionMatchesProjection ;
28
27
use rustc_data_structures:: sso:: SsoHashSet ;
29
28
use rustc_data_structures:: stack:: ensure_sufficient_stack;
@@ -975,9 +974,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
975
974
//
976
975
// NOTE: This should be kept in sync with the similar code in
977
976
// `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 { .. } | ( ) ) ?;
981
983
982
984
if node_item. is_final ( ) {
983
985
// Non-specializable items are always projectable.
@@ -1020,7 +1022,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
1020
1022
lang_items. async_fn_trait ( ) ,
1021
1023
lang_items. async_fn_mut_trait ( ) ,
1022
1024
lang_items. async_fn_once_trait ( ) ,
1023
- ] . contains ( & Some ( trait_ref. def_id ) )
1025
+ ]
1026
+ . contains ( & Some ( trait_ref. def_id ) )
1024
1027
{
1025
1028
true
1026
1029
} else if lang_items. async_fn_kind_helper ( ) == Some ( trait_ref. def_id ) {
@@ -1033,7 +1036,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
1033
1036
true
1034
1037
} else {
1035
1038
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 ( )
1037
1040
}
1038
1041
} else if lang_items. discriminant_kind_trait ( ) == Some ( trait_ref. def_id ) {
1039
1042
match self_ty. kind ( ) {
@@ -1116,34 +1119,28 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
1116
1119
// If returned by `struct_tail_without_normalization` this is the empty tuple.
1117
1120
| ty:: Tuple ( ..)
1118
1121
// 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 ,
1120
1125
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,
1134
1128
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 ( ) ;
1145
1134
false
1146
1135
}
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
+ }
1147
1144
}
1148
1145
} else {
1149
1146
bug ! ( "unexpected builtin trait with associated type: {trait_ref:?}" )
@@ -1190,7 +1187,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
1190
1187
obligation. cause . span ,
1191
1188
format ! ( "Cannot project an associated type from `{impl_source:?}`" ) ,
1192
1189
) ;
1193
- return Err ( ( ) )
1190
+ return Err ( ( ) ) ;
1194
1191
}
1195
1192
} ;
1196
1193
@@ -1510,23 +1507,15 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
1510
1507
} ;
1511
1508
let metadata_ty = self_ty. ptr_metadata_ty_or_tail ( tcx, normalize) . unwrap_or_else ( |tail| {
1512
1509
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",
1522
1514
) ;
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] )
1529
1515
}
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] )
1530
1519
} ) ;
1531
1520
( metadata_ty. into ( ) , obligations)
1532
1521
} else {
0 commit comments