pub(crate) fn generic_defaults_query(
    db: &dyn HirDatabase,
    def: GenericDefId,
) -> Arc<[Binders<Ty>]> {
    let resolver = def.resolver(db.upcast());
    let ctx =
        TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
    let generic_params = generics(db.upcast(), def);

    let defaults = generic_params
        .iter()
        .enumerate()
        .map(|(idx, (_, p))| {
            let mut ty = p.default.as_ref().map_or(Ty::Unknown, |t| Ty::from_hir(&ctx, t));

            // Each default can only refer to previous parameters.
            ty.walk_mut_binders(
                &mut |ty, binders| match ty {
                    Ty::Bound(BoundVar { debruijn, index }) if *debruijn == binders => {
                        if *index >= idx {
                            // type variable default referring to parameter coming
                            // after it. This is forbidden (FIXME: report
                            // diagnostic)
                            *ty = Ty::Unknown;
                        }
                    }
                    _ => {}
                },
                DebruijnIndex::INNERMOST,
            );

            Binders::new(idx, ty)
        })
        .collect();

    defaults
}
/// Resolve the default type params from generics
Resolve the default type params from generics
Resolve the default type params from generics
pub(crate) fn generic_defaults_query(
    db: &dyn HirDatabase,
    def: GenericDefId,
) -> Arc<[Binders<Ty>]> {
    let resolver = def.resolver(db.upcast());
    let ctx =
        TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
    let generic_params = generics(db.upcast(), def);
    let defaults = generic_params
        .iter()
        .enumerate()
        .map(|(idx, (_, p))| {
            let mut ty = p.default.as_ref().map_or(Ty::Unknown, |t| Ty::from_hir(&ctx, t));
            // Each default can only refer to previous parameters.
            ty.walk_mut_binders(
                &mut |ty, binders| match ty {
                    Ty::Bound(BoundVar { debruijn, index }) if *debruijn == binders => {
                        if *index >= idx {
                            // type variable default referring to parameter coming
                            // after it. This is forbidden (FIXME: report
                            // diagnostic)
                            *ty = Ty::Unknown;
                        }
                    }
                    _ => {}
                },
                DebruijnIndex::INNERMOST,
            );
            Binders::new(idx, ty)
        })
        .collect();
    defaults
}
pub ( crate ) fn generic_defaults_query ( db : & dyn HirDatabase , def : GenericDefId , ) -> Arc < [ Binders < Ty > ] > { let resolver = def . resolver ( db . upcast ( ) ) ; let ctx = TyLoweringContext :: new ( db , & resolver ) . with_type_param_mode ( TypeParamLoweringMode :: Variable ) ; let generic_params = generics ( db . upcast ( ) , def ) ; let defaults = generic_params . iter ( ) . enumerate ( ) . map ( | ( idx , ( _ , p ) ) | { let mut ty = p . default . as_ref ( ) . map_or ( Ty :: Unknown , | t | Ty :: from_hir ( & ctx , t ) ) ; // Each default can only refer to previous parameters. ty . walk_mut_binders ( & mut | ty , binders | match ty { Ty :: Bound ( BoundVar { debruijn , index } ) if * debruijn == binders => { if * index >= idx { // type variable default referring to parameter coming // after it. This is forbidden (FIXME: report // diagnostic) * ty = Ty :: Unknown ; } } _ => { } } , DebruijnIndex :: INNERMOST , ) ; Binders :: new ( idx , ty ) } ) . collect ( ) ; defaults }
Resolve the default type params from generics
Resolve the default type params from generics
db
&dyn HirDatabase
def
GenericDefId