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() {
146146 None => None,
147147 };
148148 }
149+
150+ // #7077
151+ let s = &String::new();
152+ let _: Option<&str> = Some(s).map(|s| s);
149153}
Original file line number Diff line number Diff line change @@ -194,5 +194,15 @@ LL | | None
194194LL | | };
195195 | |_____^ help: try this: `{ Some(0).map(|x| x + 1) }`
196196
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
198208
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 ) ]
33
44use std:: mem;
55
Original file line number Diff line number Diff line change @@ -12,14 +12,6 @@ error: replacing with `mem::MaybeUninit::uninit().assume_init()`
1212LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init());
1313 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)`
1414
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-
2315error: replacing with `mem::zeroed()`
2416 --> $DIR/repl_uninit.rs:27:23
2517 |
@@ -34,5 +26,5 @@ error: replacing with `mem::uninitialized()`
3426LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) };
3527 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)`
3628
37- error: aborting due to 5 previous errors
29+ error: aborting due to 4 previous errors
3830
Original file line number Diff line number Diff line change 11#![ feature( stmt_expr_attributes) ]
22
3- use std:: mem:: MaybeUninit ;
3+ use std:: mem:: { self , MaybeUninit } ;
44
55fn main ( ) {
66 let _: usize = unsafe { MaybeUninit :: uninit ( ) . assume_init ( ) } ;
@@ -19,4 +19,7 @@ fn main() {
1919
2020 // This is OK, because all constitutent types are uninit-compatible.
2121 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 ( ) } ;
2225}
Original file line number Diff line number Diff line change @@ -12,5 +12,11 @@ error: this call for this type may be undefined behavior
1212LL | let _: [u8; 0] = unsafe { MaybeUninit::uninit().assume_init() };
1313 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414
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
1622
You can’t perform that action at this time.
0 commit comments