aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
authorSeivan Heidari <[email protected]>2019-11-21 00:11:41 +0000
committerSeivan Heidari <[email protected]>2019-11-21 00:11:41 +0000
commit358a1bcd708c622836723e5201b6de77cc9ff327 (patch)
treeaeff9c96a6059fa2b02e7c87ec88753bc7993d8d /crates/ra_assists
parent1e2d090ab8a9bda18f148b894b7948eb05b976e6 (diff)
parent612a72fc4ea4376920f2a7da7b3c334227c1716c (diff)
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into feature/themes
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/assists/add_missing_impl_members.rs2
-rw-r--r--crates/ra_assists/src/assists/add_new.rs4
-rw-r--r--crates/ra_assists/src/assists/fill_match_arms.rs2
-rw-r--r--crates/ra_assists/src/assists/replace_if_let_with_match.rs32
4 files changed, 34 insertions, 6 deletions
diff --git a/crates/ra_assists/src/assists/add_missing_impl_members.rs b/crates/ra_assists/src/assists/add_missing_impl_members.rs
index 91af161ee..cef669cb5 100644
--- a/crates/ra_assists/src/assists/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs
@@ -174,7 +174,7 @@ fn resolve_target_trait_def(
174 .path()?; 174 .path()?;
175 175
176 match analyzer.resolve_path(db, &ast_path) { 176 match analyzer.resolve_path(db, &ast_path) {
177 Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).ast), 177 Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).value),
178 _ => None, 178 _ => None,
179 } 179 }
180} 180}
diff --git a/crates/ra_assists/src/assists/add_new.rs b/crates/ra_assists/src/assists/add_new.rs
index 2038afdc6..b5f8afb4e 100644
--- a/crates/ra_assists/src/assists/add_new.rs
+++ b/crates/ra_assists/src/assists/add_new.rs
@@ -141,7 +141,7 @@ fn find_struct_impl(
141 })?; 141 })?;
142 142
143 let struct_ty = { 143 let struct_ty = {
144 let src = hir::Source { file_id: ctx.frange.file_id.into(), ast: strukt.clone() }; 144 let src = hir::Source { file_id: ctx.frange.file_id.into(), value: strukt.clone() };
145 hir::Struct::from_source(db, src).unwrap().ty(db) 145 hir::Struct::from_source(db, src).unwrap().ty(db)
146 }; 146 };
147 147
@@ -152,7 +152,7 @@ fn find_struct_impl(
152 return false; 152 return false;
153 } 153 }
154 154
155 let src = hir::Source { file_id: ctx.frange.file_id.into(), ast: impl_blk.clone() }; 155 let src = hir::Source { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() };
156 let blk = hir::ImplBlock::from_source(db, src).unwrap(); 156 let blk = hir::ImplBlock::from_source(db, src).unwrap();
157 157
158 let same_ty = blk.target_ty(db) == struct_ty; 158 let same_ty = blk.target_ty(db) == struct_ty;
diff --git a/crates/ra_assists/src/assists/fill_match_arms.rs b/crates/ra_assists/src/assists/fill_match_arms.rs
index b851c2082..9354466d9 100644
--- a/crates/ra_assists/src/assists/fill_match_arms.rs
+++ b/crates/ra_assists/src/assists/fill_match_arms.rs
@@ -84,7 +84,7 @@ fn resolve_enum_def(
84 let expr_ty = analyzer.type_of(db, &expr)?; 84 let expr_ty = analyzer.type_of(db, &expr)?;
85 85
86 analyzer.autoderef(db, expr_ty).find_map(|ty| match ty.as_adt() { 86 analyzer.autoderef(db, expr_ty).find_map(|ty| match ty.as_adt() {
87 Some((Adt::Enum(e), _)) => Some(e.source(db).ast), 87 Some((Adt::Enum(e), _)) => Some(e.source(db).value),
88 _ => None, 88 _ => None,
89 }) 89 })
90} 90}
diff --git a/crates/ra_assists/src/assists/replace_if_let_with_match.rs b/crates/ra_assists/src/assists/replace_if_let_with_match.rs
index dff84d865..3272801ff 100644
--- a/crates/ra_assists/src/assists/replace_if_let_with_match.rs
+++ b/crates/ra_assists/src/assists/replace_if_let_with_match.rs
@@ -66,8 +66,8 @@ fn build_match_expr(
66 66
67fn format_arm(block: &ast::BlockExpr) -> String { 67fn format_arm(block: &ast::BlockExpr) -> String {
68 match extract_trivial_expression(block) { 68 match extract_trivial_expression(block) {
69 None => block.syntax().text().to_string(), 69 Some(e) if !e.syntax().text().contains_char('\n') => format!("{},", e.syntax().text()),
70 Some(e) => format!("{},", e.syntax().text()), 70 _ => block.syntax().text().to_string(),
71 } 71 }
72} 72}
73 73
@@ -103,6 +103,34 @@ impl VariantData {
103 } 103 }
104 104
105 #[test] 105 #[test]
106 fn test_replace_if_let_with_match_doesnt_unwrap_multiline_expressions() {
107 check_assist(
108 replace_if_let_with_match,
109 "
110fn foo() {
111 if <|>let VariantData::Struct(..) = a {
112 bar(
113 123
114 )
115 } else {
116 false
117 }
118} ",
119 "
120fn foo() {
121 <|>match a {
122 VariantData::Struct(..) => {
123 bar(
124 123
125 )
126 }
127 _ => false,
128 }
129} ",
130 )
131 }
132
133 #[test]
106 fn replace_if_let_with_match_target() { 134 fn replace_if_let_with_match_target() {
107 check_assist_target( 135 check_assist_target(
108 replace_if_let_with_match, 136 replace_if_let_with_match,