3 #![allow(unused_variables, clippy::unnecessary_wraps)]
5 fn option_unwrap_or() {
61 // cases where the none arm isn't a constant expression
62 // are not linted due to potential ownership issues
64 // ownership issue example, don't lint
66 let mut option: Option<NonCopyable> = None;
70 option = Some(NonCopyable);
76 // ownership issue example, don't lint
77 let option: Option<&str> = None;
80 None => &format!("{} {}!", "hello", "world"),
84 fn result_unwrap_or() {
86 match Ok::<i32, &str>(1) {
91 // int case, scrutinee is a binding
92 let a = Ok::<i32, &str>(1);
98 // int case, suggestion must surround Result expr with parenthesis
99 match Ok(1) as Result<i32, &str> {
104 // method call case, suggestion must not surround Result expr `s.method()` with parenthesis
107 fn method(self) -> Option<i32> {
118 match Ok::<i32, &str>(1) {
124 match Ok::<i32, &str>(1) {
131 match Ok::<i32, &str>(1) {
141 match Ok::<&str, &str>("Bob") {
147 match Ok::<i32, &str>(1) {
151 match Ok::<i32, &str>(1) {
156 match Ok::<i32, &str>(j) {
160 match Ok::<i32, &str>(j) {
166 // don't lint, Err value is used
167 match Ok::<&str, &str>("Alice") {
171 // could lint, but unused_variables takes care of it
172 match Ok::<&str, &str>("Alice") {
178 // don't lint in const fn
179 const fn const_fn_option_unwrap_or() {
186 const fn const_fn_result_unwrap_or() {
187 match Ok::<&str, &str>("Alice") {
194 macro_rules! some_macro {
196 if 1 > 2 { Some(1) } else { None }
201 let _ = match some_macro!() {
209 fn format_name(name: Option<&Rc<str>>) -> &str {
216 fn implicit_deref_ref() {
217 let _: &str = match Some(&"bye") {