Skip to content

Commit 70f12dc

Browse files
committed
Auto merge of #4398 - kraai:outer_expn_data, r=flip1995
Use outer_expn_data instead of outer_expn_info `outer_expn_info` has been removed, so use its replacement, `outer_expn_data`, instead. changelog: none
2 parents 348d398 + 2456b35 commit 70f12dc

File tree

11 files changed

+88
-67
lines changed

11 files changed

+88
-67
lines changed

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
445445
reg.register_early_lint_pass(box utils::internal_lints::ClippyLintsInternal);
446446
reg.register_late_lint_pass(box utils::internal_lints::CompilerLintFunctions::new());
447447
reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default());
448-
reg.register_late_lint_pass(box utils::internal_lints::OuterExpnInfoPass);
448+
reg.register_late_lint_pass(box utils::internal_lints::OuterExpnDataPass);
449449
reg.register_late_lint_pass(box utils::inspector::DeepCodeInspector);
450450
reg.register_late_lint_pass(box utils::author::Author);
451451
reg.register_late_lint_pass(box types::Types);
@@ -681,7 +681,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
681681
utils::internal_lints::CLIPPY_LINTS_INTERNAL,
682682
utils::internal_lints::COMPILER_LINT_FUNCTIONS,
683683
utils::internal_lints::LINT_WITHOUT_LINT_PASS,
684-
utils::internal_lints::OUTER_EXPN_EXPN_INFO,
684+
utils::internal_lints::OUTER_EXPN_EXPN_DATA,
685685
]);
686686

