Unnamed repository; edit this file 'description' to name the repository.
Remove SyntaxContext trait
Lukas Wirth 2023-12-20
parent 7b80455 · commit f211a40
-rw-r--r--crates/mbe/src/syntax_bridge.rs16
-rw-r--r--crates/proc-macro-api/src/msg/flat.rs4
-rw-r--r--crates/tt/src/lib.rs30
3 files changed, 10 insertions, 40 deletions
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs
index 54383f943e..110bf87213 100644
--- a/crates/mbe/src/syntax_bridge.rs
+++ b/crates/mbe/src/syntax_bridge.rs
@@ -11,7 +11,7 @@ use syntax::{
};
use tt::{
buffer::{Cursor, TokenBuffer},
- Span, SyntaxContext,
+ Span,
};
use crate::{to_parser_input::to_parser_input, tt_iter::TtIter};
@@ -37,7 +37,6 @@ impl<S: Span, SM: SpanMapper<S>> SpanMapper<S> for &SM {
/// Dummy things for testing where spans don't matter.
pub(crate) mod dummy_test_span_utils {
- use tt::SyntaxContext;
use super::*;
@@ -53,9 +52,6 @@ pub(crate) mod dummy_test_span_utils {
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct DummyTestSyntaxContext;
- impl SyntaxContext for DummyTestSyntaxContext {
- const DUMMY: Self = DummyTestSyntaxContext;
- }
pub struct DummyTestSpanMap;
@@ -82,7 +78,7 @@ pub fn syntax_node_to_token_tree<Ctx, SpanMap>(
) -> tt::Subtree<SpanData<Ctx>>
where
SpanData<Ctx>: Span,
- Ctx: SyntaxContext,
+ Ctx: Copy,
SpanMap: SpanMapper<SpanData<Ctx>>,
{
let mut c = Converter::new(node, map, Default::default(), Default::default(), span);
@@ -102,7 +98,7 @@ pub fn syntax_node_to_token_tree_modified<Ctx, SpanMap>(
where
SpanMap: SpanMapper<SpanData<Ctx>>,
SpanData<Ctx>: Span,
- Ctx: SyntaxContext,
+ Ctx: Copy,
{
let mut c = Converter::new(node, map, append, remove, call_site);
convert_tokens(&mut c)
@@ -128,7 +124,7 @@ pub fn token_tree_to_syntax_node<Ctx>(
) -> (Parse<SyntaxNode>, SpanMap<SpanData<Ctx>>)
where
SpanData<Ctx>: Span,
- Ctx: SyntaxContext,
+ Ctx: Copy,
{
let buffer = match tt {
tt::Subtree {
@@ -165,7 +161,7 @@ pub fn parse_to_token_tree<Ctx>(
) -> Option<tt::Subtree<SpanData<Ctx>>>
where
SpanData<Ctx>: Span,
- Ctx: SyntaxContext,
+ Ctx: Copy,
{
let lexed = parser::LexedStr::new(text);
if lexed.errors().next().is_some() {
@@ -531,7 +527,7 @@ impl<S: Span> SrcToken<StaticRawConverter<'_, S>, S> for usize {
}
}
-impl<Ctx: SyntaxContext> TokenConverter<SpanData<Ctx>> for RawConverter<'_, Ctx>
+impl<Ctx: Copy> TokenConverter<SpanData<Ctx>> for RawConverter<'_, Ctx>
where
SpanData<Ctx>: Span,
{
diff --git a/crates/proc-macro-api/src/msg/flat.rs b/crates/proc-macro-api/src/msg/flat.rs
index 12c0daa7e4..a12581ac13 100644
--- a/crates/proc-macro-api/src/msg/flat.rs
+++ b/crates/proc-macro-api/src/msg/flat.rs
@@ -54,9 +54,7 @@ impl std::fmt::Debug for TokenId {
}
}
-impl tt::Span for TokenId {
- const DUMMY: Self = TokenId(!0);
-}
+impl tt::Span for TokenId {}
#[derive(Serialize, Deserialize, Debug)]
pub struct FlatTree {
diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs
index 53002967f0..b3b0eeda75 100644
--- a/crates/tt/src/lib.rs
+++ b/crates/tt/src/lib.rs
@@ -11,34 +11,10 @@ use stdx::impl_from;
pub use smol_str::SmolStr;
pub use text_size::{TextRange, TextSize};
-pub trait Span: std::fmt::Debug + Copy + Sized + Eq {
- // FIXME: Should not exist. Dummy spans will always be wrong if they leak somewhere. Instead,
- // the call site or def site spans should be used in relevant places, its just that we don't
- // expose those everywhere in the yet.
- #[deprecated = "dummy spans will panic if surfaced incorrectly, as such they should be replaced appropriately"]
- const DUMMY: Self;
-}
-
-pub trait SyntaxContext: std::fmt::Debug + Copy + Sized + Eq {
- #[deprecated = "dummy spans will panic if surfaced incorrectly, as such they should be replaced appropriately"]
- const DUMMY: Self;
-}
-
-impl<Ctx: SyntaxContext> Span for span::SpanData<Ctx> {
- #[allow(deprecated)]
- const DUMMY: Self = span::SpanData {
- range: TextRange::empty(TextSize::new(0)),
- anchor: span::SpanAnchor {
- file_id: span::FileId::BOGUS,
- ast_id: span::ROOT_ERASED_FILE_AST_ID,
- },
- ctx: Ctx::DUMMY,
- };
-}
+pub trait Span: std::fmt::Debug + Copy + Sized + Eq {}
-impl SyntaxContext for span::SyntaxContextId {
- const DUMMY: Self = Self::ROOT;
-}
+impl<Ctx> Span for span::SpanData<Ctx> where span::SpanData<Ctx>: std::fmt::Debug + Copy + Sized + Eq
+{}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TokenTree<S> {