This commit is contained in:
Lukas Wirth 2021-09-19 19:00:06 +02:00
parent b02027d4fe
commit 3987bf5d6f
6 changed files with 26 additions and 30 deletions

View File

@ -106,7 +106,7 @@ impl CargoConfig {
UnsetTestCrates::Only(unset_test_crates) => CfgOverrides::Selective(
unset_test_crates
.iter()
.map(|name| name.clone())
.cloned()
.zip(iter::repeat_with(|| {
cfg::CfgDiff::new(Vec::new(), vec![cfg::CfgAtom::Flag("test".into())])
.unwrap()

View File

@ -47,13 +47,12 @@ fn get_test_json_file<T: DeserializeOwned>(file: &str) -> T {
fixup_paths(&mut json);
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 {
serde_json::Value::String(s) => replace_root(s, true),
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::Null | serde_json::Value::Bool(_) | serde_json::Value::Number(_) => {
()
}
}
}

View File

@ -189,7 +189,7 @@ impl ProjectWorkspace {
Some(rustc_dir) => Some({
let meta = CargoWorkspace::fetch_metadata(&rustc_dir, config, progress)
.with_context(|| {
format!("Failed to read Cargo metadata for Rust sources")
"Failed to read Cargo metadata for Rust sources".to_string()
})?;
CargoWorkspace::new(meta)
}),
@ -328,12 +328,12 @@ impl ProjectWorkspace {
}
PackageRoot { is_local, include, exclude }
})
.chain(sysroot.into_iter().map(|sysroot| PackageRoot {
.chain(sysroot.iter().map(|sysroot| PackageRoot {
is_local: false,
include: vec![sysroot.root().to_path_buf()],
exclude: Vec::new(),
}))
.chain(rustc.into_iter().flat_map(|rustc| {
.chain(rustc.iter().flat_map(|rustc| {
rustc.packages().map(move |krate| PackageRoot {
is_local: false,
include: vec![rustc[krate].manifest.parent().to_path_buf()],
@ -343,7 +343,7 @@ impl ProjectWorkspace {
.collect()
}
ProjectWorkspace::DetachedFiles { files, sysroot, .. } => files
.into_iter()
.iter()
.map(|detached_file| PackageRoot {
is_local: true,
include: vec![detached_file.clone()],
@ -553,7 +553,7 @@ fn cargo_to_crate_graph(
&mut crate_graph,
&cargo[pkg],
build_scripts.outputs.get(pkg),
&cfg_options,
cfg_options,
load_proc_macro,
file_id,
&cargo[tgt].name,
@ -815,7 +815,7 @@ fn add_target_crate_root(
.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,
edition,
Some(display_name),
@ -823,9 +823,7 @@ fn add_target_crate_root(
potential_cfg_options,
env,
proc_macro,
);
crate_id
)
}
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>
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.
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_MAJOR".into(), package.version.major.to_string());
env.set("CARGO_PKG_VERSION_MINOR".into(), package.version.minor.to_string());
env.set("CARGO_PKG_VERSION_PATCH".into(), package.version.patch.to_string());
env.set("CARGO_PKG_VERSION_PRE".into(), package.version.pre.to_string());
env.set("CARGO_PKG_VERSION", package.version.to_string());
env.set("CARGO_PKG_VERSION_MAJOR", package.version.major.to_string());
env.set("CARGO_PKG_VERSION_MINOR", package.version.minor.to_string());
env.set("CARGO_PKG_VERSION_PATCH", package.version.patch.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
// it's better than leaving the variable unset.
env.set("CARGO_CRATE_NAME".into(), CrateName::normalize_dashes(&package.name).to_string());
env.set("CARGO_PKG_DESCRIPTION".into(), String::new());
env.set("CARGO_PKG_HOMEPAGE".into(), String::new());
env.set("CARGO_PKG_REPOSITORY".into(), String::new());
env.set("CARGO_PKG_LICENSE".into(), String::new());
env.set("CARGO_CRATE_NAME", CrateName::normalize_dashes(&package.name).to_string());
env.set("CARGO_PKG_DESCRIPTION", String::new());
env.set("CARGO_PKG_HOMEPAGE", String::new());
env.set("CARGO_PKG_REPOSITORY", 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());
}

View File

@ -212,7 +212,7 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
look_ahead_scratch.push(rhs_ele.clone());
let mut rhs_children_clone = rhs_children.clone();
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) {
cov_mark::hit!(diff_insertions);
insert = true;

View File

@ -556,7 +556,7 @@ pub fn param(pat: ast::Pat, ty: ast::Type) -> ast::Param {
}
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 {

View File

@ -346,7 +346,6 @@ impl MiniCore {
panic!("unused minicore flag: {:?}", flag);
}
}
format!("{}", buf);
buf
}
}