Skip to content

Commit aef29a0

Browse files
committed
fix single-use lint
1 parent b406d0b commit aef29a0

29 files changed

+612
-149
lines changed

src/librustc/middle/resolve_lifetime.rs

Lines changed: 150 additions & 31 deletions
Large diffs are not rendered by default.

src/test/ui/in-band-lifetimes/single_use_lifetimes-2.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/test/ui/in-band-lifetimes/single_use_lifetimes-3.stderr

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/test/ui/in-band-lifetimes/single_use_lifetimes-4.stderr

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/test/ui/in-band-lifetimes/single_use_lifetimes-5.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/test/ui/in-band-lifetimes/single_use_lifetimes.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/test/ui/in-band-lifetimes/single_use_lifetimes.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 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+
#![deny(single_use_lifetime)]
12+
#![allow(dead_code)]
13+
#![allow(unused_variables)]
14+
15+
// Test that we DO warn when lifetime name is used only
16+
// once in a fn argument.
17+
18+
struct Foo {
19+
a: for<'a> fn(&'a u32), //~ ERROR `'a` only used once
20+
b: for<'a> fn(&'a u32, &'a u32), // OK, used twice.
21+
c: for<'a> fn(&'a u32) -> &'a u32, // OK, used twice.
22+
d: for<'a> fn() -> &'a u32, // OK, used only in return type.
23+
//~^ ERROR return type references lifetime `'a`, which is not constrained by the fn input types
24+
}
25+
26+
fn main() { }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: lifetime parameter `'a` only used once
2+
--> $DIR/fn-types.rs:19:10
3+
|
4+
LL | a: for<'a> fn(&'a u32), //~ ERROR `'a` only used once
5+
| ^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/fn-types.rs:11:9
9+
|
10+
LL | #![deny(single_use_lifetime)]
11+
| ^^^^^^^^^^^^^^^^^^^
12+
13+
error[E0581]: return type references lifetime `'a`, which is not constrained by the fn input types
14+
--> $DIR/fn-types.rs:22:22
15+
|
16+
LL | d: for<'a> fn() -> &'a u32, // OK, used only in return type.
17+
| ^^^^^^^
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0581`.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2016 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+
#![feature(in_band_lifetimes)]
12+
#![deny(single_use_lifetime)]
13+
#![allow(dead_code)]
14+
#![allow(unused_variables)]
15+
16+
// Test that we DO warn when lifetime name is used only
17+
// once in a fn argument, even with in band lifetimes.
18+
19+
fn a(x: &'a u32, y: &'b u32) {
20+
//~^ ERROR `'a` only used once
21+
//~| ERROR `'b` only used once
22+
}
23+
24+
fn main() { }

0 commit comments

Comments
 (0)