Skip to content

Commit

Permalink
Addition manual_map test for unsafe blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Nov 17, 2021
1 parent 8506f66 commit 5f861ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tests/ui/manual_map_option_2.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ fn main() {
if let Some(ref s) = s { (x.clone(), s) } else { panic!() }
});

// Issue #7820
unsafe fn f(x: u32) -> u32 {
x
}
unsafe {
let _ = Some(0).map(|x| f(x));
}
let _ = Some(0).map(|x| unsafe { f(x) });
let _ = Some(0).map(|x| unsafe { f(x) });
}
5 changes: 5 additions & 0 deletions tests/ui/manual_map_option_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fn main() {
None => None,
};

// Issue #7820
unsafe fn f(x: u32) -> u32 {
x
}
Expand All @@ -67,4 +68,8 @@ fn main() {
Some(x) => unsafe { Some(f(x)) },
None => None,
};
let _ = match Some(0) {
Some(x) => Some(unsafe { f(x) }),
None => None,
};
}
16 changes: 13 additions & 3 deletions tests/ui/manual_map_option_2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LL ~ });
|

error: manual implementation of `Option::map`
--> $DIR/manual_map_option_2.rs:61:17
--> $DIR/manual_map_option_2.rs:62:17
|
LL | let _ = match Some(0) {
| _________________^
Expand All @@ -50,7 +50,7 @@ LL | | };
| |_________^ help: try this: `Some(0).map(|x| f(x))`

error: manual implementation of `Option::map`
--> $DIR/manual_map_option_2.rs:66:13
--> $DIR/manual_map_option_2.rs:67:13
|
LL | let _ = match Some(0) {
| _____________^
Expand All @@ -59,5 +59,15 @@ LL | | None => None,
LL | | };
| |_____^ help: try this: `Some(0).map(|x| unsafe { f(x) })`

error: aborting due to 4 previous errors
error: manual implementation of `Option::map`
--> $DIR/manual_map_option_2.rs:71:13
|
LL | let _ = match Some(0) {
| _____________^
LL | | Some(x) => Some(unsafe { f(x) }),
LL | | None => None,
LL | | };
| |_____^ help: try this: `Some(0).map(|x| unsafe { f(x) })`

error: aborting due to 5 previous errors

0 comments on commit 5f861ee

Please sign in to comment.