]> git.lizzy.rs Git - rust.git/blob - src/test/ui/match/match-ref-mut-let-invariance.rs
Rollup merge of #97317 - GuillaumeGomez:gui-settings-text-click, r=jsha
[rust.git] / src / test / ui / match / match-ref-mut-let-invariance.rs
1 // ignore-compare-mode-nll
2 // revisions: base nll
3 // [nll]compile-flags: -Zborrowck=mir
4
5 // Check that when making a ref mut binding with type `&mut T`, the
6 // type `T` must match precisely the type `U` of the value being
7 // matched, and in particular cannot be some supertype of `U`. Issue
8 // #23116. This test focuses on a `let`.
9
10 #![allow(dead_code)]
11 struct S<'b>(&'b i32);
12 impl<'b> S<'b> {
13     fn bar<'a>(&'a mut self) -> &'a mut &'a i32 {
14         let ref mut x = self.0;
15         x
16         //[base]~^ ERROR mismatched types
17         //[nll]~^^ ERROR lifetime may not live long enough
18     }
19 }
20
21 fn main() {}