Skip to content

Commit b87f5bc

Browse files
committed
Don't trigger missing_const_for_fn in external macros
As reported in #3841. Only fixes the part where it triggers on the `derive`.
1 parent caccf8b commit b87f5bc

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clippy_lints/src/missing_const_for_fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::utils::{is_entrypoint_fn, span_lint};
22
use rustc::hir;
33
use rustc::hir::intravisit::FnKind;
44
use rustc::hir::{Body, Constness, FnDecl, HirId};
5-
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5+
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintPass};
66
use rustc::{declare_tool_lint, lint_array};
77
use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
88
use syntax_pos::Span;
@@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
8282
) {
8383
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
8484

85-
if is_entrypoint_fn(cx, def_id) {
85+
if in_external_macro(cx.tcx.sess, span) || is_entrypoint_fn(cx, def_id) {
8686
return;
8787
}
8888

tests/ui/missing_const_for_fn/cant_be_const.rs

+4
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ trait Foo {
5555
33
5656
}
5757
}
58+
59+
// Don't lint in external macros (derive)
60+
#[derive(PartialEq, Eq)]
61+
struct Point(isize, isize);

0 commit comments

Comments
 (0)