Skip to content

Commit caea42f

Browse files
committed
Introduce and use SyntaxContext::outer_expn_info().
It reduces two `hygiene_data` accesses to one on some hot paths.
1 parent 828f6fd commit caea42f

File tree

15 files changed

+39
-30
lines changed

15 files changed

+39
-30
lines changed

src/librustc/lint/internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
113113
.help("try using `Ty` instead")
114114
.emit();
115115
} else {
116-
if ty.span.ctxt().outer().expn_info().is_some() {
116+
if ty.span.ctxt().outer_expn_info().is_some() {
117117
return;
118118
}
119119
if let Some(t) = is_ty_or_ty_ctxt(cx, ty) {

src/librustc/lint/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ pub fn provide(providers: &mut Providers<'_>) {
880880
/// This is used to test whether a lint should not even begin to figure out whether it should
881881
/// be reported on the current node.
882882
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
883-
let info = match span.ctxt().outer().expn_info() {
883+
let info = match span.ctxt().outer_expn_info() {
884884
Some(info) => info,
885885
// no ExpnInfo means this span doesn't come from a macro
886886
None => return false,
@@ -908,7 +908,7 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
908908

909909
/// Returns whether `span` originates in a derive macro's expansion
910910
pub fn in_derive_expansion(span: Span) -> bool {
911-
let info = match span.ctxt().outer().expn_info() {
911+
let info = match span.ctxt().outer_expn_info() {
912912
Some(info) => info,
913913
// no ExpnInfo means this span doesn't come from a macro
914914
None => return false,

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
6565
format: ExpnFormat::CompilerDesugaring(_),
6666
def_site: Some(def_span),
6767
..
68-
}) = span.ctxt().outer().expn_info() {
68+
}) = span.ctxt().outer_expn_info() {
6969
span = def_span;
7070
}
7171

src/librustc_codegen_ssa/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
131131
// at the level above that.
132132
let mut span = source_info.span;
133133
while span.ctxt() != NO_EXPANSION && span.ctxt() != self.mir.span.ctxt() {
134-
if let Some(info) = span.ctxt().outer().expn_info() {
134+
if let Some(info) = span.ctxt().outer_expn_info() {
135135
span = info.call_site;
136136
} else {
137137
break;

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
158158
if fieldpat.node.is_shorthand {
159159
continue;
160160
}
161-
if fieldpat.span.ctxt().outer().expn_info().is_some() {
161+
if fieldpat.span.ctxt().outer_expn_info().is_some() {
162162
// Don't lint if this is a macro expansion: macro authors
163163
// shouldn't have to worry about this kind of style issue
164164
// (Issue #49588)
@@ -1003,7 +1003,7 @@ impl UnreachablePub {
10031003
let mut applicability = Applicability::MachineApplicable;
10041004
match vis.node {
10051005
hir::VisibilityKind::Public if !cx.access_levels.is_reachable(id) => {
1006-
if span.ctxt().outer().expn_info().is_some() {
1006+
if span.ctxt().outer_expn_info().is_some() {
10071007
applicability = Applicability::MaybeIncorrect;
10081008
}
10091009
let def_span = cx.tcx.sess.source_map().def_span(span);

src/librustc_lint/unused.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,8 @@ impl EarlyLintPass for UnusedParens {
391391
// trigger in situations that macro authors shouldn't have to care about, e.g.,
392392
// when a parenthesized token tree matched in one macro expansion is matched as
393393
// an expression in another and used as a fn/method argument (Issue #47775)
394-
if e.span.ctxt().outer().expn_info()
395-
.map_or(false, |info| info.call_site.ctxt().outer()
396-
.expn_info().is_some()) {
394+
if e.span.ctxt().outer_expn_info()
395+
.map_or(false, |info| info.call_site.ctxt().outer_expn_info().is_some()) {
397396
return;
398397
}
399398
let msg = format!("{} argument", call_kind);

src/librustc_resolve/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
762762
ItemKind::Use(..) => {
763763
// don't suggest placing a use before the prelude
764764
// import or other generated ones
765-
if item.span.ctxt().outer().expn_info().is_none() {
765+
if item.span.ctxt().outer_expn_info().is_none() {
766766
self.span = Some(item.span.shrink_to_lo());
767767
self.found_use = true;
768768
return;
@@ -772,7 +772,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
772772
ItemKind::ExternCrate(_) => {}
773773
// but place them before the first other item
774774
_ => if self.span.map_or(true, |span| item.span < span ) {
775-
if item.span.ctxt().outer().expn_info().is_none() {
775+
if item.span.ctxt().outer_expn_info().is_none() {
776776
// don't insert between attributes and an item
777777
if item.attrs.is_empty() {
778778
self.span = Some(item.span.shrink_to_lo());

src/librustc_resolve/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ impl<'a> Resolver<'a> {
413413

414414
// Possibly apply the macro helper hack
415415
if kind == MacroKind::Bang && path.len() == 1 &&
416-
path[0].ident.span.ctxt().outer().expn_info()
416+
path[0].ident.span.ctxt().outer_expn_info()
417417
.map_or(false, |info| info.local_inner_macros) {
418418
let root = Ident::new(kw::DollarCrate, path[0].ident.span);
419419
path.insert(0, Segment::from_ident(root));

src/librustc_typeck/check/demand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
327327

328328
// Check the `expn_info()` to see if this is a macro; if so, it's hard to
329329
// extract the text and make a good suggestion, so don't bother.
330-
let is_macro = sp.ctxt().outer().expn_info().is_some();
330+
let is_macro = sp.ctxt().outer_expn_info().is_some();
331331

332332
match (&expr.node, &expected.sty, &checked_ty.sty) {
333333
(_, &ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (&exp.sty, &check.sty) {

src/librustc_typeck/check/method/suggest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ impl<'a, 'tcx, 'gcx> hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'a, '
892892
hir::ItemKind::Use(..) => {
893893
// Don't suggest placing a `use` before the prelude
894894
// import or other generated ones.
895-
if item.span.ctxt().outer().expn_info().is_none() {
895+
if item.span.ctxt().outer_expn_info().is_none() {
896896
self.span = Some(item.span.shrink_to_lo());
897897
self.found_use = true;
898898
return;
@@ -902,7 +902,7 @@ impl<'a, 'tcx, 'gcx> hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'a, '
902902
hir::ItemKind::ExternCrate(_) => {}
903903
// ...but do place them before the first other item.
904904
_ => if self.span.map_or(true, |span| item.span < span ) {
905-
if item.span.ctxt().outer().expn_info().is_none() {
905+
if item.span.ctxt().outer_expn_info().is_none() {
906906
// Don't insert between attributes and an item.
907907
if item.attrs.is_empty() {
908908
self.span = Some(item.span.shrink_to_lo());

0 commit comments

Comments
 (0)