2014-12-12 10:09:24 -06:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Test that shadowed lifetimes generate an error.
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
struct Foo<'a>(&'a isize);
|
2014-12-12 10:09:24 -06:00
|
|
|
|
|
|
|
impl<'a> Foo<'a> {
|
2015-01-20 00:25:28 -06:00
|
|
|
//~^ NOTE shadowed lifetime `'a` declared here
|
2015-01-08 04:54:35 -06:00
|
|
|
fn shadow_in_method<'a>(&'a self) -> &'a isize {
|
2014-12-12 10:09:24 -06:00
|
|
|
//~^ WARNING lifetime name `'a` shadows another lifetime name that is already in scope
|
2015-01-20 00:25:28 -06:00
|
|
|
//~| NOTE deprecated
|
2014-12-12 10:09:24 -06:00
|
|
|
self.0
|
|
|
|
}
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn shadow_in_type<'b>(&'b self) -> &'b isize {
|
2015-01-20 00:25:28 -06:00
|
|
|
//~^ NOTE shadowed lifetime `'b` declared here
|
2015-01-08 04:54:35 -06:00
|
|
|
let x: for<'b> fn(&'b isize) = panic!();
|
2014-12-12 10:09:24 -06:00
|
|
|
//~^ WARNING lifetime name `'b` shadows another lifetime name that is already in scope
|
2015-01-20 00:25:28 -06:00
|
|
|
//~| NOTE deprecated
|
2014-12-12 10:09:24 -06:00
|
|
|
self.0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn not_shadow_in_item<'b>(&'b self) {
|
2015-01-08 04:54:35 -06:00
|
|
|
struct Bar<'a, 'b>(&'a isize, &'b isize); // not a shadow, separate item
|
|
|
|
fn foo<'a, 'b>(x: &'a isize, y: &'b isize) { } // same
|
2014-12-12 10:09:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// intentional error that occurs after `resolve_lifetime` runs,
|
|
|
|
// just to ensure that this test fails to compile; when shadowed
|
|
|
|
// lifetimes become either an error or a proper lint, this will
|
|
|
|
// not be needed.
|
2015-02-18 04:42:01 -06:00
|
|
|
let x: isize = 3_usize; //~ ERROR mismatched types
|
2014-12-12 10:09:24 -06:00
|
|
|
}
|