mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Merge #10290
10290: minor: Simplify r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
06ea89d3de
6 changed files with 26 additions and 30 deletions
|
@ -106,7 +106,7 @@ impl CargoConfig {
|
||||||
UnsetTestCrates::Only(unset_test_crates) => CfgOverrides::Selective(
|
UnsetTestCrates::Only(unset_test_crates) => CfgOverrides::Selective(
|
||||||
unset_test_crates
|
unset_test_crates
|
||||||
.iter()
|
.iter()
|
||||||
.map(|name| name.clone())
|
.cloned()
|
||||||
.zip(iter::repeat_with(|| {
|
.zip(iter::repeat_with(|| {
|
||||||
cfg::CfgDiff::new(Vec::new(), vec![cfg::CfgAtom::Flag("test".into())])
|
cfg::CfgDiff::new(Vec::new(), vec![cfg::CfgAtom::Flag("test".into())])
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -47,13 +47,12 @@ fn get_test_json_file<T: DeserializeOwned>(file: &str) -> T {
|
||||||
fixup_paths(&mut json);
|
fixup_paths(&mut json);
|
||||||
return serde_json::from_value(json).unwrap();
|
return serde_json::from_value(json).unwrap();
|
||||||
|
|
||||||
fn fixup_paths(val: &mut serde_json::Value) -> () {
|
fn fixup_paths(val: &mut serde_json::Value) {
|
||||||
match val {
|
match val {
|
||||||
serde_json::Value::String(s) => replace_root(s, true),
|
serde_json::Value::String(s) => replace_root(s, true),
|
||||||
serde_json::Value::Array(vals) => vals.iter_mut().for_each(fixup_paths),
|
serde_json::Value::Array(vals) => vals.iter_mut().for_each(fixup_paths),
|
||||||
serde_json::Value::Object(kvals) => kvals.values_mut().for_each(fixup_paths),
|
serde_json::Value::Object(kvals) => kvals.values_mut().for_each(fixup_paths),
|
||||||
serde_json::Value::Null | serde_json::Value::Bool(_) | serde_json::Value::Number(_) => {
|
serde_json::Value::Null | serde_json::Value::Bool(_) | serde_json::Value::Number(_) => {
|
||||||
()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,7 @@ impl ProjectWorkspace {
|
||||||
Some(rustc_dir) => Some({
|
Some(rustc_dir) => Some({
|
||||||
let meta = CargoWorkspace::fetch_metadata(&rustc_dir, config, progress)
|
let meta = CargoWorkspace::fetch_metadata(&rustc_dir, config, progress)
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!("Failed to read Cargo metadata for Rust sources")
|
"Failed to read Cargo metadata for Rust sources".to_string()
|
||||||
})?;
|
})?;
|
||||||
CargoWorkspace::new(meta)
|
CargoWorkspace::new(meta)
|
||||||
}),
|
}),
|
||||||
|
@ -328,12 +328,12 @@ impl ProjectWorkspace {
|
||||||
}
|
}
|
||||||
PackageRoot { is_local, include, exclude }
|
PackageRoot { is_local, include, exclude }
|
||||||
})
|
})
|
||||||
.chain(sysroot.into_iter().map(|sysroot| PackageRoot {
|
.chain(sysroot.iter().map(|sysroot| PackageRoot {
|
||||||
is_local: false,
|
is_local: false,
|
||||||
include: vec![sysroot.root().to_path_buf()],
|
include: vec![sysroot.root().to_path_buf()],
|
||||||
exclude: Vec::new(),
|
exclude: Vec::new(),
|
||||||
}))
|
}))
|
||||||
.chain(rustc.into_iter().flat_map(|rustc| {
|
.chain(rustc.iter().flat_map(|rustc| {
|
||||||
rustc.packages().map(move |krate| PackageRoot {
|
rustc.packages().map(move |krate| PackageRoot {
|
||||||
is_local: false,
|
is_local: false,
|
||||||
include: vec![rustc[krate].manifest.parent().to_path_buf()],
|
include: vec![rustc[krate].manifest.parent().to_path_buf()],
|
||||||
|
@ -343,7 +343,7 @@ impl ProjectWorkspace {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
ProjectWorkspace::DetachedFiles { files, sysroot, .. } => files
|
ProjectWorkspace::DetachedFiles { files, sysroot, .. } => files
|
||||||
.into_iter()
|
.iter()
|
||||||
.map(|detached_file| PackageRoot {
|
.map(|detached_file| PackageRoot {
|
||||||
is_local: true,
|
is_local: true,
|
||||||
include: vec![detached_file.clone()],
|
include: vec![detached_file.clone()],
|
||||||
|
@ -553,7 +553,7 @@ fn cargo_to_crate_graph(
|
||||||
&mut crate_graph,
|
&mut crate_graph,
|
||||||
&cargo[pkg],
|
&cargo[pkg],
|
||||||
build_scripts.outputs.get(pkg),
|
build_scripts.outputs.get(pkg),
|
||||||
&cfg_options,
|
cfg_options,
|
||||||
load_proc_macro,
|
load_proc_macro,
|
||||||
file_id,
|
file_id,
|
||||||
&cargo[tgt].name,
|
&cargo[tgt].name,
|
||||||
|
@ -815,7 +815,7 @@ fn add_target_crate_root(
|
||||||
.map(|feat| CfgFlag::KeyValue { key: "feature".into(), value: feat.0.into() }),
|
.map(|feat| CfgFlag::KeyValue { key: "feature".into(), value: feat.0.into() }),
|
||||||
);
|
);
|
||||||
|
|
||||||
let crate_id = crate_graph.add_crate_root(
|
crate_graph.add_crate_root(
|
||||||
file_id,
|
file_id,
|
||||||
edition,
|
edition,
|
||||||
Some(display_name),
|
Some(display_name),
|
||||||
|
@ -823,9 +823,7 @@ fn add_target_crate_root(
|
||||||
potential_cfg_options,
|
potential_cfg_options,
|
||||||
env,
|
env,
|
||||||
proc_macro,
|
proc_macro,
|
||||||
);
|
)
|
||||||
|
|
||||||
crate_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sysroot_to_crate_graph(
|
fn sysroot_to_crate_graph(
|
||||||
|
@ -893,27 +891,27 @@ fn inject_cargo_env(package: &PackageData, env: &mut Env) {
|
||||||
// CARGO_BIN_NAME, CARGO_BIN_EXE_<name>
|
// CARGO_BIN_NAME, CARGO_BIN_EXE_<name>
|
||||||
|
|
||||||
let manifest_dir = package.manifest.parent();
|
let manifest_dir = package.manifest.parent();
|
||||||
env.set("CARGO_MANIFEST_DIR".into(), manifest_dir.as_os_str().to_string_lossy().into_owned());
|
env.set("CARGO_MANIFEST_DIR", manifest_dir.as_os_str().to_string_lossy().into_owned());
|
||||||
|
|
||||||
// Not always right, but works for common cases.
|
// Not always right, but works for common cases.
|
||||||
env.set("CARGO".into(), "cargo".into());
|
env.set("CARGO", "cargo".into());
|
||||||
|
|
||||||
env.set("CARGO_PKG_VERSION".into(), package.version.to_string());
|
env.set("CARGO_PKG_VERSION", package.version.to_string());
|
||||||
env.set("CARGO_PKG_VERSION_MAJOR".into(), package.version.major.to_string());
|
env.set("CARGO_PKG_VERSION_MAJOR", package.version.major.to_string());
|
||||||
env.set("CARGO_PKG_VERSION_MINOR".into(), package.version.minor.to_string());
|
env.set("CARGO_PKG_VERSION_MINOR", package.version.minor.to_string());
|
||||||
env.set("CARGO_PKG_VERSION_PATCH".into(), package.version.patch.to_string());
|
env.set("CARGO_PKG_VERSION_PATCH", package.version.patch.to_string());
|
||||||
env.set("CARGO_PKG_VERSION_PRE".into(), package.version.pre.to_string());
|
env.set("CARGO_PKG_VERSION_PRE", package.version.pre.to_string());
|
||||||
|
|
||||||
env.set("CARGO_PKG_AUTHORS".into(), String::new());
|
env.set("CARGO_PKG_AUTHORS", String::new());
|
||||||
|
|
||||||
env.set("CARGO_PKG_NAME".into(), package.name.clone());
|
env.set("CARGO_PKG_NAME", package.name.clone());
|
||||||
// FIXME: This isn't really correct (a package can have many crates with different names), but
|
// FIXME: This isn't really correct (a package can have many crates with different names), but
|
||||||
// it's better than leaving the variable unset.
|
// it's better than leaving the variable unset.
|
||||||
env.set("CARGO_CRATE_NAME".into(), CrateName::normalize_dashes(&package.name).to_string());
|
env.set("CARGO_CRATE_NAME", CrateName::normalize_dashes(&package.name).to_string());
|
||||||
env.set("CARGO_PKG_DESCRIPTION".into(), String::new());
|
env.set("CARGO_PKG_DESCRIPTION", String::new());
|
||||||
env.set("CARGO_PKG_HOMEPAGE".into(), String::new());
|
env.set("CARGO_PKG_HOMEPAGE", String::new());
|
||||||
env.set("CARGO_PKG_REPOSITORY".into(), String::new());
|
env.set("CARGO_PKG_REPOSITORY", String::new());
|
||||||
env.set("CARGO_PKG_LICENSE".into(), String::new());
|
env.set("CARGO_PKG_LICENSE", String::new());
|
||||||
|
|
||||||
env.set("CARGO_PKG_LICENSE_FILE".into(), String::new());
|
env.set("CARGO_PKG_LICENSE_FILE", String::new());
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,7 +212,7 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
|
||||||
look_ahead_scratch.push(rhs_ele.clone());
|
look_ahead_scratch.push(rhs_ele.clone());
|
||||||
let mut rhs_children_clone = rhs_children.clone();
|
let mut rhs_children_clone = rhs_children.clone();
|
||||||
let mut insert = false;
|
let mut insert = false;
|
||||||
while let Some(rhs_child) = rhs_children_clone.next() {
|
for rhs_child in &mut rhs_children_clone {
|
||||||
if syntax_element_eq(&lhs_ele, &rhs_child) {
|
if syntax_element_eq(&lhs_ele, &rhs_child) {
|
||||||
cov_mark::hit!(diff_insertions);
|
cov_mark::hit!(diff_insertions);
|
||||||
insert = true;
|
insert = true;
|
||||||
|
|
|
@ -556,7 +556,7 @@ pub fn param(pat: ast::Pat, ty: ast::Type) -> ast::Param {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn self_param() -> ast::SelfParam {
|
pub fn self_param() -> ast::SelfParam {
|
||||||
ast_from_text(&format!("fn f(&self) {{ }}"))
|
ast_from_text("fn f(&self) { }")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ret_type(ty: ast::Type) -> ast::RetType {
|
pub fn ret_type(ty: ast::Type) -> ast::RetType {
|
||||||
|
|
|
@ -346,7 +346,6 @@ impl MiniCore {
|
||||||
panic!("unused minicore flag: {:?}", flag);
|
panic!("unused minicore flag: {:?}", flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
format!("{}", buf);
|
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue