Skip to content

Commit 4790916

Browse files
committed
Auto merge of rust-lang#13139 - Austaras:enum, r=Veykril
Suggest struct when completing enum closes rust-lang#13107
2 parents a1c2653 + 748567c commit 4790916

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

crates/ide-completion/src/tests/expression.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,45 @@ fn main() {
671671
);
672672
}
673673

674+
#[test]
675+
fn varaiant_with_struct() {
676+
check_empty(
677+
r#"
678+
pub struct YoloVariant {
679+
pub f: usize
680+
}
681+
682+
pub enum HH {
683+
Yolo(YoloVariant),
684+
}
685+
686+
fn brr() {
687+
let t = HH::Yolo(Y$0);
688+
}
689+
"#,
690+
expect![[r#"
691+
en HH
692+
fn brr() fn()
693+
st YoloVariant
694+
st YoloVariant {…} YoloVariant { f: usize }
695+
bt u32
696+
kw crate::
697+
kw false
698+
kw for
699+
kw if
700+
kw if let
701+
kw loop
702+
kw match
703+
kw return
704+
kw self::
705+
kw true
706+
kw unsafe
707+
kw while
708+
kw while let
709+
"#]],
710+
);
711+
}
712+
674713
#[test]
675714
fn return_unit_block() {
676715
cov_mark::check!(return_unit_block);

crates/ide-db/src/active_parameter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::RootDatabase;
1212
#[derive(Debug)]
1313
pub struct ActiveParameter {
1414
pub ty: Type,
15-
pub pat: Either<ast::SelfParam, ast::Pat>,
15+
pub pat: Option<Either<ast::SelfParam, ast::Pat>>,
1616
}
1717

1818
impl ActiveParameter {
@@ -27,12 +27,12 @@ impl ActiveParameter {
2727
return None;
2828
}
2929
let (pat, ty) = params.swap_remove(idx);
30-
pat.map(|pat| ActiveParameter { ty, pat })
30+
Some(ActiveParameter { ty, pat })
3131
}
3232

3333
pub fn ident(&self) -> Option<ast::Name> {
34-
self.pat.as_ref().right().and_then(|param| match param {
35-
ast::Pat::IdentPat(ident) => ident.name(),
34+
self.pat.as_ref().and_then(|param| match param {
35+
Either::Right(ast::Pat::IdentPat(ident)) => ident.name(),
3636
_ => None,
3737
})
3838
}

0 commit comments

Comments
 (0)