File tree Expand file tree Collapse file tree 6 files changed +29
-14
lines changed Expand file tree Collapse file tree 6 files changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -146,4 +146,8 @@ fn main() {
146
146
None => None,
147
147
};
148
148
}
149
+
150
+ // #7077
151
+ let s = &String::new();
152
+ let _: Option<&str> = Some(s).map(|s| s);
149
153
}
Original file line number Diff line number Diff line change @@ -194,5 +194,15 @@ LL | | None
194
194
LL | | };
195
195
| |_____^ help: try this: `{ Some(0).map(|x| x + 1) }`
196
196
197
- error: aborting due to 21 previous errors
197
+ error: manual implementation of `Option::map`
198
+ --> $DIR/manual_map_option.rs:218:27
199
+ |
200
+ LL | let _: Option<&str> = match Some(s) {
201
+ | ___________________________^
202
+ LL | | Some(s) => Some(s),
203
+ LL | | None => None,
204
+ LL | | };
205
+ | |_____^ help: try this: `Some(s).map(|s| s)`
206
+
207
+ error: aborting due to 22 previous errors
198
208
Original file line number Diff line number Diff line change 1
- #![ allow( deprecated, invalid_value) ]
2
- #![ warn( clippy:: all ) ]
1
+ #![ allow( deprecated, invalid_value, clippy :: uninit_assumed_init ) ]
2
+ #![ warn( clippy:: mem_replace_with_uninit ) ]
3
3
4
4
use std:: mem;
5
5
Original file line number Diff line number Diff line change @@ -12,14 +12,6 @@ error: replacing with `mem::MaybeUninit::uninit().assume_init()`
12
12
LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init());
13
13
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)`
14
14
15
- error: this call for this type may be undefined behavior
16
- --> $DIR/repl_uninit.rs:21:44
17
- |
18
- LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init());
19
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20
- |
21
- = note: `-D clippy::uninit-assumed-init` implied by `-D warnings`
22
-
23
15
error: replacing with `mem::zeroed()`
24
16
--> $DIR/repl_uninit.rs:27:23
25
17
|
@@ -34,5 +26,5 @@ error: replacing with `mem::uninitialized()`
34
26
LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) };
35
27
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)`
36
28
37
- error: aborting due to 5 previous errors
29
+ error: aborting due to 4 previous errors
38
30
Original file line number Diff line number Diff line change 1
1
#![ feature( stmt_expr_attributes) ]
2
2
3
- use std:: mem:: MaybeUninit ;
3
+ use std:: mem:: { self , MaybeUninit } ;
4
4
5
5
fn main ( ) {
6
6
let _: usize = unsafe { MaybeUninit :: uninit ( ) . assume_init ( ) } ;
@@ -19,4 +19,7 @@ fn main() {
19
19
20
20
// This is OK, because all constitutent types are uninit-compatible.
21
21
let _: ( MaybeUninit < usize > , [ MaybeUninit < bool > ; 2 ] ) = unsafe { MaybeUninit :: uninit ( ) . assume_init ( ) } ;
22
+
23
+ // Was a false negative.
24
+ let _: usize = unsafe { mem:: MaybeUninit :: uninit ( ) . assume_init ( ) } ;
22
25
}
Original file line number Diff line number Diff line change @@ -12,5 +12,11 @@ error: this call for this type may be undefined behavior
12
12
LL | let _: [u8; 0] = unsafe { MaybeUninit::uninit().assume_init() };
13
13
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14
14
15
- error: aborting due to 2 previous errors
15
+ error: this call for this type may be undefined behavior
16
+ --> $DIR/uninit.rs:24:29
17
+ |
18
+ LL | let _: usize = unsafe { mem::MaybeUninit::uninit().assume_init() };
19
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20
+
21
+ error: aborting due to 3 previous errors
16
22
You can’t perform that action at this time.
0 commit comments