Skip to content

Commit cd8eb0f

Browse files
committed
internal: Remove span trait
1 parent 2ad14b8 commit cd8eb0f

File tree

11 files changed

+52
-55
lines changed

11 files changed

+52
-55
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ impl CrateGraph {
623623
}
624624
id_map
625625
}
626+
627+
pub fn shrink_to_fit(&mut self) {
628+
self.arena.shrink_to_fit();
629+
}
626630
}
627631

628632
impl ops::Index<CrateId> for CrateGraph {

crates/mbe/src/syntax_bridge.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Conversions between [`SyntaxNode`] and [`tt::TokenTree`].
22
3+
use std::fmt;
4+
35
use rustc_hash::{FxHashMap, FxHashSet};
46
use span::{SpanAnchor, SpanData, SpanMap};
57
use stdx::{never, non_empty_vec::NonEmptyVec};
@@ -9,30 +11,27 @@ use syntax::{
911
SyntaxKind::*,
1012
SyntaxNode, SyntaxToken, SyntaxTreeBuilder, TextRange, TextSize, WalkEvent, T,
1113
};
12-
use tt::{
13-
buffer::{Cursor, TokenBuffer},
14-
Span,
15-
};
14+
use tt::buffer::{Cursor, TokenBuffer};
1615

1716
use crate::{to_parser_input::to_parser_input, tt_iter::TtIter};
1817

1918
#[cfg(test)]
2019
mod tests;
2120

22-
pub trait SpanMapper<S: Span> {
21+
pub trait SpanMapper<S> {
2322
fn span_for(&self, range: TextRange) -> S;
2423
}
2524

2625
impl<S> SpanMapper<SpanData<S>> for SpanMap<S>
2726
where
28-
SpanData<S>: Span,
27+
SpanData<S>: Copy,
2928
{
3029
fn span_for(&self, range: TextRange) -> SpanData<S> {
3130
self.span_at(range.start())
3231
}
3332
}
3433

35-
impl<S: Span, SM: SpanMapper<S>> SpanMapper<S> for &SM {
34+
impl<S: Copy, SM: SpanMapper<S>> SpanMapper<S> for &SM {
3635
fn span_for(&self, range: TextRange) -> S {
3736
SM::span_for(self, range)
3837
}
@@ -78,8 +77,7 @@ pub fn syntax_node_to_token_tree<Ctx, SpanMap>(
7877
span: SpanData<Ctx>,
7978
) -> tt::Subtree<SpanData<Ctx>>
8079
where
81-
SpanData<Ctx>: Span,
82-
Ctx: Copy,
80+
SpanData<Ctx>: Copy + fmt::Debug,
8381
SpanMap: SpanMapper<SpanData<Ctx>>,
8482
{
8583
let mut c = Converter::new(node, map, Default::default(), Default::default(), span);
@@ -98,8 +96,7 @@ pub fn syntax_node_to_token_tree_modified<Ctx, SpanMap>(
9896
) -> tt::Subtree<SpanData<Ctx>>
9997
where
10098
SpanMap: SpanMapper<SpanData<Ctx>>,
101-
SpanData<Ctx>: Span,
102-
Ctx: Copy,
99+
SpanData<Ctx>: Copy + fmt::Debug,
103100
{
104101
let mut c = Converter::new(node, map, append, remove, call_site);
105102
convert_tokens(&mut c)
@@ -124,8 +121,7 @@ pub fn token_tree_to_syntax_node<Ctx>(
124121
entry_point: parser::TopEntryPoint,
125122
) -> (Parse<SyntaxNode>, SpanMap<Ctx>)
126123
where
127-
SpanData<Ctx>: Span,
128-
Ctx: Copy,
124+
SpanData<Ctx>: Copy + fmt::Debug,
129125
{
130126
let buffer = match tt {
131127
tt::Subtree {
@@ -161,7 +157,7 @@ pub fn parse_to_token_tree<Ctx>(
161157
text: &str,
162158
) -> Option<tt::Subtree<SpanData<Ctx>>>
163159
where
164-
SpanData<Ctx>: Span,
160+
SpanData<Ctx>: Copy + fmt::Debug,
165161
Ctx: Copy,
166162
{
167163
let lexed = parser::LexedStr::new(text);
@@ -175,7 +171,7 @@ where
175171
/// Convert a string to a `TokenTree`. The passed span will be used for all spans of the produced subtree.
176172
pub fn parse_to_token_tree_static_span<S>(span: S, text: &str) -> Option<tt::Subtree<S>>
177173
where
178-
S: Span,
174+
S: Copy + fmt::Debug,
179175
{
180176
let lexed = parser::LexedStr::new(text);
181177
if lexed.errors().next().is_some() {
@@ -186,11 +182,10 @@ where
186182
}
187183

188184
/// Split token tree with separate expr: $($e:expr)SEP*
189-
pub fn parse_exprs_with_sep<S: Span>(
190-
tt: &tt::Subtree<S>,
191-
sep: char,
192-
span: S,
193-
) -> Vec<tt::Subtree<S>> {
185+
pub fn parse_exprs_with_sep<S>(tt: &tt::Subtree<S>, sep: char, span: S) -> Vec<tt::Subtree<S>>
186+
where
187+
S: Copy + fmt::Debug,
188+
{
194189
if tt.token_trees.is_empty() {
195190
return Vec::new();
196191
}
@@ -226,7 +221,8 @@ pub fn parse_exprs_with_sep<S: Span>(
226221
fn convert_tokens<S, C>(conv: &mut C) -> tt::Subtree<S>
227222
where
228223
C: TokenConverter<S>,
229-
S: Span,
224+
S: Copy + fmt::Debug,
225+
C::Token: fmt::Debug,
230226
{
231227
let entry = tt::SubtreeBuilder {
232228
delimiter: tt::Delimiter::invisible_spanned(conv.call_site()),
@@ -485,7 +481,7 @@ struct StaticRawConverter<'a, S> {
485481
span: S,
486482
}
487483

488-
trait SrcToken<Ctx, S>: std::fmt::Debug {
484+
trait SrcToken<Ctx, S> {
489485
fn kind(&self, ctx: &Ctx) -> SyntaxKind;
490486

491487
fn to_char(&self, ctx: &Ctx) -> Option<char>;
@@ -525,7 +521,7 @@ impl<S, Ctx> SrcToken<RawConverter<'_, Ctx>, S> for usize {
525521
}
526522
}
527523

528-
impl<S: Span> SrcToken<StaticRawConverter<'_, S>, S> for usize {
524+
impl<S: Copy> SrcToken<StaticRawConverter<'_, S>, S> for usize {
529525
fn kind(&self, ctx: &StaticRawConverter<'_, S>) -> SyntaxKind {
530526
ctx.lexed.kind(*self)
531527
}
@@ -541,7 +537,7 @@ impl<S: Span> SrcToken<StaticRawConverter<'_, S>, S> for usize {
541537

542538
impl<Ctx: Copy> TokenConverter<SpanData<Ctx>> for RawConverter<'_, Ctx>
543539
where
544-
SpanData<Ctx>: Span,
540+
SpanData<Ctx>: Copy,
545541
{
546542
type Token = usize;
547543

@@ -584,7 +580,7 @@ where
584580

585581
impl<S> TokenConverter<S> for StaticRawConverter<'_, S>
586582
where
587-
S: Span,
583+
S: Copy,
588584
{
589585
type Token = usize;
590586

@@ -709,7 +705,7 @@ impl<S> SynToken<S> {
709705
}
710706
}
711707

712-
impl<SpanMap, S: std::fmt::Debug> SrcToken<Converter<SpanMap, S>, S> for SynToken<S> {
708+
impl<SpanMap, S> SrcToken<Converter<SpanMap, S>, S> for SynToken<S> {
713709
fn kind(&self, _ctx: &Converter<SpanMap, S>) -> SyntaxKind {
714710
match self {
715711
SynToken::Ordinary(token) => token.kind(),
@@ -748,7 +744,7 @@ impl<SpanMap, S: std::fmt::Debug> SrcToken<Converter<SpanMap, S>, S> for SynToke
748744

749745
impl<S, SpanMap> TokenConverter<S> for Converter<SpanMap, S>
750746
where
751-
S: Span,
747+
S: Copy,
752748
SpanMap: SpanMapper<S>,
753749
{
754750
type Token = SynToken<S>;
@@ -828,7 +824,7 @@ where
828824

829825
struct TtTreeSink<'a, Ctx>
830826
where
831-
SpanData<Ctx>: Span,
827+
SpanData<Ctx>: Copy,
832828
{
833829
buf: String,
834830
cursor: Cursor<'a, SpanData<Ctx>>,
@@ -839,7 +835,7 @@ where
839835

840836
impl<'a, Ctx> TtTreeSink<'a, Ctx>
841837
where
842-
SpanData<Ctx>: Span,
838+
SpanData<Ctx>: Copy,
843839
{
844840
fn new(cursor: Cursor<'a, SpanData<Ctx>>) -> Self {
845841
TtTreeSink {
@@ -871,7 +867,7 @@ fn delim_to_str(d: tt::DelimiterKind, closing: bool) -> Option<&'static str> {
871867

872868
impl<Ctx> TtTreeSink<'_, Ctx>
873869
where
874-
SpanData<Ctx>: Span,
870+
SpanData<Ctx>: Copy,
875871
{
876872
/// Parses a float literal as if it was a one to two name ref nodes with a dot inbetween.
877873
/// This occurs when a float literal is used as a field access.

crates/mbe/src/to_parser_input.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
//! Convert macro-by-example tokens which are specific to macro expansion into a
22
//! format that works for our parser.
33
4+
use std::fmt;
5+
46
use syntax::{SyntaxKind, SyntaxKind::*, T};
57

6-
use tt::{buffer::TokenBuffer, Span};
8+
use tt::buffer::TokenBuffer;
79

8-
pub(crate) fn to_parser_input<S: Span>(buffer: &TokenBuffer<'_, S>) -> parser::Input {
10+
pub(crate) fn to_parser_input<S: Copy + fmt::Debug>(buffer: &TokenBuffer<'_, S>) -> parser::Input {
911
let mut res = parser::Input::default();
1012

1113
let mut current = buffer.begin();

crates/mbe/src/tt_iter.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! A "Parser" structure for token trees. We use this when parsing a declarative
22
//! macro definition into a list of patterns and templates.
33
4+
use core::fmt;
5+
46
use smallvec::{smallvec, SmallVec};
57
use syntax::SyntaxKind;
6-
use tt::Span;
78

89
use crate::{to_parser_input::to_parser_input, ExpandError, ExpandResult};
910

@@ -12,7 +13,7 @@ pub(crate) struct TtIter<'a, S> {
1213
pub(crate) inner: std::slice::Iter<'a, tt::TokenTree<S>>,
1314
}
1415

15-
impl<'a, S: Span> TtIter<'a, S> {
16+
impl<'a, S: Copy> TtIter<'a, S> {
1617
pub(crate) fn new(subtree: &'a tt::Subtree<S>) -> TtIter<'a, S> {
1718
TtIter { inner: subtree.token_trees.iter() }
1819
}
@@ -130,7 +131,12 @@ impl<'a, S: Span> TtIter<'a, S> {
130131
_ => Ok(smallvec![first]),
131132
}
132133
}
134+
pub(crate) fn peek_n(&self, n: usize) -> Option<&'a tt::TokenTree<S>> {
135+
self.inner.as_slice().get(n)
136+
}
137+
}
133138

139+
impl<'a, S: Copy + fmt::Debug> TtIter<'a, S> {
134140
pub(crate) fn expect_fragment(
135141
&mut self,
136142
entry_point: parser::PrefixEntryPoint,
@@ -185,10 +191,6 @@ impl<'a, S: Span> TtIter<'a, S> {
185191
};
186192
ExpandResult { value: res, err }
187193
}
188-
189-
pub(crate) fn peek_n(&self, n: usize) -> Option<&'a tt::TokenTree<S>> {
190-
self.inner.as_slice().get(n)
191-
}
192194
}
193195

194196
impl<'a, S> Iterator for TtIter<'a, S> {

crates/proc-macro-api/src/msg/flat.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ impl std::fmt::Debug for TokenId {
8888
}
8989
}
9090

91-
impl tt::Span for TokenId {}
92-
9391
#[derive(Serialize, Deserialize, Debug)]
9492
pub struct FlatTree {
9593
subtree: Vec<u32>,

crates/proc-macro-srv/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::server::TokenStream;
5252
// see `build.rs`
5353
include!(concat!(env!("OUT_DIR"), "/rustc_version.rs"));
5454

55-
trait ProcMacroSrvSpan: tt::Span {
55+
trait ProcMacroSrvSpan: Copy {
5656
type Server: proc_macro::bridge::server::Server<TokenStream = TokenStream<Self>>;
5757
fn make_server(call_site: Self, def_site: Self, mixed_site: Self) -> Self::Server;
5858
}

crates/proc-macro-srv/src/server/token_stream.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pub(super) struct TokenStreamBuilder<S> {
101101
/// pub(super)lic implementation details for the `TokenStream` type, such as iterators.
102102
pub(super) mod token_stream {
103103

104+
use core::fmt;
105+
104106
use super::{TokenStream, TokenTree};
105107

106108
/// An iterator over `TokenStream`'s `TokenTree`s.
@@ -122,7 +124,7 @@ pub(super) mod token_stream {
122124
///
123125
/// NOTE: some errors may cause panics instead of returning `LexError`. We reserve the right to
124126
/// change these errors into `LexError`s later.
125-
impl<S: tt::Span> TokenStream<S> {
127+
impl<S: Copy + fmt::Debug> TokenStream<S> {
126128
pub(crate) fn from_str(src: &str, call_site: S) -> Result<TokenStream<S>, String> {
127129
let subtree =
128130
mbe::parse_to_token_tree_static_span(call_site, src).ok_or("lexing error")?;

crates/rust-analyzer/src/reload.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ pub fn ws_to_crate_graph(
734734
});
735735
proc_macro_paths.push(crate_proc_macros);
736736
}
737+
crate_graph.shrink_to_fit();
738+
proc_macro_paths.shrink_to_fit();
737739
(crate_graph, proc_macro_paths, layouts, toolchains)
738740
}
739741

crates/tt/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,5 @@ text-size.workspace = true
1717

1818
stdx.workspace = true
1919

20-
# FIXME: Remove this dependency once the `Span` trait is gone (that is once Span::DUMMY has been removed)
21-
span.workspace = true
22-
2320
[lints]
24-
workspace = true
21+
workspace = true

crates/tt/src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@ use stdx::impl_from;
1111
pub use smol_str::SmolStr;
1212
pub use text_size::{TextRange, TextSize};
1313

14-
pub trait Span: std::fmt::Debug + Copy + Sized + Eq {}
15-
16-
impl<Ctx> Span for span::SpanData<Ctx> where span::SpanData<Ctx>: std::fmt::Debug + Copy + Sized + Eq
17-
{}
18-
1914
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2015
pub enum TokenTree<S> {
2116
Leaf(Leaf<S>),
2217
Subtree(Subtree<S>),
2318
}
2419
impl_from!(Leaf<S>, Subtree<S> for TokenTree);
25-
impl<S: Span> TokenTree<S> {
20+
impl<S: Copy> TokenTree<S> {
2621
pub fn empty(span: S) -> Self {
2722
Self::Subtree(Subtree {
2823
delimiter: Delimiter::invisible_spanned(span),
@@ -72,7 +67,7 @@ pub struct Subtree<S> {
7267
pub token_trees: Box<[TokenTree<S>]>,
7368
}
7469

75-
impl<S: Span> Subtree<S> {
70+
impl<S: Copy> Subtree<S> {
7671
pub fn empty(span: DelimSpan<S>) -> Self {
7772
Subtree { delimiter: Delimiter::invisible_delim_spanned(span), token_trees: Box::new([]) }
7873
}
@@ -114,7 +109,7 @@ pub struct Delimiter<S> {
114109
pub kind: DelimiterKind,
115110
}
116111

117-
impl<S: Span> Delimiter<S> {
112+
impl<S: Copy> Delimiter<S> {
118113
pub const fn invisible_spanned(span: S) -> Self {
119114
Delimiter { open: span, close: span, kind: DelimiterKind::Invisible }
120115
}

0 commit comments

Comments
 (0)