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

Commit 4ec8123

Browse files
committed
Remove usages of Span::DUMMY
1 parent f48ecb6 commit 4ec8123

File tree

20 files changed

+90
-87
lines changed

20 files changed

+90
-87
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ lsp-server = { version = "0.7.4" }
9393

9494
# non-local crates
9595
anyhow = "1.0.75"
96+
arrayvec = "0.7.4"
9697
bitflags = "2.4.1"
9798
cargo_metadata = "0.18.1"
9899
command-group = "2.0.1"

crates/hir-def/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rust-version.workspace = true
1212
doctest = false
1313

1414
[dependencies]
15-
arrayvec = "0.7.2"
15+
arrayvec.workspace = true
1616
bitflags.workspace = true
1717
cov-mark = "2.0.0-pre.1"
1818
dashmap.workspace = true

crates/hir-def/src/item_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use la_arena::{Arena, Idx, IdxRange, RawIdx};
5555
use profile::Count;
5656
use rustc_hash::FxHashMap;
5757
use smallvec::SmallVec;
58-
use span::SyntaxContextId;
58+
use span::Span;
5959
use stdx::never;
6060
use syntax::{ast, match_ast, SyntaxKind};
6161
use triomphe::Arc;
@@ -747,7 +747,7 @@ pub struct MacroCall {
747747
pub path: Interned<ModPath>,
748748
pub ast_id: FileAstId<ast::MacroCall>,
749749
pub expand_to: ExpandTo,
750-
pub call_site: SyntaxContextId,
750+
pub call_site: Span,
751751
}
752752

753753
#[derive(Debug, Clone, Eq, PartialEq)]

crates/hir-def/src/item_tree/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl<'a> Ctx<'a> {
549549
path,
550550
ast_id,
551551
expand_to,
552-
call_site: span_map.span_for_range(m.syntax().text_range()).ctx,
552+
call_site: span_map.span_for_range(m.syntax().text_range()),
553553
};
554554
Some(id(self.data().macro_calls.alloc(res)))
555555
}