687687
reg.register_lint_group("clippy::all", Some("clippy"), vec![

clippy_lints/src/misc.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,17 @@ fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
625625
/// generated by `#[derive(...)]` or the like).
626626
fn in_attributes_expansion(expr: &Expr) -> bool {
627627
use syntax::ext::hygiene::MacroKind;
628-
expr.span.ctxt().outer_expn_info().map_or(false, |info| {
629-
if let ExpnKind::Macro(MacroKind::Attr, _) = info.kind {
628+
if expr.span.from_expansion() {
629+
let data = expr.span.ctxt().outer_expn_data();
630+
631+
if let ExpnKind::Macro(MacroKind::Attr, _) = data.kind {
630632
true
631633
} else {
632634
false
633635
}
634-
})
636+
} else {
637+
false
638+
}
635639
}
636640

637641
/// Tests whether `res` is a variable defined outside a macro.

clippy_lints/src/panic_unimplemented.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
6969

7070
fn get_outer_span(expr: &Expr) -> Span {
7171
if_chain! {
72-
if let Some(first) = expr.span.ctxt().outer_expn_info();
73-
if let Some(second) = first.call_site.ctxt().outer_expn_info();
72+
if expr.span.from_expansion();
73+
let first = expr.span.ctxt().outer_expn_data();
74+
if first.call_site.from_expansion();
75+
let second = first.call_site.ctxt().outer_expn_data();
7476
then {
7577
second.call_site
7678
} else {

clippy_lints/src/ranges.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
147147
}) = higher::range(cx, expr);
148148
if let Some(y) = y_plus_one(end);
149149
then {
150-
let span = expr.span
151-
.ctxt()
152-
.outer_expn_info()
153-
.map_or(expr.span, |info| info.call_site);
150+
let span = if expr.span.from_expansion() {
151+
expr.span
152+
.ctxt()
153+
.outer_expn_data()
154+
.call_site
155+
} else {
156+
expr.span
157+
};
154158
span_lint_and_then(
155159
cx,
156160
RANGE_PLUS_ONE,

clippy_lints/src/returns.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ fn attr_is_cfg(attr: &ast::Attribute) -> bool {
317317

318318
// get the def site
319319
fn get_def(span: Span) -> Option<Span> {
320-
span.ctxt().outer_expn_info().and_then(|info| Some(info.def_site))
320+
if span.from_expansion() {
321+
Some(span.ctxt().outer_expn_data().def_site)
322+
} else {
323+
None
324+
}
321325
}
322326

323327
// is this expr a `()` unit?

clippy_lints/src/utils/internal_lints.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,26 @@ declare_clippy_lint! {
7676
}
7777

7878
declare_clippy_lint! {
79-
/// **What it does:** Checks for calls to `cx.outer().expn_info()` and suggests to use
80-
/// the `cx.outer_expn_info()`
79+
/// **What it does:** Checks for calls to `cx.outer().expn_data()` and suggests to use
80+
/// the `cx.outer_expn_data()`
8181
///
82-
/// **Why is this bad?** `cx.outer_expn_info()` is faster and more concise.
82+
/// **Why is this bad?** `cx.outer_expn_data()` is faster and more concise.
8383
///
8484
/// **Known problems:** None.
8585
///
8686
/// **Example:**
8787
/// Bad:
8888
/// ```rust,ignore
89-
/// expr.span.ctxt().outer().expn_info()
89+
/// expr.span.ctxt().outer().expn_data()
9090
/// ```
9191
///
9292
/// Good:
9393
/// ```rust,ignore
94-
/// expr.span.ctxt().outer_expn_info()
94+
/// expr.span.ctxt().outer_expn_data()
9595
/// ```
96-
pub OUTER_EXPN_EXPN_INFO,
96+
pub OUTER_EXPN_EXPN_DATA,
9797
internal,
98-
"using `cx.outer_expn().expn_info()` instead of `cx.outer_expn_info()`"
98+
"using `cx.outer_expn().expn_data()` instead of `cx.outer_expn_data()`"
9999
}
100100

101101
declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]);
@@ -180,11 +180,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
180180
// not able to capture the error.
181181
// Therefore, we need to climb the macro expansion tree and find the
182182
// actual span that invoked `declare_tool_lint!`:
183-
let lint_span = lint_span
184-
.ctxt()
185-
.outer_expn_info()
186-
.map(|ei| ei.call_site)
187-
.expect("unable to get call_site");
183+
let lint_span = lint_span.ctxt().outer_expn_data().call_site;
188184

189185
if !self.registered_lints.contains(lint_name) {
190186
span_lint(
@@ -278,17 +274,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions {
278274
}
279275
}
280276

281-
pub struct OuterExpnInfoPass;
277+
pub struct OuterExpnDataPass;
282278

283-
impl_lint_pass!(OuterExpnInfoPass => [OUTER_EXPN_EXPN_INFO]);
279+
impl_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]);
284280

285-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnInfoPass {
281+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass {
286282
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
287283
let (method_names, arg_lists) = method_calls(expr, 2);
288284
let method_names: Vec<LocalInternedString> = method_names.iter().map(|s| s.as_str()).collect();
289285
let method_names: Vec<&str> = method_names.iter().map(std::convert::AsRef::as_ref).collect();
290286
if_chain! {
291-
if let ["expn_info", "outer_expn"] = method_names.as_slice();
287+
if let ["expn_data", "outer_expn"] = method_names.as_slice();
292288
let args = arg_lists[1];
293289
if args.len() == 1;
294290
let self_arg = &args[0];
@@ -297,11 +293,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnInfoPass {
297293
then {
298294
span_lint_and_sugg(
299295
cx,
300-
OUTER_EXPN_EXPN_INFO,
296+
OUTER_EXPN_EXPN_DATA,
301297
expr.span.trim_start(self_arg.span).unwrap_or(expr.span),
302-
"usage of `outer_expn().expn_info()`",
298+
"usage of `outer_expn().expn_data()`",
303299
"try",
304-
".outer_expn_info()".to_string(),
300+
".outer_expn_data()".to_string(),
305301
Applicability::MachineApplicable,
306302
);
307303
}

clippy_lints/src/utils/mod.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
9292
}
9393
}
9494

95-
/// Returns `true` if this `expn_info` was expanded by any macro or desugaring
95+
/// Returns `true` if this `span` was expanded by any macro or desugaring
9696
pub fn in_macro_or_desugar(span: Span) -> bool {
97-
span.ctxt().outer_expn_info().is_some()
97+
span.from_expansion()
9898
}
9999

100-
/// Returns `true` if this `expn_info` was expanded by any macro.
100+
/// Returns `true` if this `span` was expanded by any macro.
101101
pub fn in_macro(span: Span) -> bool {
102-
if let Some(info) = span.ctxt().outer_expn_info() {
103-
if let ExpnKind::Desugaring(..) = info.kind {
102+
if span.from_expansion() {
103+
if let ExpnKind::Desugaring(..) = span.ctxt().outer_expn_data().kind {
104104
false
105105
} else {
106106
true
@@ -686,12 +686,18 @@ pub fn is_adjusted(cx: &LateContext<'_, '_>, e: &Expr) -> bool {
686686
/// See also `is_direct_expn_of`.
687687
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
688688
loop {
689-
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.kind.descr(), ei.call_site));
689+
if span.from_expansion() {
690+
let data = span.ctxt().outer_expn_data();
691+
let mac_name = data.kind.descr();
692+
let new_span = data.call_site;
690693

691-
match span_name_span {
692-
Some((mac_name, new_span)) if mac_name.as_str() == name => return Some(new_span),
693-
None => return None,
694-
Some((_, new_span)) => span = new_span,
694+
if mac_name.as_str() == name {
695+
return Some(new_span);
696+
} else {
697+
span = new_span;
698+
}
699+
} else {
700+
return None;
695701
}
696702
}
697703
}
@@ -706,11 +712,18 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
706712
/// `bar!` by
707713
/// `is_direct_expn_of`.
708714
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
709-
let span_name_span = span.ctxt().outer_expn_info().map(|ei| (ei.kind.descr(), ei.call_site));
715+
if span.from_expansion() {
716+
let data = span.ctxt().outer_expn_data();
717+
let mac_name = data.kind.descr();
718+
let new_span = data.call_site;
710719

711-
match span_name_span {
712-
Some((mac_name, new_span)) if mac_name.as_str() == name => Some(new_span),
713-
_ => None,
720+
if mac_name.as_str() == name {
721+
Some(new_span)
722+
} else {
723+
None
724+
}
725+
} else {
726+
None
714727
}
715728
}
716729

clippy_lints/src/vec.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec {
4949
// report the error around the `vec!` not inside `<std macros>:`
5050
let span = arg.span
5151
.ctxt()
52-
.outer_expn_info()
53-
.map(|info| info.call_site)
54-
.expect("unable to get call_site")
52+
.outer_expn_data()
53+
.call_site
5554
.ctxt()
56-
.outer_expn_info()
57-
.map(|info| info.call_site)
58-
.expect("unable to get call_site");
55+
.outer_expn_data()
56+
.call_site;
5957
check_vec_macro(cx, &vec_args, span);
6058
}
6159
}

tests/ui/outer_expn_info.rs renamed to tests/ui/outer_expn_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ declare_lint_pass!(Pass => [TEST_LINT]);
1616

1717
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
1818
fn check_expr(&mut self, _cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
19-
let _ = expr.span.ctxt().outer_expn().expn_info();
19+
let _ = expr.span.ctxt().outer_expn().expn_data();
2020
}
2121
}
2222

tests/ui/outer_expn_data.stderr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: usage of `outer_expn().expn_data()`
2+
--> $DIR/outer_expn_data.rs:19:33
3+
|
4+
LL | let _ = expr.span.ctxt().outer_expn().expn_data();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.outer_expn_data()`
6+
|
7+
note: lint level defined here
8+
--> $DIR/outer_expn_data.rs:1:9
9+
|
10+
LL | #![deny(clippy::internal)]
11+
| ^^^^^^^^^^^^^^^^
12+
= note: `#[deny(clippy::outer_expn_expn_data)]` implied by `#[deny(clippy::internal)]`
13+
14+
error: aborting due to previous error
15+

tests/ui/outer_expn_info.stderr

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)