1- use crate :: utils:: { get_item_name, snippet_with_applicability, span_lint, span_lint_and_sugg, walk_ptrs_ty} ;
1+ use crate :: utils:: { get_item_name, higher , snippet_with_applicability, span_lint, span_lint_and_sugg, walk_ptrs_ty} ;
22use rustc_ast:: ast:: LitKind ;
33use rustc_data_structures:: fx:: FxHashSet ;
44use rustc_errors:: Applicability ;
@@ -259,6 +259,17 @@ fn check_len(
259259
260260/// Checks if this type has an `is_empty` method.
261261fn has_is_empty ( cx : & LateContext < ' _ , ' _ > , expr : & Expr < ' _ > ) -> bool {
262+ /// Special case ranges until `range_is_empty` is stabilized. See issue 3807.
263+ fn should_skip_range ( cx : & LateContext < ' _ , ' _ > , expr : & Expr < ' _ > ) -> bool {
264+ higher:: range ( cx, expr) . map_or ( false , |_| {
265+ !cx. tcx
266+ . features ( )
267+ . declared_lib_features
268+ . iter ( )
269+ . any ( |( name, _) | name. as_str ( ) == "range_is_empty" )
270+ } )
271+ }
272+
262273 /// Gets an `AssocItem` and return true if it matches `is_empty(self)`.
263274 fn is_is_empty ( cx : & LateContext < ' _ , ' _ > , item : & ty:: AssocItem ) -> bool {
264275 if let ty:: AssocKind :: Fn = item. kind {
@@ -284,6 +295,10 @@ fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
284295 } )
285296 }
286297
298+ if should_skip_range ( cx, expr) {
299+ return false ;
300+ }
301+
287302 let ty = & walk_ptrs_ty ( cx. tables . expr_ty ( expr) ) ;
288303 match ty. kind {
289304 ty:: Dynamic ( ref tt, ..) => {
0 commit comments