From 3a317416271c6b4ea765631196f198f1664ec44a Mon Sep 17 00:00:00 2001 From: Mehul Arora Date: Wed, 12 Feb 2025 14:43:25 -0500 Subject: [PATCH 01/25] Use correct working directory for non-workspace proc-macro execution --- crates/base-db/src/input.rs | 37 +++++++++++++------ crates/base-db/src/lib.rs | 4 +- crates/hir-expand/src/proc_macro.rs | 8 ++-- crates/ide/src/lib.rs | 4 +- crates/ide/src/status.rs | 2 + crates/load-cargo/src/lib.rs | 1 - crates/project-model/src/project_json.rs | 5 +++ crates/project-model/src/workspace.rs | 17 +++++++-- .../cargo_hello_world_project_model.txt | 25 +++++++++++++ ...project_model_with_selective_overrides.txt | 25 +++++++++++++ ..._project_model_with_wildcard_overrides.txt | 25 +++++++++++++ .../output/rust_project_cfg_groups.txt | 12 ++++++ ...rust_project_hello_world_project_model.txt | 11 ++++++ crates/rust-analyzer/src/reload.rs | 1 - crates/test-fixture/src/lib.rs | 13 ++++--- 15 files changed, 159 insertions(+), 31 deletions(-) diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index c2cea07190..bd08387b58 100644 --- a/crates/base-db/src/input.rs +++ b/crates/base-db/src/input.rs @@ -296,6 +296,9 @@ pub struct CrateData { pub dependencies: Vec, pub origin: CrateOrigin, pub is_proc_macro: bool, + /// The working directory to run proc-macros in. This is the workspace root of the cargo workspace + /// for workspace members, the crate manifest dir otherwise. + pub proc_macro_cwd: Option, } #[derive(Default, Clone, PartialEq, Eq)] @@ -360,8 +363,9 @@ impl CrateGraph { cfg_options: Arc, potential_cfg_options: Option>, mut env: Env, - is_proc_macro: bool, origin: CrateOrigin, + is_proc_macro: bool, + proc_macro_cwd: Option, ) -> CrateId { env.entries.shrink_to_fit(); let data = CrateData { @@ -375,6 +379,7 @@ impl CrateGraph { dependencies: Vec::new(), origin, is_proc_macro, + proc_macro_cwd, }; self.arena.alloc(data) } @@ -698,8 +703,9 @@ mod tests { Default::default(), Default::default(), Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); let crate2 = graph.add_crate_root( FileId::from_raw(2u32), @@ -709,8 +715,9 @@ mod tests { Default::default(), Default::default(), Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); let crate3 = graph.add_crate_root( FileId::from_raw(3u32), @@ -720,8 +727,9 @@ mod tests { Default::default(), Default::default(), Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); assert!(graph .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) @@ -745,8 +753,9 @@ mod tests { Default::default(), Default::default(), Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); let crate2 = graph.add_crate_root( FileId::from_raw(2u32), @@ -756,8 +765,9 @@ mod tests { Default::default(), Default::default(), Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); assert!(graph .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) @@ -778,8 +788,9 @@ mod tests { Default::default(), Default::default(), Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); let crate2 = graph.add_crate_root( FileId::from_raw(2u32), @@ -789,8 +800,9 @@ mod tests { Default::default(), Default::default(), Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); let crate3 = graph.add_crate_root( FileId::from_raw(3u32), @@ -800,8 +812,9 @@ mod tests { Default::default(), Default::default(), Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); assert!(graph .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2,)) @@ -822,8 +835,9 @@ mod tests { Default::default(), Default::default(), Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); let crate2 = graph.add_crate_root( FileId::from_raw(2u32), @@ -833,8 +847,9 @@ mod tests { Default::default(), Default::default(), Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); assert!(graph .add_dep( diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs index c7e4168f6b..eed8c88683 100644 --- a/crates/base-db/src/lib.rs +++ b/crates/base-db/src/lib.rs @@ -10,7 +10,7 @@ use rustc_hash::FxHashMap; use span::EditionedFileId; use syntax::{ast, Parse, SourceFile, SyntaxError}; use triomphe::Arc; -use vfs::{AbsPathBuf, FileId}; +use vfs::FileId; pub use crate::{ change::FileChange, @@ -85,8 +85,6 @@ pub trait SourceDatabase: FileLoader + std::fmt::Debug { /// Crate related data shared by the whole workspace. #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub struct CrateWorkspaceData { - /// The working directory to run proc-macros in. This is usually the workspace root of cargo workspaces. - pub proc_macro_cwd: Option, // FIXME: Consider removing this, making HirDatabase::target_data_layout an input query pub data_layout: TargetLayoutLoadResult, /// Toolchain version used to compile the crate. diff --git a/crates/hir-expand/src/proc_macro.rs b/crates/hir-expand/src/proc_macro.rs index 07808fea85..3dc3dcd760 100644 --- a/crates/hir-expand/src/proc_macro.rs +++ b/crates/hir-expand/src/proc_macro.rs @@ -238,6 +238,9 @@ impl CustomProcMacroExpander { let krate_graph = db.crate_graph(); // Proc macros have access to the environment variables of the invoking crate. let env = &krate_graph[calling_crate].env; + let current_dir = + krate_graph[calling_crate].proc_macro_cwd.as_deref().map(ToString::to_string); + match proc_macro.expander.expand( tt, attr_arg, @@ -245,10 +248,7 @@ impl CustomProcMacroExpander { def_site, call_site, mixed_site, - db.crate_workspace_data()[&calling_crate] - .proc_macro_cwd - .as_ref() - .map(ToString::to_string), + current_dir, ) { Ok(t) => ExpandResult::ok(t), Err(err) => match err { diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index e942f5a6aa..27a1a510b4 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -252,14 +252,14 @@ impl Analysis { Arc::new(cfg_options), None, Env::default(), - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); change.change_file(file_id, Some(text)); let ws_data = crate_graph .iter() .zip(iter::repeat(Arc::new(CrateWorkspaceData { - proc_macro_cwd: None, data_layout: Err("fixture has no layout".into()), toolchain: None, }))) diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs index b0022cfac7..f8ecaa8fdf 100644 --- a/crates/ide/src/status.rs +++ b/crates/ide/src/status.rs @@ -68,6 +68,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option) -> String { dependencies, origin, is_proc_macro, + proc_macro_cwd, } = &crate_graph[crate_id]; format_to!( buf, @@ -85,6 +86,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option) -> String { format_to!(buf, " Env: {:?}\n", env); format_to!(buf, " Origin: {:?}\n", origin); format_to!(buf, " Is a proc macro crate: {}\n", is_proc_macro); + format_to!(buf, " Proc macro cwd: {:?}\n", proc_macro_cwd); let deps = dependencies .iter() .map(|dep| format!("{}={}", dep.name, dep.crate_id.into_raw())) diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs index 67ee9d1119..76f1a7f48b 100644 --- a/crates/load-cargo/src/lib.rs +++ b/crates/load-cargo/src/lib.rs @@ -456,7 +456,6 @@ fn load_crate_graph( let ws_data = crate_graph .iter() .zip(iter::repeat(From::from(CrateWorkspaceData { - proc_macro_cwd: None, data_layout: target_layout.clone(), toolchain: toolchain.clone(), }))) diff --git a/crates/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs index feee40a1fc..2f9612e3a4 100644 --- a/crates/project-model/src/project_json.rs +++ b/crates/project-model/src/project_json.rs @@ -164,6 +164,7 @@ impl ProjectJson { is_proc_macro: crate_data.is_proc_macro, repository: crate_data.repository, build, + proc_macro_cwd: crate_data.proc_macro_cwd.map(absolutize_on_base), } }) .collect(), @@ -240,6 +241,8 @@ pub struct Crate { pub(crate) include: Vec, pub(crate) exclude: Vec, pub(crate) is_proc_macro: bool, + /// The working directory to run proc-macros in. This is usually the workspace root of cargo workspaces. + pub(crate) proc_macro_cwd: Option, pub(crate) repository: Option, pub build: Option, } @@ -362,6 +365,8 @@ struct CrateData { repository: Option, #[serde(default)] build: Option, + #[serde(default)] + proc_macro_cwd: Option, } mod cfg_ { diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index f5d46daa80..16b5bb11af 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -958,6 +958,7 @@ fn project_json_to_crate_graph( is_proc_macro, repository, is_workspace_member, + proc_macro_cwd, .. }, file_id, @@ -1005,7 +1006,6 @@ fn project_json_to_crate_graph( Arc::new(cfg_options), None, env, - *is_proc_macro, if let Some(name) = display_name.clone() { CrateOrigin::Local { repo: repository.clone(), @@ -1014,6 +1014,8 @@ fn project_json_to_crate_graph( } else { CrateOrigin::Local { repo: None, name: None } }, + *is_proc_macro, + proc_macro_cwd.clone(), ); debug!( ?crate_graph_crate_id, @@ -1283,11 +1285,12 @@ fn detached_file_to_crate_graph( cfg_options.clone(), None, Env::default(), - false, CrateOrigin::Local { repo: None, name: display_name.map(|n| n.canonical_name().to_owned()), }, + false, + None, ); public_deps.add_to_crate_graph(&mut crate_graph, detached_file_crate); @@ -1448,8 +1451,13 @@ fn add_target_crate_root( Arc::new(cfg_options), potential_cfg_options.map(Arc::new), env, - matches!(kind, TargetKind::Lib { is_proc_macro: true }), origin, + matches!(kind, TargetKind::Lib { is_proc_macro: true }), + Some(if pkg.is_member { + cargo.workspace_root().to_path_buf() + } else { + pkg.manifest.parent().to_path_buf() + }), ); if let TargetKind::Lib { is_proc_macro: true } = kind { let proc_macro = match build_data { @@ -1587,8 +1595,9 @@ fn sysroot_to_crate_graph( cfg_options.clone(), None, Env::default(), - false, CrateOrigin::Lang(LangCrateOrigin::from(&*stitched[krate].name)), + false, + None, ); Some((krate, crate_id)) }) diff --git a/crates/project-model/test_data/output/cargo_hello_world_project_model.txt b/crates/project-model/test_data/output/cargo_hello_world_project_model.txt index 880e90c52a..fae0b6fcca 100644 --- a/crates/project-model/test_data/output/cargo_hello_world_project_model.txt +++ b/crates/project-model/test_data/output/cargo_hello_world_project_model.txt @@ -61,6 +61,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 1: CrateData { root_file_id: FileId( @@ -132,6 +137,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 2: CrateData { root_file_id: FileId( @@ -203,6 +213,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 3: CrateData { root_file_id: FileId( @@ -274,6 +289,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 4: CrateData { root_file_id: FileId( @@ -341,5 +361,10 @@ name: "libc", }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98", + ), + ), }, } \ No newline at end of file diff --git a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt index 880e90c52a..fae0b6fcca 100644 --- a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt +++ b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt @@ -61,6 +61,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 1: CrateData { root_file_id: FileId( @@ -132,6 +137,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 2: CrateData { root_file_id: FileId( @@ -203,6 +213,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 3: CrateData { root_file_id: FileId( @@ -274,6 +289,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 4: CrateData { root_file_id: FileId( @@ -341,5 +361,10 @@ name: "libc", }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98", + ), + ), }, } \ No newline at end of file diff --git a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt index 7746acd225..566174882d 100644 --- a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt +++ b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt @@ -60,6 +60,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 1: CrateData { root_file_id: FileId( @@ -130,6 +135,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 2: CrateData { root_file_id: FileId( @@ -200,6 +210,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 3: CrateData { root_file_id: FileId( @@ -270,6 +285,11 @@ ), }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$hello-world", + ), + ), }, 4: CrateData { root_file_id: FileId( @@ -337,5 +357,10 @@ name: "libc", }, is_proc_macro: false, + proc_macro_cwd: Some( + AbsPathBuf( + "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98", + ), + ), }, } \ No newline at end of file diff --git a/crates/project-model/test_data/output/rust_project_cfg_groups.txt b/crates/project-model/test_data/output/rust_project_cfg_groups.txt index 587d3c1782..9b4be19c41 100644 --- a/crates/project-model/test_data/output/rust_project_cfg_groups.txt +++ b/crates/project-model/test_data/output/rust_project_cfg_groups.txt @@ -38,6 +38,7 @@ Alloc, ), is_proc_macro: false, + proc_macro_cwd: None, }, 1: CrateData { root_file_id: FileId( @@ -69,6 +70,7 @@ Core, ), is_proc_macro: false, + proc_macro_cwd: None, }, 2: CrateData { root_file_id: FileId( @@ -100,6 +102,7 @@ Other, ), is_proc_macro: false, + proc_macro_cwd: None, }, 3: CrateData { root_file_id: FileId( @@ -131,6 +134,7 @@ Other, ), is_proc_macro: false, + proc_macro_cwd: None, }, 4: CrateData { root_file_id: FileId( @@ -179,6 +183,7 @@ ProcMacro, ), is_proc_macro: false, + proc_macro_cwd: None, }, 5: CrateData { root_file_id: FileId( @@ -210,6 +215,7 @@ Other, ), is_proc_macro: false, + proc_macro_cwd: None, }, 6: CrateData { root_file_id: FileId( @@ -306,6 +312,7 @@ Std, ), is_proc_macro: false, + proc_macro_cwd: None, }, 7: CrateData { root_file_id: FileId( @@ -337,6 +344,7 @@ Other, ), is_proc_macro: false, + proc_macro_cwd: None, }, 8: CrateData { root_file_id: FileId( @@ -368,6 +376,7 @@ Test, ), is_proc_macro: false, + proc_macro_cwd: None, }, 9: CrateData { root_file_id: FileId( @@ -399,6 +408,7 @@ Other, ), is_proc_macro: false, + proc_macro_cwd: None, }, 10: CrateData { root_file_id: FileId( @@ -477,6 +487,7 @@ ), }, is_proc_macro: false, + proc_macro_cwd: None, }, 11: CrateData { root_file_id: FileId( @@ -555,5 +566,6 @@ ), }, is_proc_macro: false, + proc_macro_cwd: None, }, } \ No newline at end of file diff --git a/crates/project-model/test_data/output/rust_project_hello_world_project_model.txt b/crates/project-model/test_data/output/rust_project_hello_world_project_model.txt index 00805c79bc..4c8e66e8e9 100644 --- a/crates/project-model/test_data/output/rust_project_hello_world_project_model.txt +++ b/crates/project-model/test_data/output/rust_project_hello_world_project_model.txt @@ -38,6 +38,7 @@ Alloc, ), is_proc_macro: false, + proc_macro_cwd: None, }, 1: CrateData { root_file_id: FileId( @@ -69,6 +70,7 @@ Core, ), is_proc_macro: false, + proc_macro_cwd: None, }, 2: CrateData { root_file_id: FileId( @@ -100,6 +102,7 @@ Other, ), is_proc_macro: false, + proc_macro_cwd: None, }, 3: CrateData { root_file_id: FileId( @@ -131,6 +134,7 @@ Other, ), is_proc_macro: false, + proc_macro_cwd: None, }, 4: CrateData { root_file_id: FileId( @@ -179,6 +183,7 @@ ProcMacro, ), is_proc_macro: false, + proc_macro_cwd: None, }, 5: CrateData { root_file_id: FileId( @@ -210,6 +215,7 @@ Other, ), is_proc_macro: false, + proc_macro_cwd: None, }, 6: CrateData { root_file_id: FileId( @@ -306,6 +312,7 @@ Std, ), is_proc_macro: false, + proc_macro_cwd: None, }, 7: CrateData { root_file_id: FileId( @@ -337,6 +344,7 @@ Other, ), is_proc_macro: false, + proc_macro_cwd: None, }, 8: CrateData { root_file_id: FileId( @@ -368,6 +376,7 @@ Test, ), is_proc_macro: false, + proc_macro_cwd: None, }, 9: CrateData { root_file_id: FileId( @@ -399,6 +408,7 @@ Other, ), is_proc_macro: false, + proc_macro_cwd: None, }, 10: CrateData { root_file_id: FileId( @@ -474,5 +484,6 @@ ), }, is_proc_macro: false, + proc_macro_cwd: None, }, } \ No newline at end of file diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index ba72ea35df..56dcad0eb1 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -885,7 +885,6 @@ pub fn ws_to_crate_graph( ws_data.extend(mapping.values().copied().zip(iter::repeat(Arc::new(CrateWorkspaceData { toolchain: toolchain.clone(), data_layout: target_layout.clone(), - proc_macro_cwd: Some(ws.workspace_root().to_owned()), })))); proc_macro_paths.push(crate_proc_macros); } diff --git a/crates/test-fixture/src/lib.rs b/crates/test-fixture/src/lib.rs index 613f27c795..37dfb87721 100644 --- a/crates/test-fixture/src/lib.rs +++ b/crates/test-fixture/src/lib.rs @@ -211,8 +211,9 @@ impl ChangeFixture { From::from(meta.cfg.clone()), Some(From::from(meta.cfg)), meta.env, - false, origin, + false, + None, ); let prev = crates.insert(crate_name.clone(), crate_id); assert!(prev.is_none(), "multiple crates with same name: {crate_name}"); @@ -249,8 +250,9 @@ impl ChangeFixture { From::from(default_cfg.clone()), Some(From::from(default_cfg)), default_env, - false, CrateOrigin::Local { repo: None, name: None }, + false, + None, ); } else { for (from, to, prelude) in crate_deps { @@ -286,8 +288,9 @@ impl ChangeFixture { String::from("__ra_is_test_fixture"), String::from("__ra_is_test_fixture"), )]), - false, CrateOrigin::Lang(LangCrateOrigin::Core), + false, + None, ); for krate in all_crates { @@ -333,8 +336,9 @@ impl ChangeFixture { String::from("__ra_is_test_fixture"), String::from("__ra_is_test_fixture"), )]), - true, CrateOrigin::Local { repo: None, name: None }, + true, + None, ); proc_macros.insert(proc_macros_crate, Ok(proc_macro)); @@ -362,7 +366,6 @@ impl ChangeFixture { crate_graph .iter() .zip(iter::repeat(From::from(CrateWorkspaceData { - proc_macro_cwd: None, data_layout: target_data_layout, toolchain, }))) From f40ff2d8dc797065b520b2069aa294b0c497343d Mon Sep 17 00:00:00 2001 From: Josh Rotenberg Date: Fri, 14 Feb 2025 16:29:36 -0800 Subject: [PATCH 02/25] move dev docs to manual fix formatting --- CONTRIBUTING.md | 2 +- README.md | 4 +- docs/book/book.toml | 5 + docs/book/src/SUMMARY.md | 8 + docs/book/src/assists_generated.md | 298 +++++++++--------- docs/{dev => book/src/contributing}/README.md | 14 +- .../src/contributing}/architecture.md | 13 +- .../src/contributing}/debugging.md | 8 +- docs/{dev => book/src/contributing}/guide.md | 13 +- .../src/contributing}/lsp-extensions.md | 2 + docs/{dev => book/src/contributing}/setup.md | 0 docs/{dev => book/src/contributing}/style.md | 2 + docs/{dev => book/src/contributing}/syntax.md | 0 xtask/src/tidy.rs | 5 +- 14 files changed, 201 insertions(+), 173 deletions(-) rename docs/{dev => book/src/contributing}/README.md (98%) rename docs/{dev => book/src/contributing}/architecture.md (98%) rename docs/{dev => book/src/contributing}/debugging.md (99%) rename docs/{dev => book/src/contributing}/guide.md (99%) rename docs/{dev => book/src/contributing}/lsp-extensions.md (99%) rename docs/{dev => book/src/contributing}/setup.md (100%) rename docs/{dev => book/src/contributing}/style.md (99%) rename docs/{dev => book/src/contributing}/syntax.md (100%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index da65b034be..6f270fc63b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ Thank you for your interest in contributing to rust-analyzer! There are many way and we appreciate all of them. To get a quick overview of the crates and structure of the project take a look at the -[./docs/dev](./docs/dev) folder. +[Contributing](https://rust-analyzer.github.io/book/contributing) section of the manual. If you have any questions please ask them in the [rust-analyzer zulip stream]( https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer) or if unsure where diff --git a/README.md b/README.md index 56883723c9..4360dea4a1 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ https://rust-analyzer.github.io/book/installation.html ## Documentation If you want to **contribute** to rust-analyzer check out the [CONTRIBUTING.md](./CONTRIBUTING.md) or -if you are just curious about how things work under the hood, check the [./docs/dev](./docs/dev) -folder. +if you are just curious about how things work under the hood, see the +[Contributing](https://rust-analyzer.github.io/book/contributing) section of the manual. If you want to **use** rust-analyzer's language server with your editor of choice, check [the manual](https://rust-analyzer.github.io/book/). diff --git a/docs/book/book.toml b/docs/book/book.toml index 5ca4badde8..a6f6a6ed78 100644 --- a/docs/book/book.toml +++ b/docs/book/book.toml @@ -34,3 +34,8 @@ use-boolean-and = true [output.html.fold] enable = true level = 3 + +[preprocessor.toc] +command = "mdbook-toc" +renderer = ["html"] +max-level = 3 diff --git a/docs/book/src/SUMMARY.md b/docs/book/src/SUMMARY.md index 9dc4f1f2d2..1f211a97d7 100644 --- a/docs/book/src/SUMMARY.md +++ b/docs/book/src/SUMMARY.md @@ -14,3 +14,11 @@ - [Assists (Code Actions)](assists.md) - [Diagnostics](diagnostics.md) - [Editor Features](editor_features.md) +- [Contributing](contributing/README.md) + - [Architecture](contributing/architecture.md) + - [Debugging](contributing/debugging.md) + - [Guide](contributing/guide.md) + - [LSP Extensions](contributing/lsp-extensions.md) + - [Setup](contributing/setup.md) + - [Style](contributing/style.md) + - [Syntax](contributing/syntax.md) diff --git a/docs/book/src/assists_generated.md b/docs/book/src/assists_generated.md index 3617badeef..761a7f859b 100644 --- a/docs/book/src/assists_generated.md +++ b/docs/book/src/assists_generated.md @@ -1,7 +1,7 @@ //! Generated by `cargo xtask codegen assists-doc-tests`, do not edit by hand. ### `add_braces` -**Source:** [add_braces.rs](crates/ide-assists/src/handlers/add_braces.rs#8) +**Source:** [add_braces.rs](/crates/ide-assists/src/handlers/add_braces.rs#8) Adds braces to lambda and match arm expressions. @@ -29,7 +29,7 @@ fn foo(n: i32) -> i32 { ### `add_explicit_type` -**Source:** [add_explicit_type.rs](crates/ide-assists/src/handlers/add_explicit_type.rs#7) +**Source:** [add_explicit_type.rs](/crates/ide-assists/src/handlers/add_explicit_type.rs#7) Specify type for a let binding. @@ -49,7 +49,7 @@ fn main() { ### `add_hash` -**Source:** [raw_string.rs](crates/ide-assists/src/handlers/raw_string.rs#89) +**Source:** [raw_string.rs](/crates/ide-assists/src/handlers/raw_string.rs#89) Adds a hash to a raw string literal. @@ -69,7 +69,7 @@ fn main() { ### `add_impl_default_members` -**Source:** [add_missing_impl_members.rs](crates/ide-assists/src/handlers/add_missing_impl_members.rs#58) +**Source:** [add_missing_impl_members.rs](/crates/ide-assists/src/handlers/add_missing_impl_members.rs#58) Adds scaffold for overriding default impl members. @@ -105,7 +105,7 @@ impl Trait for () { ### `add_impl_missing_members` -**Source:** [add_missing_impl_members.rs](crates/ide-assists/src/handlers/add_missing_impl_members.rs#16) +**Source:** [add_missing_impl_members.rs](/crates/ide-assists/src/handlers/add_missing_impl_members.rs#16) Adds scaffold for required impl members. @@ -141,7 +141,7 @@ impl Trait for () { ### `add_label_to_loop` -**Source:** [add_label_to_loop.rs](crates/ide-assists/src/handlers/add_label_to_loop.rs#9) +**Source:** [add_label_to_loop.rs](/crates/ide-assists/src/handlers/add_label_to_loop.rs#9) Adds a label to a loop. @@ -167,7 +167,7 @@ fn main() { ### `add_lifetime_to_type` -**Source:** [add_lifetime_to_type.rs](crates/ide-assists/src/handlers/add_lifetime_to_type.rs#5) +**Source:** [add_lifetime_to_type.rs](/crates/ide-assists/src/handlers/add_lifetime_to_type.rs#5) Adds a new lifetime to a struct, enum or union. @@ -189,7 +189,7 @@ struct Point<'a> { ### `add_missing_match_arms` -**Source:** [add_missing_match_arms.rs](crates/ide-assists/src/handlers/add_missing_match_arms.rs#14) +**Source:** [add_missing_match_arms.rs](/crates/ide-assists/src/handlers/add_missing_match_arms.rs#14) Adds missing clauses to a `match` expression. @@ -218,7 +218,7 @@ fn handle(action: Action) { ### `add_return_type` -**Source:** [add_return_type.rs](crates/ide-assists/src/handlers/add_return_type.rs#6) +**Source:** [add_return_type.rs](/crates/ide-assists/src/handlers/add_return_type.rs#6) Adds the return type to a function or closure inferred from its tail expression if it doesn't have a return type specified. This assists is useable in a functions or closures tail expression or return type position. @@ -235,7 +235,7 @@ fn foo() -> i32 { 42i32 } ### `add_turbo_fish` -**Source:** [add_turbo_fish.rs](crates/ide-assists/src/handlers/add_turbo_fish.rs#14) +**Source:** [add_turbo_fish.rs](/crates/ide-assists/src/handlers/add_turbo_fish.rs#14) Adds `::<_>` to a call of a generic method or function. @@ -257,7 +257,7 @@ fn main() { ### `apply_demorgan` -**Source:** [apply_demorgan.rs](crates/ide-assists/src/handlers/apply_demorgan.rs#16) +**Source:** [apply_demorgan.rs](/crates/ide-assists/src/handlers/apply_demorgan.rs#16) Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). This transforms expressions of the form `!l || !r` into `!(l && r)`. @@ -280,7 +280,7 @@ fn main() { ### `apply_demorgan_iterator` -**Source:** [apply_demorgan.rs](crates/ide-assists/src/handlers/apply_demorgan.rs#132) +**Source:** [apply_demorgan.rs](/crates/ide-assists/src/handlers/apply_demorgan.rs#132) Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) to `Iterator::all` and `Iterator::any`. @@ -311,7 +311,7 @@ fn main() { ### `auto_import` -**Source:** [auto_import.rs](crates/ide-assists/src/handlers/auto_import.rs#73) +**Source:** [auto_import.rs](/crates/ide-assists/src/handlers/auto_import.rs#73) If the name is unresolved, provides all possible imports for it. @@ -333,7 +333,7 @@ fn main() { ### `bind_unused_param` -**Source:** [bind_unused_param.rs](crates/ide-assists/src/handlers/bind_unused_param.rs#12) +**Source:** [bind_unused_param.rs](/crates/ide-assists/src/handlers/bind_unused_param.rs#12) Binds unused function parameter to an underscore. @@ -351,7 +351,7 @@ fn some_function(x: i32) { ### `bool_to_enum` -**Source:** [bool_to_enum.rs](crates/ide-assists/src/handlers/bool_to_enum.rs#29) +**Source:** [bool_to_enum.rs](/crates/ide-assists/src/handlers/bool_to_enum.rs#29) This converts boolean local variables, fields, constants, and statics into a new enum with two variants `Bool::True` and `Bool::False`, as well as replacing @@ -385,7 +385,7 @@ fn main() { ### `change_visibility` -**Source:** [change_visibility.rs](crates/ide-assists/src/handlers/change_visibility.rs#13) +**Source:** [change_visibility.rs](/crates/ide-assists/src/handlers/change_visibility.rs#13) Adds or changes existing visibility specifier. @@ -401,7 +401,7 @@ pub(crate) fn frobnicate() {} ### `comment_to_doc` -**Source:** [convert_comment_from_or_to_doc.rs](crates/ide-assists/src/handlers/convert_comment_from_or_to_doc.rs#9) +**Source:** [convert_comment_from_or_to_doc.rs](/crates/ide-assists/src/handlers/convert_comment_from_or_to_doc.rs#9) Converts comments to documentation. @@ -419,7 +419,7 @@ Converts comments to documentation. ### `convert_bool_then_to_if` -**Source:** [convert_bool_then.rs](crates/ide-assists/src/handlers/convert_bool_then.rs#131) +**Source:** [convert_bool_then.rs](/crates/ide-assists/src/handlers/convert_bool_then.rs#131) Converts a `bool::then` method call to an equivalent if expression. @@ -443,7 +443,7 @@ fn main() { ### `convert_closure_to_fn` -**Source:** [convert_closure_to_fn.rs](crates/ide-assists/src/handlers/convert_closure_to_fn.rs#25) +**Source:** [convert_closure_to_fn.rs](/crates/ide-assists/src/handlers/convert_closure_to_fn.rs#25) This converts a closure to a freestanding function, changing all captures to parameters. @@ -469,7 +469,7 @@ fn main() { ### `convert_for_loop_with_for_each` -**Source:** [convert_iter_for_each_to_for.rs](crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs#76) +**Source:** [convert_iter_for_each_to_for.rs](/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs#76) Converts a for loop into a for_each loop on the Iterator. @@ -495,7 +495,7 @@ fn main() { ### `convert_from_to_tryfrom` -**Source:** [convert_from_to_tryfrom.rs](crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs#10) +**Source:** [convert_from_to_tryfrom.rs](/crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs#10) Converts a From impl to a TryFrom impl, wrapping returns in `Ok`. @@ -527,7 +527,7 @@ impl TryFrom for Thing { ### `convert_if_to_bool_then` -**Source:** [convert_bool_then.rs](crates/ide-assists/src/handlers/convert_bool_then.rs#20) +**Source:** [convert_bool_then.rs](/crates/ide-assists/src/handlers/convert_bool_then.rs#20) Converts an if expression into a corresponding `bool::then` call. @@ -551,7 +551,7 @@ fn main() { ### `convert_integer_literal` -**Source:** [convert_integer_literal.rs](crates/ide-assists/src/handlers/convert_integer_literal.rs#5) +**Source:** [convert_integer_literal.rs](/crates/ide-assists/src/handlers/convert_integer_literal.rs#5) Converts the base of integer literals to other bases. @@ -567,7 +567,7 @@ const _: i32 = 0b1010; ### `convert_into_to_from` -**Source:** [convert_into_to_from.rs](crates/ide-assists/src/handlers/convert_into_to_from.rs#8) +**Source:** [convert_into_to_from.rs](/crates/ide-assists/src/handlers/convert_into_to_from.rs#8) Converts an Into impl to an equivalent From impl. @@ -597,7 +597,7 @@ impl From for Thing { ### `convert_iter_for_each_to_for` -**Source:** [convert_iter_for_each_to_for.rs](crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs#11) +**Source:** [convert_iter_for_each_to_for.rs](/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs#11) Converts an Iterator::for_each function into a for loop. @@ -623,7 +623,7 @@ fn main() { ### `convert_let_else_to_match` -**Source:** [convert_let_else_to_match.rs](crates/ide-assists/src/handlers/convert_let_else_to_match.rs#9) +**Source:** [convert_let_else_to_match.rs](/crates/ide-assists/src/handlers/convert_let_else_to_match.rs#9) Converts let-else statement to let statement and match expression. @@ -646,7 +646,7 @@ fn main() { ### `convert_match_to_let_else` -**Source:** [convert_match_to_let_else.rs](crates/ide-assists/src/handlers/convert_match_to_let_else.rs#12) +**Source:** [convert_match_to_let_else.rs](/crates/ide-assists/src/handlers/convert_match_to_let_else.rs#12) Converts let statement with match initializer to let-else statement. @@ -669,7 +669,7 @@ fn foo(opt: Option<()>) { ### `convert_named_struct_to_tuple_struct` -**Source:** [convert_named_struct_to_tuple_struct.rs](crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs#11) +**Source:** [convert_named_struct_to_tuple_struct.rs](/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs#11) Converts struct with named fields to tuple struct, and analogously for enum variants with named fields. @@ -714,7 +714,7 @@ impl Point { ### `convert_nested_function_to_closure` -**Source:** [convert_nested_function_to_closure.rs](crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs#7) +**Source:** [convert_nested_function_to_closure.rs](/crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs#7) Converts a function that is defined within the body of another function into a closure. @@ -742,7 +742,7 @@ fn main() { ### `convert_to_guarded_return` -**Source:** [convert_to_guarded_return.rs](crates/ide-assists/src/handlers/convert_to_guarded_return.rs#24) +**Source:** [convert_to_guarded_return.rs](/crates/ide-assists/src/handlers/convert_to_guarded_return.rs#24) Replace a large conditional with a guarded return. @@ -769,7 +769,7 @@ fn main() { ### `convert_tuple_return_type_to_struct` -**Source:** [convert_tuple_return_type_to_struct.rs](crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs#20) +**Source:** [convert_tuple_return_type_to_struct.rs](/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs#20) This converts the return type of a function from a tuple type into a tuple struct and updates the body accordingly. @@ -800,7 +800,7 @@ fn foo() -> FooResult { ### `convert_tuple_struct_to_named_struct` -**Source:** [convert_tuple_struct_to_named_struct.rs](crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs#10) +**Source:** [convert_tuple_struct_to_named_struct.rs](/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs#10) Converts tuple struct to struct with named fields, and analogously for tuple enum variants. @@ -844,7 +844,7 @@ impl Point { ### `convert_two_arm_bool_match_to_matches_macro` -**Source:** [convert_two_arm_bool_match_to_matches_macro.rs](crates/ide-assists/src/handlers/convert_two_arm_bool_match_to_matches_macro.rs#8) +**Source:** [convert_two_arm_bool_match_to_matches_macro.rs](/crates/ide-assists/src/handlers/convert_two_arm_bool_match_to_matches_macro.rs#8) Convert 2-arm match that evaluates to a boolean into the equivalent matches! invocation. @@ -867,7 +867,7 @@ fn main() { ### `convert_while_to_loop` -**Source:** [convert_while_to_loop.rs](crates/ide-assists/src/handlers/convert_while_to_loop.rs#20) +**Source:** [convert_while_to_loop.rs](/crates/ide-assists/src/handlers/convert_while_to_loop.rs#20) Replace a while with a loop. @@ -894,7 +894,7 @@ fn main() { ### `destructure_struct_binding` -**Source:** [destructure_struct_binding.rs](crates/ide-assists/src/handlers/destructure_struct_binding.rs#18) +**Source:** [destructure_struct_binding.rs](/crates/ide-assists/src/handlers/destructure_struct_binding.rs#18) Destructures a struct binding in place. @@ -926,7 +926,7 @@ fn main() { ### `destructure_tuple_binding` -**Source:** [destructure_tuple_binding.rs](crates/ide-assists/src/handlers/destructure_tuple_binding.rs#19) +**Source:** [destructure_tuple_binding.rs](/crates/ide-assists/src/handlers/destructure_tuple_binding.rs#19) Destructures a tuple binding in place. @@ -948,7 +948,7 @@ fn main() { ### `desugar_async_into_impl_future` -**Source:** [toggle_async_sugar.rs](crates/ide-assists/src/handlers/toggle_async_sugar.rs#103) +**Source:** [toggle_async_sugar.rs](/crates/ide-assists/src/handlers/toggle_async_sugar.rs#103) Rewrites asynchronous function from `async fn` into `-> impl Future`. This action does not touch the function body and therefore `0` @@ -970,7 +970,7 @@ pub fn foo() -> impl core::future::Future { ### `desugar_doc_comment` -**Source:** [desugar_doc_comment.rs](crates/ide-assists/src/handlers/desugar_doc_comment.rs#14) +**Source:** [desugar_doc_comment.rs](/crates/ide-assists/src/handlers/desugar_doc_comment.rs#14) Desugars doc-comments to the attribute form. @@ -988,7 +988,7 @@ comment"] ### `expand_glob_import` -**Source:** [expand_glob_import.rs](crates/ide-assists/src/handlers/expand_glob_import.rs#18) +**Source:** [expand_glob_import.rs](/crates/ide-assists/src/handlers/expand_glob_import.rs#18) Expands glob imports. @@ -1018,7 +1018,7 @@ fn qux(bar: Bar, baz: Baz) {} ### `explicit_enum_discriminant` -**Source:** [explicit_enum_discriminant.rs](crates/ide-assists/src/handlers/explicit_enum_discriminant.rs#11) +**Source:** [explicit_enum_discriminant.rs](/crates/ide-assists/src/handlers/explicit_enum_discriminant.rs#11) Adds explicit discriminant to all enum variants. @@ -1044,7 +1044,7 @@ enum TheEnum { ### `extract_constant` -**Source:** [extract_variable.rs](crates/ide-assists/src/handlers/extract_variable.rs#35) +**Source:** [extract_variable.rs](/crates/ide-assists/src/handlers/extract_variable.rs#35) Extracts subexpression into a constant. @@ -1065,7 +1065,7 @@ fn main() { ### `extract_expressions_from_format_string` -**Source:** [extract_expressions_from_format_string.rs](crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs#14) +**Source:** [extract_expressions_from_format_string.rs](/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs#14) Move an expression out of a format string. @@ -1085,7 +1085,7 @@ fn main() { ### `extract_function` -**Source:** [extract_function.rs](crates/ide-assists/src/handlers/extract_function.rs#39) +**Source:** [extract_function.rs](/crates/ide-assists/src/handlers/extract_function.rs#39) Extracts selected statements and comments into new function. @@ -1117,7 +1117,7 @@ fn ┃fun_name(n: i32) { ### `extract_module` -**Source:** [extract_module.rs](crates/ide-assists/src/handlers/extract_module.rs#29) +**Source:** [extract_module.rs](/crates/ide-assists/src/handlers/extract_module.rs#29) Extracts a selected region as separate module. All the references, visibility and imports are resolved. @@ -1148,7 +1148,7 @@ fn bar(name: i32) -> i32 { ### `extract_static` -**Source:** [extract_variable.rs](crates/ide-assists/src/handlers/extract_variable.rs#52) +**Source:** [extract_variable.rs](/crates/ide-assists/src/handlers/extract_variable.rs#52) Extracts subexpression into a static. @@ -1169,7 +1169,7 @@ fn main() { ### `extract_struct_from_enum_variant` -**Source:** [extract_struct_from_enum_variant.rs](crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs#26) +**Source:** [extract_struct_from_enum_variant.rs](/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs#26) Extracts a struct from enum variant. @@ -1187,7 +1187,7 @@ enum A { One(One) } ### `extract_type_alias` -**Source:** [extract_type_alias.rs](crates/ide-assists/src/handlers/extract_type_alias.rs#10) +**Source:** [extract_type_alias.rs](/crates/ide-assists/src/handlers/extract_type_alias.rs#10) Extracts the selected type as a type alias. @@ -1209,7 +1209,7 @@ struct S { ### `extract_variable` -**Source:** [extract_variable.rs](crates/ide-assists/src/handlers/extract_variable.rs#18) +**Source:** [extract_variable.rs](/crates/ide-assists/src/handlers/extract_variable.rs#18) Extracts subexpression into a variable. @@ -1230,7 +1230,7 @@ fn main() { ### `fill_record_pattern_fields` -**Source:** [fill_record_pattern_fields.rs](crates/ide-assists/src/handlers/fill_record_pattern_fields.rs#8) +**Source:** [fill_record_pattern_fields.rs](/crates/ide-assists/src/handlers/fill_record_pattern_fields.rs#8) Fills fields by replacing rest pattern in record patterns. @@ -1254,7 +1254,7 @@ fn foo(bar: Bar) { ### `fix_visibility` -**Source:** [fix_visibility.rs](crates/ide-assists/src/handlers/fix_visibility.rs#14) +**Source:** [fix_visibility.rs](/crates/ide-assists/src/handlers/fix_visibility.rs#14) Makes inaccessible item public. @@ -1280,7 +1280,7 @@ fn main() { ### `flip_binexpr` -**Source:** [flip_binexpr.rs](crates/ide-assists/src/handlers/flip_binexpr.rs#8) +**Source:** [flip_binexpr.rs](/crates/ide-assists/src/handlers/flip_binexpr.rs#8) Flips operands of a binary expression. @@ -1300,7 +1300,7 @@ fn main() { ### `flip_comma` -**Source:** [flip_comma.rs](crates/ide-assists/src/handlers/flip_comma.rs#10) +**Source:** [flip_comma.rs](/crates/ide-assists/src/handlers/flip_comma.rs#10) Flips two comma-separated items. @@ -1320,7 +1320,7 @@ fn main() { ### `flip_trait_bound` -**Source:** [flip_trait_bound.rs](crates/ide-assists/src/handlers/flip_trait_bound.rs#9) +**Source:** [flip_trait_bound.rs](/crates/ide-assists/src/handlers/flip_trait_bound.rs#9) Flips two trait bounds. @@ -1336,7 +1336,7 @@ fn foo() { } ### `generate_constant` -**Source:** [generate_constant.rs](crates/ide-assists/src/handlers/generate_constant.rs#14) +**Source:** [generate_constant.rs](/crates/ide-assists/src/handlers/generate_constant.rs#14) Generate a named constant. @@ -1361,7 +1361,7 @@ fn main() { ### `generate_default_from_enum_variant` -**Source:** [generate_default_from_enum_variant.rs](crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs#6) +**Source:** [generate_default_from_enum_variant.rs](/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs#6) Adds a Default impl for an enum using a variant. @@ -1391,7 +1391,7 @@ impl Default for Version { ### `generate_default_from_new` -**Source:** [generate_default_from_new.rs](crates/ide-assists/src/handlers/generate_default_from_new.rs#13) +**Source:** [generate_default_from_new.rs](/crates/ide-assists/src/handlers/generate_default_from_new.rs#13) Generates default implementation from new method. @@ -1425,7 +1425,7 @@ impl Default for Example { ### `generate_delegate_methods` -**Source:** [generate_delegate_methods.rs](crates/ide-assists/src/handlers/generate_delegate_methods.rs#15) +**Source:** [generate_delegate_methods.rs](/crates/ide-assists/src/handlers/generate_delegate_methods.rs#15) Generate delegate methods. @@ -1465,7 +1465,7 @@ impl Person { ### `generate_delegate_trait` -**Source:** [generate_delegate_trait.rs](crates/ide-assists/src/handlers/generate_delegate_trait.rs#29) +**Source:** [generate_delegate_trait.rs](/crates/ide-assists/src/handlers/generate_delegate_trait.rs#29) Generate delegate trait implementation for `StructField`s. @@ -1531,7 +1531,7 @@ impl SomeTrait for B { ### `generate_deref` -**Source:** [generate_deref.rs](crates/ide-assists/src/handlers/generate_deref.rs#16) +**Source:** [generate_deref.rs](/crates/ide-assists/src/handlers/generate_deref.rs#16) Generate `Deref` impl using the given struct field. @@ -1561,7 +1561,7 @@ impl core::ops::Deref for B { ### `generate_derive` -**Source:** [generate_derive.rs](crates/ide-assists/src/handlers/generate_derive.rs#8) +**Source:** [generate_derive.rs](/crates/ide-assists/src/handlers/generate_derive.rs#8) Adds a new `#[derive()]` clause to a struct or enum. @@ -1584,7 +1584,7 @@ struct Point { ### `generate_doc_example` -**Source:** [generate_documentation_template.rs](crates/ide-assists/src/handlers/generate_documentation_template.rs#76) +**Source:** [generate_documentation_template.rs](/crates/ide-assists/src/handlers/generate_documentation_template.rs#76) Generates a rustdoc example when editing an item's documentation. @@ -1610,7 +1610,7 @@ pub fn add(a: i32, b: i32) -> i32 { a + b } ### `generate_documentation_template` -**Source:** [generate_documentation_template.rs](crates/ide-assists/src/handlers/generate_documentation_template.rs#13) +**Source:** [generate_documentation_template.rs](/crates/ide-assists/src/handlers/generate_documentation_template.rs#13) Adds a documentation template above a function definition / declaration. @@ -1645,7 +1645,7 @@ impl S { ### `generate_enum_as_method` -**Source:** [generate_enum_projection_method.rs](crates/ide-assists/src/handlers/generate_enum_projection_method.rs#59) +**Source:** [generate_enum_projection_method.rs](/crates/ide-assists/src/handlers/generate_enum_projection_method.rs#59) Generate an `as_` method for this enum variant. @@ -1677,7 +1677,7 @@ impl Value { ### `generate_enum_is_method` -**Source:** [generate_enum_is_method.rs](crates/ide-assists/src/handlers/generate_enum_is_method.rs#11) +**Source:** [generate_enum_is_method.rs](/crates/ide-assists/src/handlers/generate_enum_is_method.rs#11) Generate an `is_` method for this enum variant. @@ -1711,7 +1711,7 @@ impl Version { ### `generate_enum_try_into_method` -**Source:** [generate_enum_projection_method.rs](crates/ide-assists/src/handlers/generate_enum_projection_method.rs#12) +**Source:** [generate_enum_projection_method.rs](/crates/ide-assists/src/handlers/generate_enum_projection_method.rs#12) Generate a `try_into_` method for this enum variant. @@ -1743,7 +1743,7 @@ impl Value { ### `generate_enum_variant` -**Source:** [generate_enum_variant.rs](crates/ide-assists/src/handlers/generate_enum_variant.rs#10) +**Source:** [generate_enum_variant.rs](/crates/ide-assists/src/handlers/generate_enum_variant.rs#10) Adds a variant to an enum. @@ -1772,7 +1772,7 @@ fn main() { ### `generate_fn_type_alias_named` -**Source:** [generate_fn_type_alias.rs](crates/ide-assists/src/handlers/generate_fn_type_alias.rs#10) +**Source:** [generate_fn_type_alias.rs](/crates/ide-assists/src/handlers/generate_fn_type_alias.rs#10) Generate a type alias for the function with named parameters. @@ -1790,7 +1790,7 @@ unsafe fn foo(n: i32) -> i32 { 42i32 } ### `generate_fn_type_alias_unnamed` -**Source:** [generate_fn_type_alias.rs](crates/ide-assists/src/handlers/generate_fn_type_alias.rs#24) +**Source:** [generate_fn_type_alias.rs](/crates/ide-assists/src/handlers/generate_fn_type_alias.rs#24) Generate a type alias for the function with unnamed parameters. @@ -1808,7 +1808,7 @@ unsafe fn foo(n: i32) -> i32 { 42i32 } ### `generate_from_impl_for_enum` -**Source:** [generate_from_impl_for_enum.rs](crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs#8) +**Source:** [generate_from_impl_for_enum.rs](/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs#8) Adds a From impl for this enum variant with one tuple field. @@ -1830,7 +1830,7 @@ impl From for A { ### `generate_function` -**Source:** [generate_function.rs](crates/ide-assists/src/handlers/generate_function.rs#28) +**Source:** [generate_function.rs](/crates/ide-assists/src/handlers/generate_function.rs#28) Adds a stub function with a signature matching the function under the cursor. @@ -1860,7 +1860,7 @@ fn bar(arg: &str, baz: Baz) ${0:-> _} { ### `generate_getter` -**Source:** [generate_getter_or_setter.rs](crates/ide-assists/src/handlers/generate_getter_or_setter.rs#73) +**Source:** [generate_getter_or_setter.rs](/crates/ide-assists/src/handlers/generate_getter_or_setter.rs#73) Generate a getter method. @@ -1886,7 +1886,7 @@ impl Person { ### `generate_getter_mut` -**Source:** [generate_getter_or_setter.rs](crates/ide-assists/src/handlers/generate_getter_or_setter.rs#127) +**Source:** [generate_getter_or_setter.rs](/crates/ide-assists/src/handlers/generate_getter_or_setter.rs#127) Generate a mut getter method. @@ -1912,7 +1912,7 @@ impl Person { ### `generate_impl` -**Source:** [generate_impl.rs](crates/ide-assists/src/handlers/generate_impl.rs#20) +**Source:** [generate_impl.rs](/crates/ide-assists/src/handlers/generate_impl.rs#20) Adds a new inherent impl for a type. @@ -1934,7 +1934,7 @@ impl Ctx {┃} ### `generate_is_empty_from_len` -**Source:** [generate_is_empty_from_len.rs](crates/ide-assists/src/handlers/generate_is_empty_from_len.rs#12) +**Source:** [generate_is_empty_from_len.rs](/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs#12) Generates is_empty implementation from the len method. @@ -1969,7 +1969,7 @@ impl MyStruct { ### `generate_mut_trait_impl` -**Source:** [generate_mut_trait_impl.rs](crates/ide-assists/src/handlers/generate_mut_trait_impl.rs#12) +**Source:** [generate_mut_trait_impl.rs](/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs#12) Adds a IndexMut impl from the `Index` trait. @@ -2007,7 +2007,7 @@ impl core::ops::Index for [T; 3] { ### `generate_new` -**Source:** [generate_new.rs](crates/ide-assists/src/handlers/generate_new.rs#14) +**Source:** [generate_new.rs](/crates/ide-assists/src/handlers/generate_new.rs#14) Adds a `fn new` for a type. @@ -2033,7 +2033,7 @@ impl Ctx { ### `generate_setter` -**Source:** [generate_getter_or_setter.rs](crates/ide-assists/src/handlers/generate_getter_or_setter.rs#13) +**Source:** [generate_getter_or_setter.rs](/crates/ide-assists/src/handlers/generate_getter_or_setter.rs#13) Generate a setter method. @@ -2059,7 +2059,7 @@ impl Person { ### `generate_trait_from_impl` -**Source:** [generate_trait_from_impl.rs](crates/ide-assists/src/handlers/generate_trait_from_impl.rs#18) +**Source:** [generate_trait_from_impl.rs](/crates/ide-assists/src/handlers/generate_trait_from_impl.rs#18) Generate trait for an already defined inherent impl and convert impl to a trait impl. @@ -2118,7 +2118,7 @@ impl ${0:NewTrait} for Foo { ### `generate_trait_impl` -**Source:** [generate_impl.rs](crates/ide-assists/src/handlers/generate_impl.rs#66) +**Source:** [generate_impl.rs](/crates/ide-assists/src/handlers/generate_impl.rs#66) Adds a new trait impl for a type. @@ -2140,7 +2140,7 @@ impl ${0:_} for Ctx {} ### `inline_call` -**Source:** [inline_call.rs](crates/ide-assists/src/handlers/inline_call.rs#170) +**Source:** [inline_call.rs](/crates/ide-assists/src/handlers/inline_call.rs#170) Inlines a function or method body creating a `let` statement per parameter unless the parameter can be inlined. The parameter will be inlined either if it the supplied argument is a simple local @@ -2165,7 +2165,7 @@ fn foo(name: Option<&str>) { ### `inline_const_as_literal` -**Source:** [inline_const_as_literal.rs](crates/ide-assists/src/handlers/inline_const_as_literal.rs#6) +**Source:** [inline_const_as_literal.rs](/crates/ide-assists/src/handlers/inline_const_as_literal.rs#6) Evaluate and inline const variable as literal. @@ -2189,7 +2189,7 @@ fn something() -> &'static str { ### `inline_into_callers` -**Source:** [inline_call.rs](crates/ide-assists/src/handlers/inline_call.rs#32) +**Source:** [inline_call.rs](/crates/ide-assists/src/handlers/inline_call.rs#32) Inline a function or method body into all of its callers where possible, creating a `let` statement per parameter unless the parameter can be inlined. The parameter will be inlined either if it the supplied argument is a simple local @@ -2232,7 +2232,7 @@ fn bar() { ### `inline_local_variable` -**Source:** [inline_local_variable.rs](crates/ide-assists/src/handlers/inline_local_variable.rs#17) +**Source:** [inline_local_variable.rs](/crates/ide-assists/src/handlers/inline_local_variable.rs#17) Inlines a local variable. @@ -2253,7 +2253,7 @@ fn main() { ### `inline_macro` -**Source:** [inline_macro.rs](crates/ide-assists/src/handlers/inline_macro.rs#7) +**Source:** [inline_macro.rs](/crates/ide-assists/src/handlers/inline_macro.rs#7) Takes a macro and inlines it one step. @@ -2289,7 +2289,7 @@ fn main() { ### `inline_type_alias` -**Source:** [inline_type_alias.rs](crates/ide-assists/src/handlers/inline_type_alias.rs#106) +**Source:** [inline_type_alias.rs](/crates/ide-assists/src/handlers/inline_type_alias.rs#106) Replace a type alias with its concrete type. @@ -2313,7 +2313,7 @@ fn main() { ### `inline_type_alias_uses` -**Source:** [inline_type_alias.rs](crates/ide-assists/src/handlers/inline_type_alias.rs#24) +**Source:** [inline_type_alias.rs](/crates/ide-assists/src/handlers/inline_type_alias.rs#24) Inline a type alias into all of its uses where possible. @@ -2341,7 +2341,7 @@ fn foo() { ### `into_to_qualified_from` -**Source:** [into_to_qualified_from.rs](crates/ide-assists/src/handlers/into_to_qualified_from.rs#10) +**Source:** [into_to_qualified_from.rs](/crates/ide-assists/src/handlers/into_to_qualified_from.rs#10) Convert an `into` method call to a fully qualified `from` call. @@ -2378,7 +2378,7 @@ fn main() -> () { ### `introduce_named_generic` -**Source:** [introduce_named_generic.rs](crates/ide-assists/src/handlers/introduce_named_generic.rs#7) +**Source:** [introduce_named_generic.rs](/crates/ide-assists/src/handlers/introduce_named_generic.rs#7) Replaces `impl Trait` function argument with the named generic. @@ -2394,7 +2394,7 @@ fn foo<┃B: Bar>(bar: B) {} ### `introduce_named_lifetime` -**Source:** [introduce_named_lifetime.rs](crates/ide-assists/src/handlers/introduce_named_lifetime.rs#13) +**Source:** [introduce_named_lifetime.rs](/crates/ide-assists/src/handlers/introduce_named_lifetime.rs#13) Change an anonymous lifetime to a named lifetime. @@ -2422,7 +2422,7 @@ impl<'a> Cursor<'a> { ### `invert_if` -**Source:** [invert_if.rs](crates/ide-assists/src/handlers/invert_if.rs#13) +**Source:** [invert_if.rs](/crates/ide-assists/src/handlers/invert_if.rs#13) This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}` This also works with `!=`. This assist can only be applied with the cursor on `if`. @@ -2443,7 +2443,7 @@ fn main() { ### `line_to_block` -**Source:** [convert_comment_block.rs](crates/ide-assists/src/handlers/convert_comment_block.rs#9) +**Source:** [convert_comment_block.rs](/crates/ide-assists/src/handlers/convert_comment_block.rs#9) Converts comments between block and single-line form. @@ -2463,7 +2463,7 @@ Converts comments between block and single-line form. ### `make_raw_string` -**Source:** [raw_string.rs](crates/ide-assists/src/handlers/raw_string.rs#7) +**Source:** [raw_string.rs](/crates/ide-assists/src/handlers/raw_string.rs#7) Adds `r#` to a plain string literal. @@ -2483,7 +2483,7 @@ fn main() { ### `make_usual_string` -**Source:** [raw_string.rs](crates/ide-assists/src/handlers/raw_string.rs#47) +**Source:** [raw_string.rs](/crates/ide-assists/src/handlers/raw_string.rs#47) Turns a raw string into a plain string. @@ -2503,7 +2503,7 @@ fn main() { ### `merge_imports` -**Source:** [merge_imports.rs](crates/ide-assists/src/handlers/merge_imports.rs#21) +**Source:** [merge_imports.rs](/crates/ide-assists/src/handlers/merge_imports.rs#21) Merges neighbor imports with a common prefix. @@ -2520,7 +2520,7 @@ use std::{fmt::Formatter, io}; ### `merge_match_arms` -**Source:** [merge_match_arms.rs](crates/ide-assists/src/handlers/merge_match_arms.rs#12) +**Source:** [merge_match_arms.rs](/crates/ide-assists/src/handlers/merge_match_arms.rs#12) Merges the current match arm with the following if their bodies are identical. @@ -2549,7 +2549,7 @@ fn handle(action: Action) { ### `merge_nested_if` -**Source:** [merge_nested_if.rs](crates/ide-assists/src/handlers/merge_nested_if.rs#11) +**Source:** [merge_nested_if.rs](/crates/ide-assists/src/handlers/merge_nested_if.rs#11) This transforms if expressions of the form `if x { if y {A} }` into `if x && y {A}` This assist can only be applied with the cursor on `if`. @@ -2570,7 +2570,7 @@ fn main() { ### `move_arm_cond_to_match_guard` -**Source:** [move_guard.rs](crates/ide-assists/src/handlers/move_guard.rs#69) +**Source:** [move_guard.rs](/crates/ide-assists/src/handlers/move_guard.rs#69) Moves if expression from match arm body into a guard. @@ -2600,7 +2600,7 @@ fn handle(action: Action) { ### `move_bounds_to_where_clause` -**Source:** [move_bounds.rs](crates/ide-assists/src/handlers/move_bounds.rs#12) +**Source:** [move_bounds.rs](/crates/ide-assists/src/handlers/move_bounds.rs#12) Moves inline type bounds to a where clause. @@ -2620,7 +2620,7 @@ fn apply(f: F, x: T) -> U where F: FnOnce(T) -> U { ### `move_const_to_impl` -**Source:** [move_const_to_impl.rs](crates/ide-assists/src/handlers/move_const_to_impl.rs#14) +**Source:** [move_const_to_impl.rs](/crates/ide-assists/src/handlers/move_const_to_impl.rs#14) Move a local constant item in a method to impl's associated constant. All the references will be qualified with `Self::`. @@ -2653,7 +2653,7 @@ impl S { ### `move_from_mod_rs` -**Source:** [move_from_mod_rs.rs](crates/ide-assists/src/handlers/move_from_mod_rs.rs#12) +**Source:** [move_from_mod_rs.rs](/crates/ide-assists/src/handlers/move_from_mod_rs.rs#12) Moves xxx/mod.rs to xxx.rs. @@ -2672,7 +2672,7 @@ fn t() {} ### `move_guard_to_arm_body` -**Source:** [move_guard.rs](crates/ide-assists/src/handlers/move_guard.rs#8) +**Source:** [move_guard.rs](/crates/ide-assists/src/handlers/move_guard.rs#8) Moves match guard into match arm body. @@ -2704,7 +2704,7 @@ fn handle(action: Action) { ### `move_module_to_file` -**Source:** [move_module_to_file.rs](crates/ide-assists/src/handlers/move_module_to_file.rs#15) +**Source:** [move_module_to_file.rs](/crates/ide-assists/src/handlers/move_module_to_file.rs#15) Moves inline module's contents to a separate file. @@ -2722,7 +2722,7 @@ mod foo; ### `move_to_mod_rs` -**Source:** [move_to_mod_rs.rs](crates/ide-assists/src/handlers/move_to_mod_rs.rs#12) +**Source:** [move_to_mod_rs.rs](/crates/ide-assists/src/handlers/move_to_mod_rs.rs#12) Moves xxx.rs to xxx/mod.rs. @@ -2741,7 +2741,7 @@ fn t() {} ### `normalize_import` -**Source:** [normalize_import.rs](crates/ide-assists/src/handlers/normalize_import.rs#9) +**Source:** [normalize_import.rs](/crates/ide-assists/src/handlers/normalize_import.rs#9) Normalizes an import. @@ -2757,7 +2757,7 @@ use std::{fmt::Formatter, io}; ### `promote_local_to_const` -**Source:** [promote_local_to_const.rs](crates/ide-assists/src/handlers/promote_local_to_const.rs#17) +**Source:** [promote_local_to_const.rs](/crates/ide-assists/src/handlers/promote_local_to_const.rs#17) Promotes a local variable to a const item changing its name to a `SCREAMING_SNAKE_CASE` variant if the local uses no non-const expressions. @@ -2790,7 +2790,7 @@ fn main() { ### `pull_assignment_up` -**Source:** [pull_assignment_up.rs](crates/ide-assists/src/handlers/pull_assignment_up.rs#11) +**Source:** [pull_assignment_up.rs](/crates/ide-assists/src/handlers/pull_assignment_up.rs#11) Extracts variable assignment to outside an if or match statement. @@ -2822,7 +2822,7 @@ fn main() { ### `qualify_method_call` -**Source:** [qualify_method_call.rs](crates/ide-assists/src/handlers/qualify_method_call.rs#10) +**Source:** [qualify_method_call.rs](/crates/ide-assists/src/handlers/qualify_method_call.rs#10) Replaces the method call with a qualified function call. @@ -2852,7 +2852,7 @@ fn main() { ### `qualify_path` -**Source:** [qualify_path.rs](crates/ide-assists/src/handlers/qualify_path.rs#24) +**Source:** [qualify_path.rs](/crates/ide-assists/src/handlers/qualify_path.rs#24) If the name is unresolved, provides all possible qualified paths for it. @@ -2872,7 +2872,7 @@ fn main() { ### `reformat_number_literal` -**Source:** [number_representation.rs](crates/ide-assists/src/handlers/number_representation.rs#7) +**Source:** [number_representation.rs](/crates/ide-assists/src/handlers/number_representation.rs#7) Adds or removes separators from integer literal. @@ -2888,7 +2888,7 @@ const _: i32 = 1_012_345; ### `remove_dbg` -**Source:** [remove_dbg.rs](crates/ide-assists/src/handlers/remove_dbg.rs#9) +**Source:** [remove_dbg.rs](/crates/ide-assists/src/handlers/remove_dbg.rs#9) Removes `dbg!()` macro call. @@ -2908,7 +2908,7 @@ fn main() { ### `remove_hash` -**Source:** [raw_string.rs](crates/ide-assists/src/handlers/raw_string.rs#117) +**Source:** [raw_string.rs](/crates/ide-assists/src/handlers/raw_string.rs#117) Removes a hash from a raw string literal. @@ -2928,7 +2928,7 @@ fn main() { ### `remove_mut` -**Source:** [remove_mut.rs](crates/ide-assists/src/handlers/remove_mut.rs#5) +**Source:** [remove_mut.rs](/crates/ide-assists/src/handlers/remove_mut.rs#5) Removes the `mut` keyword. @@ -2948,7 +2948,7 @@ impl Walrus { ### `remove_parentheses` -**Source:** [remove_parentheses.rs](crates/ide-assists/src/handlers/remove_parentheses.rs#5) +**Source:** [remove_parentheses.rs](/crates/ide-assists/src/handlers/remove_parentheses.rs#5) Removes redundant parentheses. @@ -2968,7 +2968,7 @@ fn main() { ### `remove_unused_imports` -**Source:** [remove_unused_imports.rs](crates/ide-assists/src/handlers/remove_unused_imports.rs#17) +**Source:** [remove_unused_imports.rs](/crates/ide-assists/src/handlers/remove_unused_imports.rs#17) Removes any use statements in the current selection that are unused. @@ -2989,7 +2989,7 @@ mod foo { ### `remove_unused_param` -**Source:** [remove_unused_param.rs](crates/ide-assists/src/handlers/remove_unused_param.rs#15) +**Source:** [remove_unused_param.rs](/crates/ide-assists/src/handlers/remove_unused_param.rs#15) Removes unused function parameter. @@ -3013,7 +3013,7 @@ fn main() { ### `reorder_fields` -**Source:** [reorder_fields.rs](crates/ide-assists/src/handlers/reorder_fields.rs#8) +**Source:** [reorder_fields.rs](/crates/ide-assists/src/handlers/reorder_fields.rs#8) Reorder the fields of record literals and record patterns in the same order as in the definition. @@ -3032,7 +3032,7 @@ const test: Foo = Foo {foo: 1, bar: 0} ### `reorder_impl_items` -**Source:** [reorder_impl_items.rs](crates/ide-assists/src/handlers/reorder_impl_items.rs#11) +**Source:** [reorder_impl_items.rs](/crates/ide-assists/src/handlers/reorder_impl_items.rs#11) Reorder the items of an `impl Trait`. The items will be ordered in the same order as in the trait definition. @@ -3071,7 +3071,7 @@ impl Foo for Bar { ### `replace_arith_with_checked` -**Source:** [replace_arith_op.rs](crates/ide-assists/src/handlers/replace_arith_op.rs#9) +**Source:** [replace_arith_op.rs](/crates/ide-assists/src/handlers/replace_arith_op.rs#9) Replaces arithmetic on integers with the `checked_*` equivalent. @@ -3091,7 +3091,7 @@ fn main() { ### `replace_arith_with_saturating` -**Source:** [replace_arith_op.rs](crates/ide-assists/src/handlers/replace_arith_op.rs#28) +**Source:** [replace_arith_op.rs](/crates/ide-assists/src/handlers/replace_arith_op.rs#28) Replaces arithmetic on integers with the `saturating_*` equivalent. @@ -3111,7 +3111,7 @@ fn main() { ### `replace_arith_with_wrapping` -**Source:** [replace_arith_op.rs](crates/ide-assists/src/handlers/replace_arith_op.rs#50) +**Source:** [replace_arith_op.rs](/crates/ide-assists/src/handlers/replace_arith_op.rs#50) Replaces arithmetic on integers with the `wrapping_*` equivalent. @@ -3131,7 +3131,7 @@ fn main() { ### `replace_char_with_string` -**Source:** [replace_string_with_char.rs](crates/ide-assists/src/handlers/replace_string_with_char.rs#51) +**Source:** [replace_string_with_char.rs](/crates/ide-assists/src/handlers/replace_string_with_char.rs#51) Replace a char literal with a string literal. @@ -3151,7 +3151,7 @@ fn main() { ### `replace_derive_with_manual_impl` -**Source:** [replace_derive_with_manual_impl.rs](crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs#20) +**Source:** [replace_derive_with_manual_impl.rs](/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs#20) Converts a `derive` impl into a manual one. @@ -3175,7 +3175,7 @@ impl Debug for S { ### `replace_if_let_with_match` -**Source:** [replace_if_let_with_match.rs](crates/ide-assists/src/handlers/replace_if_let_with_match.rs#20) +**Source:** [replace_if_let_with_match.rs](/crates/ide-assists/src/handlers/replace_if_let_with_match.rs#20) Replaces a `if let` expression with a `match` expression. @@ -3206,7 +3206,7 @@ fn handle(action: Action) { ### `replace_is_some_with_if_let_some` -**Source:** [replace_is_method_with_if_let_method.rs](crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs#9) +**Source:** [replace_is_method_with_if_let_method.rs](/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs#9) Replace `if x.is_some()` with `if let Some(_tmp) = x` or `if x.is_ok()` with `if let Ok(_tmp) = x`. @@ -3228,7 +3228,7 @@ fn main() { ### `replace_let_with_if_let` -**Source:** [replace_let_with_if_let.rs](crates/ide-assists/src/handlers/replace_let_with_if_let.rs#9) +**Source:** [replace_let_with_if_let.rs](/crates/ide-assists/src/handlers/replace_let_with_if_let.rs#9) Replaces `let` with an `if let`. @@ -3255,7 +3255,7 @@ fn compute() -> Option { None } ### `replace_match_with_if_let` -**Source:** [replace_if_let_with_match.rs](crates/ide-assists/src/handlers/replace_if_let_with_match.rs#188) +**Source:** [replace_if_let_with_match.rs](/crates/ide-assists/src/handlers/replace_if_let_with_match.rs#188) Replaces a binary `match` with a wildcard pattern and no guards with an `if let` expression. @@ -3286,7 +3286,7 @@ fn handle(action: Action) { ### `replace_named_generic_with_impl` -**Source:** [replace_named_generic_with_impl.rs](crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs#18) +**Source:** [replace_named_generic_with_impl.rs](/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs#18) Replaces named generic with an `impl Trait` in function argument. @@ -3302,7 +3302,7 @@ fn new(location: impl AsRef) -> Self {} ### `replace_qualified_name_with_use` -**Source:** [replace_qualified_name_with_use.rs](crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs#13) +**Source:** [replace_qualified_name_with_use.rs](/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs#13) Adds a use statement for a given fully-qualified name. @@ -3320,7 +3320,7 @@ fn process(map: HashMap) {} ### `replace_string_with_char` -**Source:** [replace_string_with_char.rs](crates/ide-assists/src/handlers/replace_string_with_char.rs#11) +**Source:** [replace_string_with_char.rs](/crates/ide-assists/src/handlers/replace_string_with_char.rs#11) Replace string literal with char literal. @@ -3340,7 +3340,7 @@ fn main() { ### `replace_try_expr_with_match` -**Source:** [replace_try_expr_with_match.rs](crates/ide-assists/src/handlers/replace_try_expr_with_match.rs#18) +**Source:** [replace_try_expr_with_match.rs](/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs#18) Replaces a `try` expression with a `match` expression. @@ -3363,7 +3363,7 @@ fn handle() { ### `replace_turbofish_with_explicit_type` -**Source:** [replace_turbofish_with_explicit_type.rs](crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs#12) +**Source:** [replace_turbofish_with_explicit_type.rs](/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs#12) Converts `::<_>` to an explicit type assignment. @@ -3385,7 +3385,7 @@ fn main() { ### `replace_with_eager_method` -**Source:** [replace_method_eager_lazy.rs](crates/ide-assists/src/handlers/replace_method_eager_lazy.rs#89) +**Source:** [replace_method_eager_lazy.rs](/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs#89) Replace `unwrap_or_else` with `unwrap_or` and `ok_or_else` with `ok_or`. @@ -3407,7 +3407,7 @@ fn foo() { ### `replace_with_lazy_method` -**Source:** [replace_method_eager_lazy.rs](crates/ide-assists/src/handlers/replace_method_eager_lazy.rs#9) +**Source:** [replace_method_eager_lazy.rs](/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs#9) Replace `unwrap_or` with `unwrap_or_else` and `ok_or` with `ok_or_else`. @@ -3429,7 +3429,7 @@ fn foo() { ### `sort_items` -**Source:** [sort_items.rs](crates/ide-assists/src/handlers/sort_items.rs#12) +**Source:** [sort_items.rs](/crates/ide-assists/src/handlers/sort_items.rs#12) Sorts item members alphabetically: fields, enum variants and methods. @@ -3520,7 +3520,7 @@ enum Animal { ### `split_import` -**Source:** [split_import.rs](crates/ide-assists/src/handlers/split_import.rs#5) +**Source:** [split_import.rs](/crates/ide-assists/src/handlers/split_import.rs#5) Wraps the tail of import into braces. @@ -3536,7 +3536,7 @@ use std::{collections::HashMap}; ### `sugar_impl_future_into_async` -**Source:** [toggle_async_sugar.rs](crates/ide-assists/src/handlers/toggle_async_sugar.rs#13) +**Source:** [toggle_async_sugar.rs](/crates/ide-assists/src/handlers/toggle_async_sugar.rs#13) Rewrites asynchronous function from `-> impl Future` into `async fn`. This action does not touch the function body and therefore `async { 0 }` @@ -3558,7 +3558,7 @@ pub async fn foo() -> usize { ### `toggle_ignore` -**Source:** [toggle_ignore.rs](crates/ide-assists/src/handlers/toggle_ignore.rs#8) +**Source:** [toggle_ignore.rs](/crates/ide-assists/src/handlers/toggle_ignore.rs#8) Adds `#[ignore]` attribute to the test. @@ -3581,7 +3581,7 @@ fn arithmetics { ### `toggle_macro_delimiter` -**Source:** [toggle_macro_delimiter.rs](crates/ide-assists/src/handlers/toggle_macro_delimiter.rs#9) +**Source:** [toggle_macro_delimiter.rs](/crates/ide-assists/src/handlers/toggle_macro_delimiter.rs#9) Change macro delimiters in the order of `( -> { -> [ -> (`. @@ -3605,7 +3605,7 @@ sth!{ } ### `unmerge_match_arm` -**Source:** [unmerge_match_arm.rs](crates/ide-assists/src/handlers/unmerge_match_arm.rs#10) +**Source:** [unmerge_match_arm.rs](/crates/ide-assists/src/handlers/unmerge_match_arm.rs#10) Splits the current match with a `|` pattern into two arms with identical bodies. @@ -3634,7 +3634,7 @@ fn handle(action: Action) { ### `unmerge_use` -**Source:** [unmerge_use.rs](crates/ide-assists/src/handlers/unmerge_use.rs#12) +**Source:** [unmerge_use.rs](/crates/ide-assists/src/handlers/unmerge_use.rs#12) Extracts single use item from use list. @@ -3651,7 +3651,7 @@ use std::fmt::Display; ### `unnecessary_async` -**Source:** [unnecessary_async.rs](crates/ide-assists/src/handlers/unnecessary_async.rs#17) +**Source:** [unnecessary_async.rs](/crates/ide-assists/src/handlers/unnecessary_async.rs#17) Removes the `async` mark from functions which have no `.await` in their body. Looks for calls to the functions and removes the `.await` on the call site. @@ -3670,7 +3670,7 @@ pub async fn bar() { foo() } ### `unqualify_method_call` -**Source:** [unqualify_method_call.rs](crates/ide-assists/src/handlers/unqualify_method_call.rs#9) +**Source:** [unqualify_method_call.rs](/crates/ide-assists/src/handlers/unqualify_method_call.rs#9) Transforms universal function call syntax into a method call. @@ -3692,7 +3692,7 @@ fn main() { ### `unwrap_block` -**Source:** [unwrap_block.rs](crates/ide-assists/src/handlers/unwrap_block.rs#12) +**Source:** [unwrap_block.rs](/crates/ide-assists/src/handlers/unwrap_block.rs#12) This assist removes if...else, for, while and loop control statements to just keep the body. @@ -3714,7 +3714,7 @@ fn foo() { ### `unwrap_option_return_type` -**Source:** [unwrap_return_type.rs](crates/ide-assists/src/handlers/unwrap_return_type.rs#13) +**Source:** [unwrap_return_type.rs](/crates/ide-assists/src/handlers/unwrap_return_type.rs#13) Unwrap the function's return type. @@ -3730,7 +3730,7 @@ fn foo() -> i32 { 42i32 } ### `unwrap_result_return_type` -**Source:** [unwrap_return_type.rs](crates/ide-assists/src/handlers/unwrap_return_type.rs#26) +**Source:** [unwrap_return_type.rs](/crates/ide-assists/src/handlers/unwrap_return_type.rs#26) Unwrap the function's return type. @@ -3746,7 +3746,7 @@ fn foo() -> i32 { 42i32 } ### `unwrap_tuple` -**Source:** [unwrap_tuple.rs](crates/ide-assists/src/handlers/unwrap_tuple.rs#8) +**Source:** [unwrap_tuple.rs](/crates/ide-assists/src/handlers/unwrap_tuple.rs#8) Unwrap the tuple to different variables. @@ -3767,7 +3767,7 @@ fn main() { ### `wrap_return_type_in_option` -**Source:** [wrap_return_type.rs](crates/ide-assists/src/handlers/wrap_return_type.rs#16) +**Source:** [wrap_return_type.rs](/crates/ide-assists/src/handlers/wrap_return_type.rs#16) Wrap the function's return type into Option. @@ -3783,7 +3783,7 @@ fn foo() -> Option { Some(42i32) } ### `wrap_return_type_in_result` -**Source:** [wrap_return_type.rs](crates/ide-assists/src/handlers/wrap_return_type.rs#29) +**Source:** [wrap_return_type.rs](/crates/ide-assists/src/handlers/wrap_return_type.rs#29) Wrap the function's return type into Result. @@ -3799,7 +3799,7 @@ fn foo() -> Result { Ok(42i32) } ### `wrap_unwrap_cfg_attr` -**Source:** [wrap_unwrap_cfg_attr.rs](crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs#12) +**Source:** [wrap_unwrap_cfg_attr.rs](/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs#12) Wraps an attribute to a cfg_attr attribute or unwraps a cfg_attr attribute to the inner attributes. diff --git a/docs/dev/README.md b/docs/book/src/contributing/README.md similarity index 98% rename from docs/dev/README.md rename to docs/book/src/contributing/README.md index c990212d58..cbbf6acf3e 100644 --- a/docs/dev/README.md +++ b/docs/book/src/contributing/README.md @@ -9,7 +9,7 @@ $ cargo test should be enough to get you started! -To learn more about how rust-analyzer works, see [./architecture.md](./architecture.md). +To learn more about how rust-analyzer works, see [Architecture](architecture.md). It also explains the high-level layout of the source code. Do skim through that document. @@ -24,7 +24,9 @@ rust-analyzer is a part of the [RLS-2.0 working group](https://github.com/rust-lang/compiler-team/tree/6a769c13656c0a6959ebc09e7b1f7c09b86fb9c0/working-groups/rls-2.0). Discussion happens in this Zulip stream: -https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer + + + # Issue Labels @@ -54,7 +56,7 @@ https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer # Code Style & Review Process -Do see [./style.md](./style.md). +See the [Style Guide](style.md). # Cookbook @@ -88,11 +90,13 @@ As a sanity check after I'm done, I use `cargo xtask install --server` and **Rel If the problem concerns only the VS Code extension, I use **Run Installed Extension** launch configuration from `launch.json`. Notably, this uses the usual `rust-analyzer` binary from `PATH`. For this, it is important to have the following in your `settings.json` file: + ```json { "rust-analyzer.server.path": "rust-analyzer" } ``` + After I am done with the fix, I use `cargo xtask install --client` to try the new extension for real. If I need to fix something in the `rust-analyzer` crate, I feel sad because it's on the boundary between the two processes, and working there is slow. @@ -117,6 +121,7 @@ cd editors/code npm ci npm run lint ``` + ## How to ... * ... add an assist? [#7535](https://github.com/rust-lang/rust-analyzer/pull/7535) @@ -142,14 +147,15 @@ Note that `stdout` is used for the actual protocol, so `println!` will break thi To log all communication between the server and the client, there are two choices: * You can log on the server side, by running something like + ``` env RA_LOG=lsp_server=debug code . ``` + * You can log on the client side, by the `rust-analyzer: Toggle LSP Logs` command or enabling `"rust-analyzer.trace.server": "verbose"` workspace setting. These logs are shown in a separate tab in the output and could be used with LSP inspector. Kudos to [@DJMcNab](https://github.com/DJMcNab) for setting this awesome infra up! - There are also several VS Code commands which might be of interest: * `rust-analyzer: Status` shows some memory-usage statistics. diff --git a/docs/dev/architecture.md b/docs/book/src/contributing/architecture.md similarity index 98% rename from docs/dev/architecture.md rename to docs/book/src/contributing/architecture.md index 9c9e05a429..b9b98bfea3 100644 --- a/docs/dev/architecture.md +++ b/docs/book/src/contributing/architecture.md @@ -8,19 +8,20 @@ It goes deeper than what is covered in this document, but will take some time to See also these implementation-related blog posts: -* https://rust-analyzer.github.io/blog/2019/11/13/find-usages.html -* https://rust-analyzer.github.io/blog/2020/07/20/three-architectures-for-responsive-ide.html -* https://rust-analyzer.github.io/blog/2020/09/16/challeging-LR-parsing.html -* https://rust-analyzer.github.io/blog/2020/09/28/how-to-make-a-light-bulb.html -* https://rust-analyzer.github.io/blog/2020/10/24/introducing-ungrammar.html +* +* +* +* +* For older, by now mostly outdated stuff, see the [guide](./guide.md) and [another playlist](https://www.youtube.com/playlist?list=PL85XCvVPmGQho7MZkdW-wtPtuJcFpzycE). - ## Bird's Eye View ![](https://user-images.githubusercontent.com/4789492/107129398-0ab70f00-687a-11eb-9bfc-d4eb023aec06.png) + + On the highest level, rust-analyzer is a thing which accepts input source code from the client and produces a structured semantic model of the code. More specifically, input data consists of a set of test files (`(PathBuf, String)` pairs) and information about project structure, captured in the so called `CrateGraph`. diff --git a/docs/dev/debugging.md b/docs/book/src/contributing/debugging.md similarity index 99% rename from docs/dev/debugging.md rename to docs/book/src/contributing/debugging.md index 48caec1d8f..db3a28eed1 100644 --- a/docs/dev/debugging.md +++ b/docs/book/src/contributing/debugging.md @@ -8,6 +8,7 @@ Debug options view - Install all TypeScript dependencies + ```bash cd editors/code npm ci @@ -19,7 +20,6 @@ where **only** the `rust-analyzer` extension being debugged is enabled. * To activate the extension you need to open any Rust project folder in `[Extension Development Host]`. - ## Debug TypeScript VSCode extension - `Run Installed Extension` - runs the extension with the globally installed `rust-analyzer` binary. @@ -36,12 +36,12 @@ To apply changes to an already running debug process, press Ctrl+Shift+PCtrl+Shift+P + ## The big picture On the highest possible level, rust-analyzer is a stateful component. A client may @@ -76,10 +78,10 @@ to study its methods to understand all the input data. The `change_file` method controls the set of the input files, where each file has an integer id (`FileId`, picked by the client) and text (`Option>`). -Paths are tricky; they'll be explained below, in source roots section, +Paths are tricky; they'll be explained below, in source roots section, together with the `set_roots` method. The "source root" [`is_library`] flag -along with the concept of [`durability`] allows us to add a group of files which -are assumed to rarely change. It's mostly an optimization and does not change +along with the concept of [`durability`] allows us to add a group of files which +are assumed to rarely change. It's mostly an optimization and does not change the fundamental picture. [`is_library`]: https://github.com/rust-lang/rust-analyzer/blob/2024-01-01/crates/base-db/src/input.rs#L38 @@ -141,7 +143,7 @@ the source root, even `/dev/random`. ## Language Server Protocol -Now let's see how the `Analysis` API is exposed via the JSON RPC based language server protocol. +Now let's see how the `Analysis` API is exposed via the JSON RPC based language server protocol. The hard part here is managing changes (which can come either from the file system or from the editor) and concurrency (we want to spawn background jobs for things like syntax highlighting). We use the event loop pattern to manage the zoo, and @@ -152,13 +154,12 @@ the loop is the [`GlobalState::run`] function initiated by [`main_loop`] after [`GlobalState::new`]: https://github.com/rust-lang/rust-analyzer/blob/2024-01-01/crates/rust-analyzer/src/global_state.rs#L148-L215 [`GlobalState::run`]: https://github.com/rust-lang/rust-analyzer/blob/2024-01-01/crates/rust-analyzer/src/main_loop.rs#L114-L140 - Let's walk through a typical analyzer session! First, we need to figure out what to analyze. To do this, we run `cargo metadata` to learn about Cargo packages for current workspace and dependencies, and we run `rustc --print sysroot` and scan the "sysroot" -(the directory containing the current Rust toolchain's files) to learn about crates +(the directory containing the current Rust toolchain's files) to learn about crates like `std`. This happens in the [`GlobalState::fetch_workspaces`] method. We load this configuration at the start of the server in [`GlobalState::new`], but it's also triggered by workspace change events and requests to reload the diff --git a/docs/dev/lsp-extensions.md b/docs/book/src/contributing/lsp-extensions.md similarity index 99% rename from docs/dev/lsp-extensions.md rename to docs/book/src/contributing/lsp-extensions.md index c7ee4e4023..14a3fd1ebd 100644 --- a/docs/dev/lsp-extensions.md +++ b/docs/book/src/contributing/lsp-extensions.md @@ -19,6 +19,8 @@ Requests, which are likely to always remain specific to `rust-analyzer` are unde If you want to be notified about the changes to this document, subscribe to [#4604](https://github.com/rust-lang/rust-analyzer/issues/4604). + + ## Configuration in `initializationOptions` **Upstream Issue:** https://github.com/microsoft/language-server-protocol/issues/567 diff --git a/docs/dev/setup.md b/docs/book/src/contributing/setup.md similarity index 100% rename from docs/dev/setup.md rename to docs/book/src/contributing/setup.md diff --git a/docs/dev/style.md b/docs/book/src/contributing/style.md similarity index 99% rename from docs/dev/style.md rename to docs/book/src/contributing/style.md index 51b60ab2eb..6e5d1869b1 100644 --- a/docs/dev/style.md +++ b/docs/book/src/contributing/style.md @@ -1,3 +1,5 @@ +# Style + Our approach to "clean code" is two-fold: * We generally don't block PRs on style changes. diff --git a/docs/dev/syntax.md b/docs/book/src/contributing/syntax.md similarity index 100% rename from docs/dev/syntax.md rename to docs/book/src/contributing/syntax.md diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs index 35412be876..fbc88e7acf 100644 --- a/xtask/src/tidy.rs +++ b/xtask/src/tidy.rs @@ -27,8 +27,9 @@ fn check_lsp_extensions_docs(sh: &Shell) { }; let actual_hash = { - let lsp_extensions_md = - sh.read_file(project_root().join("docs/dev/lsp-extensions.md")).unwrap(); + let lsp_extensions_md = sh + .read_file(project_root().join("docs/book/src/contributing/lsp-extensions.md")) + .unwrap(); let text = lsp_extensions_md .lines() .find_map(|line| line.strip_prefix("lsp/ext.rs hash:")) From 6543225ad9920d19cfe1f3a4486cf635c08d436e Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 18 Feb 2025 11:37:43 +0100 Subject: [PATCH 03/25] Revert "pass struct fields to chalk" --- crates/hir-ty/src/chalk_db.rs | 20 +++++++++++--------- crates/hir-ty/src/tests/coercion.rs | 25 +++---------------------- crates/hir-ty/src/tests/traits.rs | 12 ++++++------ 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/crates/hir-ty/src/chalk_db.rs b/crates/hir-ty/src/chalk_db.rs index 6d4753ea38..c8ff6cba3d 100644 --- a/crates/hir-ty/src/chalk_db.rs +++ b/crates/hir-ty/src/chalk_db.rs @@ -768,21 +768,23 @@ pub(crate) fn adt_datum_query( phantom_data, }; - let variant_id_to_fields = |id: VariantId| { + // this slows down rust-analyzer by quite a bit unfortunately, so enabling this is currently not worth it + let _variant_id_to_fields = |id: VariantId| { let variant_data = &id.variant_data(db.upcast()); - let fields = if variant_data.fields().is_empty() || bound_vars_subst.is_empty(Interner) { + let fields = if variant_data.fields().is_empty() { vec![] } else { - // HACK: provide full struct type info slows down rust-analyzer by quite a bit unfortunately, - // so we trick chalk into thinking that our struct impl Unsize - if let Some(ty) = bound_vars_subst.at(Interner, 0).ty(Interner) { - vec![ty.clone()] - } else { - vec![] - } + let field_types = db.field_types(id); + variant_data + .fields() + .iter() + .map(|(idx, _)| field_types[idx].clone().substitute(Interner, &bound_vars_subst)) + .filter(|it| !it.contains_unknown()) + .collect() }; rust_ir::AdtVariantDatum { fields } }; + let variant_id_to_fields = |_: VariantId| rust_ir::AdtVariantDatum { fields: vec![] }; let (kind, variants) = match adt_id { hir_def::AdtId::StructId(id) => { diff --git a/crates/hir-ty/src/tests/coercion.rs b/crates/hir-ty/src/tests/coercion.rs index ef94814d58..7e7c1f835c 100644 --- a/crates/hir-ty/src/tests/coercion.rs +++ b/crates/hir-ty/src/tests/coercion.rs @@ -535,7 +535,7 @@ fn test() { #[test] fn coerce_unsize_generic() { - check_no_mismatches( + check( r#" //- minicore: coerce_unsized struct Foo { t: T }; @@ -543,7 +543,9 @@ struct Bar(Foo); fn test() { let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] }; + //^^^^^^^^^^^^^^^^^^^^^ expected &'? Foo<[usize]>, got &'? Foo<[i32; 3]> let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); + //^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &'? Bar<[usize]>, got &'? Bar<[i32; 3]> } "#, ); @@ -955,24 +957,3 @@ fn f() { "#, ); } - -#[test] -fn coerce_nested_unsized_struct() { - check_types( - r#" -//- minicore: fn, coerce_unsized, dispatch_from_dyn, sized -use core::marker::Unsize; - -struct Foo(T); - -fn need(_: &Foo i32>) { -} - -fn test() { - let callback = |x| x; - //^ i32 - need(&Foo(callback)); -} -"#, - ) -} diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs index f0eb41b1ce..dda7bfb2ba 100644 --- a/crates/hir-ty/src/tests/traits.rs +++ b/crates/hir-ty/src/tests/traits.rs @@ -4694,21 +4694,21 @@ fn f() { Struct::::IS_SEND; //^^^^^^^^^^^^^^^^^^^^Yes Struct::::IS_SEND; - //^^^^^^^^^^^^^^^^^^^^{unknown} + //^^^^^^^^^^^^^^^^^^^^Yes Struct::<*const T>::IS_SEND; - //^^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown} + //^^^^^^^^^^^^^^^^^^^^^^^^^^^Yes Enum::::IS_SEND; //^^^^^^^^^^^^^^^^^^Yes Enum::::IS_SEND; - //^^^^^^^^^^^^^^^^^^{unknown} + //^^^^^^^^^^^^^^^^^^Yes Enum::<*const T>::IS_SEND; - //^^^^^^^^^^^^^^^^^^^^^^^^^{unknown} + //^^^^^^^^^^^^^^^^^^^^^^^^^Yes Union::::IS_SEND; //^^^^^^^^^^^^^^^^^^^Yes Union::::IS_SEND; - //^^^^^^^^^^^^^^^^^^^{unknown} + //^^^^^^^^^^^^^^^^^^^Yes Union::<*const T>::IS_SEND; - //^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown} + //^^^^^^^^^^^^^^^^^^^^^^^^^^Yes PhantomData::::IS_SEND; //^^^^^^^^^^^^^^^^^^^^^^^^^Yes PhantomData::::IS_SEND; From e5484d9c735b23b53f93a83618dab24f2e5fd4e5 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Tue, 18 Feb 2025 17:22:45 +0100 Subject: [PATCH 04/25] Fix dead link --- xtask/src/tidy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs index fbc88e7acf..b500b251ed 100644 --- a/xtask/src/tidy.rs +++ b/xtask/src/tidy.rs @@ -186,7 +186,7 @@ Zlib OR Apache-2.0 OR MIT fn check_test_attrs(path: &Path, text: &str) { let panic_rule = - "https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/style.md#should_panic"; + "https://github.com/rust-lang/rust-analyzer/blob/master/docs/book/src/contributing/style.md#should_panic"; let need_panic: &[&str] = &[ // This file. "slow-tests/tidy.rs", From fc10fe44def77b36fd1ee26165ea3a9e38b1b9b0 Mon Sep 17 00:00:00 2001 From: Ali Bektas Date: Tue, 18 Feb 2025 20:49:43 +0100 Subject: [PATCH 05/25] Fix 19090 --- crates/ide-assists/src/assist_config.rs | 1 + .../src/handlers/generate_delegate_methods.rs | 4 ++ .../src/handlers/generate_delegate_trait.rs | 4 ++ crates/ide-assists/src/tests.rs | 57 +++++++++++++++++++ crates/rust-analyzer/src/config.rs | 1 + 5 files changed, 67 insertions(+) diff --git a/crates/ide-assists/src/assist_config.rs b/crates/ide-assists/src/assist_config.rs index fb533077d9..05105c8c92 100644 --- a/crates/ide-assists/src/assist_config.rs +++ b/crates/ide-assists/src/assist_config.rs @@ -20,6 +20,7 @@ pub struct AssistConfig { pub assist_emit_must_use: bool, pub term_search_fuel: u64, pub term_search_borrowck: bool, + pub code_action_grouping: bool, } impl AssistConfig { diff --git a/crates/ide-assists/src/handlers/generate_delegate_methods.rs b/crates/ide-assists/src/handlers/generate_delegate_methods.rs index 081e36b4ff..03ec60bede 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_methods.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_methods.rs @@ -48,6 +48,10 @@ use crate::{ // } // ``` pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { + if !ctx.config.code_action_grouping { + return None; + } + let strukt = ctx.find_node_at_offset::()?; let strukt_name = strukt.name()?; let current_module = ctx.sema.scope(strukt.syntax())?.module(); diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index 66bf9b0186..6a4541e4fe 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -88,6 +88,10 @@ use syntax::{ // } // ``` pub(crate) fn generate_delegate_trait(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { + if !ctx.config.code_action_grouping { + return None; + } + let strukt = Struct::new(ctx.find_node_at_offset::()?)?; let field: Field = match ctx.find_node_at_offset::() { diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs index 48d2af6d3f..87851e445d 100644 --- a/crates/ide-assists/src/tests.rs +++ b/crates/ide-assists/src/tests.rs @@ -34,6 +34,26 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig { assist_emit_must_use: false, term_search_fuel: 400, term_search_borrowck: true, + code_action_grouping: true, +}; + +pub(crate) const TEST_CONFIG_NO_GROUPING: AssistConfig = AssistConfig { + snippet_cap: SnippetCap::new(true), + allowed: None, + insert_use: InsertUseConfig { + granularity: ImportGranularity::Crate, + prefix_kind: hir::PrefixKind::Plain, + enforce_granularity: true, + group: true, + skip_glob_imports: true, + }, + prefer_no_std: false, + prefer_prelude: true, + prefer_absolute: false, + assist_emit_must_use: false, + term_search_fuel: 400, + term_search_borrowck: true, + code_action_grouping: false, }; pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig { @@ -52,6 +72,7 @@ pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig { assist_emit_must_use: false, term_search_fuel: 400, term_search_borrowck: true, + code_action_grouping: true, }; pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig { @@ -70,6 +91,7 @@ pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig { assist_emit_must_use: false, term_search_fuel: 400, term_search_borrowck: true, + code_action_grouping: true, }; pub(crate) fn with_single_file(text: &str) -> (RootDatabase, EditionedFileId) { @@ -346,6 +368,41 @@ fn labels(assists: &[Assist]) -> String { labels.into_iter().collect::() } +#[test] +fn long_groups_are_skipped_under_skip_resolve_strategy() { + let before = r#" +trait SomeTrait { + type T; + fn fn_(arg: u32) -> u32; + fn method_(&mut self) -> bool; +} +struct A; +impl SomeTrait for A { + type T = u32; + + fn fn_(arg: u32) -> u32 { + 42 + } + + fn method_(&mut self) -> bool { + false + } +} +struct B { + a$0 : A, +} + "#; + let (before_cursor_pos, before) = extract_offset(before); + let (db, file_id) = with_single_file(&before); + let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; + let res = assists(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange.into()); + assert!(res.iter().map(|a| &a.id).any(|a| { a.0 == "generate_delegate_trait" })); + + let limited = + assists(&db, &TEST_CONFIG_NO_GROUPING, AssistResolveStrategy::None, frange.into()); + assert!(!limited.iter().map(|a| &a.id).any(|a| { a.0 == "generate_delegate_trait" })); +} + #[test] fn assist_order_field_struct() { let before = "struct Foo { $0bar: u32 }"; diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index d7e9a5c586..1dce0bea1a 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -1476,6 +1476,7 @@ impl Config { prefer_absolute: self.imports_prefixExternPrelude(source_root).to_owned(), term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64, term_search_borrowck: self.assist_termSearch_borrowcheck(source_root).to_owned(), + code_action_grouping: self.code_action_group(), } } From ea9e17928707d57918e9dd12a0806e462ca069a0 Mon Sep 17 00:00:00 2001 From: Josh Rotenberg Date: Tue, 18 Feb 2025 12:57:18 -0800 Subject: [PATCH 06/25] use fully qualified url for source path --- xtask/src/codegen.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index e84c259e97..58a3fb6441 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs @@ -117,7 +117,13 @@ impl fmt::Display for Location { let path = self.file.strip_prefix(project_root()).unwrap().display().to_string(); let path = path.replace('\\', "/"); let name = self.file.file_name().unwrap(); - write!(f, " [{}](/{}#{}) ", name.to_str().unwrap(), path, self.line) + write!( + f, + " [{}](https://github.com/rust-lang/rust-analyzer/blob/master/{}#{}) ", + name.to_str().unwrap(), + path, + self.line + ) } } From 9d5a97368a0f15a7fdaf823b5b397446b8551483 Mon Sep 17 00:00:00 2001 From: Ali Bektas Date: Tue, 18 Feb 2025 21:58:27 +0100 Subject: [PATCH 07/25] Add a check_assist_* overload and move tests under assists --- .../src/handlers/generate_delegate_methods.rs | 21 +++++++- .../src/handlers/generate_delegate_trait.rs | 33 ++++++++++++- crates/ide-assists/src/tests.rs | 49 ++++++------------- 3 files changed, 66 insertions(+), 37 deletions(-) diff --git a/crates/ide-assists/src/handlers/generate_delegate_methods.rs b/crates/ide-assists/src/handlers/generate_delegate_methods.rs index 03ec60bede..220259451e 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_methods.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_methods.rs @@ -217,7 +217,9 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<' #[cfg(test)] mod tests { - use crate::tests::{check_assist, check_assist_not_applicable}; + use crate::tests::{ + check_assist, check_assist_not_applicable, check_assist_not_applicable_no_grouping, + }; use super::*; @@ -721,4 +723,21 @@ impl Person { "#, ); } + + #[test] + fn delegate_method_skipped_when_no_grouping() { + check_assist_not_applicable_no_grouping( + generate_delegate_methods, + r#" +struct Age(u8); +impl Age { + fn age(&self) -> u8 { + self.0 + } +} +struct Person { + ag$0e: Age, +}"#, + ); + } } diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index 6a4541e4fe..55b860d0ff 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -792,7 +792,9 @@ fn qualified_path(qual_path_ty: ast::Path, path_expr_seg: ast::Path) -> ast::Pat mod test { use super::*; - use crate::tests::{check_assist, check_assist_not_applicable}; + use crate::tests::{ + check_assist, check_assist_not_applicable, check_assist_not_applicable_no_grouping, + }; #[test] fn test_tuple_struct_basic() { @@ -1840,4 +1842,33 @@ impl> C for B { "#, ) } + + #[test] + fn delegate_trait_skipped_when_no_grouping() { + check_assist_not_applicable_no_grouping( + generate_delegate_trait, + r#" +trait SomeTrait { + type T; + fn fn_(arg: u32) -> u32; + fn method_(&mut self) -> bool; +} +struct A; +impl SomeTrait for A { + type T = u32; + + fn fn_(arg: u32) -> u32 { + 42 + } + + fn method_(&mut self) -> bool { + false + } +} +struct B { + a$0 : A, +} +"#, + ); + } } diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs index 87851e445d..11aeb21c77 100644 --- a/crates/ide-assists/src/tests.rs +++ b/crates/ide-assists/src/tests.rs @@ -195,6 +195,20 @@ pub(crate) fn check_assist_not_applicable_for_import_one( ); } +#[track_caller] +pub(crate) fn check_assist_not_applicable_no_grouping( + assist: Handler, + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) { + check_with_config( + TEST_CONFIG_NO_GROUPING, + assist, + ra_fixture, + ExpectedResult::NotApplicable, + None, + ); +} + /// Check assist in unresolved state. Useful to check assists for lazy computation. #[track_caller] pub(crate) fn check_assist_unresolved( @@ -368,41 +382,6 @@ fn labels(assists: &[Assist]) -> String { labels.into_iter().collect::() } -#[test] -fn long_groups_are_skipped_under_skip_resolve_strategy() { - let before = r#" -trait SomeTrait { - type T; - fn fn_(arg: u32) -> u32; - fn method_(&mut self) -> bool; -} -struct A; -impl SomeTrait for A { - type T = u32; - - fn fn_(arg: u32) -> u32 { - 42 - } - - fn method_(&mut self) -> bool { - false - } -} -struct B { - a$0 : A, -} - "#; - let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = with_single_file(&before); - let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; - let res = assists(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange.into()); - assert!(res.iter().map(|a| &a.id).any(|a| { a.0 == "generate_delegate_trait" })); - - let limited = - assists(&db, &TEST_CONFIG_NO_GROUPING, AssistResolveStrategy::None, frange.into()); - assert!(!limited.iter().map(|a| &a.id).any(|a| { a.0 == "generate_delegate_trait" })); -} - #[test] fn assist_order_field_struct() { let before = "struct Foo { $0bar: u32 }"; From 9d459e8de73123f9dc80aa08cc56d0e03dc2d58f Mon Sep 17 00:00:00 2001 From: Shoyu Vanilla Date: Thu, 20 Feb 2025 00:47:21 +0900 Subject: [PATCH 08/25] fix: Binding wrong assoc ty when lowering trait ref bound --- crates/hir-ty/src/lower/path.rs | 19 +++++++-------- crates/hir-ty/src/mir/eval/tests.rs | 36 ++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/crates/hir-ty/src/lower/path.rs b/crates/hir-ty/src/lower/path.rs index 22c5bb9923..176c147b71 100644 --- a/crates/hir-ty/src/lower/path.rs +++ b/crates/hir-ty/src/lower/path.rs @@ -837,15 +837,16 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> { } (_, ImplTraitLoweringMode::Param | ImplTraitLoweringMode::Variable) => { // Find the generic index for the target of our `bound` - let target_param_idx = - self.ctx.resolver.where_predicates_in_scope().find_map(|(p, _)| { - match p { - WherePredicate::TypeBound { - target: WherePredicateTypeTarget::TypeOrConstParam(idx), - bound: b, - } if b == bound => Some(idx), - _ => None, - } + let target_param_idx = self + .ctx + .resolver + .where_predicates_in_scope() + .find_map(|(p, (_, types_map))| match p { + WherePredicate::TypeBound { + target: WherePredicateTypeTarget::TypeOrConstParam(idx), + bound: b, + } if b == bound && self.ctx.types_map == types_map => Some(idx), + _ => None, }); let ty = if let Some(target_param_idx) = target_param_idx { let mut counter = 0; diff --git a/crates/hir-ty/src/mir/eval/tests.rs b/crates/hir-ty/src/mir/eval/tests.rs index 9625ae5f88..2b5486fc5f 100644 --- a/crates/hir-ty/src/mir/eval/tests.rs +++ b/crates/hir-ty/src/mir/eval/tests.rs @@ -3,7 +3,7 @@ use span::{Edition, EditionedFileId}; use syntax::{TextRange, TextSize}; use test_fixture::WithFixture; -use crate::{db::HirDatabase, test_db::TestDB, Interner, Substitution}; +use crate::{db::HirDatabase, mir::MirLowerError, test_db::TestDB, Interner, Substitution}; use super::{interpret_mir, MirEvalError}; @@ -84,6 +84,16 @@ fn check_panic(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected_panic: assert_eq!(e.is_panic().unwrap_or_else(|| panic!("unexpected error: {e:?}")), expected_panic); } +fn check_error_with( + #[rust_analyzer::rust_fixture] ra_fixture: &str, + expect_err: impl FnOnce(MirEvalError) -> bool, +) { + let (db, file_ids) = TestDB::with_many_files(ra_fixture); + let file_id = *file_ids.last().unwrap(); + let e = eval_main(&db, file_id).unwrap_err(); + assert!(expect_err(e)); +} + #[test] fn function_with_extern_c_abi() { check_pass( @@ -945,3 +955,27 @@ fn main() { "#, ); } + +#[test] +fn regression_19177() { + check_error_with( + r#" +//- minicore: copy +trait Foo {} +trait Bar {} +trait Baz {} +trait Qux { + type Assoc; +} + +fn main<'a, T: Foo + Bar + Baz>( + x: &T, + y: (), + z: &'a dyn Qux, + w: impl Foo + Bar, +) { +} +"#, + |e| matches!(e, MirEvalError::MirLowerError(_, MirLowerError::GenericArgNotProvided(..))), + ); +} From a82773ab483e3943fecbacd959f6637ed07790f2 Mon Sep 17 00:00:00 2001 From: Shoyu Vanilla Date: Thu, 20 Feb 2025 08:49:00 +0900 Subject: [PATCH 09/25] Explicitly compare `TypesMap` as ptrs --- crates/hir-ty/src/lower/path.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/crates/hir-ty/src/lower/path.rs b/crates/hir-ty/src/lower/path.rs index 176c147b71..a165932ddc 100644 --- a/crates/hir-ty/src/lower/path.rs +++ b/crates/hir-ty/src/lower/path.rs @@ -10,7 +10,7 @@ use hir_def::{ generics::{TypeParamProvenance, WherePredicate, WherePredicateTypeTarget}, path::{GenericArg, GenericArgs, Path, PathSegment, PathSegments}, resolver::{ResolveValueResult, TypeNs, ValueNs}, - type_ref::{TypeBound, TypeRef}, + type_ref::{TypeBound, TypeRef, TypesMap}, GenericDefId, GenericParamId, ItemContainerId, Lookup, TraitId, }; use smallvec::SmallVec; @@ -837,17 +837,22 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> { } (_, ImplTraitLoweringMode::Param | ImplTraitLoweringMode::Variable) => { // Find the generic index for the target of our `bound` - let target_param_idx = self - .ctx - .resolver - .where_predicates_in_scope() - .find_map(|(p, (_, types_map))| match p { - WherePredicate::TypeBound { - target: WherePredicateTypeTarget::TypeOrConstParam(idx), - bound: b, - } if b == bound && self.ctx.types_map == types_map => Some(idx), - _ => None, - }); + let target_param_idx = + self.ctx.resolver.where_predicates_in_scope().find_map( + |(p, (_, types_map))| match p { + WherePredicate::TypeBound { + target: WherePredicateTypeTarget::TypeOrConstParam(idx), + bound: b, + } if std::ptr::eq::( + self.ctx.types_map, + types_map, + ) && bound == b => + { + Some(idx) + } + _ => None, + }, + ); let ty = if let Some(target_param_idx) = target_param_idx { let mut counter = 0; let generics = self.ctx.generics().expect("generics in scope"); From 11daea37b69f94f91584059874e26a8015a1398a Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Thu, 20 Feb 2025 01:28:20 +0100 Subject: [PATCH 10/25] Update architecture.md it is stable since 1.52 --- docs/book/src/contributing/architecture.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/book/src/contributing/architecture.md b/docs/book/src/contributing/architecture.md index b9b98bfea3..1cc13b3b96 100644 --- a/docs/book/src/contributing/architecture.md +++ b/docs/book/src/contributing/architecture.md @@ -296,7 +296,7 @@ For this reason, all path APIs generally take some existing path as a "file syst ### `crates/stdx` This crate contains various non-rust-analyzer specific utils, which could have been in std, as well -as copies of unstable std items we would like to make use of already, like `std::str::split_once`. +as copies of unstable std items we would like to make use of already. ### `crates/profile` From 5968782ce653dabc98dbd311a807e68add53166e Mon Sep 17 00:00:00 2001 From: Josh Rotenberg Date: Wed, 19 Feb 2025 16:52:12 -0800 Subject: [PATCH 11/25] missed the L for the line number --- xtask/src/codegen.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 58a3fb6441..8165a2a12b 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs @@ -119,7 +119,7 @@ impl fmt::Display for Location { let name = self.file.file_name().unwrap(); write!( f, - " [{}](https://github.com/rust-lang/rust-analyzer/blob/master/{}#{}) ", + " [{}](https://github.com/rust-lang/rust-analyzer/blob/master/{}#L{}) ", name.to_str().unwrap(), path, self.line From 92e9c76f15fc29994cbaf75c708810ec3fa5e541 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Thu, 20 Feb 2025 03:21:45 +0100 Subject: [PATCH 12/25] Update configuration.md fix dead links --- docs/book/src/configuration.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/book/src/configuration.md b/docs/book/src/configuration.md index 221a571c17..fd94a4221a 100644 --- a/docs/book/src/configuration.md +++ b/docs/book/src/configuration.md @@ -3,13 +3,13 @@ **Source:** [config.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs) -The [Installation](#_installation) section contains details on +The [Installation](./installation.md) section contains details on configuration for some of the editors. In general `rust-analyzer` is configured via LSP messages, which means that it’s up to the editor to decide on the exact format and location of configuration files. -Some clients, such as [VS Code](#vs-code) or [COC plugin in -Vim](#coc-rust-analyzer) provide `rust-analyzer` specific configuration +Some clients, such as [VS Code](./vs_code.md) or [COC plugin in +Vim](./other_editors.md#coc-rust-analyzer) provide `rust-analyzer` specific configuration UIs. Others may require you to know a bit more about the interaction with `rust-analyzer`. From 85e627433bb0a8d7a8562519520185c39cff3edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Thu, 20 Feb 2025 09:34:19 +0200 Subject: [PATCH 13/25] Use ubuntu-latest workers for releases --- .github/workflows/release.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3f1c8b2a9c..fe090267dc 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -34,14 +34,14 @@ jobs: - os: windows-latest target: aarch64-pc-windows-msvc code-target: win32-arm64 - - os: ubuntu-20.04 + - os: ubuntu-latest target: x86_64-unknown-linux-gnu code-target: linux-x64 container: rockylinux:8 - - os: ubuntu-20.04 + - os: ubuntu-latest target: aarch64-unknown-linux-gnu code-target: linux-arm64 - - os: ubuntu-20.04 + - os: ubuntu-latest target: arm-unknown-linux-gnueabihf code-target: linux-armhf - os: macos-13 From 701c2de137d8133e63a33535d00210314ce3cb48 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Thu, 20 Feb 2025 17:05:18 +0100 Subject: [PATCH 14/25] Update editor_features.md fix typos in snippets --- docs/book/src/editor_features.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/book/src/editor_features.md b/docs/book/src/editor_features.md index 73fe9f49a9..5521e395c7 100644 --- a/docs/book/src/editor_features.md +++ b/docs/book/src/editor_features.md @@ -1,6 +1,5 @@ # Editor Features - ## VS Code ### Color configurations @@ -118,7 +117,7 @@ Or it is possible to specify vars more granularly: "rust-analyzer.runnables.extraEnv": [ { // "mask": null, // null mask means that this rule will be applied for all runnables - env: { + "env": { "APP_ID": "1", "APP_DATA": "asdf" } @@ -145,7 +144,7 @@ If needed, you can set different values for different platforms: "rust-analyzer.runnables.extraEnv": [ { "platform": "win32", // windows only - env: { + "env": { "APP_DATA": "windows specific data" } }, From 6b32c8329f56a62aa0dc899a16753173e18d2ca6 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 20 Feb 2025 13:05:06 +0100 Subject: [PATCH 15/25] Improve unset OUT_DIR error message --- crates/hir-expand/src/builtin/fn_macro.rs | 2 +- crates/ide-diagnostics/src/handlers/macro_error.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/hir-expand/src/builtin/fn_macro.rs b/crates/hir-expand/src/builtin/fn_macro.rs index 310ddaaf9e..55242ab3e5 100644 --- a/crates/hir-expand/src/builtin/fn_macro.rs +++ b/crates/hir-expand/src/builtin/fn_macro.rs @@ -833,7 +833,7 @@ fn env_expand( if key.as_str() == "OUT_DIR" { err = Some(ExpandError::other( span, - r#"`OUT_DIR` not set, enable "build scripts" to fix"#, + r#"`OUT_DIR` not set, build scripts may have failed to run"#, )); } diff --git a/crates/ide-diagnostics/src/handlers/macro_error.rs b/crates/ide-diagnostics/src/handlers/macro_error.rs index 99894fefef..2f13298589 100644 --- a/crates/ide-diagnostics/src/handlers/macro_error.rs +++ b/crates/ide-diagnostics/src/handlers/macro_error.rs @@ -133,7 +133,7 @@ macro_rules! env { () => {} } macro_rules! concat { () => {} } include!(concat!(env!("OUT_DIR"), "/out.rs")); - //^^^^^^^^^ error: `OUT_DIR` not set, enable "build scripts" to fix + //^^^^^^^^^ error: `OUT_DIR` not set, build scripts may have failed to run "#, ); } @@ -186,7 +186,7 @@ fn main() { //^^^^^^^ error: expected string literal env!("OUT_DIR"); - //^^^^^^^^^ error: `OUT_DIR` not set, enable "build scripts" to fix + //^^^^^^^^^ error: `OUT_DIR` not set, build scripts may have failed to run compile_error!("compile_error works"); //^^^^^^^^^^^^^ error: compile_error works From 3a333962ee3a496b79ded27d31384b883636f3ff Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Thu, 20 Feb 2025 19:38:24 +0100 Subject: [PATCH 16/25] Update style.md fix dead link --- docs/book/src/contributing/style.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/book/src/contributing/style.md b/docs/book/src/contributing/style.md index 6e5d1869b1..5654e37753 100644 --- a/docs/book/src/contributing/style.md +++ b/docs/book/src/contributing/style.md @@ -276,7 +276,7 @@ fn f() { Assert liberally. Prefer [`stdx::never!`](https://docs.rs/always-assert/0.1.2/always_assert/macro.never.html) to standard `assert!`. -**Rationale:** See [cross cutting concern: error handling](https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/architecture.md#error-handling). +**Rationale:** See [cross cutting concern: error handling](https://github.com/rust-lang/rust-analyzer/blob/master/docs/book/src/contributing/architecture.md#error-handling). ## Getters & Setters From 255ac6797cf9f3c1845f29c8fe6bdfb2b5de0df7 Mon Sep 17 00:00:00 2001 From: Josh Rotenberg Date: Fri, 21 Feb 2025 20:40:19 -0800 Subject: [PATCH 17/25] toc for other editors --- docs/book/src/other_editors.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/book/src/other_editors.md b/docs/book/src/other_editors.md index 0a9a453e01..1eac7dd2c2 100644 --- a/docs/book/src/other_editors.md +++ b/docs/book/src/other_editors.md @@ -6,6 +6,8 @@ Protocol](https://microsoft.github.io/language-server-protocol/). This page assumes that you have already [installed the rust-analyzer binary](./rust_analyzer_binary.html). + + ## Emacs To use `rust-analyzer`, you need to install and enable one of the two From a7547a473b8e841d4db14687a57228194a0dee33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sat, 22 Feb 2025 09:07:52 +0200 Subject: [PATCH 18/25] Switch back to RUST_SRC_PATH --- crates/project-model/src/sysroot.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/project-model/src/sysroot.rs b/crates/project-model/src/sysroot.rs index 544ba43ba6..fb752fe47b 100644 --- a/crates/project-model/src/sysroot.rs +++ b/crates/project-model/src/sysroot.rs @@ -312,8 +312,8 @@ impl Sysroot { RustLibSrcWorkspace::Empty => true, }; if !has_core { - let var_note = if env::var_os("rust_lib_src_PATH").is_some() { - " (env var `rust_lib_src_PATH` is set and may be incorrect, try unsetting it)" + let var_note = if env::var_os("RUST_SRC_PATH").is_some() { + " (env var `RUST_SRC_PATH` is set and may be incorrect, try unsetting it)" } else { ", try running `rustup component add rust-src` to possibly fix this" }; @@ -422,18 +422,16 @@ fn discover_sysroot_dir( } fn discover_rust_lib_src_dir(sysroot_path: &AbsPathBuf) -> Option { - if let Ok(path) = env::var("rust_lib_src_PATH") { + if let Ok(path) = env::var("RUST_SRC_PATH") { if let Ok(path) = AbsPathBuf::try_from(path.as_str()) { let core = path.join("core"); if fs::metadata(&core).is_ok() { - tracing::debug!("Discovered sysroot by rust_lib_src_PATH: {path}"); + tracing::debug!("Discovered sysroot by RUST_SRC_PATH: {path}"); return Some(path); } - tracing::debug!( - "rust_lib_src_PATH is set, but is invalid (no core: {core:?}), ignoring" - ); + tracing::debug!("RUST_SRC_PATH is set, but is invalid (no core: {core:?}), ignoring"); } else { - tracing::debug!("rust_lib_src_PATH is set, but is invalid, ignoring"); + tracing::debug!("RUST_SRC_PATH is set, but is invalid, ignoring"); } } From 7236109f563c9d2afa92b21fa5ed5a1285cef28e Mon Sep 17 00:00:00 2001 From: niller-g Date: Sun, 23 Feb 2025 11:34:44 +0100 Subject: [PATCH 19/25] Fix parser inline tests codegen panics When running `cargo codegen` the cwd="rust-analyzer" however when running `cargo test` the cwd="rust-analyzer/xtask" which makes the codegen panic --- xtask/src/codegen/parser_inline_tests.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/xtask/src/codegen/parser_inline_tests.rs b/xtask/src/codegen/parser_inline_tests.rs index f9f73df8eb..1e614f44e2 100644 --- a/xtask/src/codegen/parser_inline_tests.rs +++ b/xtask/src/codegen/parser_inline_tests.rs @@ -18,23 +18,21 @@ use crate::{ util::list_rust_files, }; -const PARSER_CRATE_ROOT: &str = "crates/parser"; -const PARSER_TEST_DATA: &str = "crates/parser/test_data"; -const PARSER_TEST_DATA_INLINE: &str = "crates/parser/test_data/parser/inline"; - pub(crate) fn generate(check: bool) { - let tests = tests_from_dir( - &project_root().join(Path::new(&format!("{PARSER_CRATE_ROOT}/src/grammar"))), - ); + let parser_crate_root = project_root().join("crates/parser"); + let parser_test_data = parser_crate_root.join("test_data"); + let parser_test_data_inline = parser_test_data.join("parser/inline"); + + let tests = tests_from_dir(&parser_crate_root.join("src/grammar")); let mut some_file_was_updated = false; some_file_was_updated |= - install_tests(&tests.ok, &format!("{PARSER_TEST_DATA_INLINE}/ok"), check).unwrap(); + install_tests(&tests.ok, parser_test_data_inline.join("ok"), check).unwrap(); some_file_was_updated |= - install_tests(&tests.err, &format!("{PARSER_TEST_DATA_INLINE}/err"), check).unwrap(); + install_tests(&tests.err, parser_test_data_inline.join("err"), check).unwrap(); if some_file_was_updated { - let _ = fs::File::open(format!("{PARSER_CRATE_ROOT}/src/tests.rs")) + let _ = fs::File::open(parser_crate_root.join("src/tests.rs")) .unwrap() .set_modified(SystemTime::now()); @@ -95,15 +93,14 @@ pub(crate) fn generate(check: bool) { let pretty = reformat(output.to_string()); ensure_file_contents( crate::flags::CodegenType::ParserTests, - format!("{PARSER_TEST_DATA}/generated/runner.rs").as_ref(), + parser_test_data.join("generated/runner.rs").as_ref(), &pretty, check, ); } } -fn install_tests(tests: &HashMap, into: &str, check: bool) -> Result { - let tests_dir = project_root().join(into); +fn install_tests(tests: &HashMap, tests_dir: PathBuf, check: bool) -> Result { if !tests_dir.is_dir() { fs::create_dir_all(&tests_dir)?; } From 18d6e281b32b228c86ffbf99af6df633ddba6e03 Mon Sep 17 00:00:00 2001 From: niller-g Date: Sun, 23 Feb 2025 11:41:34 +0100 Subject: [PATCH 20/25] Fix codegen of parser inline tests runner When running `cargo codegen` the `crates/parser/test_data/generated/runner.rs` file is only updated when some file in `crates/parser/test_data/inline` changes. However this is not sufficient in all cases --- crates/parser/test_data/generated/runner.rs | 8 +- xtask/src/codegen/parser_inline_tests.rs | 122 ++++++++++---------- 2 files changed, 64 insertions(+), 66 deletions(-) diff --git a/crates/parser/test_data/generated/runner.rs b/crates/parser/test_data/generated/runner.rs index c8ea8c547a..1a74773158 100644 --- a/crates/parser/test_data/generated/runner.rs +++ b/crates/parser/test_data/generated/runner.rs @@ -721,16 +721,16 @@ mod err { #[test] fn bad_asm_expr() { run_and_expect_errors("test_data/parser/inline/err/bad_asm_expr.rs"); } #[test] + fn comma_after_default_values_syntax() { + run_and_expect_errors("test_data/parser/inline/err/comma_after_default_values_syntax.rs"); + } + #[test] fn comma_after_functional_update_syntax() { run_and_expect_errors( "test_data/parser/inline/err/comma_after_functional_update_syntax.rs", ); } #[test] - fn comma_after_default_values_syntax() { - run_and_expect_errors("test_data/parser/inline/err/comma_after_default_values_syntax.rs"); - } - #[test] fn crate_visibility_empty_recover() { run_and_expect_errors("test_data/parser/inline/err/crate_visibility_empty_recover.rs"); } diff --git a/xtask/src/codegen/parser_inline_tests.rs b/xtask/src/codegen/parser_inline_tests.rs index 1e614f44e2..88732cebe7 100644 --- a/xtask/src/codegen/parser_inline_tests.rs +++ b/xtask/src/codegen/parser_inline_tests.rs @@ -35,69 +35,67 @@ pub(crate) fn generate(check: bool) { let _ = fs::File::open(parser_crate_root.join("src/tests.rs")) .unwrap() .set_modified(SystemTime::now()); - - let ok_tests = tests.ok.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| { - let test_name = quote::format_ident!("{}", test.name); - let test_file = format!("test_data/parser/inline/ok/{test_name}.rs"); - let (test_func, args) = match &test.edition { - Some(edition) => { - let edition = quote::format_ident!("Edition{edition}"); - ( - quote::format_ident!("run_and_expect_no_errors_with_edition"), - quote::quote! {#test_file, crate::Edition::#edition}, - ) - } - None => { - (quote::format_ident!("run_and_expect_no_errors"), quote::quote! {#test_file}) - } - }; - quote::quote! { - #[test] - fn #test_name() { - #test_func(#args); - } - } - }); - let err_tests = tests.err.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| { - let test_name = quote::format_ident!("{}", test.name); - let test_file = format!("test_data/parser/inline/err/{test_name}.rs"); - let (test_func, args) = match &test.edition { - Some(edition) => { - let edition = quote::format_ident!("Edition{edition}"); - ( - quote::format_ident!("run_and_expect_errors_with_edition"), - quote::quote! {#test_file, crate::Edition::#edition}, - ) - } - None => (quote::format_ident!("run_and_expect_errors"), quote::quote! {#test_file}), - }; - quote::quote! { - #[test] - fn #test_name() { - #test_func(#args); - } - } - }); - - let output = quote::quote! { - mod ok { - use crate::tests::*; - #(#ok_tests)* - } - mod err { - use crate::tests::*; - #(#err_tests)* - } - }; - - let pretty = reformat(output.to_string()); - ensure_file_contents( - crate::flags::CodegenType::ParserTests, - parser_test_data.join("generated/runner.rs").as_ref(), - &pretty, - check, - ); } + + let ok_tests = tests.ok.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| { + let test_name = quote::format_ident!("{}", test.name); + let test_file = format!("test_data/parser/inline/ok/{test_name}.rs"); + let (test_func, args) = match &test.edition { + Some(edition) => { + let edition = quote::format_ident!("Edition{edition}"); + ( + quote::format_ident!("run_and_expect_no_errors_with_edition"), + quote::quote! {#test_file, crate::Edition::#edition}, + ) + } + None => (quote::format_ident!("run_and_expect_no_errors"), quote::quote! {#test_file}), + }; + quote::quote! { + #[test] + fn #test_name() { + #test_func(#args); + } + } + }); + let err_tests = tests.err.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| { + let test_name = quote::format_ident!("{}", test.name); + let test_file = format!("test_data/parser/inline/err/{test_name}.rs"); + let (test_func, args) = match &test.edition { + Some(edition) => { + let edition = quote::format_ident!("Edition{edition}"); + ( + quote::format_ident!("run_and_expect_errors_with_edition"), + quote::quote! {#test_file, crate::Edition::#edition}, + ) + } + None => (quote::format_ident!("run_and_expect_errors"), quote::quote! {#test_file}), + }; + quote::quote! { + #[test] + fn #test_name() { + #test_func(#args); + } + } + }); + + let output = quote::quote! { + mod ok { + use crate::tests::*; + #(#ok_tests)* + } + mod err { + use crate::tests::*; + #(#err_tests)* + } + }; + + let pretty = reformat(output.to_string()); + ensure_file_contents( + crate::flags::CodegenType::ParserTests, + parser_test_data.join("generated/runner.rs").as_ref(), + &pretty, + check, + ); } fn install_tests(tests: &HashMap, tests_dir: PathBuf, check: bool) -> Result { From 0b2e8166a108715d425359aec60214b1764d6aa8 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 20 Feb 2025 18:58:42 +0100 Subject: [PATCH 21/25] Remove `limit` crate in favor `usize` --- Cargo.lock | 9 --- Cargo.toml | 1 - crates/hir-def/Cargo.toml | 1 - crates/hir-def/src/expander.rs | 9 ++- crates/hir-def/src/nameres/collector.rs | 13 ++-- crates/hir-def/src/nameres/mod_resolution.rs | 5 +- crates/hir-expand/Cargo.toml | 1 - crates/hir-expand/src/db.rs | 12 ++-- crates/hir-ty/Cargo.toml | 1 - crates/hir-ty/src/autoderef.rs | 5 +- crates/ide-db/Cargo.toml | 1 - crates/ide-db/src/imports/import_assets.rs | 4 +- crates/ide-db/src/items_locator.rs | 3 +- crates/limit/Cargo.toml | 16 ----- crates/limit/src/lib.rs | 67 -------------------- crates/parser/Cargo.toml | 1 - crates/parser/src/parser.rs | 5 +- 17 files changed, 23 insertions(+), 131 deletions(-) delete mode 100644 crates/limit/Cargo.toml delete mode 100644 crates/limit/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 6d7f6042de..fc3680ce27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -559,7 +559,6 @@ dependencies = [ "intern", "itertools", "la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "limit", "mbe", "ra-ap-rustc_abi", "ra-ap-rustc_parse_format", @@ -591,7 +590,6 @@ dependencies = [ "intern", "itertools", "la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "limit", "mbe", "parser", "rustc-hash 2.0.0", @@ -626,7 +624,6 @@ dependencies = [ "intern", "itertools", "la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "limit", "nohash-hasher", "oorandom", "project-model", @@ -744,7 +741,6 @@ dependencies = [ "hir", "indexmap", "itertools", - "limit", "line-index 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "memchr", "nohash-hasher", @@ -943,10 +939,6 @@ dependencies = [ "redox_syscall", ] -[[package]] -name = "limit" -version = "0.0.0" - [[package]] name = "line-index" version = "0.1.2" @@ -1279,7 +1271,6 @@ dependencies = [ "drop_bomb", "edition", "expect-test", - "limit", "ra-ap-rustc_lexer", "stdx", "tracing", diff --git a/Cargo.toml b/Cargo.toml index 924ffb8dd2..5060013b13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,7 +64,6 @@ ide-db = { path = "./crates/ide-db", version = "0.0.0" } ide-diagnostics = { path = "./crates/ide-diagnostics", version = "0.0.0" } ide-ssr = { path = "./crates/ide-ssr", version = "0.0.0" } intern = { path = "./crates/intern", version = "0.0.0" } -limit = { path = "./crates/limit", version = "0.0.0" } load-cargo = { path = "./crates/load-cargo", version = "0.0.0" } mbe = { path = "./crates/mbe", version = "0.0.0" } parser = { path = "./crates/parser", version = "0.0.0" } diff --git a/crates/hir-def/Cargo.toml b/crates/hir-def/Cargo.toml index 375f18d9fe..74fe49b767 100644 --- a/crates/hir-def/Cargo.toml +++ b/crates/hir-def/Cargo.toml @@ -43,7 +43,6 @@ hir-expand.workspace = true mbe.workspace = true cfg.workspace = true tt.workspace = true -limit.workspace = true span.workspace = true diff --git a/crates/hir-def/src/expander.rs b/crates/hir-def/src/expander.rs index 108258d5a1..a1b3123c99 100644 --- a/crates/hir-def/src/expander.rs +++ b/crates/hir-def/src/expander.rs @@ -9,7 +9,6 @@ use hir_expand::{ attrs::RawAttrs, mod_path::ModPath, span_map::SpanMap, ExpandError, ExpandErrorKind, ExpandResult, HirFileId, InFile, Lookup, MacroCallId, }; -use limit::Limit; use span::{Edition, SyntaxContextId}; use syntax::{ast, Parse}; use triomphe::Arc; @@ -28,18 +27,18 @@ pub struct Expander { pub(crate) module: ModuleId, /// `recursion_depth == usize::MAX` indicates that the recursion limit has been reached. recursion_depth: u32, - recursion_limit: Limit, + recursion_limit: usize, } impl Expander { pub fn new(db: &dyn DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander { let recursion_limit = module.def_map(db).recursion_limit() as usize; - let recursion_limit = Limit::new(if cfg!(test) { + let recursion_limit = if cfg!(test) { // Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug std::cmp::min(32, recursion_limit) } else { recursion_limit - }); + }; Expander { current_file_id, module, @@ -194,7 +193,7 @@ impl Expander { let Some(call_id) = value else { return ExpandResult { value: None, err }; }; - if self.recursion_limit.check(self.recursion_depth as usize + 1).is_err() { + if self.recursion_depth as usize > self.recursion_limit { self.recursion_depth = u32::MAX; cov_mark::hit!(your_stack_belongs_to_me); return ExpandResult::only_err(ExpandError::new( diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 254c137991..16f3fd56eb 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -19,7 +19,6 @@ use hir_expand::{ use intern::{sym, Interned}; use itertools::{izip, Itertools}; use la_arena::Idx; -use limit::Limit; use rustc_hash::{FxHashMap, FxHashSet}; use span::{Edition, EditionedFileId, FileAstId, SyntaxContextId}; use syntax::ast; @@ -55,8 +54,8 @@ use crate::{ UnresolvedMacro, UseId, UseLoc, }; -static GLOB_RECURSION_LIMIT: Limit = Limit::new(100); -static FIXED_POINT_LIMIT: Limit = Limit::new(8192); +const GLOB_RECURSION_LIMIT: usize = 100; +const FIXED_POINT_LIMIT: usize = 8192; pub(super) fn collect_defs(db: &dyn DefDatabase, def_map: DefMap, tree_id: TreeId) -> DefMap { let crate_graph = db.crate_graph(); @@ -393,7 +392,7 @@ impl DefCollector<'_> { } i += 1; - if FIXED_POINT_LIMIT.check(i).is_err() { + if i > FIXED_POINT_LIMIT { tracing::error!("name resolution is stuck"); break 'resolve_attr; } @@ -993,7 +992,7 @@ impl DefCollector<'_> { import: Option, depth: usize, ) { - if GLOB_RECURSION_LIMIT.check(depth).is_err() { + if depth > GLOB_RECURSION_LIMIT { // prevent stack overflows (but this shouldn't be possible) panic!("infinite recursion in glob imports!"); } @@ -1470,8 +1469,7 @@ impl DefCollector<'_> { depth: usize, container: ItemContainerId, ) { - let recursion_limit = Limit::new(self.def_map.recursion_limit() as usize); - if recursion_limit.check(depth).is_err() { + if depth > self.def_map.recursion_limit() as usize { cov_mark::hit!(macro_expansion_overflow); tracing::warn!("macro expansion is too deep"); return; @@ -1499,7 +1497,6 @@ impl DefCollector<'_> { fn finish(mut self) -> DefMap { // Emit diagnostics for all remaining unexpanded macros. - let _p = tracing::info_span!("DefCollector::finish").entered(); for directive in &self.unresolved_macros { diff --git a/crates/hir-def/src/nameres/mod_resolution.rs b/crates/hir-def/src/nameres/mod_resolution.rs index d7e4ca41cd..afee42ecec 100644 --- a/crates/hir-def/src/nameres/mod_resolution.rs +++ b/crates/hir-def/src/nameres/mod_resolution.rs @@ -2,12 +2,11 @@ use arrayvec::ArrayVec; use base_db::AnchoredPath; use hir_expand::{name::Name, HirFileIdExt}; -use limit::Limit; use span::EditionedFileId; use crate::{db::DefDatabase, HirFileId}; -static MOD_DEPTH_LIMIT: Limit = Limit::new(32); +const MOD_DEPTH_LIMIT: usize = 32; #[derive(Clone, Debug)] pub(super) struct ModDir { @@ -50,7 +49,7 @@ impl ModDir { fn child(&self, dir_path: DirPath, root_non_dir_owner: bool) -> Option { let depth = self.depth + 1; - if MOD_DEPTH_LIMIT.check(depth as usize).is_err() { + if depth as usize > MOD_DEPTH_LIMIT { tracing::error!("MOD_DEPTH_LIMIT exceeded"); cov_mark::hit!(circular_mods); return None; diff --git a/crates/hir-expand/Cargo.toml b/crates/hir-expand/Cargo.toml index 03a9d54d2e..b193a34a01 100644 --- a/crates/hir-expand/Cargo.toml +++ b/crates/hir-expand/Cargo.toml @@ -31,7 +31,6 @@ cfg.workspace = true syntax.workspace = true tt.workspace = true mbe.workspace = true -limit.workspace = true span.workspace = true parser.workspace = true syntax-bridge.workspace = true diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs index b7804f888a..8ca8bf1ba4 100644 --- a/crates/hir-expand/src/db.rs +++ b/crates/hir-expand/src/db.rs @@ -2,7 +2,6 @@ use base_db::{ra_salsa, CrateId, SourceDatabase}; use either::Either; -use limit::Limit; use mbe::MatchedArmIndex; use rustc_hash::FxHashSet; use span::{AstIdMap, Edition, EditionedFileId, Span, SyntaxContextData, SyntaxContextId}; @@ -35,7 +34,7 @@ type MacroArgResult = (Arc, SyntaxFixupUndoInfo, Span); /// an error will be emitted. /// /// Actual max for `analysis-stats .` at some point: 30672. -static TOKEN_LIMIT: Limit = Limit::new(2_097_152); +const TOKEN_LIMIT: usize = 2_097_152; #[derive(Debug, Clone, Eq, PartialEq)] pub enum TokenExpander { @@ -740,20 +739,19 @@ pub(crate) fn token_tree_to_syntax_node( fn check_tt_count(tt: &tt::TopSubtree) -> Result<(), ExpandResult<()>> { let tt = tt.top_subtree(); let count = tt.count(); - if TOKEN_LIMIT.check(count).is_err() { + if count <= TOKEN_LIMIT { + Ok(()) + } else { Err(ExpandResult { value: (), err: Some(ExpandError::other( tt.delimiter.open, format!( "macro invocation exceeds token limit: produced {} tokens, limit is {}", - count, - TOKEN_LIMIT.inner(), + count, TOKEN_LIMIT, ), )), }) - } else { - Ok(()) } } diff --git a/crates/hir-ty/Cargo.toml b/crates/hir-ty/Cargo.toml index 989f0955e1..eaa258a6b5 100644 --- a/crates/hir-ty/Cargo.toml +++ b/crates/hir-ty/Cargo.toml @@ -47,7 +47,6 @@ hir-def.workspace = true hir-expand.workspace = true base-db.workspace = true syntax.workspace = true -limit.workspace = true span.workspace = true [dev-dependencies] diff --git a/crates/hir-ty/src/autoderef.rs b/crates/hir-ty/src/autoderef.rs index e0e366f450..171ba001c4 100644 --- a/crates/hir-ty/src/autoderef.rs +++ b/crates/hir-ty/src/autoderef.rs @@ -9,7 +9,6 @@ use chalk_ir::cast::Cast; use hir_def::lang_item::LangItem; use hir_expand::name::Name; use intern::sym; -use limit::Limit; use triomphe::Arc; use crate::{ @@ -17,7 +16,7 @@ use crate::{ TraitEnvironment, Ty, TyBuilder, TyKind, }; -static AUTODEREF_RECURSION_LIMIT: Limit = Limit::new(20); +const AUTODEREF_RECURSION_LIMIT: usize = 20; #[derive(Debug)] pub(crate) enum AutoderefKind { @@ -140,7 +139,7 @@ impl Iterator for Autoderef<'_, '_, T> { return Some((self.ty.clone(), 0)); } - if AUTODEREF_RECURSION_LIMIT.check(self.steps.len() + 1).is_err() { + if self.steps.len() > AUTODEREF_RECURSION_LIMIT { return None; } diff --git a/crates/ide-db/Cargo.toml b/crates/ide-db/Cargo.toml index 17f0e69bde..c8a8a2d169 100644 --- a/crates/ide-db/Cargo.toml +++ b/crates/ide-db/Cargo.toml @@ -30,7 +30,6 @@ bitflags.workspace = true # local deps base-db.workspace = true -limit.workspace = true parser.workspace = true profile.workspace = true stdx.workspace = true diff --git a/crates/ide-db/src/imports/import_assets.rs b/crates/ide-db/src/imports/import_assets.rs index ad86d855b5..77fc59b4ec 100644 --- a/crates/ide-db/src/imports/import_assets.rs +++ b/crates/ide-db/src/imports/import_assets.rs @@ -357,7 +357,7 @@ fn path_applicable_imports( let mod_path = mod_path(item)?; Some(LocatedImport::new(mod_path, item, item)) }) - .take(DEFAULT_QUERY_SEARCH_LIMIT.inner()) + .take(DEFAULT_QUERY_SEARCH_LIMIT) .collect() } // we have some unresolved qualifier that we search an import for @@ -383,7 +383,7 @@ fn path_applicable_imports( qualifier_rest, ) }) - .take(DEFAULT_QUERY_SEARCH_LIMIT.inner()) + .take(DEFAULT_QUERY_SEARCH_LIMIT) .collect(), } } diff --git a/crates/ide-db/src/items_locator.rs b/crates/ide-db/src/items_locator.rs index a2062f36d3..4d9c051354 100644 --- a/crates/ide-db/src/items_locator.rs +++ b/crates/ide-db/src/items_locator.rs @@ -6,7 +6,6 @@ use std::ops::ControlFlow; use either::Either; use hir::{import_map, Crate, ItemInNs, Module, Semantics}; -use limit::Limit; use crate::{ imports::import_assets::NameToImport, @@ -15,7 +14,7 @@ use crate::{ }; /// A value to use, when uncertain which limit to pick. -pub static DEFAULT_QUERY_SEARCH_LIMIT: Limit = Limit::new(100); +pub const DEFAULT_QUERY_SEARCH_LIMIT: usize = 100; pub use import_map::AssocSearchMode; diff --git a/crates/limit/Cargo.toml b/crates/limit/Cargo.toml deleted file mode 100644 index 30666f5219..0000000000 --- a/crates/limit/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "limit" -version = "0.0.0" -repository.workspace = true -description = "A struct to enforce limits for rust-analyzer." - -authors.workspace = true -edition.workspace = true -license.workspace = true -rust-version.workspace = true - -[features] -tracking = [] - -[lints] -workspace = true diff --git a/crates/limit/src/lib.rs b/crates/limit/src/lib.rs deleted file mode 100644 index c1caeed2f8..0000000000 --- a/crates/limit/src/lib.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! limit defines a struct to enforce limits. - -#[cfg(feature = "tracking")] -use std::sync::atomic::AtomicUsize; - -/// Represents a struct used to enforce a numerical limit. -#[derive(Debug)] -pub struct Limit { - upper_bound: usize, - #[cfg(feature = "tracking")] - max: AtomicUsize, -} - -impl Limit { - /// Creates a new limit. - #[inline] - pub const fn new(upper_bound: usize) -> Self { - Self { - upper_bound, - #[cfg(feature = "tracking")] - max: AtomicUsize::new(0), - } - } - - /// Creates a new limit. - #[inline] - #[cfg(feature = "tracking")] - pub const fn new_tracking(upper_bound: usize) -> Self { - Self { - upper_bound, - #[cfg(feature = "tracking")] - max: AtomicUsize::new(1), - } - } - - /// Gets the underlying numeric limit. - #[inline] - pub const fn inner(&self) -> usize { - self.upper_bound - } - - /// Checks whether the given value is below the limit. - /// Returns `Ok` when `other` is below `self`, and `Err` otherwise. - #[inline] - pub fn check(&self, other: usize) -> Result<(), ()> { - if other > self.upper_bound { - Err(()) - } else { - #[cfg(feature = "tracking")] - loop { - use std::sync::atomic::Ordering; - let old_max = self.max.load(Ordering::Relaxed); - if other <= old_max || old_max == 0 { - break; - } - _ = self.max.compare_exchange_weak( - old_max, - other, - Ordering::Relaxed, - Ordering::Relaxed, - ); - } - - Ok(()) - } - } -} diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 3629d275c0..48436ec71f 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -15,7 +15,6 @@ doctest = false [dependencies] drop_bomb = "0.1.5" ra-ap-rustc_lexer.workspace = true -limit.workspace = true tracing = { workspace = true, optional = true } edition.workspace = true diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs index 2f6ba52574..b058686276 100644 --- a/crates/parser/src/parser.rs +++ b/crates/parser/src/parser.rs @@ -3,7 +3,6 @@ use std::cell::Cell; use drop_bomb::DropBomb; -use limit::Limit; use crate::{ event::Event, @@ -30,7 +29,7 @@ pub(crate) struct Parser<'t> { edition: Edition, } -static PARSER_STEP_LIMIT: Limit = Limit::new(15_000_000); +const PARSER_STEP_LIMIT: usize = 15_000_000; impl<'t> Parser<'t> { pub(super) fn new(inp: &'t Input, edition: Edition) -> Parser<'t> { @@ -54,7 +53,7 @@ impl<'t> Parser<'t> { assert!(n <= 3); let steps = self.steps.get(); - assert!(PARSER_STEP_LIMIT.check(steps as usize).is_ok(), "the parser seems stuck"); + assert!((steps as usize) < PARSER_STEP_LIMIT, "the parser seems stuck"); self.steps.set(steps + 1); self.inp.kind(self.pos + n) From 6f2bd412e3e3079639e977255ac4674700c89d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 24 Feb 2025 09:42:28 +0200 Subject: [PATCH 22/25] Preparing for merge from rust-lang/rust --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 4006d06e4f..6cd39fabee 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -273465e1f2932a30a5b56ac95859cdc86f3f33fa +e0be1a02626abef2878cb7f4aaef7ae409477112 From a5bf2d5604b246c4f0265d77efb94cfc47c0e0aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 24 Feb 2025 10:10:51 +0200 Subject: [PATCH 23/25] Add rustc_hashes and bump the others --- Cargo.lock | 44 +++++++++++++++++++++++++++------------ Cargo.toml | 11 +++++----- crates/hir-def/Cargo.toml | 1 + crates/hir-ty/Cargo.toml | 1 + 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc3680ce27..01e6a39f7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -561,6 +561,7 @@ dependencies = [ "la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "mbe", "ra-ap-rustc_abi", + "ra-ap-rustc_hashes", "ra-ap-rustc_parse_format", "rustc-hash 2.0.0", "rustc_apfloat", @@ -628,6 +629,7 @@ dependencies = [ "oorandom", "project-model", "ra-ap-rustc_abi", + "ra-ap-rustc_hashes", "ra-ap-rustc_index", "ra-ap-rustc_pattern_analysis", "rustc-hash 2.0.0", @@ -1505,20 +1507,30 @@ dependencies = [ [[package]] name = "ra-ap-rustc_abi" -version = "0.95.0" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b40c4e339b71a8f075a829b1acaf32f870a11b466d9b8623d50b0ce33e65af95" +checksum = "3829c3355d1681ffeaf1450ec71edcdace6820fe2e86469d8fc1ad45e2c96460" dependencies = [ "bitflags 2.7.0", + "ra-ap-rustc_hashes", "ra-ap-rustc_index", "tracing", ] [[package]] -name = "ra-ap-rustc_index" -version = "0.95.0" +name = "ra-ap-rustc_hashes" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "872072e2ba11d11147ebe9fde1608fe7f7d9b5c51dac524af28ee07c6dade468" +checksum = "1bd4d6d4c434bec08e02370a4f64a4985312097215a62e82d0f757f3a98e502e" +dependencies = [ + "rustc-stable-hash", +] + +[[package]] +name = "ra-ap-rustc_index" +version = "0.97.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bad6fc4bd7522e31096e2de5b0351144fe0684b608791ee26c842bf2da1b19ae" dependencies = [ "ra-ap-rustc_index_macros", "smallvec", @@ -1526,9 +1538,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_index_macros" -version = "0.95.0" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffcd77debcaf2ad690a57c2d041c11eb33fe66869754b2c5f35c52954b46af0c" +checksum = "cfb234e1f84b92be45276c3025bee18789e9bc95bec8789bec961e78edb01c52" dependencies = [ "proc-macro2", "quote", @@ -1537,9 +1549,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_lexer" -version = "0.95.0" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49265cdf8823f8d246e476c79c60bd6e5b551c81ae76e1c8d6a5e0dc73df0bca" +checksum = "7a3a40bd11dc43d1cb110e730b80620cf8102f4cca8920a02b65954da0ed931f" dependencies = [ "memchr", "unicode-properties", @@ -1548,9 +1560,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_parse_format" -version = "0.95.0" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3da239fdc971176de0db45cb631d71475b52033a3d0027d91964da7be89eee6" +checksum = "5feb877478994cb4c0c0c7a5116a352eefc0634aefc8636feb00a893fa5b7135" dependencies = [ "ra-ap-rustc_index", "ra-ap-rustc_lexer", @@ -1558,9 +1570,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_pattern_analysis" -version = "0.95.0" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56057d08fdfa0d95494e461bbdd5d4b3fdb349cca6be05ad7759bc964be1b8d4" +checksum = "a76774d35934d464c4115908cde16f76a4f7e540fe1eea6b79336c556e37bdd3" dependencies = [ "ra-ap-rustc_index", "rustc-hash 2.0.0", @@ -1735,6 +1747,12 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +[[package]] +name = "rustc-stable-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2febf9acc5ee5e99d1ad0afcdbccc02d87aa3f857a1f01f825b80eacf8edfcd1" + [[package]] name = "rustc_apfloat" version = "0.2.1+llvm-462a31f5a5ab" diff --git a/Cargo.toml b/Cargo.toml index 5060013b13..1ff36a68e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,11 +86,12 @@ vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" } vfs = { path = "./crates/vfs", version = "0.0.0" } edition = { path = "./crates/edition", version = "0.0.0" } -ra-ap-rustc_lexer = { version = "0.95", default-features = false } -ra-ap-rustc_parse_format = { version = "0.95", default-features = false } -ra-ap-rustc_index = { version = "0.95", default-features = false } -ra-ap-rustc_abi = { version = "0.95", default-features = false } -ra-ap-rustc_pattern_analysis = { version = "0.95", default-features = false } +ra-ap-rustc_hashes = { version = "0.97", default-features = false } +ra-ap-rustc_lexer = { version = "0.97", default-features = false } +ra-ap-rustc_parse_format = { version = "0.97", default-features = false } +ra-ap-rustc_index = { version = "0.97", default-features = false } +ra-ap-rustc_abi = { version = "0.97", default-features = false } +ra-ap-rustc_pattern_analysis = { version = "0.97", default-features = false } # local crates that aren't published to crates.io. These should not have versions. diff --git a/crates/hir-def/Cargo.toml b/crates/hir-def/Cargo.toml index 74fe49b767..9a448ec14e 100644 --- a/crates/hir-def/Cargo.toml +++ b/crates/hir-def/Cargo.toml @@ -31,6 +31,7 @@ triomphe.workspace = true rustc_apfloat = "0.2.0" text-size.workspace = true +ra-ap-rustc_hashes.workspace = true ra-ap-rustc_parse_format.workspace = true ra-ap-rustc_abi.workspace = true diff --git a/crates/hir-ty/Cargo.toml b/crates/hir-ty/Cargo.toml index eaa258a6b5..4d36de0b38 100644 --- a/crates/hir-ty/Cargo.toml +++ b/crates/hir-ty/Cargo.toml @@ -36,6 +36,7 @@ indexmap.workspace = true rustc_apfloat = "0.2.0" ra-ap-rustc_abi.workspace = true +ra-ap-rustc_hashes.workspace = true ra-ap-rustc_index.workspace = true ra-ap-rustc_pattern_analysis.workspace = true From f641813e07d72ce5643114cb4957c22d29a5d606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 24 Feb 2025 10:28:46 +0200 Subject: [PATCH 24/25] Format code --- crates/hir-def/src/data/adt.rs | 8 +++++++- crates/hir-ty/src/layout.rs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/hir-def/src/data/adt.rs b/crates/hir-def/src/data/adt.rs index 5d1834a864..c94622016d 100644 --- a/crates/hir-def/src/data/adt.rs +++ b/crates/hir-def/src/data/adt.rs @@ -173,7 +173,13 @@ fn parse_repr_tt(tt: &TopSubtree) -> Option { } } - Some(ReprOptions { int, align: max_align, pack: min_pack, flags, field_shuffle_seed: Hash64::ZERO }) + Some(ReprOptions { + int, + align: max_align, + pack: min_pack, + flags, + field_shuffle_seed: Hash64::ZERO, + }) } impl StructData { diff --git a/crates/hir-ty/src/layout.rs b/crates/hir-ty/src/layout.rs index a72bcad50a..e2ab336d2e 100644 --- a/crates/hir-ty/src/layout.rs +++ b/crates/hir-ty/src/layout.rs @@ -14,8 +14,8 @@ use hir_def::{ }; use la_arena::{Idx, RawIdx}; use rustc_abi::AddressSpace; -use rustc_index::{IndexSlice, IndexVec}; use rustc_hashes::Hash64; +use rustc_index::{IndexSlice, IndexVec}; use triomphe::Arc; From c96554a622154458a56eb0883fb5a736d37ba897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 24 Feb 2025 10:28:52 +0200 Subject: [PATCH 25/25] Update assist docs --- docs/book/src/assists_generated.md | 324 ++++++++++++++++------------- 1 file changed, 175 insertions(+), 149 deletions(-) diff --git a/docs/book/src/assists_generated.md b/docs/book/src/assists_generated.md index 761a7f859b..9d68a873ff 100644 --- a/docs/book/src/assists_generated.md +++ b/docs/book/src/assists_generated.md @@ -1,7 +1,7 @@ //! Generated by `cargo xtask codegen assists-doc-tests`, do not edit by hand. ### `add_braces` -**Source:** [add_braces.rs](/crates/ide-assists/src/handlers/add_braces.rs#8) +**Source:** [add_braces.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/add_braces.rs#L8) Adds braces to lambda and match arm expressions. @@ -29,7 +29,7 @@ fn foo(n: i32) -> i32 { ### `add_explicit_type` -**Source:** [add_explicit_type.rs](/crates/ide-assists/src/handlers/add_explicit_type.rs#7) +**Source:** [add_explicit_type.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/add_explicit_type.rs#L7) Specify type for a let binding. @@ -49,7 +49,7 @@ fn main() { ### `add_hash` -**Source:** [raw_string.rs](/crates/ide-assists/src/handlers/raw_string.rs#89) +**Source:** [raw_string.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/raw_string.rs#L89) Adds a hash to a raw string literal. @@ -69,7 +69,7 @@ fn main() { ### `add_impl_default_members` -**Source:** [add_missing_impl_members.rs](/crates/ide-assists/src/handlers/add_missing_impl_members.rs#58) +**Source:** [add_missing_impl_members.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/add_missing_impl_members.rs#L58) Adds scaffold for overriding default impl members. @@ -105,7 +105,7 @@ impl Trait for () { ### `add_impl_missing_members` -**Source:** [add_missing_impl_members.rs](/crates/ide-assists/src/handlers/add_missing_impl_members.rs#16) +**Source:** [add_missing_impl_members.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/add_missing_impl_members.rs#L16) Adds scaffold for required impl members. @@ -141,7 +141,7 @@ impl Trait for () { ### `add_label_to_loop` -**Source:** [add_label_to_loop.rs](/crates/ide-assists/src/handlers/add_label_to_loop.rs#9) +**Source:** [add_label_to_loop.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/add_label_to_loop.rs#L9) Adds a label to a loop. @@ -167,7 +167,7 @@ fn main() { ### `add_lifetime_to_type` -**Source:** [add_lifetime_to_type.rs](/crates/ide-assists/src/handlers/add_lifetime_to_type.rs#5) +**Source:** [add_lifetime_to_type.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/add_lifetime_to_type.rs#L5) Adds a new lifetime to a struct, enum or union. @@ -189,7 +189,7 @@ struct Point<'a> { ### `add_missing_match_arms` -**Source:** [add_missing_match_arms.rs](/crates/ide-assists/src/handlers/add_missing_match_arms.rs#14) +**Source:** [add_missing_match_arms.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/add_missing_match_arms.rs#L16) Adds missing clauses to a `match` expression. @@ -218,7 +218,7 @@ fn handle(action: Action) { ### `add_return_type` -**Source:** [add_return_type.rs](/crates/ide-assists/src/handlers/add_return_type.rs#6) +**Source:** [add_return_type.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/add_return_type.rs#L6) Adds the return type to a function or closure inferred from its tail expression if it doesn't have a return type specified. This assists is useable in a functions or closures tail expression or return type position. @@ -235,7 +235,7 @@ fn foo() -> i32 { 42i32 } ### `add_turbo_fish` -**Source:** [add_turbo_fish.rs](/crates/ide-assists/src/handlers/add_turbo_fish.rs#14) +**Source:** [add_turbo_fish.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/add_turbo_fish.rs#L14) Adds `::<_>` to a call of a generic method or function. @@ -257,7 +257,7 @@ fn main() { ### `apply_demorgan` -**Source:** [apply_demorgan.rs](/crates/ide-assists/src/handlers/apply_demorgan.rs#16) +**Source:** [apply_demorgan.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/apply_demorgan.rs#L16) Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). This transforms expressions of the form `!l || !r` into `!(l && r)`. @@ -280,7 +280,7 @@ fn main() { ### `apply_demorgan_iterator` -**Source:** [apply_demorgan.rs](/crates/ide-assists/src/handlers/apply_demorgan.rs#132) +**Source:** [apply_demorgan.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/apply_demorgan.rs#L132) Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) to `Iterator::all` and `Iterator::any`. @@ -311,7 +311,7 @@ fn main() { ### `auto_import` -**Source:** [auto_import.rs](/crates/ide-assists/src/handlers/auto_import.rs#73) +**Source:** [auto_import.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/auto_import.rs#L73) If the name is unresolved, provides all possible imports for it. @@ -333,7 +333,7 @@ fn main() { ### `bind_unused_param` -**Source:** [bind_unused_param.rs](/crates/ide-assists/src/handlers/bind_unused_param.rs#12) +**Source:** [bind_unused_param.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/bind_unused_param.rs#L12) Binds unused function parameter to an underscore. @@ -351,7 +351,7 @@ fn some_function(x: i32) { ### `bool_to_enum` -**Source:** [bool_to_enum.rs](/crates/ide-assists/src/handlers/bool_to_enum.rs#29) +**Source:** [bool_to_enum.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/bool_to_enum.rs#L29) This converts boolean local variables, fields, constants, and statics into a new enum with two variants `Bool::True` and `Bool::False`, as well as replacing @@ -385,7 +385,7 @@ fn main() { ### `change_visibility` -**Source:** [change_visibility.rs](/crates/ide-assists/src/handlers/change_visibility.rs#13) +**Source:** [change_visibility.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/change_visibility.rs#L13) Adds or changes existing visibility specifier. @@ -401,7 +401,7 @@ pub(crate) fn frobnicate() {} ### `comment_to_doc` -**Source:** [convert_comment_from_or_to_doc.rs](/crates/ide-assists/src/handlers/convert_comment_from_or_to_doc.rs#9) +**Source:** [convert_comment_from_or_to_doc.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_comment_from_or_to_doc.rs#L9) Converts comments to documentation. @@ -419,7 +419,7 @@ Converts comments to documentation. ### `convert_bool_then_to_if` -**Source:** [convert_bool_then.rs](/crates/ide-assists/src/handlers/convert_bool_then.rs#131) +**Source:** [convert_bool_then.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_bool_then.rs#L131) Converts a `bool::then` method call to an equivalent if expression. @@ -443,7 +443,7 @@ fn main() { ### `convert_closure_to_fn` -**Source:** [convert_closure_to_fn.rs](/crates/ide-assists/src/handlers/convert_closure_to_fn.rs#25) +**Source:** [convert_closure_to_fn.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_closure_to_fn.rs#L25) This converts a closure to a freestanding function, changing all captures to parameters. @@ -469,7 +469,7 @@ fn main() { ### `convert_for_loop_with_for_each` -**Source:** [convert_iter_for_each_to_for.rs](/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs#76) +**Source:** [convert_iter_for_each_to_for.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs#L76) Converts a for loop into a for_each loop on the Iterator. @@ -495,7 +495,7 @@ fn main() { ### `convert_from_to_tryfrom` -**Source:** [convert_from_to_tryfrom.rs](/crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs#10) +**Source:** [convert_from_to_tryfrom.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_from_to_tryfrom.rs#L10) Converts a From impl to a TryFrom impl, wrapping returns in `Ok`. @@ -527,7 +527,7 @@ impl TryFrom for Thing { ### `convert_if_to_bool_then` -**Source:** [convert_bool_then.rs](/crates/ide-assists/src/handlers/convert_bool_then.rs#20) +**Source:** [convert_bool_then.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_bool_then.rs#L20) Converts an if expression into a corresponding `bool::then` call. @@ -551,7 +551,7 @@ fn main() { ### `convert_integer_literal` -**Source:** [convert_integer_literal.rs](/crates/ide-assists/src/handlers/convert_integer_literal.rs#5) +**Source:** [convert_integer_literal.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_integer_literal.rs#L5) Converts the base of integer literals to other bases. @@ -567,7 +567,7 @@ const _: i32 = 0b1010; ### `convert_into_to_from` -**Source:** [convert_into_to_from.rs](/crates/ide-assists/src/handlers/convert_into_to_from.rs#8) +**Source:** [convert_into_to_from.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_into_to_from.rs#L8) Converts an Into impl to an equivalent From impl. @@ -597,7 +597,7 @@ impl From for Thing { ### `convert_iter_for_each_to_for` -**Source:** [convert_iter_for_each_to_for.rs](/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs#11) +**Source:** [convert_iter_for_each_to_for.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_iter_for_each_to_for.rs#L11) Converts an Iterator::for_each function into a for loop. @@ -623,7 +623,7 @@ fn main() { ### `convert_let_else_to_match` -**Source:** [convert_let_else_to_match.rs](/crates/ide-assists/src/handlers/convert_let_else_to_match.rs#9) +**Source:** [convert_let_else_to_match.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_let_else_to_match.rs#L9) Converts let-else statement to let statement and match expression. @@ -646,7 +646,7 @@ fn main() { ### `convert_match_to_let_else` -**Source:** [convert_match_to_let_else.rs](/crates/ide-assists/src/handlers/convert_match_to_let_else.rs#12) +**Source:** [convert_match_to_let_else.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_match_to_let_else.rs#L12) Converts let statement with match initializer to let-else statement. @@ -669,7 +669,7 @@ fn foo(opt: Option<()>) { ### `convert_named_struct_to_tuple_struct` -**Source:** [convert_named_struct_to_tuple_struct.rs](/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs#11) +**Source:** [convert_named_struct_to_tuple_struct.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs#L11) Converts struct with named fields to tuple struct, and analogously for enum variants with named fields. @@ -714,7 +714,7 @@ impl Point { ### `convert_nested_function_to_closure` -**Source:** [convert_nested_function_to_closure.rs](/crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs#7) +**Source:** [convert_nested_function_to_closure.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_nested_function_to_closure.rs#L7) Converts a function that is defined within the body of another function into a closure. @@ -742,7 +742,7 @@ fn main() { ### `convert_to_guarded_return` -**Source:** [convert_to_guarded_return.rs](/crates/ide-assists/src/handlers/convert_to_guarded_return.rs#24) +**Source:** [convert_to_guarded_return.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_to_guarded_return.rs#L24) Replace a large conditional with a guarded return. @@ -769,7 +769,7 @@ fn main() { ### `convert_tuple_return_type_to_struct` -**Source:** [convert_tuple_return_type_to_struct.rs](/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs#20) +**Source:** [convert_tuple_return_type_to_struct.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs#L20) This converts the return type of a function from a tuple type into a tuple struct and updates the body accordingly. @@ -800,7 +800,7 @@ fn foo() -> FooResult { ### `convert_tuple_struct_to_named_struct` -**Source:** [convert_tuple_struct_to_named_struct.rs](/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs#10) +**Source:** [convert_tuple_struct_to_named_struct.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs#L10) Converts tuple struct to struct with named fields, and analogously for tuple enum variants. @@ -844,7 +844,7 @@ impl Point { ### `convert_two_arm_bool_match_to_matches_macro` -**Source:** [convert_two_arm_bool_match_to_matches_macro.rs](/crates/ide-assists/src/handlers/convert_two_arm_bool_match_to_matches_macro.rs#8) +**Source:** [convert_two_arm_bool_match_to_matches_macro.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_two_arm_bool_match_to_matches_macro.rs#L8) Convert 2-arm match that evaluates to a boolean into the equivalent matches! invocation. @@ -867,7 +867,7 @@ fn main() { ### `convert_while_to_loop` -**Source:** [convert_while_to_loop.rs](/crates/ide-assists/src/handlers/convert_while_to_loop.rs#20) +**Source:** [convert_while_to_loop.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_while_to_loop.rs#L20) Replace a while with a loop. @@ -894,7 +894,7 @@ fn main() { ### `destructure_struct_binding` -**Source:** [destructure_struct_binding.rs](/crates/ide-assists/src/handlers/destructure_struct_binding.rs#18) +**Source:** [destructure_struct_binding.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/destructure_struct_binding.rs#L18) Destructures a struct binding in place. @@ -926,7 +926,7 @@ fn main() { ### `destructure_tuple_binding` -**Source:** [destructure_tuple_binding.rs](/crates/ide-assists/src/handlers/destructure_tuple_binding.rs#19) +**Source:** [destructure_tuple_binding.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/destructure_tuple_binding.rs#L19) Destructures a tuple binding in place. @@ -948,7 +948,7 @@ fn main() { ### `desugar_async_into_impl_future` -**Source:** [toggle_async_sugar.rs](/crates/ide-assists/src/handlers/toggle_async_sugar.rs#103) +**Source:** [toggle_async_sugar.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/toggle_async_sugar.rs#L103) Rewrites asynchronous function from `async fn` into `-> impl Future`. This action does not touch the function body and therefore `0` @@ -970,7 +970,7 @@ pub fn foo() -> impl core::future::Future { ### `desugar_doc_comment` -**Source:** [desugar_doc_comment.rs](/crates/ide-assists/src/handlers/desugar_doc_comment.rs#14) +**Source:** [desugar_doc_comment.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/desugar_doc_comment.rs#L14) Desugars doc-comments to the attribute form. @@ -988,7 +988,7 @@ comment"] ### `expand_glob_import` -**Source:** [expand_glob_import.rs](/crates/ide-assists/src/handlers/expand_glob_import.rs#18) +**Source:** [expand_glob_import.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/expand_glob_import.rs#L19) Expands glob imports. @@ -1017,8 +1017,34 @@ fn qux(bar: Bar, baz: Baz) {} ``` +### `expand_glob_reexport` +**Source:** [expand_glob_import.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/expand_glob_import.rs#L81) + +Expands non-private glob imports. + +#### Before +```rust +mod foo { + pub struct Bar; + pub struct Baz; +} + +pub use foo::*┃; +``` + +#### After +```rust +mod foo { + pub struct Bar; + pub struct Baz; +} + +pub use foo::{Bar, Baz}; +``` + + ### `explicit_enum_discriminant` -**Source:** [explicit_enum_discriminant.rs](/crates/ide-assists/src/handlers/explicit_enum_discriminant.rs#11) +**Source:** [explicit_enum_discriminant.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/explicit_enum_discriminant.rs#L11) Adds explicit discriminant to all enum variants. @@ -1044,7 +1070,7 @@ enum TheEnum { ### `extract_constant` -**Source:** [extract_variable.rs](/crates/ide-assists/src/handlers/extract_variable.rs#35) +**Source:** [extract_variable.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/extract_variable.rs#L35) Extracts subexpression into a constant. @@ -1065,7 +1091,7 @@ fn main() { ### `extract_expressions_from_format_string` -**Source:** [extract_expressions_from_format_string.rs](/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs#14) +**Source:** [extract_expressions_from_format_string.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs#L14) Move an expression out of a format string. @@ -1085,7 +1111,7 @@ fn main() { ### `extract_function` -**Source:** [extract_function.rs](/crates/ide-assists/src/handlers/extract_function.rs#39) +**Source:** [extract_function.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/extract_function.rs#L39) Extracts selected statements and comments into new function. @@ -1117,7 +1143,7 @@ fn ┃fun_name(n: i32) { ### `extract_module` -**Source:** [extract_module.rs](/crates/ide-assists/src/handlers/extract_module.rs#29) +**Source:** [extract_module.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/extract_module.rs#L29) Extracts a selected region as separate module. All the references, visibility and imports are resolved. @@ -1148,7 +1174,7 @@ fn bar(name: i32) -> i32 { ### `extract_static` -**Source:** [extract_variable.rs](/crates/ide-assists/src/handlers/extract_variable.rs#52) +**Source:** [extract_variable.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/extract_variable.rs#L52) Extracts subexpression into a static. @@ -1169,7 +1195,7 @@ fn main() { ### `extract_struct_from_enum_variant` -**Source:** [extract_struct_from_enum_variant.rs](/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs#26) +**Source:** [extract_struct_from_enum_variant.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs#L26) Extracts a struct from enum variant. @@ -1187,7 +1213,7 @@ enum A { One(One) } ### `extract_type_alias` -**Source:** [extract_type_alias.rs](/crates/ide-assists/src/handlers/extract_type_alias.rs#10) +**Source:** [extract_type_alias.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/extract_type_alias.rs#L10) Extracts the selected type as a type alias. @@ -1209,7 +1235,7 @@ struct S { ### `extract_variable` -**Source:** [extract_variable.rs](/crates/ide-assists/src/handlers/extract_variable.rs#18) +**Source:** [extract_variable.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/extract_variable.rs#L18) Extracts subexpression into a variable. @@ -1230,7 +1256,7 @@ fn main() { ### `fill_record_pattern_fields` -**Source:** [fill_record_pattern_fields.rs](/crates/ide-assists/src/handlers/fill_record_pattern_fields.rs#8) +**Source:** [fill_record_pattern_fields.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/fill_record_pattern_fields.rs#L8) Fills fields by replacing rest pattern in record patterns. @@ -1254,7 +1280,7 @@ fn foo(bar: Bar) { ### `fix_visibility` -**Source:** [fix_visibility.rs](/crates/ide-assists/src/handlers/fix_visibility.rs#14) +**Source:** [fix_visibility.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/fix_visibility.rs#L14) Makes inaccessible item public. @@ -1280,7 +1306,7 @@ fn main() { ### `flip_binexpr` -**Source:** [flip_binexpr.rs](/crates/ide-assists/src/handlers/flip_binexpr.rs#8) +**Source:** [flip_binexpr.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/flip_binexpr.rs#L8) Flips operands of a binary expression. @@ -1300,7 +1326,7 @@ fn main() { ### `flip_comma` -**Source:** [flip_comma.rs](/crates/ide-assists/src/handlers/flip_comma.rs#10) +**Source:** [flip_comma.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/flip_comma.rs#L10) Flips two comma-separated items. @@ -1320,7 +1346,7 @@ fn main() { ### `flip_trait_bound` -**Source:** [flip_trait_bound.rs](/crates/ide-assists/src/handlers/flip_trait_bound.rs#9) +**Source:** [flip_trait_bound.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/flip_trait_bound.rs#L9) Flips two trait bounds. @@ -1336,7 +1362,7 @@ fn foo() { } ### `generate_constant` -**Source:** [generate_constant.rs](/crates/ide-assists/src/handlers/generate_constant.rs#14) +**Source:** [generate_constant.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_constant.rs#L14) Generate a named constant. @@ -1361,7 +1387,7 @@ fn main() { ### `generate_default_from_enum_variant` -**Source:** [generate_default_from_enum_variant.rs](/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs#6) +**Source:** [generate_default_from_enum_variant.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs#L6) Adds a Default impl for an enum using a variant. @@ -1391,7 +1417,7 @@ impl Default for Version { ### `generate_default_from_new` -**Source:** [generate_default_from_new.rs](/crates/ide-assists/src/handlers/generate_default_from_new.rs#13) +**Source:** [generate_default_from_new.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_default_from_new.rs#L13) Generates default implementation from new method. @@ -1425,7 +1451,7 @@ impl Default for Example { ### `generate_delegate_methods` -**Source:** [generate_delegate_methods.rs](/crates/ide-assists/src/handlers/generate_delegate_methods.rs#15) +**Source:** [generate_delegate_methods.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_delegate_methods.rs#L15) Generate delegate methods. @@ -1465,7 +1491,7 @@ impl Person { ### `generate_delegate_trait` -**Source:** [generate_delegate_trait.rs](/crates/ide-assists/src/handlers/generate_delegate_trait.rs#29) +**Source:** [generate_delegate_trait.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_delegate_trait.rs#L29) Generate delegate trait implementation for `StructField`s. @@ -1531,7 +1557,7 @@ impl SomeTrait for B { ### `generate_deref` -**Source:** [generate_deref.rs](/crates/ide-assists/src/handlers/generate_deref.rs#16) +**Source:** [generate_deref.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_deref.rs#L16) Generate `Deref` impl using the given struct field. @@ -1561,7 +1587,7 @@ impl core::ops::Deref for B { ### `generate_derive` -**Source:** [generate_derive.rs](/crates/ide-assists/src/handlers/generate_derive.rs#8) +**Source:** [generate_derive.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_derive.rs#L8) Adds a new `#[derive()]` clause to a struct or enum. @@ -1584,7 +1610,7 @@ struct Point { ### `generate_doc_example` -**Source:** [generate_documentation_template.rs](/crates/ide-assists/src/handlers/generate_documentation_template.rs#76) +**Source:** [generate_documentation_template.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_documentation_template.rs#L76) Generates a rustdoc example when editing an item's documentation. @@ -1610,7 +1636,7 @@ pub fn add(a: i32, b: i32) -> i32 { a + b } ### `generate_documentation_template` -**Source:** [generate_documentation_template.rs](/crates/ide-assists/src/handlers/generate_documentation_template.rs#13) +**Source:** [generate_documentation_template.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_documentation_template.rs#L13) Adds a documentation template above a function definition / declaration. @@ -1645,7 +1671,7 @@ impl S { ### `generate_enum_as_method` -**Source:** [generate_enum_projection_method.rs](/crates/ide-assists/src/handlers/generate_enum_projection_method.rs#59) +**Source:** [generate_enum_projection_method.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_enum_projection_method.rs#L59) Generate an `as_` method for this enum variant. @@ -1677,7 +1703,7 @@ impl Value { ### `generate_enum_is_method` -**Source:** [generate_enum_is_method.rs](/crates/ide-assists/src/handlers/generate_enum_is_method.rs#11) +**Source:** [generate_enum_is_method.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_enum_is_method.rs#L11) Generate an `is_` method for this enum variant. @@ -1711,7 +1737,7 @@ impl Version { ### `generate_enum_try_into_method` -**Source:** [generate_enum_projection_method.rs](/crates/ide-assists/src/handlers/generate_enum_projection_method.rs#12) +**Source:** [generate_enum_projection_method.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_enum_projection_method.rs#L12) Generate a `try_into_` method for this enum variant. @@ -1743,7 +1769,7 @@ impl Value { ### `generate_enum_variant` -**Source:** [generate_enum_variant.rs](/crates/ide-assists/src/handlers/generate_enum_variant.rs#10) +**Source:** [generate_enum_variant.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_enum_variant.rs#L10) Adds a variant to an enum. @@ -1772,7 +1798,7 @@ fn main() { ### `generate_fn_type_alias_named` -**Source:** [generate_fn_type_alias.rs](/crates/ide-assists/src/handlers/generate_fn_type_alias.rs#10) +**Source:** [generate_fn_type_alias.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_fn_type_alias.rs#L10) Generate a type alias for the function with named parameters. @@ -1790,7 +1816,7 @@ unsafe fn foo(n: i32) -> i32 { 42i32 } ### `generate_fn_type_alias_unnamed` -**Source:** [generate_fn_type_alias.rs](/crates/ide-assists/src/handlers/generate_fn_type_alias.rs#24) +**Source:** [generate_fn_type_alias.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_fn_type_alias.rs#L24) Generate a type alias for the function with unnamed parameters. @@ -1808,7 +1834,7 @@ unsafe fn foo(n: i32) -> i32 { 42i32 } ### `generate_from_impl_for_enum` -**Source:** [generate_from_impl_for_enum.rs](/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs#8) +**Source:** [generate_from_impl_for_enum.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs#L8) Adds a From impl for this enum variant with one tuple field. @@ -1830,7 +1856,7 @@ impl From for A { ### `generate_function` -**Source:** [generate_function.rs](/crates/ide-assists/src/handlers/generate_function.rs#28) +**Source:** [generate_function.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_function.rs#L28) Adds a stub function with a signature matching the function under the cursor. @@ -1860,7 +1886,7 @@ fn bar(arg: &str, baz: Baz) ${0:-> _} { ### `generate_getter` -**Source:** [generate_getter_or_setter.rs](/crates/ide-assists/src/handlers/generate_getter_or_setter.rs#73) +**Source:** [generate_getter_or_setter.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_getter_or_setter.rs#L73) Generate a getter method. @@ -1886,7 +1912,7 @@ impl Person { ### `generate_getter_mut` -**Source:** [generate_getter_or_setter.rs](/crates/ide-assists/src/handlers/generate_getter_or_setter.rs#127) +**Source:** [generate_getter_or_setter.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_getter_or_setter.rs#L127) Generate a mut getter method. @@ -1912,7 +1938,7 @@ impl Person { ### `generate_impl` -**Source:** [generate_impl.rs](/crates/ide-assists/src/handlers/generate_impl.rs#20) +**Source:** [generate_impl.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_impl.rs#L20) Adds a new inherent impl for a type. @@ -1934,7 +1960,7 @@ impl Ctx {┃} ### `generate_is_empty_from_len` -**Source:** [generate_is_empty_from_len.rs](/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs#12) +**Source:** [generate_is_empty_from_len.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_is_empty_from_len.rs#L12) Generates is_empty implementation from the len method. @@ -1969,7 +1995,7 @@ impl MyStruct { ### `generate_mut_trait_impl` -**Source:** [generate_mut_trait_impl.rs](/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs#12) +**Source:** [generate_mut_trait_impl.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs#L12) Adds a IndexMut impl from the `Index` trait. @@ -2007,7 +2033,7 @@ impl core::ops::Index for [T; 3] { ### `generate_new` -**Source:** [generate_new.rs](/crates/ide-assists/src/handlers/generate_new.rs#14) +**Source:** [generate_new.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_new.rs#L14) Adds a `fn new` for a type. @@ -2033,7 +2059,7 @@ impl Ctx { ### `generate_setter` -**Source:** [generate_getter_or_setter.rs](/crates/ide-assists/src/handlers/generate_getter_or_setter.rs#13) +**Source:** [generate_getter_or_setter.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_getter_or_setter.rs#L13) Generate a setter method. @@ -2059,7 +2085,7 @@ impl Person { ### `generate_trait_from_impl` -**Source:** [generate_trait_from_impl.rs](/crates/ide-assists/src/handlers/generate_trait_from_impl.rs#18) +**Source:** [generate_trait_from_impl.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_trait_from_impl.rs#L18) Generate trait for an already defined inherent impl and convert impl to a trait impl. @@ -2118,7 +2144,7 @@ impl ${0:NewTrait} for Foo { ### `generate_trait_impl` -**Source:** [generate_impl.rs](/crates/ide-assists/src/handlers/generate_impl.rs#66) +**Source:** [generate_impl.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/generate_impl.rs#L66) Adds a new trait impl for a type. @@ -2140,7 +2166,7 @@ impl ${0:_} for Ctx {} ### `inline_call` -**Source:** [inline_call.rs](/crates/ide-assists/src/handlers/inline_call.rs#170) +**Source:** [inline_call.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/inline_call.rs#L170) Inlines a function or method body creating a `let` statement per parameter unless the parameter can be inlined. The parameter will be inlined either if it the supplied argument is a simple local @@ -2165,7 +2191,7 @@ fn foo(name: Option<&str>) { ### `inline_const_as_literal` -**Source:** [inline_const_as_literal.rs](/crates/ide-assists/src/handlers/inline_const_as_literal.rs#6) +**Source:** [inline_const_as_literal.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/inline_const_as_literal.rs#L6) Evaluate and inline const variable as literal. @@ -2189,7 +2215,7 @@ fn something() -> &'static str { ### `inline_into_callers` -**Source:** [inline_call.rs](/crates/ide-assists/src/handlers/inline_call.rs#32) +**Source:** [inline_call.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/inline_call.rs#L32) Inline a function or method body into all of its callers where possible, creating a `let` statement per parameter unless the parameter can be inlined. The parameter will be inlined either if it the supplied argument is a simple local @@ -2232,7 +2258,7 @@ fn bar() { ### `inline_local_variable` -**Source:** [inline_local_variable.rs](/crates/ide-assists/src/handlers/inline_local_variable.rs#17) +**Source:** [inline_local_variable.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/inline_local_variable.rs#L17) Inlines a local variable. @@ -2253,7 +2279,7 @@ fn main() { ### `inline_macro` -**Source:** [inline_macro.rs](/crates/ide-assists/src/handlers/inline_macro.rs#7) +**Source:** [inline_macro.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/inline_macro.rs#L7) Takes a macro and inlines it one step. @@ -2289,7 +2315,7 @@ fn main() { ### `inline_type_alias` -**Source:** [inline_type_alias.rs](/crates/ide-assists/src/handlers/inline_type_alias.rs#106) +**Source:** [inline_type_alias.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/inline_type_alias.rs#L106) Replace a type alias with its concrete type. @@ -2313,7 +2339,7 @@ fn main() { ### `inline_type_alias_uses` -**Source:** [inline_type_alias.rs](/crates/ide-assists/src/handlers/inline_type_alias.rs#24) +**Source:** [inline_type_alias.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/inline_type_alias.rs#L24) Inline a type alias into all of its uses where possible. @@ -2341,7 +2367,7 @@ fn foo() { ### `into_to_qualified_from` -**Source:** [into_to_qualified_from.rs](/crates/ide-assists/src/handlers/into_to_qualified_from.rs#10) +**Source:** [into_to_qualified_from.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/into_to_qualified_from.rs#L10) Convert an `into` method call to a fully qualified `from` call. @@ -2378,7 +2404,7 @@ fn main() -> () { ### `introduce_named_generic` -**Source:** [introduce_named_generic.rs](/crates/ide-assists/src/handlers/introduce_named_generic.rs#7) +**Source:** [introduce_named_generic.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/introduce_named_generic.rs#L7) Replaces `impl Trait` function argument with the named generic. @@ -2394,7 +2420,7 @@ fn foo<┃B: Bar>(bar: B) {} ### `introduce_named_lifetime` -**Source:** [introduce_named_lifetime.rs](/crates/ide-assists/src/handlers/introduce_named_lifetime.rs#13) +**Source:** [introduce_named_lifetime.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/introduce_named_lifetime.rs#L13) Change an anonymous lifetime to a named lifetime. @@ -2422,7 +2448,7 @@ impl<'a> Cursor<'a> { ### `invert_if` -**Source:** [invert_if.rs](/crates/ide-assists/src/handlers/invert_if.rs#13) +**Source:** [invert_if.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/invert_if.rs#L13) This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}` This also works with `!=`. This assist can only be applied with the cursor on `if`. @@ -2443,7 +2469,7 @@ fn main() { ### `line_to_block` -**Source:** [convert_comment_block.rs](/crates/ide-assists/src/handlers/convert_comment_block.rs#9) +**Source:** [convert_comment_block.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/convert_comment_block.rs#L9) Converts comments between block and single-line form. @@ -2463,7 +2489,7 @@ Converts comments between block and single-line form. ### `make_raw_string` -**Source:** [raw_string.rs](/crates/ide-assists/src/handlers/raw_string.rs#7) +**Source:** [raw_string.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/raw_string.rs#L7) Adds `r#` to a plain string literal. @@ -2483,7 +2509,7 @@ fn main() { ### `make_usual_string` -**Source:** [raw_string.rs](/crates/ide-assists/src/handlers/raw_string.rs#47) +**Source:** [raw_string.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/raw_string.rs#L47) Turns a raw string into a plain string. @@ -2503,7 +2529,7 @@ fn main() { ### `merge_imports` -**Source:** [merge_imports.rs](/crates/ide-assists/src/handlers/merge_imports.rs#21) +**Source:** [merge_imports.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/merge_imports.rs#L21) Merges neighbor imports with a common prefix. @@ -2520,7 +2546,7 @@ use std::{fmt::Formatter, io}; ### `merge_match_arms` -**Source:** [merge_match_arms.rs](/crates/ide-assists/src/handlers/merge_match_arms.rs#12) +**Source:** [merge_match_arms.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/merge_match_arms.rs#L12) Merges the current match arm with the following if their bodies are identical. @@ -2549,7 +2575,7 @@ fn handle(action: Action) { ### `merge_nested_if` -**Source:** [merge_nested_if.rs](/crates/ide-assists/src/handlers/merge_nested_if.rs#11) +**Source:** [merge_nested_if.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/merge_nested_if.rs#L11) This transforms if expressions of the form `if x { if y {A} }` into `if x && y {A}` This assist can only be applied with the cursor on `if`. @@ -2570,7 +2596,7 @@ fn main() { ### `move_arm_cond_to_match_guard` -**Source:** [move_guard.rs](/crates/ide-assists/src/handlers/move_guard.rs#69) +**Source:** [move_guard.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/move_guard.rs#L69) Moves if expression from match arm body into a guard. @@ -2600,7 +2626,7 @@ fn handle(action: Action) { ### `move_bounds_to_where_clause` -**Source:** [move_bounds.rs](/crates/ide-assists/src/handlers/move_bounds.rs#12) +**Source:** [move_bounds.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/move_bounds.rs#L12) Moves inline type bounds to a where clause. @@ -2620,7 +2646,7 @@ fn apply(f: F, x: T) -> U where F: FnOnce(T) -> U { ### `move_const_to_impl` -**Source:** [move_const_to_impl.rs](/crates/ide-assists/src/handlers/move_const_to_impl.rs#14) +**Source:** [move_const_to_impl.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/move_const_to_impl.rs#L14) Move a local constant item in a method to impl's associated constant. All the references will be qualified with `Self::`. @@ -2653,7 +2679,7 @@ impl S { ### `move_from_mod_rs` -**Source:** [move_from_mod_rs.rs](/crates/ide-assists/src/handlers/move_from_mod_rs.rs#12) +**Source:** [move_from_mod_rs.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/move_from_mod_rs.rs#L12) Moves xxx/mod.rs to xxx.rs. @@ -2672,7 +2698,7 @@ fn t() {} ### `move_guard_to_arm_body` -**Source:** [move_guard.rs](/crates/ide-assists/src/handlers/move_guard.rs#8) +**Source:** [move_guard.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/move_guard.rs#L8) Moves match guard into match arm body. @@ -2704,7 +2730,7 @@ fn handle(action: Action) { ### `move_module_to_file` -**Source:** [move_module_to_file.rs](/crates/ide-assists/src/handlers/move_module_to_file.rs#15) +**Source:** [move_module_to_file.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/move_module_to_file.rs#L15) Moves inline module's contents to a separate file. @@ -2722,7 +2748,7 @@ mod foo; ### `move_to_mod_rs` -**Source:** [move_to_mod_rs.rs](/crates/ide-assists/src/handlers/move_to_mod_rs.rs#12) +**Source:** [move_to_mod_rs.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/move_to_mod_rs.rs#L12) Moves xxx.rs to xxx/mod.rs. @@ -2741,7 +2767,7 @@ fn t() {} ### `normalize_import` -**Source:** [normalize_import.rs](/crates/ide-assists/src/handlers/normalize_import.rs#9) +**Source:** [normalize_import.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/normalize_import.rs#L9) Normalizes an import. @@ -2757,7 +2783,7 @@ use std::{fmt::Formatter, io}; ### `promote_local_to_const` -**Source:** [promote_local_to_const.rs](/crates/ide-assists/src/handlers/promote_local_to_const.rs#17) +**Source:** [promote_local_to_const.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/promote_local_to_const.rs#L17) Promotes a local variable to a const item changing its name to a `SCREAMING_SNAKE_CASE` variant if the local uses no non-const expressions. @@ -2790,7 +2816,7 @@ fn main() { ### `pull_assignment_up` -**Source:** [pull_assignment_up.rs](/crates/ide-assists/src/handlers/pull_assignment_up.rs#11) +**Source:** [pull_assignment_up.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/pull_assignment_up.rs#L11) Extracts variable assignment to outside an if or match statement. @@ -2822,7 +2848,7 @@ fn main() { ### `qualify_method_call` -**Source:** [qualify_method_call.rs](/crates/ide-assists/src/handlers/qualify_method_call.rs#10) +**Source:** [qualify_method_call.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/qualify_method_call.rs#L10) Replaces the method call with a qualified function call. @@ -2852,7 +2878,7 @@ fn main() { ### `qualify_path` -**Source:** [qualify_path.rs](/crates/ide-assists/src/handlers/qualify_path.rs#24) +**Source:** [qualify_path.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/qualify_path.rs#L24) If the name is unresolved, provides all possible qualified paths for it. @@ -2872,7 +2898,7 @@ fn main() { ### `reformat_number_literal` -**Source:** [number_representation.rs](/crates/ide-assists/src/handlers/number_representation.rs#7) +**Source:** [number_representation.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/number_representation.rs#L7) Adds or removes separators from integer literal. @@ -2888,7 +2914,7 @@ const _: i32 = 1_012_345; ### `remove_dbg` -**Source:** [remove_dbg.rs](/crates/ide-assists/src/handlers/remove_dbg.rs#9) +**Source:** [remove_dbg.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/remove_dbg.rs#L9) Removes `dbg!()` macro call. @@ -2908,7 +2934,7 @@ fn main() { ### `remove_hash` -**Source:** [raw_string.rs](/crates/ide-assists/src/handlers/raw_string.rs#117) +**Source:** [raw_string.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/raw_string.rs#L117) Removes a hash from a raw string literal. @@ -2928,7 +2954,7 @@ fn main() { ### `remove_mut` -**Source:** [remove_mut.rs](/crates/ide-assists/src/handlers/remove_mut.rs#5) +**Source:** [remove_mut.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/remove_mut.rs#L5) Removes the `mut` keyword. @@ -2948,7 +2974,7 @@ impl Walrus { ### `remove_parentheses` -**Source:** [remove_parentheses.rs](/crates/ide-assists/src/handlers/remove_parentheses.rs#5) +**Source:** [remove_parentheses.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/remove_parentheses.rs#L5) Removes redundant parentheses. @@ -2968,7 +2994,7 @@ fn main() { ### `remove_unused_imports` -**Source:** [remove_unused_imports.rs](/crates/ide-assists/src/handlers/remove_unused_imports.rs#17) +**Source:** [remove_unused_imports.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/remove_unused_imports.rs#L17) Removes any use statements in the current selection that are unused. @@ -2989,7 +3015,7 @@ mod foo { ### `remove_unused_param` -**Source:** [remove_unused_param.rs](/crates/ide-assists/src/handlers/remove_unused_param.rs#15) +**Source:** [remove_unused_param.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/remove_unused_param.rs#L15) Removes unused function parameter. @@ -3013,7 +3039,7 @@ fn main() { ### `reorder_fields` -**Source:** [reorder_fields.rs](/crates/ide-assists/src/handlers/reorder_fields.rs#8) +**Source:** [reorder_fields.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/reorder_fields.rs#L8) Reorder the fields of record literals and record patterns in the same order as in the definition. @@ -3032,7 +3058,7 @@ const test: Foo = Foo {foo: 1, bar: 0} ### `reorder_impl_items` -**Source:** [reorder_impl_items.rs](/crates/ide-assists/src/handlers/reorder_impl_items.rs#11) +**Source:** [reorder_impl_items.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/reorder_impl_items.rs#L11) Reorder the items of an `impl Trait`. The items will be ordered in the same order as in the trait definition. @@ -3071,7 +3097,7 @@ impl Foo for Bar { ### `replace_arith_with_checked` -**Source:** [replace_arith_op.rs](/crates/ide-assists/src/handlers/replace_arith_op.rs#9) +**Source:** [replace_arith_op.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_arith_op.rs#L9) Replaces arithmetic on integers with the `checked_*` equivalent. @@ -3091,7 +3117,7 @@ fn main() { ### `replace_arith_with_saturating` -**Source:** [replace_arith_op.rs](/crates/ide-assists/src/handlers/replace_arith_op.rs#28) +**Source:** [replace_arith_op.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_arith_op.rs#L28) Replaces arithmetic on integers with the `saturating_*` equivalent. @@ -3111,7 +3137,7 @@ fn main() { ### `replace_arith_with_wrapping` -**Source:** [replace_arith_op.rs](/crates/ide-assists/src/handlers/replace_arith_op.rs#50) +**Source:** [replace_arith_op.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_arith_op.rs#L50) Replaces arithmetic on integers with the `wrapping_*` equivalent. @@ -3131,7 +3157,7 @@ fn main() { ### `replace_char_with_string` -**Source:** [replace_string_with_char.rs](/crates/ide-assists/src/handlers/replace_string_with_char.rs#51) +**Source:** [replace_string_with_char.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_string_with_char.rs#L51) Replace a char literal with a string literal. @@ -3151,7 +3177,7 @@ fn main() { ### `replace_derive_with_manual_impl` -**Source:** [replace_derive_with_manual_impl.rs](/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs#20) +**Source:** [replace_derive_with_manual_impl.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs#L20) Converts a `derive` impl into a manual one. @@ -3175,7 +3201,7 @@ impl Debug for S { ### `replace_if_let_with_match` -**Source:** [replace_if_let_with_match.rs](/crates/ide-assists/src/handlers/replace_if_let_with_match.rs#20) +**Source:** [replace_if_let_with_match.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_if_let_with_match.rs#L20) Replaces a `if let` expression with a `match` expression. @@ -3206,7 +3232,7 @@ fn handle(action: Action) { ### `replace_is_some_with_if_let_some` -**Source:** [replace_is_method_with_if_let_method.rs](/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs#9) +**Source:** [replace_is_method_with_if_let_method.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs#L9) Replace `if x.is_some()` with `if let Some(_tmp) = x` or `if x.is_ok()` with `if let Ok(_tmp) = x`. @@ -3228,7 +3254,7 @@ fn main() { ### `replace_let_with_if_let` -**Source:** [replace_let_with_if_let.rs](/crates/ide-assists/src/handlers/replace_let_with_if_let.rs#9) +**Source:** [replace_let_with_if_let.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_let_with_if_let.rs#L9) Replaces `let` with an `if let`. @@ -3255,7 +3281,7 @@ fn compute() -> Option { None } ### `replace_match_with_if_let` -**Source:** [replace_if_let_with_match.rs](/crates/ide-assists/src/handlers/replace_if_let_with_match.rs#188) +**Source:** [replace_if_let_with_match.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_if_let_with_match.rs#L188) Replaces a binary `match` with a wildcard pattern and no guards with an `if let` expression. @@ -3286,7 +3312,7 @@ fn handle(action: Action) { ### `replace_named_generic_with_impl` -**Source:** [replace_named_generic_with_impl.rs](/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs#18) +**Source:** [replace_named_generic_with_impl.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_named_generic_with_impl.rs#L18) Replaces named generic with an `impl Trait` in function argument. @@ -3302,7 +3328,7 @@ fn new(location: impl AsRef) -> Self {} ### `replace_qualified_name_with_use` -**Source:** [replace_qualified_name_with_use.rs](/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs#13) +**Source:** [replace_qualified_name_with_use.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs#L13) Adds a use statement for a given fully-qualified name. @@ -3320,7 +3346,7 @@ fn process(map: HashMap) {} ### `replace_string_with_char` -**Source:** [replace_string_with_char.rs](/crates/ide-assists/src/handlers/replace_string_with_char.rs#11) +**Source:** [replace_string_with_char.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_string_with_char.rs#L11) Replace string literal with char literal. @@ -3340,7 +3366,7 @@ fn main() { ### `replace_try_expr_with_match` -**Source:** [replace_try_expr_with_match.rs](/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs#18) +**Source:** [replace_try_expr_with_match.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_try_expr_with_match.rs#L18) Replaces a `try` expression with a `match` expression. @@ -3363,7 +3389,7 @@ fn handle() { ### `replace_turbofish_with_explicit_type` -**Source:** [replace_turbofish_with_explicit_type.rs](/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs#12) +**Source:** [replace_turbofish_with_explicit_type.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_turbofish_with_explicit_type.rs#L12) Converts `::<_>` to an explicit type assignment. @@ -3385,7 +3411,7 @@ fn main() { ### `replace_with_eager_method` -**Source:** [replace_method_eager_lazy.rs](/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs#89) +**Source:** [replace_method_eager_lazy.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs#L89) Replace `unwrap_or_else` with `unwrap_or` and `ok_or_else` with `ok_or`. @@ -3407,7 +3433,7 @@ fn foo() { ### `replace_with_lazy_method` -**Source:** [replace_method_eager_lazy.rs](/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs#9) +**Source:** [replace_method_eager_lazy.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/replace_method_eager_lazy.rs#L9) Replace `unwrap_or` with `unwrap_or_else` and `ok_or` with `ok_or_else`. @@ -3429,7 +3455,7 @@ fn foo() { ### `sort_items` -**Source:** [sort_items.rs](/crates/ide-assists/src/handlers/sort_items.rs#12) +**Source:** [sort_items.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/sort_items.rs#L12) Sorts item members alphabetically: fields, enum variants and methods. @@ -3520,7 +3546,7 @@ enum Animal { ### `split_import` -**Source:** [split_import.rs](/crates/ide-assists/src/handlers/split_import.rs#5) +**Source:** [split_import.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/split_import.rs#L5) Wraps the tail of import into braces. @@ -3536,7 +3562,7 @@ use std::{collections::HashMap}; ### `sugar_impl_future_into_async` -**Source:** [toggle_async_sugar.rs](/crates/ide-assists/src/handlers/toggle_async_sugar.rs#13) +**Source:** [toggle_async_sugar.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/toggle_async_sugar.rs#L13) Rewrites asynchronous function from `-> impl Future` into `async fn`. This action does not touch the function body and therefore `async { 0 }` @@ -3558,7 +3584,7 @@ pub async fn foo() -> usize { ### `toggle_ignore` -**Source:** [toggle_ignore.rs](/crates/ide-assists/src/handlers/toggle_ignore.rs#8) +**Source:** [toggle_ignore.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/toggle_ignore.rs#L8) Adds `#[ignore]` attribute to the test. @@ -3581,7 +3607,7 @@ fn arithmetics { ### `toggle_macro_delimiter` -**Source:** [toggle_macro_delimiter.rs](/crates/ide-assists/src/handlers/toggle_macro_delimiter.rs#9) +**Source:** [toggle_macro_delimiter.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/toggle_macro_delimiter.rs#L9) Change macro delimiters in the order of `( -> { -> [ -> (`. @@ -3605,7 +3631,7 @@ sth!{ } ### `unmerge_match_arm` -**Source:** [unmerge_match_arm.rs](/crates/ide-assists/src/handlers/unmerge_match_arm.rs#10) +**Source:** [unmerge_match_arm.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/unmerge_match_arm.rs#L10) Splits the current match with a `|` pattern into two arms with identical bodies. @@ -3634,7 +3660,7 @@ fn handle(action: Action) { ### `unmerge_use` -**Source:** [unmerge_use.rs](/crates/ide-assists/src/handlers/unmerge_use.rs#12) +**Source:** [unmerge_use.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/unmerge_use.rs#L12) Extracts single use item from use list. @@ -3651,7 +3677,7 @@ use std::fmt::Display; ### `unnecessary_async` -**Source:** [unnecessary_async.rs](/crates/ide-assists/src/handlers/unnecessary_async.rs#17) +**Source:** [unnecessary_async.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/unnecessary_async.rs#L17) Removes the `async` mark from functions which have no `.await` in their body. Looks for calls to the functions and removes the `.await` on the call site. @@ -3670,7 +3696,7 @@ pub async fn bar() { foo() } ### `unqualify_method_call` -**Source:** [unqualify_method_call.rs](/crates/ide-assists/src/handlers/unqualify_method_call.rs#9) +**Source:** [unqualify_method_call.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/unqualify_method_call.rs#L9) Transforms universal function call syntax into a method call. @@ -3692,7 +3718,7 @@ fn main() { ### `unwrap_block` -**Source:** [unwrap_block.rs](/crates/ide-assists/src/handlers/unwrap_block.rs#12) +**Source:** [unwrap_block.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/unwrap_block.rs#L12) This assist removes if...else, for, while and loop control statements to just keep the body. @@ -3714,7 +3740,7 @@ fn foo() { ### `unwrap_option_return_type` -**Source:** [unwrap_return_type.rs](/crates/ide-assists/src/handlers/unwrap_return_type.rs#13) +**Source:** [unwrap_return_type.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/unwrap_return_type.rs#L13) Unwrap the function's return type. @@ -3730,7 +3756,7 @@ fn foo() -> i32 { 42i32 } ### `unwrap_result_return_type` -**Source:** [unwrap_return_type.rs](/crates/ide-assists/src/handlers/unwrap_return_type.rs#26) +**Source:** [unwrap_return_type.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/unwrap_return_type.rs#L26) Unwrap the function's return type. @@ -3746,7 +3772,7 @@ fn foo() -> i32 { 42i32 } ### `unwrap_tuple` -**Source:** [unwrap_tuple.rs](/crates/ide-assists/src/handlers/unwrap_tuple.rs#8) +**Source:** [unwrap_tuple.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/unwrap_tuple.rs#L8) Unwrap the tuple to different variables. @@ -3767,7 +3793,7 @@ fn main() { ### `wrap_return_type_in_option` -**Source:** [wrap_return_type.rs](/crates/ide-assists/src/handlers/wrap_return_type.rs#16) +**Source:** [wrap_return_type.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/wrap_return_type.rs#L16) Wrap the function's return type into Option. @@ -3783,7 +3809,7 @@ fn foo() -> Option { Some(42i32) } ### `wrap_return_type_in_result` -**Source:** [wrap_return_type.rs](/crates/ide-assists/src/handlers/wrap_return_type.rs#29) +**Source:** [wrap_return_type.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/wrap_return_type.rs#L29) Wrap the function's return type into Result. @@ -3799,7 +3825,7 @@ fn foo() -> Result { Ok(42i32) } ### `wrap_unwrap_cfg_attr` -**Source:** [wrap_unwrap_cfg_attr.rs](/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs#12) +**Source:** [wrap_unwrap_cfg_attr.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/wrap_unwrap_cfg_attr.rs#L12) Wraps an attribute to a cfg_attr attribute or unwraps a cfg_attr attribute to the inner attributes.