mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Implement FromStr for enum Edition
This commit is contained in:
parent
f5e1b0f97c
commit
b69738590c
3 changed files with 14 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ra_cfg::CfgOptions;
|
use ra_cfg::CfgOptions;
|
||||||
|
@ -164,7 +165,7 @@ fn parse_meta(meta: &str) -> ParsedMeta {
|
||||||
match key {
|
match key {
|
||||||
"crate" => krate = Some(value.to_string()),
|
"crate" => krate = Some(value.to_string()),
|
||||||
"deps" => deps = value.split(',').map(|it| it.to_string()).collect(),
|
"deps" => deps = value.split(',').map(|it| it.to_string()).collect(),
|
||||||
"edition" => edition = Edition::from_string(&value),
|
"edition" => edition = Edition::from_str(&value).unwrap(),
|
||||||
"cfg" => {
|
"cfg" => {
|
||||||
for key in value.split(',') {
|
for key in value.split(',') {
|
||||||
match split1(key, '=') {
|
match split1(key, '=') {
|
||||||
|
|
|
@ -13,6 +13,7 @@ use ra_syntax::SmolStr;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use crate::{RelativePath, RelativePathBuf};
|
use crate::{RelativePath, RelativePathBuf};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
/// `FileId` is an integer which uniquely identifies a file. File paths are
|
/// `FileId` is an integer which uniquely identifies a file. File paths are
|
||||||
/// messy and system-dependent, so most of the code should work directly with
|
/// messy and system-dependent, so most of the code should work directly with
|
||||||
|
@ -97,12 +98,13 @@ pub enum Edition {
|
||||||
Edition2015,
|
Edition2015,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Edition {
|
impl FromStr for Edition {
|
||||||
//FIXME: replace with FromStr with proper error handling
|
type Err = String;
|
||||||
pub fn from_string(s: &str) -> Edition {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
match s {
|
match s {
|
||||||
"2015" => Edition::Edition2015,
|
"2015" => Ok(Edition::Edition2015),
|
||||||
"2018" | _ => Edition::Edition2018,
|
"2018" => Ok(Edition::Edition2018),
|
||||||
|
_ => Err(format! {"unknown edition: {}" , s}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use cargo_metadata::{CargoOpt, MetadataCommand};
|
use cargo_metadata::{CargoOpt, MetadataCommand};
|
||||||
use ra_arena::{impl_arena_id, Arena, RawId};
|
use ra_arena::{impl_arena_id, Arena, RawId};
|
||||||
|
@ -141,12 +142,14 @@ impl CargoWorkspace {
|
||||||
|
|
||||||
for meta_pkg in meta.packages {
|
for meta_pkg in meta.packages {
|
||||||
let is_member = ws_members.contains(&meta_pkg.id);
|
let is_member = ws_members.contains(&meta_pkg.id);
|
||||||
|
let name = meta_pkg.name;
|
||||||
let pkg = packages.alloc(PackageData {
|
let pkg = packages.alloc(PackageData {
|
||||||
name: meta_pkg.name,
|
name: name.clone(),
|
||||||
manifest: meta_pkg.manifest_path.clone(),
|
manifest: meta_pkg.manifest_path.clone(),
|
||||||
targets: Vec::new(),
|
targets: Vec::new(),
|
||||||
is_member,
|
is_member,
|
||||||
edition: Edition::from_string(&meta_pkg.edition),
|
edition: Edition::from_str(&meta_pkg.edition)
|
||||||
|
.unwrap_or_else(|e| panic!("unknown edition {} for package {:?}", e, &name)),
|
||||||
dependencies: Vec::new(),
|
dependencies: Vec::new(),
|
||||||
features: Vec::new(),
|
features: Vec::new(),
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue