Skip to content

Commit 1bd8714

Browse files
committed
1 parent 348d398 commit 1bd8714

File tree

8 files changed

+49
-58
lines changed

8 files changed

+49
-58
lines changed

clippy_lints/src/misc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,13 @@ 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 {
630-
true
631-
} else {
632-
false
633-
}
634-
})
628+
629+
let expn_data = expr.span.ctxt().outer_expn_data();
630+
if let ExpnKind::Macro(MacroKind::Attr, _) = expn_data.kind {
631+
true
632+
} else {
633+
false
634+
}
635635
}
636636

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

clippy_lints/src/panic_unimplemented.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
6868
}
6969

7070
fn get_outer_span(expr: &Expr) -> Span {
71-
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();
74-
then {
75-
second.call_site
76-
} else {
77-
expr.span
78-
}
79-
}
71+
expr.span
72+
.ctxt()
73+
.outer_expn_data()
74+
.call_site
75+
.ctxt()
76+
.outer_expn_data()
77+
.call_site
8078
}
8179

8280
fn match_panic(params: &P<[Expr]>, expr: &Expr, cx: &LateContext<'_, '_>) {

clippy_lints/src/ranges.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ 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 = expr.span.ctxt().outer_expn_data().call_site;
154151
span_lint_and_then(
155152
cx,
156153
RANGE_PLUS_ONE,

clippy_lints/src/returns.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ fn attr_is_cfg(attr: &ast::Attribute) -> bool {
316316
}
317317

318318
// get the def site
319-
fn get_def(span: Span) -> Option<Span> {
320-
span.ctxt().outer_expn_info().and_then(|info| Some(info.def_site))
319+
fn get_def(span: Span) -> Span {
320+
span.ctxt().outer_expn_data().def_site
321321
}
322322

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

clippy_lints/src/utils/internal_lints.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ declare_clippy_lint! {
7777

7878
declare_clippy_lint! {
7979
/// **What it does:** Checks for calls to `cx.outer().expn_info()` and suggests to use
80-
/// the `cx.outer_expn_info()`
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
///
@@ -91,11 +91,11 @@ declare_clippy_lint! {
9191
///
9292
/// Good:
9393
/// ```rust,ignore
94-
/// expr.span.ctxt().outer_expn_info()
94+
/// expr.span.ctxt().outer_expn_data()
9595
/// ```
9696
pub OUTER_EXPN_EXPN_INFO,
9797
internal,
98-
"using `cx.outer_expn().expn_info()` instead of `cx.outer_expn_info()`"
98+
"using `cx.outer_expn().expn_info()` 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(
@@ -301,7 +297,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnInfoPass {
301297
expr.span.trim_start(self_arg.span).unwrap_or(expr.span),
302298
"usage of `outer_expn().expn_info()`",
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: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
9494

9595
/// Returns `true` if this `expn_info` 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

100100
/// Returns `true` if this `expn_info` 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 {
104-
false
105-
} else {
106-
true
107-
}
108-
} else {
102+
let expn_data = span.ctxt().outer_expn_data();
103+
if expn_data.is_root() {
104+
return false;
105+
}
106+
if let ExpnKind::Desugaring(..) = expn_data.kind {
109107
false
108+
} else {
109+
true
110110
}
111111
}
112112
// If the snippet is empty, it's an attribute that was inserted during macro
@@ -686,13 +686,14 @@ 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+
let expn_data = span.ctxt().outer_expn_data();
690+
let (mac_name, new_span) = (expn_data.kind.descr(), expn_data.call_site);
690691

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,
692+
if mac_name.as_str() == name {
693+
return Some(new_span);
695694
}
695+
696+
span = new_span;
696697
}
697698
}
698699

@@ -706,12 +707,13 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
706707
/// `bar!` by
707708
/// `is_direct_expn_of`.
708709
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));
710+
let expn_data = span.ctxt().outer_expn_data();
711+
let (mac_name, new_span) = (expn_data.kind.descr(), expn_data.call_site);
710712

711-
match span_name_span {
712-
Some((mac_name, new_span)) if mac_name.as_str() == name => Some(new_span),
713-
_ => None,
713+
if mac_name.as_str() == name {
714+
return Some(new_span);
714715
}
716+
None
715717
}
716718

717719
/// Convenience function to get the return type of a function.

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.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: usage of `outer_expn().expn_info()`
2-
--> $DIR/outer_expn_info.rs:19:33
2+
--> $DIR.outer_expn_data.rs:19:33
33
|
44
LL | let _ = expr.span.ctxt().outer_expn().expn_info();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.outer_expn_info()`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.outer_expn_data()`
66
|
77
note: lint level defined here
8-
--> $DIR/outer_expn_info.rs:1:9
8+
--> $DIR.outer_expn_data.rs:1:9
99
|
1010
LL | #![deny(clippy::internal)]
1111
| ^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)