From f4b1fb1554b639374adeffa50d4719f834a0d475 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 14:12:45 +0300 Subject: Reorder --- crates/ra_db/src/input.rs | 74 +++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'crates') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 777e63442..b6d851776 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -80,16 +80,16 @@ pub struct CrateGraph { arena: FxHashMap, } -#[derive(Debug)] -pub struct CyclicDependencies; - #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CrateId(pub u32); -impl CrateId { - pub fn shift(self, amount: u32) -> CrateId { - CrateId(self.0 + amount) - } +#[derive(Debug, Clone, PartialEq, Eq)] +struct CrateData { + file_id: FileId, + edition: Edition, + cfg_options: CfgOptions, + env: Env, + dependencies: Vec, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -103,37 +103,12 @@ pub struct Env { entries: FxHashMap, } -#[derive(Debug, Clone, PartialEq, Eq)] -struct CrateData { - file_id: FileId, - edition: Edition, - dependencies: Vec, - cfg_options: CfgOptions, - env: Env, -} - -impl CrateData { - fn new(file_id: FileId, edition: Edition, cfg_options: CfgOptions, env: Env) -> CrateData { - CrateData { file_id, edition, dependencies: Vec::new(), cfg_options, env } - } - - fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { - self.dependencies.push(Dependency { name, crate_id }) - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub struct Dependency { pub crate_id: CrateId, pub name: SmolStr, } -impl Dependency { - pub fn crate_id(&self) -> CrateId { - self.crate_id - } -} - impl CrateGraph { pub fn add_crate_root( &mut self, @@ -158,9 +133,9 @@ impl CrateGraph { from: CrateId, name: SmolStr, to: CrateId, - ) -> Result<(), CyclicDependencies> { + ) -> Result<(), CyclicDependenciesError> { if self.dfs_find(from, to, &mut FxHashSet::default()) { - return Err(CyclicDependencies); + return Err(CyclicDependenciesError); } self.arena.get_mut(&from).unwrap().add_dep(name, to); Ok(()) @@ -231,9 +206,20 @@ impl CrateGraph { } } -#[derive(Debug)] -pub struct ParseEditionError { - invalid_input: String, +impl CrateId { + pub fn shift(self, amount: u32) -> CrateId { + CrateId(self.0 + amount) + } +} + +impl CrateData { + fn new(file_id: FileId, edition: Edition, cfg_options: CfgOptions, env: Env) -> CrateData { + CrateData { file_id, edition, dependencies: Vec::new(), cfg_options, env } + } + + fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { + self.dependencies.push(Dependency { name, crate_id }) + } } impl FromStr for Edition { @@ -249,6 +235,17 @@ impl FromStr for Edition { } } +impl Dependency { + pub fn crate_id(&self) -> CrateId { + self.crate_id + } +} + +#[derive(Debug)] +pub struct ParseEditionError { + invalid_input: String, +} + impl fmt::Display for ParseEditionError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "invalid edition: {:?}", self.invalid_input) @@ -257,6 +254,9 @@ impl fmt::Display for ParseEditionError { impl std::error::Error for ParseEditionError {} +#[derive(Debug)] +pub struct CyclicDependenciesError; + #[cfg(test)] mod tests { use super::{CfgOptions, CrateGraph, Edition::Edition2018, Env, FileId, SmolStr}; -- cgit v1.2.3