@@ -29,10 +29,11 @@ use rustc_typeck::hir_ty_to_ty;
2929use crate :: consts:: { constant, Constant } ;
3030use crate :: utils:: paths;
3131use crate :: utils:: {
32- clip, comparisons, differing_macro_contexts, higher, in_constant, indent_of, int_bits, is_type_diagnostic_item,
33- last_path_segment, match_def_path, match_path, method_chain_args, multispan_sugg, numeric_literal:: NumericLiteral ,
34- qpath_res, sext, snippet, snippet_block_with_applicability, snippet_opt, snippet_with_applicability,
35- snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, unsext,
32+ clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro, indent_of, int_bits,
33+ is_type_diagnostic_item, last_path_segment, match_def_path, match_path, method_chain_args, multispan_sugg,
34+ numeric_literal:: NumericLiteral , qpath_res, sext, snippet, snippet_block_with_applicability, snippet_opt,
35+ snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg,
36+ span_lint_and_then, unsext,
3637} ;
3738
3839declare_clippy_lint ! {
@@ -1965,35 +1966,37 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons {
19651966 use crate :: types:: AbsurdComparisonResult :: { AlwaysFalse , AlwaysTrue , InequalityImpossible } ;
19661967 use crate :: types:: ExtremeType :: { Maximum , Minimum } ;
19671968
1969+ if in_macro ( expr. span ) {
1970+ return ;
1971+ }
1972+
19681973 if let ExprKind :: Binary ( ref cmp, ref lhs, ref rhs) = expr. kind {
19691974 if let Some ( ( culprit, result) ) = detect_absurd_comparison ( cx, cmp. node , lhs, rhs) {
1970- if !expr. span . from_expansion ( ) {
1971- let msg = "this comparison involving the minimum or maximum element for this \
1975+ let msg = "this comparison involving the minimum or maximum element for this \
19721976 type contains a case that is always true or always false";
19731977
1974- let conclusion = match result {
1975- AlwaysFalse => "this comparison is always false" . to_owned ( ) ,
1976- AlwaysTrue => "this comparison is always true" . to_owned ( ) ,
1977- InequalityImpossible => format ! (
1978- "the case where the two sides are not equal never occurs, consider using `{} == {}` \
1978+ let conclusion = match result {
1979+ AlwaysFalse => "this comparison is always false" . to_owned ( ) ,
1980+ AlwaysTrue => "this comparison is always true" . to_owned ( ) ,
1981+ InequalityImpossible => format ! (
1982+ "the case where the two sides are not equal never occurs, consider using `{} == {}` \
19791983 instead",
1980- snippet( cx, lhs. span, "lhs" ) ,
1981- snippet( cx, rhs. span, "rhs" )
1982- ) ,
1983- } ;
1984+ snippet( cx, lhs. span, "lhs" ) ,
1985+ snippet( cx, rhs. span, "rhs" )
1986+ ) ,
1987+ } ;
19841988
1985- let help = format ! (
1986- "because `{}` is the {} value for this type, {}" ,
1987- snippet( cx, culprit. expr. span, "x" ) ,
1988- match culprit. which {
1989- Minimum => "minimum" ,
1990- Maximum => "maximum" ,
1991- } ,
1992- conclusion
1993- ) ;
1989+ let help = format ! (
1990+ "because `{}` is the {} value for this type, {}" ,
1991+ snippet( cx, culprit. expr. span, "x" ) ,
1992+ match culprit. which {
1993+ Minimum => "minimum" ,
1994+ Maximum => "maximum" ,
1995+ } ,
1996+ conclusion
1997+ ) ;
19941998
1995- span_lint_and_help ( cx, ABSURD_EXTREME_COMPARISONS , expr. span , msg, None , & help) ;
1996- }
1999+ span_lint_and_help ( cx, ABSURD_EXTREME_COMPARISONS , expr. span , msg, None , & help) ;
19972000 }
19982001 }
19992002 }
0 commit comments