Skip to content

Commit 90b673b

Browse files
committed
Auto merge of #3584 - flip1995:rollup, r=flip1995
Rollup of 2 pull requests Successful merges: - #3577 (Fix false positives for `implicit_return` and `empty_loop` on macro expansion.) - #3579 (update CARGO_CLIPPY_HELP string to suggest tool lints.) Failed merges: r? @ghost
2 parents af14342 + 0a10f4a commit 90b673b

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

clippy_lints/src/implicit_return.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1212
use crate::rustc::{declare_tool_lint, lint_array};
1313
use crate::rustc_errors::Applicability;
1414
use crate::syntax::{ast::NodeId, source_map::Span};
15-
use crate::utils::{snippet_opt, span_lint_and_then};
15+
use crate::utils::{snippet_opt, span_lint_and_then, in_macro};
1616

1717
/// **What it does:** Checks for missing return statements at the end of a block.
1818
///
@@ -116,14 +116,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
116116
_: FnKind<'tcx>,
117117
_: &'tcx FnDecl,
118118
body: &'tcx Body,
119-
_: Span,
119+
span: Span,
120120
_: NodeId,
121121
) {
122122
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
123123
let mir = cx.tcx.optimized_mir(def_id);
124124

125125
// checking return type through MIR, HIR is not able to determine inferred closure return types
126-
if !mir.return_ty().is_unit() {
126+
// make sure it's not a macro
127+
if !mir.return_ty().is_unit() && !in_macro(span) {
127128
Self::expr_match(cx, &body.value);
128129
}
129130
}

clippy_lints/src/loops.rs

+5
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,11 @@ impl LintPass for Pass {
478478

479479
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
480480
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
481+
// we don't want to check expanded macros
482+
if in_macro(expr.span) {
483+
return;
484+
}
485+
481486
if let Some((pat, arg, body)) = higher::for_loop(expr) {
482487
check_for_loop(cx, pat, arg, body, expr);
483488
}

src/main.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ with:
3333
-D --deny OPT Set lint denied
3434
-F --forbid OPT Set lint forbidden
3535
36-
The feature `cargo-clippy` is automatically defined for convenience. You can use
37-
it to allow or deny lints from the code, eg.:
36+
You can use tool lints to allow or deny lints from your code, eg.:
3837
39-
#[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
38+
#[allow(clippy::needless_lifetimes)]
4039
"#;
4140

4241
fn show_help() {

0 commit comments

Comments
 (0)