Skip to content

Commit

Permalink
Auto merge of rust-lang#13439 - Veykril:simplify, r=Veykril
Browse files Browse the repository at this point in the history
Simplify
  • Loading branch information
bors committed Oct 19, 2022
2 parents 97b357e + 9d3e616 commit 3392573
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
4 changes: 3 additions & 1 deletion crates/project-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ semver = "1.0.14"
serde = { version = "1.0.137", features = ["derive"] }
serde_json = "1.0.86"
anyhow = "1.0.62"
expect-test = "1.4.0"
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }

cfg = { path = "../cfg", version = "0.0.0" }
Expand All @@ -26,3 +25,6 @@ toolchain = { path = "../toolchain", version = "0.0.0" }
paths = { path = "../paths", version = "0.0.0" }
stdx = { path = "../stdx", version = "0.0.0" }
profile = { path = "../profile", version = "0.0.0" }

[dev-dependencies]
expect-test = "1.4.0"
46 changes: 24 additions & 22 deletions crates/project-model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ impl CargoWorkspace {
}
CargoFeatures::Selected { features, no_default_features } => {
if *no_default_features {
// FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
// https://github.com/oli-obk/cargo_metadata/issues/79
meta.features(CargoOpt::NoDefaultFeatures);
}
if !features.is_empty() {
Expand Down Expand Up @@ -329,18 +327,21 @@ impl CargoWorkspace {
let ws_members = &meta.workspace_members;

meta.packages.sort_by(|a, b| a.id.cmp(&b.id));
for meta_pkg in &meta.packages {
for meta_pkg in meta.packages {
let cargo_metadata::Package {
id,
edition,
name,
manifest_path,
version,
metadata,
id,
source,
targets: meta_targets,
features,
manifest_path,
repository,
edition,
metadata,
..
} = meta_pkg;
let meta = from_value::<PackageMetadata>(metadata.clone()).unwrap_or_default();
let meta = from_value::<PackageMetadata>(metadata).unwrap_or_default();
let edition = match edition {
cargo_metadata::Edition::E2015 => Edition::Edition2015,
cargo_metadata::Edition::E2018 => Edition::Edition2018,
Expand All @@ -352,35 +353,36 @@ impl CargoWorkspace {
};
// We treat packages without source as "local" packages. That includes all members of
// the current workspace, as well as any path dependency outside the workspace.
let is_local = meta_pkg.source.is_none();
let is_member = ws_members.contains(id);
let is_local = source.is_none();
let is_member = ws_members.contains(&id);

let pkg = packages.alloc(PackageData {
id: id.repr.clone(),
name: name.clone(),
version: version.clone(),
manifest: AbsPathBuf::assert(PathBuf::from(&manifest_path)).try_into().unwrap(),
name,
version,
manifest: AbsPathBuf::assert(manifest_path.into()).try_into().unwrap(),
targets: Vec::new(),
is_local,
is_member,
edition,
repository: repository.clone(),
repository,
dependencies: Vec::new(),
features: meta_pkg.features.clone().into_iter().collect(),
features: features.into_iter().collect(),
active_features: Vec::new(),
metadata: meta.rust_analyzer.unwrap_or_default(),
});
let pkg_data = &mut packages[pkg];
pkg_by_id.insert(id, pkg);
for meta_tgt in &meta_pkg.targets {
let is_proc_macro = meta_tgt.kind.as_slice() == ["proc-macro"];
for meta_tgt in meta_targets {
let cargo_metadata::Target { name, kind, required_features, src_path, .. } =
meta_tgt;
let tgt = targets.alloc(TargetData {
package: pkg,
name: meta_tgt.name.clone(),
root: AbsPathBuf::assert(PathBuf::from(&meta_tgt.src_path)),
kind: TargetKind::new(meta_tgt.kind.as_slice()),
is_proc_macro,
required_features: meta_tgt.required_features.clone(),
name,
root: AbsPathBuf::assert(src_path.into()),
kind: TargetKind::new(&kind),
is_proc_macro: &*kind == ["proc-macro"],
required_features,
});
pkg_data.targets.push(tgt);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/project-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl ProjectManifest {
if path.file_name().unwrap_or_default() == "Cargo.toml" {
return Ok(ProjectManifest::CargoToml(path));
}
bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display())
bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display());
}

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

if !candidates.is_empty() {
bail!("more than one project")
bail!("more than one project");
}
Ok(res)
}
Expand Down
1 change: 1 addition & 0 deletions crates/project-model/src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ fn discover_sysroot_src_dir(sysroot_path: &AbsPathBuf) -> Option<AbsPathBuf> {

get_rust_src(sysroot_path)
}

fn discover_sysroot_src_dir_or_add_component(
sysroot_path: &AbsPathBuf,
current_dir: &AbsPath,
Expand Down
5 changes: 2 additions & 3 deletions crates/syntax/src/ast/edit_in_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ impl ast::RecordPatFieldList {
}

fn get_or_insert_comma_after(syntax: &SyntaxNode) -> SyntaxToken {
let comma = match syntax
match syntax
.siblings_with_tokens(Direction::Next)
.filter_map(|it| it.into_token())
.find(|it| it.kind() == T![,])
Expand All @@ -656,8 +656,7 @@ fn get_or_insert_comma_after(syntax: &SyntaxNode) -> SyntaxToken {
ted::insert(Position::after(syntax), &comma);
comma
}
};
comma
}
}

impl ast::StmtList {
Expand Down
2 changes: 1 addition & 1 deletion crates/syntax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<T> Parse<T> {
SyntaxNode::new_root(self.green.clone())
}
pub fn errors(&self) -> &[SyntaxError] {
&*self.errors
&self.errors
}
}

Expand Down

0 comments on commit 3392573

Please sign in to comment.