We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f780145 commit f9379dfCopy full SHA for f9379df
crates/ide-db/src/use_trivial_contructor.rs
@@ -0,0 +1,31 @@
1
+use hir::StructKind;
2
+use syntax::ast;
3
+
4
+pub fn use_trivial_constructor(
5
+ db: &crate::RootDatabase,
6
+ path: ast::Path,
7
+ ty: &hir::Type,
8
+) -> Option<ast::Expr> {
9
+ match ty.as_adt() {
10
+ Some(hir::Adt::Enum(x)) => {
11
+ if let &[variant] = &*x.variants(db) {
12
+ if variant.kind(db) == hir::StructKind::Unit {
13
+ let path = ast::make::path_qualified(
14
+ path,
15
+ syntax::ast::make::path_segment(ast::make::name_ref(
16
+ &variant.name(db).to_smol_str(),
17
+ )),
18
+ );
19
20
+ return Some(syntax::ast::make::expr_path(path));
21
+ }
22
23
24
+ Some(hir::Adt::Struct(x)) if x.kind(db) == StructKind::Unit => {
25
26
27
+ _ => {}
28
29
30
+ None
31
+}
0 commit comments