diff options
50 files changed, 2014 insertions, 1862 deletions
diff --git a/PRIVACY.md b/PRIVACY.md index 27e39ca60..718fbed12 100644 --- a/PRIVACY.md +++ b/PRIVACY.md | |||
@@ -1,17 +1 @@ | |||
1 | # Privacy Notes | See the [Privacy](https://rust-analyzer.github.io/manual.html#security) section of the user manual. | |
2 | |||
3 | ## LSP server binary | ||
4 | |||
5 | The LSP server performs no network access in itself, but runs `cargo metadata` which will update or download the crate registry and the source code of the project dependencies. | ||
6 | |||
7 | ## Visual Studio Code extension | ||
8 | |||
9 | The Code extension connects to GitHub to download updated LSP binaries and, if the nightly channel is selected, to perform update checks. | ||
10 | |||
11 | ## Other editor plugins | ||
12 | |||
13 | Any other editor plugins that integrate with `rust-analyzer` are not under the control of the `rust-analyzer` developers. For any privacy concerns, you should check with their respective developers. | ||
14 | |||
15 | ## Others | ||
16 | |||
17 | If `cargo check` is enabled (the default), any build scripts or procedural macros used by the project or its dependencies will be executed. This is also the case when `cargo check` is disabled, but build script or procedural macro support is enabled in `rust-analyzer` (on by default). | ||
@@ -27,6 +27,10 @@ If you want to **use** rust-analyzer's language server with your editor of | |||
27 | choice, check [the manual](https://rust-analyzer.github.io/manual.html) folder. | 27 | choice, check [the manual](https://rust-analyzer.github.io/manual.html) folder. |
28 | It also contains some tips & tricks to help you be more productive when using rust-analyzer. | 28 | It also contains some tips & tricks to help you be more productive when using rust-analyzer. |
29 | 29 | ||
30 | ## Security and Privacy | ||
31 | |||
32 | See the corresponding sections of [the manual](https://rust-analyzer.github.io/manual.html#security). | ||
33 | |||
30 | ## Communication | 34 | ## Communication |
31 | 35 | ||
32 | For usage and troubleshooting requests, please use "IDEs and Editors" category of the Rust forum: | 36 | For usage and troubleshooting requests, please use "IDEs and Editors" category of the Rust forum: |
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index 1b17db102..d56b20b83 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs | |||
@@ -9,8 +9,8 @@ use test_utils::{ | |||
9 | use vfs::{file_set::FileSet, VfsPath}; | 9 | use vfs::{file_set::FileSet, VfsPath}; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | input::CrateName, Change, CrateGraph, CrateId, Edition, Env, FileId, FilePosition, FileRange, | 12 | input::CrateName, Change, CrateDisplayName, CrateGraph, CrateId, Edition, Env, FileId, |
13 | SourceDatabaseExt, SourceRoot, SourceRootId, | 13 | FilePosition, FileRange, SourceDatabaseExt, SourceRoot, SourceRootId, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | pub const WORKSPACE: SourceRootId = SourceRootId(0); | 16 | pub const WORKSPACE: SourceRootId = SourceRootId(0); |
@@ -81,7 +81,7 @@ pub struct ChangeFixture { | |||
81 | 81 | ||
82 | impl ChangeFixture { | 82 | impl ChangeFixture { |
83 | pub fn parse(ra_fixture: &str) -> ChangeFixture { | 83 | pub fn parse(ra_fixture: &str) -> ChangeFixture { |
84 | let fixture = Fixture::parse(ra_fixture); | 84 | let (mini_core, fixture) = Fixture::parse(ra_fixture); |
85 | let mut change = Change::new(); | 85 | let mut change = Change::new(); |
86 | 86 | ||
87 | let mut files = Vec::new(); | 87 | let mut files = Vec::new(); |
@@ -166,6 +166,31 @@ impl ChangeFixture { | |||
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | if let Some(mini_core) = mini_core { | ||
170 | let core_file = file_id; | ||
171 | file_id.0 += 1; | ||
172 | |||
173 | let mut fs = FileSet::default(); | ||
174 | fs.insert(core_file, VfsPath::new_virtual_path("/sysroot/core/lib.rs".to_string())); | ||
175 | roots.push(SourceRoot::new_library(fs)); | ||
176 | |||
177 | change.change_file(core_file, Some(Arc::new(mini_core.source_code()))); | ||
178 | |||
179 | let all_crates = crate_graph.crates_in_topological_order(); | ||
180 | |||
181 | let core_crate = crate_graph.add_crate_root( | ||
182 | core_file, | ||
183 | Edition::Edition2021, | ||
184 | Some(CrateDisplayName::from_canonical_name("core".to_string())), | ||
185 | CfgOptions::default(), | ||
186 | Env::default(), | ||
187 | Vec::new(), | ||
188 | ); | ||
189 | |||
190 | for krate in all_crates { | ||
191 | crate_graph.add_dep(krate, CrateName::new("core").unwrap(), core_crate).unwrap(); | ||
192 | } | ||
193 | } | ||
169 | roots.push(SourceRoot::new_local(mem::take(&mut file_set))); | 194 | roots.push(SourceRoot::new_local(mem::take(&mut file_set))); |
170 | change.set_roots(roots); | 195 | change.set_roots(roots); |
171 | change.set_crate_graph(crate_graph); | 196 | change.set_crate_graph(crate_graph); |
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 6fab58f15..fc2c50fb8 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -1992,8 +1992,8 @@ mod tests { | |||
1992 | collector.def_map | 1992 | collector.def_map |
1993 | } | 1993 | } |
1994 | 1994 | ||
1995 | fn do_resolve(code: &str) -> DefMap { | 1995 | fn do_resolve(not_ra_fixture: &str) -> DefMap { |
1996 | let (db, _file_id) = TestDB::with_single_file(code); | 1996 | let (db, _file_id) = TestDB::with_single_file(not_ra_fixture); |
1997 | let krate = db.test_crate(); | 1997 | let krate = db.test_crate(); |
1998 | 1998 | ||
1999 | let edition = db.crate_graph()[krate].edition; | 1999 | let edition = db.crate_graph()[krate].edition; |
@@ -2005,24 +2005,37 @@ mod tests { | |||
2005 | fn test_macro_expand_will_stop_1() { | 2005 | fn test_macro_expand_will_stop_1() { |
2006 | do_resolve( | 2006 | do_resolve( |
2007 | r#" | 2007 | r#" |
2008 | macro_rules! foo { | 2008 | macro_rules! foo { |
2009 | ($($ty:ty)*) => { foo!($($ty)*); } | 2009 | ($($ty:ty)*) => { foo!($($ty)*); } |
2010 | } | 2010 | } |
2011 | foo!(KABOOM); | 2011 | foo!(KABOOM); |
2012 | "#, | 2012 | "#, |
2013 | ); | ||
2014 | do_resolve( | ||
2015 | r#" | ||
2016 | macro_rules! foo { | ||
2017 | ($($ty:ty)*) => { foo!(() $($ty)*); } | ||
2018 | } | ||
2019 | foo!(KABOOM); | ||
2020 | "#, | ||
2013 | ); | 2021 | ); |
2014 | } | 2022 | } |
2015 | 2023 | ||
2016 | #[ignore] // this test does succeed, but takes quite a while :/ | 2024 | #[ignore] |
2017 | #[test] | 2025 | #[test] |
2018 | fn test_macro_expand_will_stop_2() { | 2026 | fn test_macro_expand_will_stop_2() { |
2027 | // FIXME: this test does succeed, but takes quite a while: 90 seconds in | ||
2028 | // the release mode. That's why the argument is not an ra_fixture -- | ||
2029 | // otherwise injection highlighting gets stuck. | ||
2030 | // | ||
2031 | // We need to find a way to fail this faster. | ||
2019 | do_resolve( | 2032 | do_resolve( |
2020 | r#" | 2033 | r#" |
2021 | macro_rules! foo { | 2034 | macro_rules! foo { |
2022 | ($($ty:ty)*) => { foo!($($ty)* $($ty)*); } | 2035 | ($($ty:ty)*) => { foo!($($ty)* $($ty)*); } |
2023 | } | 2036 | } |
2024 | foo!(KABOOM); | 2037 | foo!(KABOOM); |
2025 | "#, | 2038 | "#, |
2026 | ); | 2039 | ); |
2027 | } | 2040 | } |
2028 | } | 2041 | } |
diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs index 71047703d..713b74165 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs | |||
@@ -23,38 +23,29 @@ fn infer_block_expr_type_mismatch() { | |||
23 | fn coerce_places() { | 23 | fn coerce_places() { |
24 | check_infer( | 24 | check_infer( |
25 | r#" | 25 | r#" |
26 | struct S<T> { a: T } | 26 | //- minicore: coerce_unsized |
27 | struct S<T> { a: T } | ||
27 | 28 | ||
28 | fn f<T>(_: &[T]) -> T { loop {} } | 29 | fn f<T>(_: &[T]) -> T { loop {} } |
29 | fn g<T>(_: S<&[T]>) -> T { loop {} } | 30 | fn g<T>(_: S<&[T]>) -> T { loop {} } |
30 | 31 | ||
31 | fn gen<T>() -> *mut [T; 2] { loop {} } | 32 | fn gen<T>() -> *mut [T; 2] { loop {} } |
32 | fn test1<U>() -> *mut [U] { | 33 | fn test1<U>() -> *mut [U] { |
33 | gen() | 34 | gen() |
34 | } | 35 | } |
35 | |||
36 | fn test2() { | ||
37 | let arr: &[u8; 1] = &[1]; | ||
38 | |||
39 | let a: &[_] = arr; | ||
40 | let b = f(arr); | ||
41 | let c: &[_] = { arr }; | ||
42 | let d = g(S { a: arr }); | ||
43 | let e: [&[_]; 1] = [arr]; | ||
44 | let f: [&[_]; 2] = [arr; 2]; | ||
45 | let g: (&[_], &[_]) = (arr, arr); | ||
46 | } | ||
47 | 36 | ||
48 | #[lang = "sized"] | 37 | fn test2() { |
49 | pub trait Sized {} | 38 | let arr: &[u8; 1] = &[1]; |
50 | #[lang = "unsize"] | ||
51 | pub trait Unsize<T: ?Sized> {} | ||
52 | #[lang = "coerce_unsized"] | ||
53 | pub trait CoerceUnsized<T> {} | ||
54 | 39 | ||
55 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} | 40 | let a: &[_] = arr; |
56 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} | 41 | let b = f(arr); |
57 | "#, | 42 | let c: &[_] = { arr }; |
43 | let d = g(S { a: arr }); | ||
44 | let e: [&[_]; 1] = [arr]; | ||
45 | let f: [&[_]; 2] = [arr; 2]; | ||
46 | let g: (&[_], &[_]) = (arr, arr); | ||
47 | } | ||
48 | "#, | ||
58 | expect![[r#" | 49 | expect![[r#" |
59 | 30..31 '_': &[T] | 50 | 30..31 '_': &[T] |
60 | 44..55 '{ loop {} }': T | 51 | 44..55 '{ loop {} }': T |
@@ -131,60 +122,52 @@ fn infer_let_stmt_coerce() { | |||
131 | fn infer_custom_coerce_unsized() { | 122 | fn infer_custom_coerce_unsized() { |
132 | check_infer( | 123 | check_infer( |
133 | r#" | 124 | r#" |
134 | struct A<T: ?Sized>(*const T); | 125 | //- minicore: coerce_unsized |
135 | struct B<T: ?Sized>(*const T); | 126 | use core::{marker::Unsize, ops::CoerceUnsized}; |
136 | struct C<T: ?Sized> { inner: *const T } | ||
137 | 127 | ||
138 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<B<U>> for B<T> {} | 128 | struct A<T: ?Sized>(*const T); |
139 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<C<U>> for C<T> {} | 129 | struct B<T: ?Sized>(*const T); |
130 | struct C<T: ?Sized> { inner: *const T } | ||
140 | 131 | ||
141 | fn foo1<T>(x: A<[T]>) -> A<[T]> { x } | 132 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<B<U>> for B<T> {} |
142 | fn foo2<T>(x: B<[T]>) -> B<[T]> { x } | 133 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<C<U>> for C<T> {} |
143 | fn foo3<T>(x: C<[T]>) -> C<[T]> { x } | ||
144 | 134 | ||
145 | fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) { | 135 | fn foo1<T>(x: A<[T]>) -> A<[T]> { x } |
146 | let d = foo1(a); | 136 | fn foo2<T>(x: B<[T]>) -> B<[T]> { x } |
147 | let e = foo2(b); | 137 | fn foo3<T>(x: C<[T]>) -> C<[T]> { x } |
148 | let f = foo3(c); | ||
149 | } | ||
150 | |||
151 | |||
152 | #[lang = "sized"] | ||
153 | pub trait Sized {} | ||
154 | #[lang = "unsize"] | ||
155 | pub trait Unsize<T: ?Sized> {} | ||
156 | #[lang = "coerce_unsized"] | ||
157 | pub trait CoerceUnsized<T> {} | ||
158 | 138 | ||
159 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} | 139 | fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) { |
160 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} | 140 | let d = foo1(a); |
161 | "#, | 141 | let e = foo2(b); |
142 | let f = foo3(c); | ||
143 | } | ||
144 | "#, | ||
162 | expect![[r#" | 145 | expect![[r#" |
163 | 257..258 'x': A<[T]> | 146 | 306..307 'x': A<[T]> |
164 | 278..283 '{ x }': A<[T]> | 147 | 327..332 '{ x }': A<[T]> |
165 | 280..281 'x': A<[T]> | 148 | 329..330 'x': A<[T]> |
166 | 295..296 'x': B<[T]> | 149 | 344..345 'x': B<[T]> |
167 | 316..321 '{ x }': B<[T]> | 150 | 365..370 '{ x }': B<[T]> |
168 | 318..319 'x': B<[T]> | 151 | 367..368 'x': B<[T]> |
169 | 333..334 'x': C<[T]> | 152 | 382..383 'x': C<[T]> |
170 | 354..359 '{ x }': C<[T]> | 153 | 403..408 '{ x }': C<[T]> |
171 | 356..357 'x': C<[T]> | 154 | 405..406 'x': C<[T]> |
172 | 369..370 'a': A<[u8; 2]> | 155 | 418..419 'a': A<[u8; 2]> |
173 | 384..385 'b': B<[u8; 2]> | 156 | 433..434 'b': B<[u8; 2]> |
174 | 399..400 'c': C<[u8; 2]> | 157 | 448..449 'c': C<[u8; 2]> |
175 | 414..480 '{ ...(c); }': () | 158 | 463..529 '{ ...(c); }': () |
176 | 424..425 'd': A<[{unknown}]> | 159 | 473..474 'd': A<[{unknown}]> |
177 | 428..432 'foo1': fn foo1<{unknown}>(A<[{unknown}]>) -> A<[{unknown}]> | 160 | 477..481 'foo1': fn foo1<{unknown}>(A<[{unknown}]>) -> A<[{unknown}]> |
178 | 428..435 'foo1(a)': A<[{unknown}]> | 161 | 477..484 'foo1(a)': A<[{unknown}]> |
179 | 433..434 'a': A<[u8; 2]> | 162 | 482..483 'a': A<[u8; 2]> |
180 | 445..446 'e': B<[u8]> | 163 | 494..495 'e': B<[u8]> |
181 | 449..453 'foo2': fn foo2<u8>(B<[u8]>) -> B<[u8]> | 164 | 498..502 'foo2': fn foo2<u8>(B<[u8]>) -> B<[u8]> |
182 | 449..456 'foo2(b)': B<[u8]> | 165 | 498..505 'foo2(b)': B<[u8]> |
183 | 454..455 'b': B<[u8; 2]> | 166 | 503..504 'b': B<[u8; 2]> |
184 | 466..467 'f': C<[u8]> | 167 | 515..516 'f': C<[u8]> |
185 | 470..474 'foo3': fn foo3<u8>(C<[u8]>) -> C<[u8]> | 168 | 519..523 'foo3': fn foo3<u8>(C<[u8]>) -> C<[u8]> |
186 | 470..477 'foo3(c)': C<[u8]> | 169 | 519..526 'foo3(c)': C<[u8]> |
187 | 475..476 'c': C<[u8; 2]> | 170 | 524..525 'c': C<[u8; 2]> |
188 | "#]], | 171 | "#]], |
189 | ); | 172 | ); |
190 | } | 173 | } |
@@ -193,21 +176,16 @@ fn infer_custom_coerce_unsized() { | |||
193 | fn infer_if_coerce() { | 176 | fn infer_if_coerce() { |
194 | check_infer( | 177 | check_infer( |
195 | r#" | 178 | r#" |
196 | fn foo<T>(x: &[T]) -> &[T] { loop {} } | 179 | //- minicore: unsize |
197 | fn test() { | 180 | fn foo<T>(x: &[T]) -> &[T] { loop {} } |
198 | let x = if true { | 181 | fn test() { |
199 | foo(&[1]) | 182 | let x = if true { |
200 | } else { | 183 | foo(&[1]) |
201 | &[1] | 184 | } else { |
202 | }; | 185 | &[1] |
203 | } | 186 | }; |
204 | 187 | } | |
205 | 188 | "#, | |
206 | #[lang = "sized"] | ||
207 | pub trait Sized {} | ||
208 | #[lang = "unsize"] | ||
209 | pub trait Unsize<T: ?Sized> {} | ||
210 | "#, | ||
211 | expect![[r#" | 189 | expect![[r#" |
212 | 10..11 'x': &[T] | 190 | 10..11 'x': &[T] |
213 | 27..38 '{ loop {} }': &[T] | 191 | 27..38 '{ loop {} }': &[T] |
@@ -235,25 +213,16 @@ fn infer_if_coerce() { | |||
235 | fn infer_if_else_coerce() { | 213 | fn infer_if_else_coerce() { |
236 | check_infer( | 214 | check_infer( |
237 | r#" | 215 | r#" |
238 | fn foo<T>(x: &[T]) -> &[T] { loop {} } | 216 | //- minicore: coerce_unsized |
239 | fn test() { | 217 | fn foo<T>(x: &[T]) -> &[T] { loop {} } |
240 | let x = if true { | 218 | fn test() { |
241 | &[1] | 219 | let x = if true { |
242 | } else { | 220 | &[1] |
243 | foo(&[1]) | 221 | } else { |
244 | }; | 222 | foo(&[1]) |
245 | } | 223 | }; |
246 | 224 | } | |
247 | #[lang = "sized"] | 225 | "#, |
248 | pub trait Sized {} | ||
249 | #[lang = "unsize"] | ||
250 | pub trait Unsize<T: ?Sized> {} | ||
251 | #[lang = "coerce_unsized"] | ||
252 | pub trait CoerceUnsized<T> {} | ||
253 | |||
254 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} | ||
255 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} | ||
256 | "#, | ||
257 | expect![[r#" | 226 | expect![[r#" |
258 | 10..11 'x': &[T] | 227 | 10..11 'x': &[T] |
259 | 27..38 '{ loop {} }': &[T] | 228 | 27..38 '{ loop {} }': &[T] |
@@ -281,20 +250,16 @@ fn infer_if_else_coerce() { | |||
281 | fn infer_match_first_coerce() { | 250 | fn infer_match_first_coerce() { |
282 | check_infer( | 251 | check_infer( |
283 | r#" | 252 | r#" |
284 | fn foo<T>(x: &[T]) -> &[T] { loop {} } | 253 | //- minicore: unsize |
285 | fn test(i: i32) { | 254 | fn foo<T>(x: &[T]) -> &[T] { loop {} } |
286 | let x = match i { | 255 | fn test(i: i32) { |
287 | 2 => foo(&[2]), | 256 | let x = match i { |
288 | 1 => &[1], | 257 | 2 => foo(&[2]), |
289 | _ => &[3], | 258 | 1 => &[1], |
290 | }; | 259 | _ => &[3], |
291 | } | 260 | }; |
292 | 261 | } | |
293 | #[lang = "sized"] | 262 | "#, |
294 | pub trait Sized {} | ||
295 | #[lang = "unsize"] | ||
296 | pub trait Unsize<T: ?Sized> {} | ||
297 | "#, | ||
298 | expect![[r#" | 263 | expect![[r#" |
299 | 10..11 'x': &[T] | 264 | 10..11 'x': &[T] |
300 | 27..38 '{ loop {} }': &[T] | 265 | 27..38 '{ loop {} }': &[T] |
@@ -329,25 +294,16 @@ fn infer_match_first_coerce() { | |||
329 | fn infer_match_second_coerce() { | 294 | fn infer_match_second_coerce() { |
330 | check_infer( | 295 | check_infer( |
331 | r#" | 296 | r#" |
332 | fn foo<T>(x: &[T]) -> &[T] { loop {} } | 297 | //- minicore: coerce_unsized |
333 | fn test(i: i32) { | 298 | fn foo<T>(x: &[T]) -> &[T] { loop {} } |
334 | let x = match i { | 299 | fn test(i: i32) { |
335 | 1 => &[1], | 300 | let x = match i { |
336 | 2 => foo(&[2]), | 301 | 1 => &[1], |
337 | _ => &[3], | 302 | 2 => foo(&[2]), |
338 | }; | 303 | _ => &[3], |
339 | } | 304 | }; |
340 | 305 | } | |
341 | #[lang = "sized"] | 306 | "#, |
342 | pub trait Sized {} | ||
343 | #[lang = "unsize"] | ||
344 | pub trait Unsize<T: ?Sized> {} | ||
345 | #[lang = "coerce_unsized"] | ||
346 | pub trait CoerceUnsized<T> {} | ||
347 | |||
348 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} | ||
349 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} | ||
350 | "#, | ||
351 | expect![[r#" | 307 | expect![[r#" |
352 | 10..11 'x': &[T] | 308 | 10..11 'x': &[T] |
353 | 27..38 '{ loop {} }': &[T] | 309 | 27..38 '{ loop {} }': &[T] |
@@ -470,15 +426,15 @@ fn coerce_autoderef() { | |||
470 | #[test] | 426 | #[test] |
471 | fn coerce_autoderef_generic() { | 427 | fn coerce_autoderef_generic() { |
472 | check_infer_with_mismatches( | 428 | check_infer_with_mismatches( |
473 | r" | 429 | r#" |
474 | struct Foo; | 430 | struct Foo; |
475 | fn takes_ref<T>(x: &T) -> T { *x } | 431 | fn takes_ref<T>(x: &T) -> T { *x } |
476 | fn test() { | 432 | fn test() { |
477 | takes_ref(&Foo); | 433 | takes_ref(&Foo); |
478 | takes_ref(&&Foo); | 434 | takes_ref(&&Foo); |
479 | takes_ref(&&&Foo); | 435 | takes_ref(&&&Foo); |
480 | } | 436 | } |
481 | ", | 437 | "#, |
482 | expect![[r" | 438 | expect![[r" |
483 | 28..29 'x': &T | 439 | 28..29 'x': &T |
484 | 40..46 '{ *x }': T | 440 | 40..46 '{ *x }': T |
@@ -508,30 +464,29 @@ fn coerce_autoderef_generic() { | |||
508 | fn coerce_autoderef_block() { | 464 | fn coerce_autoderef_block() { |
509 | check_infer_with_mismatches( | 465 | check_infer_with_mismatches( |
510 | r#" | 466 | r#" |
511 | struct String {} | 467 | //- minicore: deref |
512 | #[lang = "deref"] | 468 | struct String {} |
513 | trait Deref { type Target; } | 469 | impl core::ops::Deref for String { type Target = str; } |
514 | impl Deref for String { type Target = str; } | 470 | fn takes_ref_str(x: &str) {} |
515 | fn takes_ref_str(x: &str) {} | 471 | fn returns_string() -> String { loop {} } |
516 | fn returns_string() -> String { loop {} } | 472 | fn test() { |
517 | fn test() { | 473 | takes_ref_str(&{ returns_string() }); |
518 | takes_ref_str(&{ returns_string() }); | 474 | } |
519 | } | 475 | "#, |
520 | "#, | 476 | expect![[r#" |
521 | expect![[r" | 477 | 90..91 'x': &str |
522 | 126..127 'x': &str | 478 | 99..101 '{}': () |
523 | 135..137 '{}': () | 479 | 132..143 '{ loop {} }': String |
524 | 168..179 '{ loop {} }': String | 480 | 134..141 'loop {}': ! |
525 | 170..177 'loop {}': ! | 481 | 139..141 '{}': () |
526 | 175..177 '{}': () | 482 | 154..199 '{ ... }); }': () |
527 | 190..235 '{ ... }); }': () | 483 | 160..173 'takes_ref_str': fn takes_ref_str(&str) |
528 | 196..209 'takes_ref_str': fn takes_ref_str(&str) | 484 | 160..196 'takes_...g() })': () |
529 | 196..232 'takes_...g() })': () | 485 | 174..195 '&{ ret...ng() }': &String |
530 | 210..231 '&{ ret...ng() }': &String | 486 | 175..195 '{ retu...ng() }': String |
531 | 211..231 '{ retu...ng() }': String | 487 | 177..191 'returns_string': fn returns_string() -> String |
532 | 213..227 'returns_string': fn returns_string() -> String | 488 | 177..193 'return...ring()': String |
533 | 213..229 'return...ring()': String | 489 | "#]], |
534 | "]], | ||
535 | ); | 490 | ); |
536 | } | 491 | } |
537 | 492 | ||
@@ -674,25 +629,19 @@ fn coerce_placeholder_ref() { | |||
674 | fn coerce_unsize_array() { | 629 | fn coerce_unsize_array() { |
675 | check_infer_with_mismatches( | 630 | check_infer_with_mismatches( |
676 | r#" | 631 | r#" |
677 | #[lang = "unsize"] | 632 | //- minicore: coerce_unsized |
678 | pub trait Unsize<T> {} | 633 | fn test() { |
679 | #[lang = "coerce_unsized"] | 634 | let f: &[usize] = &[1, 2, 3]; |
680 | pub trait CoerceUnsized<T> {} | 635 | } |
681 | |||
682 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
683 | |||
684 | fn test() { | ||
685 | let f: &[usize] = &[1, 2, 3]; | ||
686 | } | ||
687 | "#, | 636 | "#, |
688 | expect![[r#" | 637 | expect![[r#" |
689 | 161..198 '{ ... 3]; }': () | 638 | 10..47 '{ ... 3]; }': () |
690 | 171..172 'f': &[usize] | 639 | 20..21 'f': &[usize] |
691 | 185..195 '&[1, 2, 3]': &[usize; 3] | 640 | 34..44 '&[1, 2, 3]': &[usize; 3] |
692 | 186..195 '[1, 2, 3]': [usize; 3] | 641 | 35..44 '[1, 2, 3]': [usize; 3] |
693 | 187..188 '1': usize | 642 | 36..37 '1': usize |
694 | 190..191 '2': usize | 643 | 39..40 '2': usize |
695 | 193..194 '3': usize | 644 | 42..43 '3': usize |
696 | "#]], | 645 | "#]], |
697 | ); | 646 | ); |
698 | } | 647 | } |
@@ -701,93 +650,94 @@ fn coerce_unsize_array() { | |||
701 | fn coerce_unsize_trait_object_simple() { | 650 | fn coerce_unsize_trait_object_simple() { |
702 | check_infer_with_mismatches( | 651 | check_infer_with_mismatches( |
703 | r#" | 652 | r#" |
704 | #[lang = "sized"] | 653 | //- minicore: coerce_unsized |
705 | pub trait Sized {} | 654 | trait Foo<T, U> {} |
706 | #[lang = "unsize"] | 655 | trait Bar<U, T, X>: Foo<T, U> {} |
707 | pub trait Unsize<T> {} | 656 | trait Baz<T, X>: Bar<usize, T, X> {} |
708 | #[lang = "coerce_unsized"] | 657 | |
709 | pub trait CoerceUnsized<T> {} | 658 | struct S<T, X>; |
710 | 659 | impl<T, X> Foo<T, usize> for S<T, X> {} | |
711 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | 660 | impl<T, X> Bar<usize, T, X> for S<T, X> {} |
712 | 661 | impl<T, X> Baz<T, X> for S<T, X> {} | |
713 | trait Foo<T, U> {} | 662 | |
714 | trait Bar<U, T, X>: Foo<T, U> {} | 663 | fn test() { |
715 | trait Baz<T, X>: Bar<usize, T, X> {} | 664 | let obj: &dyn Baz<i8, i16> = &S; |
716 | 665 | let obj: &dyn Bar<_, i8, i16> = &S; | |
717 | struct S<T, X>; | 666 | let obj: &dyn Foo<i8, _> = &S; |
718 | impl<T, X> Foo<T, usize> for S<T, X> {} | 667 | } |
719 | impl<T, X> Bar<usize, T, X> for S<T, X> {} | 668 | "#, |
720 | impl<T, X> Baz<T, X> for S<T, X> {} | 669 | expect![[r#" |
721 | 670 | 236..351 '{ ... &S; }': () | |
722 | fn test() { | 671 | 246..249 'obj': &dyn Baz<i8, i16> |
723 | let obj: &dyn Baz<i8, i16> = &S; | 672 | 271..273 '&S': &S<i8, i16> |
724 | let obj: &dyn Bar<_, i8, i16> = &S; | 673 | 272..273 'S': S<i8, i16> |
725 | let obj: &dyn Foo<i8, _> = &S; | 674 | 283..286 'obj': &dyn Bar<usize, i8, i16> |
726 | } | 675 | 311..313 '&S': &S<i8, i16> |
727 | "#, | 676 | 312..313 'S': S<i8, i16> |
728 | expect![[r" | 677 | 323..326 'obj': &dyn Foo<i8, usize> |
729 | 424..539 '{ ... &S; }': () | 678 | 346..348 '&S': &S<i8, {unknown}> |
730 | 434..437 'obj': &dyn Baz<i8, i16> | 679 | 347..348 'S': S<i8, {unknown}> |
731 | 459..461 '&S': &S<i8, i16> | 680 | "#]], |
732 | 460..461 'S': S<i8, i16> | ||
733 | 471..474 'obj': &dyn Bar<usize, i8, i16> | ||
734 | 499..501 '&S': &S<i8, i16> | ||
735 | 500..501 'S': S<i8, i16> | ||
736 | 511..514 'obj': &dyn Foo<i8, usize> | ||
737 | 534..536 '&S': &S<i8, {unknown}> | ||
738 | 535..536 'S': S<i8, {unknown}> | ||
739 | "]], | ||
740 | ); | 681 | ); |
741 | } | 682 | } |
742 | 683 | ||
743 | #[test] | 684 | #[test] |
744 | // The rust reference says this should be possible, but rustc doesn't implement | ||
745 | // it. We used to support it, but Chalk doesn't. | ||
746 | #[ignore] | ||
747 | fn coerce_unsize_trait_object_to_trait_object() { | 685 | fn coerce_unsize_trait_object_to_trait_object() { |
686 | // FIXME: The rust reference says this should be possible, but rustc doesn't | ||
687 | // implement it. We used to support it, but Chalk doesn't. Here's the | ||
688 | // correct expect: | ||
689 | // | ||
690 | // 424..609 '{ ...bj2; }': () | ||
691 | // 434..437 'obj': &dyn Baz<i8, i16> | ||
692 | // 459..461 '&S': &S<i8, i16> | ||
693 | // 460..461 'S': S<i8, i16> | ||
694 | // 471..474 'obj': &dyn Bar<usize, i8, i16> | ||
695 | // 496..499 'obj': &dyn Baz<i8, i16> | ||
696 | // 509..512 'obj': &dyn Foo<i8, usize> | ||
697 | // 531..534 'obj': &dyn Bar<usize, i8, i16> | ||
698 | // 544..548 'obj2': &dyn Baz<i8, i16> | ||
699 | // 570..572 '&S': &S<i8, i16> | ||
700 | // 571..572 'S': S<i8, i16> | ||
701 | // 582..583 '_': &dyn Foo<i8, usize> | ||
702 | // 602..606 'obj2': &dyn Baz<i8, i16> | ||
748 | check_infer_with_mismatches( | 703 | check_infer_with_mismatches( |
749 | r#" | 704 | r#" |
750 | #[lang = "sized"] | 705 | //- minicore: coerce_unsized |
751 | pub trait Sized {} | 706 | trait Foo<T, U> {} |
752 | #[lang = "unsize"] | 707 | trait Bar<U, T, X>: Foo<T, U> {} |
753 | pub trait Unsize<T> {} | 708 | trait Baz<T, X>: Bar<usize, T, X> {} |
754 | #[lang = "coerce_unsized"] | 709 | |
755 | pub trait CoerceUnsized<T> {} | 710 | struct S<T, X>; |
756 | 711 | impl<T, X> Foo<T, usize> for S<T, X> {} | |
757 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | 712 | impl<T, X> Bar<usize, T, X> for S<T, X> {} |
758 | 713 | impl<T, X> Baz<T, X> for S<T, X> {} | |
759 | trait Foo<T, U> {} | 714 | |
760 | trait Bar<U, T, X>: Foo<T, U> {} | 715 | fn test() { |
761 | trait Baz<T, X>: Bar<usize, T, X> {} | 716 | let obj: &dyn Baz<i8, i16> = &S; |
762 | 717 | let obj: &dyn Bar<_, _, _> = obj; | |
763 | struct S<T, X>; | 718 | let obj: &dyn Foo<_, _> = obj; |
764 | impl<T, X> Foo<T, usize> for S<T, X> {} | 719 | let obj2: &dyn Baz<i8, i16> = &S; |
765 | impl<T, X> Bar<usize, T, X> for S<T, X> {} | 720 | let _: &dyn Foo<_, _> = obj2; |
766 | impl<T, X> Baz<T, X> for S<T, X> {} | 721 | } |
767 | 722 | "#, | |
768 | fn test() { | 723 | expect![[r#" |
769 | let obj: &dyn Baz<i8, i16> = &S; | 724 | 236..421 '{ ...bj2; }': () |
770 | let obj: &dyn Bar<_, _, _> = obj; | 725 | 246..249 'obj': &dyn Baz<i8, i16> |
771 | let obj: &dyn Foo<_, _> = obj; | 726 | 271..273 '&S': &S<i8, i16> |
772 | let obj2: &dyn Baz<i8, i16> = &S; | 727 | 272..273 'S': S<i8, i16> |
773 | let _: &dyn Foo<_, _> = obj2; | 728 | 283..286 'obj': &dyn Bar<{unknown}, {unknown}, {unknown}> |
774 | } | 729 | 308..311 'obj': &dyn Baz<i8, i16> |
775 | "#, | 730 | 321..324 'obj': &dyn Foo<{unknown}, {unknown}> |
776 | expect![[r" | 731 | 343..346 'obj': &dyn Bar<{unknown}, {unknown}, {unknown}> |
777 | 424..609 '{ ...bj2; }': () | 732 | 356..360 'obj2': &dyn Baz<i8, i16> |
778 | 434..437 'obj': &dyn Baz<i8, i16> | 733 | 382..384 '&S': &S<i8, i16> |
779 | 459..461 '&S': &S<i8, i16> | 734 | 383..384 'S': S<i8, i16> |
780 | 460..461 'S': S<i8, i16> | 735 | 394..395 '_': &dyn Foo<{unknown}, {unknown}> |
781 | 471..474 'obj': &dyn Bar<usize, i8, i16> | 736 | 414..418 'obj2': &dyn Baz<i8, i16> |
782 | 496..499 'obj': &dyn Baz<i8, i16> | 737 | 308..311: expected &dyn Bar<{unknown}, {unknown}, {unknown}>, got &dyn Baz<i8, i16> |
783 | 509..512 'obj': &dyn Foo<i8, usize> | 738 | 343..346: expected &dyn Foo<{unknown}, {unknown}>, got &dyn Bar<{unknown}, {unknown}, {unknown}> |
784 | 531..534 'obj': &dyn Bar<usize, i8, i16> | 739 | 414..418: expected &dyn Foo<{unknown}, {unknown}>, got &dyn Baz<i8, i16> |
785 | 544..548 'obj2': &dyn Baz<i8, i16> | 740 | "#]], |
786 | 570..572 '&S': &S<i8, i16> | ||
787 | 571..572 'S': S<i8, i16> | ||
788 | 582..583 '_': &dyn Foo<i8, usize> | ||
789 | 602..606 'obj2': &dyn Baz<i8, i16> | ||
790 | "]], | ||
791 | ); | 741 | ); |
792 | } | 742 | } |
793 | 743 | ||
@@ -795,40 +745,32 @@ fn coerce_unsize_trait_object_to_trait_object() { | |||
795 | fn coerce_unsize_super_trait_cycle() { | 745 | fn coerce_unsize_super_trait_cycle() { |
796 | check_infer_with_mismatches( | 746 | check_infer_with_mismatches( |
797 | r#" | 747 | r#" |
798 | #[lang = "sized"] | 748 | //- minicore: coerce_unsized |
799 | pub trait Sized {} | 749 | trait A {} |
800 | #[lang = "unsize"] | 750 | trait B: C + A {} |
801 | pub trait Unsize<T> {} | 751 | trait C: B {} |
802 | #[lang = "coerce_unsized"] | 752 | trait D: C |
803 | pub trait CoerceUnsized<T> {} | 753 | |
804 | 754 | struct S; | |
805 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | 755 | impl A for S {} |
806 | 756 | impl B for S {} | |
807 | trait A {} | 757 | impl C for S {} |
808 | trait B: C + A {} | 758 | impl D for S {} |
809 | trait C: B {} | 759 | |
810 | trait D: C | 760 | fn test() { |
811 | 761 | let obj: &dyn D = &S; | |
812 | struct S; | 762 | let obj: &dyn A = &S; |
813 | impl A for S {} | 763 | } |
814 | impl B for S {} | 764 | "#, |
815 | impl C for S {} | 765 | expect![[r#" |
816 | impl D for S {} | 766 | 140..195 '{ ... &S; }': () |
817 | 767 | 150..153 'obj': &dyn D | |
818 | fn test() { | 768 | 164..166 '&S': &S |
819 | let obj: &dyn D = &S; | 769 | 165..166 'S': S |
820 | let obj: &dyn A = &S; | 770 | 176..179 'obj': &dyn A |
821 | } | 771 | 190..192 '&S': &S |
822 | "#, | 772 | 191..192 'S': S |
823 | expect![[r" | 773 | "#]], |
824 | 328..383 '{ ... &S; }': () | ||
825 | 338..341 'obj': &dyn D | ||
826 | 352..354 '&S': &S | ||
827 | 353..354 'S': S | ||
828 | 364..367 'obj': &dyn A | ||
829 | 378..380 '&S': &S | ||
830 | 379..380 'S': S | ||
831 | "]], | ||
832 | ); | 774 | ); |
833 | } | 775 | } |
834 | 776 | ||
@@ -837,41 +779,35 @@ fn coerce_unsize_generic() { | |||
837 | // FIXME: fix the type mismatches here | 779 | // FIXME: fix the type mismatches here |
838 | check_infer_with_mismatches( | 780 | check_infer_with_mismatches( |
839 | r#" | 781 | r#" |
840 | #[lang = "unsize"] | 782 | //- minicore: coerce_unsized |
841 | pub trait Unsize<T> {} | 783 | struct Foo<T> { t: T }; |
842 | #[lang = "coerce_unsized"] | 784 | struct Bar<T>(Foo<T>); |
843 | pub trait CoerceUnsized<T> {} | ||
844 | |||
845 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
846 | 785 | ||
847 | struct Foo<T> { t: T }; | 786 | fn test() { |
848 | struct Bar<T>(Foo<T>); | 787 | let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] }; |
849 | 788 | let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); | |
850 | fn test() { | 789 | } |
851 | let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] }; | 790 | "#, |
852 | let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); | ||
853 | } | ||
854 | "#, | ||
855 | expect![[r#" | 791 | expect![[r#" |
856 | 209..317 '{ ... }); }': () | 792 | 58..166 '{ ... }); }': () |
857 | 219..220 '_': &Foo<[usize]> | 793 | 68..69 '_': &Foo<[usize]> |
858 | 238..259 '&Foo {..., 3] }': &Foo<[usize]> | 794 | 87..108 '&Foo {..., 3] }': &Foo<[usize]> |
859 | 239..259 'Foo { ..., 3] }': Foo<[usize]> | 795 | 88..108 'Foo { ..., 3] }': Foo<[usize]> |
860 | 248..257 '[1, 2, 3]': [usize; 3] | 796 | 97..106 '[1, 2, 3]': [usize; 3] |
861 | 249..250 '1': usize | 797 | 98..99 '1': usize |
862 | 252..253 '2': usize | 798 | 101..102 '2': usize |
863 | 255..256 '3': usize | 799 | 104..105 '3': usize |
864 | 269..270 '_': &Bar<[usize]> | 800 | 118..119 '_': &Bar<[usize]> |
865 | 288..314 '&Bar(F... 3] })': &Bar<[i32; 3]> | 801 | 137..163 '&Bar(F... 3] })': &Bar<[i32; 3]> |
866 | 289..292 'Bar': Bar<[i32; 3]>(Foo<[i32; 3]>) -> Bar<[i32; 3]> | 802 | 138..141 'Bar': Bar<[i32; 3]>(Foo<[i32; 3]>) -> Bar<[i32; 3]> |
867 | 289..314 'Bar(Fo... 3] })': Bar<[i32; 3]> | 803 | 138..163 'Bar(Fo... 3] })': Bar<[i32; 3]> |
868 | 293..313 'Foo { ..., 3] }': Foo<[i32; 3]> | 804 | 142..162 'Foo { ..., 3] }': Foo<[i32; 3]> |
869 | 302..311 '[1, 2, 3]': [i32; 3] | 805 | 151..160 '[1, 2, 3]': [i32; 3] |
870 | 303..304 '1': i32 | 806 | 152..153 '1': i32 |
871 | 306..307 '2': i32 | 807 | 155..156 '2': i32 |
872 | 309..310 '3': i32 | 808 | 158..159 '3': i32 |
873 | 248..257: expected [usize], got [usize; 3] | 809 | 97..106: expected [usize], got [usize; 3] |
874 | 288..314: expected &Bar<[usize]>, got &Bar<[i32; 3]> | 810 | 137..163: expected &Bar<[usize]>, got &Bar<[i32; 3]> |
875 | "#]], | 811 | "#]], |
876 | ); | 812 | ); |
877 | } | 813 | } |
@@ -881,15 +817,7 @@ fn coerce_unsize_apit() { | |||
881 | // FIXME: #8984 | 817 | // FIXME: #8984 |
882 | check_infer_with_mismatches( | 818 | check_infer_with_mismatches( |
883 | r#" | 819 | r#" |
884 | #[lang = "sized"] | 820 | //- minicore: coerce_unsized |
885 | pub trait Sized {} | ||
886 | #[lang = "unsize"] | ||
887 | pub trait Unsize<T> {} | ||
888 | #[lang = "coerce_unsized"] | ||
889 | pub trait CoerceUnsized<T> {} | ||
890 | |||
891 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
892 | |||
893 | trait Foo {} | 821 | trait Foo {} |
894 | 822 | ||
895 | fn test(f: impl Foo) { | 823 | fn test(f: impl Foo) { |
@@ -897,12 +825,12 @@ fn test(f: impl Foo) { | |||
897 | } | 825 | } |
898 | "#, | 826 | "#, |
899 | expect![[r#" | 827 | expect![[r#" |
900 | 210..211 'f': impl Foo | 828 | 22..23 'f': impl Foo |
901 | 223..252 '{ ... &f; }': () | 829 | 35..64 '{ ... &f; }': () |
902 | 233..234 '_': &dyn Foo | 830 | 45..46 '_': &dyn Foo |
903 | 247..249 '&f': &impl Foo | 831 | 59..61 '&f': &impl Foo |
904 | 248..249 'f': impl Foo | 832 | 60..61 'f': impl Foo |
905 | 247..249: expected &dyn Foo, got &impl Foo | 833 | 59..61: expected &dyn Foo, got &impl Foo |
906 | "#]], | 834 | "#]], |
907 | ); | 835 | ); |
908 | } | 836 | } |
@@ -998,15 +926,7 @@ fn main() { | |||
998 | fn coerce_unsize_expected_type() { | 926 | fn coerce_unsize_expected_type() { |
999 | check_no_mismatches( | 927 | check_no_mismatches( |
1000 | r#" | 928 | r#" |
1001 | #[lang = "sized"] | 929 | //- minicore: coerce_unsized |
1002 | pub trait Sized {} | ||
1003 | #[lang = "unsize"] | ||
1004 | pub trait Unsize<T> {} | ||
1005 | #[lang = "coerce_unsized"] | ||
1006 | pub trait CoerceUnsized<T> {} | ||
1007 | |||
1008 | impl<T: Unsize<U>, U> CoerceUnsized<&U> for &T {} | ||
1009 | |||
1010 | fn main() { | 930 | fn main() { |
1011 | let foo: &[u32] = &[1, 2]; | 931 | let foo: &[u32] = &[1, 2]; |
1012 | let foo: &[u32] = match true { | 932 | let foo: &[u32] = match true { |
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index f26b2c8a7..d9b5ee9cf 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs | |||
@@ -780,10 +780,7 @@ fn test() { (&S).foo(); } | |||
780 | fn method_resolution_unsize_array() { | 780 | fn method_resolution_unsize_array() { |
781 | check_types( | 781 | check_types( |
782 | r#" | 782 | r#" |
783 | #[lang = "slice"] | 783 | //- minicore: slice |
784 | impl<T> [T] { | ||
785 | fn len(&self) -> usize { loop {} } | ||
786 | } | ||
787 | fn test() { | 784 | fn test() { |
788 | let a = [1, 2, 3]; | 785 | let a = [1, 2, 3]; |
789 | a.len(); | 786 | a.len(); |
@@ -1178,11 +1175,7 @@ fn main() { | |||
1178 | fn autoderef_visibility_field() { | 1175 | fn autoderef_visibility_field() { |
1179 | check_infer( | 1176 | check_infer( |
1180 | r#" | 1177 | r#" |
1181 | #[lang = "deref"] | 1178 | //- minicore: deref |
1182 | pub trait Deref { | ||
1183 | type Target; | ||
1184 | fn deref(&self) -> &Self::Target; | ||
1185 | } | ||
1186 | mod a { | 1179 | mod a { |
1187 | pub struct Foo(pub char); | 1180 | pub struct Foo(pub char); |
1188 | pub struct Bar(i32); | 1181 | pub struct Bar(i32); |
@@ -1191,7 +1184,7 @@ mod a { | |||
1191 | Self(0) | 1184 | Self(0) |
1192 | } | 1185 | } |
1193 | } | 1186 | } |
1194 | impl super::Deref for Bar { | 1187 | impl core::ops::Deref for Bar { |
1195 | type Target = Foo; | 1188 | type Target = Foo; |
1196 | fn deref(&self) -> &Foo { | 1189 | fn deref(&self) -> &Foo { |
1197 | &Foo('z') | 1190 | &Foo('z') |
@@ -1205,22 +1198,21 @@ mod b { | |||
1205 | } | 1198 | } |
1206 | "#, | 1199 | "#, |
1207 | expect![[r#" | 1200 | expect![[r#" |
1208 | 67..71 'self': &Self | 1201 | 107..138 '{ ... }': Bar |
1209 | 200..231 '{ ... }': Bar | 1202 | 121..125 'Self': Bar(i32) -> Bar |
1210 | 214..218 'Self': Bar(i32) -> Bar | 1203 | 121..128 'Self(0)': Bar |
1211 | 214..221 'Self(0)': Bar | 1204 | 126..127 '0': i32 |
1212 | 219..220 '0': i32 | 1205 | 226..230 'self': &Bar |
1213 | 315..319 'self': &Bar | 1206 | 240..273 '{ ... }': &Foo |
1214 | 329..362 '{ ... }': &Foo | 1207 | 254..263 '&Foo('z')': &Foo |
1215 | 343..352 '&Foo('z')': &Foo | 1208 | 255..258 'Foo': Foo(char) -> Foo |
1216 | 344..347 'Foo': Foo(char) -> Foo | 1209 | 255..263 'Foo('z')': Foo |
1217 | 344..352 'Foo('z')': Foo | 1210 | 259..262 ''z'': char |
1218 | 348..351 ''z'': char | 1211 | 303..350 '{ ... }': () |
1219 | 392..439 '{ ... }': () | 1212 | 317..318 'x': char |
1220 | 406..407 'x': char | 1213 | 321..339 'super:...r::new': fn new() -> Bar |
1221 | 410..428 'super:...r::new': fn new() -> Bar | 1214 | 321..341 'super:...:new()': Bar |
1222 | 410..430 'super:...:new()': Bar | 1215 | 321..343 'super:...ew().0': char |
1223 | 410..432 'super:...ew().0': char | ||
1224 | "#]], | 1216 | "#]], |
1225 | ) | 1217 | ) |
1226 | } | 1218 | } |
@@ -1230,11 +1222,7 @@ fn autoderef_visibility_method() { | |||
1230 | cov_mark::check!(autoderef_candidate_not_visible); | 1222 | cov_mark::check!(autoderef_candidate_not_visible); |
1231 | check_infer( | 1223 | check_infer( |
1232 | r#" | 1224 | r#" |
1233 | #[lang = "deref"] | 1225 | //- minicore: deref |
1234 | pub trait Deref { | ||
1235 | type Target; | ||
1236 | fn deref(&self) -> &Self::Target; | ||
1237 | } | ||
1238 | mod a { | 1226 | mod a { |
1239 | pub struct Foo(pub char); | 1227 | pub struct Foo(pub char); |
1240 | impl Foo { | 1228 | impl Foo { |
@@ -1251,7 +1239,7 @@ mod a { | |||
1251 | self.0 | 1239 | self.0 |
1252 | } | 1240 | } |
1253 | } | 1241 | } |
1254 | impl super::Deref for Bar { | 1242 | impl core::ops::Deref for Bar { |
1255 | type Target = Foo; | 1243 | type Target = Foo; |
1256 | fn deref(&self) -> &Foo { | 1244 | fn deref(&self) -> &Foo { |
1257 | &Foo('z') | 1245 | &Foo('z') |
@@ -1265,30 +1253,29 @@ mod b { | |||
1265 | } | 1253 | } |
1266 | "#, | 1254 | "#, |
1267 | expect![[r#" | 1255 | expect![[r#" |
1268 | 67..71 'self': &Self | 1256 | 75..79 'self': &Foo |
1269 | 168..172 'self': &Foo | 1257 | 89..119 '{ ... }': char |
1270 | 182..212 '{ ... }': char | 1258 | 103..107 'self': &Foo |
1271 | 196..200 'self': &Foo | 1259 | 103..109 'self.0': char |
1272 | 196..202 'self.0': char | 1260 | 195..226 '{ ... }': Bar |
1273 | 288..319 '{ ... }': Bar | 1261 | 209..213 'Self': Bar(i32) -> Bar |
1274 | 302..306 'Self': Bar(i32) -> Bar | 1262 | 209..216 'Self(0)': Bar |
1275 | 302..309 'Self(0)': Bar | 1263 | 214..215 '0': i32 |
1276 | 307..308 '0': i32 | 1264 | 245..249 'self': &Bar |
1277 | 338..342 'self': &Bar | 1265 | 258..288 '{ ... }': i32 |
1278 | 351..381 '{ ... }': i32 | 1266 | 272..276 'self': &Bar |
1279 | 365..369 'self': &Bar | 1267 | 272..278 'self.0': i32 |
1280 | 365..371 'self.0': i32 | 1268 | 376..380 'self': &Bar |
1281 | 465..469 'self': &Bar | 1269 | 390..423 '{ ... }': &Foo |
1282 | 479..512 '{ ... }': &Foo | 1270 | 404..413 '&Foo('z')': &Foo |
1283 | 493..502 '&Foo('z')': &Foo | 1271 | 405..408 'Foo': Foo(char) -> Foo |
1284 | 494..497 'Foo': Foo(char) -> Foo | 1272 | 405..413 'Foo('z')': Foo |
1285 | 494..502 'Foo('z')': Foo | 1273 | 409..412 ''z'': char |
1286 | 498..501 ''z'': char | 1274 | 453..506 '{ ... }': () |
1287 | 542..595 '{ ... }': () | 1275 | 467..468 'x': char |
1288 | 556..557 'x': char | 1276 | 471..489 'super:...r::new': fn new() -> Bar |
1289 | 560..578 'super:...r::new': fn new() -> Bar | 1277 | 471..491 'super:...:new()': Bar |
1290 | 560..580 'super:...:new()': Bar | 1278 | 471..499 'super:...ango()': char |
1291 | 560..588 'super:...ango()': char | ||
1292 | "#]], | 1279 | "#]], |
1293 | ) | 1280 | ) |
1294 | } | 1281 | } |
diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 1019e783b..abd9c385a 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs | |||
@@ -927,35 +927,33 @@ fn issue_6628() { | |||
927 | fn issue_6852() { | 927 | fn issue_6852() { |
928 | check_infer( | 928 | check_infer( |
929 | r#" | 929 | r#" |
930 | #[lang = "deref"] | 930 | //- minicore: deref |
931 | pub trait Deref { | 931 | use core::ops::Deref; |
932 | type Target; | ||
933 | } | ||
934 | 932 | ||
935 | struct BufWriter {} | 933 | struct BufWriter {} |
936 | 934 | ||
937 | struct Mutex<T> {} | 935 | struct Mutex<T> {} |
938 | struct MutexGuard<'a, T> {} | 936 | struct MutexGuard<'a, T> {} |
939 | impl<T> Mutex<T> { | 937 | impl<T> Mutex<T> { |
940 | fn lock(&self) -> MutexGuard<'_, T> {} | 938 | fn lock(&self) -> MutexGuard<'_, T> {} |
941 | } | 939 | } |
942 | impl<'a, T: 'a> Deref for MutexGuard<'a, T> { | 940 | impl<'a, T: 'a> Deref for MutexGuard<'a, T> { |
943 | type Target = T; | 941 | type Target = T; |
944 | } | 942 | } |
945 | fn flush(&self) { | 943 | fn flush(&self) { |
946 | let w: &Mutex<BufWriter>; | 944 | let w: &Mutex<BufWriter>; |
947 | *(w.lock()); | 945 | *(w.lock()); |
948 | } | 946 | } |
949 | "#, | 947 | "#, |
950 | expect![[r#" | 948 | expect![[r#" |
951 | 156..160 'self': &Mutex<T> | 949 | 123..127 'self': &Mutex<T> |
952 | 183..185 '{}': () | 950 | 150..152 '{}': () |
953 | 267..271 'self': &{unknown} | 951 | 234..238 'self': &{unknown} |
954 | 273..323 '{ ...()); }': () | 952 | 240..290 '{ ...()); }': () |
955 | 283..284 'w': &Mutex<BufWriter> | 953 | 250..251 'w': &Mutex<BufWriter> |
956 | 309..320 '*(w.lock())': BufWriter | 954 | 276..287 '*(w.lock())': BufWriter |
957 | 311..312 'w': &Mutex<BufWriter> | 955 | 278..279 'w': &Mutex<BufWriter> |
958 | 311..319 'w.lock()': MutexGuard<BufWriter> | 956 | 278..286 'w.lock()': MutexGuard<BufWriter> |
959 | "#]], | 957 | "#]], |
960 | ); | 958 | ); |
961 | } | 959 | } |
@@ -977,37 +975,33 @@ fn param_overrides_fn() { | |||
977 | fn lifetime_from_chalk_during_deref() { | 975 | fn lifetime_from_chalk_during_deref() { |
978 | check_types( | 976 | check_types( |
979 | r#" | 977 | r#" |
980 | #[lang = "deref"] | 978 | //- minicore: deref |
981 | pub trait Deref { | 979 | struct Box<T: ?Sized> {} |
982 | type Target; | 980 | impl<T> core::ops::Deref for Box<T> { |
983 | } | 981 | type Target = T; |
984 | |||
985 | struct Box<T: ?Sized> {} | ||
986 | impl<T> Deref for Box<T> { | ||
987 | type Target = T; | ||
988 | 982 | ||
989 | fn deref(&self) -> &Self::Target { | 983 | fn deref(&self) -> &Self::Target { |
990 | loop {} | 984 | loop {} |
991 | } | 985 | } |
992 | } | 986 | } |
993 | 987 | ||
994 | trait Iterator { | 988 | trait Iterator { |
995 | type Item; | 989 | type Item; |
996 | } | 990 | } |
997 | 991 | ||
998 | pub struct Iter<'a, T: 'a> { | 992 | pub struct Iter<'a, T: 'a> { |
999 | inner: Box<dyn IterTrait<'a, T, Item = &'a T> + 'a>, | 993 | inner: Box<dyn IterTrait<'a, T, Item = &'a T> + 'a>, |
1000 | } | 994 | } |
1001 | 995 | ||
1002 | trait IterTrait<'a, T: 'a>: Iterator<Item = &'a T> { | 996 | trait IterTrait<'a, T: 'a>: Iterator<Item = &'a T> { |
1003 | fn clone_box(&self); | 997 | fn clone_box(&self); |
1004 | } | 998 | } |
1005 | 999 | ||
1006 | fn clone_iter<T>(s: Iter<T>) { | 1000 | fn clone_iter<T>(s: Iter<T>) { |
1007 | s.inner.clone_box(); | 1001 | s.inner.clone_box(); |
1008 | //^^^^^^^^^^^^^^^^^^^ () | 1002 | //^^^^^^^^^^^^^^^^^^^ () |
1009 | } | 1003 | } |
1010 | "#, | 1004 | "#, |
1011 | ) | 1005 | ) |
1012 | } | 1006 | } |
1013 | 1007 | ||
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index 3418ed21e..68776f3c0 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs | |||
@@ -113,7 +113,7 @@ fn type_alias_in_struct_lit() { | |||
113 | fn infer_ranges() { | 113 | fn infer_ranges() { |
114 | check_types( | 114 | check_types( |
115 | r#" | 115 | r#" |
116 | //- /main.rs crate:main deps:core | 116 | //- minicore: range |
117 | fn test() { | 117 | fn test() { |
118 | let a = ..; | 118 | let a = ..; |
119 | let b = 1..; | 119 | let b = 1..; |
@@ -125,32 +125,6 @@ fn test() { | |||
125 | let t = (a, b, c, d, e, f); | 125 | let t = (a, b, c, d, e, f); |
126 | t; | 126 | t; |
127 | } //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>) | 127 | } //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>) |
128 | |||
129 | //- /core.rs crate:core | ||
130 | #[prelude_import] use prelude::*; | ||
131 | mod prelude {} | ||
132 | |||
133 | pub mod ops { | ||
134 | pub struct Range<Idx> { | ||
135 | pub start: Idx, | ||
136 | pub end: Idx, | ||
137 | } | ||
138 | pub struct RangeFrom<Idx> { | ||
139 | pub start: Idx, | ||
140 | } | ||
141 | struct RangeFull; | ||
142 | pub struct RangeInclusive<Idx> { | ||
143 | start: Idx, | ||
144 | end: Idx, | ||
145 | is_empty: u8, | ||
146 | } | ||
147 | pub struct RangeTo<Idx> { | ||
148 | pub end: Idx, | ||
149 | } | ||
150 | pub struct RangeToInclusive<Idx> { | ||
151 | pub end: Idx, | ||
152 | } | ||
153 | } | ||
154 | "#, | 128 | "#, |
155 | ); | 129 | ); |
156 | } | 130 | } |
@@ -175,16 +149,17 @@ fn test() { | |||
175 | fn infer_basics() { | 149 | fn infer_basics() { |
176 | check_infer( | 150 | check_infer( |
177 | r#" | 151 | r#" |
178 | fn test(a: u32, b: isize, c: !, d: &str) { | 152 | fn test(a: u32, b: isize, c: !, d: &str) { |
179 | a; | 153 | a; |
180 | b; | 154 | b; |
181 | c; | 155 | c; |
182 | d; | 156 | d; |
183 | 1usize; | 157 | 1usize; |
184 | 1isize; | 158 | 1isize; |
185 | "test"; | 159 | "test"; |
186 | 1.0f32; | 160 | 1.0f32; |
187 | }"#, | 161 | } |
162 | "#, | ||
188 | expect![[r#" | 163 | expect![[r#" |
189 | 8..9 'a': u32 | 164 | 8..9 'a': u32 |
190 | 16..17 'b': isize | 165 | 16..17 'b': isize |
@@ -207,15 +182,15 @@ fn infer_basics() { | |||
207 | fn infer_let() { | 182 | fn infer_let() { |
208 | check_infer( | 183 | check_infer( |
209 | r#" | 184 | r#" |
210 | fn test() { | 185 | fn test() { |
211 | let a = 1isize; | 186 | let a = 1isize; |
212 | let b: usize = 1; | 187 | let b: usize = 1; |
213 | let c = b; | 188 | let c = b; |
214 | let d: u32; | 189 | let d: u32; |
215 | let e; | 190 | let e; |
216 | let f: i32 = e; | 191 | let f: i32 = e; |
217 | } | 192 | } |
218 | "#, | 193 | "#, |
219 | expect![[r#" | 194 | expect![[r#" |
220 | 10..117 '{ ...= e; }': () | 195 | 10..117 '{ ...= e; }': () |
221 | 20..21 'a': isize | 196 | 20..21 'a': isize |
@@ -236,17 +211,17 @@ fn infer_let() { | |||
236 | fn infer_paths() { | 211 | fn infer_paths() { |
237 | check_infer( | 212 | check_infer( |
238 | r#" | 213 | r#" |
239 | fn a() -> u32 { 1 } | 214 | fn a() -> u32 { 1 } |
240 | 215 | ||
241 | mod b { | 216 | mod b { |
242 | fn c() -> u32 { 1 } | 217 | fn c() -> u32 { 1 } |
243 | } | 218 | } |
244 | 219 | ||
245 | fn test() { | 220 | fn test() { |
246 | a(); | 221 | a(); |
247 | b::c(); | 222 | b::c(); |
248 | } | 223 | } |
249 | "#, | 224 | "#, |
250 | expect![[r#" | 225 | expect![[r#" |
251 | 14..19 '{ 1 }': u32 | 226 | 14..19 '{ 1 }': u32 |
252 | 16..17 '1': u32 | 227 | 16..17 '1': u32 |
@@ -265,17 +240,17 @@ fn infer_paths() { | |||
265 | fn infer_path_type() { | 240 | fn infer_path_type() { |
266 | check_infer( | 241 | check_infer( |
267 | r#" | 242 | r#" |
268 | struct S; | 243 | struct S; |
269 | 244 | ||
270 | impl S { | 245 | impl S { |
271 | fn foo() -> i32 { 1 } | 246 | fn foo() -> i32 { 1 } |
272 | } | 247 | } |
273 | 248 | ||
274 | fn test() { | 249 | fn test() { |
275 | S::foo(); | 250 | S::foo(); |
276 | <S>::foo(); | 251 | <S>::foo(); |
277 | } | 252 | } |
278 | "#, | 253 | "#, |
279 | expect![[r#" | 254 | expect![[r#" |
280 | 40..45 '{ 1 }': i32 | 255 | 40..45 '{ 1 }': i32 |
281 | 42..43 '1': i32 | 256 | 42..43 '1': i32 |
@@ -292,21 +267,21 @@ fn infer_path_type() { | |||
292 | fn infer_struct() { | 267 | fn infer_struct() { |
293 | check_infer( | 268 | check_infer( |
294 | r#" | 269 | r#" |
295 | struct A { | 270 | struct A { |
296 | b: B, | 271 | b: B, |
297 | c: C, | 272 | c: C, |
298 | } | 273 | } |
299 | struct B; | 274 | struct B; |
300 | struct C(usize); | 275 | struct C(usize); |
301 | 276 | ||
302 | fn test() { | 277 | fn test() { |
303 | let c = C(1); | 278 | let c = C(1); |
304 | B; | 279 | B; |
305 | let a: A = A { b: B, c: C(1) }; | 280 | let a: A = A { b: B, c: C(1) }; |
306 | a.b; | 281 | a.b; |
307 | a.c; | 282 | a.c; |
308 | } | 283 | } |
309 | "#, | 284 | "#, |
310 | expect![[r#" | 285 | expect![[r#" |
311 | 71..153 '{ ...a.c; }': () | 286 | 71..153 '{ ...a.c; }': () |
312 | 81..82 'c': C | 287 | 81..82 'c': C |
@@ -332,14 +307,15 @@ fn infer_struct() { | |||
332 | fn infer_enum() { | 307 | fn infer_enum() { |
333 | check_infer( | 308 | check_infer( |
334 | r#" | 309 | r#" |
335 | enum E { | 310 | enum E { |
336 | V1 { field: u32 }, | 311 | V1 { field: u32 }, |
337 | V2 | 312 | V2 |
338 | } | 313 | } |
339 | fn test() { | 314 | fn test() { |
340 | E::V1 { field: 1 }; | 315 | E::V1 { field: 1 }; |
341 | E::V2; | 316 | E::V2; |
342 | }"#, | 317 | } |
318 | "#, | ||
343 | expect![[r#" | 319 | expect![[r#" |
344 | 51..89 '{ ...:V2; }': () | 320 | 51..89 '{ ...:V2; }': () |
345 | 57..75 'E::V1 ...d: 1 }': E | 321 | 57..75 'E::V1 ...d: 1 }': E |
@@ -353,23 +329,23 @@ fn infer_enum() { | |||
353 | fn infer_union() { | 329 | fn infer_union() { |
354 | check_infer( | 330 | check_infer( |
355 | r#" | 331 | r#" |
356 | union MyUnion { | 332 | union MyUnion { |
357 | foo: u32, | 333 | foo: u32, |
358 | bar: f32, | 334 | bar: f32, |
359 | } | 335 | } |
360 | 336 | ||
361 | fn test() { | 337 | fn test() { |
362 | let u = MyUnion { foo: 0 }; | 338 | let u = MyUnion { foo: 0 }; |
363 | unsafe { baz(u); } | 339 | unsafe { baz(u); } |
364 | let u = MyUnion { bar: 0.0 }; | 340 | let u = MyUnion { bar: 0.0 }; |
365 | unsafe { baz(u); } | 341 | unsafe { baz(u); } |
366 | } | 342 | } |
367 | 343 | ||
368 | unsafe fn baz(u: MyUnion) { | 344 | unsafe fn baz(u: MyUnion) { |
369 | let inner = u.foo; | 345 | let inner = u.foo; |
370 | let inner = u.bar; | 346 | let inner = u.bar; |
371 | } | 347 | } |
372 | "#, | 348 | "#, |
373 | expect![[r#" | 349 | expect![[r#" |
374 | 57..172 '{ ...); } }': () | 350 | 57..172 '{ ...); } }': () |
375 | 67..68 'u': MyUnion | 351 | 67..68 'u': MyUnion |
@@ -404,19 +380,19 @@ fn infer_union() { | |||
404 | fn infer_refs() { | 380 | fn infer_refs() { |
405 | check_infer( | 381 | check_infer( |
406 | r#" | 382 | r#" |
407 | fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { | 383 | fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) { |
408 | a; | 384 | a; |
409 | *a; | 385 | *a; |
410 | &a; | 386 | &a; |
411 | &mut a; | 387 | &mut a; |
412 | b; | 388 | b; |
413 | *b; | 389 | *b; |
414 | &b; | 390 | &b; |
415 | c; | 391 | c; |
416 | *c; | 392 | *c; |
417 | d; | 393 | d; |
418 | *d; | 394 | *d; |
419 | } | 395 | } |
420 | "#, | 396 | "#, |
421 | expect![[r#" | 397 | expect![[r#" |
422 | 8..9 'a': &u32 | 398 | 8..9 'a': &u32 |
@@ -450,11 +426,11 @@ fn infer_refs() { | |||
450 | fn infer_raw_ref() { | 426 | fn infer_raw_ref() { |
451 | check_infer( | 427 | check_infer( |
452 | r#" | 428 | r#" |
453 | fn test(a: i32) { | 429 | fn test(a: i32) { |
454 | &raw mut a; | 430 | &raw mut a; |
455 | &raw const a; | 431 | &raw const a; |
456 | } | 432 | } |
457 | "#, | 433 | "#, |
458 | expect![[r#" | 434 | expect![[r#" |
459 | 8..9 'a': i32 | 435 | 8..9 'a': i32 |
460 | 16..53 '{ ...t a; }': () | 436 | 16..53 '{ ...t a; }': () |
@@ -524,26 +500,26 @@ h"; | |||
524 | fn infer_unary_op() { | 500 | fn infer_unary_op() { |
525 | check_infer( | 501 | check_infer( |
526 | r#" | 502 | r#" |
527 | enum SomeType {} | 503 | enum SomeType {} |
528 | 504 | ||
529 | fn test(x: SomeType) { | 505 | fn test(x: SomeType) { |
530 | let b = false; | 506 | let b = false; |
531 | let c = !b; | 507 | let c = !b; |
532 | let a = 100; | 508 | let a = 100; |
533 | let d: i128 = -a; | 509 | let d: i128 = -a; |
534 | let e = -100; | 510 | let e = -100; |
535 | let f = !!!true; | 511 | let f = !!!true; |
536 | let g = !42; | 512 | let g = !42; |
537 | let h = !10u32; | 513 | let h = !10u32; |
538 | let j = !a; | 514 | let j = !a; |
539 | -3.14; | 515 | -3.14; |
540 | !3; | 516 | !3; |
541 | -x; | 517 | -x; |
542 | !x; | 518 | !x; |
543 | -"hello"; | 519 | -"hello"; |
544 | !"hello"; | 520 | !"hello"; |
545 | } | 521 | } |
546 | "#, | 522 | "#, |
547 | expect![[r#" | 523 | expect![[r#" |
548 | 26..27 'x': SomeType | 524 | 26..27 'x': SomeType |
549 | 39..271 '{ ...lo"; }': () | 525 | 39..271 '{ ...lo"; }': () |
@@ -594,19 +570,19 @@ fn infer_unary_op() { | |||
594 | fn infer_backwards() { | 570 | fn infer_backwards() { |
595 | check_infer( | 571 | check_infer( |
596 | r#" | 572 | r#" |
597 | fn takes_u32(x: u32) {} | 573 | fn takes_u32(x: u32) {} |
598 | 574 | ||
599 | struct S { i32_field: i32 } | 575 | struct S { i32_field: i32 } |
600 | 576 | ||
601 | fn test() -> &mut &f64 { | 577 | fn test() -> &mut &f64 { |
602 | let a = unknown_function(); | 578 | let a = unknown_function(); |
603 | takes_u32(a); | 579 | takes_u32(a); |
604 | let b = unknown_function(); | 580 | let b = unknown_function(); |
605 | S { i32_field: b }; | 581 | S { i32_field: b }; |
606 | let c = unknown_function(); | 582 | let c = unknown_function(); |
607 | &mut &c | 583 | &mut &c |
608 | } | 584 | } |
609 | "#, | 585 | "#, |
610 | expect![[r#" | 586 | expect![[r#" |
611 | 13..14 'x': u32 | 587 | 13..14 'x': u32 |
612 | 21..23 '{}': () | 588 | 21..23 '{}': () |
@@ -636,23 +612,23 @@ fn infer_backwards() { | |||
636 | fn infer_self() { | 612 | fn infer_self() { |
637 | check_infer( | 613 | check_infer( |
638 | r#" | 614 | r#" |
639 | struct S; | 615 | struct S; |
640 | 616 | ||
641 | impl S { | 617 | impl S { |
642 | fn test(&self) { | 618 | fn test(&self) { |
643 | self; | 619 | self; |
644 | } | 620 | } |
645 | fn test2(self: &Self) { | 621 | fn test2(self: &Self) { |
646 | self; | 622 | self; |
647 | } | 623 | } |
648 | fn test3() -> Self { | 624 | fn test3() -> Self { |
649 | S {} | 625 | S {} |
650 | } | 626 | } |
651 | fn test4() -> Self { | 627 | fn test4() -> Self { |
652 | Self {} | 628 | Self {} |
653 | } | 629 | } |
654 | } | 630 | } |
655 | "#, | 631 | "#, |
656 | expect![[r#" | 632 | expect![[r#" |
657 | 33..37 'self': &S | 633 | 33..37 'self': &S |
658 | 39..60 '{ ... }': () | 634 | 39..60 '{ ... }': () |
@@ -672,30 +648,30 @@ fn infer_self() { | |||
672 | fn infer_self_as_path() { | 648 | fn infer_self_as_path() { |
673 | check_infer( | 649 | check_infer( |
674 | r#" | 650 | r#" |
675 | struct S1; | 651 | struct S1; |
676 | struct S2(isize); | 652 | struct S2(isize); |
677 | enum E { | 653 | enum E { |
678 | V1, | 654 | V1, |
679 | V2(u32), | 655 | V2(u32), |
680 | } | 656 | } |
681 | 657 | ||
682 | impl S1 { | 658 | impl S1 { |
683 | fn test() { | 659 | fn test() { |
684 | Self; | 660 | Self; |
685 | } | 661 | } |
686 | } | 662 | } |
687 | impl S2 { | 663 | impl S2 { |
688 | fn test() { | 664 | fn test() { |
689 | Self(1); | 665 | Self(1); |
690 | } | 666 | } |
691 | } | 667 | } |
692 | impl E { | 668 | impl E { |
693 | fn test() { | 669 | fn test() { |
694 | Self::V1; | 670 | Self::V1; |
695 | Self::V2(1); | 671 | Self::V2(1); |
696 | } | 672 | } |
697 | } | 673 | } |
698 | "#, | 674 | "#, |
699 | expect![[r#" | 675 | expect![[r#" |
700 | 86..107 '{ ... }': () | 676 | 86..107 '{ ... }': () |
701 | 96..100 'Self': S1 | 677 | 96..100 'Self': S1 |
@@ -716,26 +692,26 @@ fn infer_self_as_path() { | |||
716 | fn infer_binary_op() { | 692 | fn infer_binary_op() { |
717 | check_infer( | 693 | check_infer( |
718 | r#" | 694 | r#" |
719 | fn f(x: bool) -> i32 { | 695 | fn f(x: bool) -> i32 { |
720 | 0i32 | 696 | 0i32 |
721 | } | 697 | } |
722 | 698 | ||
723 | fn test() -> bool { | 699 | fn test() -> bool { |
724 | let x = a && b; | 700 | let x = a && b; |
725 | let y = true || false; | 701 | let y = true || false; |
726 | let z = x == y; | 702 | let z = x == y; |
727 | let t = x != y; | 703 | let t = x != y; |
728 | let minus_forty: isize = -40isize; | 704 | let minus_forty: isize = -40isize; |
729 | let h = minus_forty <= CONST_2; | 705 | let h = minus_forty <= CONST_2; |
730 | let c = f(z || y) + 5; | 706 | let c = f(z || y) + 5; |
731 | let d = b; | 707 | let d = b; |
732 | let g = minus_forty ^= i; | 708 | let g = minus_forty ^= i; |
733 | let ten: usize = 10; | 709 | let ten: usize = 10; |
734 | let ten_is_eleven = ten == some_num; | 710 | let ten_is_eleven = ten == some_num; |
735 | 711 | ||
736 | ten < 3 | 712 | ten < 3 |
737 | } | 713 | } |
738 | "#, | 714 | "#, |
739 | expect![[r#" | 715 | expect![[r#" |
740 | 5..6 'x': bool | 716 | 5..6 'x': bool |
741 | 21..33 '{ 0i32 }': i32 | 717 | 21..33 '{ 0i32 }': i32 |
@@ -795,11 +771,11 @@ fn infer_binary_op() { | |||
795 | fn infer_shift_op() { | 771 | fn infer_shift_op() { |
796 | check_infer( | 772 | check_infer( |
797 | r#" | 773 | r#" |
798 | fn test() { | 774 | fn test() { |
799 | 1u32 << 5u8; | 775 | 1u32 << 5u8; |
800 | 1u32 >> 5u8; | 776 | 1u32 >> 5u8; |
801 | } | 777 | } |
802 | "#, | 778 | "#, |
803 | expect![[r#" | 779 | expect![[r#" |
804 | 10..47 '{ ...5u8; }': () | 780 | 10..47 '{ ...5u8; }': () |
805 | 16..20 '1u32': u32 | 781 | 16..20 '1u32': u32 |
@@ -816,29 +792,29 @@ fn infer_shift_op() { | |||
816 | fn infer_field_autoderef() { | 792 | fn infer_field_autoderef() { |
817 | check_infer( | 793 | check_infer( |
818 | r#" | 794 | r#" |
819 | struct A { | 795 | struct A { |
820 | b: B, | 796 | b: B, |
821 | } | 797 | } |
822 | struct B; | 798 | struct B; |
823 | |||
824 | fn test1(a: A) { | ||
825 | let a1 = a; | ||
826 | a1.b; | ||
827 | let a2 = &a; | ||
828 | a2.b; | ||
829 | let a3 = &mut a; | ||
830 | a3.b; | ||
831 | let a4 = &&&&&&&a; | ||
832 | a4.b; | ||
833 | let a5 = &mut &&mut &&mut a; | ||
834 | a5.b; | ||
835 | } | ||
836 | 799 | ||
837 | fn test2(a1: *const A, a2: *mut A) { | 800 | fn test1(a: A) { |
838 | a1.b; | 801 | let a1 = a; |
839 | a2.b; | 802 | a1.b; |
840 | } | 803 | let a2 = &a; |
841 | "#, | 804 | a2.b; |
805 | let a3 = &mut a; | ||
806 | a3.b; | ||
807 | let a4 = &&&&&&&a; | ||
808 | a4.b; | ||
809 | let a5 = &mut &&mut &&mut a; | ||
810 | a5.b; | ||
811 | } | ||
812 | |||
813 | fn test2(a1: *const A, a2: *mut A) { | ||
814 | a1.b; | ||
815 | a2.b; | ||
816 | } | ||
817 | "#, | ||
842 | expect![[r#" | 818 | expect![[r#" |
843 | 43..44 'a': A | 819 | 43..44 'a': A |
844 | 49..212 '{ ...5.b; }': () | 820 | 49..212 '{ ...5.b; }': () |
@@ -891,58 +867,53 @@ fn infer_field_autoderef() { | |||
891 | fn infer_argument_autoderef() { | 867 | fn infer_argument_autoderef() { |
892 | check_infer( | 868 | check_infer( |
893 | r#" | 869 | r#" |
894 | #[lang = "deref"] | 870 | //- minicore: deref |
895 | pub trait Deref { | 871 | use core::ops::Deref; |
896 | type Target; | 872 | struct A<T>(T); |
897 | fn deref(&self) -> &Self::Target; | ||
898 | } | ||
899 | |||
900 | struct A<T>(T); | ||
901 | 873 | ||
902 | impl<T> A<T> { | 874 | impl<T> A<T> { |
903 | fn foo(&self) -> &T { | 875 | fn foo(&self) -> &T { |
904 | &self.0 | 876 | &self.0 |
905 | } | 877 | } |
906 | } | 878 | } |
907 | 879 | ||
908 | struct B<T>(T); | 880 | struct B<T>(T); |
909 | 881 | ||
910 | impl<T> Deref for B<T> { | 882 | impl<T> Deref for B<T> { |
911 | type Target = T; | 883 | type Target = T; |
912 | fn deref(&self) -> &Self::Target { | 884 | fn deref(&self) -> &Self::Target { |
913 | &self.0 | 885 | &self.0 |
914 | } | 886 | } |
915 | } | 887 | } |
916 | 888 | ||
917 | fn test() { | 889 | fn test() { |
918 | let t = A::foo(&&B(B(A(42)))); | 890 | let t = A::foo(&&B(B(A(42)))); |
919 | } | 891 | } |
920 | "#, | 892 | "#, |
921 | expect![[r#" | 893 | expect![[r#" |
922 | 67..71 'self': &Self | 894 | 66..70 'self': &A<T> |
923 | 138..142 'self': &A<T> | 895 | 78..101 '{ ... }': &T |
924 | 150..173 '{ ... }': &T | 896 | 88..95 '&self.0': &T |
925 | 160..167 '&self.0': &T | 897 | 89..93 'self': &A<T> |
926 | 161..165 'self': &A<T> | 898 | 89..95 'self.0': T |
927 | 161..167 'self.0': T | 899 | 182..186 'self': &B<T> |
928 | 254..258 'self': &B<T> | 900 | 205..228 '{ ... }': &T |
929 | 277..300 '{ ... }': &T | 901 | 215..222 '&self.0': &T |
930 | 287..294 '&self.0': &T | 902 | 216..220 'self': &B<T> |
931 | 288..292 'self': &B<T> | 903 | 216..222 'self.0': T |
932 | 288..294 'self.0': T | 904 | 242..280 '{ ...))); }': () |
933 | 314..352 '{ ...))); }': () | 905 | 252..253 't': &i32 |
934 | 324..325 't': &i32 | 906 | 256..262 'A::foo': fn foo<i32>(&A<i32>) -> &i32 |
935 | 328..334 'A::foo': fn foo<i32>(&A<i32>) -> &i32 | 907 | 256..277 'A::foo...42))))': &i32 |
936 | 328..349 'A::foo...42))))': &i32 | 908 | 263..276 '&&B(B(A(42)))': &&B<B<A<i32>>> |
937 | 335..348 '&&B(B(A(42)))': &&B<B<A<i32>>> | 909 | 264..276 '&B(B(A(42)))': &B<B<A<i32>>> |
938 | 336..348 '&B(B(A(42)))': &B<B<A<i32>>> | 910 | 265..266 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>> |
939 | 337..338 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>> | 911 | 265..276 'B(B(A(42)))': B<B<A<i32>>> |
940 | 337..348 'B(B(A(42)))': B<B<A<i32>>> | 912 | 267..268 'B': B<A<i32>>(A<i32>) -> B<A<i32>> |
941 | 339..340 'B': B<A<i32>>(A<i32>) -> B<A<i32>> | 913 | 267..275 'B(A(42))': B<A<i32>> |
942 | 339..347 'B(A(42))': B<A<i32>> | 914 | 269..270 'A': A<i32>(i32) -> A<i32> |
943 | 341..342 'A': A<i32>(i32) -> A<i32> | 915 | 269..274 'A(42)': A<i32> |
944 | 341..346 'A(42)': A<i32> | 916 | 271..273 '42': i32 |
945 | 343..345 '42': i32 | ||
946 | "#]], | 917 | "#]], |
947 | ); | 918 | ); |
948 | } | 919 | } |
@@ -951,62 +922,57 @@ fn infer_argument_autoderef() { | |||
951 | fn infer_method_argument_autoderef() { | 922 | fn infer_method_argument_autoderef() { |
952 | check_infer( | 923 | check_infer( |
953 | r#" | 924 | r#" |
954 | #[lang = "deref"] | 925 | //- minicore: deref |
955 | pub trait Deref { | 926 | use core::ops::Deref; |
956 | type Target; | 927 | struct A<T>(*mut T); |
957 | fn deref(&self) -> &Self::Target; | ||
958 | } | ||
959 | 928 | ||
960 | struct A<T>(*mut T); | 929 | impl<T> A<T> { |
961 | 930 | fn foo(&self, x: &A<T>) -> &T { | |
962 | impl<T> A<T> { | 931 | &*x.0 |
963 | fn foo(&self, x: &A<T>) -> &T { | 932 | } |
964 | &*x.0 | 933 | } |
965 | } | ||
966 | } | ||
967 | 934 | ||
968 | struct B<T>(T); | 935 | struct B<T>(T); |
969 | 936 | ||
970 | impl<T> Deref for B<T> { | 937 | impl<T> Deref for B<T> { |
971 | type Target = T; | 938 | type Target = T; |
972 | fn deref(&self) -> &Self::Target { | 939 | fn deref(&self) -> &Self::Target { |
973 | &self.0 | 940 | &self.0 |
974 | } | 941 | } |
975 | } | 942 | } |
976 | 943 | ||
977 | fn test(a: A<i32>) { | 944 | fn test(a: A<i32>) { |
978 | let t = A(0 as *mut _).foo(&&B(B(a))); | 945 | let t = A(0 as *mut _).foo(&&B(B(a))); |
979 | } | 946 | } |
980 | "#, | 947 | "#, |
981 | expect![[r#" | 948 | expect![[r#" |
982 | 67..71 'self': &Self | 949 | 71..75 'self': &A<T> |
983 | 143..147 'self': &A<T> | 950 | 77..78 'x': &A<T> |
984 | 149..150 'x': &A<T> | 951 | 93..114 '{ ... }': &T |
985 | 165..186 '{ ... }': &T | 952 | 103..108 '&*x.0': &T |
986 | 175..180 '&*x.0': &T | 953 | 104..108 '*x.0': T |
987 | 176..180 '*x.0': T | 954 | 105..106 'x': &A<T> |
988 | 177..178 'x': &A<T> | 955 | 105..108 'x.0': *mut T |
989 | 177..180 'x.0': *mut T | 956 | 195..199 'self': &B<T> |
990 | 267..271 'self': &B<T> | 957 | 218..241 '{ ... }': &T |
991 | 290..313 '{ ... }': &T | 958 | 228..235 '&self.0': &T |
992 | 300..307 '&self.0': &T | 959 | 229..233 'self': &B<T> |
993 | 301..305 'self': &B<T> | 960 | 229..235 'self.0': T |
994 | 301..307 'self.0': T | 961 | 253..254 'a': A<i32> |
995 | 325..326 'a': A<i32> | 962 | 264..310 '{ ...))); }': () |
996 | 336..382 '{ ...))); }': () | 963 | 274..275 't': &i32 |
997 | 346..347 't': &i32 | 964 | 278..279 'A': A<i32>(*mut i32) -> A<i32> |
998 | 350..351 'A': A<i32>(*mut i32) -> A<i32> | 965 | 278..292 'A(0 as *mut _)': A<i32> |
999 | 350..364 'A(0 as *mut _)': A<i32> | 966 | 278..307 'A(0 as...B(a)))': &i32 |
1000 | 350..379 'A(0 as...B(a)))': &i32 | 967 | 280..281 '0': i32 |
1001 | 352..353 '0': i32 | 968 | 280..291 '0 as *mut _': *mut i32 |
1002 | 352..363 '0 as *mut _': *mut i32 | 969 | 297..306 '&&B(B(a))': &&B<B<A<i32>>> |
1003 | 369..378 '&&B(B(a))': &&B<B<A<i32>>> | 970 | 298..306 '&B(B(a))': &B<B<A<i32>>> |
1004 | 370..378 '&B(B(a))': &B<B<A<i32>>> | 971 | 299..300 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>> |
1005 | 371..372 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>> | 972 | 299..306 'B(B(a))': B<B<A<i32>>> |
1006 | 371..378 'B(B(a))': B<B<A<i32>>> | 973 | 301..302 'B': B<A<i32>>(A<i32>) -> B<A<i32>> |
1007 | 373..374 'B': B<A<i32>>(A<i32>) -> B<A<i32>> | 974 | 301..305 'B(a)': B<A<i32>> |
1008 | 373..377 'B(a)': B<A<i32>> | 975 | 303..304 'a': A<i32> |
1009 | 375..376 'a': A<i32> | ||
1010 | "#]], | 976 | "#]], |
1011 | ); | 977 | ); |
1012 | } | 978 | } |
@@ -1015,15 +981,15 @@ fn infer_method_argument_autoderef() { | |||
1015 | fn infer_in_elseif() { | 981 | fn infer_in_elseif() { |
1016 | check_infer( | 982 | check_infer( |
1017 | r#" | 983 | r#" |
1018 | struct Foo { field: i32 } | 984 | struct Foo { field: i32 } |
1019 | fn main(foo: Foo) { | 985 | fn main(foo: Foo) { |
1020 | if true { | 986 | if true { |
1021 | 987 | ||
1022 | } else if false { | 988 | } else if false { |
1023 | foo.field | 989 | foo.field |
1024 | } | 990 | } |
1025 | } | 991 | } |
1026 | "#, | 992 | "#, |
1027 | expect![[r#" | 993 | expect![[r#" |
1028 | 34..37 'foo': Foo | 994 | 34..37 'foo': Foo |
1029 | 44..108 '{ ... } }': () | 995 | 44..108 '{ ... } }': () |
@@ -1043,28 +1009,29 @@ fn infer_in_elseif() { | |||
1043 | fn infer_if_match_with_return() { | 1009 | fn infer_if_match_with_return() { |
1044 | check_infer( | 1010 | check_infer( |
1045 | r#" | 1011 | r#" |
1046 | fn foo() { | 1012 | fn foo() { |
1047 | let _x1 = if true { | 1013 | let _x1 = if true { |
1048 | 1 | 1014 | 1 |
1049 | } else { | 1015 | } else { |
1050 | return; | 1016 | return; |
1051 | }; | 1017 | }; |
1052 | let _x2 = if true { | 1018 | let _x2 = if true { |
1053 | 2 | 1019 | 2 |
1054 | } else { | 1020 | } else { |
1055 | return | 1021 | return |
1056 | }; | 1022 | }; |
1057 | let _x3 = match true { | 1023 | let _x3 = match true { |
1058 | true => 3, | 1024 | true => 3, |
1059 | _ => { | 1025 | _ => { |
1060 | return; | 1026 | return; |
1061 | } | 1027 | } |
1062 | }; | 1028 | }; |
1063 | let _x4 = match true { | 1029 | let _x4 = match true { |
1064 | true => 4, | 1030 | true => 4, |
1065 | _ => return | 1031 | _ => return |
1066 | }; | 1032 | }; |
1067 | }"#, | 1033 | } |
1034 | "#, | ||
1068 | expect![[r#" | 1035 | expect![[r#" |
1069 | 9..322 '{ ... }; }': () | 1036 | 9..322 '{ ... }; }': () |
1070 | 19..22 '_x1': i32 | 1037 | 19..22 '_x1': i32 |
@@ -2639,11 +2606,8 @@ fn f() { | |||
2639 | fn infer_boxed_self_receiver() { | 2606 | fn infer_boxed_self_receiver() { |
2640 | check_infer( | 2607 | check_infer( |
2641 | r#" | 2608 | r#" |
2642 | #[lang = "deref"] | 2609 | //- minicore: deref |
2643 | pub trait Deref { | 2610 | use core::ops::Deref; |
2644 | type Target; | ||
2645 | fn deref(&self) -> &Self::Target; | ||
2646 | } | ||
2647 | 2611 | ||
2648 | struct Box<T>(T); | 2612 | struct Box<T>(T); |
2649 | 2613 | ||
@@ -2675,40 +2639,39 @@ fn main() { | |||
2675 | } | 2639 | } |
2676 | "#, | 2640 | "#, |
2677 | expect![[r#" | 2641 | expect![[r#" |
2678 | 67..71 'self': &Self | 2642 | 104..108 'self': &Box<T> |
2679 | 175..179 'self': &Box<T> | 2643 | 188..192 'self': &Box<Foo<T>> |
2680 | 259..263 'self': &Box<Foo<T>> | 2644 | 218..220 '{}': () |
2681 | 289..291 '{}': () | 2645 | 242..246 'self': &Box<Foo<T>> |
2682 | 313..317 'self': &Box<Foo<T>> | 2646 | 275..277 '{}': () |
2683 | 346..348 '{}': () | 2647 | 297..301 'self': Box<Foo<T>> |
2684 | 368..372 'self': Box<Foo<T>> | 2648 | 322..324 '{}': () |
2685 | 393..395 '{}': () | 2649 | 338..559 '{ ...r(); }': () |
2686 | 409..630 '{ ...r(); }': () | 2650 | 348..353 'boxed': Box<Foo<i32>> |
2687 | 419..424 'boxed': Box<Foo<i32>> | 2651 | 356..359 'Box': Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>> |
2688 | 427..430 'Box': Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>> | 2652 | 356..371 'Box(Foo(0_i32))': Box<Foo<i32>> |
2689 | 427..442 'Box(Foo(0_i32))': Box<Foo<i32>> | 2653 | 360..363 'Foo': Foo<i32>(i32) -> Foo<i32> |
2690 | 431..434 'Foo': Foo<i32>(i32) -> Foo<i32> | 2654 | 360..370 'Foo(0_i32)': Foo<i32> |
2691 | 431..441 'Foo(0_i32)': Foo<i32> | 2655 | 364..369 '0_i32': i32 |
2692 | 435..440 '0_i32': i32 | 2656 | 382..386 'bad1': &i32 |
2693 | 453..457 'bad1': &i32 | 2657 | 389..394 'boxed': Box<Foo<i32>> |
2694 | 460..465 'boxed': Box<Foo<i32>> | 2658 | 389..406 'boxed....nner()': &i32 |
2695 | 460..477 'boxed....nner()': &i32 | 2659 | 416..421 'good1': &i32 |
2696 | 487..492 'good1': &i32 | 2660 | 424..438 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32 |
2697 | 495..509 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32 | 2661 | 424..446 'Foo::g...boxed)': &i32 |
2698 | 495..517 'Foo::g...boxed)': &i32 | 2662 | 439..445 '&boxed': &Box<Foo<i32>> |
2699 | 510..516 '&boxed': &Box<Foo<i32>> | 2663 | 440..445 'boxed': Box<Foo<i32>> |
2700 | 511..516 'boxed': Box<Foo<i32>> | 2664 | 457..461 'bad2': &Foo<i32> |
2701 | 528..532 'bad2': &Foo<i32> | 2665 | 464..469 'boxed': Box<Foo<i32>> |
2702 | 535..540 'boxed': Box<Foo<i32>> | 2666 | 464..480 'boxed....self()': &Foo<i32> |
2703 | 535..551 'boxed....self()': &Foo<i32> | 2667 | 490..495 'good2': &Foo<i32> |
2704 | 561..566 'good2': &Foo<i32> | 2668 | 498..511 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32> |
2705 | 569..582 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32> | 2669 | 498..519 'Foo::g...boxed)': &Foo<i32> |
2706 | 569..590 'Foo::g...boxed)': &Foo<i32> | 2670 | 512..518 '&boxed': &Box<Foo<i32>> |
2707 | 583..589 '&boxed': &Box<Foo<i32>> | 2671 | 513..518 'boxed': Box<Foo<i32>> |
2708 | 584..589 'boxed': Box<Foo<i32>> | 2672 | 530..535 'inner': Foo<i32> |
2709 | 601..606 'inner': Foo<i32> | 2673 | 538..543 'boxed': Box<Foo<i32>> |
2710 | 609..614 'boxed': Box<Foo<i32>> | 2674 | 538..556 'boxed....nner()': Foo<i32> |
2711 | 609..627 'boxed....nner()': Foo<i32> | ||
2712 | "#]], | 2675 | "#]], |
2713 | ); | 2676 | ); |
2714 | } | 2677 | } |
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 6bcede4c4..65fed02d2 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -6,10 +6,10 @@ use super::{check_infer, check_infer_with_mismatches, check_types}; | |||
6 | fn infer_await() { | 6 | fn infer_await() { |
7 | check_types( | 7 | check_types( |
8 | r#" | 8 | r#" |
9 | //- /main.rs crate:main deps:core | 9 | //- minicore: future |
10 | struct IntFuture; | 10 | struct IntFuture; |
11 | 11 | ||
12 | impl Future for IntFuture { | 12 | impl core::future::Future for IntFuture { |
13 | type Output = u64; | 13 | type Output = u64; |
14 | } | 14 | } |
15 | 15 | ||
@@ -18,16 +18,6 @@ fn test() { | |||
18 | let v = r.await; | 18 | let v = r.await; |
19 | v; | 19 | v; |
20 | } //^ u64 | 20 | } //^ u64 |
21 | |||
22 | //- /core.rs crate:core | ||
23 | pub mod prelude { | ||
24 | pub mod rust_2018 { | ||
25 | #[lang = "future_trait"] | ||
26 | pub trait Future { | ||
27 | type Output; | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | "#, | 21 | "#, |
32 | ); | 22 | ); |
33 | } | 23 | } |
@@ -36,25 +26,14 @@ pub mod prelude { | |||
36 | fn infer_async() { | 26 | fn infer_async() { |
37 | check_types( | 27 | check_types( |
38 | r#" | 28 | r#" |
39 | //- /main.rs crate:main deps:core | 29 | //- minicore: future |
40 | async fn foo() -> u64 { | 30 | async fn foo() -> u64 { 128 } |
41 | 128 | ||
42 | } | ||
43 | 31 | ||
44 | fn test() { | 32 | fn test() { |
45 | let r = foo(); | 33 | let r = foo(); |
46 | let v = r.await; | 34 | let v = r.await; |
47 | v; | 35 | v; |
48 | } //^ u64 | 36 | } //^ u64 |
49 | |||
50 | //- /core.rs crate:core | ||
51 | #[prelude_import] use future::*; | ||
52 | mod future { | ||
53 | #[lang = "future_trait"] | ||
54 | trait Future { | ||
55 | type Output; | ||
56 | } | ||
57 | } | ||
58 | "#, | 37 | "#, |
59 | ); | 38 | ); |
60 | } | 39 | } |
@@ -63,24 +42,13 @@ mod future { | |||
63 | fn infer_desugar_async() { | 42 | fn infer_desugar_async() { |
64 | check_types( | 43 | check_types( |
65 | r#" | 44 | r#" |
66 | //- /main.rs crate:main deps:core | 45 | //- minicore: future |
67 | async fn foo() -> u64 { | 46 | async fn foo() -> u64 { 128 } |
68 | 128 | ||
69 | } | ||
70 | 47 | ||
71 | fn test() { | 48 | fn test() { |
72 | let r = foo(); | 49 | let r = foo(); |
73 | r; | 50 | r; |
74 | } //^ impl Future<Output = u64> | 51 | } //^ impl Future<Output = u64> |
75 | |||
76 | //- /core.rs crate:core | ||
77 | #[prelude_import] use future::*; | ||
78 | mod future { | ||
79 | trait Future { | ||
80 | type Output; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | "#, | 52 | "#, |
85 | ); | 53 | ); |
86 | } | 54 | } |
@@ -89,7 +57,7 @@ mod future { | |||
89 | fn infer_async_block() { | 57 | fn infer_async_block() { |
90 | check_types( | 58 | check_types( |
91 | r#" | 59 | r#" |
92 | //- /main.rs crate:main deps:core | 60 | //- minicore: future, option |
93 | async fn test() { | 61 | async fn test() { |
94 | let a = async { 42 }; | 62 | let a = async { 42 }; |
95 | a; | 63 | a; |
@@ -101,7 +69,7 @@ async fn test() { | |||
101 | b; | 69 | b; |
102 | // ^ () | 70 | // ^ () |
103 | let c = async { | 71 | let c = async { |
104 | let y = Option::None; | 72 | let y = None; |
105 | y | 73 | y |
106 | // ^ Option<u64> | 74 | // ^ Option<u64> |
107 | }; | 75 | }; |
@@ -109,18 +77,6 @@ async fn test() { | |||
109 | c; | 77 | c; |
110 | // ^ impl Future<Output = Option<u64>> | 78 | // ^ impl Future<Output = Option<u64>> |
111 | } | 79 | } |
112 | |||
113 | enum Option<T> { None, Some(T) } | ||
114 | |||
115 | //- /core.rs crate:core | ||
116 | #[prelude_import] use future::*; | ||
117 | mod future { | ||
118 | #[lang = "future_trait"] | ||
119 | trait Future { | ||
120 | type Output; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | "#, | 80 | "#, |
125 | ); | 81 | ); |
126 | } | 82 | } |
@@ -704,14 +660,9 @@ mod ops { | |||
704 | fn deref_trait() { | 660 | fn deref_trait() { |
705 | check_types( | 661 | check_types( |
706 | r#" | 662 | r#" |
707 | #[lang = "deref"] | 663 | //- minicore: deref |
708 | trait Deref { | ||
709 | type Target; | ||
710 | fn deref(&self) -> &Self::Target; | ||
711 | } | ||
712 | |||
713 | struct Arc<T>; | 664 | struct Arc<T>; |
714 | impl<T> Deref for Arc<T> { | 665 | impl<T> core::ops::Deref for Arc<T> { |
715 | type Target = T; | 666 | type Target = T; |
716 | } | 667 | } |
717 | 668 | ||
@@ -731,16 +682,10 @@ fn test(s: Arc<S>) { | |||
731 | fn deref_trait_with_inference_var() { | 682 | fn deref_trait_with_inference_var() { |
732 | check_types( | 683 | check_types( |
733 | r#" | 684 | r#" |
734 | //- /main.rs | 685 | //- minicore: deref |
735 | #[lang = "deref"] | ||
736 | trait Deref { | ||
737 | type Target; | ||
738 | fn deref(&self) -> &Self::Target; | ||
739 | } | ||
740 | |||
741 | struct Arc<T>; | 686 | struct Arc<T>; |
742 | fn new_arc<T>() -> Arc<T> {} | 687 | fn new_arc<T>() -> Arc<T> {} |
743 | impl<T> Deref for Arc<T> { | 688 | impl<T> core::ops::Deref for Arc<T> { |
744 | type Target = T; | 689 | type Target = T; |
745 | } | 690 | } |
746 | 691 | ||
@@ -761,15 +706,10 @@ fn test() { | |||
761 | fn deref_trait_infinite_recursion() { | 706 | fn deref_trait_infinite_recursion() { |
762 | check_types( | 707 | check_types( |
763 | r#" | 708 | r#" |
764 | #[lang = "deref"] | 709 | //- minicore: deref |
765 | trait Deref { | ||
766 | type Target; | ||
767 | fn deref(&self) -> &Self::Target; | ||
768 | } | ||
769 | |||
770 | struct S; | 710 | struct S; |
771 | 711 | ||
772 | impl Deref for S { | 712 | impl core::ops::Deref for S { |
773 | type Target = S; | 713 | type Target = S; |
774 | } | 714 | } |
775 | 715 | ||
@@ -784,14 +724,9 @@ fn test(s: S) { | |||
784 | fn deref_trait_with_question_mark_size() { | 724 | fn deref_trait_with_question_mark_size() { |
785 | check_types( | 725 | check_types( |
786 | r#" | 726 | r#" |
787 | #[lang = "deref"] | 727 | //- minicore: deref |
788 | trait Deref { | ||
789 | type Target; | ||
790 | fn deref(&self) -> &Self::Target; | ||
791 | } | ||
792 | |||
793 | struct Arc<T>; | 728 | struct Arc<T>; |
794 | impl<T> Deref for Arc<T> { | 729 | impl<T: ?Sized> core::ops::Deref for Arc<T> { |
795 | type Target = T; | 730 | type Target = T; |
796 | } | 731 | } |
797 | 732 | ||
@@ -1475,7 +1410,6 @@ fn test( | |||
1475 | } | 1410 | } |
1476 | 1411 | ||
1477 | #[test] | 1412 | #[test] |
1478 | #[ignore] | ||
1479 | fn error_bound_chalk() { | 1413 | fn error_bound_chalk() { |
1480 | check_types( | 1414 | check_types( |
1481 | r#" | 1415 | r#" |
@@ -2626,12 +2560,9 @@ fn test<T: Trait>() { | |||
2626 | fn dyn_trait_through_chalk() { | 2560 | fn dyn_trait_through_chalk() { |
2627 | check_types( | 2561 | check_types( |
2628 | r#" | 2562 | r#" |
2563 | //- minicore: deref | ||
2629 | struct Box<T> {} | 2564 | struct Box<T> {} |
2630 | #[lang = "deref"] | 2565 | impl<T> core::ops::Deref for Box<T> { |
2631 | trait Deref { | ||
2632 | type Target; | ||
2633 | } | ||
2634 | impl<T> Deref for Box<T> { | ||
2635 | type Target = T; | 2566 | type Target = T; |
2636 | } | 2567 | } |
2637 | trait Trait { | 2568 | trait Trait { |
@@ -3696,16 +3627,7 @@ impl foo::Foo for u32 { | |||
3696 | fn infer_async_ret_type() { | 3627 | fn infer_async_ret_type() { |
3697 | check_types( | 3628 | check_types( |
3698 | r#" | 3629 | r#" |
3699 | //- /main.rs crate:main deps:core | 3630 | //- minicore: future, result |
3700 | |||
3701 | enum Result<T, E> { | ||
3702 | Ok(T), | ||
3703 | Err(E), | ||
3704 | } | ||
3705 | |||
3706 | use Result::*; | ||
3707 | |||
3708 | |||
3709 | struct Fooey; | 3631 | struct Fooey; |
3710 | 3632 | ||
3711 | impl Fooey { | 3633 | impl Fooey { |
@@ -3728,15 +3650,6 @@ async fn get_accounts() -> Result<u32, ()> { | |||
3728 | // ^ u32 | 3650 | // ^ u32 |
3729 | Ok(ret) | 3651 | Ok(ret) |
3730 | } | 3652 | } |
3731 | |||
3732 | //- /core.rs crate:core | ||
3733 | #[prelude_import] use future::*; | ||
3734 | mod future { | ||
3735 | #[lang = "future_trait"] | ||
3736 | trait Future { | ||
3737 | type Output; | ||
3738 | } | ||
3739 | } | ||
3740 | "#, | 3653 | "#, |
3741 | ); | 3654 | ); |
3742 | } | 3655 | } |
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 57ae9455b..7ac0118fe 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs | |||
@@ -241,6 +241,10 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> { | |||
241 | Definition::ModuleDef(ModuleDef::Module(module)) => module.krate(), | 241 | Definition::ModuleDef(ModuleDef::Module(module)) => module.krate(), |
242 | _ => definition.module(db)?.krate(), | 242 | _ => definition.module(db)?.krate(), |
243 | }; | 243 | }; |
244 | // FIXME: using import map doesn't make sense here. What we want here is | ||
245 | // canonical path. What import map returns is the shortest path suitable for | ||
246 | // import. See this test: | ||
247 | cov_mark::hit!(test_reexport_order); | ||
244 | let import_map = db.import_map(krate.into()); | 248 | let import_map = db.import_map(krate.into()); |
245 | 249 | ||
246 | let mut base = krate.display_name(db)?.to_string(); | 250 | let mut base = krate.display_name(db)?.to_string(); |
@@ -642,13 +646,15 @@ pub mod foo { | |||
642 | ) | 646 | ) |
643 | } | 647 | } |
644 | 648 | ||
645 | // FIXME: ImportMap will return re-export paths instead of public module | ||
646 | // paths. The correct path to documentation will never be a re-export. | ||
647 | // This problem stops us from resolving stdlib items included in the prelude | ||
648 | // such as `Option::Some` correctly. | ||
649 | #[ignore = "ImportMap may return re-exports"] | ||
650 | #[test] | 649 | #[test] |
651 | fn test_reexport_order() { | 650 | fn test_reexport_order() { |
651 | cov_mark::check!(test_reexport_order); | ||
652 | // FIXME: This should return | ||
653 | // | ||
654 | // https://docs.rs/test/*/test/wrapper/modulestruct.Item.html | ||
655 | // | ||
656 | // That is, we should point inside the module, rather than at the | ||
657 | // re-export. | ||
652 | check( | 658 | check( |
653 | r#" | 659 | r#" |
654 | pub mod wrapper { | 660 | pub mod wrapper { |
@@ -663,7 +669,7 @@ fn foo() { | |||
663 | let bar: wrapper::It$0em; | 669 | let bar: wrapper::It$0em; |
664 | } | 670 | } |
665 | "#, | 671 | "#, |
666 | expect![[r#"https://docs.rs/test/*/test/wrapper/module/struct.Item.html"#]], | 672 | expect![[r#"https://docs.rs/test/*/test/wrapper/struct.Item.html"#]], |
667 | ) | 673 | ) |
668 | } | 674 | } |
669 | } | 675 | } |
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 8dd643a0f..d8e0dc4d5 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs | |||
@@ -1130,15 +1130,15 @@ fn foo<'foobar>(_: &'foobar ()) { | |||
1130 | } | 1130 | } |
1131 | 1131 | ||
1132 | #[test] | 1132 | #[test] |
1133 | #[ignore] // requires the HIR to somehow track these hrtb lifetimes | ||
1134 | fn goto_lifetime_hrtb() { | 1133 | fn goto_lifetime_hrtb() { |
1135 | check( | 1134 | // FIXME: requires the HIR to somehow track these hrtb lifetimes |
1135 | check_unresolved( | ||
1136 | r#"trait Foo<T> {} | 1136 | r#"trait Foo<T> {} |
1137 | fn foo<T>() where for<'a> T: Foo<&'a$0 (u8, u16)>, {} | 1137 | fn foo<T>() where for<'a> T: Foo<&'a$0 (u8, u16)>, {} |
1138 | //^^ | 1138 | //^^ |
1139 | "#, | 1139 | "#, |
1140 | ); | 1140 | ); |
1141 | check( | 1141 | check_unresolved( |
1142 | r#"trait Foo<T> {} | 1142 | r#"trait Foo<T> {} |
1143 | fn foo<T>() where for<'a$0> T: Foo<&'a (u8, u16)>, {} | 1143 | fn foo<T>() where for<'a$0> T: Foo<&'a (u8, u16)>, {} |
1144 | //^^ | 1144 | //^^ |
@@ -1147,9 +1147,9 @@ fn foo<T>() where for<'a$0> T: Foo<&'a (u8, u16)>, {} | |||
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | #[test] | 1149 | #[test] |
1150 | #[ignore] // requires ForTypes to be implemented | ||
1151 | fn goto_lifetime_hrtb_for_type() { | 1150 | fn goto_lifetime_hrtb_for_type() { |
1152 | check( | 1151 | // FIXME: requires ForTypes to be implemented |
1152 | check_unresolved( | ||
1153 | r#"trait Foo<T> {} | 1153 | r#"trait Foo<T> {} |
1154 | fn foo<T>() where T: for<'a> Foo<&'a$0 (u8, u16)>, {} | 1154 | fn foo<T>() where T: for<'a> Foo<&'a$0 (u8, u16)>, {} |
1155 | //^^ | 1155 | //^^ |
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index c08516805..14cf94d60 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -1821,9 +1821,10 @@ pub struct B$0ar | |||
1821 | ); | 1821 | ); |
1822 | } | 1822 | } |
1823 | 1823 | ||
1824 | #[ignore = "path based links currently only support documentation on ModuleDef items"] | ||
1825 | #[test] | 1824 | #[test] |
1826 | fn test_hover_path_link_field() { | 1825 | fn test_hover_path_link_field() { |
1826 | // FIXME: Should be | ||
1827 | // [Foo](https://docs.rs/test/*/test/struct.Foo.html) | ||
1827 | check( | 1828 | check( |
1828 | r#" | 1829 | r#" |
1829 | pub struct Foo; | 1830 | pub struct Foo; |
@@ -1845,7 +1846,7 @@ pub struct Bar { | |||
1845 | 1846 | ||
1846 | --- | 1847 | --- |
1847 | 1848 | ||
1848 | [Foo](https://docs.rs/test/*/test/struct.Foo.html) | 1849 | [Foo](struct.Foo.html) |
1849 | "#]], | 1850 | "#]], |
1850 | ); | 1851 | ); |
1851 | } | 1852 | } |
@@ -2999,29 +3000,24 @@ fn foo(ar$0g: &impl Foo + Bar<S>) {} | |||
2999 | fn test_hover_async_block_impl_trait_has_goto_type_action() { | 3000 | fn test_hover_async_block_impl_trait_has_goto_type_action() { |
3000 | check_actions( | 3001 | check_actions( |
3001 | r#" | 3002 | r#" |
3003 | //- minicore: future | ||
3002 | struct S; | 3004 | struct S; |
3003 | fn foo() { | 3005 | fn foo() { |
3004 | let fo$0o = async { S }; | 3006 | let fo$0o = async { S }; |
3005 | } | 3007 | } |
3006 | |||
3007 | #[prelude_import] use future::*; | ||
3008 | mod future { | ||
3009 | #[lang = "future_trait"] | ||
3010 | pub trait Future { type Output; } | ||
3011 | } | ||
3012 | "#, | 3008 | "#, |
3013 | expect![[r#" | 3009 | expect![[r#" |
3014 | [ | 3010 | [ |
3015 | GoToType( | 3011 | GoToType( |
3016 | [ | 3012 | [ |
3017 | HoverGotoTypeData { | 3013 | HoverGotoTypeData { |
3018 | mod_path: "test::future::Future", | 3014 | mod_path: "core::future::Future", |
3019 | nav: NavigationTarget { | 3015 | nav: NavigationTarget { |
3020 | file_id: FileId( | 3016 | file_id: FileId( |
3021 | 0, | 3017 | 1, |
3022 | ), | 3018 | ), |
3023 | full_range: 101..163, | 3019 | full_range: 244..426, |
3024 | focus_range: 140..146, | 3020 | focus_range: 283..289, |
3025 | name: "Future", | 3021 | name: "Future", |
3026 | kind: Trait, | 3022 | kind: Trait, |
3027 | description: "pub trait Future", | 3023 | description: "pub trait Future", |
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 9db387d26..4bd073cc3 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -567,7 +567,6 @@ impl Analysis { | |||
567 | }; | 567 | }; |
568 | 568 | ||
569 | self.with_db(|db| { | 569 | self.with_db(|db| { |
570 | let ssr_assists = ssr::ssr_assists(db, &resolve, frange); | ||
571 | let diagnostic_assists = if include_fixes { | 570 | let diagnostic_assists = if include_fixes { |
572 | ide_diagnostics::diagnostics(db, diagnostics_config, &resolve, frange.file_id) | 571 | ide_diagnostics::diagnostics(db, diagnostics_config, &resolve, frange.file_id) |
573 | .into_iter() | 572 | .into_iter() |
@@ -577,10 +576,12 @@ impl Analysis { | |||
577 | } else { | 576 | } else { |
578 | Vec::new() | 577 | Vec::new() |
579 | }; | 578 | }; |
579 | let ssr_assists = ssr::ssr_assists(db, &resolve, frange); | ||
580 | let assists = ide_assists::assists(db, assist_config, resolve, frange); | ||
580 | 581 | ||
581 | let mut res = ide_assists::assists(db, assist_config, resolve, frange); | 582 | let mut res = diagnostic_assists; |
582 | res.extend(ssr_assists.into_iter()); | 583 | res.extend(ssr_assists.into_iter()); |
583 | res.extend(diagnostic_assists.into_iter()); | 584 | res.extend(assists.into_iter()); |
584 | 585 | ||
585 | res | 586 | res |
586 | }) | 587 | }) |
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 7a53268e8..6834fe11a 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs | |||
@@ -48,7 +48,13 @@ pub(super) fn element( | |||
48 | match name_kind { | 48 | match name_kind { |
49 | Some(NameClass::ExternCrate(_)) => SymbolKind::Module.into(), | 49 | Some(NameClass::ExternCrate(_)) => SymbolKind::Module.into(), |
50 | Some(NameClass::Definition(def)) => { | 50 | Some(NameClass::Definition(def)) => { |
51 | highlight_def(db, krate, def) | HlMod::Definition | 51 | let mut h = highlight_def(db, krate, def) | HlMod::Definition; |
52 | if let Definition::ModuleDef(hir::ModuleDef::Trait(trait_)) = &def { | ||
53 | if trait_.is_unsafe(db) { | ||
54 | h |= HlMod::Unsafe; | ||
55 | } | ||
56 | } | ||
57 | h | ||
52 | } | 58 | } |
53 | Some(NameClass::ConstReference(def)) => highlight_def(db, krate, def), | 59 | Some(NameClass::ConstReference(def)) => highlight_def(db, krate, def), |
54 | Some(NameClass::PatFieldShorthand { field_ref, .. }) => { | 60 | Some(NameClass::PatFieldShorthand { field_ref, .. }) => { |
@@ -87,20 +93,34 @@ pub(super) fn element( | |||
87 | 93 | ||
88 | let mut h = highlight_def(db, krate, def); | 94 | let mut h = highlight_def(db, krate, def); |
89 | 95 | ||
90 | if let Definition::Local(local) = &def { | 96 | match def { |
91 | if is_consumed_lvalue(name_ref.syntax().clone().into(), local, db) { | 97 | Definition::Local(local) |
98 | if is_consumed_lvalue( | ||
99 | name_ref.syntax().clone().into(), | ||
100 | &local, | ||
101 | db, | ||
102 | ) => | ||
103 | { | ||
92 | h |= HlMod::Consuming; | 104 | h |= HlMod::Consuming; |
93 | } | 105 | } |
94 | } | 106 | Definition::ModuleDef(hir::ModuleDef::Trait(trait_)) |
95 | 107 | if trait_.is_unsafe(db) => | |
96 | if let Some(parent) = name_ref.syntax().parent() { | 108 | { |
97 | if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) { | 109 | if ast::Impl::for_trait_name_ref(&name_ref).is_some() { |
98 | if let Definition::Field(field) = def { | 110 | h |= HlMod::Unsafe; |
99 | if let hir::VariantDef::Union(_) = field.parent_def(db) { | 111 | } |
100 | h |= HlMod::Unsafe; | 112 | } |
113 | Definition::Field(field) => { | ||
114 | if let Some(parent) = name_ref.syntax().parent() { | ||
115 | if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) { | ||
116 | if let hir::VariantDef::Union(_) = field.parent_def(db) | ||
117 | { | ||
118 | h |= HlMod::Unsafe; | ||
119 | } | ||
101 | } | 120 | } |
102 | } | 121 | } |
103 | } | 122 | } |
123 | _ => (), | ||
104 | } | 124 | } |
105 | 125 | ||
106 | h | 126 | h |
@@ -354,15 +374,7 @@ fn highlight_def(db: &RootDatabase, krate: Option<hir::Crate>, def: Definition) | |||
354 | 374 | ||
355 | h | 375 | h |
356 | } | 376 | } |
357 | hir::ModuleDef::Trait(trait_) => { | 377 | hir::ModuleDef::Trait(_) => Highlight::new(HlTag::Symbol(SymbolKind::Trait)), |
358 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Trait)); | ||
359 | |||
360 | if trait_.is_unsafe(db) { | ||
361 | h |= HlMod::Unsafe; | ||
362 | } | ||
363 | |||
364 | h | ||
365 | } | ||
366 | hir::ModuleDef::TypeAlias(type_) => { | 378 | hir::ModuleDef::TypeAlias(type_) => { |
367 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias)); | 379 | let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias)); |
368 | 380 | ||
diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs index 478facfee..21376a7ae 100644 --- a/crates/ide/src/syntax_highlighting/html.rs +++ b/crates/ide/src/syntax_highlighting/html.rs | |||
@@ -67,6 +67,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
67 | .field { color: #94BFF3; } | 67 | .field { color: #94BFF3; } |
68 | .function { color: #93E0E3; } | 68 | .function { color: #93E0E3; } |
69 | .function.unsafe { color: #BC8383; } | 69 | .function.unsafe { color: #BC8383; } |
70 | .trait.unsafe { color: #BC8383; } | ||
70 | .operator.unsafe { color: #BC8383; } | 71 | .operator.unsafe { color: #BC8383; } |
71 | .parameter { color: #94BFF3; } | 72 | .parameter { color: #94BFF3; } |
72 | .text { color: #DCDCCC; } | 73 | .text { color: #DCDCCC; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html b/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html index a0ea1db34..4e85f7c0b 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html | |||
@@ -15,6 +15,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
15 | .field { color: #94BFF3; } | 15 | .field { color: #94BFF3; } |
16 | .function { color: #93E0E3; } | 16 | .function { color: #93E0E3; } |
17 | .function.unsafe { color: #BC8383; } | 17 | .function.unsafe { color: #BC8383; } |
18 | .trait.unsafe { color: #BC8383; } | ||
18 | .operator.unsafe { color: #BC8383; } | 19 | .operator.unsafe { color: #BC8383; } |
19 | .parameter { color: #94BFF3; } | 20 | .parameter { color: #94BFF3; } |
20 | .text { color: #DCDCCC; } | 21 | .text { color: #DCDCCC; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html index 921a956e6..79a285107 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html | |||
@@ -15,6 +15,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
15 | .field { color: #94BFF3; } | 15 | .field { color: #94BFF3; } |
16 | .function { color: #93E0E3; } | 16 | .function { color: #93E0E3; } |
17 | .function.unsafe { color: #BC8383; } | 17 | .function.unsafe { color: #BC8383; } |
18 | .trait.unsafe { color: #BC8383; } | ||
18 | .operator.unsafe { color: #BC8383; } | 19 | .operator.unsafe { color: #BC8383; } |
19 | .parameter { color: #94BFF3; } | 20 | .parameter { color: #94BFF3; } |
20 | .text { color: #DCDCCC; } | 21 | .text { color: #DCDCCC; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html index ca9bb1e7d..13f589cc0 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html | |||
@@ -15,6 +15,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
15 | .field { color: #94BFF3; } | 15 | .field { color: #94BFF3; } |
16 | .function { color: #93E0E3; } | 16 | .function { color: #93E0E3; } |
17 | .function.unsafe { color: #BC8383; } | 17 | .function.unsafe { color: #BC8383; } |
18 | .trait.unsafe { color: #BC8383; } | ||
18 | .operator.unsafe { color: #BC8383; } | 19 | .operator.unsafe { color: #BC8383; } |
19 | .parameter { color: #94BFF3; } | 20 | .parameter { color: #94BFF3; } |
20 | .text { color: #DCDCCC; } | 21 | .text { color: #DCDCCC; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html index 6202a03ce..50df376ae 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html | |||
@@ -15,6 +15,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
15 | .field { color: #94BFF3; } | 15 | .field { color: #94BFF3; } |
16 | .function { color: #93E0E3; } | 16 | .function { color: #93E0E3; } |
17 | .function.unsafe { color: #BC8383; } | 17 | .function.unsafe { color: #BC8383; } |
18 | .trait.unsafe { color: #BC8383; } | ||
18 | .operator.unsafe { color: #BC8383; } | 19 | .operator.unsafe { color: #BC8383; } |
19 | .parameter { color: #94BFF3; } | 20 | .parameter { color: #94BFF3; } |
20 | .text { color: #DCDCCC; } | 21 | .text { color: #DCDCCC; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html index e860d713e..96cb09642 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html | |||
@@ -15,6 +15,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
15 | .field { color: #94BFF3; } | 15 | .field { color: #94BFF3; } |
16 | .function { color: #93E0E3; } | 16 | .function { color: #93E0E3; } |
17 | .function.unsafe { color: #BC8383; } | 17 | .function.unsafe { color: #BC8383; } |
18 | .trait.unsafe { color: #BC8383; } | ||
18 | .operator.unsafe { color: #BC8383; } | 19 | .operator.unsafe { color: #BC8383; } |
19 | .parameter { color: #94BFF3; } | 20 | .parameter { color: #94BFF3; } |
20 | .text { color: #DCDCCC; } | 21 | .text { color: #DCDCCC; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html index 68165bdbf..55453468b 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html | |||
@@ -15,6 +15,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
15 | .field { color: #94BFF3; } | 15 | .field { color: #94BFF3; } |
16 | .function { color: #93E0E3; } | 16 | .function { color: #93E0E3; } |
17 | .function.unsafe { color: #BC8383; } | 17 | .function.unsafe { color: #BC8383; } |
18 | .trait.unsafe { color: #BC8383; } | ||
18 | .operator.unsafe { color: #BC8383; } | 19 | .operator.unsafe { color: #BC8383; } |
19 | .parameter { color: #94BFF3; } | 20 | .parameter { color: #94BFF3; } |
20 | .text { color: #DCDCCC; } | 21 | .text { color: #DCDCCC; } |
@@ -61,6 +62,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
61 | <span class="field declaration">a</span><span class="colon">:</span> <span class="builtin_type">u16</span><span class="comma">,</span> | 62 | <span class="field declaration">a</span><span class="colon">:</span> <span class="builtin_type">u16</span><span class="comma">,</span> |
62 | <span class="brace">}</span> | 63 | <span class="brace">}</span> |
63 | 64 | ||
65 | <span class="keyword unsafe">unsafe</span> <span class="keyword">trait</span> <span class="trait declaration unsafe">UnsafeTrait</span> <span class="brace">{</span><span class="brace">}</span> | ||
66 | <span class="keyword unsafe">unsafe</span> <span class="keyword">impl</span> <span class="trait unsafe">UnsafeTrait</span> <span class="keyword">for</span> <span class="struct">Packed</span> <span class="brace">{</span><span class="brace">}</span> | ||
67 | |||
68 | <span class="keyword">fn</span> <span class="function declaration">require_unsafe_trait</span><span class="angle"><</span><span class="type_param declaration">T</span><span class="colon">:</span> <span class="trait">UnsafeTrait</span><span class="angle">></span><span class="parenthesis">(</span><span class="punctuation">_</span><span class="colon">:</span> <span class="type_param">T</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | ||
69 | |||
64 | <span class="keyword">trait</span> <span class="trait declaration">DoTheAutoref</span> <span class="brace">{</span> | 70 | <span class="keyword">trait</span> <span class="trait declaration">DoTheAutoref</span> <span class="brace">{</span> |
65 | <span class="keyword">fn</span> <span class="function associated declaration trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 71 | <span class="keyword">fn</span> <span class="function associated declaration trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
66 | <span class="brace">}</span> | 72 | <span class="brace">}</span> |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index 59f1e8e4c..9232cf905 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html | |||
@@ -15,6 +15,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
15 | .field { color: #94BFF3; } | 15 | .field { color: #94BFF3; } |
16 | .function { color: #93E0E3; } | 16 | .function { color: #93E0E3; } |
17 | .function.unsafe { color: #BC8383; } | 17 | .function.unsafe { color: #BC8383; } |
18 | .trait.unsafe { color: #BC8383; } | ||
18 | .operator.unsafe { color: #BC8383; } | 19 | .operator.unsafe { color: #BC8383; } |
19 | .parameter { color: #94BFF3; } | 20 | .parameter { color: #94BFF3; } |
20 | .text { color: #DCDCCC; } | 21 | .text { color: #DCDCCC; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/injection.html b/crates/ide/src/syntax_highlighting/test_data/injection.html index 9ab46d05c..082837328 100644 --- a/crates/ide/src/syntax_highlighting/test_data/injection.html +++ b/crates/ide/src/syntax_highlighting/test_data/injection.html | |||
@@ -15,6 +15,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
15 | .field { color: #94BFF3; } | 15 | .field { color: #94BFF3; } |
16 | .function { color: #93E0E3; } | 16 | .function { color: #93E0E3; } |
17 | .function.unsafe { color: #BC8383; } | 17 | .function.unsafe { color: #BC8383; } |
18 | .trait.unsafe { color: #BC8383; } | ||
18 | .operator.unsafe { color: #BC8383; } | 19 | .operator.unsafe { color: #BC8383; } |
19 | .parameter { color: #94BFF3; } | 20 | .parameter { color: #94BFF3; } |
20 | .text { color: #DCDCCC; } | 21 | .text { color: #DCDCCC; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html b/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html index 666b0b228..763917714 100644 --- a/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html | |||
@@ -15,6 +15,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
15 | .field { color: #94BFF3; } | 15 | .field { color: #94BFF3; } |
16 | .function { color: #93E0E3; } | 16 | .function { color: #93E0E3; } |
17 | .function.unsafe { color: #BC8383; } | 17 | .function.unsafe { color: #BC8383; } |
18 | .trait.unsafe { color: #BC8383; } | ||
18 | .operator.unsafe { color: #BC8383; } | 19 | .operator.unsafe { color: #BC8383; } |
19 | .parameter { color: #94BFF3; } | 20 | .parameter { color: #94BFF3; } |
20 | .text { color: #DCDCCC; } | 21 | .text { color: #DCDCCC; } |
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index f7d8334a0..4f0b1ce85 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs | |||
@@ -527,6 +527,11 @@ struct Packed { | |||
527 | a: u16, | 527 | a: u16, |
528 | } | 528 | } |
529 | 529 | ||
530 | unsafe trait UnsafeTrait {} | ||
531 | unsafe impl UnsafeTrait for Packed {} | ||
532 | |||
533 | fn require_unsafe_trait<T: UnsafeTrait>(_: T) {} | ||
534 | |||
530 | trait DoTheAutoref { | 535 | trait DoTheAutoref { |
531 | fn calls_autoref(&self); | 536 | fn calls_autoref(&self); |
532 | } | 537 | } |
diff --git a/crates/ide_assists/src/handlers/fix_visibility.rs b/crates/ide_assists/src/handlers/fix_visibility.rs index 9b432e92f..f834bf16a 100644 --- a/crates/ide_assists/src/handlers/fix_visibility.rs +++ b/crates/ide_assists/src/handlers/fix_visibility.rs | |||
@@ -361,8 +361,6 @@ pub struct Foo { pub bar: () } | |||
361 | } | 361 | } |
362 | 362 | ||
363 | #[test] | 363 | #[test] |
364 | #[ignore] | ||
365 | // FIXME reenable this test when `Semantics::resolve_record_field` works with union fields | ||
366 | fn fix_visibility_of_union_field() { | 364 | fn fix_visibility_of_union_field() { |
367 | check_assist( | 365 | check_assist( |
368 | fix_visibility, | 366 | fix_visibility, |
@@ -583,25 +581,25 @@ pub struct Foo { pub(crate) bar: () } | |||
583 | } | 581 | } |
584 | 582 | ||
585 | #[test] | 583 | #[test] |
586 | #[ignore] | ||
587 | // FIXME handle reexports properly | ||
588 | fn fix_visibility_of_reexport() { | 584 | fn fix_visibility_of_reexport() { |
585 | // FIXME: broken test, this should fix visibility of the re-export | ||
586 | // rather than the struct. | ||
589 | check_assist( | 587 | check_assist( |
590 | fix_visibility, | 588 | fix_visibility, |
591 | r" | 589 | r#" |
592 | mod foo { | 590 | mod foo { |
593 | use bar::Baz; | 591 | use bar::Baz; |
594 | mod bar { pub(super) struct Baz; } | 592 | mod bar { pub(super) struct Baz; } |
595 | } | 593 | } |
596 | foo::Baz$0 | 594 | foo::Baz$0 |
597 | ", | 595 | "#, |
598 | r" | 596 | r#" |
599 | mod foo { | 597 | mod foo { |
600 | $0pub(crate) use bar::Baz; | 598 | use bar::Baz; |
601 | mod bar { pub(super) struct Baz; } | 599 | mod bar { $0pub(crate) struct Baz; } |
602 | } | 600 | } |
603 | foo::Baz | 601 | foo::Baz |
604 | ", | 602 | "#, |
605 | ) | 603 | ) |
606 | } | 604 | } |
607 | } | 605 | } |
diff --git a/crates/ide_assists/src/handlers/generate_function.rs b/crates/ide_assists/src/handlers/generate_function.rs index 706c995ac..6a658d4cf 100644 --- a/crates/ide_assists/src/handlers/generate_function.rs +++ b/crates/ide_assists/src/handlers/generate_function.rs | |||
@@ -811,9 +811,8 @@ fn bar(baz: Baz::Bof) ${0:-> ()} { | |||
811 | } | 811 | } |
812 | 812 | ||
813 | #[test] | 813 | #[test] |
814 | #[ignore] | ||
815 | // FIXME fix printing the generics of a `Ty` to make this test pass | ||
816 | fn add_function_with_generic_arg() { | 814 | fn add_function_with_generic_arg() { |
815 | // FIXME: This is wrong, generated `bar` should include generic parameter. | ||
817 | check_assist( | 816 | check_assist( |
818 | generate_function, | 817 | generate_function, |
819 | r" | 818 | r" |
@@ -826,7 +825,7 @@ fn foo<T>(t: T) { | |||
826 | bar(t) | 825 | bar(t) |
827 | } | 826 | } |
828 | 827 | ||
829 | fn bar<T>(t: T) ${0:-> ()} { | 828 | fn bar(t: T) ${0:-> ()} { |
830 | todo!() | 829 | todo!() |
831 | } | 830 | } |
832 | ", | 831 | ", |
@@ -834,9 +833,8 @@ fn bar<T>(t: T) ${0:-> ()} { | |||
834 | } | 833 | } |
835 | 834 | ||
836 | #[test] | 835 | #[test] |
837 | #[ignore] | ||
838 | // FIXME Fix function type printing to make this test pass | ||
839 | fn add_function_with_fn_arg() { | 836 | fn add_function_with_fn_arg() { |
837 | // FIXME: The argument in `bar` is wrong. | ||
840 | check_assist( | 838 | check_assist( |
841 | generate_function, | 839 | generate_function, |
842 | r" | 840 | r" |
@@ -857,7 +855,7 @@ fn foo() { | |||
857 | bar(Baz::new); | 855 | bar(Baz::new); |
858 | } | 856 | } |
859 | 857 | ||
860 | fn bar(arg: fn() -> Baz) ${0:-> ()} { | 858 | fn bar(new: fn) ${0:-> ()} { |
861 | todo!() | 859 | todo!() |
862 | } | 860 | } |
863 | ", | 861 | ", |
@@ -865,9 +863,8 @@ fn bar(arg: fn() -> Baz) ${0:-> ()} { | |||
865 | } | 863 | } |
866 | 864 | ||
867 | #[test] | 865 | #[test] |
868 | #[ignore] | ||
869 | // FIXME Fix closure type printing to make this test pass | ||
870 | fn add_function_with_closure_arg() { | 866 | fn add_function_with_closure_arg() { |
867 | // FIXME: The argument in `bar` is wrong. | ||
871 | check_assist( | 868 | check_assist( |
872 | generate_function, | 869 | generate_function, |
873 | r" | 870 | r" |
@@ -882,7 +879,7 @@ fn foo() { | |||
882 | bar(closure) | 879 | bar(closure) |
883 | } | 880 | } |
884 | 881 | ||
885 | fn bar(closure: impl Fn(i64) -> i64) ${0:-> ()} { | 882 | fn bar(closure: ()) ${0:-> ()} { |
886 | todo!() | 883 | todo!() |
887 | } | 884 | } |
888 | ", | 885 | ", |
@@ -986,13 +983,10 @@ fn foo() { | |||
986 | } | 983 | } |
987 | 984 | ||
988 | #[test] | 985 | #[test] |
989 | #[ignore] | ||
990 | // Ignored until local imports are supported. | ||
991 | // See https://github.com/rust-analyzer/rust-analyzer/issues/1165 | ||
992 | fn qualified_path_uses_correct_scope() { | 986 | fn qualified_path_uses_correct_scope() { |
993 | check_assist( | 987 | check_assist( |
994 | generate_function, | 988 | generate_function, |
995 | " | 989 | r#" |
996 | mod foo { | 990 | mod foo { |
997 | pub struct Foo; | 991 | pub struct Foo; |
998 | } | 992 | } |
@@ -1001,8 +995,8 @@ fn bar() { | |||
1001 | let foo = Foo; | 995 | let foo = Foo; |
1002 | baz$0(foo) | 996 | baz$0(foo) |
1003 | } | 997 | } |
1004 | ", | 998 | "#, |
1005 | " | 999 | r#" |
1006 | mod foo { | 1000 | mod foo { |
1007 | pub struct Foo; | 1001 | pub struct Foo; |
1008 | } | 1002 | } |
@@ -1015,7 +1009,7 @@ fn bar() { | |||
1015 | fn baz(foo: foo::Foo) ${0:-> ()} { | 1009 | fn baz(foo: foo::Foo) ${0:-> ()} { |
1016 | todo!() | 1010 | todo!() |
1017 | } | 1011 | } |
1018 | ", | 1012 | "#, |
1019 | ) | 1013 | ) |
1020 | } | 1014 | } |
1021 | 1015 | ||
@@ -1141,40 +1135,29 @@ fn bar() {} | |||
1141 | // The assist is only active if the cursor is on an unresolved path, | 1135 | // The assist is only active if the cursor is on an unresolved path, |
1142 | // but the assist should only be offered if the path is a function call. | 1136 | // but the assist should only be offered if the path is a function call. |
1143 | generate_function, | 1137 | generate_function, |
1144 | r" | 1138 | r#" |
1145 | fn foo() { | 1139 | fn foo() { |
1146 | bar(b$0az); | 1140 | bar(b$0az); |
1147 | } | 1141 | } |
1148 | 1142 | ||
1149 | fn bar(baz: ()) {} | 1143 | fn bar(baz: ()) {} |
1150 | ", | 1144 | "#, |
1151 | ) | 1145 | ) |
1152 | } | 1146 | } |
1153 | 1147 | ||
1154 | #[test] | 1148 | #[test] |
1155 | #[ignore] | ||
1156 | fn create_method_with_no_args() { | 1149 | fn create_method_with_no_args() { |
1157 | check_assist( | 1150 | // FIXME: This is wrong, this should just work. |
1151 | check_assist_not_applicable( | ||
1158 | generate_function, | 1152 | generate_function, |
1159 | r" | 1153 | r#" |
1160 | struct Foo; | 1154 | struct Foo; |
1161 | impl Foo { | 1155 | impl Foo { |
1162 | fn foo(&self) { | 1156 | fn foo(&self) { |
1163 | self.bar()$0; | 1157 | self.bar()$0; |
1164 | } | 1158 | } |
1165 | } | 1159 | } |
1166 | ", | 1160 | "#, |
1167 | r" | ||
1168 | struct Foo; | ||
1169 | impl Foo { | ||
1170 | fn foo(&self) { | ||
1171 | self.bar(); | ||
1172 | } | ||
1173 | fn bar(&self) { | ||
1174 | todo!(); | ||
1175 | } | ||
1176 | } | ||
1177 | ", | ||
1178 | ) | 1161 | ) |
1179 | } | 1162 | } |
1180 | } | 1163 | } |
diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs index f91770a76..1d7be183a 100644 --- a/crates/ide_assists/src/handlers/qualify_path.rs +++ b/crates/ide_assists/src/handlers/qualify_path.rs | |||
@@ -216,28 +216,28 @@ mod tests { | |||
216 | cov_mark::check!(qualify_path_unqualified_name); | 216 | cov_mark::check!(qualify_path_unqualified_name); |
217 | check_assist( | 217 | check_assist( |
218 | qualify_path, | 218 | qualify_path, |
219 | r" | 219 | r#" |
220 | mod std { | 220 | mod std { |
221 | pub mod fmt { | 221 | pub mod fmt { |
222 | pub struct Formatter; | 222 | pub struct Formatter; |
223 | } | 223 | } |
224 | } | 224 | } |
225 | 225 | ||
226 | use std::fmt; | 226 | use std::fmt; |
227 | 227 | ||
228 | $0Formatter | 228 | $0Formatter |
229 | ", | 229 | "#, |
230 | r" | 230 | r#" |
231 | mod std { | 231 | mod std { |
232 | pub mod fmt { | 232 | pub mod fmt { |
233 | pub struct Formatter; | 233 | pub struct Formatter; |
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
237 | use std::fmt; | 237 | use std::fmt; |
238 | 238 | ||
239 | fmt::Formatter | 239 | fmt::Formatter |
240 | ", | 240 | "#, |
241 | ); | 241 | ); |
242 | } | 242 | } |
243 | 243 | ||
@@ -245,20 +245,20 @@ mod tests { | |||
245 | fn applicable_when_found_an_import() { | 245 | fn applicable_when_found_an_import() { |
246 | check_assist( | 246 | check_assist( |
247 | qualify_path, | 247 | qualify_path, |
248 | r" | 248 | r#" |
249 | $0PubStruct | 249 | $0PubStruct |
250 | 250 | ||
251 | pub mod PubMod { | 251 | pub mod PubMod { |
252 | pub struct PubStruct; | 252 | pub struct PubStruct; |
253 | } | 253 | } |
254 | ", | 254 | "#, |
255 | r" | 255 | r#" |
256 | PubMod::PubStruct | 256 | PubMod::PubStruct |
257 | 257 | ||
258 | pub mod PubMod { | 258 | pub mod PubMod { |
259 | pub struct PubStruct; | 259 | pub struct PubStruct; |
260 | } | 260 | } |
261 | ", | 261 | "#, |
262 | ); | 262 | ); |
263 | } | 263 | } |
264 | 264 | ||
@@ -266,26 +266,26 @@ mod tests { | |||
266 | fn applicable_in_macros() { | 266 | fn applicable_in_macros() { |
267 | check_assist( | 267 | check_assist( |
268 | qualify_path, | 268 | qualify_path, |
269 | r" | 269 | r#" |
270 | macro_rules! foo { | 270 | macro_rules! foo { |
271 | ($i:ident) => { fn foo(a: $i) {} } | 271 | ($i:ident) => { fn foo(a: $i) {} } |
272 | } | 272 | } |
273 | foo!(Pub$0Struct); | 273 | foo!(Pub$0Struct); |
274 | 274 | ||
275 | pub mod PubMod { | 275 | pub mod PubMod { |
276 | pub struct PubStruct; | 276 | pub struct PubStruct; |
277 | } | 277 | } |
278 | ", | 278 | "#, |
279 | r" | 279 | r#" |
280 | macro_rules! foo { | 280 | macro_rules! foo { |
281 | ($i:ident) => { fn foo(a: $i) {} } | 281 | ($i:ident) => { fn foo(a: $i) {} } |
282 | } | 282 | } |
283 | foo!(PubMod::PubStruct); | 283 | foo!(PubMod::PubStruct); |
284 | 284 | ||
285 | pub mod PubMod { | 285 | pub mod PubMod { |
286 | pub struct PubStruct; | 286 | pub struct PubStruct; |
287 | } | 287 | } |
288 | ", | 288 | "#, |
289 | ); | 289 | ); |
290 | } | 290 | } |
291 | 291 | ||
@@ -293,32 +293,32 @@ mod tests { | |||
293 | fn applicable_when_found_multiple_imports() { | 293 | fn applicable_when_found_multiple_imports() { |
294 | check_assist( | 294 | check_assist( |
295 | qualify_path, | 295 | qualify_path, |
296 | r" | 296 | r#" |
297 | PubSt$0ruct | 297 | PubSt$0ruct |
298 | 298 | ||
299 | pub mod PubMod1 { | 299 | pub mod PubMod1 { |
300 | pub struct PubStruct; | 300 | pub struct PubStruct; |
301 | } | 301 | } |
302 | pub mod PubMod2 { | 302 | pub mod PubMod2 { |
303 | pub struct PubStruct; | 303 | pub struct PubStruct; |
304 | } | 304 | } |
305 | pub mod PubMod3 { | 305 | pub mod PubMod3 { |
306 | pub struct PubStruct; | 306 | pub struct PubStruct; |
307 | } | 307 | } |
308 | ", | 308 | "#, |
309 | r" | 309 | r#" |
310 | PubMod3::PubStruct | 310 | PubMod3::PubStruct |
311 | 311 | ||
312 | pub mod PubMod1 { | 312 | pub mod PubMod1 { |
313 | pub struct PubStruct; | 313 | pub struct PubStruct; |
314 | } | 314 | } |
315 | pub mod PubMod2 { | 315 | pub mod PubMod2 { |
316 | pub struct PubStruct; | 316 | pub struct PubStruct; |
317 | } | 317 | } |
318 | pub mod PubMod3 { | 318 | pub mod PubMod3 { |
319 | pub struct PubStruct; | 319 | pub struct PubStruct; |
320 | } | 320 | } |
321 | ", | 321 | "#, |
322 | ); | 322 | ); |
323 | } | 323 | } |
324 | 324 | ||
@@ -326,15 +326,15 @@ mod tests { | |||
326 | fn not_applicable_for_already_imported_types() { | 326 | fn not_applicable_for_already_imported_types() { |
327 | check_assist_not_applicable( | 327 | check_assist_not_applicable( |
328 | qualify_path, | 328 | qualify_path, |
329 | r" | 329 | r#" |
330 | use PubMod::PubStruct; | 330 | use PubMod::PubStruct; |
331 | 331 | ||
332 | PubStruct$0 | 332 | PubStruct$0 |
333 | 333 | ||
334 | pub mod PubMod { | 334 | pub mod PubMod { |
335 | pub struct PubStruct; | 335 | pub struct PubStruct; |
336 | } | 336 | } |
337 | ", | 337 | "#, |
338 | ); | 338 | ); |
339 | } | 339 | } |
340 | 340 | ||
@@ -342,35 +342,32 @@ mod tests { | |||
342 | fn not_applicable_for_types_with_private_paths() { | 342 | fn not_applicable_for_types_with_private_paths() { |
343 | check_assist_not_applicable( | 343 | check_assist_not_applicable( |
344 | qualify_path, | 344 | qualify_path, |
345 | r" | 345 | r#" |
346 | PrivateStruct$0 | 346 | PrivateStruct$0 |
347 | 347 | ||
348 | pub mod PubMod { | 348 | pub mod PubMod { |
349 | struct PrivateStruct; | 349 | struct PrivateStruct; |
350 | } | 350 | } |
351 | ", | 351 | "#, |
352 | ); | 352 | ); |
353 | } | 353 | } |
354 | 354 | ||
355 | #[test] | 355 | #[test] |
356 | fn not_applicable_when_no_imports_found() { | 356 | fn not_applicable_when_no_imports_found() { |
357 | check_assist_not_applicable( | 357 | check_assist_not_applicable(qualify_path, r#"PubStruct$0"#); |
358 | qualify_path, | ||
359 | " | ||
360 | PubStruct$0", | ||
361 | ); | ||
362 | } | 358 | } |
363 | 359 | ||
364 | #[test] | 360 | #[test] |
365 | fn not_applicable_in_import_statements() { | 361 | fn not_applicable_in_import_statements() { |
366 | check_assist_not_applicable( | 362 | check_assist_not_applicable( |
367 | qualify_path, | 363 | qualify_path, |
368 | r" | 364 | r#" |
369 | use PubStruct$0; | 365 | use PubStruct$0; |
370 | 366 | ||
371 | pub mod PubMod { | 367 | pub mod PubMod { |
372 | pub struct PubStruct; | 368 | pub struct PubStruct; |
373 | }", | 369 | } |
370 | "#, | ||
374 | ); | 371 | ); |
375 | } | 372 | } |
376 | 373 | ||
@@ -378,20 +375,20 @@ mod tests { | |||
378 | fn qualify_function() { | 375 | fn qualify_function() { |
379 | check_assist( | 376 | check_assist( |
380 | qualify_path, | 377 | qualify_path, |
381 | r" | 378 | r#" |
382 | test_function$0 | 379 | test_function$0 |
383 | 380 | ||
384 | pub mod PubMod { | 381 | pub mod PubMod { |
385 | pub fn test_function() {}; | 382 | pub fn test_function() {}; |
386 | } | 383 | } |
387 | ", | 384 | "#, |
388 | r" | 385 | r#" |
389 | PubMod::test_function | 386 | PubMod::test_function |
390 | 387 | ||
391 | pub mod PubMod { | 388 | pub mod PubMod { |
392 | pub fn test_function() {}; | 389 | pub fn test_function() {}; |
393 | } | 390 | } |
394 | ", | 391 | "#, |
395 | ); | 392 | ); |
396 | } | 393 | } |
397 | 394 | ||
@@ -399,7 +396,7 @@ mod tests { | |||
399 | fn qualify_macro() { | 396 | fn qualify_macro() { |
400 | check_assist( | 397 | check_assist( |
401 | qualify_path, | 398 | qualify_path, |
402 | r" | 399 | r#" |
403 | //- /lib.rs crate:crate_with_macro | 400 | //- /lib.rs crate:crate_with_macro |
404 | #[macro_export] | 401 | #[macro_export] |
405 | macro_rules! foo { | 402 | macro_rules! foo { |
@@ -410,12 +407,12 @@ macro_rules! foo { | |||
410 | fn main() { | 407 | fn main() { |
411 | foo$0 | 408 | foo$0 |
412 | } | 409 | } |
413 | ", | 410 | "#, |
414 | r" | 411 | r#" |
415 | fn main() { | 412 | fn main() { |
416 | crate_with_macro::foo | 413 | crate_with_macro::foo |
417 | } | 414 | } |
418 | ", | 415 | "#, |
419 | ); | 416 | ); |
420 | } | 417 | } |
421 | 418 | ||
@@ -423,13 +420,13 @@ fn main() { | |||
423 | fn qualify_path_target() { | 420 | fn qualify_path_target() { |
424 | check_assist_target( | 421 | check_assist_target( |
425 | qualify_path, | 422 | qualify_path, |
426 | r" | 423 | r#" |
427 | struct AssistInfo { | 424 | struct AssistInfo { |
428 | group_label: Option<$0GroupLabel>, | 425 | group_label: Option<$0GroupLabel>, |
429 | } | 426 | } |
430 | 427 | ||
431 | mod m { pub struct GroupLabel; } | 428 | mod m { pub struct GroupLabel; } |
432 | ", | 429 | "#, |
433 | "GroupLabel", | 430 | "GroupLabel", |
434 | ) | 431 | ) |
435 | } | 432 | } |
@@ -438,20 +435,20 @@ fn main() { | |||
438 | fn not_applicable_when_path_start_is_imported() { | 435 | fn not_applicable_when_path_start_is_imported() { |
439 | check_assist_not_applicable( | 436 | check_assist_not_applicable( |
440 | qualify_path, | 437 | qualify_path, |
441 | r" | 438 | r#" |
442 | pub mod mod1 { | 439 | pub mod mod1 { |
443 | pub mod mod2 { | 440 | pub mod mod2 { |
444 | pub mod mod3 { | 441 | pub mod mod3 { |
445 | pub struct TestStruct; | 442 | pub struct TestStruct; |
446 | } | 443 | } |
447 | } | 444 | } |
448 | } | 445 | } |
449 | 446 | ||
450 | use mod1::mod2; | 447 | use mod1::mod2; |
451 | fn main() { | 448 | fn main() { |
452 | mod2::mod3::TestStruct$0 | 449 | mod2::mod3::TestStruct$0 |
453 | } | 450 | } |
454 | ", | 451 | "#, |
455 | ); | 452 | ); |
456 | } | 453 | } |
457 | 454 | ||
@@ -459,16 +456,16 @@ fn main() { | |||
459 | fn not_applicable_for_imported_function() { | 456 | fn not_applicable_for_imported_function() { |
460 | check_assist_not_applicable( | 457 | check_assist_not_applicable( |
461 | qualify_path, | 458 | qualify_path, |
462 | r" | 459 | r#" |
463 | pub mod test_mod { | 460 | pub mod test_mod { |
464 | pub fn test_function() {} | 461 | pub fn test_function() {} |
465 | } | 462 | } |
466 | 463 | ||
467 | use test_mod::test_function; | 464 | use test_mod::test_function; |
468 | fn main() { | 465 | fn main() { |
469 | test_function$0 | 466 | test_function$0 |
470 | } | 467 | } |
471 | ", | 468 | "#, |
472 | ); | 469 | ); |
473 | } | 470 | } |
474 | 471 | ||
@@ -476,30 +473,30 @@ fn main() { | |||
476 | fn associated_struct_function() { | 473 | fn associated_struct_function() { |
477 | check_assist( | 474 | check_assist( |
478 | qualify_path, | 475 | qualify_path, |
479 | r" | 476 | r#" |
480 | mod test_mod { | 477 | mod test_mod { |
481 | pub struct TestStruct {} | 478 | pub struct TestStruct {} |
482 | impl TestStruct { | 479 | impl TestStruct { |
483 | pub fn test_function() {} | 480 | pub fn test_function() {} |
484 | } | 481 | } |
485 | } | 482 | } |
486 | 483 | ||
487 | fn main() { | 484 | fn main() { |
488 | TestStruct::test_function$0 | 485 | TestStruct::test_function$0 |
489 | } | 486 | } |
490 | ", | 487 | "#, |
491 | r" | 488 | r#" |
492 | mod test_mod { | 489 | mod test_mod { |
493 | pub struct TestStruct {} | 490 | pub struct TestStruct {} |
494 | impl TestStruct { | 491 | impl TestStruct { |
495 | pub fn test_function() {} | 492 | pub fn test_function() {} |
496 | } | 493 | } |
497 | } | 494 | } |
498 | 495 | ||
499 | fn main() { | 496 | fn main() { |
500 | test_mod::TestStruct::test_function | 497 | test_mod::TestStruct::test_function |
501 | } | 498 | } |
502 | ", | 499 | "#, |
503 | ); | 500 | ); |
504 | } | 501 | } |
505 | 502 | ||
@@ -508,62 +505,50 @@ fn main() { | |||
508 | cov_mark::check!(qualify_path_qualifier_start); | 505 | cov_mark::check!(qualify_path_qualifier_start); |
509 | check_assist( | 506 | check_assist( |
510 | qualify_path, | 507 | qualify_path, |
511 | r" | 508 | r#" |
512 | mod test_mod { | 509 | mod test_mod { |
513 | pub struct TestStruct {} | 510 | pub struct TestStruct {} |
514 | impl TestStruct { | 511 | impl TestStruct { |
515 | const TEST_CONST: u8 = 42; | 512 | const TEST_CONST: u8 = 42; |
516 | } | 513 | } |
517 | } | 514 | } |
518 | 515 | ||
519 | fn main() { | 516 | fn main() { |
520 | TestStruct::TEST_CONST$0 | 517 | TestStruct::TEST_CONST$0 |
521 | } | 518 | } |
522 | ", | 519 | "#, |
523 | r" | 520 | r#" |
524 | mod test_mod { | 521 | mod test_mod { |
525 | pub struct TestStruct {} | 522 | pub struct TestStruct {} |
526 | impl TestStruct { | 523 | impl TestStruct { |
527 | const TEST_CONST: u8 = 42; | 524 | const TEST_CONST: u8 = 42; |
528 | } | 525 | } |
529 | } | 526 | } |
530 | 527 | ||
531 | fn main() { | 528 | fn main() { |
532 | test_mod::TestStruct::TEST_CONST | 529 | test_mod::TestStruct::TEST_CONST |
533 | } | 530 | } |
534 | ", | 531 | "#, |
535 | ); | 532 | ); |
536 | } | 533 | } |
537 | 534 | ||
538 | #[test] | 535 | #[test] |
539 | #[ignore = "FIXME: non-trait assoc items completion is unsupported yet, see FIXME in the import_assets.rs for more details"] | ||
540 | fn associated_struct_const_unqualified() { | 536 | fn associated_struct_const_unqualified() { |
541 | check_assist( | 537 | // FIXME: non-trait assoc items completion is unsupported yet, see FIXME in the import_assets.rs for more details |
538 | check_assist_not_applicable( | ||
542 | qualify_path, | 539 | qualify_path, |
543 | r" | 540 | r#" |
544 | mod test_mod { | 541 | mod test_mod { |
545 | pub struct TestStruct {} | 542 | pub struct TestStruct {} |
546 | impl TestStruct { | 543 | impl TestStruct { |
547 | const TEST_CONST: u8 = 42; | 544 | const TEST_CONST: u8 = 42; |
548 | } | 545 | } |
549 | } | 546 | } |
550 | |||
551 | fn main() { | ||
552 | TEST_CONST$0 | ||
553 | } | ||
554 | ", | ||
555 | r" | ||
556 | mod test_mod { | ||
557 | pub struct TestStruct {} | ||
558 | impl TestStruct { | ||
559 | const TEST_CONST: u8 = 42; | ||
560 | } | ||
561 | } | ||
562 | 547 | ||
563 | fn main() { | 548 | fn main() { |
564 | test_mod::TestStruct::TEST_CONST | 549 | TEST_CONST$0 |
565 | } | 550 | } |
566 | ", | 551 | "#, |
567 | ); | 552 | ); |
568 | } | 553 | } |
569 | 554 | ||
@@ -571,36 +556,36 @@ fn main() { | |||
571 | fn associated_trait_function() { | 556 | fn associated_trait_function() { |
572 | check_assist( | 557 | check_assist( |
573 | qualify_path, | 558 | qualify_path, |
574 | r" | 559 | r#" |
575 | mod test_mod { | 560 | mod test_mod { |
576 | pub trait TestTrait { | 561 | pub trait TestTrait { |
577 | fn test_function(); | 562 | fn test_function(); |
578 | } | 563 | } |
579 | pub struct TestStruct {} | 564 | pub struct TestStruct {} |
580 | impl TestTrait for TestStruct { | 565 | impl TestTrait for TestStruct { |
581 | fn test_function() {} | 566 | fn test_function() {} |
582 | } | 567 | } |
583 | } | 568 | } |
584 | 569 | ||
585 | fn main() { | 570 | fn main() { |
586 | test_mod::TestStruct::test_function$0 | 571 | test_mod::TestStruct::test_function$0 |
587 | } | 572 | } |
588 | ", | 573 | "#, |
589 | r" | 574 | r#" |
590 | mod test_mod { | 575 | mod test_mod { |
591 | pub trait TestTrait { | 576 | pub trait TestTrait { |
592 | fn test_function(); | 577 | fn test_function(); |
593 | } | 578 | } |
594 | pub struct TestStruct {} | 579 | pub struct TestStruct {} |
595 | impl TestTrait for TestStruct { | 580 | impl TestTrait for TestStruct { |
596 | fn test_function() {} | 581 | fn test_function() {} |
597 | } | 582 | } |
598 | } | 583 | } |
599 | 584 | ||
600 | fn main() { | 585 | fn main() { |
601 | <test_mod::TestStruct as test_mod::TestTrait>::test_function | 586 | <test_mod::TestStruct as test_mod::TestTrait>::test_function |
602 | } | 587 | } |
603 | ", | 588 | "#, |
604 | ); | 589 | ); |
605 | } | 590 | } |
606 | 591 | ||
@@ -608,31 +593,31 @@ fn main() { | |||
608 | fn not_applicable_for_imported_trait_for_function() { | 593 | fn not_applicable_for_imported_trait_for_function() { |
609 | check_assist_not_applicable( | 594 | check_assist_not_applicable( |
610 | qualify_path, | 595 | qualify_path, |
611 | r" | 596 | r#" |
612 | mod test_mod { | 597 | mod test_mod { |
613 | pub trait TestTrait { | 598 | pub trait TestTrait { |
614 | fn test_function(); | 599 | fn test_function(); |
615 | } | 600 | } |
616 | pub trait TestTrait2 { | 601 | pub trait TestTrait2 { |
617 | fn test_function(); | 602 | fn test_function(); |
618 | } | 603 | } |
619 | pub enum TestEnum { | 604 | pub enum TestEnum { |
620 | One, | 605 | One, |
621 | Two, | 606 | Two, |
622 | } | 607 | } |
623 | impl TestTrait2 for TestEnum { | 608 | impl TestTrait2 for TestEnum { |
624 | fn test_function() {} | 609 | fn test_function() {} |
625 | } | 610 | } |
626 | impl TestTrait for TestEnum { | 611 | impl TestTrait for TestEnum { |
627 | fn test_function() {} | 612 | fn test_function() {} |
628 | } | 613 | } |
629 | } | 614 | } |
630 | 615 | ||
631 | use test_mod::TestTrait2; | 616 | use test_mod::TestTrait2; |
632 | fn main() { | 617 | fn main() { |
633 | test_mod::TestEnum::test_function$0; | 618 | test_mod::TestEnum::test_function$0; |
634 | } | 619 | } |
635 | ", | 620 | "#, |
636 | ) | 621 | ) |
637 | } | 622 | } |
638 | 623 | ||
@@ -641,36 +626,36 @@ fn main() { | |||
641 | cov_mark::check!(qualify_path_trait_assoc_item); | 626 | cov_mark::check!(qualify_path_trait_assoc_item); |
642 | check_assist( | 627 | check_assist( |
643 | qualify_path, | 628 | qualify_path, |
644 | r" | 629 | r#" |
645 | mod test_mod { | 630 | mod test_mod { |
646 | pub trait TestTrait { | 631 | pub trait TestTrait { |
647 | const TEST_CONST: u8; | 632 | const TEST_CONST: u8; |
648 | } | 633 | } |
649 | pub struct TestStruct {} | 634 | pub struct TestStruct {} |
650 | impl TestTrait for TestStruct { | 635 | impl TestTrait for TestStruct { |
651 | const TEST_CONST: u8 = 42; | 636 | const TEST_CONST: u8 = 42; |
652 | } | 637 | } |
653 | } | 638 | } |
654 | 639 | ||
655 | fn main() { | 640 | fn main() { |
656 | test_mod::TestStruct::TEST_CONST$0 | 641 | test_mod::TestStruct::TEST_CONST$0 |
657 | } | 642 | } |
658 | ", | 643 | "#, |
659 | r" | 644 | r#" |
660 | mod test_mod { | 645 | mod test_mod { |
661 | pub trait TestTrait { | 646 | pub trait TestTrait { |
662 | const TEST_CONST: u8; | 647 | const TEST_CONST: u8; |
663 | } | 648 | } |
664 | pub struct TestStruct {} | 649 | pub struct TestStruct {} |
665 | impl TestTrait for TestStruct { | 650 | impl TestTrait for TestStruct { |
666 | const TEST_CONST: u8 = 42; | 651 | const TEST_CONST: u8 = 42; |
667 | } | 652 | } |
668 | } | 653 | } |
669 | 654 | ||
670 | fn main() { | 655 | fn main() { |
671 | <test_mod::TestStruct as test_mod::TestTrait>::TEST_CONST | 656 | <test_mod::TestStruct as test_mod::TestTrait>::TEST_CONST |
672 | } | 657 | } |
673 | ", | 658 | "#, |
674 | ); | 659 | ); |
675 | } | 660 | } |
676 | 661 | ||
@@ -678,31 +663,31 @@ fn main() { | |||
678 | fn not_applicable_for_imported_trait_for_const() { | 663 | fn not_applicable_for_imported_trait_for_const() { |
679 | check_assist_not_applicable( | 664 | check_assist_not_applicable( |
680 | qualify_path, | 665 | qualify_path, |
681 | r" | 666 | r#" |
682 | mod test_mod { | 667 | mod test_mod { |
683 | pub trait TestTrait { | 668 | pub trait TestTrait { |
684 | const TEST_CONST: u8; | 669 | const TEST_CONST: u8; |
685 | } | 670 | } |
686 | pub trait TestTrait2 { | 671 | pub trait TestTrait2 { |
687 | const TEST_CONST: f64; | 672 | const TEST_CONST: f64; |
688 | } | 673 | } |
689 | pub enum TestEnum { | 674 | pub enum TestEnum { |
690 | One, | 675 | One, |
691 | Two, | 676 | Two, |
692 | } | 677 | } |
693 | impl TestTrait2 for TestEnum { | 678 | impl TestTrait2 for TestEnum { |
694 | const TEST_CONST: f64 = 42.0; | 679 | const TEST_CONST: f64 = 42.0; |
695 | } | 680 | } |
696 | impl TestTrait for TestEnum { | 681 | impl TestTrait for TestEnum { |
697 | const TEST_CONST: u8 = 42; | 682 | const TEST_CONST: u8 = 42; |
698 | } | 683 | } |
699 | } | 684 | } |
700 | 685 | ||
701 | use test_mod::TestTrait2; | 686 | use test_mod::TestTrait2; |
702 | fn main() { | 687 | fn main() { |
703 | test_mod::TestEnum::TEST_CONST$0; | 688 | test_mod::TestEnum::TEST_CONST$0; |
704 | } | 689 | } |
705 | ", | 690 | "#, |
706 | ) | 691 | ) |
707 | } | 692 | } |
708 | 693 | ||
@@ -711,38 +696,38 @@ fn main() { | |||
711 | cov_mark::check!(qualify_path_trait_method); | 696 | cov_mark::check!(qualify_path_trait_method); |
712 | check_assist( | 697 | check_assist( |
713 | qualify_path, | 698 | qualify_path, |
714 | r" | 699 | r#" |
715 | mod test_mod { | 700 | mod test_mod { |
716 | pub trait TestTrait { | 701 | pub trait TestTrait { |
717 | fn test_method(&self); | 702 | fn test_method(&self); |
718 | } | 703 | } |
719 | pub struct TestStruct {} | 704 | pub struct TestStruct {} |
720 | impl TestTrait for TestStruct { | 705 | impl TestTrait for TestStruct { |
721 | fn test_method(&self) {} | 706 | fn test_method(&self) {} |
722 | } | 707 | } |
723 | } | 708 | } |
724 | 709 | ||
725 | fn main() { | 710 | fn main() { |
726 | let test_struct = test_mod::TestStruct {}; | 711 | let test_struct = test_mod::TestStruct {}; |
727 | test_struct.test_meth$0od() | 712 | test_struct.test_meth$0od() |
728 | } | 713 | } |
729 | ", | 714 | "#, |
730 | r" | 715 | r#" |
731 | mod test_mod { | 716 | mod test_mod { |
732 | pub trait TestTrait { | 717 | pub trait TestTrait { |
733 | fn test_method(&self); | 718 | fn test_method(&self); |
734 | } | 719 | } |
735 | pub struct TestStruct {} | 720 | pub struct TestStruct {} |
736 | impl TestTrait for TestStruct { | 721 | impl TestTrait for TestStruct { |
737 | fn test_method(&self) {} | 722 | fn test_method(&self) {} |
738 | } | 723 | } |
739 | } | 724 | } |
740 | 725 | ||
741 | fn main() { | 726 | fn main() { |
742 | let test_struct = test_mod::TestStruct {}; | 727 | let test_struct = test_mod::TestStruct {}; |
743 | test_mod::TestTrait::test_method(&test_struct) | 728 | test_mod::TestTrait::test_method(&test_struct) |
744 | } | 729 | } |
745 | ", | 730 | "#, |
746 | ); | 731 | ); |
747 | } | 732 | } |
748 | 733 | ||
@@ -750,38 +735,38 @@ fn main() { | |||
750 | fn trait_method_multi_params() { | 735 | fn trait_method_multi_params() { |
751 | check_assist( | 736 | check_assist( |
752 | qualify_path, | 737 | qualify_path, |
753 | r" | 738 | r#" |
754 | mod test_mod { | 739 | mod test_mod { |
755 | pub trait TestTrait { | 740 | pub trait TestTrait { |
756 | fn test_method(&self, test: i32); | 741 | fn test_method(&self, test: i32); |
757 | } | 742 | } |
758 | pub struct TestStruct {} | 743 | pub struct TestStruct {} |
759 | impl TestTrait for TestStruct { | 744 | impl TestTrait for TestStruct { |
760 | fn test_method(&self, test: i32) {} | 745 | fn test_method(&self, test: i32) {} |
761 | } | 746 | } |
762 | } | 747 | } |
763 | 748 | ||
764 | fn main() { | 749 | fn main() { |
765 | let test_struct = test_mod::TestStruct {}; | 750 | let test_struct = test_mod::TestStruct {}; |
766 | test_struct.test_meth$0od(42) | 751 | test_struct.test_meth$0od(42) |
767 | } | 752 | } |
768 | ", | 753 | "#, |
769 | r" | 754 | r#" |
770 | mod test_mod { | 755 | mod test_mod { |
771 | pub trait TestTrait { | 756 | pub trait TestTrait { |
772 | fn test_method(&self, test: i32); | 757 | fn test_method(&self, test: i32); |
773 | } | 758 | } |
774 | pub struct TestStruct {} | 759 | pub struct TestStruct {} |
775 | impl TestTrait for TestStruct { | 760 | impl TestTrait for TestStruct { |
776 | fn test_method(&self, test: i32) {} | 761 | fn test_method(&self, test: i32) {} |
777 | } | 762 | } |
778 | } | 763 | } |
779 | 764 | ||
780 | fn main() { | 765 | fn main() { |
781 | let test_struct = test_mod::TestStruct {}; | 766 | let test_struct = test_mod::TestStruct {}; |
782 | test_mod::TestTrait::test_method(&test_struct, 42) | 767 | test_mod::TestTrait::test_method(&test_struct, 42) |
783 | } | 768 | } |
784 | ", | 769 | "#, |
785 | ); | 770 | ); |
786 | } | 771 | } |
787 | 772 | ||
@@ -789,38 +774,38 @@ fn main() { | |||
789 | fn trait_method_consume() { | 774 | fn trait_method_consume() { |
790 | check_assist( | 775 | check_assist( |
791 | qualify_path, | 776 | qualify_path, |
792 | r" | 777 | r#" |
793 | mod test_mod { | 778 | mod test_mod { |
794 | pub trait TestTrait { | 779 | pub trait TestTrait { |
795 | fn test_method(self); | 780 | fn test_method(self); |
796 | } | 781 | } |
797 | pub struct TestStruct {} | 782 | pub struct TestStruct {} |
798 | impl TestTrait for TestStruct { | 783 | impl TestTrait for TestStruct { |
799 | fn test_method(self) {} | 784 | fn test_method(self) {} |
800 | } | 785 | } |
801 | } | 786 | } |
802 | 787 | ||
803 | fn main() { | 788 | fn main() { |
804 | let test_struct = test_mod::TestStruct {}; | 789 | let test_struct = test_mod::TestStruct {}; |
805 | test_struct.test_meth$0od() | 790 | test_struct.test_meth$0od() |
806 | } | 791 | } |
807 | ", | 792 | "#, |
808 | r" | 793 | r#" |
809 | mod test_mod { | 794 | mod test_mod { |
810 | pub trait TestTrait { | 795 | pub trait TestTrait { |
811 | fn test_method(self); | 796 | fn test_method(self); |
812 | } | 797 | } |
813 | pub struct TestStruct {} | 798 | pub struct TestStruct {} |
814 | impl TestTrait for TestStruct { | 799 | impl TestTrait for TestStruct { |
815 | fn test_method(self) {} | 800 | fn test_method(self) {} |
816 | } | 801 | } |
817 | } | 802 | } |
818 | 803 | ||
819 | fn main() { | 804 | fn main() { |
820 | let test_struct = test_mod::TestStruct {}; | 805 | let test_struct = test_mod::TestStruct {}; |
821 | test_mod::TestTrait::test_method(test_struct) | 806 | test_mod::TestTrait::test_method(test_struct) |
822 | } | 807 | } |
823 | ", | 808 | "#, |
824 | ); | 809 | ); |
825 | } | 810 | } |
826 | 811 | ||
@@ -828,29 +813,29 @@ fn main() { | |||
828 | fn trait_method_cross_crate() { | 813 | fn trait_method_cross_crate() { |
829 | check_assist( | 814 | check_assist( |
830 | qualify_path, | 815 | qualify_path, |
831 | r" | 816 | r#" |
832 | //- /main.rs crate:main deps:dep | 817 | //- /main.rs crate:main deps:dep |
833 | fn main() { | 818 | fn main() { |
834 | let test_struct = dep::test_mod::TestStruct {}; | 819 | let test_struct = dep::test_mod::TestStruct {}; |
835 | test_struct.test_meth$0od() | 820 | test_struct.test_meth$0od() |
836 | } | 821 | } |
837 | //- /dep.rs crate:dep | 822 | //- /dep.rs crate:dep |
838 | pub mod test_mod { | 823 | pub mod test_mod { |
839 | pub trait TestTrait { | 824 | pub trait TestTrait { |
840 | fn test_method(&self); | 825 | fn test_method(&self); |
841 | } | 826 | } |
842 | pub struct TestStruct {} | 827 | pub struct TestStruct {} |
843 | impl TestTrait for TestStruct { | 828 | impl TestTrait for TestStruct { |
844 | fn test_method(&self) {} | 829 | fn test_method(&self) {} |
845 | } | 830 | } |
846 | } | 831 | } |
847 | ", | 832 | "#, |
848 | r" | 833 | r#" |
849 | fn main() { | 834 | fn main() { |
850 | let test_struct = dep::test_mod::TestStruct {}; | 835 | let test_struct = dep::test_mod::TestStruct {}; |
851 | dep::test_mod::TestTrait::test_method(&test_struct) | 836 | dep::test_mod::TestTrait::test_method(&test_struct) |
852 | } | 837 | } |
853 | ", | 838 | "#, |
854 | ); | 839 | ); |
855 | } | 840 | } |
856 | 841 | ||
@@ -858,27 +843,27 @@ fn main() { | |||
858 | fn assoc_fn_cross_crate() { | 843 | fn assoc_fn_cross_crate() { |
859 | check_assist( | 844 | check_assist( |
860 | qualify_path, | 845 | qualify_path, |
861 | r" | 846 | r#" |
862 | //- /main.rs crate:main deps:dep | 847 | //- /main.rs crate:main deps:dep |
863 | fn main() { | 848 | fn main() { |
864 | dep::test_mod::TestStruct::test_func$0tion | 849 | dep::test_mod::TestStruct::test_func$0tion |
865 | } | 850 | } |
866 | //- /dep.rs crate:dep | 851 | //- /dep.rs crate:dep |
867 | pub mod test_mod { | 852 | pub mod test_mod { |
868 | pub trait TestTrait { | 853 | pub trait TestTrait { |
869 | fn test_function(); | 854 | fn test_function(); |
870 | } | 855 | } |
871 | pub struct TestStruct {} | 856 | pub struct TestStruct {} |
872 | impl TestTrait for TestStruct { | 857 | impl TestTrait for TestStruct { |
873 | fn test_function() {} | 858 | fn test_function() {} |
874 | } | 859 | } |
875 | } | 860 | } |
876 | ", | 861 | "#, |
877 | r" | 862 | r#" |
878 | fn main() { | 863 | fn main() { |
879 | <dep::test_mod::TestStruct as dep::test_mod::TestTrait>::test_function | 864 | <dep::test_mod::TestStruct as dep::test_mod::TestTrait>::test_function |
880 | } | 865 | } |
881 | ", | 866 | "#, |
882 | ); | 867 | ); |
883 | } | 868 | } |
884 | 869 | ||
@@ -886,27 +871,27 @@ fn main() { | |||
886 | fn assoc_const_cross_crate() { | 871 | fn assoc_const_cross_crate() { |
887 | check_assist( | 872 | check_assist( |
888 | qualify_path, | 873 | qualify_path, |
889 | r" | 874 | r#" |
890 | //- /main.rs crate:main deps:dep | 875 | //- /main.rs crate:main deps:dep |
891 | fn main() { | 876 | fn main() { |
892 | dep::test_mod::TestStruct::CONST$0 | 877 | dep::test_mod::TestStruct::CONST$0 |
893 | } | 878 | } |
894 | //- /dep.rs crate:dep | 879 | //- /dep.rs crate:dep |
895 | pub mod test_mod { | 880 | pub mod test_mod { |
896 | pub trait TestTrait { | 881 | pub trait TestTrait { |
897 | const CONST: bool; | 882 | const CONST: bool; |
898 | } | 883 | } |
899 | pub struct TestStruct {} | 884 | pub struct TestStruct {} |
900 | impl TestTrait for TestStruct { | 885 | impl TestTrait for TestStruct { |
901 | const CONST: bool = true; | 886 | const CONST: bool = true; |
902 | } | 887 | } |
903 | } | 888 | } |
904 | ", | 889 | "#, |
905 | r" | 890 | r#" |
906 | fn main() { | 891 | fn main() { |
907 | <dep::test_mod::TestStruct as dep::test_mod::TestTrait>::CONST | 892 | <dep::test_mod::TestStruct as dep::test_mod::TestTrait>::CONST |
908 | } | 893 | } |
909 | ", | 894 | "#, |
910 | ); | 895 | ); |
911 | } | 896 | } |
912 | 897 | ||
@@ -914,23 +899,23 @@ fn main() { | |||
914 | fn assoc_fn_as_method_cross_crate() { | 899 | fn assoc_fn_as_method_cross_crate() { |
915 | check_assist_not_applicable( | 900 | check_assist_not_applicable( |
916 | qualify_path, | 901 | qualify_path, |
917 | r" | 902 | r#" |
918 | //- /main.rs crate:main deps:dep | 903 | //- /main.rs crate:main deps:dep |
919 | fn main() { | 904 | fn main() { |
920 | let test_struct = dep::test_mod::TestStruct {}; | 905 | let test_struct = dep::test_mod::TestStruct {}; |
921 | test_struct.test_func$0tion() | 906 | test_struct.test_func$0tion() |
922 | } | 907 | } |
923 | //- /dep.rs crate:dep | 908 | //- /dep.rs crate:dep |
924 | pub mod test_mod { | 909 | pub mod test_mod { |
925 | pub trait TestTrait { | 910 | pub trait TestTrait { |
926 | fn test_function(); | 911 | fn test_function(); |
927 | } | 912 | } |
928 | pub struct TestStruct {} | 913 | pub struct TestStruct {} |
929 | impl TestTrait for TestStruct { | 914 | impl TestTrait for TestStruct { |
930 | fn test_function() {} | 915 | fn test_function() {} |
931 | } | 916 | } |
932 | } | 917 | } |
933 | ", | 918 | "#, |
934 | ); | 919 | ); |
935 | } | 920 | } |
936 | 921 | ||
@@ -938,23 +923,23 @@ fn main() { | |||
938 | fn private_trait_cross_crate() { | 923 | fn private_trait_cross_crate() { |
939 | check_assist_not_applicable( | 924 | check_assist_not_applicable( |
940 | qualify_path, | 925 | qualify_path, |
941 | r" | 926 | r#" |
942 | //- /main.rs crate:main deps:dep | 927 | //- /main.rs crate:main deps:dep |
943 | fn main() { | 928 | fn main() { |
944 | let test_struct = dep::test_mod::TestStruct {}; | 929 | let test_struct = dep::test_mod::TestStruct {}; |
945 | test_struct.test_meth$0od() | 930 | test_struct.test_meth$0od() |
946 | } | 931 | } |
947 | //- /dep.rs crate:dep | 932 | //- /dep.rs crate:dep |
948 | pub mod test_mod { | 933 | pub mod test_mod { |
949 | trait TestTrait { | 934 | trait TestTrait { |
950 | fn test_method(&self); | 935 | fn test_method(&self); |
951 | } | 936 | } |
952 | pub struct TestStruct {} | 937 | pub struct TestStruct {} |
953 | impl TestTrait for TestStruct { | 938 | impl TestTrait for TestStruct { |
954 | fn test_method(&self) {} | 939 | fn test_method(&self) {} |
955 | } | 940 | } |
956 | } | 941 | } |
957 | ", | 942 | "#, |
958 | ); | 943 | ); |
959 | } | 944 | } |
960 | 945 | ||
@@ -962,32 +947,32 @@ fn main() { | |||
962 | fn not_applicable_for_imported_trait_for_method() { | 947 | fn not_applicable_for_imported_trait_for_method() { |
963 | check_assist_not_applicable( | 948 | check_assist_not_applicable( |
964 | qualify_path, | 949 | qualify_path, |
965 | r" | 950 | r#" |
966 | mod test_mod { | 951 | mod test_mod { |
967 | pub trait TestTrait { | 952 | pub trait TestTrait { |
968 | fn test_method(&self); | 953 | fn test_method(&self); |
969 | } | 954 | } |
970 | pub trait TestTrait2 { | 955 | pub trait TestTrait2 { |
971 | fn test_method(&self); | 956 | fn test_method(&self); |
972 | } | 957 | } |
973 | pub enum TestEnum { | 958 | pub enum TestEnum { |
974 | One, | 959 | One, |
975 | Two, | 960 | Two, |
976 | } | 961 | } |
977 | impl TestTrait2 for TestEnum { | 962 | impl TestTrait2 for TestEnum { |
978 | fn test_method(&self) {} | 963 | fn test_method(&self) {} |
979 | } | 964 | } |
980 | impl TestTrait for TestEnum { | 965 | impl TestTrait for TestEnum { |
981 | fn test_method(&self) {} | 966 | fn test_method(&self) {} |
982 | } | 967 | } |
983 | } | 968 | } |
984 | 969 | ||
985 | use test_mod::TestTrait2; | 970 | use test_mod::TestTrait2; |
986 | fn main() { | 971 | fn main() { |
987 | let one = test_mod::TestEnum::One; | 972 | let one = test_mod::TestEnum::One; |
988 | one.test$0_method(); | 973 | one.test$0_method(); |
989 | } | 974 | } |
990 | ", | 975 | "#, |
991 | ) | 976 | ) |
992 | } | 977 | } |
993 | 978 | ||
@@ -1114,7 +1099,7 @@ fn main() {} | |||
1114 | fn keep_generic_annotations_leading_colon() { | 1099 | fn keep_generic_annotations_leading_colon() { |
1115 | check_assist( | 1100 | check_assist( |
1116 | qualify_path, | 1101 | qualify_path, |
1117 | r" | 1102 | r#" |
1118 | //- /lib.rs crate:dep | 1103 | //- /lib.rs crate:dep |
1119 | pub mod generic { pub struct Thing<'a, T>(&'a T); } | 1104 | pub mod generic { pub struct Thing<'a, T>(&'a T); } |
1120 | 1105 | ||
@@ -1122,7 +1107,7 @@ pub mod generic { pub struct Thing<'a, T>(&'a T); } | |||
1122 | fn foo() -> Thin$0g::<'static, ()> {} | 1107 | fn foo() -> Thin$0g::<'static, ()> {} |
1123 | 1108 | ||
1124 | fn main() {} | 1109 | fn main() {} |
1125 | ", | 1110 | "#, |
1126 | r" | 1111 | r" |
1127 | fn foo() -> dep::generic::Thing::<'static, ()> {} | 1112 | fn foo() -> dep::generic::Thing::<'static, ()> {} |
1128 | 1113 | ||
@@ -1135,30 +1120,30 @@ fn main() {} | |||
1135 | fn associated_struct_const_generic() { | 1120 | fn associated_struct_const_generic() { |
1136 | check_assist( | 1121 | check_assist( |
1137 | qualify_path, | 1122 | qualify_path, |
1138 | r" | 1123 | r#" |
1139 | mod test_mod { | 1124 | mod test_mod { |
1140 | pub struct TestStruct<T> {} | 1125 | pub struct TestStruct<T> {} |
1141 | impl<T> TestStruct<T> { | 1126 | impl<T> TestStruct<T> { |
1142 | const TEST_CONST: u8 = 42; | 1127 | const TEST_CONST: u8 = 42; |
1143 | } | 1128 | } |
1144 | } | 1129 | } |
1145 | 1130 | ||
1146 | fn main() { | 1131 | fn main() { |
1147 | TestStruct::<()>::TEST_CONST$0 | 1132 | TestStruct::<()>::TEST_CONST$0 |
1148 | } | 1133 | } |
1149 | ", | 1134 | "#, |
1150 | r" | 1135 | r#" |
1151 | mod test_mod { | 1136 | mod test_mod { |
1152 | pub struct TestStruct<T> {} | 1137 | pub struct TestStruct<T> {} |
1153 | impl<T> TestStruct<T> { | 1138 | impl<T> TestStruct<T> { |
1154 | const TEST_CONST: u8 = 42; | 1139 | const TEST_CONST: u8 = 42; |
1155 | } | 1140 | } |
1156 | } | 1141 | } |
1157 | 1142 | ||
1158 | fn main() { | 1143 | fn main() { |
1159 | test_mod::TestStruct::<()>::TEST_CONST | 1144 | test_mod::TestStruct::<()>::TEST_CONST |
1160 | } | 1145 | } |
1161 | ", | 1146 | "#, |
1162 | ); | 1147 | ); |
1163 | } | 1148 | } |
1164 | 1149 | ||
@@ -1166,36 +1151,36 @@ fn main() {} | |||
1166 | fn associated_trait_const_generic() { | 1151 | fn associated_trait_const_generic() { |
1167 | check_assist( | 1152 | check_assist( |
1168 | qualify_path, | 1153 | qualify_path, |
1169 | r" | 1154 | r#" |
1170 | mod test_mod { | 1155 | mod test_mod { |
1171 | pub trait TestTrait { | 1156 | pub trait TestTrait { |
1172 | const TEST_CONST: u8; | 1157 | const TEST_CONST: u8; |
1173 | } | 1158 | } |
1174 | pub struct TestStruct<T> {} | 1159 | pub struct TestStruct<T> {} |
1175 | impl<T> TestTrait for TestStruct<T> { | 1160 | impl<T> TestTrait for TestStruct<T> { |
1176 | const TEST_CONST: u8 = 42; | 1161 | const TEST_CONST: u8 = 42; |
1177 | } | 1162 | } |
1178 | } | 1163 | } |
1179 | 1164 | ||
1180 | fn main() { | 1165 | fn main() { |
1181 | test_mod::TestStruct::<()>::TEST_CONST$0 | 1166 | test_mod::TestStruct::<()>::TEST_CONST$0 |
1182 | } | 1167 | } |
1183 | ", | 1168 | "#, |
1184 | r" | 1169 | r#" |
1185 | mod test_mod { | 1170 | mod test_mod { |
1186 | pub trait TestTrait { | 1171 | pub trait TestTrait { |
1187 | const TEST_CONST: u8; | 1172 | const TEST_CONST: u8; |
1188 | } | 1173 | } |
1189 | pub struct TestStruct<T> {} | 1174 | pub struct TestStruct<T> {} |
1190 | impl<T> TestTrait for TestStruct<T> { | 1175 | impl<T> TestTrait for TestStruct<T> { |
1191 | const TEST_CONST: u8 = 42; | 1176 | const TEST_CONST: u8 = 42; |
1192 | } | 1177 | } |
1193 | } | 1178 | } |
1194 | 1179 | ||
1195 | fn main() { | 1180 | fn main() { |
1196 | <test_mod::TestStruct::<()> as test_mod::TestTrait>::TEST_CONST | 1181 | <test_mod::TestStruct::<()> as test_mod::TestTrait>::TEST_CONST |
1197 | } | 1182 | } |
1198 | ", | 1183 | "#, |
1199 | ); | 1184 | ); |
1200 | } | 1185 | } |
1201 | 1186 | ||
@@ -1203,38 +1188,38 @@ fn main() {} | |||
1203 | fn trait_method_generic() { | 1188 | fn trait_method_generic() { |
1204 | check_assist( | 1189 | check_assist( |
1205 | qualify_path, | 1190 | qualify_path, |
1206 | r" | 1191 | r#" |
1207 | mod test_mod { | 1192 | mod test_mod { |
1208 | pub trait TestTrait { | 1193 | pub trait TestTrait { |
1209 | fn test_method<T>(&self); | 1194 | fn test_method<T>(&self); |
1210 | } | 1195 | } |
1211 | pub struct TestStruct {} | 1196 | pub struct TestStruct {} |
1212 | impl TestTrait for TestStruct { | 1197 | impl TestTrait for TestStruct { |
1213 | fn test_method<T>(&self) {} | 1198 | fn test_method<T>(&self) {} |
1214 | } | 1199 | } |
1215 | } | 1200 | } |
1216 | 1201 | ||
1217 | fn main() { | 1202 | fn main() { |
1218 | let test_struct = test_mod::TestStruct {}; | 1203 | let test_struct = test_mod::TestStruct {}; |
1219 | test_struct.test_meth$0od::<()>() | 1204 | test_struct.test_meth$0od::<()>() |
1220 | } | 1205 | } |
1221 | ", | 1206 | "#, |
1222 | r" | 1207 | r#" |
1223 | mod test_mod { | 1208 | mod test_mod { |
1224 | pub trait TestTrait { | 1209 | pub trait TestTrait { |
1225 | fn test_method<T>(&self); | 1210 | fn test_method<T>(&self); |
1226 | } | 1211 | } |
1227 | pub struct TestStruct {} | 1212 | pub struct TestStruct {} |
1228 | impl TestTrait for TestStruct { | 1213 | impl TestTrait for TestStruct { |
1229 | fn test_method<T>(&self) {} | 1214 | fn test_method<T>(&self) {} |
1230 | } | 1215 | } |
1231 | } | 1216 | } |
1232 | 1217 | ||
1233 | fn main() { | 1218 | fn main() { |
1234 | let test_struct = test_mod::TestStruct {}; | 1219 | let test_struct = test_mod::TestStruct {}; |
1235 | test_mod::TestTrait::test_method::<()>(&test_struct) | 1220 | test_mod::TestTrait::test_method::<()>(&test_struct) |
1236 | } | 1221 | } |
1237 | ", | 1222 | "#, |
1238 | ); | 1223 | ); |
1239 | } | 1224 | } |
1240 | } | 1225 | } |
diff --git a/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs b/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs index 540a905cc..a2af2035f 100644 --- a/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs +++ b/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs | |||
@@ -105,12 +105,13 @@ fn foo<B: Bar | |||
105 | } | 105 | } |
106 | 106 | ||
107 | #[test] | 107 | #[test] |
108 | #[ignore = "This case is very rare but there is no simple solutions to fix it."] | ||
109 | fn replace_impl_trait_with_exist_generic_letter() { | 108 | fn replace_impl_trait_with_exist_generic_letter() { |
109 | // FIXME: This is wrong, we should pick a different name if the one we | ||
110 | // want is already bound. | ||
110 | check_assist( | 111 | check_assist( |
111 | replace_impl_trait_with_generic, | 112 | replace_impl_trait_with_generic, |
112 | r#"fn foo<B>(bar: $0impl Bar) {}"#, | 113 | r#"fn foo<B>(bar: $0impl Bar) {}"#, |
113 | r#"fn foo<B, C: Bar>(bar: C) {}"#, | 114 | r#"fn foo<B, B: Bar>(bar: B) {}"#, |
114 | ); | 115 | ); |
115 | } | 116 | } |
116 | 117 | ||
diff --git a/crates/ide_completion/src/completions/attribute/derive.rs b/crates/ide_completion/src/completions/attribute/derive.rs index d526824fb..7b3133e53 100644 --- a/crates/ide_completion/src/completions/attribute/derive.rs +++ b/crates/ide_completion/src/completions/attribute/derive.rs | |||
@@ -93,57 +93,20 @@ mod tests { | |||
93 | } | 93 | } |
94 | 94 | ||
95 | #[test] | 95 | #[test] |
96 | #[ignore] // FIXME: Fixtures cant test proc-macros/derives yet as we cant specify them in fixtures | ||
97 | fn empty_derive() { | 96 | fn empty_derive() { |
98 | check( | 97 | // FIXME: Add build-in derives to fixture. |
99 | r#"#[derive($0)] struct Test;"#, | 98 | check(r#"#[derive($0)] struct Test;"#, expect![[r#""#]]); |
100 | expect![[r#" | ||
101 | at Clone | ||
102 | at Clone, Copy | ||
103 | at Debug | ||
104 | at Default | ||
105 | at Hash | ||
106 | at PartialEq | ||
107 | at PartialEq, Eq | ||
108 | at PartialEq, PartialOrd | ||
109 | at PartialEq, Eq, PartialOrd, Ord | ||
110 | "#]], | ||
111 | ); | ||
112 | } | 99 | } |
113 | 100 | ||
114 | #[test] | 101 | #[test] |
115 | #[ignore] // FIXME: Fixtures cant test proc-macros/derives yet as we cant specify them in fixtures | ||
116 | fn derive_with_input() { | 102 | fn derive_with_input() { |
117 | check( | 103 | // FIXME: Add build-in derives to fixture. |
118 | r#"#[derive(serde::Serialize, PartialEq, $0)] struct Test;"#, | 104 | check(r#"#[derive(serde::Serialize, PartialEq, $0)] struct Test;"#, expect![[r#""#]]) |
119 | expect![[r#" | ||
120 | at Clone | ||
121 | at Clone, Copy | ||
122 | at Debug | ||
123 | at Default | ||
124 | at Hash | ||
125 | at Eq | ||
126 | at PartialOrd | ||
127 | at Eq, PartialOrd, Ord | ||
128 | "#]], | ||
129 | ) | ||
130 | } | 105 | } |
131 | 106 | ||
132 | #[test] | 107 | #[test] |
133 | #[ignore] // FIXME: Fixtures cant test proc-macros/derives yet as we cant specify them in fixtures | ||
134 | fn derive_with_input2() { | 108 | fn derive_with_input2() { |
135 | check( | 109 | // FIXME: Add build-in derives to fixture. |
136 | r#"#[derive($0 serde::Serialize, PartialEq)] struct Test;"#, | 110 | check(r#"#[derive($0 serde::Serialize, PartialEq)] struct Test;"#, expect![[r#""#]]) |
137 | expect![[r#" | ||
138 | at Clone | ||
139 | at Clone, Copy | ||
140 | at Debug | ||
141 | at Default | ||
142 | at Hash | ||
143 | at Eq | ||
144 | at PartialOrd | ||
145 | at Eq, PartialOrd, Ord | ||
146 | "#]], | ||
147 | ) | ||
148 | } | 111 | } |
149 | } | 112 | } |
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index ba13d3707..0fccbeccf 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs | |||
@@ -536,17 +536,11 @@ Some multi-line comment$0 | |||
536 | fn test_completion_await_impls_future() { | 536 | fn test_completion_await_impls_future() { |
537 | check( | 537 | check( |
538 | r#" | 538 | r#" |
539 | //- /main.rs crate:main deps:std | 539 | //- minicore: future |
540 | use std::future::*; | 540 | use core::future::*; |
541 | struct A {} | 541 | struct A {} |
542 | impl Future for A {} | 542 | impl Future for A {} |
543 | fn foo(a: A) { a.$0 } | 543 | fn foo(a: A) { a.$0 } |
544 | |||
545 | //- /std/lib.rs crate:std | ||
546 | pub mod future { | ||
547 | #[lang = "future_trait"] | ||
548 | pub trait Future {} | ||
549 | } | ||
550 | "#, | 544 | "#, |
551 | expect![[r#" | 545 | expect![[r#" |
552 | kw await expr.await | 546 | kw await expr.await |
@@ -555,20 +549,12 @@ pub mod future { | |||
555 | 549 | ||
556 | check( | 550 | check( |
557 | r#" | 551 | r#" |
558 | //- /main.rs crate:main deps:std | 552 | //- minicore: future |
559 | use std::future::*; | 553 | use std::future::*; |
560 | fn foo() { | 554 | fn foo() { |
561 | let a = async {}; | 555 | let a = async {}; |
562 | a.$0 | 556 | a.$0 |
563 | } | 557 | } |
564 | |||
565 | //- /std/lib.rs crate:std | ||
566 | pub mod future { | ||
567 | #[lang = "future_trait"] | ||
568 | pub trait Future { | ||
569 | type Output; | ||
570 | } | ||
571 | } | ||
572 | "#, | 558 | "#, |
573 | expect![[r#" | 559 | expect![[r#" |
574 | kw await expr.await | 560 | kw await expr.await |
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index d8ca18c73..3eb51e80b 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs | |||
@@ -1152,16 +1152,11 @@ fn main() { | |||
1152 | fn suggest_deref() { | 1152 | fn suggest_deref() { |
1153 | check_relevance( | 1153 | check_relevance( |
1154 | r#" | 1154 | r#" |
1155 | #[lang = "deref"] | 1155 | //- minicore: deref |
1156 | trait Deref { | ||
1157 | type Target; | ||
1158 | fn deref(&self) -> &Self::Target; | ||
1159 | } | ||
1160 | |||
1161 | struct S; | 1156 | struct S; |
1162 | struct T(S); | 1157 | struct T(S); |
1163 | 1158 | ||
1164 | impl Deref for T { | 1159 | impl core::ops::Deref for T { |
1165 | type Target = S; | 1160 | type Target = S; |
1166 | 1161 | ||
1167 | fn deref(&self) -> &Self::Target { | 1162 | fn deref(&self) -> &Self::Target { |
@@ -1185,8 +1180,9 @@ fn main() { | |||
1185 | st T [] | 1180 | st T [] |
1186 | st S [] | 1181 | st S [] |
1187 | fn main() [] | 1182 | fn main() [] |
1188 | tt Deref [] | ||
1189 | fn foo(…) [] | 1183 | fn foo(…) [] |
1184 | md core [] | ||
1185 | tt Sized [] | ||
1190 | "#]], | 1186 | "#]], |
1191 | ) | 1187 | ) |
1192 | } | 1188 | } |
diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs index 70b11bf81..5a88ec742 100644 --- a/crates/ide_db/src/helpers/insert_use/tests.rs +++ b/crates/ide_db/src/helpers/insert_use/tests.rs | |||
@@ -511,13 +511,14 @@ use std::io; | |||
511 | } | 511 | } |
512 | 512 | ||
513 | #[test] | 513 | #[test] |
514 | #[ignore] // FIXME: Support this | ||
515 | fn split_out_merge() { | 514 | fn split_out_merge() { |
515 | // FIXME: This is suboptimal, we want to get `use std::fmt::{self, Result}` | ||
516 | // instead. | ||
516 | check_module( | 517 | check_module( |
517 | "std::fmt::Result", | 518 | "std::fmt::Result", |
518 | r"use std::{fmt, io};", | 519 | r"use std::{fmt, io};", |
519 | r"use std::fmt::{self, Result}; | 520 | r"use std::fmt::Result; |
520 | use std::io;", | 521 | use std::{fmt, io};", |
521 | ) | 522 | ) |
522 | } | 523 | } |
523 | 524 | ||
diff --git a/crates/ide_diagnostics/src/handlers/incorrect_case.rs b/crates/ide_diagnostics/src/handlers/incorrect_case.rs index 72f251961..68f25f284 100644 --- a/crates/ide_diagnostics/src/handlers/incorrect_case.rs +++ b/crates/ide_diagnostics/src/handlers/incorrect_case.rs | |||
@@ -341,43 +341,27 @@ mod F { | |||
341 | } | 341 | } |
342 | 342 | ||
343 | #[test] | 343 | #[test] |
344 | #[ignore] | 344 | fn complex_ignore() { |
345 | fn bug_trait_inside_fn() { | 345 | // FIXME: this should trigger errors for the second case. |
346 | // FIXME: | ||
347 | // This is broken, and in fact, should not even be looked at by this | ||
348 | // lint in the first place. There's weird stuff going on in the | ||
349 | // collection phase. | ||
350 | // It's currently being brought in by: | ||
351 | // * validate_func on `a` recursing into modules | ||
352 | // * then it finds the trait and then the function while iterating | ||
353 | // through modules | ||
354 | // * then validate_func is called on Dirty | ||
355 | // * ... which then proceeds to look at some unknown module taking no | ||
356 | // attrs from either the impl or the fn a, and then finally to the root | ||
357 | // module | ||
358 | // | ||
359 | // It should find the attribute on the trait, but it *doesn't even see | ||
360 | // the trait* as far as I can tell. | ||
361 | |||
362 | check_diagnostics( | 346 | check_diagnostics( |
363 | r#" | 347 | r#" |
364 | trait T { fn a(); } | 348 | trait T { fn a(); } |
365 | struct U {} | 349 | struct U {} |
366 | impl T for U { | 350 | impl T for U { |
367 | fn a() { | 351 | fn a() { |
368 | // this comes out of bitflags, mostly | ||
369 | #[allow(non_snake_case)] | 352 | #[allow(non_snake_case)] |
370 | trait __BitFlags { | 353 | trait __BitFlagsOk { |
371 | const HiImAlsoBad: u8 = 2; | 354 | const HiImAlsoBad: u8 = 2; |
372 | #[inline] | 355 | fn Dirty(&self) -> bool { false } |
373 | fn Dirty(&self) -> bool { | ||
374 | false | ||
375 | } | ||
376 | } | 356 | } |
377 | 357 | ||
358 | trait __BitFlagsBad { | ||
359 | const HiImAlsoBad: u8 = 2; | ||
360 | fn Dirty(&self) -> bool { false } | ||
361 | } | ||
378 | } | 362 | } |
379 | } | 363 | } |
380 | "#, | 364 | "#, |
381 | ); | 365 | ); |
382 | } | 366 | } |
383 | 367 | ||
@@ -414,18 +398,14 @@ extern { | |||
414 | } | 398 | } |
415 | 399 | ||
416 | #[test] | 400 | #[test] |
417 | #[ignore] | ||
418 | fn bug_traits_arent_checked() { | 401 | fn bug_traits_arent_checked() { |
419 | // FIXME: Traits and functions in traits aren't currently checked by | 402 | // FIXME: Traits and functions in traits aren't currently checked by |
420 | // r-a, even though rustc will complain about them. | 403 | // r-a, even though rustc will complain about them. |
421 | check_diagnostics( | 404 | check_diagnostics( |
422 | r#" | 405 | r#" |
423 | trait BAD_TRAIT { | 406 | trait BAD_TRAIT { |
424 | // ^^^^^^^^^ 💡 weak: Trait `BAD_TRAIT` should have CamelCase name, e.g. `BadTrait` | ||
425 | fn BAD_FUNCTION(); | 407 | fn BAD_FUNCTION(); |
426 | // ^^^^^^^^^^^^ 💡 weak: Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function` | ||
427 | fn BadFunction(); | 408 | fn BadFunction(); |
428 | // ^^^^^^^^^^^^ 💡 weak: Function `BadFunction` should have snake_case name, e.g. `bad_function` | ||
429 | } | 409 | } |
430 | "#, | 410 | "#, |
431 | ); | 411 | ); |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 3b20d741a..5588c15da 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -1062,8 +1062,8 @@ mod tests { | |||
1062 | let package_json_path = project_root().join("editors/code/package.json"); | 1062 | let package_json_path = project_root().join("editors/code/package.json"); |
1063 | let mut package_json = fs::read_to_string(&package_json_path).unwrap(); | 1063 | let mut package_json = fs::read_to_string(&package_json_path).unwrap(); |
1064 | 1064 | ||
1065 | let start_marker = " \"$generated-start\": false,\n"; | 1065 | let start_marker = " \"$generated-start\": {},\n"; |
1066 | let end_marker = " \"$generated-end\": false\n"; | 1066 | let end_marker = " \"$generated-end\": {}\n"; |
1067 | 1067 | ||
1068 | let start = package_json.find(start_marker).unwrap() + start_marker.len(); | 1068 | let start = package_json.find(start_marker).unwrap() + start_marker.len(); |
1069 | let end = package_json.find(end_marker).unwrap(); | 1069 | let end = package_json.find(end_marker).unwrap(); |
diff --git a/crates/rust-analyzer/tests/slow-tests/support.rs b/crates/rust-analyzer/tests/slow-tests/support.rs index e22c295f9..260a504e7 100644 --- a/crates/rust-analyzer/tests/slow-tests/support.rs +++ b/crates/rust-analyzer/tests/slow-tests/support.rs | |||
@@ -75,7 +75,9 @@ impl<'a> Project<'a> { | |||
75 | profile::init_from(crate::PROFILE); | 75 | profile::init_from(crate::PROFILE); |
76 | }); | 76 | }); |
77 | 77 | ||
78 | for entry in Fixture::parse(self.fixture) { | 78 | let (mini_core, fixtures) = Fixture::parse(self.fixture); |
79 | assert!(mini_core.is_none()); | ||
80 | for entry in fixtures { | ||
79 | let path = tmp_dir.path().join(&entry.path['/'.len_utf8()..]); | 81 | let path = tmp_dir.path().join(&entry.path['/'.len_utf8()..]); |
80 | fs::create_dir_all(path.parent().unwrap()).unwrap(); | 82 | fs::create_dir_all(path.parent().unwrap()).unwrap(); |
81 | fs::write(path.as_path(), entry.text.as_bytes()).unwrap(); | 83 | fs::write(path.as_path(), entry.text.as_bytes()).unwrap(); |
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 3d27d2c1a..2bd9ad867 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs | |||
@@ -325,6 +325,15 @@ impl ast::Impl { | |||
325 | let second = types.next(); | 325 | let second = types.next(); |
326 | (first, second) | 326 | (first, second) |
327 | } | 327 | } |
328 | |||
329 | pub fn for_trait_name_ref(name_ref: &ast::NameRef) -> Option<ast::Impl> { | ||
330 | let this = name_ref.syntax().ancestors().find_map(ast::Impl::cast)?; | ||
331 | if this.trait_()?.syntax().text_range().start() == name_ref.syntax().text_range().start() { | ||
332 | Some(this) | ||
333 | } else { | ||
334 | None | ||
335 | } | ||
336 | } | ||
328 | } | 337 | } |
329 | 338 | ||
330 | #[derive(Debug, Clone, PartialEq, Eq)] | 339 | #[derive(Debug, Clone, PartialEq, Eq)] |
diff --git a/crates/syntax/test_data/parser/ok/0011_outer_attribute.rast b/crates/syntax/test_data/parser/ok/0011_outer_attribute.rast index ff5877a7b..31f76589d 100644 --- a/crates/syntax/test_data/parser/ok/0011_outer_attribute.rast +++ b/crates/syntax/test_data/parser/ok/0011_outer_attribute.rast | |||
@@ -21,7 +21,7 @@ [email protected] | |||
21 | [email protected] | 21 | [email protected] |
22 | [email protected] | 22 | [email protected] |
23 | [email protected] | 23 | [email protected] |
24 | [email protected] "ignore" | 24 | [email protected] "Ignore" |
25 | [email protected] "]" | 25 | [email protected] "]" |
26 | [email protected] "\n" | 26 | [email protected] "\n" |
27 | [email protected] "fn" | 27 | [email protected] "fn" |
diff --git a/crates/syntax/test_data/parser/ok/0011_outer_attribute.rs b/crates/syntax/test_data/parser/ok/0011_outer_attribute.rs index 3d2e01d5c..6f04cb171 100644 --- a/crates/syntax/test_data/parser/ok/0011_outer_attribute.rs +++ b/crates/syntax/test_data/parser/ok/0011_outer_attribute.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | #[cfg(test)] | 1 | #[cfg(test)] |
2 | #[ignore] | 2 | #[Ignore] |
3 | fn foo() {} | 3 | fn foo() {} |
4 | 4 | ||
5 | #[path = "a.rs"] | 5 | #[path = "a.rs"] |
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index d0bddf7d8..6ba112de8 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs | |||
@@ -77,6 +77,11 @@ pub struct Fixture { | |||
77 | pub introduce_new_source_root: bool, | 77 | pub introduce_new_source_root: bool, |
78 | } | 78 | } |
79 | 79 | ||
80 | pub struct MiniCore { | ||
81 | activated_flags: Vec<String>, | ||
82 | valid_flags: Vec<String>, | ||
83 | } | ||
84 | |||
80 | impl Fixture { | 85 | impl Fixture { |
81 | /// Parses text which looks like this: | 86 | /// Parses text which looks like this: |
82 | /// | 87 | /// |
@@ -86,12 +91,28 @@ impl Fixture { | |||
86 | /// line 2 | 91 | /// line 2 |
87 | /// //- other meta | 92 | /// //- other meta |
88 | /// ``` | 93 | /// ``` |
89 | pub fn parse(ra_fixture: &str) -> Vec<Fixture> { | 94 | /// |
95 | /// Fixture can also start with a minicore declaration: | ||
96 | /// | ||
97 | /// ``` | ||
98 | /// //- minicore: sized | ||
99 | /// ``` | ||
100 | /// | ||
101 | /// That will include a subset of `libcore` into the fixture, see | ||
102 | /// `minicore.rs` for what's available. | ||
103 | pub fn parse(ra_fixture: &str) -> (Option<MiniCore>, Vec<Fixture>) { | ||
90 | let fixture = trim_indent(ra_fixture); | 104 | let fixture = trim_indent(ra_fixture); |
91 | 105 | let mut fixture = fixture.as_str(); | |
106 | let mut mini_core = None; | ||
92 | let mut res: Vec<Fixture> = Vec::new(); | 107 | let mut res: Vec<Fixture> = Vec::new(); |
93 | 108 | ||
94 | let default = if ra_fixture.contains("//-") { None } else { Some("//- /main.rs") }; | 109 | if fixture.starts_with("//- minicore:") { |
110 | let first_line = fixture.split_inclusive('\n').next().unwrap(); | ||
111 | mini_core = Some(MiniCore::parse(first_line)); | ||
112 | fixture = &fixture[first_line.len()..]; | ||
113 | } | ||
114 | |||
115 | let default = if fixture.contains("//-") { None } else { Some("//- /main.rs") }; | ||
95 | 116 | ||
96 | for (ix, line) in default.into_iter().chain(fixture.split_inclusive('\n')).enumerate() { | 117 | for (ix, line) in default.into_iter().chain(fixture.split_inclusive('\n')).enumerate() { |
97 | if line.contains("//-") { | 118 | if line.contains("//-") { |
@@ -113,7 +134,7 @@ impl Fixture { | |||
113 | } | 134 | } |
114 | } | 135 | } |
115 | 136 | ||
116 | res | 137 | (mini_core, res) |
117 | } | 138 | } |
118 | 139 | ||
119 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo | 140 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo |
@@ -172,6 +193,133 @@ impl Fixture { | |||
172 | } | 193 | } |
173 | } | 194 | } |
174 | 195 | ||
196 | impl MiniCore { | ||
197 | fn has_flag(&self, flag: &str) -> bool { | ||
198 | self.activated_flags.iter().any(|it| it == flag) | ||
199 | } | ||
200 | |||
201 | #[track_caller] | ||
202 | fn assert_valid_flag(&self, flag: &str) { | ||
203 | if !self.valid_flags.iter().any(|it| it == flag) { | ||
204 | panic!("invalid flag: {:?}, valid flags: {:?}", flag, self.valid_flags); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | fn parse(line: &str) -> MiniCore { | ||
209 | let mut res = MiniCore { activated_flags: Vec::new(), valid_flags: Vec::new() }; | ||
210 | |||
211 | let line = line.strip_prefix("//- minicore:").unwrap().trim(); | ||
212 | for entry in line.split(", ") { | ||
213 | if res.has_flag(entry) { | ||
214 | panic!("duplicate minicore flag: {:?}", entry) | ||
215 | } | ||
216 | res.activated_flags.push(entry.to_string()) | ||
217 | } | ||
218 | |||
219 | res | ||
220 | } | ||
221 | |||
222 | /// Strips parts of minicore.rs which are flagged by inactive flags. | ||
223 | /// | ||
224 | /// This is probably over-engineered to support flags dependencies. | ||
225 | pub fn source_code(mut self) -> String { | ||
226 | let mut buf = String::new(); | ||
227 | let raw_mini_core = include_str!("./minicore.rs"); | ||
228 | let mut lines = raw_mini_core.split_inclusive('\n'); | ||
229 | |||
230 | let mut parsing_flags = false; | ||
231 | let mut implications = Vec::new(); | ||
232 | |||
233 | // Parse `//!` preamble and extract flags and dependencies. | ||
234 | for line in lines.by_ref() { | ||
235 | let line = match line.strip_prefix("//!") { | ||
236 | Some(it) => it, | ||
237 | None => { | ||
238 | assert!(line.trim().is_empty()); | ||
239 | break; | ||
240 | } | ||
241 | }; | ||
242 | |||
243 | if parsing_flags { | ||
244 | let (flag, deps) = line.split_once(':').unwrap(); | ||
245 | let flag = flag.trim(); | ||
246 | self.valid_flags.push(flag.to_string()); | ||
247 | for dep in deps.split(", ") { | ||
248 | let dep = dep.trim(); | ||
249 | if !dep.is_empty() { | ||
250 | self.assert_valid_flag(dep); | ||
251 | implications.push((flag, dep)); | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | |||
256 | if line.contains("Available flags:") { | ||
257 | parsing_flags = true; | ||
258 | } | ||
259 | } | ||
260 | |||
261 | for flag in &self.activated_flags { | ||
262 | self.assert_valid_flag(flag); | ||
263 | } | ||
264 | |||
265 | // Fixed point loop to compute transitive closure of flags. | ||
266 | loop { | ||
267 | let mut changed = false; | ||
268 | for &(u, v) in implications.iter() { | ||
269 | if self.has_flag(u) && !self.has_flag(v) { | ||
270 | self.activated_flags.push(v.to_string()); | ||
271 | changed = true; | ||
272 | } | ||
273 | } | ||
274 | if !changed { | ||
275 | break; | ||
276 | } | ||
277 | } | ||
278 | |||
279 | let mut curr_region = ""; | ||
280 | let mut seen_regions = Vec::new(); | ||
281 | for line in lines { | ||
282 | let trimmed = line.trim(); | ||
283 | if let Some(region) = trimmed.strip_prefix("// region:") { | ||
284 | assert_eq!(curr_region, ""); | ||
285 | curr_region = region; | ||
286 | continue; | ||
287 | } | ||
288 | if let Some(region) = trimmed.strip_prefix("// endregion:") { | ||
289 | assert_eq!(curr_region, region); | ||
290 | curr_region = ""; | ||
291 | continue; | ||
292 | } | ||
293 | seen_regions.push(curr_region); | ||
294 | |||
295 | let mut flag = curr_region; | ||
296 | if let Some(idx) = trimmed.find("// :") { | ||
297 | flag = &trimmed[idx + "// :".len()..]; | ||
298 | } | ||
299 | |||
300 | let skip = if flag == "" { | ||
301 | false | ||
302 | } else { | ||
303 | assert!(!flag.starts_with(' '), "region marker starts with a space: {:?}", flag); | ||
304 | self.assert_valid_flag(flag); | ||
305 | !self.has_flag(flag) | ||
306 | }; | ||
307 | |||
308 | if !skip { | ||
309 | buf.push_str(line) | ||
310 | } | ||
311 | } | ||
312 | |||
313 | for flag in &self.valid_flags { | ||
314 | if !seen_regions.iter().any(|it| it == flag) { | ||
315 | panic!("unused minicore flag: {:?}", flag); | ||
316 | } | ||
317 | } | ||
318 | |||
319 | buf | ||
320 | } | ||
321 | } | ||
322 | |||
175 | #[test] | 323 | #[test] |
176 | #[should_panic] | 324 | #[should_panic] |
177 | fn parse_fixture_checks_further_indented_metadata() { | 325 | fn parse_fixture_checks_further_indented_metadata() { |
@@ -189,12 +337,14 @@ fn parse_fixture_checks_further_indented_metadata() { | |||
189 | 337 | ||
190 | #[test] | 338 | #[test] |
191 | fn parse_fixture_gets_full_meta() { | 339 | fn parse_fixture_gets_full_meta() { |
192 | let parsed = Fixture::parse( | 340 | let (mini_core, parsed) = Fixture::parse( |
193 | r" | 341 | r#" |
194 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b,atom env:OUTDIR=path/to,OTHER=foo | 342 | //- minicore: coerce_unsized |
195 | mod m; | 343 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b,atom env:OUTDIR=path/to,OTHER=foo |
196 | ", | 344 | mod m; |
345 | "#, | ||
197 | ); | 346 | ); |
347 | assert_eq!(mini_core.unwrap().activated_flags, vec!["coerce_unsized".to_string()]); | ||
198 | assert_eq!(1, parsed.len()); | 348 | assert_eq!(1, parsed.len()); |
199 | 349 | ||
200 | let meta = &parsed[0]; | 350 | let meta = &parsed[0]; |
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index b2fe25f82..d55bae62a 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs | |||
@@ -23,7 +23,10 @@ use text_size::{TextRange, TextSize}; | |||
23 | pub use dissimilar::diff as __diff; | 23 | pub use dissimilar::diff as __diff; |
24 | pub use rustc_hash::FxHashMap; | 24 | pub use rustc_hash::FxHashMap; |
25 | 25 | ||
26 | pub use crate::{assert_linear::AssertLinear, fixture::Fixture}; | 26 | pub use crate::{ |
27 | assert_linear::AssertLinear, | ||
28 | fixture::{Fixture, MiniCore}, | ||
29 | }; | ||
27 | 30 | ||
28 | pub const CURSOR_MARKER: &str = "$0"; | 31 | pub const CURSOR_MARKER: &str = "$0"; |
29 | pub const ESCAPED_CURSOR_MARKER: &str = "\\$0"; | 32 | pub const ESCAPED_CURSOR_MARKER: &str = "\\$0"; |
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs new file mode 100644 index 000000000..5ff60178c --- /dev/null +++ b/crates/test_utils/src/minicore.rs | |||
@@ -0,0 +1,204 @@ | |||
1 | //! This is a fixture we use for tests that need lang items. | ||
2 | //! | ||
3 | //! We want to include the minimal subset of core for each test, so this file | ||
4 | //! supports "conditional compilation". Tests use the following syntax to include minicore: | ||
5 | //! | ||
6 | //! //- minicore: flag1, flag2 | ||
7 | //! | ||
8 | //! We then strip all the code marked with other flags. | ||
9 | //! | ||
10 | //! Available flags: | ||
11 | //! sized: | ||
12 | //! slice: | ||
13 | //! range: | ||
14 | //! unsize: sized | ||
15 | //! deref: sized | ||
16 | //! coerce_unsized: unsize | ||
17 | //! pin: | ||
18 | //! future: pin | ||
19 | //! option: | ||
20 | //! result: | ||
21 | |||
22 | pub mod marker { | ||
23 | // region:sized | ||
24 | #[lang = "sized"] | ||
25 | #[fundamental] | ||
26 | #[rustc_specialization_trait] | ||
27 | pub trait Sized {} | ||
28 | // endregion:sized | ||
29 | |||
30 | // region:unsize | ||
31 | #[lang = "unsize"] | ||
32 | pub trait Unsize<T: ?Sized> {} | ||
33 | // endregion:unsize | ||
34 | } | ||
35 | |||
36 | pub mod ops { | ||
37 | // region:coerce_unsized | ||
38 | mod unsize { | ||
39 | use crate::marker::Unsize; | ||
40 | |||
41 | #[lang = "coerce_unsized"] | ||
42 | pub trait CoerceUnsized<T: ?Sized> {} | ||
43 | |||
44 | impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {} | ||
45 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {} | ||
46 | impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {} | ||
47 | impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {} | ||
48 | |||
49 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} | ||
50 | impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {} | ||
51 | |||
52 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} | ||
53 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {} | ||
54 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {} | ||
55 | } | ||
56 | pub use self::unsize::CoerceUnsized; | ||
57 | // endregion:coerce_unsized | ||
58 | |||
59 | // region:deref | ||
60 | mod deref { | ||
61 | #[lang = "deref"] | ||
62 | pub trait Deref { | ||
63 | #[lang = "deref_target"] | ||
64 | type Target: ?Sized; | ||
65 | fn deref(&self) -> &Self::Target; | ||
66 | } | ||
67 | } | ||
68 | pub use self::deref::Deref; | ||
69 | // endregion:deref | ||
70 | |||
71 | // region:range | ||
72 | mod range { | ||
73 | #[lang = "RangeFull"] | ||
74 | pub struct RangeFull; | ||
75 | |||
76 | #[lang = "Range"] | ||
77 | pub struct Range<Idx> { | ||
78 | pub start: Idx, | ||
79 | pub end: Idx, | ||
80 | } | ||
81 | |||
82 | #[lang = "RangeFrom"] | ||
83 | pub struct RangeFrom<Idx> { | ||
84 | pub start: Idx, | ||
85 | } | ||
86 | |||
87 | #[lang = "RangeTo"] | ||
88 | pub struct RangeTo<Idx> { | ||
89 | pub end: Idx, | ||
90 | } | ||
91 | |||
92 | #[lang = "RangeInclusive"] | ||
93 | pub struct RangeInclusive<Idx> { | ||
94 | pub(crate) start: Idx, | ||
95 | pub(crate) end: Idx, | ||
96 | pub(crate) exhausted: bool, | ||
97 | } | ||
98 | |||
99 | #[lang = "RangeToInclusive"] | ||
100 | pub struct RangeToInclusive<Idx> { | ||
101 | pub end: Idx, | ||
102 | } | ||
103 | } | ||
104 | pub use self::range::{Range, RangeFrom, RangeFull, RangeTo}; | ||
105 | pub use self::range::{RangeInclusive, RangeToInclusive}; | ||
106 | // endregion:range | ||
107 | } | ||
108 | |||
109 | // region:slice | ||
110 | pub mod slice { | ||
111 | #[lang = "slice"] | ||
112 | impl<T> [T] { | ||
113 | pub fn len(&self) -> usize { | ||
114 | loop {} | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | // endregion:slice | ||
119 | |||
120 | // region:option | ||
121 | pub mod option { | ||
122 | pub enum Option<T> { | ||
123 | #[lang = "None"] | ||
124 | None, | ||
125 | #[lang = "Some"] | ||
126 | Some(T), | ||
127 | } | ||
128 | } | ||
129 | // endregion:option | ||
130 | |||
131 | // region:result | ||
132 | pub mod result { | ||
133 | pub enum Result<T, E> { | ||
134 | #[lang = "Ok"] | ||
135 | Ok(T), | ||
136 | #[lang = "Err"] | ||
137 | Err(E), | ||
138 | } | ||
139 | } | ||
140 | // endregion:result | ||
141 | |||
142 | // region:pin | ||
143 | pub mod pin { | ||
144 | #[lang = "pin"] | ||
145 | #[fundamental] | ||
146 | pub struct Pin<P> { | ||
147 | pointer: P, | ||
148 | } | ||
149 | } | ||
150 | // endregion:pin | ||
151 | |||
152 | // region:future | ||
153 | pub mod future { | ||
154 | use crate::{ | ||
155 | pin::Pin, | ||
156 | task::{Context, Poll}, | ||
157 | }; | ||
158 | |||
159 | #[lang = "future_trait"] | ||
160 | pub trait Future { | ||
161 | type Output; | ||
162 | #[lang = "poll"] | ||
163 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>; | ||
164 | } | ||
165 | } | ||
166 | pub mod task { | ||
167 | pub enum Poll<T> { | ||
168 | #[lang = "Ready"] | ||
169 | Ready(T), | ||
170 | #[lang = "Pending"] | ||
171 | Pending, | ||
172 | } | ||
173 | |||
174 | pub struct Context<'a> { | ||
175 | waker: &'a (), | ||
176 | } | ||
177 | } | ||
178 | // endregion:future | ||
179 | |||
180 | pub mod prelude { | ||
181 | pub mod v1 { | ||
182 | pub use crate::{ | ||
183 | marker::Sized, // :sized | ||
184 | option::Option::{self, None, Some}, // :option | ||
185 | result::Result::{self, Err, Ok}, // :result | ||
186 | }; | ||
187 | } | ||
188 | |||
189 | pub mod rust_2015 { | ||
190 | pub use super::v1::*; | ||
191 | } | ||
192 | |||
193 | pub mod rust_2018 { | ||
194 | pub use super::v1::*; | ||
195 | } | ||
196 | |||
197 | pub mod rust_2021 { | ||
198 | pub use super::v1::*; | ||
199 | } | ||
200 | } | ||
201 | |||
202 | #[prelude_import] | ||
203 | #[allow(unused)] | ||
204 | use prelude::v1::*; | ||
diff --git a/docs/dev/style.md b/docs/dev/style.md index 96dd684b3..84485ea28 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md | |||
@@ -174,6 +174,13 @@ Instead, explicitly check for `None`, `Err`, etc. | |||
174 | `rust-analyzer` is not a library, we don't need to test for API misuse, and we have to handle any user input without panics. | 174 | `rust-analyzer` is not a library, we don't need to test for API misuse, and we have to handle any user input without panics. |
175 | Panic messages in the logs from the `#[should_panic]` tests are confusing. | 175 | Panic messages in the logs from the `#[should_panic]` tests are confusing. |
176 | 176 | ||
177 | ## `#[ignore]` | ||
178 | |||
179 | Do not `#[ignore]` tests. | ||
180 | If the test currently does not work, assert the wrong behavior and add a fixme explaining why it is wrong. | ||
181 | |||
182 | **Rationale:** noticing when the behavior is fixed, making sure that even the wrong behavior is acceptable (ie, not a panic). | ||
183 | |||
177 | ## Function Preconditions | 184 | ## Function Preconditions |
178 | 185 | ||
179 | Express function preconditions in types and force the caller to provide them (rather than checking in callee): | 186 | Express function preconditions in types and force the caller to provide them (rather than checking in callee): |
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index e28263c59..816e094c2 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc | |||
@@ -618,9 +618,14 @@ Here is a **non-exhaustive** list of ways to make rust-analyzer execute arbitrar | |||
618 | * VS Code plugin reads configuration from project directory, and that can be used to override paths to various executables, like `rustfmt` or `rust-analyzer` itself. | 618 | * VS Code plugin reads configuration from project directory, and that can be used to override paths to various executables, like `rustfmt` or `rust-analyzer` itself. |
619 | * rust-analyzer's syntax trees library uses a lot of `unsafe` and hasn't been properly audited for memory safety. | 619 | * rust-analyzer's syntax trees library uses a lot of `unsafe` and hasn't been properly audited for memory safety. |
620 | 620 | ||
621 | rust-analyzer itself doesn't access the network. | 621 | == Privacy |
622 | The VS Code plugin doesn't access the network unless the nightly channel is selected in the settings. | 622 | |
623 | In that case, the plugin uses the GitHub API to check for and download updates. | 623 | The LSP server performs no network access in itself, but runs `cargo metadata` which will update or download the crate registry and the source code of the project dependencies. |
624 | If enabled (the default), build scripts and procedural macros can do anything. | ||
625 | |||
626 | The Code extension automatically connects to GitHub to download updated LSP binaries and, if the nightly channel is selected, to perform update checks using the GitHub API. For `rust-analyzer` developers, using `cargo xtask release` uses the same API to put together the release notes. | ||
627 | |||
628 | Any other editor plugins are not under the control of the `rust-analyzer` developers. For any privacy concerns, you should check with their respective developers. | ||
624 | 629 | ||
625 | == Features | 630 | == Features |
626 | 631 | ||
diff --git a/editors/code/package.json b/editors/code/package.json index 0f3ed48a0..aa47bd0ed 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -313,7 +313,7 @@ | |||
313 | }, | 313 | }, |
314 | "rust-analyzer.updates.askBeforeDownload": { | 314 | "rust-analyzer.updates.askBeforeDownload": { |
315 | "type": "boolean", | 315 | "type": "boolean", |
316 | "default": true, | 316 | "default": false, |
317 | "description": "Whether to ask for permission before downloading any files from the Internet." | 317 | "description": "Whether to ask for permission before downloading any files from the Internet." |
318 | }, | 318 | }, |
319 | "rust-analyzer.server.path": { | 319 | "rust-analyzer.server.path": { |
@@ -389,7 +389,7 @@ | |||
389 | "default": {}, | 389 | "default": {}, |
390 | "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`" | 390 | "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`" |
391 | }, | 391 | }, |
392 | "$generated-start": false, | 392 | "$generated-start": {}, |
393 | "rust-analyzer.assist.importGranularity": { | 393 | "rust-analyzer.assist.importGranularity": { |
394 | "markdownDescription": "How imports should be grouped into use statements.", | 394 | "markdownDescription": "How imports should be grouped into use statements.", |
395 | "default": "crate", | 395 | "default": "crate", |
@@ -841,7 +841,7 @@ | |||
841 | "Search for all symbols kinds" | 841 | "Search for all symbols kinds" |
842 | ] | 842 | ] |
843 | }, | 843 | }, |
844 | "$generated-end": false | 844 | "$generated-end": {} |
845 | } | 845 | } |
846 | }, | 846 | }, |
847 | "problemPatterns": [ | 847 | "problemPatterns": [ |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index f58d26215..15f2151ad 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -158,7 +158,7 @@ export async function deactivate() { | |||
158 | } | 158 | } |
159 | 159 | ||
160 | async function bootstrap(config: Config, state: PersistentState): Promise<string> { | 160 | async function bootstrap(config: Config, state: PersistentState): Promise<string> { |
161 | await vscode.workspace.fs.createDirectory(config.globalStorageUri); | 161 | await vscode.workspace.fs.createDirectory(config.globalStorageUri).then(); |
162 | 162 | ||
163 | if (!config.currentExtensionIsNightly) { | 163 | if (!config.currentExtensionIsNightly) { |
164 | await state.updateNightlyReleaseId(undefined); | 164 | await state.updateNightlyReleaseId(undefined); |
@@ -277,11 +277,11 @@ async function patchelf(dest: vscode.Uri): Promise<void> { | |||
277 | ''; | 277 | ''; |
278 | } | 278 | } |
279 | `; | 279 | `; |
280 | const origFile = vscode.Uri.file(dest.path + "-orig"); | 280 | const origFile = vscode.Uri.file(dest.fsPath + "-orig"); |
281 | await vscode.workspace.fs.rename(dest, origFile); | 281 | await vscode.workspace.fs.rename(dest, origFile); |
282 | progress.report({ message: "Patching executable", increment: 20 }); | 282 | progress.report({ message: "Patching executable", increment: 20 }); |
283 | await new Promise((resolve, reject) => { | 283 | await new Promise((resolve, reject) => { |
284 | const handle = exec(`nix-build -E - --argstr srcStr '${origFile.path}' -o '${dest.path}'`, | 284 | const handle = exec(`nix-build -E - --argstr srcStr '${origFile.fsPath}' -o '${dest.fsPath}'`, |
285 | (err, stdout, stderr) => { | 285 | (err, stdout, stderr) => { |
286 | if (err != null) { | 286 | if (err != null) { |
287 | reject(Error(stderr)); | 287 | reject(Error(stderr)); |
@@ -338,14 +338,14 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
338 | await state.updateServerVersion(undefined); | 338 | await state.updateServerVersion(undefined); |
339 | } | 339 | } |
340 | 340 | ||
341 | if (state.serverVersion === config.package.version) return dest.path; | 341 | if (state.serverVersion === config.package.version) return dest.fsPath; |
342 | 342 | ||
343 | if (config.askBeforeDownload) { | 343 | if (config.askBeforeDownload) { |
344 | const userResponse = await vscode.window.showInformationMessage( | 344 | const userResponse = await vscode.window.showInformationMessage( |
345 | `Language server version ${config.package.version} for rust-analyzer is not installed.`, | 345 | `Language server version ${config.package.version} for rust-analyzer is not installed.`, |
346 | "Download now" | 346 | "Download now" |
347 | ); | 347 | ); |
348 | if (userResponse !== "Download now") return dest.path; | 348 | if (userResponse !== "Download now") return dest.fsPath; |
349 | } | 349 | } |
350 | 350 | ||
351 | const releaseTag = config.package.releaseTag; | 351 | const releaseTag = config.package.releaseTag; |
@@ -372,7 +372,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
372 | } | 372 | } |
373 | 373 | ||
374 | await state.updateServerVersion(config.package.version); | 374 | await state.updateServerVersion(config.package.version); |
375 | return dest.path; | 375 | return dest.fsPath; |
376 | } | 376 | } |
377 | 377 | ||
378 | function serverPath(config: Config): string | null { | 378 | function serverPath(config: Config): string | null { |
@@ -383,7 +383,7 @@ async function isNixOs(): Promise<boolean> { | |||
383 | try { | 383 | try { |
384 | const contents = (await vscode.workspace.fs.readFile(vscode.Uri.file("/etc/os-release"))).toString(); | 384 | const contents = (await vscode.workspace.fs.readFile(vscode.Uri.file("/etc/os-release"))).toString(); |
385 | return contents.indexOf("ID=nixos") !== -1; | 385 | return contents.indexOf("ID=nixos") !== -1; |
386 | } catch (e) { | 386 | } catch { |
387 | return false; | 387 | return false; |
388 | } | 388 | } |
389 | } | 389 | } |
diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index 747c02db9..722dab756 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts | |||
@@ -91,7 +91,7 @@ export async function download(opts: DownloadOpts) { | |||
91 | // to prevent partially downloaded files when user kills vscode | 91 | // to prevent partially downloaded files when user kills vscode |
92 | // This also avoids overwriting running executables | 92 | // This also avoids overwriting running executables |
93 | const randomHex = crypto.randomBytes(5).toString("hex"); | 93 | const randomHex = crypto.randomBytes(5).toString("hex"); |
94 | const rawDest = path.parse(opts.dest.path); | 94 | const rawDest = path.parse(opts.dest.fsPath); |
95 | const tempFilePath = vscode.Uri.joinPath(vscode.Uri.file(rawDest.dir), `${rawDest.name}${randomHex}`); | 95 | const tempFilePath = vscode.Uri.joinPath(vscode.Uri.file(rawDest.dir), `${rawDest.name}${randomHex}`); |
96 | 96 | ||
97 | await vscode.window.withProgress( | 97 | await vscode.window.withProgress( |
@@ -116,7 +116,7 @@ export async function download(opts: DownloadOpts) { | |||
116 | } | 116 | } |
117 | ); | 117 | ); |
118 | 118 | ||
119 | await vscode.workspace.fs.rename(tempFilePath, opts.dest); | 119 | await vscode.workspace.fs.rename(tempFilePath, opts.dest, { overwrite: true }); |
120 | } | 120 | } |
121 | 121 | ||
122 | async function downloadFile( | 122 | async function downloadFile( |
@@ -127,17 +127,19 @@ async function downloadFile( | |||
127 | httpProxy: string | null | undefined, | 127 | httpProxy: string | null | undefined, |
128 | onProgress: (readBytes: number, totalBytes: number) => void | 128 | onProgress: (readBytes: number, totalBytes: number) => void |
129 | ): Promise<void> { | 129 | ): Promise<void> { |
130 | const urlString = url.toString(); | ||
131 | |||
130 | const res = await (() => { | 132 | const res = await (() => { |
131 | if (httpProxy) { | 133 | if (httpProxy) { |
132 | log.debug(`Downloading ${url.path} via proxy: ${httpProxy}`); | 134 | log.debug(`Downloading ${urlString} via proxy: ${httpProxy}`); |
133 | return fetch(url.path, { agent: new HttpsProxyAgent(httpProxy) }); | 135 | return fetch(urlString, { agent: new HttpsProxyAgent(httpProxy) }); |
134 | } | 136 | } |
135 | 137 | ||
136 | return fetch(url.path); | 138 | return fetch(urlString); |
137 | })(); | 139 | })(); |
138 | 140 | ||
139 | if (!res.ok) { | 141 | if (!res.ok) { |
140 | log.error("Error", res.status, "while downloading file from", url.path); | 142 | log.error("Error", res.status, "while downloading file from", urlString); |
141 | log.error({ body: await res.text(), headers: res.headers }); | 143 | log.error({ body: await res.text(), headers: res.headers }); |
142 | 144 | ||
143 | throw new Error(`Got response ${res.status} when trying to download a file.`); | 145 | throw new Error(`Got response ${res.status} when trying to download a file.`); |
@@ -146,7 +148,7 @@ async function downloadFile( | |||
146 | const totalBytes = Number(res.headers.get('content-length')); | 148 | const totalBytes = Number(res.headers.get('content-length')); |
147 | assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); | 149 | assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); |
148 | 150 | ||
149 | log.debug("Downloading file of", totalBytes, "bytes size from", url.path, "to", destFilePath.path); | 151 | log.debug("Downloading file of", totalBytes, "bytes size from", urlString, "to", destFilePath.fsPath); |
150 | 152 | ||
151 | let readBytes = 0; | 153 | let readBytes = 0; |
152 | res.body.on("data", (chunk: Buffer) => { | 154 | res.body.on("data", (chunk: Buffer) => { |
@@ -154,7 +156,7 @@ async function downloadFile( | |||
154 | onProgress(readBytes, totalBytes); | 156 | onProgress(readBytes, totalBytes); |
155 | }); | 157 | }); |
156 | 158 | ||
157 | const destFileStream = fs.createWriteStream(destFilePath.path, { mode }); | 159 | const destFileStream = fs.createWriteStream(destFilePath.fsPath, { mode }); |
158 | const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body; | 160 | const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body; |
159 | 161 | ||
160 | await pipeline(srcStream, destFileStream); | 162 | await pipeline(srcStream, destFileStream); |
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts index 902d0ddda..355dd76fe 100644 --- a/editors/code/src/toolchain.ts +++ b/editors/code/src/toolchain.ts | |||
@@ -159,7 +159,7 @@ export const getPathForExecutable = memoize( | |||
159 | // it is not mentioned in docs and cannot be infered by the type signature... | 159 | // it is not mentioned in docs and cannot be infered by the type signature... |
160 | const standardPath = vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo", "bin", executableName); | 160 | const standardPath = vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo", "bin", executableName); |
161 | 161 | ||
162 | if (isFile(standardPath.path)) return standardPath.path; | 162 | if (isFileAtUri(standardPath)) return standardPath.fsPath; |
163 | } catch (err) { | 163 | } catch (err) { |
164 | log.error("Failed to read the fs info", err); | 164 | log.error("Failed to read the fs info", err); |
165 | } | 165 | } |
@@ -177,9 +177,17 @@ function lookupInPath(exec: string): boolean { | |||
177 | : [candidate]; | 177 | : [candidate]; |
178 | }); | 178 | }); |
179 | 179 | ||
180 | return candidates.some(isFile); | 180 | return candidates.some(isFileAtPath); |
181 | } | 181 | } |
182 | 182 | ||
183 | async function isFile(path: string): Promise<boolean> { | 183 | async function isFileAtPath(path: string): Promise<boolean> { |
184 | return ((await vscode.workspace.fs.stat(vscode.Uri.file(path))).type & vscode.FileType.File) !== 0; | 184 | return isFileAtUri(vscode.Uri.file(path)); |
185 | } | ||
186 | |||
187 | async function isFileAtUri(uri: vscode.Uri): Promise<boolean> { | ||
188 | try { | ||
189 | return ((await vscode.workspace.fs.stat(uri)).type & vscode.FileType.File) !== 0; | ||
190 | } catch { | ||
191 | return false; | ||
192 | } | ||
185 | } | 193 | } |
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index 3a67294c5..c7363688a 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs | |||
@@ -45,8 +45,8 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> { | |||
45 | patch | 45 | patch |
46 | .replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version)) | 46 | .replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version)) |
47 | .replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag)) | 47 | .replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag)) |
48 | .replace(r#""$generated-start": false,"#, "") | 48 | .replace(r#""$generated-start": {},"#, "") |
49 | .replace(",\n \"$generated-end\": false", ""); | 49 | .replace(",\n \"$generated-end\": {}", ""); |
50 | 50 | ||
51 | if nightly { | 51 | if nightly { |
52 | patch.replace( | 52 | patch.replace( |
diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs index f2ba8efef..06219d155 100644 --- a/xtask/src/tidy.rs +++ b/xtask/src/tidy.rs | |||
@@ -89,6 +89,7 @@ fn rust_files_are_tidy() { | |||
89 | let text = read_file(&path).unwrap(); | 89 | let text = read_file(&path).unwrap(); |
90 | check_todo(&path, &text); | 90 | check_todo(&path, &text); |
91 | check_dbg(&path, &text); | 91 | check_dbg(&path, &text); |
92 | check_test_attrs(&path, &text); | ||
92 | check_trailing_ws(&path, &text); | 93 | check_trailing_ws(&path, &text); |
93 | deny_clippy(&path, &text); | 94 | deny_clippy(&path, &text); |
94 | tidy_docs.visit(&path, &text); | 95 | tidy_docs.visit(&path, &text); |
@@ -334,6 +335,36 @@ fn check_dbg(path: &Path, text: &str) { | |||
334 | } | 335 | } |
335 | } | 336 | } |
336 | 337 | ||
338 | fn check_test_attrs(path: &Path, text: &str) { | ||
339 | let ignore_rule = | ||
340 | "https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#ignore"; | ||
341 | let need_ignore: &[&str] = &[ | ||
342 | // Special case to run `#[ignore]` tests | ||
343 | "ide/src/runnables.rs", | ||
344 | // A legit test which needs to be ignored, as it takes too long to run | ||
345 | // :( | ||
346 | "hir_def/src/nameres/collector.rs", | ||
347 | // Obviously needs ignore. | ||
348 | "ide_assists/src/handlers/toggle_ignore.rs", | ||
349 | // See above. | ||
350 | "ide_assists/src/tests/generated.rs", | ||
351 | ]; | ||
352 | if text.contains("#[ignore") && !need_ignore.iter().any(|p| path.ends_with(p)) { | ||
353 | panic!("\ndon't `#[ignore]` tests, see:\n\n {}\n\n {}\n", ignore_rule, path.display(),) | ||
354 | } | ||
355 | |||
356 | let panic_rule = | ||
357 | "https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#should_panic"; | ||
358 | let need_panic: &[&str] = &["test_utils/src/fixture.rs"]; | ||
359 | if text.contains("#[should_panic") && !need_panic.iter().any(|p| path.ends_with(p)) { | ||
360 | panic!( | ||
361 | "\ndon't add `#[should_panic]` tests, see:\n\n {}\n\n {}\n", | ||
362 | panic_rule, | ||
363 | path.display(), | ||
364 | ) | ||
365 | } | ||
366 | } | ||
367 | |||
337 | fn check_trailing_ws(path: &Path, text: &str) { | 368 | fn check_trailing_ws(path: &Path, text: &str) { |
338 | if is_exclude_dir(path, &["test_data"]) { | 369 | if is_exclude_dir(path, &["test_data"]) { |
339 | return; | 370 | return; |