Unnamed repository; edit this file 'description' to name the repository.
Move Edition into span crate
Lukas Wirth 2024-03-21
parent 8d74705 · commit 255a8ae
-rw-r--r--Cargo.lock3
-rw-r--r--crates/base-db/src/input.rs73
-rw-r--r--crates/base-db/src/lib.rs6
-rw-r--r--crates/hir-def/src/lib.rs4
-rw-r--r--crates/hir-def/src/nameres.rs4
-rw-r--r--crates/hir-def/src/nameres/collector.rs4
-rw-r--r--crates/hir-def/src/nameres/path_resolution.rs2
-rw-r--r--crates/hir-expand/src/builtin_fn_macro.rs4
-rw-r--r--crates/hir-expand/src/declarative.rs4
-rw-r--r--crates/hir-expand/src/lib.rs5
-rw-r--r--crates/hir-ty/Cargo.toml1
-rw-r--r--crates/hir-ty/src/method_resolution.rs3
-rw-r--r--crates/hir/src/lib.rs3
-rw-r--r--crates/ide/Cargo.toml1
-rw-r--r--crates/ide/src/lib.rs5
-rw-r--r--crates/project-model/Cargo.toml1
-rw-r--r--crates/project-model/src/cargo_workspace.rs2
-rw-r--r--crates/project-model/src/project_json.rs3
-rw-r--r--crates/project-model/src/workspace.rs5
-rw-r--r--crates/span/src/lib.rs50
-rw-r--r--crates/test-fixture/src/lib.rs21
21 files changed, 103 insertions, 101 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 733e119b04..7ab4e24f08 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -594,6 +594,7 @@ dependencies = [
"rustc-hash",
"scoped-tls",
"smallvec",
+ "span",
"stdx",
"syntax",
"test-fixture",
@@ -637,6 +638,7 @@ dependencies = [
"pulldown-cmark",
"pulldown-cmark-to-cmark",
"smallvec",
+ "span",
"stdx",
"syntax",
"test-fixture",
@@ -1380,6 +1382,7 @@ dependencies = [
"semver",
"serde",
"serde_json",
+ "span",
"stdx",
"toolchain",
"tracing",
diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs
index b243b37b77..f59c4e5016 100644
--- a/crates/base-db/src/input.rs
+++ b/crates/base-db/src/input.rs
@@ -6,11 +6,12 @@
//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
//! actual IO is done and lowered to input.
-use std::{fmt, mem, ops, str::FromStr};
+use std::{fmt, mem, ops};
use cfg::CfgOptions;
use la_arena::{Arena, Idx, RawIdx};
use rustc_hash::{FxHashMap, FxHashSet};
+use span::Edition;
use syntax::SmolStr;
use triomphe::Arc;
use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
@@ -293,42 +294,11 @@ pub struct CrateData {
pub is_proc_macro: bool,
}
-#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
-pub enum Edition {
- Edition2015,
- Edition2018,
- Edition2021,
- Edition2024,
-}
-
-impl Edition {
- pub const CURRENT: Edition = Edition::Edition2021;
- pub const DEFAULT: Edition = Edition::Edition2015;
-}
-
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct Env {
entries: FxHashMap<String, String>,
}
-impl Env {
- pub fn new_for_test_fixture() -> Self {
- Env {
- entries: FxHashMap::from_iter([(
- String::from("__ra_is_test_fixture"),
- String::from("__ra_is_test_fixture"),
- )]),
- }
- }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum DependencyKind {
- Normal,
- Dev,
- Build,
-}
-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Dependency {
pub crate_id: CrateId,
@@ -670,32 +640,6 @@ impl CrateData {
}
}
-impl FromStr for Edition {
- type Err = ParseEditionError;
-
- fn from_str(s: &str) -> Result<Self, Self::Err> {
- let res = match s {
- "2015" => Edition::Edition2015,
- "2018" => Edition::Edition2018,
- "2021" => Edition::Edition2021,
- "2024" => Edition::Edition2024,
- _ => return Err(ParseEditionError { invalid_input: s.to_owned() }),
- };
- Ok(res)
- }
-}
-
-impl fmt::Display for Edition {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.write_str(match self {
- Edition::Edition2015 => "2015",
- Edition::Edition2018 => "2018",
- Edition::Edition2021 => "2021",
- Edition::Edition2024 => "2024",
- })
- }
-}
-
impl Extend<(String, String)> for Env {
fn extend<T: IntoIterator<Item = (String, String)>>(&mut self, iter: T) {
self.entries.extend(iter);
@@ -723,19 +667,6 @@ impl Env {
}
#[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)
- }
-}
-
-impl std::error::Error for ParseEditionError {}
-
-#[derive(Debug)]
pub struct CyclicDependenciesError {
path: Vec<(CrateId, Option<CrateDisplayName>)>,
}
diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs
index 5dcb580723..785ff9ceff 100644
--- a/crates/base-db/src/lib.rs
+++ b/crates/base-db/src/lib.rs
@@ -14,9 +14,9 @@ use triomphe::Arc;
pub use crate::{
change::FileChange,
input::{
- CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency,
- DependencyKind, Edition, Env, LangCrateOrigin, ProcMacroPaths, ReleaseChannel, SourceRoot,
- SourceRootId, TargetLayoutLoadResult,
+ CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Env,
+ LangCrateOrigin, ProcMacroPaths, ReleaseChannel, SourceRoot, SourceRootId,
+ TargetLayoutLoadResult,
},
};
pub use salsa::{self, Cancelled};
diff --git a/crates/hir-def/src/lib.rs b/crates/hir-def/src/lib.rs
index 828842de7e..46898ce542 100644
--- a/crates/hir-def/src/lib.rs
+++ b/crates/hir-def/src/lib.rs
@@ -73,7 +73,7 @@ use std::{
use base_db::{
impl_intern_key,
salsa::{self, impl_intern_value_trivial},
- CrateId, Edition,
+ CrateId,
};
use hir_expand::{
builtin_attr_macro::BuiltinAttrExpander,
@@ -90,7 +90,7 @@ use hir_expand::{
use item_tree::ExternBlock;
use la_arena::Idx;
use nameres::DefMap;
-use span::{AstIdNode, FileAstId, FileId, SyntaxContextId};
+use span::{AstIdNode, Edition, FileAstId, FileId, SyntaxContextId};
use stdx::impl_from;
use syntax::{ast, AstNode};
diff --git a/crates/hir-def/src/nameres.rs b/crates/hir-def/src/nameres.rs
index b56dee3efb..2d1e92c1af 100644
--- a/crates/hir-def/src/nameres.rs
+++ b/crates/hir-def/src/nameres.rs
@@ -59,14 +59,14 @@ mod tests;
use std::ops::Deref;
-use base_db::{CrateId, Edition, FileId};
+use base_db::{CrateId, FileId};
use hir_expand::{
name::Name, proc_macro::ProcMacroKind, ErasedAstId, HirFileId, InFile, MacroCallId, MacroDefId,
};
use itertools::Itertools;
use la_arena::Arena;
use rustc_hash::{FxHashMap, FxHashSet};
-use span::{FileAstId, ROOT_ERASED_FILE_AST_ID};
+use span::{Edition, FileAstId, ROOT_ERASED_FILE_AST_ID};
use stdx::format_to;
use syntax::{ast, SmolStr};
use triomphe::Arc;
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs
index 3d026447fb..312938e2c1 100644
--- a/crates/hir-def/src/nameres/collector.rs
+++ b/crates/hir-def/src/nameres/collector.rs
@@ -5,7 +5,7 @@
use std::{cmp::Ordering, iter, mem, ops::Not};
-use base_db::{CrateId, Dependency, Edition, FileId};
+use base_db::{CrateId, Dependency, FileId};
use cfg::{CfgExpr, CfgOptions};
use either::Either;
use hir_expand::{
@@ -22,7 +22,7 @@ use itertools::{izip, Itertools};
use la_arena::Idx;
use limit::Limit;
use rustc_hash::{FxHashMap, FxHashSet};
-use span::{ErasedFileAstId, FileAstId, Span, SyntaxContextId};
+use span::{Edition, ErasedFileAstId, FileAstId, Span, SyntaxContextId};
use stdx::always;
use syntax::{ast, SmolStr};
use triomphe::Arc;
diff --git a/crates/hir-def/src/nameres/path_resolution.rs b/crates/hir-def/src/nameres/path_resolution.rs
index 9e53b03728..ee29b89f3d 100644
--- a/crates/hir-def/src/nameres/path_resolution.rs
+++ b/crates/hir-def/src/nameres/path_resolution.rs
@@ -10,8 +10,8 @@
//!
//! `ReachedFixedPoint` signals about this.
-use base_db::Edition;
use hir_expand::{name::Name, Lookup};
+use span::Edition;
use triomphe::Arc;
use crate::{
diff --git a/crates/hir-expand/src/builtin_fn_macro.rs b/crates/hir-expand/src/builtin_fn_macro.rs
index 9fb6a0b234..fd3e4e7a4d 100644
--- a/crates/hir-expand/src/builtin_fn_macro.rs
+++ b/crates/hir-expand/src/builtin_fn_macro.rs
@@ -1,11 +1,11 @@
//! Builtin macro
-use base_db::{AnchoredPath, Edition, FileId};
+use base_db::{AnchoredPath, FileId};
use cfg::CfgExpr;
use either::Either;
use itertools::Itertools;
use mbe::{parse_exprs_with_sep, parse_to_token_tree};
-use span::{Span, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID};
+use span::{Edition, Span, SpanAnchor, SyntaxContextId, ROOT_ERASED_FILE_AST_ID};
use syntax::ast::{self, AstToken};
use crate::{
diff --git a/crates/hir-expand/src/declarative.rs b/crates/hir-expand/src/declarative.rs
index 33643c0272..7272ea5c35 100644
--- a/crates/hir-expand/src/declarative.rs
+++ b/crates/hir-expand/src/declarative.rs
@@ -1,8 +1,8 @@
//! Compiled declarative macro expanders (`macro_rules!`` and `macro`)
use std::sync::OnceLock;
-use base_db::{CrateId, Edition, VersionReq};
-use span::{MacroCallId, Span};
+use base_db::{CrateId, VersionReq};
+use span::{Edition, MacroCallId, Span};
use syntax::{ast, AstNode};
use triomphe::Arc;
diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs
index 5d4f7dc146..80b8518711 100644
--- a/crates/hir-expand/src/lib.rs
+++ b/crates/hir-expand/src/lib.rs
@@ -30,10 +30,11 @@ use triomphe::Arc;
use std::{fmt, hash::Hash};
-use base_db::{salsa::impl_intern_value_trivial, CrateId, Edition, FileId};
+use base_db::{salsa::impl_intern_value_trivial, CrateId, FileId};
use either::Either;
use span::{
- ErasedFileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor, SyntaxContextData, SyntaxContextId,
+ Edition, ErasedFileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor, SyntaxContextData,
+ SyntaxContextId,
};
use syntax::{
ast::{self, AstNode},
diff --git a/crates/hir-ty/Cargo.toml b/crates/hir-ty/Cargo.toml
index a2711f8cbe..bf47374016 100644
--- a/crates/hir-ty/Cargo.toml
+++ b/crates/hir-ty/Cargo.toml
@@ -47,6 +47,7 @@ hir-expand.workspace = true
base-db.workspace = true
syntax.workspace = true
limit.workspace = true
+span.workspace = true
[dev-dependencies]
expect-test = "1.4.0"
diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs
index 0885d92ae8..064d317835 100644
--- a/crates/hir-ty/src/method_resolution.rs
+++ b/crates/hir-ty/src/method_resolution.rs
@@ -4,7 +4,7 @@
//! and the corresponding code mostly in rustc_hir_analysis/check/method/probe.rs.
use std::ops::ControlFlow;
-use base_db::{CrateId, Edition};
+use base_db::CrateId;
use chalk_ir::{cast::Cast, Mutability, TyKind, UniverseIndex, WhereClause};
use hir_def::{
data::{adt::StructFlags, ImplData},
@@ -15,6 +15,7 @@ use hir_def::{
use hir_expand::name::Name;
use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::{smallvec, SmallVec};
+use span::Edition;
use stdx::never;
use triomphe::Arc;
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 9d7be9a421..15a0967b3d 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -38,7 +38,7 @@ mod display;
use std::{iter, mem::discriminant, ops::ControlFlow};
use arrayvec::ArrayVec;
-use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId};
+use base_db::{CrateDisplayName, CrateId, CrateOrigin, FileId};
use either::Either;
use hir_def::{
body::{BodyDiagnostic, SyntheticSyntax},
@@ -79,6 +79,7 @@ use hir_ty::{
use itertools::Itertools;
use nameres::diagnostics::DefDiagnosticKind;
use rustc_hash::FxHashSet;
+use span::Edition;
use stdx::{impl_from, never};
use syntax::{
ast::{self, HasAttrs as _, HasName},
diff --git a/crates/ide/Cargo.toml b/crates/ide/Cargo.toml
index aca7d613e1..a535015a27 100644
--- a/crates/ide/Cargo.toml
+++ b/crates/ide/Cargo.toml
@@ -36,6 +36,7 @@ ide-ssr.workspace = true
profile.workspace = true
stdx.workspace = true
syntax.workspace = true
+span.workspace = true
text-edit.workspace = true
# ide should depend only on the top-level `hir` package. if you need
# something from some `hir-xxx` subpackage, reexport the API via `hir`.
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 11eaa88c5c..7a6c6ec41d 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -119,8 +119,8 @@ pub use ide_completion::{
};
pub use ide_db::{
base_db::{
- Cancelled, CrateGraph, CrateId, Edition, FileChange, FileId, FilePosition, FileRange,
- SourceRoot, SourceRootId,
+ Cancelled, CrateGraph, CrateId, FileChange, FileId, FilePosition, FileRange, SourceRoot,
+ SourceRootId,
},
documentation::Documentation,
label::Label,
@@ -135,6 +135,7 @@ pub use ide_diagnostics::{
Diagnostic, DiagnosticCode, DiagnosticsConfig, ExprFillDefaultMode, Severity,
};
pub use ide_ssr::SsrError;
+pub use span::Edition;
pub use syntax::{TextRange, TextSize};
pub use text_edit::{Indel, TextEdit};
diff --git a/crates/project-model/Cargo.toml b/crates/project-model/Cargo.toml
index 139689975d..097ee1f75c 100644
--- a/crates/project-model/Cargo.toml
+++ b/crates/project-model/Cargo.toml
@@ -25,6 +25,7 @@ itertools.workspace = true
# local deps
base-db.workspace = true
+span.workspace = true
cfg.workspace = true
paths = { workspace = true, features = ["serde1"] }
stdx.workspace = true
diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs
index 4f6bac08f6..957366b610 100644
--- a/crates/project-model/src/cargo_workspace.rs
+++ b/crates/project-model/src/cargo_workspace.rs
@@ -4,13 +4,13 @@ use std::ops;
use std::str::from_utf8;
use anyhow::Context;
-use base_db::Edition;
use cargo_metadata::{CargoOpt, MetadataCommand};
use la_arena::{Arena, Idx};
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
use rustc_hash::{FxHashMap, FxHashSet};
use serde::Deserialize;
use serde_json::from_value;
+use span::Edition;
use toolchain::Tool;
use crate::{utf8_stdout, InvocationLocation, ManifestPath, Sysroot};
diff --git a/crates/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs
index 0b6e8caf5d..512588cc8f 100644
--- a/crates/project-model/src/project_json.rs
+++ b/crates/project-model/src/project_json.rs
@@ -49,11 +49,12 @@
//! user explores them belongs to that extension (it's totally valid to change
//! rust-project.json over time via configuration request!)
-use base_db::{CrateDisplayName, CrateId, CrateName, Dependency, Edition};
+use base_db::{CrateDisplayName, CrateId, CrateName, Dependency};
use la_arena::RawIdx;
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
use rustc_hash::FxHashMap;
use serde::{de, Deserialize};
+use span::Edition;
use crate::cfg_flag::CfgFlag;
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index c6642efca2..1556e9b549 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -6,13 +6,14 @@ use std::{collections::VecDeque, fmt, fs, iter, str::FromStr, sync};
use anyhow::{format_err, Context};
use base_db::{
- CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
- FileId, LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
+ CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Env, FileId,
+ LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
};
use cfg::{CfgAtom, CfgDiff, CfgOptions};
use paths::{AbsPath, AbsPathBuf};
use rustc_hash::{FxHashMap, FxHashSet};
use semver::Version;
+use span::Edition;
use stdx::always;
use toolchain::Tool;
use triomphe::Arc;
diff --git a/crates/span/src/lib.rs b/crates/span/src/lib.rs
index 6b849ce373..c9109c72d0 100644
--- a/crates/span/src/lib.rs
+++ b/crates/span/src/lib.rs
@@ -16,6 +16,56 @@ pub use self::{
pub use syntax::{TextRange, TextSize};
pub use vfs::FileId;
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+pub enum Edition {
+ Edition2015,
+ Edition2018,
+ Edition2021,
+ Edition2024,
+}
+
+impl Edition {
+ pub const CURRENT: Edition = Edition::Edition2021;
+ pub const DEFAULT: Edition = Edition::Edition2015;
+}
+
+#[derive(Debug)]
+pub struct ParseEditionError {
+ invalid_input: String,
+}
+
+impl std::error::Error for ParseEditionError {}
+impl fmt::Display for ParseEditionError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "invalid edition: {:?}", self.invalid_input)
+ }
+}
+
+impl std::str::FromStr for Edition {
+ type Err = ParseEditionError;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ let res = match s {
+ "2015" => Edition::Edition2015,
+ "2018" => Edition::Edition2018,
+ "2021" => Edition::Edition2021,
+ "2024" => Edition::Edition2024,
+ _ => return Err(ParseEditionError { invalid_input: s.to_owned() }),
+ };
+ Ok(res)
+ }
+}
+
+impl fmt::Display for Edition {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.write_str(match self {
+ Edition::Edition2015 => "2015",
+ Edition::Edition2018 => "2018",
+ Edition::Edition2021 => "2021",
+ Edition::Edition2024 => "2024",
+ })
+ }
+}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct FilePosition {
pub file_id: FileId,
diff --git a/crates/test-fixture/src/lib.rs b/crates/test-fixture/src/lib.rs
index 8cf65d11c6..b20315eefc 100644
--- a/crates/test-fixture/src/lib.rs
+++ b/crates/test-fixture/src/lib.rs
@@ -2,8 +2,8 @@
use std::{iter, mem, ops::Not, str::FromStr, sync};
use base_db::{
- CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env,
- FileChange, FileSet, LangCrateOrigin, SourceDatabaseExt, SourceRoot, Version, VfsPath,
+ CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Env, FileChange,
+ FileSet, LangCrateOrigin, SourceDatabaseExt, SourceRoot, Version, VfsPath,
};
use cfg::CfgOptions;
use hir_expand::{
@@ -14,7 +14,7 @@ use hir_expand::{
},
};
use rustc_hash::FxHashMap;
-use span::{FileId, FilePosition, FileRange, Span};
+use span::{Edition, FileId, FilePosition, FileRange, Span};
use test_utils::{
extract_range_or_offset, Fixture, FixtureWithProjectMeta, RangeOrOffset, CURSOR_MARKER,
ESCAPED_CURSOR_MARKER,
@@ -137,7 +137,10 @@ impl ChangeFixture {
let mut crate_deps = Vec::new();
let mut default_crate_root: Option<FileId> = None;
let mut default_cfg = CfgOptions::default();
- let mut default_env = Env::new_for_test_fixture();
+ let mut default_env = Env::from_iter([(
+ String::from("__ra_is_test_fixture"),
+ String::from("__ra_is_test_fixture"),
+ )]);
let mut file_set = FileSet::default();
let mut current_source_root_kind = SourceRootKind::Local;
@@ -262,7 +265,10 @@ impl ChangeFixture {
None,
Default::default(),
Default::default(),
- Env::new_for_test_fixture(),
+ Env::from_iter([(
+ String::from("__ra_is_test_fixture"),
+ String::from("__ra_is_test_fixture"),
+ )]),
false,
CrateOrigin::Lang(LangCrateOrigin::Core),
);
@@ -298,7 +304,10 @@ impl ChangeFixture {
None,
Default::default(),
Default::default(),
- Env::new_for_test_fixture(),
+ Env::from_iter([(
+ String::from("__ra_is_test_fixture"),
+ String::from("__ra_is_test_fixture"),
+ )]),
true,
CrateOrigin::Local { repo: None, name: None },
);