Don't use guess_head_span
in predicates_of
for foreign span
Previously, the result of `predicates_of` for a foreign trait would depend on the *current* state of the corresponding source file in the foreign crate. This could lead to ICEs during incremental compilation, since the on-disk contents of the upstream source file could potentially change without the upstream crate being recompiled. Additionally, this ensure that that the metadata we produce for a crate only depends on its *compiled* upstream dependencies (e.g an rlib or rmeta file), *not* the current on-disk state of the upstream crate source files.
This commit is contained in:
parent
ac50a53359
commit
c9157efad6
9 changed files with 97 additions and 15 deletions
|
@ -567,6 +567,17 @@ impl SourceMap {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns whether or not this span points into a file
|
||||
/// in the current crate. This may be `false` for spans
|
||||
/// produced by a macro expansion, or for spans associated
|
||||
/// with the definition of an item in a foreign crate
|
||||
pub fn is_local_span(&self, sp: Span) -> bool {
|
||||
let local_begin = self.lookup_byte_offset(sp.lo());
|
||||
let local_end = self.lookup_byte_offset(sp.hi());
|
||||
// This might be a weird span that covers multiple files
|
||||
local_begin.sf.src.is_some() && local_end.sf.src.is_some()
|
||||
}
|
||||
|
||||
/// Returns the source snippet as `String` corresponding to the given `Span`.
|
||||
pub fn span_to_snippet(&self, sp: Span) -> Result<String, SpanSnippetError> {
|
||||
self.span_to_source(sp, |src, start_index, end_index| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue