fn enum_variants_with_paths(
    acc: &mut Completions,
    ctx: &CompletionContext,
    enum_: hir::Enum,
    cb: impl Fn(&mut Completions, &CompletionContext, hir::Variant, hir::ModPath),
) {
    let variants = enum_.variants(ctx.db);

    if let Some(impl_) = ctx.impl_def.as_ref().and_then(|impl_| ctx.sema.to_def(impl_)) {
        if impl_.self_ty(ctx.db).as_adt() == Some(hir::Adt::Enum(enum_)) {
            for &variant in &variants {
                let self_path = hir::ModPath::from_segments(
                    hir::PathKind::Plain,
                    iter::once(known::SELF_TYPE).chain(iter::once(variant.name(ctx.db))),
                );
                cb(acc, ctx, variant, self_path);
            }
        }
    }

    for variant in variants {
        if let Some(path) = ctx.module.find_use_path(ctx.db, hir::ModuleDef::from(variant)) {
            // Variants with trivial paths are already added by the existing completion logic,
            // so we should avoid adding these twice
            if path.segments().len() > 1 {
                cb(acc, ctx, variant, path);
            }
        }
    }
}
/// Calls the callback for each variant of the provided enum with the path to the variant.
/// Skips variants that are visible with single segment paths.
Calls the callback for each variant of the provided enum with the path to the variant.
Skips variants that are visible with single segment paths.
Calls the callback for each variant of the provided enum with the path to the variant . Skips variants that are visible with single segment paths .
fn enum_variants_with_paths(
    acc: &mut Completions,
    ctx: &CompletionContext,
    enum_: hir::Enum,
    cb: impl Fn(&mut Completions, &CompletionContext, hir::Variant, hir::ModPath),
) {
    let variants = enum_.variants(ctx.db);
    if let Some(impl_) = ctx.impl_def.as_ref().and_then(|impl_| ctx.sema.to_def(impl_)) {
        if impl_.self_ty(ctx.db).as_adt() == Some(hir::Adt::Enum(enum_)) {
            for &variant in &variants {
                let self_path = hir::ModPath::from_segments(
                    hir::PathKind::Plain,
                    iter::once(known::SELF_TYPE).chain(iter::once(variant.name(ctx.db))),
                );
                cb(acc, ctx, variant, self_path);
            }
        }
    }
    for variant in variants {
        if let Some(path) = ctx.module.find_use_path(ctx.db, hir::ModuleDef::from(variant)) {
            // Variants with trivial paths are already added by the existing completion logic,
            // so we should avoid adding these twice
            if path.segments().len() > 1 {
                cb(acc, ctx, variant, path);
            }
        }
    }
}
fn enum_variants_with_paths ( acc : & mut Completions , ctx : & CompletionContext , enum_ : hir :: Enum , cb : impl Fn ( & mut Completions , & CompletionContext , hir :: Variant , hir :: ModPath ) , ) { let variants = enum_ . variants ( ctx . db ) ; if let Some ( impl_ ) = ctx . impl_def . as_ref ( ) . and_then ( | impl_ | ctx . sema . to_def ( impl_ ) ) { if impl_ . self_ty ( ctx . db ) . as_adt ( ) == Some ( hir :: Adt :: Enum ( enum_ ) ) { for & variant in & variants { let self_path = hir :: ModPath :: from_segments ( hir :: PathKind :: Plain , iter :: once ( known :: SELF_TYPE ) . chain ( iter :: once ( variant . name ( ctx . db ) ) ) , ) ; cb ( acc , ctx , variant , self_path ) ; } } } for variant in variants { if let Some ( path ) = ctx . module . find_use_path ( ctx . db , hir :: ModuleDef :: from ( variant ) ) { // Variants with trivial paths are already added by the existing completion logic, // so we should avoid adding these twice if path . segments ( ) . len ( ) > 1 { cb ( acc , ctx , variant , path ) ; } } } }
Calls the callback for each variant of the provided enum with the path to the variant.
Calls the callback for each variant of the provided enum with the path to the variant .
acc
&mut Completions
ctx
&CompletionContext
enum_
hir::Enum
cb
impl Fn(&mut Completions, &CompletionContext, hir::Variant, hir::ModPath)
acc
&mut Completions
ctx
&CompletionContext
enum_
hir::Enum
cb
impl Fn(&mut Completions, &CompletionContext, hir::Variant, hir::ModPath)