Skip to content

Commit 6251b69

Browse files
committed
don't allow fields whose types are uncertain
1 parent be7e3ce commit 6251b69

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

clippy_lints/src/no_effect.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<Vec
348348
reduce_expression(cx, inner).or_else(|| Some(vec![inner]))
349349
},
350350
ExprKind::Struct(_, fields, ref base) => {
351-
if has_drop(cx, cx.typeck_results().expr_ty(expr)) {
351+
if fields.iter().any(|f| !expr_type_is_certain(cx, &f.expr))
352+
|| has_drop(cx, cx.typeck_results().expr_ty(expr))
353+
{
352354
None
353355
} else {
354356
let base = match base {

tests/ui/unnecessary_operation.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,15 @@ fn issue15173_original<MsU>(handler: impl FnOnce() -> MsU + Clone + 'static) {
157157
None
158158
}) as Box<dyn Fn(i32) -> Option<i32>>;
159159
}
160+
161+
fn issue15381() {
162+
struct Resources;
163+
struct DescriptorSet {
164+
slots: Vec<Resources>,
165+
}
166+
167+
fn main() {
168+
Vec::new();
169+
//~^ unnecessary_operation
170+
}
171+
}

tests/ui/unnecessary_operation.stderr

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ error: unnecessary operation
6767
LL | ..get_number();
6868
| ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();`
6969

70-
error: unnecessary operation
71-
--> tests/ui/unnecessary_operation.rs:93:5
72-
|
73-
LL | 5..get_number();
74-
| ^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();`
75-
7670
error: unnecessary operation
7771
--> tests/ui/unnecessary_operation.rs:95:5
7872
|
@@ -112,26 +106,11 @@ LL | | get_number()
112106
LL | | };
113107
| |______^ help: statement can be reduced to: `get_number();`
114108

115-
error: unnecessary operation
116-
--> tests/ui/unnecessary_operation.rs:109:5
117-
|
118-
LL | / FooString {
119-
LL | |
120-
LL | | s: String::from("blah"),
121-
LL | | };
122-
| |______^ help: statement can be reduced to: `String::from("blah");`
123-
124109
error: unnecessary operation
125110
--> tests/ui/unnecessary_operation.rs:150:5
126111
|
127112
LL | [42, 55][get_usize()];
128113
| ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());`
129114

130-
error: unnecessary operation
131-
--> tests/ui/unnecessary_operation.rs:173:5
132-
|
133-
LL | DescriptorSet { slots: Vec::new() };
134-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `Vec::new();`
135-
136-
error: aborting due to 21 previous errors
115+
error: aborting due to 18 previous errors
137116

0 commit comments

Comments
 (0)