File tree 4 files changed +149
-31
lines changed
4 files changed +149
-31
lines changed Original file line number Diff line number Diff line change 1
1
use clippy_utils:: diagnostics:: span_lint_and_then;
2
- use clippy_utils:: path_to_local;
3
2
use clippy_utils:: source:: snippet;
4
3
use clippy_utils:: visitors:: { for_each_expr, is_local_used} ;
4
+ use clippy_utils:: { in_constant, path_to_local} ;
5
5
use rustc_ast:: { BorrowKind , LitKind } ;
6
6
use rustc_errors:: Applicability ;
7
7
use rustc_hir:: def:: { DefKind , Res } ;
@@ -123,7 +123,7 @@ fn check_method_calls<'tcx>(
123
123
// `s if s.is_empty()` becomes ""
124
124
// `arr if arr.is_empty()` becomes []
125
125
126
- if ty. is_str ( ) {
126
+ if ty. is_str ( ) && ! in_constant ( cx , if_expr . hir_id ) {
127
127
r#""""# . into ( )
128
128
} else if slice_like {
129
129
"[]" . into ( )
Original file line number Diff line number Diff line change 1
1
//@aux-build:proc_macros.rs
2
2
#![feature(if_let_guard)]
3
- #![allow(clippy::no_effect, unused)]
3
+ #![allow(clippy::no_effect, unused, clippy::single_match )]
4
4
#![warn(clippy::redundant_guards)]
5
5
6
6
#[macro_use]
@@ -16,6 +16,7 @@ struct C(u32, u32);
16
16
17
17
#[derive(PartialEq)]
18
18
struct FloatWrapper(f32);
19
+
19
20
fn issue11304() {
20
21
match 0.1 {
21
22
x if x == 0.0 => todo!(),
@@ -258,3 +259,49 @@ fn issue11807() {
258
259
_ => {},
259
260
}
260
261
}
262
+
263
+ mod issue12243 {
264
+ pub const fn const_fn(x: &str) {
265
+ match x {
266
+ // Shouldn't lint.
267
+ y if y.is_empty() => {},
268
+ _ => {},
269
+ }
270
+ }
271
+
272
+ pub fn non_const_fn(x: &str) {
273
+ match x {
274
+ "" => {},
275
+ //~^ ERROR: redundant guard
276
+ _ => {},
277
+ }
278
+ }
279
+
280
+ struct Bar;
281
+
282
+ impl Bar {
283
+ pub const fn const_bar(x: &str) {
284
+ match x {
285
+ // Shouldn't lint.
286
+ y if y.is_empty() => {},
287
+ _ => {},
288
+ }
289
+ }
290
+
291
+ pub fn non_const_bar(x: &str) {
292
+ match x {
293
+ "" => {},
294
+ //~^ ERROR: redundant guard
295
+ _ => {},
296
+ }
297
+ }
298
+ }
299
+
300
+ static FOO: () = {
301
+ match "" {
302
+ // Shouldn't lint.
303
+ x if x.is_empty() => {},
304
+ _ => {},
305
+ }
306
+ };
307
+ }
Original file line number Diff line number Diff line change 1
1
//@aux-build:proc_macros.rs
2
2
#![ feature( if_let_guard) ]
3
- #![ allow( clippy:: no_effect, unused) ]
3
+ #![ allow( clippy:: no_effect, unused, clippy :: single_match ) ]
4
4
#![ warn( clippy:: redundant_guards) ]
5
5
6
6
#[ macro_use]
@@ -16,6 +16,7 @@ struct C(u32, u32);
16
16
17
17
#[ derive( PartialEq ) ]
18
18
struct FloatWrapper ( f32 ) ;
19
+
19
20
fn issue11304 ( ) {
20
21
match 0.1 {
21
22
x if x == 0.0 => todo ! ( ) ,
@@ -258,3 +259,49 @@ fn issue11807() {
258
259
_ => { } ,
259
260
}
260
261
}
262
+
263
+ mod issue12243 {
264
+ pub const fn const_fn ( x : & str ) {
265
+ match x {
266
+ // Shouldn't lint.
267
+ y if y. is_empty ( ) => { } ,
268
+ _ => { } ,
269
+ }
270
+ }
271
+
272
+ pub fn non_const_fn ( x : & str ) {
273
+ match x {
274
+ y if y. is_empty ( ) => { } ,
275
+ //~^ ERROR: redundant guard
276
+ _ => { } ,
277
+ }
278
+ }
279
+
280
+ struct Bar ;
281
+
282
+ impl Bar {
283
+ pub const fn const_bar ( x : & str ) {
284
+ match x {
285
+ // Shouldn't lint.
286
+ y if y. is_empty ( ) => { } ,
287
+ _ => { } ,
288
+ }
289
+ }
290
+
291
+ pub fn non_const_bar ( x : & str ) {
292
+ match x {
293
+ y if y. is_empty ( ) => { } ,
294
+ //~^ ERROR: redundant guard
295
+ _ => { } ,
296
+ }
297
+ }
298
+ }
299
+
300
+ static FOO : ( ) = {
301
+ match "" {
302
+ // Shouldn't lint.
303
+ x if x. is_empty ( ) => { } ,
304
+ _ => { } ,
305
+ }
306
+ } ;
307
+ }
You can’t perform that action at this time.
0 commit comments