]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/shadowed-lifetime.rs
debuginfo: Make debuginfo source location assignment more stable (Pt. 1)
[rust.git] / src / test / compile-fail / shadowed-lifetime.rs
1 // Copyright 2013 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 // Test that shadowed lifetimes generate an error.
12
13 struct Foo<'a>(&'a isize);
14
15 impl<'a> Foo<'a> {
16     //~^ HELP shadowed lifetime `'a` declared here
17     fn shadow_in_method<'a>(&'a self) -> &'a isize {
18         //~^ WARNING lifetime name `'a` shadows another lifetime name that is already in scope
19         //~| HELP deprecated
20         self.0
21     }
22
23     fn shadow_in_type<'b>(&'b self) -> &'b isize {
24         //~^ HELP shadowed lifetime `'b` declared here
25         let x: for<'b> fn(&'b isize) = panic!();
26         //~^ WARNING lifetime name `'b` shadows another lifetime name that is already in scope
27         //~| HELP deprecated
28         self.0
29     }
30
31     fn not_shadow_in_item<'b>(&'b self) {
32         struct Bar<'a, 'b>(&'a isize, &'b isize); // not a shadow, separate item
33         fn foo<'a, 'b>(x: &'a isize, y: &'b isize) { } // same
34     }
35 }
36
37 fn main() {
38     // intentional error that occurs after `resolve_lifetime` runs,
39     // just to ensure that this test fails to compile; when shadowed
40     // lifetimes become either an error or a proper lint, this will
41     // not be needed.
42     let x: isize = 3us; //~ ERROR mismatched types
43 }