aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide/src/references/rename.rs33
-rw-r--r--crates/ide_assists/src/handlers/inline_local_variable.rs17
-rw-r--r--crates/ide_completion/src/completions/postfix/format_like.rs18
-rw-r--r--crates/rust-analyzer/src/bin/flags.rs24
-rw-r--r--crates/rust-analyzer/src/bin/main.rs6
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs8
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs3
-rw-r--r--xtask/src/metrics.rs5
8 files changed, 82 insertions, 32 deletions
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs
index 01fe3a1a1..2a4a1c3c8 100644
--- a/crates/ide/src/references/rename.rs
+++ b/crates/ide/src/references/rename.rs
@@ -170,7 +170,17 @@ fn find_definition(
170 NameClass::classify(sema, &name).map(|class| class.referenced_or_defined(sema.db)) 170 NameClass::classify(sema, &name).map(|class| class.referenced_or_defined(sema.db))
171 } 171 }
172 ast::NameLike::NameRef(name_ref) => { 172 ast::NameLike::NameRef(name_ref) => {
173 NameRefClass::classify(sema, &name_ref).map(|class| class.referenced(sema.db)) 173 if let Some(def) =
174 NameRefClass::classify(sema, &name_ref).map(|class| class.referenced(sema.db))
175 {
176 // if the name differs from the definitions name it has to be an alias
177 if def.name(sema.db).map_or(false, |it| it.to_string() != name_ref.text()) {
178 bail!("Renaming aliases is currently unsupported");
179 }
180 Some(def)
181 } else {
182 None
183 }
174 } 184 }
175 ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, &lifetime) 185 ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, &lifetime)
176 .map(|class| NameRefClass::referenced(class, sema.db)) 186 .map(|class| NameRefClass::referenced(class, sema.db))
@@ -1907,4 +1917,25 @@ impl Fo0 where Self: {}
1907"#, 1917"#,
1908 ); 1918 );
1909 } 1919 }
1920
1921 #[test]
1922 fn test_rename_fails_on_aliases() {
1923 check(
1924 "Baz",
1925 r#"
1926struct Foo;
1927use Foo as Bar$0;
1928"#,
1929 "error: Renaming aliases is currently unsupported",
1930 );
1931 check(
1932 "Baz",
1933 r#"
1934struct Foo;
1935use Foo as Bar;
1936use Bar$0;
1937"#,
1938 "error: Renaming aliases is currently unsupported",
1939 );
1940 }
1910} 1941}
diff --git a/crates/ide_assists/src/handlers/inline_local_variable.rs b/crates/ide_assists/src/handlers/inline_local_variable.rs
index f5dafc8cb..2441dbb8b 100644
--- a/crates/ide_assists/src/handlers/inline_local_variable.rs
+++ b/crates/ide_assists/src/handlers/inline_local_variable.rs
@@ -182,6 +182,10 @@ fn inline_usage(ctx: &AssistContext) -> Option<InlineData> {
182 PathResolution::Local(local) => local, 182 PathResolution::Local(local) => local,
183 _ => return None, 183 _ => return None,
184 }; 184 };
185 if local.is_mut(ctx.sema.db) {
186 cov_mark::hit!(test_not_inline_mut_variable_use);
187 return None;
188 }
185 189
186 let bind_pat = match local.source(ctx.db()).value { 190 let bind_pat = match local.source(ctx.db()).value {
187 Either::Left(ident) => ident, 191 Either::Left(ident) => ident,
@@ -427,6 +431,19 @@ fn foo() {
427 } 431 }
428 432
429 #[test] 433 #[test]
434 fn test_not_inline_mut_variable_use() {
435 cov_mark::check!(test_not_inline_mut_variable_use);
436 check_assist_not_applicable(
437 inline_local_variable,
438 r"
439fn foo() {
440 let mut a = 1 + 1;
441 a$0 + 1;
442}",
443 );
444 }
445
446 #[test]
430 fn test_call_expr() { 447 fn test_call_expr() {
431 check_assist( 448 check_assist(
432 inline_local_variable, 449 inline_local_variable,
diff --git a/crates/ide_completion/src/completions/postfix/format_like.rs b/crates/ide_completion/src/completions/postfix/format_like.rs
index 0dcb3e898..9ebe1dcc0 100644
--- a/crates/ide_completion/src/completions/postfix/format_like.rs
+++ b/crates/ide_completion/src/completions/postfix/format_like.rs
@@ -4,15 +4,15 @@
4// 4//
5// The following postfix snippets are available: 5// The following postfix snippets are available:
6// 6//
7// - `format` -> `format!(...)` 7// * `format` -> `format!(...)`
8// - `panic` -> `panic!(...)` 8// * `panic` -> `panic!(...)`
9// - `println` -> `println!(...)` 9// * `println` -> `println!(...)`
10// - `log`: 10// * `log`:
11// + `logd` -> `log::debug!(...)` 11// ** `logd` -> `log::debug!(...)`
12// + `logt` -> `log::trace!(...)` 12// ** `logt` -> `log::trace!(...)`
13// + `logi` -> `log::info!(...)` 13// ** `logi` -> `log::info!(...)`
14// + `logw` -> `log::warn!(...)` 14// ** `logw` -> `log::warn!(...)`
15// + `loge` -> `log::error!(...)` 15// ** `loge` -> `log::error!(...)`
16// 16//
17// image::https://user-images.githubusercontent.com/48062697/113020656-b560f500-917a-11eb-87de-02991f61beb8.gif[] 17// image::https://user-images.githubusercontent.com/48062697/113020656-b560f500-917a-11eb-87de-02991f61beb8.gif[]
18 18
diff --git a/crates/rust-analyzer/src/bin/flags.rs b/crates/rust-analyzer/src/bin/flags.rs
index 63953098a..19173241b 100644
--- a/crates/rust-analyzer/src/bin/flags.rs
+++ b/crates/rust-analyzer/src/bin/flags.rs
@@ -67,10 +67,10 @@ xflags::xflags! {
67 /// Don't load sysroot crates (`std`, `core` & friends). 67 /// Don't load sysroot crates (`std`, `core` & friends).
68 optional --no-sysroot 68 optional --no-sysroot
69 69
70 /// Load OUT_DIR values by running `cargo check` before analysis. 70 /// Don't run build scripts or load `OUT_DIR` values by running `cargo check` before analysis.
71 optional --load-output-dirs 71 optional --disable-build-scripts
72 /// Use proc-macro-srv for proc-macro expanding. 72 /// Don't use expand proc macros.
73 optional --with-proc-macro 73 optional --disable-proc-macros
74 /// Only resolve names, don't run type inference. 74 /// Only resolve names, don't run type inference.
75 optional --skip-inference 75 optional --skip-inference
76 } 76 }
@@ -79,10 +79,10 @@ xflags::xflags! {
79 /// Directory with Cargo.toml. 79 /// Directory with Cargo.toml.
80 required path: PathBuf 80 required path: PathBuf
81 { 81 {
82 /// Load OUT_DIR values by running `cargo check` before analysis. 82 /// Don't run build scripts or load `OUT_DIR` values by running `cargo check` before analysis.
83 optional --load-output-dirs 83 optional --disable-build-scripts
84 /// Use proc-macro-srv for proc-macro expanding. 84 /// Don't use expand proc macros.
85 optional --with-proc-macro 85 optional --disable-proc-macros
86 } 86 }
87 87
88 cmd ssr 88 cmd ssr
@@ -158,8 +158,8 @@ pub struct AnalysisStats {
158 pub only: Option<String>, 158 pub only: Option<String>,
159 pub with_deps: bool, 159 pub with_deps: bool,
160 pub no_sysroot: bool, 160 pub no_sysroot: bool,
161 pub load_output_dirs: bool, 161 pub disable_build_scripts: bool,
162 pub with_proc_macro: bool, 162 pub disable_proc_macros: bool,
163 pub skip_inference: bool, 163 pub skip_inference: bool,
164} 164}
165 165
@@ -167,8 +167,8 @@ pub struct AnalysisStats {
167pub struct Diagnostics { 167pub struct Diagnostics {
168 pub path: PathBuf, 168 pub path: PathBuf,
169 169
170 pub load_output_dirs: bool, 170 pub disable_build_scripts: bool,
171 pub with_proc_macro: bool, 171 pub disable_proc_macros: bool,
172} 172}
173 173
174#[derive(Debug)] 174#[derive(Debug)]
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index 2b842d393..afc96505f 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -91,14 +91,14 @@ fn try_main() -> Result<()> {
91 with_deps: cmd.with_deps, 91 with_deps: cmd.with_deps,
92 no_sysroot: cmd.no_sysroot, 92 no_sysroot: cmd.no_sysroot,
93 path: cmd.path, 93 path: cmd.path,
94 load_output_dirs: cmd.load_output_dirs, 94 enable_build_scripts: !cmd.disable_build_scripts,
95 with_proc_macro: cmd.with_proc_macro, 95 enable_proc_macros: !cmd.disable_proc_macros,
96 skip_inference: cmd.skip_inference, 96 skip_inference: cmd.skip_inference,
97 } 97 }
98 .run(verbosity)?, 98 .run(verbosity)?,
99 99
100 flags::RustAnalyzerCmd::Diagnostics(cmd) => { 100 flags::RustAnalyzerCmd::Diagnostics(cmd) => {
101 cli::diagnostics(&cmd.path, cmd.load_output_dirs, cmd.with_proc_macro)? 101 cli::diagnostics(&cmd.path, !cmd.disable_build_scripts, !cmd.disable_proc_macros)?
102 } 102 }
103 flags::RustAnalyzerCmd::Ssr(cmd) => cli::apply_ssr_rules(cmd.rule)?, 103 flags::RustAnalyzerCmd::Ssr(cmd) => cli::apply_ssr_rules(cmd.rule)?,
104 flags::RustAnalyzerCmd::Search(cmd) => cli::search_for_patterns(cmd.pattern, cmd.debug)?, 104 flags::RustAnalyzerCmd::Search(cmd) => cli::search_for_patterns(cmd.pattern, cmd.debug)?,
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 14dbbb20d..5364e907c 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -51,8 +51,8 @@ pub struct AnalysisStatsCmd {
51 pub with_deps: bool, 51 pub with_deps: bool,
52 pub no_sysroot: bool, 52 pub no_sysroot: bool,
53 pub path: PathBuf, 53 pub path: PathBuf,
54 pub load_output_dirs: bool, 54 pub enable_build_scripts: bool,
55 pub with_proc_macro: bool, 55 pub enable_proc_macros: bool,
56 pub skip_inference: bool, 56 pub skip_inference: bool,
57} 57}
58 58
@@ -67,9 +67,9 @@ impl AnalysisStatsCmd {
67 let mut cargo_config = CargoConfig::default(); 67 let mut cargo_config = CargoConfig::default();
68 cargo_config.no_sysroot = self.no_sysroot; 68 cargo_config.no_sysroot = self.no_sysroot;
69 let load_cargo_config = LoadCargoConfig { 69 let load_cargo_config = LoadCargoConfig {
70 load_out_dirs_from_check: self.load_output_dirs, 70 load_out_dirs_from_check: self.enable_build_scripts,
71 wrap_rustc: false, 71 wrap_rustc: false,
72 with_proc_macro: self.with_proc_macro, 72 with_proc_macro: self.enable_proc_macros,
73 }; 73 };
74 let (host, vfs, _proc_macro) = 74 let (host, vfs, _proc_macro) =
75 load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?; 75 load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?;
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index 75bad1112..8cee65478 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -4,6 +4,7 @@ use std::{path::Path, sync::Arc};
4 4
5use anyhow::Result; 5use anyhow::Result;
6use crossbeam_channel::{unbounded, Receiver}; 6use crossbeam_channel::{unbounded, Receiver};
7use hir::db::DefDatabase;
7use ide::{AnalysisHost, Change}; 8use ide::{AnalysisHost, Change};
8use ide_db::base_db::CrateGraph; 9use ide_db::base_db::CrateGraph;
9use project_model::{ 10use project_model::{
@@ -94,6 +95,8 @@ fn load_crate_graph(
94 let mut host = AnalysisHost::new(lru_cap); 95 let mut host = AnalysisHost::new(lru_cap);
95 let mut analysis_change = Change::new(); 96 let mut analysis_change = Change::new();
96 97
98 host.raw_database_mut().set_enable_proc_attr_macros(true);
99
97 // wait until Vfs has loaded all roots 100 // wait until Vfs has loaded all roots
98 for task in receiver { 101 for task in receiver {
99 match task { 102 match task {
diff --git a/xtask/src/metrics.rs b/xtask/src/metrics.rs
index b0b76b8aa..34679062f 100644
--- a/xtask/src/metrics.rs
+++ b/xtask/src/metrics.rs
@@ -81,9 +81,8 @@ impl Metrics {
81 } 81 }
82 fn measure_analysis_stats_path(&mut self, name: &str, path: &str) -> Result<()> { 82 fn measure_analysis_stats_path(&mut self, name: &str, path: &str) -> Result<()> {
83 eprintln!("\nMeasuring analysis-stats/{}", name); 83 eprintln!("\nMeasuring analysis-stats/{}", name);
84 let output = 84 let output = cmd!("./target/release/rust-analyzer -q analysis-stats --memory-usage {path}")
85 cmd!("./target/release/rust-analyzer --quiet analysis-stats --memory-usage {path}") 85 .read()?;
86 .read()?;
87 for (metric, value, unit) in parse_metrics(&output) { 86 for (metric, value, unit) in parse_metrics(&output) {
88 self.report(&format!("analysis-stats/{}/{}", name, metric), value, unit.into()); 87 self.report(&format!("analysis-stats/{}/{}", name, metric), value, unit.into());
89 } 88 }