2 #![allow(unused_variables)]
3 fn some_or_wildcard(r: &Option<i32>, b: &i32) {
4 let _: &i32 = match r {
10 fn none_or_wildcard(r: &Option<i32>, b: &i32) {
11 let _: &i32 = match r {
17 fn some_or_ref_none(r: &Option<i32>, b: &i32) {
18 let _: &i32 = match r {
24 fn ref_some_or_none(r: &Option<i32>, b: &i32) {
25 let _: &i32 = match r {
31 fn some_or_self(r: &Option<i32>) {
32 let _: &Option<i32> = match r {
41 fn multiple_deref(r: &&&&&Option<i32>) {
42 let _: i32 = match r {
49 // FIXME(tschottdorf): #44912.
51 // let x = &Some((3, 3));
52 // let _: &i32 = match x {
53 // Some((x, 3)) | &Some((ref x, 5)) => x,
59 match (&Some(5), &Some(6)) {
60 (Some(a), &Some(mut b)) => {
61 // Here, the `a` will be `&i32`, because in the first half of the tuple
62 // we hit a non-reference pattern and shift into `ref` mode.
64 // In the second half of the tuple there's no non-reference pattern,
65 // so `b` will be `i32` (bound with `move` mode). Moreover, `b` is
75 fn nested_mixed_multiple_deref_1() {
76 let x = (1, &Some(5));
79 Some((a, Some(b))) => {
87 fn nested_mixed_multiple_deref_2() {
98 fn new_mutable_reference() {
99 let mut x = &mut Some(5);
115 fn let_implicit_ref_binding() {
118 // Note that these rules apply to any pattern matching
119 // whether it be in a `match` or a `let`.
120 // For example, `x` here is a `ref` binding:
121 let Foo(x) = &Foo(3);
125 fn explicit_mut_binding() {
134 match &mut Some(5i32) {
142 match &mut &mut Some(5i32) {
150 fn tuple_mut_and_mut_mut() {
151 match (Some(5i32), &Some(5i32)) {
152 (Some(n), Some(m)) => {
153 // `n` and `m` are bound as immutable references. Make new references from them to
160 // Assert the types. Note that we use `n` and `m` here which would fail had they been
161 // moved due to the assignments above.
168 match (&Some(5i32), &&Some(5i32)) {
169 (Some(n), Some(m)) => {
176 match &mut &mut (Some(5i32), Some(5i32)) {
177 (Some(n), Some(m)) => {
178 // Dereferenced through &mut &mut, so a mutable binding results.
185 match (&mut Some(5i32), &mut &mut Some(5i32)) {
186 (Some(n), Some(m)) => {
194 fn min_mir_embedded_type() {
195 // The reduced invocation that an ICE was diagnosed with (was consuming
196 // adjustments in wrong order).
197 match (0u8, &&Some(5i32)) {
213 // Constant of generic type (string)
214 const Y: &'static str = "foo";
215 assert_eq!(0, match "foo" {
220 // Reference pattern.
225 let r: &Option<i32> = &Some(3);
228 none_or_wildcard(r, b);
229 some_or_wildcard(r, b);
230 some_or_ref_none(r, b);
231 ref_some_or_none(r, b);
234 multiple_deref(&&&&r);
238 nested_mixed_multiple_deref_1();
239 nested_mixed_multiple_deref_2();
241 new_mutable_reference();
242 explicit_mut_binding();
243 tuple_mut_and_mut_mut();
244 min_mir_embedded_type();
246 let_implicit_ref_binding();