crates/hir-def/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ use hir_expand::{
8080
use item_tree::ExternBlock;
8181
use la_arena::Idx;
8282
use nameres::DefMap;
83-
use span::SyntaxContextId;
83+
use span::Span;
8484
use stdx::impl_from;
8585
use syntax::{ast, AstNode};
8686

@@ -1172,7 +1172,7 @@ impl AsMacroCall for InFile<&ast::MacroCall> {
11721172
return Ok(ExpandResult::only_err(ExpandError::other("malformed macro invocation")));
11731173
};
11741174

1175-
let call_site = span_map.span_for_range(self.value.syntax().text_range()).ctx;
1175+
let call_site = span_map.span_for_range(self.value.syntax().text_range());
11761176

11771177
macro_call_as_call_id_with_eager(
11781178
db,
@@ -1202,7 +1202,7 @@ impl<T: AstIdNode> AstIdWithPath<T> {
12021202
fn macro_call_as_call_id(
12031203
db: &dyn ExpandDatabase,
12041204
call: &AstIdWithPath<ast::MacroCall>,
1205-
call_site: SyntaxContextId,
1205+
call_site: Span,
12061206
expand_to: ExpandTo,
12071207
krate: CrateId,
12081208
resolver: impl Fn(path::ModPath) -> Option<MacroDefId> + Copy,
@@ -1214,7 +1214,7 @@ fn macro_call_as_call_id(
12141214
fn macro_call_as_call_id_with_eager(
12151215
db: &dyn ExpandDatabase,
12161216
call: &AstIdWithPath<ast::MacroCall>,
1217-
call_site: SyntaxContextId,
1217+
call_site: Span,
12181218
expand_to: ExpandTo,
12191219
krate: CrateId,
12201220
resolver: impl FnOnce(path::ModPath) -> Option<MacroDefId>,
@@ -1320,7 +1320,7 @@ fn derive_macro_as_call_id(
13201320
item_attr: &AstIdWithPath<ast::Adt>,
13211321
derive_attr_index: AttrId,
13221322
derive_pos: u32,
1323-
call_site: SyntaxContextId,
1323+
call_site: Span,
13241324
krate: CrateId,
13251325
resolver: impl Fn(path::ModPath) -> Option<(MacroId, MacroDefId)>,
13261326
) -> Result<(MacroId, MacroDefId, MacroCallId), UnresolvedMacro> {
@@ -1365,7 +1365,7 @@ fn attr_macro_as_call_id(
13651365
attr_args: arg.map(Arc::new),
13661366
invoc_attr_index: macro_attr.id,
13671367
},
1368-
macro_attr.ctxt,
1368+
macro_attr.span,
13691369
)
13701370
}
13711371

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ enum MacroDirectiveKind {
228228
FnLike {
229229
ast_id: AstIdWithPath<ast::MacroCall>,
230230
expand_to: ExpandTo,
231-
call_site: SyntaxContextId,
231+
call_site: Span,
232232
},
233233
Derive {
234234
ast_id: AstIdWithPath<ast::Adt>,
235235
derive_attr: AttrId,
236236
derive_pos: usize,
237-
call_site: SyntaxContextId,
237+
call_site: Span,
238238
},
239239
Attr {
240240
ast_id: AstIdWithPath<ast::Item>,
@@ -1305,38 +1305,37 @@ impl DefCollector<'_> {
13051305
// Not resolved to a derive helper or the derive attribute, so try to treat as a normal attribute.
13061306
let call_id =
13071307
attr_macro_as_call_id(self.db, file_ast_id, attr, self.def_map.krate, def);
1308-
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call_id);
13091308

13101309
// If proc attribute macro expansion is disabled, skip expanding it here
13111310
if !self.db.expand_proc_attr_macros() {
13121311
self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro(
13131312
directive.module_id,
1314-
loc.kind,
1315-
loc.def.krate,
1313+
self.db.lookup_intern_macro_call(call_id).kind,
1314+
def.krate,
13161315
));
13171316
return recollect_without(self);
13181317
}
13191318

13201319
// Skip #[test]/#[bench] expansion, which would merely result in more memory usage
13211320
// due to duplicating functions into macro expansions
13221321
if matches!(
1323-
loc.def.kind,
1322+
def.kind,
13241323
MacroDefKind::BuiltInAttr(expander, _)
13251324
if expander.is_test() || expander.is_bench()
13261325
) {
13271326
return recollect_without(self);
13281327
}
13291328

1330-
if let MacroDefKind::ProcMacro(exp, ..) = loc.def.kind {
1329+
if let MacroDefKind::ProcMacro(exp, ..) = def.kind {
13311330
if exp.is_dummy() {
13321331
// If there's no expander for the proc macro (e.g.
13331332
// because proc macros are disabled, or building the
13341333
// proc macro crate failed), report this and skip
13351334
// expansion like we would if it was disabled
13361335
self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro(
13371336
directive.module_id,
1338-
loc.kind,
1339-
loc.def.krate,
1337+
self.db.lookup_intern_macro_call(call_id).kind,
1338+
def.krate,
13401339
));
13411340

13421341
return recollect_without(self);

crates/hir-expand/src/attrs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use either::Either;
77
use intern::Interned;
88
use mbe::{syntax_node_to_token_tree, DelimiterKind, Punct};
99
use smallvec::{smallvec, SmallVec};
10-
use span::SyntaxContextId;
10+
use span::Span;
1111
use syntax::{ast, match_ast, AstNode, AstToken, SmolStr, SyntaxNode};
1212
use triomphe::Arc;
1313

@@ -53,7 +53,7 @@ impl RawAttrs {
5353
id,
5454
input: Some(Interned::new(AttrInput::Literal(SmolStr::new(doc)))),
5555
path: Interned::new(ModPath::from(crate::name!(doc))),
56-
ctxt: span_map.span_for_range(comment.syntax().text_range()).ctx,
56+
span: span_map.span_for_range(comment.syntax().text_range()),
5757
}),
5858
});
5959
let entries: Arc<[Attr]> = Arc::from_iter(entries);
@@ -177,7 +177,7 @@ pub struct Attr {
177177
pub id: AttrId,
178178
pub path: Interned<ModPath>,
179179
pub input: Option<Interned<AttrInput>>,
180-
pub ctxt: SyntaxContextId,
180+
pub span: Span,
181181
}
182182

183183
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -218,7 +218,7 @@ impl Attr {
218218
} else {
219219
None
220220
};
221-
Some(Attr { id, path, input, ctxt: span_map.span_for_range(ast.syntax().text_range()).ctx })
221+
Some(Attr { id, path, input, span: span_map.span_for_range(ast.syntax().text_range()) })
222222
}
223223

224224
fn from_tt(db: &dyn ExpandDatabase, tt: &tt::Subtree, id: AttrId) -> Option<Attr> {
@@ -266,7 +266,7 @@ impl Attr {
266266
pub fn parse_path_comma_token_tree<'a>(
267267
&'a self,
268268
db: &'a dyn ExpandDatabase,
269-
) -> Option<impl Iterator<Item = (ModPath, SyntaxContextId)> + 'a> {
269+
) -> Option<impl Iterator<Item = (ModPath, Span)> + 'a> {
270270
let args = self.token_tree_value()?;
271271

272272
if args.delimiter.kind != DelimiterKind::Parenthesis {
@@ -294,7 +294,7 @@ impl Attr {
294294
return None;
295295
}
296296
let path = meta.path()?;
297-
let call_site = span_map.span_at(path.syntax().text_range().start()).ctx;
297+
let call_site = span_map.span_at(path.syntax().text_range().start());
298298
Some((
299299
ModPath::from_src(db, path, SpanMapRef::ExpansionSpanMap(&span_map))?,
300300
call_site,

crates/hir-expand/src/builtin_attr_macro.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Builtin attributes.
2-
use span::{FileId, MacroCallId, Span, SyntaxContextId, ROOT_ERASED_FILE_AST_ID};
3-
use syntax::{TextRange, TextSize};
2+
use span::{MacroCallId, Span};
43

54
use crate::{db::ExpandDatabase, name, tt, ExpandResult, MacroCallKind};
65

@@ -110,20 +109,13 @@ fn derive_attr_expand(
110109
pub fn pseudo_derive_attr_expansion(
111110
tt: &tt::Subtree,
112111
args: &tt::Subtree,
113-
call_site: SyntaxContextId,
112+
call_site: Span,
114113
) -> ExpandResult<tt::Subtree> {
115114
let mk_leaf = |char| {
116115
tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct {
117116
char,
118117
spacing: tt::Spacing::Alone,
119-
span: Span {
120-
range: TextRange::empty(TextSize::new(0)),
121-
anchor: span::SpanAnchor {
122-
file_id: FileId::BOGUS,
123-
ast_id: ROOT_ERASED_FILE_AST_ID,
124-
},
125-
ctx: call_site,
126-
},
118+
span: call_site,
127119
}))
128120
};
129121

crates/hir-expand/src/db.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use either::Either;
1010
use limit::Limit;
1111
use mbe::{syntax_node_to_token_tree, ValueResult};
1212
use rustc_hash::FxHashSet;
13-
use span::SyntaxContextId;
13+
use span::{Span, SyntaxContextId};
1414
use syntax::{
1515
ast::{self, HasAttrs},
1616
AstNode, Parse, SyntaxError, SyntaxNode, SyntaxToken, T,
@@ -57,7 +57,8 @@ impl DeclarativeMacroExpander {
5757
tt: tt::Subtree,
5858
call_id: MacroCallId,
5959
) -> ExpandResult<tt::Subtree> {
60-
let toolchain = &db.crate_graph()[db.lookup_intern_macro_call(call_id).def.krate].toolchain;
60+
let loc = db.lookup_intern_macro_call(call_id);
61+
let toolchain = &db.crate_graph()[loc.def.krate].toolchain;
6162
let new_meta_vars = toolchain.as_ref().map_or(false, |version| {
6263
REQUIREMENT.get_or_init(|| VersionReq::parse(">=1.76").unwrap()).matches(
6364
&base_db::Version {
@@ -80,6 +81,7 @@ impl DeclarativeMacroExpander {
8081
&tt,
8182
|s| s.ctx = apply_mark(db, s.ctx, call_id, self.transparency),
8283
new_meta_vars,
84+
loc.call_site,
8385
)
8486
.map_err(Into::into),
8587
}
@@ -90,6 +92,7 @@ impl DeclarativeMacroExpander {
9092
db: &dyn ExpandDatabase,
9193
tt: tt::Subtree,
9294
krate: CrateId,
95+
call_site: Span,
9396
) -> ExpandResult<tt::Subtree> {
9497
let toolchain = &db.crate_graph()[krate].toolchain;
9598
let new_meta_vars = toolchain.as_ref().map_or(false, |version| {
@@ -108,7 +111,7 @@ impl DeclarativeMacroExpander {
108111
tt::Subtree::empty(tt::DelimSpan::DUMMY),
109112
ExpandError::other(format!("invalid macro definition: {e}")),
110113
),
111-
None => self.mac.expand(&tt, |_| (), new_meta_vars).map_err(Into::into),
114+
None => self.mac.expand(&tt, |_| (), new_meta_vars, call_site).map_err(Into::into),
112115
}
113116
}
114117
}
@@ -315,9 +318,12 @@ pub fn expand_speculative(
315318
let adt = ast::Adt::cast(speculative_args.clone()).unwrap();
316319
expander.expand(db, actual_macro_call, &adt, span_map)
317320
}
318-
MacroDefKind::Declarative(it) => {
319-
db.decl_macro_expander(loc.krate, it).expand_unhygienic(db, tt, loc.def.krate)
320-
}
321+
MacroDefKind::Declarative(it) => db.decl_macro_expander(loc.krate, it).expand_unhygienic(
322+
db,
323+
tt,
324+
loc.def.krate,
325+
loc.call_site,
326+
),
321327
MacroDefKind::BuiltIn(it, _) => it.expand(db, actual_macro_call, &tt).map_err(Into::into),
322328
MacroDefKind::BuiltInEager(it, _) => {
323329
it.expand(db, actual_macro_call, &tt).map_err(Into::into)

crates/hir-expand/src/eager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//!
2020
//! See the full discussion : <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros>
2121
use base_db::CrateId;
22-
use span::SyntaxContextId;
22+
use span::Span;
2323
use syntax::{ted, Parse, SyntaxElement, SyntaxNode, TextSize, WalkEvent};
2424
use triomphe::Arc;
2525

@@ -37,7 +37,7 @@ pub fn expand_eager_macro_input(
3737
krate: CrateId,
3838
macro_call: InFile<ast::MacroCall>,
3939
def: MacroDefId,
40-
call_site: SyntaxContextId,
40+
call_site: Span,
4141
resolver: &dyn Fn(ModPath) -> Option<MacroDefId>,
4242
) -> ExpandResult<Option<MacroCallId>> {
4343
let ast_map = db.ast_id_map(macro_call.file_id);
@@ -102,7 +102,7 @@ fn lazy_expand(
102102
def: &MacroDefId,
103103
macro_call: InFile<ast::MacroCall>,
104104
krate: CrateId,
105-
call_site: SyntaxContextId,
105+
call_site: Span,
106106
) -> ExpandResult<(InFile<Parse<SyntaxNode>>, Arc<ExpansionSpanMap>)> {
107107
let ast_id = db.ast_id_map(macro_call.file_id).ast_id(&macro_call.value);
108108

@@ -122,7 +122,7 @@ fn eager_macro_recur(
122122
mut offset: TextSize,
123123
curr: InFile<SyntaxNode>,
124124
krate: CrateId,
125-
call_site: SyntaxContextId,
125+
call_site: Span,
126126
macro_resolver: &dyn Fn(ModPath) -> Option<MacroDefId>,
127127
) -> ExpandResult<Option<(SyntaxNode, TextSize)>> {
128128
let original = curr.value.clone_for_update();

crates/hir-expand/src/hygiene.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub(super) fn apply_mark(
116116
return apply_mark_internal(db, ctxt, Some(call_id), transparency);
117117
}
118118

119-
let call_site_ctxt = db.lookup_intern_macro_call(call_id).call_site;
119+
let call_site_ctxt = db.lookup_intern_macro_call(call_id).call_site.ctx;
120120
let mut call_site_ctxt = if transparency == Transparency::SemiTransparent {
121121
call_site_ctxt.normalize_to_macros_2_0(db)
122122
} else {

crates/hir-expand/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,20 @@ pub struct MacroCallLoc {
116116
pub krate: CrateId,
117117
/// Some if this is a macro call for an eager macro. Note that this is `None`
118118
/// for the eager input macro file.
119+
// FIXME: This seems bad to save in an interned structure
119120
eager: Option<Arc<EagerCallInfo>>,
120121
pub kind: MacroCallKind,
121-
pub call_site: SyntaxContextId,
122+
pub call_site: Span,
122123
}
123124

125+
// FIXME: Might make sense to intern this? Given it's gonna be the same for a bunch of macro calls
124126
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
125127
pub struct MacroDefId {
126128
pub krate: CrateId,
127129
pub kind: MacroDefKind,
128130
pub local_inner: bool,
129131
pub allow_internal_unsafe: bool,
130-
// pub def_site: SyntaxContextId,
132+
// pub def_site: Span,
131133
}
132134

133135
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -348,7 +350,7 @@ impl MacroDefId {
348350
db: &dyn db::ExpandDatabase,
349351
krate: CrateId,
350352
kind: MacroCallKind,
351-
call_site: SyntaxContextId,
353+
call_site: Span,
352354
) -> MacroCallId {
353355
db.intern_macro_call(MacroCallLoc { def: self, krate, eager: None, kind, call_site })
354356
}

crates/hir-ty/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ doctest = false
1414
[dependencies]
1515
cov-mark = "2.0.0-pre.1"
1616
itertools.workspace = true
17-
arrayvec = "0.7.2"
17+
arrayvec.workspace = true
1818
bitflags.workspace = true
1919
smallvec.workspace = true
2020
ena = "0.14.0"

crates/hir/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ doctest = false
1414
[dependencies]
1515
rustc-hash.workspace = true
1616
either.workspace = true
17-
arrayvec = "0.7.2"
17+
arrayvec.workspace = true
1818
itertools.workspace = true
1919
smallvec.workspace = true
2020
triomphe.workspace = true

0 commit comments

Comments
 (0)