Rollup merge of #112706 - WaffleLapkin:syntax_context_is_root, r=petrochenkov
Add `SyntaxContext::is_root` Makes the code a tad nicer.
This commit is contained in:
commit
56c96d7552
@ -9,7 +9,7 @@ use rustc_session::parse::{feature_err, ParseSess};
|
|||||||
use rustc_span::symbol::{kw, sym, Ident};
|
use rustc_span::symbol::{kw, sym, Ident};
|
||||||
|
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::{Span, SyntaxContext};
|
use rustc_span::Span;
|
||||||
|
|
||||||
const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
|
const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
|
||||||
`ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, \
|
`ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, \
|
||||||
@ -72,7 +72,7 @@ pub(super) fn parse(
|
|||||||
// `SyntaxContext::root()` from a foreign crate will
|
// `SyntaxContext::root()` from a foreign crate will
|
||||||
// have the edition of that crate (which we manually
|
// have the edition of that crate (which we manually
|
||||||
// retrieve via the `edition` parameter).
|
// retrieve via the `edition` parameter).
|
||||||
if span.ctxt() == SyntaxContext::root() {
|
if span.ctxt().is_root() {
|
||||||
edition
|
edition
|
||||||
} else {
|
} else {
|
||||||
span.edition()
|
span.edition()
|
||||||
|
@ -3,7 +3,7 @@ use rustc_middle::hir;
|
|||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::config::MirSpanview;
|
use rustc_session::config::MirSpanview;
|
||||||
use rustc_span::{BytePos, Pos, Span, SyntaxContext};
|
use rustc_span::{BytePos, Pos, Span};
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
@ -327,7 +327,7 @@ fn compute_block_span(data: &BasicBlockData<'_>, body_span: Span) -> Span {
|
|||||||
let mut span = data.terminator().source_info.span;
|
let mut span = data.terminator().source_info.span;
|
||||||
for statement_span in data.statements.iter().map(|statement| statement.source_info.span) {
|
for statement_span in data.statements.iter().map(|statement| statement.source_info.span) {
|
||||||
// Only combine Spans from the root context, and within the function's body_span.
|
// Only combine Spans from the root context, and within the function's body_span.
|
||||||
if statement_span.ctxt() == SyntaxContext::root() && body_span.contains(statement_span) {
|
if statement_span.ctxt().is_root() && body_span.contains(statement_span) {
|
||||||
span = span.to(statement_span);
|
span = span.to(statement_span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -507,7 +507,7 @@ impl HygieneData {
|
|||||||
self.normalize_to_macro_rules(call_site_ctxt)
|
self.normalize_to_macro_rules(call_site_ctxt)
|
||||||
};
|
};
|
||||||
|
|
||||||
if call_site_ctxt == SyntaxContext::root() {
|
if call_site_ctxt.is_root() {
|
||||||
return self.apply_mark_internal(ctxt, expn_id, transparency);
|
return self.apply_mark_internal(ctxt, expn_id, transparency);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,12 +671,17 @@ impl SyntaxContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn as_u32(self) -> u32 {
|
pub const fn is_root(self) -> bool {
|
||||||
|
self.0 == SyntaxContext::root().as_u32()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub(crate) const fn as_u32(self) -> u32 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn from_u32(raw: u32) -> SyntaxContext {
|
pub(crate) const fn from_u32(raw: u32) -> SyntaxContext {
|
||||||
SyntaxContext(raw)
|
SyntaxContext(raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1500,7 +1505,7 @@ impl<CTX: HashStableContext> HashStable<CTX> for SyntaxContext {
|
|||||||
const TAG_EXPANSION: u8 = 0;
|
const TAG_EXPANSION: u8 = 0;
|
||||||
const TAG_NO_EXPANSION: u8 = 1;
|
const TAG_NO_EXPANSION: u8 = 1;
|
||||||
|
|
||||||
if *self == SyntaxContext::root() {
|
if self.is_root() {
|
||||||
TAG_NO_EXPANSION.hash_stable(ctx, hasher);
|
TAG_NO_EXPANSION.hash_stable(ctx, hasher);
|
||||||
} else {
|
} else {
|
||||||
TAG_EXPANSION.hash_stable(ctx, hasher);
|
TAG_EXPANSION.hash_stable(ctx, hasher);
|
||||||
|
@ -826,9 +826,9 @@ impl Span {
|
|||||||
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
|
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
|
||||||
// have an incomplete span than a completely nonsensical one.
|
// have an incomplete span than a completely nonsensical one.
|
||||||
if span_data.ctxt != end_data.ctxt {
|
if span_data.ctxt != end_data.ctxt {
|
||||||
if span_data.ctxt == SyntaxContext::root() {
|
if span_data.ctxt.is_root() {
|
||||||
return end;
|
return end;
|
||||||
} else if end_data.ctxt == SyntaxContext::root() {
|
} else if end_data.ctxt.is_root() {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
// Both spans fall within a macro.
|
// Both spans fall within a macro.
|
||||||
@ -837,7 +837,7 @@ impl Span {
|
|||||||
Span::new(
|
Span::new(
|
||||||
cmp::min(span_data.lo, end_data.lo),
|
cmp::min(span_data.lo, end_data.lo),
|
||||||
cmp::max(span_data.hi, end_data.hi),
|
cmp::max(span_data.hi, end_data.hi),
|
||||||
if span_data.ctxt == SyntaxContext::root() { end_data.ctxt } else { span_data.ctxt },
|
if span_data.ctxt.is_root() { end_data.ctxt } else { span_data.ctxt },
|
||||||
if span_data.parent == end_data.parent { span_data.parent } else { None },
|
if span_data.parent == end_data.parent { span_data.parent } else { None },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -855,7 +855,7 @@ impl Span {
|
|||||||
Span::new(
|
Span::new(
|
||||||
span.hi,
|
span.hi,
|
||||||
end.lo,
|
end.lo,
|
||||||
if end.ctxt == SyntaxContext::root() { end.ctxt } else { span.ctxt },
|
if end.ctxt.is_root() { end.ctxt } else { span.ctxt },
|
||||||
if span.parent == end.parent { span.parent } else { None },
|
if span.parent == end.parent { span.parent } else { None },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -879,9 +879,9 @@ impl Span {
|
|||||||
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
|
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
|
||||||
// have an incomplete span than a completely nonsensical one.
|
// have an incomplete span than a completely nonsensical one.
|
||||||
if span_data.ctxt != end_data.ctxt {
|
if span_data.ctxt != end_data.ctxt {
|
||||||
if span_data.ctxt == SyntaxContext::root() {
|
if span_data.ctxt.is_root() {
|
||||||
return end;
|
return end;
|
||||||
} else if end_data.ctxt == SyntaxContext::root() {
|
} else if end_data.ctxt.is_root() {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
// Both spans fall within a macro.
|
// Both spans fall within a macro.
|
||||||
@ -890,7 +890,7 @@ impl Span {
|
|||||||
Span::new(
|
Span::new(
|
||||||
span_data.lo,
|
span_data.lo,
|
||||||
end_data.lo,
|
end_data.lo,
|
||||||
if end_data.ctxt == SyntaxContext::root() { end_data.ctxt } else { span_data.ctxt },
|
if end_data.ctxt.is_root() { end_data.ctxt } else { span_data.ctxt },
|
||||||
if span_data.parent == end_data.parent { span_data.parent } else { None },
|
if span_data.parent == end_data.parent { span_data.parent } else { None },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user