Skip to content

Commit 3392573

Browse files
committed
Auto merge of rust-lang#13439 - Veykril:simplify, r=Veykril
Simplify
2 parents 97b357e + 9d3e616 commit 3392573

File tree

6 files changed

+33
-29
lines changed

6 files changed

+33
-29
lines changed

crates/project-model/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ semver = "1.0.14"
1717
serde = { version = "1.0.137", features = ["derive"] }
1818
serde_json = "1.0.86"
1919
anyhow = "1.0.62"
20-
expect-test = "1.4.0"
2120
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
2221

2322
cfg = { path = "../cfg", version = "0.0.0" }
@@ -26,3 +25,6 @@ toolchain = { path = "../toolchain", version = "0.0.0" }
2625
paths = { path = "../paths", version = "0.0.0" }
2726
stdx = { path = "../stdx", version = "0.0.0" }
2827
profile = { path = "../profile", version = "0.0.0" }
28+
29+
[dev-dependencies]
30+
expect-test = "1.4.0"

crates/project-model/src/cargo_workspace.rs

+24-22
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ impl CargoWorkspace {
283283
}
284284
CargoFeatures::Selected { features, no_default_features } => {
285285
if *no_default_features {
286-
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
287-
// https://github.com/oli-obk/cargo_metadata/issues/79
288286
meta.features(CargoOpt::NoDefaultFeatures);
289287
}
290288
if !features.is_empty() {
@@ -329,18 +327,21 @@ impl CargoWorkspace {
329327
let ws_members = &meta.workspace_members;
330328

331329
meta.packages.sort_by(|a, b| a.id.cmp(&b.id));
332-
for meta_pkg in &meta.packages {
330+
for meta_pkg in meta.packages {
333331
let cargo_metadata::Package {
334-
id,
335-
edition,
336332
name,
337-
manifest_path,
338333
version,
339-
metadata,
334+
id,
335+
source,
336+
targets: meta_targets,
337+
features,
338+
manifest_path,
340339
repository,
340+
edition,
341+
metadata,
341342
..
342343
} = meta_pkg;
343-
let meta = from_value::<PackageMetadata>(metadata.clone()).unwrap_or_default();
344+
let meta = from_value::<PackageMetadata>(metadata).unwrap_or_default();
344345
let edition = match edition {
345346
cargo_metadata::Edition::E2015 => Edition::Edition2015,
346347
cargo_metadata::Edition::E2018 => Edition::Edition2018,
@@ -352,35 +353,36 @@ impl CargoWorkspace {
352353
};
353354
// We treat packages without source as "local" packages. That includes all members of
354355
// the current workspace, as well as any path dependency outside the workspace.
355-
let is_local = meta_pkg.source.is_none();
356-
let is_member = ws_members.contains(id);
356+
let is_local = source.is_none();
357+
let is_member = ws_members.contains(&id);
357358

358359
let pkg = packages.alloc(PackageData {
359360
id: id.repr.clone(),
360-
name: name.clone(),
361-
version: version.clone(),
362-
manifest: AbsPathBuf::assert(PathBuf::from(&manifest_path)).try_into().unwrap(),
361+
name,
362+
version,
363+
manifest: AbsPathBuf::assert(manifest_path.into()).try_into().unwrap(),
363364
targets: Vec::new(),
364365
is_local,
365366
is_member,
366367
edition,
367-
repository: repository.clone(),
368+
repository,
368369
dependencies: Vec::new(),
369-
features: meta_pkg.features.clone().into_iter().collect(),
370+
features: features.into_iter().collect(),
370371
active_features: Vec::new(),
371372
metadata: meta.rust_analyzer.unwrap_or_default(),
372373
});
373374
let pkg_data = &mut packages[pkg];
374375
pkg_by_id.insert(id, pkg);
375-
for meta_tgt in &meta_pkg.targets {
376-
let is_proc_macro = meta_tgt.kind.as_slice() == ["proc-macro"];
376+
for meta_tgt in meta_targets {
377+
let cargo_metadata::Target { name, kind, required_features, src_path, .. } =
378+
meta_tgt;
377379
let tgt = targets.alloc(TargetData {
378380
package: pkg,
379-
name: meta_tgt.name.clone(),
380-
root: AbsPathBuf::assert(PathBuf::from(&meta_tgt.src_path)),
381-
kind: TargetKind::new(meta_tgt.kind.as_slice()),
382-
is_proc_macro,
383-
required_features: meta_tgt.required_features.clone(),
381+
name,
382+
root: AbsPathBuf::assert(src_path.into()),
383+
kind: TargetKind::new(&kind),
384+
is_proc_macro: &*kind == ["proc-macro"],
385+
required_features,
384386
});
385387
pkg_data.targets.push(tgt);
386388
}

crates/project-model/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl ProjectManifest {
6767
if path.file_name().unwrap_or_default() == "Cargo.toml" {
6868
return Ok(ProjectManifest::CargoToml(path));
6969
}
70-
bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display())
70+
bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display());
7171
}
7272

7373
pub fn discover_single(path: &AbsPath) -> Result<ProjectManifest> {
@@ -78,7 +78,7 @@ impl ProjectManifest {
7878
};
7979

8080
if !candidates.is_empty() {
81-
bail!("more than one project")
81+
bail!("more than one project");
8282
}
8383
Ok(res)
8484
}

crates/project-model/src/sysroot.rs

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ fn discover_sysroot_src_dir(sysroot_path: &AbsPathBuf) -> Option<AbsPathBuf> {
189189

190190
get_rust_src(sysroot_path)
191191
}
192+
192193
fn discover_sysroot_src_dir_or_add_component(
193194
sysroot_path: &AbsPathBuf,
194195
current_dir: &AbsPath,

crates/syntax/src/ast/edit_in_place.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl ast::RecordPatFieldList {
645645
}
646646

647647
fn get_or_insert_comma_after(syntax: &SyntaxNode) -> SyntaxToken {
648-
let comma = match syntax
648+
match syntax
649649
.siblings_with_tokens(Direction::Next)
650650
.filter_map(|it| it.into_token())
651651
.find(|it| it.kind() == T![,])
@@ -656,8 +656,7 @@ fn get_or_insert_comma_after(syntax: &SyntaxNode) -> SyntaxToken {
656656
ted::insert(Position::after(syntax), &comma);
657657
comma
658658
}
659-
};
660-
comma
659+
}
661660
}
662661

663662
impl ast::StmtList {

crates/syntax/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<T> Parse<T> {
9292
SyntaxNode::new_root(self.green.clone())
9393
}
9494
pub fn errors(&self) -> &[SyntaxError] {
95-
&*self.errors
95+
&self.errors
9696
}
9797
}
9898

0 commit comments

Comments
 (0)