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.

src/libsyntax/parse/lexer/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::diagnostics::plugin::ErrorMap;
99
use crate::with_default_globals;
1010
use std::io;
1111
use std::path::PathBuf;
12-
use syntax_pos::{BytePos, Span, NO_EXPANSION, edition::Edition};
12+
use syntax_pos::{BytePos, Span, edition::Edition};
1313
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
1414
use rustc_data_structures::sync::{Lock, Once};
1515

@@ -61,7 +61,7 @@ fn t1() {
6161
let tok1 = string_reader.next_token();
6262
let tok2 = Token::new(
6363
mk_ident("fn"),
64-
Span::new(BytePos(21), BytePos(23), NO_EXPANSION),
64+
Span::with_root_ctxt(BytePos(21), BytePos(23)),
6565
);
6666
assert_eq!(tok1.kind, tok2.kind);
6767
assert_eq!(tok1.span, tok2.span);
@@ -71,7 +71,7 @@ fn t1() {
7171
assert_eq!(string_reader.pos.clone(), BytePos(28));
7272
let tok4 = Token::new(
7373
mk_ident("main"),
74-
Span::new(BytePos(24), BytePos(28), NO_EXPANSION),
74+
Span::with_root_ctxt(BytePos(24), BytePos(28)),
7575
);
7676
assert_eq!(tok3.kind, tok4.kind);
7777
assert_eq!(tok3.span, tok4.span);

src/libsyntax/parse/lexer/unicode_chars.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use super::StringReader;
55
use errors::{Applicability, DiagnosticBuilder};
6-
use syntax_pos::{BytePos, Pos, Span, NO_EXPANSION, symbol::kw};
6+
use syntax_pos::{BytePos, Pos, Span, symbol::kw};
77
use crate::parse::token;
88

99
#[rustfmt::skip] // for line breaks
@@ -343,7 +343,7 @@ crate fn check_for_substitution<'a>(
343343
None => return None,
344344
};
345345

346-
let span = Span::new(pos, pos + Pos::from_usize(ch.len_utf8()), NO_EXPANSION);
346+
let span = Span::with_root_ctxt(pos, pos + Pos::from_usize(ch.len_utf8()));
347347

348348
let (ascii_name, token) = match ASCII_ARRAY.iter().find(|&&(c, _, _)| c == ascii_char) {
349349
Some((_ascii_char, ascii_name, token)) => (ascii_name, token),
@@ -362,10 +362,9 @@ crate fn check_for_substitution<'a>(
362362
ascii_char, ascii_name
363363
);
364364
err.span_suggestion(
365-
Span::new(
365+
Span::with_root_ctxt(
366366
pos,
367367
pos + Pos::from_usize('“'.len_utf8() + s.len() + '”'.len_utf8()),
368-
NO_EXPANSION,
369368
),
370369
&msg,
371370
format!("\"{}\"", s),

src/libsyntax/parse/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::symbol::{kw, sym};
1212
use crate::tests::{matches_codepattern, string_to_stream, with_error_checking_parse};
1313
use crate::tokenstream::{DelimSpan, TokenTree, TokenStream};
1414
use crate::with_default_globals;
15-
use syntax_pos::{Span, BytePos, Pos, NO_EXPANSION};
15+
use syntax_pos::{Span, BytePos, Pos};
1616

1717
use std::path::PathBuf;
1818

@@ -27,7 +27,7 @@ fn parse_item_from_source_str(name: FileName, source: String, sess: &ParseSess)
2727

2828
// produce a syntax_pos::span
2929
fn sp(a: u32, b: u32) -> Span {
30-
Span::new(BytePos(a), BytePos(b), NO_EXPANSION)
30+
Span::with_root_ctxt(BytePos(a), BytePos(b))
3131
}
3232

3333
/// Parse a string, return an expr

src/libsyntax/source_map/tests.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn t6() {
9191
fn t7() {
9292
// Test span_to_lines for a span ending at the end of source_file
9393
let sm = init_source_map();
94-
let span = Span::new(BytePos(12), BytePos(23), NO_EXPANSION);
94+
let span = Span::with_root_ctxt(BytePos(12), BytePos(23));
9595
let file_lines = sm.span_to_lines(span).unwrap();
9696

9797
assert_eq!(file_lines.file.name, PathBuf::from("blork.rs").into());
@@ -107,7 +107,7 @@ fn span_from_selection(input: &str, selection: &str) -> Span {
107107
assert_eq!(input.len(), selection.len());
108108
let left_index = selection.find('~').unwrap() as u32;
109109
let right_index = selection.rfind('~').map(|x|x as u32).unwrap_or(left_index);
110-
Span::new(BytePos(left_index), BytePos(right_index + 1), NO_EXPANSION)
110+
Span::with_root_ctxt(BytePos(left_index), BytePos(right_index + 1))
111111
}
112112

113113
/// Tests span_to_snippet and span_to_lines for a span converting 3
@@ -137,7 +137,7 @@ fn span_to_snippet_and_lines_spanning_multiple_lines() {
137137
fn t8() {
138138
// Test span_to_snippet for a span ending at the end of source_file
139139
let sm = init_source_map();
140-
let span = Span::new(BytePos(12), BytePos(23), NO_EXPANSION);
140+
let span = Span::with_root_ctxt(BytePos(12), BytePos(23));
141141
let snippet = sm.span_to_snippet(span);
142142

143143
assert_eq!(snippet, Ok("second line".to_string()));
@@ -147,7 +147,7 @@ fn t8() {
147147
fn t9() {
148148
// Test span_to_str for a span ending at the end of source_file
149149
let sm = init_source_map();
150-
let span = Span::new(BytePos(12), BytePos(23), NO_EXPANSION);
150+
let span = Span::with_root_ctxt(BytePos(12), BytePos(23));
151151
let sstr = sm.span_to_string(span);
152152

153153
assert_eq!(sstr, "blork.rs:2:1: 2:12");
@@ -198,10 +198,9 @@ impl SourceMapExtension for SourceMap {
198198
let lo = hi + offset;
199199
hi = lo + substring.len();
200200
if i == n {
201-
let span = Span::new(
201+
let span = Span::with_root_ctxt(
202202
BytePos(lo as u32 + file.start_pos.0),
203203
BytePos(hi as u32 + file.start_pos.0),
204-
NO_EXPANSION,
205204
);
206205
assert_eq!(&self.span_to_snippet(span).unwrap()[..],
207206
substring);

src/libsyntax/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::with_default_globals;
99
use errors::emitter::EmitterWriter;
1010
use errors::Handler;
1111
use rustc_data_structures::sync::Lrc;
12-
use syntax_pos::{BytePos, NO_EXPANSION, Span, MultiSpan};
12+
use syntax_pos::{BytePos, Span, MultiSpan};
1313

1414
use std::io;
1515
use std::io::prelude::*;
@@ -169,7 +169,7 @@ fn make_span(file_text: &str, start: &Position, end: &Position) -> Span {
169169
let start = make_pos(file_text, start);
170170
let end = make_pos(file_text, end) + end.string.len(); // just after matching thing ends
171171
assert!(start <= end);
172-
Span::new(BytePos(start as u32), BytePos(end as u32), NO_EXPANSION)
172+
Span::with_root_ctxt(BytePos(start as u32), BytePos(end as u32))
173173
}
174174

175175
fn make_pos(file_text: &str, pos: &Position) -> usize {

src/libsyntax/tokenstream/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use super::*;
33
use crate::ast::Name;
44
use crate::with_default_globals;
55
use crate::tests::string_to_stream;
6-
use syntax_pos::{Span, BytePos, NO_EXPANSION};
6+
use syntax_pos::{Span, BytePos};
77

88
fn string_to_ts(string: &str) -> TokenStream {
99
string_to_stream(string.to_owned())
1010
}
1111

1212
fn sp(a: u32, b: u32) -> Span {
13-
Span::new(BytePos(a), BytePos(b), NO_EXPANSION)
13+
Span::with_root_ctxt(BytePos(a), BytePos(b))
1414
}
1515

1616
#[test]

src/libsyntax_ext/global_allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn expand(
2929
};
3030

3131
// Generate a bunch of new items using the AllocFnFactory
32-
let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(ecx.current_expansion.id));
32+
let span = item.span.with_ctxt(SyntaxContext::root().apply_mark(ecx.current_expansion.id));
3333
let f = AllocFnFactory {
3434
span,
3535
kind: AllocatorKind::Global,

src/libsyntax_ext/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn expand_test_case(
2929

3030
if !ecx.ecfg.should_test { return vec![]; }
3131

32-
let sp = attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(ecx.current_expansion.id));
32+
let sp = attr_sp.with_ctxt(SyntaxContext::root().apply_mark(ecx.current_expansion.id));
3333
let mut item = anno_item.expect_item();
3434
item = item.map(|mut item| {
3535
item.vis = respan(item.vis.span, ast::VisibilityKind::Public);
@@ -93,7 +93,7 @@ pub fn expand_test_or_bench(
9393
return vec![Annotatable::Item(item)];
9494
}
9595

96-
let ctxt = SyntaxContext::empty().apply_mark(cx.current_expansion.id);
96+
let ctxt = SyntaxContext::root().apply_mark(cx.current_expansion.id);
9797
let (sp, attr_sp) = (item.span.with_ctxt(ctxt), attr_sp.with_ctxt(ctxt));
9898

9999
// Gensym "test" so we can extern crate without conflicting with any local names

src/libsyntax_pos/hygiene.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl HygieneData {
246246

247247
fn marks(&self, mut ctxt: SyntaxContext) -> Vec<(ExpnId, Transparency)> {
248248
let mut marks = Vec::new();
249-
while ctxt != SyntaxContext::empty() {
249+
while ctxt != SyntaxContext::root() {
250250
marks.push((self.outer_expn(ctxt), self.outer_transparency(ctxt)));
251251
ctxt = self.parent_ctxt(ctxt);
252252
}
@@ -286,14 +286,14 @@ impl HygieneData {
286286
}
287287

288288
let call_site_ctxt =
289-
self.expn_info(expn_id).map_or(SyntaxContext::empty(), |info| info.call_site.ctxt());
289+
self.expn_info(expn_id).map_or(SyntaxContext::root(), |info| info.call_site.ctxt());
290290
let mut call_site_ctxt = if transparency == Transparency::SemiTransparent {
291291
self.modern(call_site_ctxt)
292292
} else {
293293
self.modern_and_legacy(call_site_ctxt)
294294
};
295295

296-
if call_site_ctxt == SyntaxContext::empty() {
296+
if call_site_ctxt == SyntaxContext::root() {
297297
return self.apply_mark_internal(ctxt, expn_id, transparency);
298298
}
299299

@@ -400,7 +400,7 @@ pub fn update_dollar_crate_names(mut get_name: impl FnMut(SyntaxContext) -> Symb
400400

401401
impl SyntaxContext {
402402
#[inline]
403-
pub const fn empty() -> Self {
403+
pub const fn root() -> Self {
404404
SyntaxContext(0)
405405
}
406406

@@ -615,7 +615,7 @@ impl Span {
615615
pub fn fresh_expansion(self, parent: ExpnId, expn_info: ExpnInfo) -> Span {
616616
HygieneData::with(|data| {
617617
let expn_id = data.fresh_expn(parent, Some(expn_info));
618-
self.with_ctxt(data.apply_mark(SyntaxContext::empty(), expn_id))
618+
self.with_ctxt(data.apply_mark(SyntaxContext::root(), expn_id))
619619
})
620620
}
621621
}
@@ -775,6 +775,6 @@ impl Encodable for SyntaxContext {
775775

776776
impl Decodable for SyntaxContext {
777777
fn decode<D: Decoder>(_: &mut D) -> Result<SyntaxContext, D::Error> {
778-
Ok(SyntaxContext::empty()) // FIXME(jseyfried) intercrate hygiene
778+
Ok(SyntaxContext::root()) // FIXME(jseyfried) intercrate hygiene
779779
}
780780
}

0 commit comments

Comments
 (0)