Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 255a8ae

Browse files
committed
Move Edition into span crate
1 parent 8d74705 commit 255a8ae

File tree

21 files changed

+103
-101
lines changed

21 files changed

+103
-101
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/base-db/src/input.rs

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
77
//! actual IO is done and lowered to input.
88
9-
use std::{fmt, mem, ops, str::FromStr};
9+
use std::{fmt, mem, ops};
1010

1111
use cfg::CfgOptions;
1212
use la_arena::{Arena, Idx, RawIdx};
1313
use rustc_hash::{FxHashMap, FxHashSet};
14+
use span::Edition;
1415
use syntax::SmolStr;
1516
use triomphe::Arc;
1617
use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
@@ -293,42 +294,11 @@ pub struct CrateData {
293294
pub is_proc_macro: bool,
294295
}
295296

296-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
297-
pub enum Edition {
298-
Edition2015,
299-
Edition2018,
300-
Edition2021,
301-
Edition2024,
302-
}
303-
304-
impl Edition {
305-
pub const CURRENT: Edition = Edition::Edition2021;
306-
pub const DEFAULT: Edition = Edition::Edition2015;
307-
}
308-
309297
#[derive(Default, Debug, Clone, PartialEq, Eq)]
310298
pub struct Env {
311299
entries: FxHashMap<String, String>,
312300
}
313301

314-
impl Env {
315-
pub fn new_for_test_fixture() -> Self {
316-
Env {
317-
entries: FxHashMap::from_iter([(
318-
String::from("__ra_is_test_fixture"),
319-
String::from("__ra_is_test_fixture"),
320-
)]),
321-
}
322-
}
323-
}
324-
325-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
326-
pub enum DependencyKind {
327-
Normal,
328-
Dev,
329-
Build,
330-
}
331-
332302
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
333303
pub struct Dependency {
334304
pub crate_id: CrateId,
@@ -670,32 +640,6 @@ impl CrateData {
670640
}
671641
}
672642

