Skip to content

Commit 6a5f211

Browse files
xFrednetVeetaha
andauthored
API, Rustc: Rework spans (and fix a few errors) (#218)
* API: `Span` the documentation bow * Rustc: Update `Span` conversion * API: Add `SpanSource` information * Rustc: Update `Span` conversion backend * Rustc: Fix invalid `LexExpr` id and resugared `Span`s * API: Prettify `Span` debug string * Rustc: Fix `QuestionMarkExpr` resugar * uilints: Bless after `Span` rework and prettification * Chore: Address PR review Co-authored-by: Veetaha <[email protected]> --------- Co-authored-by: Veetaha <[email protected]>
1 parent 878f1b8 commit 6a5f211

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1415
-1360
lines changed

marker_adapter/src/context.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use marker_api::{
55
ast::{
66
item::{Body, ItemKind},
77
ty::SemTyKind,
8-
BodyId, ExprId, ItemId, Span, SpanId, SymbolId, TyDefId,
8+
BodyId, ExpnId, ExpnInfo, ExprId, FileInfo, FilePos, ItemId, Span, SpanId, SpanPos, SpanSource, SymbolId,
9+
TyDefId,
910
},
1011
context::DriverCallbacks,
1112
diagnostic::{Diagnostic, EmissionNode},
@@ -47,6 +48,9 @@ impl<'ast> DriverContextWrapper<'ast> {
4748
expr_ty,
4849
span,
4950
span_snippet,
51+
span_source,
52+
span_pos_to_file_loc,
53+
span_expn_info,
5054
symbol_str,
5155
resolve_method_target,
5256
}
@@ -55,7 +59,7 @@ impl<'ast> DriverContextWrapper<'ast> {
5559

5660
// False positive because `EmissionNode` are non-exhaustive
5761
#[allow(improper_ctypes_definitions)]
58-
extern "C" fn lint_level_at(data: &(), lint: &'static Lint, node: EmissionNode) -> Level {
62+
extern "C" fn lint_level_at<'ast>(data: &'ast (), lint: &'static Lint, node: EmissionNode) -> Level {
5963
unsafe { as_driver_cx(data) }.lint_level_at(lint, node)
6064
}
6165

@@ -91,11 +95,29 @@ extern "C" fn span_snippet<'ast>(data: &'ast (), span: &Span<'ast>) -> ffi::FfiO
9195
unsafe { as_driver_cx(data) }.span_snippet(span).map(Into::into).into()
9296
}
9397

98+
// False positive because `SpanSource` is non-exhaustive
99+
#[allow(improper_ctypes_definitions)]
100+
extern "C" fn span_source<'ast>(data: &'ast (), span: &Span<'_>) -> SpanSource<'ast> {
101+
unsafe { as_driver_cx(data) }.span_source(span)
102+
}
103+
104+
extern "C" fn span_pos_to_file_loc<'ast>(
105+
data: &'ast (),
106+
file: &FileInfo<'ast>,
107+
pos: SpanPos,
108+
) -> ffi::FfiOption<FilePos<'ast>> {
109+
unsafe { as_driver_cx(data) }.span_pos_to_file_loc(file, pos).into()
110+
}
111+
112+
extern "C" fn span_expn_info<'ast>(data: &'ast (), expn_id: ExpnId) -> FfiOption<&'ast ExpnInfo<'ast>> {
113+
unsafe { as_driver_cx(data) }.span_expn_info(expn_id).into()
114+
}
115+
94116
extern "C" fn symbol_str<'ast>(data: &'ast (), sym: SymbolId) -> ffi::FfiStr<'ast> {
95117
unsafe { as_driver_cx(data) }.symbol_str(sym).into()
96118
}
97119

98-
extern "C" fn resolve_method_target(data: &(), id: ExprId) -> ItemId {
120+
extern "C" fn resolve_method_target<'ast>(data: &'ast (), id: ExprId) -> ItemId {
99121
unsafe { as_driver_cx(data) }.resolve_method_target(id)
100122
}
101123

@@ -117,7 +139,10 @@ pub trait DriverContext<'ast> {
117139

118140
fn expr_ty(&'ast self, expr: ExprId) -> SemTyKind<'ast>;
119141
fn span(&'ast self, owner: SpanId) -> &'ast Span<'ast>;
120-
fn span_snippet(&'ast self, span: &Span<'ast>) -> Option<&'ast str>;
142+
fn span_snippet(&'ast self, span: &Span<'_>) -> Option<&'ast str>;
143+
fn span_source(&'ast self, span: &Span<'_>) -> SpanSource<'ast>;
144+
fn span_expn_info(&'ast self, expn_id: ExpnId) -> Option<&'ast ExpnInfo<'ast>>;
145+
fn span_pos_to_file_loc(&'ast self, file: &FileInfo<'ast>, pos: SpanPos) -> Option<FilePos<'ast>>;
121146
fn symbol_str(&'ast self, api_id: SymbolId) -> &'ast str;
122147
fn resolve_method_target(&'ast self, id: ExprId) -> ItemId;
123148
}

marker_api/src/ast/common/id.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ new_id! {
6969
pub GenericId: u64
7070
}
7171

72+
new_id! {
73+
/// This ID uniquely identifies a macro during linting.
74+
pub MacroId: u64
75+
}
76+
7277
new_id! {
7378
/// This ID uniquely identifies a body during linting.
7479
pub BodyId: u64
@@ -117,6 +122,15 @@ new_id! {
117122
pub(crate) SpanSrcId: u32
118123
}
119124

125+
new_id! {
126+
/// **Unstable**
127+
///
128+
/// This id is used to identify a specific expansion. This type is only intended for internal
129+
/// use. For now it's only intended for drivers to map spans back
130+
#[cfg_attr(feature = "driver-api", visibility::make(pub))]
131+
pub(crate) ExpnId: u64
132+
}
133+
120134
new_id! {
121135
/// **Unstable**
122136
///

0 commit comments

Comments
 (0)