]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-variance-contravariant-use-covariant.rs
Rollup merge of #97317 - GuillaumeGomez:gui-settings-text-click, r=jsha
[rust.git] / src / test / ui / regions / regions-variance-contravariant-use-covariant.rs
1 // Test that a type which is covariant with respect to its region
2 // parameter yields an error when used in a contravariant way.
3 //
4 // Note: see variance-regions-*.rs for the tests that check that the
5 // variance inference works in the first place.
6
7 // revisions: base nll
8 // ignore-compare-mode-nll
9 //[nll] compile-flags: -Z borrowck=mir
10
11 // This is contravariant with respect to 'a, meaning that
12 // Contravariant<'long> <: Contravariant<'short> iff
13 // 'short <= 'long
14 struct Contravariant<'a> {
15     f: &'a isize
16 }
17
18 fn use_<'short,'long>(c: Contravariant<'short>,
19                       s: &'short isize,
20                       l: &'long isize,
21                       _where:Option<&'short &'long ()>) {
22
23     // Test whether Contravariant<'short> <: Contravariant<'long>.  Since
24     // 'short <= 'long, this would be true if the Contravariant type were
25     // covariant with respect to its parameter 'a.
26
27     let _: Contravariant<'long> = c;
28     //[base]~^ ERROR E0623
29     //[nll]~^^ ERROR lifetime may not live long enough
30 }
31
32 fn main() {}