673-
impl FromStr for Edition {
674-
type Err = ParseEditionError;
675-
676-
fn from_str(s: &str) -> Result<Self, Self::Err> {
677-
let res = match s {
678-
"2015" => Edition::Edition2015,
679-
"2018" => Edition::Edition2018,
680-
"2021" => Edition::Edition2021,
681-
"2024" => Edition::Edition2024,
682-
_ => return Err(ParseEditionError { invalid_input: s.to_owned() }),
683-
};
684-
Ok(res)
685-
}
686-
}
687-
688-
impl fmt::Display for Edition {
689-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
690-
f.write_str(match self {
691-
Edition::Edition2015 => "2015",
692-
Edition::Edition2018 => "2018",
693-
Edition::Edition2021 => "2021",
694-
Edition::Edition2024 => "2024",
695-
})
696-
}
697-
}
698-
699643
impl Extend<(String, String)> for Env {
700644
fn extend<T: IntoIterator<Item = (String, String)>>(&mut self, iter: T) {
701645
self.entries.extend(iter);
@@ -722,19 +666,6 @@ impl Env {
722666
}
723667
}
724668

725-
#[derive(Debug)]
726-
pub struct ParseEditionError {
727-
invalid_input: String,
728-
}
729-
730-
impl fmt::Display for ParseEditionError {
731-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
732-
write!(f, "invalid edition: {:?}", self.invalid_input)
733-
}
734-
}
735-
736-
impl std::error::Error for ParseEditionError {}
737-
738669
#[derive(Debug)]
739670
pub struct CyclicDependenciesError {
740671
path: Vec<(CrateId, Option<CrateDisplayName>)>,

crates/base-db/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use triomphe::Arc;
1414
pub use crate::{
1515
change::FileChange,
1616
input::{
17-
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency,
18-
DependencyKind, Edition, Env, LangCrateOrigin, ProcMacroPaths, ReleaseChannel, SourceRoot,
19-
SourceRootId, TargetLayoutLoadResult,
17+
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Env,
18+
LangCrateOrigin, ProcMacroPaths, ReleaseChannel, SourceRoot, SourceRootId,
19+
TargetLayoutLoadResult,
2020
},
2121
};
2222
pub use salsa::{self, Cancelled};

crates/hir-def/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use std::{
7373
use base_db::{
7474
impl_intern_key,
7575
salsa::{self, impl_intern_value_trivial},
76-
CrateId, Edition,
76+
CrateId,
7777
};
7878
use hir_expand::{
7979
builtin_attr_macro::BuiltinAttrExpander,
@@ -90,7 +90,7 @@ use hir_expand::{
9090
use item_tree::ExternBlock;
9191
use la_arena::Idx;
9292
use nameres::DefMap;
93-
use span::{AstIdNode, FileAstId, FileId, SyntaxContextId};
93+
use span::{AstIdNode, Edition, FileAstId, FileId, SyntaxContextId};
9494
use stdx::impl_from;
9595
use syntax::{ast, AstNode};
9696

crates/hir-def/src/nameres.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ mod tests;
5959

6060
use std::ops::Deref;
6161

62-
use base_db::{CrateId, Edition, FileId};
62+
use base_db::{CrateId, FileId};
6363
use hir_expand::{
6464
name::Name, proc_macro::ProcMacroKind, ErasedAstId, HirFileId, InFile, MacroCallId, MacroDefId,
6565
};
6666
use itertools::Itertools;
6767
use la_arena::Arena;
6868
use rustc_hash::{FxHashMap, FxHashSet};
69-
use span::{FileAstId, ROOT_ERASED_FILE_AST_ID};
69+
use span::{Edition, FileAstId, ROOT_ERASED_FILE_AST_ID};
7070
use stdx::format_to;
7171
use syntax::{ast, SmolStr};
7272
use triomphe::Arc;

crates/hir-def/src/nameres/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use std::{cmp::Ordering, iter, mem, ops::Not};
77

8-
use base_db::{CrateId, Dependency, Edition, FileId};
8+
use base_db::{CrateId, Dependency, FileId};
99
use cfg::{CfgExpr, CfgOptions};
1010
use either::Either;
1111
use hir_expand::{
@@ -22,7 +22,7 @@ use itertools::{izip, Itertools};
2222
use la_arena::Idx;
2323
use limit::Limit;
2424
use rustc_hash::{FxHashMap, FxHashSet};
25-
use span::{ErasedFileAstId, FileAstId, Span, SyntaxContextId};
25+
use span::{Edition, ErasedFileAstId, FileAstId, Span, SyntaxContextId};
2626
use stdx::always;
2727
use syntax::{ast, SmolStr};
2828
use triomphe::Arc;

crates/hir-def/src/nameres/path_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//!
1111
//! `ReachedFixedPoint` signals about this.
1212
13-
use base_db::Edition;
1413
use hir_expand::{name::Name, Lookup};
14+
use span::Edition;
1515
use triomphe::Arc;
1616

1717
use crate::{

crates/hir-expand/src/builtin_fn_macro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Builtin macro
22
3-
use base_db::{AnchoredPath, Edition, FileId};
3+
use base_db::{AnchoredPath, FileId};
44
use cfg::CfgExpr;
55
use either::Either;
66
use itertools::Itertools;
77
use mbe::{parse_exprs_with_sep, parse_to_token_tree};
8-
use span::{Span, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID};
8+
use span::{Edition, Span, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID};
99
use syntax::ast::{self, AstToken};
1010

1111
use crate::{

crates/hir-expand/src/declarative.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Compiled declarative macro expanders (`macro_rules!`` and `macro`)
22
use std::sync::OnceLock;
33

4-
use base_db::{CrateId, Edition, VersionReq};
5-
use span::{MacroCallId, Span};
4+
use base_db::{CrateId, VersionReq};
5+
use span::{Edition, MacroCallId, Span};
66
use syntax::{ast, AstNode};
77
use triomphe::Arc;
88

crates/hir-expand/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ use triomphe::Arc;
3030

3131
use std::{fmt, hash::Hash};
3232

33-
use base_db::{salsa::impl_intern_value_trivial, CrateId, Edition, FileId};
33+
use base_db::{salsa::impl_intern_value_trivial, CrateId, FileId};
3434
use either::Either;
3535
use span::{
36-
ErasedFileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor, SyntaxContextData, SyntaxContextId,
36+
Edition, ErasedFileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor, SyntaxContextData,
37+
SyntaxContextId,
3738
};
3839
use syntax::{
3940
ast::{self, AstNode},

crates/hir-ty/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ hir-expand.workspace = true
4747
base-db.workspace = true
4848
syntax.workspace = true
4949
limit.workspace = true
50+
span.workspace = true
5051

5152
[dev-dependencies]
5253
expect-test = "1.4.0"

crates/hir-ty/src/method_resolution.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! and the corresponding code mostly in rustc_hir_analysis/check/method/probe.rs.
55
use std::ops::ControlFlow;
66

7-
use base_db::{CrateId, Edition};
7+
use base_db::CrateId;
88
use chalk_ir::{cast::Cast, Mutability, TyKind, UniverseIndex, WhereClause};
99
use hir_def::{
1010
data::{adt::StructFlags, ImplData},
@@ -15,6 +15,7 @@ use hir_def::{
1515
use hir_expand::name::Name;
1616
use rustc_hash::{FxHashMap, FxHashSet};
1717
use smallvec::{smallvec, SmallVec};
18+
use span::Edition;
1819
use stdx::never;
1920
use triomphe::Arc;
2021

crates/hir/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod display;
3838
use std::{iter, mem::discriminant, ops::ControlFlow};
3939

4040
use arrayvec::ArrayVec;
41-
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId};
41+
use base_db::{CrateDisplayName, CrateId, CrateOrigin, FileId};
4242
use either::Either;
4343
use hir_def::{
4444
body::{BodyDiagnostic, SyntheticSyntax},
@@ -79,6 +79,7 @@ use hir_ty::{
7979
use itertools::Itertools;
8080
use nameres::diagnostics::DefDiagnosticKind;
8181
use rustc_hash::FxHashSet;
82+
use span::Edition;
8283
use stdx::{impl_from, never};
8384
use syntax::{
8485
ast::{self, HasAttrs as _, HasName},

crates/ide/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ide-ssr.workspace = true
3636
profile.workspace = true
3737
stdx.workspace = true
3838
syntax.workspace = true
39+
span.workspace = true
3940
text-edit.workspace = true
4041
# ide should depend only on the top-level `hir` package. if you need
4142
# something from some `hir-xxx` subpackage, reexport the API via `hir`.

crates/ide/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ pub use ide_completion::{
119119
};
120120
pub use ide_db::{
121121
base_db::{
122-
Cancelled, CrateGraph, CrateId, Edition, FileChange, FileId, FilePosition, FileRange,
123-
SourceRoot, SourceRootId,
122+
Cancelled, CrateGraph, CrateId, FileChange, FileId, FilePosition, FileRange, SourceRoot,
123+
SourceRootId,
124124
},
125125
documentation::Documentation,
126126
label::Label,
@@ -135,6 +135,7 @@ pub use ide_diagnostics::{
135135
Diagnostic, DiagnosticCode, DiagnosticsConfig, ExprFillDefaultMode, Severity,
136136
};
137137
pub use ide_ssr::SsrError;
138+
pub use span::Edition;
138139
pub use syntax::{TextRange, TextSize};
139140
pub use text_edit::{Indel, TextEdit};
140141

crates/project-model/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ itertools.workspace = true
2525

2626
# local deps
2727
base-db.workspace = true
28+
span.workspace = true
2829
cfg.workspace = true
2930
paths = { workspace = true, features = ["serde1"] }
3031
stdx.workspace = true

crates/project-model/src/cargo_workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use std::ops;
44
use std::str::from_utf8;
55

66
use anyhow::Context;
7-
use base_db::Edition;
87
use cargo_metadata::{CargoOpt, MetadataCommand};
98
use la_arena::{Arena, Idx};
109
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
1110
use rustc_hash::{FxHashMap, FxHashSet};
1211
use serde::Deserialize;
1312
use serde_json::from_value;
13+
use span::Edition;
1414
use toolchain::Tool;
1515

1616
use crate::{utf8_stdout, InvocationLocation, ManifestPath, Sysroot};

crates/project-model/src/project_json.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@
4949
//! user explores them belongs to that extension (it's totally valid to change
5050
//! rust-project.json over time via configuration request!)
5151
52-
use base_db::{CrateDisplayName, CrateId, CrateName, Dependency, Edition};
52+
use base_db::{CrateDisplayName, CrateId, CrateName, Dependency};
5353
use la_arena::RawIdx;
5454
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
5555
use rustc_hash::FxHashMap;
5656
use serde::{de, Deserialize};
57+
use span::Edition;
5758

5859
use crate::cfg_flag::CfgFlag;
5960

crates/project-model/src/workspace.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ use std::{collections::VecDeque, fmt, fs, iter, str::FromStr, sync};
66

77
use anyhow::{format_err, Context};
88
use base_db::{
9-
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
10-
FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
9+
CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Env, FileId,
10+
LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
1111
};
1212
use cfg::{CfgAtom, CfgDiff, CfgOptions};
1313
use paths::{AbsPath, AbsPathBuf};
1414
use rustc_hash::{FxHashMap, FxHashSet};
1515
use semver::Version;
16+
use span::Edition;
1617
use stdx::always;
1718
use toolchain::Tool;
1819
use triomphe::Arc;

0 commit comments

Comments
 (0)