mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Keep track of crate edition
This commit is contained in:
parent
1526eb25c9
commit
3a9934e2c3
8 changed files with 44 additions and 24 deletions
|
@ -56,15 +56,22 @@ pub struct CyclicDependencies;
|
|||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct CrateId(pub u32);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Edition {
|
||||
Edition2018,
|
||||
Edition2015,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
struct CrateData {
|
||||
file_id: FileId,
|
||||
edition: Edition,
|
||||
dependencies: Vec<Dependency>,
|
||||
}
|
||||
|
||||
impl CrateData {
|
||||
fn new(file_id: FileId) -> CrateData {
|
||||
CrateData { file_id, dependencies: Vec::new() }
|
||||
fn new(file_id: FileId, edition: Edition) -> CrateData {
|
||||
CrateData { file_id, edition, dependencies: Vec::new() }
|
||||
}
|
||||
|
||||
fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) {
|
||||
|
@ -85,9 +92,9 @@ impl Dependency {
|
|||
}
|
||||
|
||||
impl CrateGraph {
|
||||
pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId {
|
||||
pub fn add_crate_root(&mut self, file_id: FileId, edition: Edition) -> CrateId {
|
||||
let crate_id = CrateId(self.arena.len() as u32);
|
||||
let prev = self.arena.insert(crate_id, CrateData::new(file_id));
|
||||
let prev = self.arena.insert(crate_id, CrateData::new(file_id, edition));
|
||||
assert!(prev.is_none());
|
||||
crate_id
|
||||
}
|
||||
|
@ -159,14 +166,14 @@ impl CrateGraph {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{CrateGraph, FileId, SmolStr};
|
||||
use super::{CrateGraph, FileId, SmolStr, Edition::Edition2018};
|
||||
|
||||
#[test]
|
||||
fn it_should_painc_because_of_cycle_dependencies() {
|
||||
fn it_should_panic_because_of_cycle_dependencies() {
|
||||
let mut graph = CrateGraph::default();
|
||||
let crate1 = graph.add_crate_root(FileId(1u32));
|
||||
let crate2 = graph.add_crate_root(FileId(2u32));
|
||||
let crate3 = graph.add_crate_root(FileId(3u32));
|
||||
let crate1 = graph.add_crate_root(FileId(1u32), Edition2018);
|
||||
let crate2 = graph.add_crate_root(FileId(2u32), Edition2018);
|
||||
let crate3 = graph.add_crate_root(FileId(3u32), Edition2018);
|
||||
assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok());
|
||||
assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok());
|
||||
assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err());
|
||||
|
@ -175,9 +182,9 @@ mod tests {
|
|||
#[test]
|
||||
fn it_works() {
|
||||
let mut graph = CrateGraph::default();
|
||||
let crate1 = graph.add_crate_root(FileId(1u32));
|
||||
let crate2 = graph.add_crate_root(FileId(2u32));
|
||||
let crate3 = graph.add_crate_root(FileId(3u32));
|
||||
let crate1 = graph.add_crate_root(FileId(1u32), Edition2018);
|
||||
let crate2 = graph.add_crate_root(FileId(2u32), Edition2018);
|
||||
let crate3 = graph.add_crate_root(FileId(3u32), Edition2018);
|
||||
assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok());
|
||||
assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok());
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ pub use ::salsa as salsa;
|
|||
pub use crate::{
|
||||
cancellation::Canceled,
|
||||
input::{
|
||||
FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency,
|
||||
FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, Edition,
|
||||
},
|
||||
loc2id::LocationIntener,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue