diff options
-rw-r--r-- | crates/assists/src/handlers/extract_struct_from_enum_variant.rs | 22 | ||||
-rw-r--r-- | crates/hir/src/code_model.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 13 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlighting.html | 6 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tests.rs | 6 | ||||
-rw-r--r-- | docs/dev/README.md | 2 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 1 |
7 files changed, 39 insertions, 13 deletions
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 48433feb9..178718c5e 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -37,6 +37,12 @@ pub(crate) fn extract_struct_from_enum_variant( | |||
37 | ast::StructKind::Tuple(field_list) => field_list, | 37 | ast::StructKind::Tuple(field_list) => field_list, |
38 | _ => return None, | 38 | _ => return None, |
39 | }; | 39 | }; |
40 | |||
41 | // skip 1-tuple variants | ||
42 | if field_list.fields().count() == 1 { | ||
43 | return None; | ||
44 | } | ||
45 | |||
40 | let variant_name = variant.name()?.to_string(); | 46 | let variant_name = variant.name()?.to_string(); |
41 | let variant_hir = ctx.sema.to_def(&variant)?; | 47 | let variant_hir = ctx.sema.to_def(&variant)?; |
42 | if existing_struct_def(ctx.db(), &variant_name, &variant_hir) { | 48 | if existing_struct_def(ctx.db(), &variant_name, &variant_hir) { |
@@ -233,17 +239,6 @@ enum A { One(One) }"#, | |||
233 | } | 239 | } |
234 | 240 | ||
235 | #[test] | 241 | #[test] |
236 | fn test_extract_struct_one_field() { | ||
237 | check_assist( | ||
238 | extract_struct_from_enum_variant, | ||
239 | "enum A { <|>One(u32) }", | ||
240 | r#"struct One(pub u32); | ||
241 | |||
242 | enum A { One(One) }"#, | ||
243 | ); | ||
244 | } | ||
245 | |||
246 | #[test] | ||
247 | fn test_extract_struct_pub_visibility() { | 242 | fn test_extract_struct_pub_visibility() { |
248 | check_assist( | 243 | check_assist( |
249 | extract_struct_from_enum_variant, | 244 | extract_struct_from_enum_variant, |
@@ -324,4 +319,9 @@ fn another_fn() { | |||
324 | enum A { <|>One(u8) }"#, | 319 | enum A { <|>One(u8) }"#, |
325 | ); | 320 | ); |
326 | } | 321 | } |
322 | |||
323 | #[test] | ||
324 | fn test_extract_not_applicable_one_field() { | ||
325 | check_not_applicable(r"enum A { <|>One(u32) }"); | ||
326 | } | ||
327 | } | 327 | } |
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 63c1a8ebf..563145f92 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -1398,7 +1398,7 @@ impl Type { | |||
1398 | }; | 1398 | }; |
1399 | 1399 | ||
1400 | let canonical_ty = Canonical { value: self.ty.value.clone(), kinds: Arc::new([]) }; | 1400 | let canonical_ty = Canonical { value: self.ty.value.clone(), kinds: Arc::new([]) }; |
1401 | method_resolution::implements_trait( | 1401 | method_resolution::implements_trait_unique( |
1402 | &canonical_ty, | 1402 | &canonical_ty, |
1403 | db, | 1403 | db, |
1404 | self.ty.environment.clone(), | 1404 | self.ty.environment.clone(), |
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 8961df404..5a6f0c67f 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs | |||
@@ -740,6 +740,19 @@ pub fn implements_trait( | |||
740 | solution.is_some() | 740 | solution.is_some() |
741 | } | 741 | } |
742 | 742 | ||
743 | pub fn implements_trait_unique( | ||
744 | ty: &Canonical<Ty>, | ||
745 | db: &dyn HirDatabase, | ||
746 | env: Arc<TraitEnvironment>, | ||
747 | krate: CrateId, | ||
748 | trait_: TraitId, | ||
749 | ) -> bool { | ||
750 | let goal = generic_implements_goal(db, env, trait_, ty.clone()); | ||
751 | let solution = db.trait_solve(krate, goal); | ||
752 | |||
753 | matches!(solution, Some(crate::traits::Solution::Unique(_))) | ||
754 | } | ||
755 | |||
743 | /// This creates Substs for a trait with the given Self type and type variables | 756 | /// This creates Substs for a trait with the given Self type and type variables |
744 | /// for all other parameters, to query Chalk with it. | 757 | /// for all other parameters, to query Chalk with it. |
745 | fn generic_implements_goal( | 758 | fn generic_implements_goal( |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index b0e547d57..5eb222ee2 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html | |||
@@ -119,6 +119,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
119 | <span class="value_param callable">f</span><span class="punctuation">(</span><span class="punctuation">)</span> | 119 | <span class="value_param callable">f</span><span class="punctuation">(</span><span class="punctuation">)</span> |
120 | <span class="punctuation">}</span> | 120 | <span class="punctuation">}</span> |
121 | 121 | ||
122 | <span class="keyword">fn</span> <span class="function declaration">foobar</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="keyword">impl</span> <span class="unresolved_reference">Copy</span> <span class="punctuation">{</span><span class="punctuation">}</span> | ||
123 | |||
124 | <span class="keyword">fn</span> <span class="function declaration">foo</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> | ||
125 | <span class="keyword">let</span> <span class="variable declaration">bar</span> <span class="operator">=</span> <span class="function">foobar</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | ||
126 | <span class="punctuation">}</span> | ||
127 | |||
122 | <span class="macro">macro_rules!</span> <span class="macro declaration">def_fn</span> <span class="punctuation">{</span> | 128 | <span class="macro">macro_rules!</span> <span class="macro declaration">def_fn</span> <span class="punctuation">{</span> |
123 | <span class="punctuation">(</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">:</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">)</span> <span class="operator">=</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">}</span> | 129 | <span class="punctuation">(</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">:</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">)</span> <span class="operator">=</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">}</span> |
124 | <span class="punctuation">}</span> | 130 | <span class="punctuation">}</span> |
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index f13cf3ef3..2b667b0d4 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs | |||
@@ -93,6 +93,12 @@ fn baz<F: Fn() -> ()>(f: F) { | |||
93 | f() | 93 | f() |
94 | } | 94 | } |
95 | 95 | ||
96 | fn foobar() -> impl Copy {} | ||
97 | |||
98 | fn foo() { | ||
99 | let bar = foobar(); | ||
100 | } | ||
101 | |||
96 | macro_rules! def_fn { | 102 | macro_rules! def_fn { |
97 | ($($tt:tt)*) => {$($tt)*} | 103 | ($($tt:tt)*) => {$($tt)*} |
98 | } | 104 | } |
diff --git a/docs/dev/README.md b/docs/dev/README.md index 90e74f226..abb387e8e 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md | |||
@@ -80,7 +80,7 @@ For this, it is important to have the following in your `settings.json` file: | |||
80 | "rust-analyzer.serverPath": "rust-analyzer" | 80 | "rust-analyzer.serverPath": "rust-analyzer" |
81 | } | 81 | } |
82 | ``` | 82 | ``` |
83 | After I am done with the fix, I use `cargo xtask install --client-code` to try the new extension for real. | 83 | After I am done with the fix, I use `cargo xtask install --client` to try the new extension for real. |
84 | 84 | ||
85 | If I need to fix something in the `rust-analyzer` crate, I feel sad because it's on the boundary between the two processes, and working there is slow. | 85 | If I need to fix something in the `rust-analyzer` crate, I feel sad because it's on the boundary between the two processes, and working there is slow. |
86 | I usually just `cargo xtask install --server` and poke changes from my live environment. | 86 | I usually just `cargo xtask install --server` and poke changes from my live environment. |
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index ed0db2924..09f40229b 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts | |||
@@ -60,6 +60,7 @@ function createHintStyle(hintKind: "type" | "parameter" | "chaining") { | |||
60 | color: fg, | 60 | color: fg, |
61 | backgroundColor: bg, | 61 | backgroundColor: bg, |
62 | fontStyle: "normal", | 62 | fontStyle: "normal", |
63 | fontWeight: "normal", | ||
63 | }, | 64 | }, |
64 | }), | 65 | }), |
65 | toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions { | 66 | toDecoration(hint: ra.InlayHint, conv: lc.Protocol2CodeConverter): vscode.DecorationOptions { |