]> git.proxmox.com Git - rustc.git/blob - src/test/ui/constructor-lifetime-args.rs
New upstream version 1.51.0+dfsg1
[rustc.git] / src / test / ui / constructor-lifetime-args.rs
1 // All lifetime parameters in struct constructors are currently considered early bound,
2 // i.e., `S::<ARGS>` is interpreted kinda like an associated item `S::<ARGS>::ctor`.
3 // This behavior is a bit weird, because if equivalent constructor were written manually
4 // it would get late bound lifetime parameters.
5 // Variant constructors behave in the same way, lifetime parameters are considered
6 // belonging to the enum and being early bound.
7 // https://github.com/rust-lang/rust/issues/30904
8
9 struct S<'a, 'b>(&'a u8, &'b u8);
10 enum E<'a, 'b> {
11 V(&'a u8),
12 U(&'b u8),
13 }
14
15 fn main() {
16 S(&0, &0); // OK
17 S::<'static>(&0, &0);
18 //~^ ERROR this struct takes 2 lifetime arguments but only 1 lifetime argument was supplied
19 S::<'static, 'static, 'static>(&0, &0);
20 //~^ ERROR this struct takes 2 lifetime arguments but 3 lifetime arguments were supplied
21 E::V(&0); // OK
22 E::V::<'static>(&0);
23 //~^ ERROR this enum takes 2 lifetime arguments but only 1 lifetime argument was supplied
24 E::V::<'static, 'static, 'static>(&0);
25 //~^ ERROR this enum takes 2 lifetime arguments but 3 lifetime arguments were supplied
26 }