Skip to content

Commit 16918a8

Browse files
committed
Rename some things in syntax_pos/hygiene
More consistent with other naming: ExpnFormat -> ExpnKind ExpnKind::name -> ExpnKind::descr DesugaringKind::name -> DesugaringKind::descr Shorter, no tautology: CompilerDesugaring -> Desugaring CompilerDesugaringKind -> DesugaringKind
1 parent ec376c7 commit 16918a8

File tree

25 files changed

+111
-110
lines changed

25 files changed

+111
-110
lines changed

src/librustc/hir/lowering.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ use syntax::ast::*;
6262
use syntax::errors;
6363
use syntax::ext::hygiene::{Mark, SyntaxContext};
6464
use syntax::print::pprust;
65-
use syntax::source_map::{self, respan, ExpnInfo, CompilerDesugaringKind, Spanned};
66-
use syntax::source_map::CompilerDesugaringKind::CondTemporary;
65+
use syntax::source_map::{respan, ExpnInfo, ExpnKind, DesugaringKind, Spanned};
6766
use syntax::std_inject;
6867
use syntax::symbol::{kw, sym, Symbol};
6968
use syntax::tokenstream::{TokenStream, TokenTree};
@@ -872,15 +871,15 @@ impl<'a> LoweringContext<'a> {
872871
/// allowed inside this span.
873872
fn mark_span_with_reason(
874873
&self,
875-
reason: CompilerDesugaringKind,
874+
reason: DesugaringKind,
876875
span: Span,
877876
allow_internal_unstable: Option<Lrc<[Symbol]>>,
878877
) -> Span {
879878
let mark = Mark::fresh(Mark::root());
880879
mark.set_expn_info(ExpnInfo {
881880
def_site: Some(span),
882881
allow_internal_unstable,
883-
..ExpnInfo::default(source_map::CompilerDesugaring(reason), span, self.sess.edition())
882+
..ExpnInfo::default(ExpnKind::Desugaring(reason), span, self.sess.edition())
884883
});
885884
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
886885
}
@@ -1188,7 +1187,7 @@ impl<'a> LoweringContext<'a> {
11881187
};
11891188

11901189
let unstable_span = self.mark_span_with_reason(
1191-
CompilerDesugaringKind::Async,
1190+
DesugaringKind::Async,
11921191
span,
11931192
self.allow_gen_future.clone(),
11941193
);
@@ -1733,7 +1732,7 @@ impl<'a> LoweringContext<'a> {
17331732
// Not tracking it makes lints in rustc and clippy very fragile, as
17341733
// frequently opened issues show.
17351734
let exist_ty_span = self.mark_span_with_reason(
1736-
CompilerDesugaringKind::ExistentialType,
1735+
DesugaringKind::ExistentialType,
17371736
span,
17381737
None,
17391738
);
@@ -2603,7 +2602,7 @@ impl<'a> LoweringContext<'a> {
26032602
let span = output.span();
26042603

26052604
let exist_ty_span = self.mark_span_with_reason(
2606-
CompilerDesugaringKind::Async,
2605+
DesugaringKind::Async,
26072606
span,
26082607
None,
26092608
);
@@ -3275,7 +3274,7 @@ impl<'a> LoweringContext<'a> {
32753274
};
32763275

32773276
let desugared_span =
3278-
this.mark_span_with_reason(CompilerDesugaringKind::Async, span, None);
3277+
this.mark_span_with_reason(DesugaringKind::Async, span, None);
32793278

32803279
// Construct an argument representing `__argN: <ty>` to replace the argument of the
32813280
// async function.
@@ -4410,7 +4409,9 @@ impl<'a> LoweringContext<'a> {
44104409
_ => {
44114410
// Lower condition:
44124411
let cond = self.lower_expr(cond);
4413-
let span_block = self.mark_span_with_reason(CondTemporary, cond.span, None);
4412+
let span_block = self.mark_span_with_reason(
4413+
DesugaringKind::CondTemporary, cond.span, None
4414+
);
44144415
// Wrap in a construct equivalent to `{ let _t = $cond; _t }`
44154416
// to preserve drop semantics since `if cond { ... }` does not
44164417
// let temporaries live outside of `cond`.
@@ -4469,7 +4470,9 @@ impl<'a> LoweringContext<'a> {
44694470

44704471
// Lower condition:
44714472
let cond = this.with_loop_condition_scope(|this| this.lower_expr(cond));
4472-
let span_block = this.mark_span_with_reason(CondTemporary, cond.span, None);
4473+
let span_block = this.mark_span_with_reason(
4474+
DesugaringKind::CondTemporary, cond.span, None
4475+
);
44734476
// Wrap in a construct equivalent to `{ let _t = $cond; _t }`
44744477
// to preserve drop semantics since `while cond { ... }` does not
44754478
// let temporaries live outside of `cond`.
@@ -4508,7 +4511,7 @@ impl<'a> LoweringContext<'a> {
45084511
ExprKind::TryBlock(ref body) => {
45094512
self.with_catch_scope(body.id, |this| {
45104513
let unstable_span = this.mark_span_with_reason(
4511-
CompilerDesugaringKind::TryBlock,
4514+
DesugaringKind::TryBlock,
45124515
body.span,
45134516
this.allow_try_trait.clone(),
45144517
);
@@ -4836,7 +4839,7 @@ impl<'a> LoweringContext<'a> {
48364839
let mut head = self.lower_expr(head);
48374840
let head_sp = head.span;
48384841
let desugared_span = self.mark_span_with_reason(
4839-
CompilerDesugaringKind::ForLoop,
4842+
DesugaringKind::ForLoop,
48404843
head_sp,
48414844
None,
48424845
);
@@ -4990,13 +4993,13 @@ impl<'a> LoweringContext<'a> {
49904993
// }
49914994

49924995
let unstable_span = self.mark_span_with_reason(
4993-
CompilerDesugaringKind::QuestionMark,
4996+
DesugaringKind::QuestionMark,
49944997
e.span,
49954998
self.allow_try_trait.clone(),
49964999
);
49975000
let try_span = self.sess.source_map().end_point(e.span);
49985001
let try_span = self.mark_span_with_reason(
4999-
CompilerDesugaringKind::QuestionMark,
5002+
DesugaringKind::QuestionMark,
50005003
try_span,
50015004
self.allow_try_trait.clone(),
50025005
);
@@ -5811,12 +5814,12 @@ impl<'a> LoweringContext<'a> {
58115814
}
58125815
}
58135816
let span = self.mark_span_with_reason(
5814-
CompilerDesugaringKind::Await,
5817+
DesugaringKind::Await,
58155818
await_span,
58165819
None,
58175820
);
58185821
let gen_future_span = self.mark_span_with_reason(
5819-
CompilerDesugaringKind::Await,
5822+
DesugaringKind::Await,
58205823
await_span,
58215824
self.allow_gen_future.clone(),
58225825
);

src/librustc/ich/impls_syntax.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency {
398398

399399
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
400400
call_site,
401-
format,
401+
kind,
402402
def_site,
403403
default_transparency,
404404
allow_internal_unstable,
@@ -407,13 +407,13 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
407407
edition
408408
});
409409

410-
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnFormat {
410+
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnKind {
411411
MacroAttribute(sym),
412412
MacroBang(sym),
413-
CompilerDesugaring(kind)
413+
Desugaring(kind)
414414
});
415415

416-
impl_stable_hash_for!(enum ::syntax_pos::hygiene::CompilerDesugaringKind {
416+
impl_stable_hash_for!(enum ::syntax_pos::hygiene::DesugaringKind {
417417
CondTemporary,
418418
Async,
419419
Await,

src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::infer::InferCtxt;
55
use crate::infer::type_variable::TypeVariableOriginKind;
66
use crate::ty::{self, Ty, Infer, TyVar};
77
use crate::ty::print::Print;
8-
use syntax::source_map::CompilerDesugaringKind;
8+
use syntax::source_map::DesugaringKind;
99
use syntax_pos::Span;
1010
use errors::DiagnosticBuilder;
1111

@@ -194,12 +194,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
194194
));
195195
} else if let Some(pattern) = local_visitor.found_local_pattern {
196196
if let Some(simple_ident) = pattern.simple_ident() {
197-
match pattern.span.compiler_desugaring_kind() {
197+
match pattern.span.desugaring_kind() {
198198
None => labels.push((
199199
pattern.span,
200200
format!("consider giving `{}` {}", simple_ident, suffix),
201201
)),
202-
Some(CompilerDesugaringKind::ForLoop) => labels.push((
202+
Some(DesugaringKind::ForLoop) => labels.push((
203203
pattern.span,
204204
"the element type for this iterator is not specified".to_owned(),
205205
)),

src/librustc/lint/internal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ impl EarlyLintPass for LintPassImpl {
247247
}
248248

249249
fn is_lint_pass_expansion(expn_info: &ExpnInfo) -> bool {
250-
if expn_info.format.name() == sym::impl_lint_pass {
250+
if expn_info.kind.descr() == sym::impl_lint_pass {
251251
true
252252
} else if let Some(info) = expn_info.call_site.ctxt().outer_expn_info() {
253-
info.format.name() == sym::declare_lint_pass
253+
info.kind.descr() == sym::declare_lint_pass
254254
} else {
255255
false
256256
}

src/librustc/lint/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::util::nodemap::NodeMap;
3535
use errors::{DiagnosticBuilder, DiagnosticId};
3636
use std::{hash, ptr};
3737
use syntax::ast;
38-
use syntax::source_map::{MultiSpan, ExpnFormat, CompilerDesugaringKind};
38+
use syntax::source_map::{MultiSpan, ExpnKind, DesugaringKind};
3939
use syntax::early_buffered_lints::BufferedEarlyLintId;
4040
use syntax::edition::Edition;
4141
use syntax::symbol::{Symbol, sym};
@@ -883,11 +883,11 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
883883
None => return false,
884884
};
885885

886-
match info.format {
887-
ExpnFormat::MacroAttribute(..) => true, // definitely a plugin
888-
ExpnFormat::CompilerDesugaring(CompilerDesugaringKind::ForLoop) => false,
889-
ExpnFormat::CompilerDesugaring(_) => true, // well, it's "external"
890-
ExpnFormat::MacroBang(..) => {
886+
match info.kind {
887+
ExpnKind::MacroAttribute(..) => true, // definitely a plugin
888+
ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
889+
ExpnKind::Desugaring(_) => true, // well, it's "external"
890+
ExpnKind::MacroBang(..) => {
891891
let def_site = match info.def_site {
892892
Some(span) => span,
893893
// no span for the def_site means it's an external macro
@@ -911,8 +911,8 @@ pub fn in_derive_expansion(span: Span) -> bool {
911911
None => return false,
912912
};
913913

914-
match info.format {
915-
ExpnFormat::MacroAttribute(symbol) => symbol.as_str().starts_with("derive("),
914+
match info.kind {
915+
ExpnKind::MacroAttribute(symbol) => symbol.as_str().starts_with("derive("),
916916
_ => false,
917917
}
918918
}

src/librustc/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ impl<'tcx> LocalDecl<'tcx> {
928928
/// `__next` from a `for` loop.
929929
#[inline]
930930
pub fn from_compiler_desugaring(&self) -> bool {
931-
self.source_info.span.compiler_desugaring_kind().is_some()
931+
self.source_info.span.desugaring_kind().is_some()
932932
}
933933

934934
/// Creates a new `LocalDecl` for a temporary.

src/librustc/traits/error_reporting.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use errors::{Applicability, DiagnosticBuilder};
3636
use std::fmt;
3737
use syntax::ast;
3838
use syntax::symbol::sym;
39-
use syntax_pos::{DUMMY_SP, Span, ExpnInfo, ExpnFormat};
39+
use syntax_pos::{DUMMY_SP, Span, ExpnInfo, ExpnKind};
4040

4141
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
4242
pub fn report_fulfillment_errors(&self,
@@ -62,7 +62,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
6262
// if one is the result of a desugaring and the other is not.
6363
let mut span = error.obligation.cause.span;
6464
if let Some(ExpnInfo {
65-
format: ExpnFormat::CompilerDesugaring(_),
65+
kind: ExpnKind::Desugaring(_),
6666
def_site: Some(def_span),
6767
..
6868
}) = span.ctxt().outer_expn_info() {
@@ -373,9 +373,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
373373
flags.push((sym::parent_trait, Some(t)));
374374
}
375375

376-
if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {
376+
if let Some(k) = obligation.cause.span.desugaring_kind() {
377377
flags.push((sym::from_desugaring, None));
378-
flags.push((sym::from_desugaring, Some(k.name().to_string())));
378+
flags.push((sym::from_desugaring, Some(k.descr().to_string())));
379379
}
380380
let generics = self.tcx.generics_of(def_id);
381381
let self_ty = trait_ref.self_ty();

src/librustc_allocator/expand.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use syntax::{
88
},
99
attr,
1010
source_map::{
11-
respan, ExpnInfo, MacroAttribute,
11+
respan, ExpnInfo, ExpnKind,
1212
},
1313
ext::{
1414
base::{ExtCtxt, Resolver},
@@ -87,7 +87,8 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
8787
// Create a fresh Mark for the new macro expansion we are about to do
8888
let mark = Mark::fresh(Mark::root());
8989
mark.set_expn_info(ExpnInfo::with_unstable(
90-
MacroAttribute(sym::global_allocator), item.span, self.sess.edition, &[sym::rustc_attrs]
90+
ExpnKind::MacroAttribute(sym::global_allocator), item.span, self.sess.edition,
91+
&[sym::rustc_attrs],
9192
));
9293

9394
// Tie the span to the macro expansion info we just created

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use std::cell::{Cell, RefCell};
3333
use std::fmt;
3434
use std::rc::Rc;
3535
use std::hash::{Hash, Hasher};
36-
use syntax::source_map::CompilerDesugaringKind;
36+
use syntax::source_map::DesugaringKind;
3737
use syntax_pos::{MultiSpan, Span};
3838
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
3939
use log::debug;
@@ -734,8 +734,8 @@ impl BorrowckCtxt<'_, 'tcx> {
734734
},
735735
moved_lp.ty));
736736
}
737-
if let (Some(CompilerDesugaringKind::ForLoop), Ok(snippet)) = (
738-
move_span.compiler_desugaring_kind(),
737+
if let (Some(DesugaringKind::ForLoop), Ok(snippet)) = (
738+
move_span.desugaring_kind(),
739739
self.tcx.sess.source_map().span_to_snippet(move_span),
740740
) {
741741
if !snippet.starts_with("&") {

src/librustc_mir/borrow_check/conflict_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_data_structures::fx::FxHashSet;
1010
use rustc_data_structures::indexed_vec::Idx;
1111
use rustc_errors::{Applicability, DiagnosticBuilder};
1212
use syntax_pos::Span;
13-
use syntax::source_map::CompilerDesugaringKind;
13+
use syntax::source_map::DesugaringKind;
1414

1515
use super::nll::explain_borrow::BorrowExplanation;
1616
use super::nll::region_infer::{RegionName, RegionNameSource};
@@ -174,7 +174,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
174174
format!("variable moved due to use{}", move_spans.describe()),
175175
);
176176
}
177-
if Some(CompilerDesugaringKind::ForLoop) == move_span.compiler_desugaring_kind() {
177+
if Some(DesugaringKind::ForLoop) == move_span.desugaring_kind() {
178178
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
179179
err.span_suggestion(
180180
move_span,

0 commit comments

Comments
 (0)