]> git.lizzy.rs Git - rust.git/blob - src/test/ui/constructor-lifetime-args.rs
1fe50cfebbac364c2e75add17a3f9e36685007ae
[rust.git] / src / test / ui / constructor-lifetime-args.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // All lifetime parameters in struct constructors are currently considered early bound,
12 // i.e. `S::<ARGS>` is interpreted kinda like an associated item `S::<ARGS>::ctor`.
13 // This behavior is a bit weird, because if equivalent constructor were written manually
14 // it would get late bound lifetime parameters.
15 // Variant constructors behave in the same way, lifetime parameters are considered
16 // belonging to the enum and being early bound.
17 // https://github.com/rust-lang/rust/issues/30904
18
19 struct S<'a, 'b>(&'a u8, &'b u8);
20 enum E<'a, 'b> {
21     V(&'a u8),
22     U(&'b u8),
23 }
24
25 fn main() {
26     S(&0, &0); // OK
27     S::<'static>(&0, &0);
28     //~^ ERROR wrong number of lifetime arguments: expected 2, found 1
29     S::<'static, 'static, 'static>(&0, &0);
30     //~^ ERROR wrong number of lifetime arguments: expected 2, found 3
31     E::V(&0); // OK
32     E::V::<'static>(&0);
33     //~^ ERROR wrong number of lifetime arguments: expected 2, found 1
34     E::V::<'static, 'static, 'static>(&0);
35     //~^ ERROR wrong number of lifetime arguments: expected 2, found 3
36 }