@@ -981,10 +981,11 @@ impl<'a> TyLoweringContext<'a> {
981
981
982
982
fn lower_dyn_trait ( & self , bounds : & [ Interned < TypeBound > ] ) -> Ty {
983
983
let self_ty = TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , 0 ) ) . intern ( Interner ) ;
984
- // INVARIANT: The principal trait bound must come first. Others may be in any order but
985
- // should be in the same order for the same set but possibly different order of bounds in
986
- // the input.
987
- // This invariant is used by `TyExt::dyn_trait()` and chalk.
984
+ // INVARIANT: The principal trait bound, if present, must come first. Others may be in any
985
+ // order but should be in the same order for the same set but possibly different order of
986
+ // bounds in the input.
987
+ // INVARIANT: If this function returns `DynTy`, there should be at least one trait bound.
988
+ // These invariants are utilized by `TyExt::dyn_trait()` and chalk.
988
989
let bounds = self . with_shifted_in ( DebruijnIndex :: ONE , |ctx| {
989
990
let mut bounds: Vec < _ > = bounds
990
991
. iter ( )
@@ -1035,6 +1036,12 @@ impl<'a> TyLoweringContext<'a> {
1035
1036
return None ;
1036
1037
}
1037
1038
1039
+ if bounds. first ( ) . and_then ( |b| b. trait_id ( ) ) . is_none ( ) {
1040
+ // When there's no trait bound, that's an error. This happens when the trait refs
1041
+ // are unresolved.
1042
+ return None ;
1043
+ }
1044
+
1038
1045
// As multiple occurrences of the same auto traits *are* permitted, we dedulicate the
1039
1046
// bounds. We shouldn't have repeated elements besides auto traits at this point.
1040
1047
bounds. dedup ( ) ;
@@ -1046,7 +1053,8 @@ impl<'a> TyLoweringContext<'a> {
1046
1053
let bounds = crate :: make_single_type_binders ( bounds) ;
1047
1054
TyKind :: Dyn ( DynTy { bounds, lifetime : static_lifetime ( ) } ) . intern ( Interner )
1048
1055
} else {
1049
- // FIXME: report error (additional non-auto traits or associated type rebound)
1056
+ // FIXME: report error
1057
+ // (additional non-auto traits, associated type rebound, or no resolved trait)
1050
1058
TyKind :: Error . intern ( Interner )
1051
1059
}
1052
1060
}
0 commit comments