Skip to content

Commit

Permalink
Auto merge of rust-lang#13139 - Austaras:enum, r=Veykril
Browse files Browse the repository at this point in the history
Suggest struct when completing enum

closes rust-lang#13107
  • Loading branch information
bors committed Sep 5, 2022
2 parents a1c2653 + 748567c commit 4790916
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
39 changes: 39 additions & 0 deletions crates/ide-completion/src/tests/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,45 @@ fn main() {
);
}

#[test]
fn varaiant_with_struct() {
check_empty(
r#"
pub struct YoloVariant {
pub f: usize
}
pub enum HH {
Yolo(YoloVariant),
}
fn brr() {
let t = HH::Yolo(Y$0);
}
"#,
expect![[r#"
en HH
fn brr() fn()
st YoloVariant
st YoloVariant {…} YoloVariant { f: usize }
bt u32
kw crate::
kw false
kw for
kw if
kw if let
kw loop
kw match
kw return
kw self::
kw true
kw unsafe
kw while
kw while let
"#]],
);
}

#[test]
fn return_unit_block() {
cov_mark::check!(return_unit_block);
Expand Down
8 changes: 4 additions & 4 deletions crates/ide-db/src/active_parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::RootDatabase;
#[derive(Debug)]
pub struct ActiveParameter {
pub ty: Type,
pub pat: Either<ast::SelfParam, ast::Pat>,
pub pat: Option<Either<ast::SelfParam, ast::Pat>>,
}

impl ActiveParameter {
Expand All @@ -27,12 +27,12 @@ impl ActiveParameter {
return None;
}
let (pat, ty) = params.swap_remove(idx);
pat.map(|pat| ActiveParameter { ty, pat })
Some(ActiveParameter { ty, pat })
}

pub fn ident(&self) -> Option<ast::Name> {
self.pat.as_ref().right().and_then(|param| match param {
ast::Pat::IdentPat(ident) => ident.name(),
self.pat.as_ref().and_then(|param| match param {
Either::Right(ast::Pat::IdentPat(ident)) => ident.name(),
_ => None,
})
}
Expand Down

0 comments on commit 4790916

Please sign in to comment.