1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
//@ revisions: stable2021 classic2021 structural2021 classic2024 structural2024
//@[stable2021] edition: 2021
//@[classic2021] edition: 2021
//@[structural2021] edition: 2021
//@[classic2024] edition: 2024
//@[structural2024] edition: 2024
//@ dont-require-annotations: NOTE
//! Test cases for poorly-typed patterns in edition 2024 which are caught by HIR typeck. These must
//! be separate from cases caught by MIR borrowck or the latter errors may not be emitted.
#![allow(incomplete_features)]
#![cfg_attr(any(classic2021, classic2024), feature(ref_pat_eat_one_layer_2024))]
#![cfg_attr(any(structural2021, structural2024), feature(ref_pat_eat_one_layer_2024_structural))]
pub fn main() {
if let Some(&mut x) = &Some(&mut 0) {
//[classic2024]~^ ERROR: mismatched types
//[classic2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(any(stable2021, classic2021, structural2021))] let _: u32 = x;
#[cfg(structural2024)] let _: &u32 = x;
}
if let Some(&mut Some(&x)) = &Some(&mut Some(0)) {
//[stable2021,classic2021,structural2021,classic2024]~^ ERROR: mismatched types
//[stable2021,classic2021,structural2021]~| NOTE expected integer, found `&_`
//[classic2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(structural2024)] let _: u32 = x;
}
if let Some(Some(&mut x)) = &Some(Some(&mut 0)) {
//[classic2024]~^ ERROR: mismatched types
//[classic2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(any(stable2021, classic2021, structural2021))] let _: u32 = x;
#[cfg(structural2024)] let _: &u32 = x;
}
if let Some(&mut Some(&_)) = &Some(&Some(0)) {
//~^ ERROR: mismatched types
//[stable2021,classic2021,structural2021]~| NOTE types differ in mutability
//[classic2024,structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
}
if let Some(&Some(&mut x)) = &Some(&mut Some(0)) {
//[stable2021,classic2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE types differ in mutability
//[classic2021,structural2021]~| NOTE expected integer, found `&mut _`
//[structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(classic2024)] let _: u32 = x;
}
if let Some(&Some(&mut _)) = &mut Some(&Some(0)) {
//~^ ERROR: mismatched types
//[stable2021,classic2021,structural2021]~| NOTE expected integer, found `&mut _`
//[classic2024,structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
}
if let Some(&Some(Some(&mut x))) = &Some(Some(&mut Some(0))) {
//[stable2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE expected `Option<&mut Option<{integer}>>`, found `&_`
//[structural2021,structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(any(classic2021, classic2024))] let _: u32 = x;
}
if let Some(&mut Some(x)) = &Some(Some(0)) {
//~^ ERROR: mismatched types
//[stable2021]~| NOTE expected `Option<{integer}>`, found `&mut _`
//[classic2021,structural2021,classic2024,structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
}
}
fn structural_errors_0() {
let &[&mut x] = &&mut [0];
//[stable2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE expected integer, found `&mut _`
//[structural2021,structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(any(classic2021, classic2024))] let _: u32 = x;
let &[&mut x] = &mut &mut [0];
//[stable2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE types differ in mutability
//[structural2021,structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(any(classic2021, classic2024))] let _: u32 = x;
let &[&mut ref x] = &&mut [0];
//[stable2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE expected integer, found `&mut _`
//[structural2021,structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(any(classic2021, classic2024))] let _: &u32 = x;
let &[&mut ref x] = &mut &mut [0];
//[stable2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE types differ in mutability
//[structural2021,structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(any(classic2021, classic2024))] let _: &u32 = x;
let &[&mut mut x] = &&mut [0];
//[stable2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE expected integer, found `&mut _`
//[structural2021,structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(any(classic2021, classic2024))] let _: u32 = x;
let &[&mut mut x] = &mut &mut [0];
//[stable2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE types differ in mutability
//[structural2021,structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(any(classic2021, classic2024))] let _: u32 = x;
}
fn structural_errors_1() {
let [&(mut x)] = &[&0];
//[structural2024]~^ ERROR: binding cannot be both mutable and by-reference
#[cfg(any(stable2021, classic2021, structural2021))] let _: u32 = x;
#[cfg(classic2024)] let _: &u32 = x;
let [&(mut x)] = &mut [&0];
//[structural2024]~^ ERROR: binding cannot be both mutable and by-reference
#[cfg(any(stable2021, classic2021, structural2021))] let _: u32 = x;
#[cfg(classic2024)] let _: &u32 = x;
}
fn structural_errors_2() {
let [&&mut x] = &[&mut 0];
//[stable2021,classic2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE types differ in mutability
//[classic2021,structural2021] NOTE expected integer, found `&mut _`
//[structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(classic2024)] let _: u32 = x;
let [&&mut x] = &mut [&mut 0];
//[stable2021,classic2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE types differ in mutability
//[classic2021,structural2021] NOTE expected integer, found `&mut _`
//[structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(classic2024)] let _: u32 = x;
let [&&mut ref x] = &[&mut 0];
//[stable2021,classic2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE types differ in mutability
//[classic2021,structural2021] NOTE expected integer, found `&mut _`
//[structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(classic2024)] let _: &u32 = x;
let [&&mut ref x] = &mut [&mut 0];
//[stable2021,classic2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE types differ in mutability
//[classic2021,structural2021] NOTE expected integer, found `&mut _`
//[structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(classic2024)] let _: &u32 = x;
let [&&mut mut x] = &[&mut 0];
//[stable2021,classic2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE types differ in mutability
//[classic2021,structural2021] NOTE expected integer, found `&mut _`
//[structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(classic2024)] let _: u32 = x;
let [&&mut mut x] = &mut [&mut 0];
//[stable2021,classic2021,structural2021,structural2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE types differ in mutability
//[classic2021,structural2021] NOTE expected integer, found `&mut _`
//[structural2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(classic2024)] let _: u32 = x;
}
fn classic_errors_0() {
let [&mut x] = &[&mut 0];
//[classic2024]~^ ERROR: mismatched types
//[classic2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(any(stable2021, classic2021, structural2021))] let _: u32 = x;
#[cfg(structural2024)] let _: &u32 = x;
let [&mut &x] = &[&mut 0];
//[stable2021,classic2021,structural2021,classic2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE expected integer, found `&_`
//[classic2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(structural2024)] let _: u32 = x;
let [&mut &ref x] = &[&mut 0];
//[stable2021,classic2021,structural2021,classic2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE expected integer, found `&_`
//[classic2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(structural2024)] let _: &u32 = x;
let [&mut &(mut x)] = &[&mut 0];
//[stable2021,classic2021,structural2021,classic2024]~^ ERROR: mismatched types
//[stable2021]~| NOTE expected integer, found `&_`
//[classic2024]~| NOTE cannot match inherited `&` with `&mut` pattern
#[cfg(structural2024)] let _: u32 = x;
}
|