Skip to content

Commit 533a526

Browse files
committed
auto merge of #13152 : huonw/rust/wtf-are-things-in-spans, r=alexcrichton
Add some docs to ExpnInfo. Add a single overlooked `new_span` call to the folder (I'm pretty sure nothing reads this span, though, so it's probably pointless).
2 parents 2c71cdf + 6419848 commit 533a526

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Diff for: src/libsyntax/codemap.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ to the original source.
8888
pub struct Span {
8989
lo: BytePos,
9090
hi: BytePos,
91+
/// Information about where the macro came from, if this piece of
92+
/// code was created by a macro expansion.
9193
expn_info: Option<@ExpnInfo>
9294
}
9395

@@ -162,26 +164,47 @@ pub struct LocWithOpt {
162164
pub struct FileMapAndLine {fm: Rc<FileMap>, line: uint}
163165
pub struct FileMapAndBytePos {fm: Rc<FileMap>, pos: BytePos}
164166

167+
/// The syntax with which a macro was invoked.
165168
#[deriving(Clone, Hash, Show)]
166169
pub enum MacroFormat {
167-
// e.g. #[deriving(...)] <item>
170+
/// e.g. #[deriving(...)] <item>
168171
MacroAttribute,
169-
// e.g. `format!()`
172+
/// e.g. `format!()`
170173
MacroBang
171174
}
172175

173176
#[deriving(Clone, Hash, Show)]
174177
pub struct NameAndSpan {
178+
/// The name of the macro that was invoked to create the thing
179+
/// with this Span.
175180
name: ~str,
176-
// the format with which the macro was invoked.
181+
/// The format with which the macro was invoked.
177182
format: MacroFormat,
183+
/// The span of the macro definition itself. The macro may not
184+
/// have a sensible definition span (e.g. something defined
185+
/// completely inside libsyntax) in which case this is None.
178186
span: Option<Span>
179187
}
180188

181189
/// Extra information for tracking macro expansion of spans
182190
#[deriving(Hash, Show)]
183191
pub struct ExpnInfo {
192+
/// The location of the actual macro invocation, e.g. `let x =
193+
/// foo!();`
194+
///
195+
/// This may recursively refer to other macro invocations, e.g. if
196+
/// `foo!()` invoked `bar!()` internally, and there was an
197+
/// expression inside `bar!`; the call_site of the expression in
198+
/// the expansion would point to the `bar!` invocation; that
199+
/// call_site span would have its own ExpnInfo, with the call_site
200+
/// pointing to the `foo!` invocation.
184201
call_site: Span,
202+
/// Information about the macro and its definition.
203+
///
204+
/// The `callee` of the inner expression in the `call_site`
205+
/// example would point to the `macro_rules! bar { ... }` and that
206+
/// of the `bar!()` invocation would point to the `macro_rules!
207+
/// foo { ... }`.
185208
callee: NameAndSpan
186209
}
187210

Diff for: src/libsyntax/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub trait Folder {
134134
node.move_iter().map(|node| {
135135
@Spanned {
136136
node: node,
137-
span: d.span,
137+
span: self.new_span(d.span),
138138
}
139139
}).collect()
140140
}

0 commit comments

Comments
 (0)