aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_def/src/builtin_attr.rs430
-rw-r--r--crates/hir_def/src/lib.rs1
-rw-r--r--crates/ide/src/hover.rs16
-rw-r--r--crates/rust-analyzer/src/cli.rs23
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs5
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs8
-rw-r--r--crates/rust-analyzer/src/lib.rs21
7 files changed, 473 insertions, 31 deletions
diff --git a/crates/hir_def/src/builtin_attr.rs b/crates/hir_def/src/builtin_attr.rs
new file mode 100644
index 000000000..2e989c504
--- /dev/null
+++ b/crates/hir_def/src/builtin_attr.rs
@@ -0,0 +1,430 @@
1//! Builtin attributes resolved by nameres.
2//!
3//! The actual definitions were copied from rustc's `compiler/rustc_feature/src/builtin_attrs.rs`.
4//!
5//! It was last synchronized with upstream commit 2225ee1b62ff089917434aefd9b2bf509cfa087f.
6//!
7//! The macros were adjusted to only expand to the attribute name, since that is all we need to do
8//! name resolution, and `BUILTIN_ATTRIBUTES` is almost entirely unchanged from the original, to
9//! ease updating.
10
11/// Ignored attribute namespaces used by tools.
12pub const TOOL_MODULES: &[&str] = &["rustfmt", "clippy"];
13
14type BuiltinAttribute = &'static str;
15
16macro_rules! ungated {
17 ($attr:ident, $typ:expr, $tpl:expr $(,)?) => {
18 stringify!($attr)
19 };
20}
21
22macro_rules! gated {
23 ($attr:ident $($rest:tt)*) => {
24 stringify!($attr)
25 };
26}
27
28macro_rules! rustc_attr {
29 (TEST, $attr:ident $($rest:tt)*) => {
30 stringify!($attr)
31 };
32 ($attr:ident $($rest:tt)*) => {
33 stringify!($attr)
34 };
35}
36
37/// Attributes that have a special meaning to rustc or rustdoc.
38#[rustfmt::skip]
39pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
40 // ==========================================================================
41 // Stable attributes:
42 // ==========================================================================
43
44 // Conditional compilation:
45 ungated!(cfg, Normal, template!(List: "predicate")),
46 ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ...")),
47
48 // Testing:
49 ungated!(ignore, Normal, template!(Word, NameValueStr: "reason")),
50 ungated!(
51 should_panic, Normal,
52 template!(Word, List: r#"expected = "reason"#, NameValueStr: "reason"),
53 ),
54 // FIXME(Centril): This can be used on stable but shouldn't.
55 ungated!(reexport_test_harness_main, Normal, template!(NameValueStr: "name")),
56
57 // Macros:
58 ungated!(derive, Normal, template!(List: "Trait1, Trait2, ...")),
59 ungated!(automatically_derived, Normal, template!(Word)),
60 // FIXME(#14407)
61 ungated!(macro_use, Normal, template!(Word, List: "name1, name2, ...")),
62 ungated!(macro_escape, Normal, template!(Word)), // Deprecated synonym for `macro_use`.
63 ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros")),
64 ungated!(proc_macro, Normal, template!(Word)),
65 ungated!(
66 proc_macro_derive, Normal,
67 template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"),
68 ),
69 ungated!(proc_macro_attribute, Normal, template!(Word)),
70
71 // Lints:
72 ungated!(warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
73 ungated!(allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
74 ungated!(forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
75 ungated!(deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
76 ungated!(must_use, AssumedUsed, template!(Word, NameValueStr: "reason")),
77 // FIXME(#14407)
78 ungated!(
79 deprecated, Normal,
80 template!(
81 Word,
82 List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#,
83 NameValueStr: "reason"
84 ),
85 ),
86
87 // Crate properties:
88 ungated!(crate_name, CrateLevel, template!(NameValueStr: "name")),
89 ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|...")),
90 ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored")),
91
92 // ABI, linking, symbols, and FFI
93 ungated!(
94 link, AssumedUsed,
95 template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...""#),
96 ),
97 ungated!(link_name, AssumedUsed, template!(NameValueStr: "name")),
98 ungated!(no_link, Normal, template!(Word)),
99 ungated!(repr, Normal, template!(List: "C")),
100 ungated!(export_name, AssumedUsed, template!(NameValueStr: "name")),
101 ungated!(link_section, AssumedUsed, template!(NameValueStr: "name")),
102 ungated!(no_mangle, AssumedUsed, template!(Word)),
103 ungated!(used, AssumedUsed, template!(Word)),
104
105 // Limits:
106 ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")),
107 ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N")),
108 gated!(
109 const_eval_limit, CrateLevel, template!(NameValueStr: "N"), const_eval_limit,
110 experimental!(const_eval_limit)
111 ),
112
113 // Entry point:
114 ungated!(main, Normal, template!(Word)),
115 ungated!(start, Normal, template!(Word)),
116 ungated!(no_start, CrateLevel, template!(Word)),
117 ungated!(no_main, CrateLevel, template!(Word)),
118
119 // Modules, prelude, and resolution:
120 ungated!(path, Normal, template!(NameValueStr: "file")),
121 ungated!(no_std, CrateLevel, template!(Word)),
122 ungated!(no_implicit_prelude, Normal, template!(Word)),
123 ungated!(non_exhaustive, AssumedUsed, template!(Word)),
124
125 // Runtime
126 ungated!(windows_subsystem, AssumedUsed, template!(NameValueStr: "windows|console")),
127 ungated!(panic_handler, Normal, template!(Word)), // RFC 2070
128
129 // Code generation:
130 ungated!(inline, AssumedUsed, template!(Word, List: "always|never")),
131 ungated!(cold, AssumedUsed, template!(Word)),
132 ungated!(no_builtins, AssumedUsed, template!(Word)),
133 ungated!(target_feature, AssumedUsed, template!(List: r#"enable = "name""#)),
134 ungated!(track_caller, AssumedUsed, template!(Word)),
135 gated!(
136 no_sanitize, AssumedUsed,
137 template!(List: "address, memory, thread"),
138 experimental!(no_sanitize)
139 ),
140
141 // FIXME: #14408 assume docs are used since rustdoc looks at them.
142 ungated!(doc, AssumedUsed, template!(List: "hidden|inline|...", NameValueStr: "string")),
143
144 // ==========================================================================
145 // Unstable attributes:
146 // ==========================================================================
147
148 // Linking:
149 gated!(naked, AssumedUsed, template!(Word), naked_functions, experimental!(naked)),
150 gated!(
151 link_args, Normal, template!(NameValueStr: "args"),
152 "the `link_args` attribute is experimental and not portable across platforms, \
153 it is recommended to use `#[link(name = \"foo\")] instead",
154 ),
155 gated!(
156 link_ordinal, AssumedUsed, template!(List: "ordinal"), raw_dylib,
157 experimental!(link_ordinal)
158 ),
159
160 // Plugins:
161 // XXX Modified for use in rust-analyzer
162 gated!(plugin_registrar),
163 gated!(plugin),
164
165 // Testing:
166 gated!(allow_fail, Normal, template!(Word), experimental!(allow_fail)),
167 gated!(
168 test_runner, CrateLevel, template!(List: "path"), custom_test_frameworks,
169 "custom test frameworks are an unstable feature",
170 ),
171 // RFC #1268
172 gated!(marker, Normal, template!(Word), marker_trait_attr, experimental!(marker)),
173 gated!(
174 thread_local, AssumedUsed, template!(Word),
175 "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
176 ),
177 gated!(no_core, CrateLevel, template!(Word), experimental!(no_core)),
178 // RFC 2412
179 gated!(
180 optimize, AssumedUsed, template!(List: "size|speed"), optimize_attribute,
181 experimental!(optimize),
182 ),
183 // RFC 2867
184 gated!(instruction_set, AssumedUsed, template!(List: "set"), isa_attribute, experimental!(instruction_set)),
185
186 gated!(ffi_returns_twice, AssumedUsed, template!(Word), experimental!(ffi_returns_twice)),
187 gated!(ffi_pure, AssumedUsed, template!(Word), experimental!(ffi_pure)),
188 gated!(ffi_const, AssumedUsed, template!(Word), experimental!(ffi_const)),
189 gated!(
190 register_attr, CrateLevel, template!(List: "attr1, attr2, ..."),
191 experimental!(register_attr),
192 ),
193 gated!(
194 register_tool, CrateLevel, template!(List: "tool1, tool2, ..."),
195 experimental!(register_tool),
196 ),
197
198 gated!(cmse_nonsecure_entry, AssumedUsed, template!(Word), experimental!(cmse_nonsecure_entry)),
199
200 // ==========================================================================
201 // Internal attributes: Stability, deprecation, and unsafe:
202 // ==========================================================================
203
204 ungated!(feature, CrateLevel, template!(List: "name1, name1, ...")),
205 // FIXME(#14407) -- only looked at on-demand so we can't
206 // guarantee they'll have already been checked.
207 ungated!(
208 rustc_deprecated, AssumedUsed,
209 template!(List: r#"since = "version", reason = "...""#)
210 ),
211 // FIXME(#14407)
212 ungated!(stable, AssumedUsed, template!(List: r#"feature = "name", since = "version""#)),
213 // FIXME(#14407)
214 ungated!(
215 unstable, AssumedUsed,
216 template!(List: r#"feature = "name", reason = "...", issue = "N""#),
217 ),
218 // FIXME(#14407)
219 ungated!(rustc_const_unstable, AssumedUsed, template!(List: r#"feature = "name""#)),
220 // FIXME(#14407)
221 ungated!(rustc_const_stable, AssumedUsed, template!(List: r#"feature = "name""#)),
222 gated!(
223 allow_internal_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
224 "allow_internal_unstable side-steps feature gating and stability checks",
225 ),
226 gated!(
227 rustc_allow_const_fn_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
228 "rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
229 ),
230 gated!(
231 allow_internal_unsafe, Normal, template!(Word),
232 "allow_internal_unsafe side-steps the unsafe_code lint",
233 ),
234
235 // ==========================================================================
236 // Internal attributes: Type system related:
237 // ==========================================================================
238
239 gated!(fundamental, AssumedUsed, template!(Word), experimental!(fundamental)),
240 gated!(
241 may_dangle, Normal, template!(Word), dropck_eyepatch,
242 "`may_dangle` has unstable semantics and may be removed in the future",
243 ),
244
245 // ==========================================================================
246 // Internal attributes: Runtime related:
247 // ==========================================================================
248
249 rustc_attr!(rustc_allocator, AssumedUsed, template!(Word), IMPL_DETAIL),
250 rustc_attr!(rustc_allocator_nounwind, AssumedUsed, template!(Word), IMPL_DETAIL),
251 gated!(alloc_error_handler, Normal, template!(Word), experimental!(alloc_error_handler)),
252 gated!(
253 default_lib_allocator, AssumedUsed, template!(Word), allocator_internals,
254 experimental!(default_lib_allocator),
255 ),
256 gated!(
257 needs_allocator, Normal, template!(Word), allocator_internals,
258 experimental!(needs_allocator),
259 ),
260 gated!(panic_runtime, AssumedUsed, template!(Word), experimental!(panic_runtime)),
261 gated!(needs_panic_runtime, AssumedUsed, template!(Word), experimental!(needs_panic_runtime)),
262 gated!(
263 unwind, AssumedUsed, template!(List: "allowed|aborts"), unwind_attributes,
264 experimental!(unwind),
265 ),
266 gated!(
267 compiler_builtins, AssumedUsed, template!(Word),
268 "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
269 which contains compiler-rt intrinsics and will never be stable",
270 ),
271 gated!(
272 profiler_runtime, AssumedUsed, template!(Word),
273 "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
274 which contains the profiler runtime and will never be stable",
275 ),
276
277 // ==========================================================================
278 // Internal attributes, Linkage:
279 // ==========================================================================
280
281 gated!(
282 linkage, AssumedUsed, template!(NameValueStr: "external|internal|..."),
283 "the `linkage` attribute is experimental and not portable across platforms",
284 ),
285 rustc_attr!(rustc_std_internal_symbol, AssumedUsed, template!(Word), INTERNAL_UNSTABLE),
286
287 // ==========================================================================
288 // Internal attributes, Macro related:
289 // ==========================================================================
290
291 rustc_attr!(rustc_builtin_macro, AssumedUsed, template!(Word), IMPL_DETAIL),
292 rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), INTERNAL_UNSTABLE),
293 rustc_attr!(
294 rustc_macro_transparency, AssumedUsed,
295 template!(NameValueStr: "transparent|semitransparent|opaque"),
296 "used internally for testing macro hygiene",
297 ),
298
299 // ==========================================================================
300 // Internal attributes, Diagnostics related:
301 // ==========================================================================
302
303 rustc_attr!(
304 rustc_on_unimplemented, AssumedUsed,
305 template!(
306 List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#,
307 NameValueStr: "message"
308 ),
309 INTERNAL_UNSTABLE
310 ),
311 // Enumerates "identity-like" conversion methods to suggest on type mismatch.
312 rustc_attr!(rustc_conversion_suggestion, AssumedUsed, template!(Word), INTERNAL_UNSTABLE),
313
314 // ==========================================================================
315 // Internal attributes, Const related:
316 // ==========================================================================
317
318 rustc_attr!(rustc_promotable, AssumedUsed, template!(Word), IMPL_DETAIL),
319 rustc_attr!(rustc_args_required_const, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),
320
321 // ==========================================================================
322 // Internal attributes, Layout related:
323 // ==========================================================================
324
325 rustc_attr!(
326 rustc_layout_scalar_valid_range_start, AssumedUsed, template!(List: "value"),
327 "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
328 niche optimizations in libcore and will never be stable",
329 ),
330 rustc_attr!(
331 rustc_layout_scalar_valid_range_end, AssumedUsed, template!(List: "value"),
332 "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
333 niche optimizations in libcore and will never be stable",
334 ),
335 rustc_attr!(
336 rustc_nonnull_optimization_guaranteed, AssumedUsed, template!(Word),
337 "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \
338 niche optimizations in libcore and will never be stable",
339 ),
340
341 // ==========================================================================
342 // Internal attributes, Misc:
343 // ==========================================================================
344 gated!(
345 lang, Normal, template!(NameValueStr: "name"), lang_items,
346 "language items are subject to change",
347 ),
348 gated!(rustc_diagnostic_item), // XXX modified in rust-analyzer
349 gated!(
350 // Used in resolve:
351 prelude_import, AssumedUsed, template!(Word),
352 "`#[prelude_import]` is for use by rustc only",
353 ),
354 gated!(
355 rustc_paren_sugar, Normal, template!(Word), unboxed_closures,
356 "unboxed_closures are still evolving",
357 ),
358 rustc_attr!(
359 rustc_inherit_overflow_checks, AssumedUsed, template!(Word),
360 "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
361 overflow checking behavior of several libcore functions that are inlined \
362 across crates and will never be stable",
363 ),
364 rustc_attr!(rustc_reservation_impl, Normal, template!(NameValueStr: "reservation message"),
365 "the `#[rustc_reservation_impl]` attribute is internally used \
366 for reserving for `for<T> From<!> for T` impl"
367 ),
368 rustc_attr!(
369 rustc_test_marker, Normal, template!(Word),
370 "the `#[rustc_test_marker]` attribute is used internally to track tests",
371 ),
372 rustc_attr!(
373 rustc_unsafe_specialization_marker, Normal, template!(Word),
374 "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
375 ),
376 rustc_attr!(
377 rustc_specialization_trait, Normal, template!(Word),
378 "the `#[rustc_specialization_trait]` attribute is used to check specializations"
379 ),
380
381 // ==========================================================================
382 // Internal attributes, Testing:
383 // ==========================================================================
384
385 rustc_attr!(TEST, rustc_outlives, Normal, template!(Word)),
386 rustc_attr!(TEST, rustc_capture_analysis, Normal, template!(Word)),
387 rustc_attr!(TEST, rustc_variance, Normal, template!(Word)),
388 rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ...")),
389 rustc_attr!(TEST, rustc_regions, Normal, template!(Word)),
390 rustc_attr!(
391 TEST, rustc_error, AssumedUsed,
392 template!(Word, List: "delay_span_bug_from_inside_query")
393 ),
394 rustc_attr!(TEST, rustc_dump_user_substs, AssumedUsed, template!(Word)),
395 rustc_attr!(TEST, rustc_if_this_changed, AssumedUsed, template!(Word, List: "DepNode")),
396 rustc_attr!(TEST, rustc_then_this_would_need, AssumedUsed, template!(List: "DepNode")),
397 rustc_attr!(
398 TEST, rustc_dirty, AssumedUsed,
399 template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
400 ),
401 rustc_attr!(
402 TEST, rustc_clean, AssumedUsed,
403 template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
404 ),
405 rustc_attr!(
406 TEST, rustc_partition_reused, AssumedUsed,
407 template!(List: r#"cfg = "...", module = "...""#),
408 ),
409 rustc_attr!(
410 TEST, rustc_partition_codegened, AssumedUsed,
411 template!(List: r#"cfg = "...", module = "...""#),
412 ),
413 rustc_attr!(
414 TEST, rustc_expected_cgu_reuse, AssumedUsed,
415 template!(List: r#"cfg = "...", module = "...", kind = "...""#),
416 ),
417 rustc_attr!(TEST, rustc_synthetic, AssumedUsed, template!(Word)),
418 rustc_attr!(TEST, rustc_symbol_name, AssumedUsed, template!(Word)),
419 rustc_attr!(TEST, rustc_polymorphize_error, AssumedUsed, template!(Word)),
420 rustc_attr!(TEST, rustc_def_path, AssumedUsed, template!(Word)),
421 rustc_attr!(TEST, rustc_mir, AssumedUsed, template!(List: "arg1, arg2, ...")),
422 rustc_attr!(TEST, rustc_dump_program_clauses, AssumedUsed, template!(Word)),
423 rustc_attr!(TEST, rustc_dump_env_program_clauses, AssumedUsed, template!(Word)),
424 rustc_attr!(TEST, rustc_object_lifetime_default, AssumedUsed, template!(Word)),
425 rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/)),
426 gated!(
427 omit_gdb_pretty_printer_section, AssumedUsed, template!(Word),
428 "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite",
429 ),
430];
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs
index 02ed30e4d..a75d4d302 100644
--- a/crates/hir_def/src/lib.rs
+++ b/crates/hir_def/src/lib.rs
@@ -18,6 +18,7 @@ pub mod attr;
18pub mod path; 18pub mod path;
19pub mod type_ref; 19pub mod type_ref;
20pub mod builtin_type; 20pub mod builtin_type;
21pub mod builtin_attr;
21pub mod diagnostics; 22pub mod diagnostics;
22pub mod per_ns; 23pub mod per_ns;
23pub mod item_scope; 24pub mod item_scope;
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index cf04c3de0..ab017d2ad 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -139,6 +139,11 @@ pub(crate) fn hover(
139 } 139 }
140 } 140 }
141 141
142 if token.kind() == syntax::SyntaxKind::COMMENT {
143 // don't highlight the entire parent node on comment hover
144 return None;
145 }
146
142 let node = token.ancestors().find(|n| { 147 let node = token.ancestors().find(|n| {
143 ast::Expr::can_cast(n.kind()) 148 ast::Expr::can_cast(n.kind())
144 || ast::Pat::can_cast(n.kind()) 149 || ast::Pat::can_cast(n.kind())
@@ -3419,4 +3424,15 @@ mod Foo<|> {
3419 "#]], 3424 "#]],
3420 ); 3425 );
3421 } 3426 }
3427
3428 #[test]
3429 fn hover_comments_dont_highlight_parent() {
3430 check_hover_no_result(
3431 r#"
3432fn no_hover() {
3433 // no<|>hover
3434}
3435"#,
3436 );
3437 }
3422} 3438}
diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs
index 6966ee576..6879a462d 100644
--- a/crates/rust-analyzer/src/cli.rs
+++ b/crates/rust-analyzer/src/cli.rs
@@ -10,8 +10,9 @@ mod ssr;
10use std::io::Read; 10use std::io::Read;
11 11
12use anyhow::Result; 12use anyhow::Result;
13use ide::Analysis; 13use ide::{Analysis, AnalysisHost};
14use syntax::{AstNode, SourceFile}; 14use syntax::{AstNode, SourceFile};
15use vfs::Vfs;
15 16
16pub use self::{ 17pub use self::{
17 analysis_bench::{BenchCmd, BenchWhat, Position}, 18 analysis_bench::{BenchCmd, BenchWhat, Position},
@@ -82,3 +83,23 @@ fn report_metric(metric: &str, value: u64, unit: &str) {
82 } 83 }
83 println!("METRIC:{}:{}:{}", metric, value, unit) 84 println!("METRIC:{}:{}:{}", metric, value, unit)
84} 85}
86
87fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
88 let mut mem = host.per_query_memory_usage();
89
90 let before = profile::memory_usage();
91 drop(vfs);
92 let vfs = before.allocated - profile::memory_usage().allocated;
93 mem.push(("VFS".into(), vfs));
94
95 let before = profile::memory_usage();
96 drop(host);
97 mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated));
98
99 mem.push(("Remaining".into(), profile::memory_usage().allocated));
100
101 for (name, bytes) in mem {
102 // NOTE: Not a debug print, so avoid going through the `eprintln` defined above.
103 eprintln!("{:>8} {}", bytes, name);
104 }
105}
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs
index 8e33986d5..5a8484c62 100644
--- a/crates/rust-analyzer/src/cli/analysis_bench.rs
+++ b/crates/rust-analyzer/src/cli/analysis_bench.rs
@@ -12,10 +12,7 @@ use ide_db::base_db::{
12}; 12};
13use vfs::AbsPathBuf; 13use vfs::AbsPathBuf;
14 14
15use crate::{ 15use crate::cli::{load_cargo::load_cargo, print_memory_usage, Verbosity};
16 cli::{load_cargo::load_cargo, Verbosity},
17 print_memory_usage,
18};
19 16
20pub struct BenchCmd { 17pub struct BenchCmd {
21 pub path: PathBuf, 18 pub path: PathBuf,
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 58d284d47..a23fb7a33 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -23,11 +23,9 @@ use rustc_hash::FxHashSet;
23use stdx::format_to; 23use stdx::format_to;
24use syntax::AstNode; 24use syntax::AstNode;
25 25
26use crate::{ 26use crate::cli::{
27 cli::{ 27 load_cargo::load_cargo, print_memory_usage, progress_report::ProgressReport, report_metric,
28 load_cargo::load_cargo, progress_report::ProgressReport, report_metric, Result, Verbosity, 28 Result, Verbosity,
29 },
30 print_memory_usage,
31}; 29};
32use profile::StopWatch; 30use profile::StopWatch;
33 31
diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs
index ad08f1afb..79fe30e53 100644
--- a/crates/rust-analyzer/src/lib.rs
+++ b/crates/rust-analyzer/src/lib.rs
@@ -37,10 +37,8 @@ mod document;
37pub mod lsp_ext; 37pub mod lsp_ext;
38pub mod config; 38pub mod config;
39 39
40use ide::AnalysisHost;
41use serde::de::DeserializeOwned; 40use serde::de::DeserializeOwned;
42use std::fmt; 41use std::fmt;
43use vfs::Vfs;
44 42
45pub use crate::{caps::server_capabilities, main_loop::main_loop}; 43pub use crate::{caps::server_capabilities, main_loop::main_loop};
46 44
@@ -72,22 +70,3 @@ impl fmt::Display for LspError {
72} 70}
73 71
74impl std::error::Error for LspError {} 72impl std::error::Error for LspError {}
75
76fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
77 let mut mem = host.per_query_memory_usage();
78
79 let before = profile::memory_usage();
80 drop(vfs);
81 let vfs = before.allocated - profile::memory_usage().allocated;
82 mem.push(("VFS".into(), vfs));
83
84 let before = profile::memory_usage();
85 drop(host);
86 mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated));
87
88 mem.push(("Remaining".into(), profile::memory_usage().allocated));
89
90 for (name, bytes) in mem {
91 eprintln!("{:>8} {}", bytes, name);
92 }
93}