@@ -29,10 +29,11 @@ use rustc_typeck::hir_ty_to_ty;
29
29
use crate :: consts:: { constant, Constant } ;
30
30
use crate :: utils:: paths;
31
31
use 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,
36
37
} ;
37
38
38
39
declare_clippy_lint ! {
@@ -1965,35 +1966,37 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons {
1965
1966
use crate :: types:: AbsurdComparisonResult :: { AlwaysFalse , AlwaysTrue , InequalityImpossible } ;
1966
1967
use crate :: types:: ExtremeType :: { Maximum , Minimum } ;
1967
1968
1969
+ if in_macro ( expr. span ) {
1970
+ return ;
1971
+ }
1972
+
1968
1973
if let ExprKind :: Binary ( ref cmp, ref lhs, ref rhs) = expr. kind {
1969
1974
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 \
1972
1976
type contains a case that is always true or always false";
1973
1977
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 `{} == {}` \
1979
1983
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
+ } ;
1984
1988
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
+ ) ;
1994
1998
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) ;
1997
2000
}
1998
2001
}
1999
2002
}
0 commit comments