Skip to content

Commit 67d6ce4

Browse files
committed
syntax_pos: NO_EXPANSION/SyntaxContext::empty() -> SyntaxContext::root()
For consistency with `ExpnId::root`. Also introduce a helper `Span::with_root_ctxt` for creating spans with `SyntaxContext::root()` context
1 parent dfcbe75 commit 67d6ce4

File tree

20 files changed

+53
-53
lines changed

20 files changed

+53
-53
lines changed

src/librustc/ich/hcx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
350350
let line_col_len = col | line | len;
351351
std_hash::Hash::hash(&line_col_len, hasher);
352352

353-
if span.ctxt == SyntaxContext::empty() {
353+
if span.ctxt == SyntaxContext::root() {
354354
TAG_NO_EXPANSION.hash_stable(hcx, hasher);
355355
} else {
356356
TAG_EXPANSION.hash_stable(hcx, hasher);

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx> {
592592
// `SyntaxContextData::prev_ctxt` or `SyntaxContextData::opaque`. These things
593593
// don't seem to be used after HIR lowering, so everything should be fine
594594
// as long as incremental compilation does not kick in before that.
595-
let location = || Span::new(lo, hi, SyntaxContext::empty());
595+
let location = || Span::with_root_ctxt(lo, hi);
596596
let recover_from_expn_info = |this: &Self, expn_info, pos| {
597597
let span = location().fresh_expansion(ExpnId::root(), expn_info);
598598
this.synthetic_expansion_infos.borrow_mut().insert(pos, span.ctxt());
@@ -816,7 +816,7 @@ where
816816
col_lo.encode(self)?;
817817
len.encode(self)?;
818818

819-
if span_data.ctxt == SyntaxContext::empty() {
819+
if span_data.ctxt == SyntaxContext::root() {
820820
TAG_NO_EXPANSION_INFO.encode(self)
821821
} else {
822822
let (expn_id, expn_info) = span_data.ctxt.outer_expn_with_info();

src/librustc_errors/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ use syntax_pos::{BytePos,
4343
SourceFile,
4444
FileName,
4545
MultiSpan,
46-
Span,
47-
NO_EXPANSION};
46+
Span};
4847

4948
/// Indicates the confidence in the correctness of a suggestion.
5049
///
@@ -189,7 +188,7 @@ impl CodeSuggestion {
189188
// Find the bounding span.
190189
let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap();
191190
let hi = substitution.parts.iter().map(|part| part.span.hi()).min().unwrap();
192-
let bounding_span = Span::new(lo, hi, NO_EXPANSION);
191+
let bounding_span = Span::with_root_ctxt(lo, hi);
193192
let lines = cm.span_to_lines(bounding_span).unwrap();
194193
assert!(!lines.lines.is_empty());
195194

src/librustc_metadata/cstore_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use syntax::ext::proc_macro::BangProcMacro;
3535
use syntax::parse::source_file_to_stream;
3636
use syntax::parse::parser::emit_unclosed_delims;
3737
use syntax::symbol::{Symbol, sym};
38-
use syntax_pos::{Span, NO_EXPANSION, FileName};
38+
use syntax_pos::{Span, FileName};
3939
use rustc_data_structures::bit_set::BitSet;
4040

4141
macro_rules! provide {
@@ -443,7 +443,7 @@ impl cstore::CStore {
443443
let source_name = FileName::Macros(macro_full_name);
444444

445445
let source_file = sess.parse_sess.source_map().new_source_file(source_name, def.body);
446-
let local_span = Span::new(source_file.start_pos, source_file.end_pos, NO_EXPANSION);
446+
let local_span = Span::with_root_ctxt(source_file.start_pos, source_file.end_pos);
447447
let (body, mut errors) = source_file_to_stream(&sess.parse_sess, source_file, None);
448448
emit_unclosed_delims(&mut errors, &sess.diagnostic());
449449

src/librustc_metadata/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use syntax::source_map;
3232
use syntax::symbol::{Symbol, sym};
3333
use syntax::ext::base::{MacroKind, SyntaxExtension};
3434
use syntax::ext::hygiene::ExpnId;
35-
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION};
35+
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP};
3636
use log::debug;
3737

3838
pub struct DecodeContext<'a, 'tcx> {
@@ -344,7 +344,7 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
344344
let hi = (hi + source_file.translated_source_file.start_pos)
345345
- source_file.original_start_pos;
346346

347-
Ok(Span::new(lo, hi, NO_EXPANSION))
347+
Ok(Span::with_root_ctxt(lo, hi))
348348
}
349349
}
350350

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ impl<'a> Resolver<'a> {
14301430
}
14311431
let (general_span, modern_span) = if ident.name == kw::SelfUpper {
14321432
// FIXME(jseyfried) improve `Self` hygiene
1433-
let empty_span = ident.span.with_ctxt(SyntaxContext::empty());
1433+
let empty_span = ident.span.with_ctxt(SyntaxContext::root());
14341434
(empty_span, empty_span)
14351435
} else if ns == TypeNS {
14361436
let modern_span = ident.span.modern();

src/libsyntax/ext/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ impl<'a> ExtCtxt<'a> {
762762
}
763763
}
764764
pub fn backtrace(&self) -> SyntaxContext {
765-
SyntaxContext::empty().apply_mark(self.current_expansion.id)
765+
SyntaxContext::root().apply_mark(self.current_expansion.id)
766766
}
767767

768768
/// Returns span for the macro which originally caused the current expansion to happen.

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ impl<'a> Parser<'a> {
759759
let msg = format!("macro expansion ignores token `{}` and any following",
760760
self.this_token_to_string());
761761
// Avoid emitting backtrace info twice.
762-
let def_site_span = self.token.span.with_ctxt(SyntaxContext::empty());
762+
let def_site_span = self.token.span.with_ctxt(SyntaxContext::root());
763763
let mut err = self.diagnostic().struct_span_err(def_site_span, &msg);
764764
err.span_label(span, "caused by the macro expansion here");
765765
let msg = format!(

src/libsyntax/ext/proc_macro_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<'a> Rustc<'a> {
365365
let location = cx.current_expansion.id.expn_info().unwrap().call_site;
366366
let to_span = |transparency| {
367367
location.with_ctxt(
368-
SyntaxContext::empty()
368+
SyntaxContext::root()
369369
.apply_mark_with_transparency(cx.current_expansion.id, transparency),
370370
)
371371
};

src/libsyntax/parse/lexer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::symbol::{sym, Symbol};
44
use crate::parse::unescape_error_reporting::{emit_unescape_error, push_escaped_char};
55

66
use errors::{FatalError, DiagnosticBuilder};
7-
use syntax_pos::{BytePos, Pos, Span, NO_EXPANSION};
7+
use syntax_pos::{BytePos, Pos, Span};
88
use rustc_lexer::Base;
99
use rustc_lexer::unescape;
1010

@@ -84,7 +84,7 @@ impl<'a> StringReader<'a> {
8484

8585

8686
fn mk_sp(&self, lo: BytePos, hi: BytePos) -> Span {
87-
self.override_span.unwrap_or_else(|| Span::new(lo, hi, NO_EXPANSION))
87+
self.override_span.unwrap_or_else(|| Span::with_root_ctxt(lo, hi))
8888
}
8989

9090
/// Returns the next token, including trivia like whitespace or comments.

0 commit comments

Comments
 (0)