mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 14:51:48 +00:00
Reorder
This commit is contained in:
parent
0861ac061e
commit
f4b1fb1554
1 changed files with 37 additions and 37 deletions
|
@ -80,16 +80,16 @@ pub struct CrateGraph {
|
||||||
arena: FxHashMap<CrateId, CrateData>,
|
arena: FxHashMap<CrateId, CrateData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct CyclicDependencies;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct CrateId(pub u32);
|
pub struct CrateId(pub u32);
|
||||||
|
|
||||||
impl CrateId {
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub fn shift(self, amount: u32) -> CrateId {
|
struct CrateData {
|
||||||
CrateId(self.0 + amount)
|
file_id: FileId,
|
||||||
}
|
edition: Edition,
|
||||||
|
cfg_options: CfgOptions,
|
||||||
|
env: Env,
|
||||||
|
dependencies: Vec<Dependency>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
@ -103,37 +103,12 @@ pub struct Env {
|
||||||
entries: FxHashMap<String, String>,
|
entries: FxHashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
struct CrateData {
|
|
||||||
file_id: FileId,
|
|
||||||
edition: Edition,
|
|
||||||
dependencies: Vec<Dependency>,
|
|
||||||
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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Dependency {
|
pub struct Dependency {
|
||||||
pub crate_id: CrateId,
|
pub crate_id: CrateId,
|
||||||
pub name: SmolStr,
|
pub name: SmolStr,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dependency {
|
|
||||||
pub fn crate_id(&self) -> CrateId {
|
|
||||||
self.crate_id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CrateGraph {
|
impl CrateGraph {
|
||||||
pub fn add_crate_root(
|
pub fn add_crate_root(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -158,9 +133,9 @@ impl CrateGraph {
|
||||||
from: CrateId,
|
from: CrateId,
|
||||||
name: SmolStr,
|
name: SmolStr,
|
||||||
to: CrateId,
|
to: CrateId,
|
||||||
) -> Result<(), CyclicDependencies> {
|
) -> Result<(), CyclicDependenciesError> {
|
||||||
if self.dfs_find(from, to, &mut FxHashSet::default()) {
|
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);
|
self.arena.get_mut(&from).unwrap().add_dep(name, to);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -231,9 +206,20 @@ impl CrateGraph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
impl CrateId {
|
||||||
pub struct ParseEditionError {
|
pub fn shift(self, amount: u32) -> CrateId {
|
||||||
invalid_input: String,
|
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 {
|
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 {
|
impl fmt::Display for ParseEditionError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "invalid edition: {:?}", self.invalid_input)
|
write!(f, "invalid edition: {:?}", self.invalid_input)
|
||||||
|
@ -257,6 +254,9 @@ impl fmt::Display for ParseEditionError {
|
||||||
|
|
||||||
impl std::error::Error for ParseEditionError {}
|
impl std::error::Error for ParseEditionError {}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct CyclicDependenciesError;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{CfgOptions, CrateGraph, Edition::Edition2018, Env, FileId, SmolStr};
|
use super::{CfgOptions, CrateGraph, Edition::Edition2018, Env, FileId, SmolStr};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue