fix single-use lint
This commit is contained in:
parent
b406d0b268
commit
aef29a0583
29 changed files with 612 additions and 149 deletions
|
|
@ -1,14 +0,0 @@
|
|||
error: lifetime name `'x` only used once
|
||||
--> $DIR/single_use_lifetimes-2.rs:12:10
|
||||
|
|
||||
LL | fn deref<'x>() -> &'x u32 { //~ ERROR lifetime name `'x` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/single_use_lifetimes-2.rs:10:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
error: lifetime name `'x` only used once
|
||||
--> $DIR/single_use_lifetimes-3.rs:11:12
|
||||
|
|
||||
LL | struct Foo<'x> { //~ ERROR lifetime name `'x` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/single_use_lifetimes-3.rs:10:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: lifetime name `'y` only used once
|
||||
--> $DIR/single_use_lifetimes-3.rs:16:6
|
||||
|
|
||||
LL | impl<'y> Foo<'y> { //~ ERROR lifetime name `'y` only used once
|
||||
| ^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
error: lifetime name `'x` only used once
|
||||
--> $DIR/single_use_lifetimes-4.rs:12:12
|
||||
|
|
||||
LL | struct Foo<'x> { //~ ERROR lifetime name `'x` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/single_use_lifetimes-4.rs:10:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: lifetime name `'x` only used once
|
||||
--> $DIR/single_use_lifetimes-4.rs:16:10
|
||||
|
|
||||
LL | enum Bar<'x> { //~ ERROR lifetime name `'x` only used once
|
||||
| ^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
error: lifetime name `'x` only used once
|
||||
--> $DIR/single_use_lifetimes-5.rs:12:11
|
||||
|
|
||||
LL | trait Foo<'x> { //~ ERROR lifetime name `'x` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/single_use_lifetimes-5.rs:10:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
#![deny(single_use_lifetime)]
|
||||
|
||||
fn deref<'x>(v: &'x u32) -> u32 { //~ ERROR lifetime name `'x` only used once
|
||||
*v
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
error: lifetime name `'x` only used once
|
||||
--> $DIR/single_use_lifetimes.rs:12:10
|
||||
|
|
||||
LL | fn deref<'x>(v: &'x u32) -> u32 { //~ ERROR lifetime name `'x` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/single_use_lifetimes.rs:10:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
26
src/test/ui/single-use-lifetime/fn-types.rs
Normal file
26
src/test/ui/single-use-lifetime/fn-types.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
// Test that we DO warn when lifetime name is used only
|
||||
// once in a fn argument.
|
||||
|
||||
struct Foo {
|
||||
a: for<'a> fn(&'a u32), //~ ERROR `'a` only used once
|
||||
b: for<'a> fn(&'a u32, &'a u32), // OK, used twice.
|
||||
c: for<'a> fn(&'a u32) -> &'a u32, // OK, used twice.
|
||||
d: for<'a> fn() -> &'a u32, // OK, used only in return type.
|
||||
//~^ ERROR return type references lifetime `'a`, which is not constrained by the fn input types
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
21
src/test/ui/single-use-lifetime/fn-types.stderr
Normal file
21
src/test/ui/single-use-lifetime/fn-types.stderr
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
error: lifetime parameter `'a` only used once
|
||||
--> $DIR/fn-types.rs:19:10
|
||||
|
|
||||
LL | a: for<'a> fn(&'a u32), //~ ERROR `'a` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/fn-types.rs:11:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0581]: return type references lifetime `'a`, which is not constrained by the fn input types
|
||||
--> $DIR/fn-types.rs:22:22
|
||||
|
|
||||
LL | d: for<'a> fn() -> &'a u32, // OK, used only in return type.
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0581`.
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
#![feature(in_band_lifetimes)]
|
||||
#![deny(single_use_lifetime)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
// Test that we DO warn when lifetime name is used only
|
||||
// once in a fn argument, even with in band lifetimes.
|
||||
|
||||
fn a(x: &'a u32, y: &'b u32) {
|
||||
//~^ ERROR `'a` only used once
|
||||
//~| ERROR `'b` only used once
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
error: lifetime parameter `'b` only used once
|
||||
--> $DIR/one-use-in-fn-argument-in-band.rs:19:22
|
||||
|
|
||||
LL | fn a(x: &'a u32, y: &'b u32) {
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/one-use-in-fn-argument-in-band.rs:12:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: lifetime parameter `'a` only used once
|
||||
--> $DIR/one-use-in-fn-argument-in-band.rs:19:10
|
||||
|
|
||||
LL | fn a(x: &'a u32, y: &'b u32) {
|
||||
| ^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
|
|
@ -7,10 +7,15 @@
|
|||
// <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.
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
// FIXME(#44752) -- this scenario should not be warned
|
||||
fn deref<'x>() -> &'x u32 { //~ ERROR lifetime name `'x` only used once
|
||||
22
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
// Test that we DO warn when lifetime name is used only
|
||||
// once in a fn argument.
|
||||
|
||||
fn a<'a>(x: &'a u32) { //~ ERROR `'a` only used once
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
error: lifetime parameter `'a` only used once
|
||||
--> $DIR/one-use-in-fn-argument.rs:18:6
|
||||
|
|
||||
LL | fn a<'a>(x: &'a u32) { //~ ERROR `'a` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/one-use-in-fn-argument.rs:11:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
30
src/test/ui/single-use-lifetime/one-use-in-fn-return.rs
Normal file
30
src/test/ui/single-use-lifetime/one-use-in-fn-return.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
// compile-pass
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
// Test that we DO NOT warn when lifetime name is used only
|
||||
// once in a fn return type -- using `'_` is not legal there,
|
||||
// as it must refer back to an argument.
|
||||
//
|
||||
// (Normally, using `'static` would be preferred, but there are
|
||||
// times when that is not what you want.)
|
||||
//
|
||||
// run-pass
|
||||
|
||||
fn b<'a>() -> &'a u32 { // OK: used only in return type
|
||||
&22
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
// Test that we DO warn for a lifetime used only once in an impl.
|
||||
//
|
||||
// (Actually, until #15872 is fixed, you can't use `'_` here, but
|
||||
// hopefully that will come soon.)
|
||||
|
||||
struct Foo<'f> {
|
||||
data: &'f u32
|
||||
}
|
||||
|
||||
impl<'f> Foo<'f> { //~ ERROR `'f` only used once
|
||||
fn inherent_a(&self) {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
error: lifetime parameter `'f` only used once
|
||||
--> $DIR/one-use-in-inherent-impl-header.rs:24:6
|
||||
|
|
||||
LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/one-use-in-inherent-impl-header.rs:11:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
// Test that we DO warn for a lifetime used only once in an inherent method.
|
||||
|
||||
struct Foo<'f> {
|
||||
data: &'f u32
|
||||
}
|
||||
|
||||
impl<'f> Foo<'f> { //~ ERROR `'f` only used once
|
||||
fn inherent_a<'a>(&self, data: &'a u32) { //~ ERROR `'a` only used once
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
error: lifetime parameter `'a` only used once
|
||||
--> $DIR/one-use-in-inherent-method-argument.rs:22:19
|
||||
|
|
||||
LL | fn inherent_a<'a>(&self, data: &'a u32) { //~ ERROR `'a` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/one-use-in-inherent-method-argument.rs:11:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: lifetime parameter `'f` only used once
|
||||
--> $DIR/one-use-in-inherent-method-argument.rs:21:6
|
||||
|
|
||||
LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
|
||||
| ^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
// Test that we DO NOT warn for a lifetime used just once in a return type,
|
||||
// where that return type is in an inherent method.
|
||||
|
||||
struct Foo<'f> {
|
||||
data: &'f u32
|
||||
}
|
||||
|
||||
impl<'f> Foo<'f> { //~ ERROR `'f` only used once
|
||||
fn inherent_a<'a>(&self) -> &'a u32 { // OK for 'a
|
||||
&22
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
error: lifetime parameter `'f` only used once
|
||||
--> $DIR/one-use-in-inherent-method-return.rs:22:6
|
||||
|
|
||||
LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/one-use-in-inherent-method-return.rs:11:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
31
src/test/ui/single-use-lifetime/one-use-in-struct.rs
Normal file
31
src/test/ui/single-use-lifetime/one-use-in-struct.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2016 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 we do not warn for named lifetimes in structs,
|
||||
// even when they are only used once (since to not use a named
|
||||
// lifetime is illegal!)
|
||||
//
|
||||
// compile-pass
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
struct Foo<'f> {
|
||||
data: &'f u32
|
||||
}
|
||||
|
||||
enum Bar<'f> {
|
||||
Data(&'f u32)
|
||||
}
|
||||
|
||||
trait Baz<'f> { }
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2016 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 we DO warn for a lifetime on an impl used only in `&self`
|
||||
// in a trait method.
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
struct Foo<'f> {
|
||||
data: &'f u32
|
||||
}
|
||||
|
||||
impl<'f> Iterator for Foo<'f> {
|
||||
type Item = &'f u32;
|
||||
|
||||
fn next<'g>(&'g mut self) -> Option<Self::Item> { //~ ERROR `'g` only used once
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
error: lifetime parameter `'g` only used once
|
||||
--> $DIR/one-use-in-trait-method-argument.rs:25:13
|
||||
|
|
||||
LL | fn next<'g>(&'g mut self) -> Option<Self::Item> { //~ ERROR `'g` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/one-use-in-trait-method-argument.rs:14:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
|
|
@ -7,10 +7,18 @@
|
|||
// <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 we DO NOT warn when lifetime name is used in
|
||||
// both the argument and return.
|
||||
//
|
||||
// compile-pass
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
// Should not issue a warning, as explicit lifetimes are mandatory in this case:
|
||||
trait Foo<'x> { //~ ERROR lifetime name `'x` only used once
|
||||
fn foo(&self, arg: &'x u32);
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
fn c<'a>(x: &'a u32) -> &'a u32 { // OK: used twice
|
||||
&22
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
|
|
@ -7,14 +7,20 @@
|
|||
// <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 we DO NOT warn when lifetime name is used multiple
|
||||
// argments, or more than once in a single argument.
|
||||
//
|
||||
// compile-pass
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
// Neither should issue a warning, as explicit lifetimes are mandatory in this case
|
||||
struct Foo<'x> { //~ ERROR lifetime name `'x` only used once
|
||||
x: &'x u32
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
fn c<'a>(x: &'a u32, y: &'a u32) { // OK: used twice
|
||||
}
|
||||
|
||||
enum Bar<'x> { //~ ERROR lifetime name `'x` only used once
|
||||
Variant(&'x u32)
|
||||
fn d<'a>(x: (&'a u32, &'a u32)) { // OK: used twice
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
|
|
@ -7,14 +7,22 @@
|
|||
// <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 we DO NOT warn for a lifetime used twice in an impl.
|
||||
//
|
||||
// compile-pass
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
struct Foo<'x> { //~ ERROR lifetime name `'x` only used once
|
||||
x: &'x u32 // no warning!
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
struct Foo<'f> {
|
||||
data: &'f u32
|
||||
}
|
||||
|
||||
// Once #44524 is fixed, this should issue a warning.
|
||||
impl<'y> Foo<'y> { //~ ERROR lifetime name `'y` only used once
|
||||
fn method() { }
|
||||
impl<'f> Foo<'f> {
|
||||
fn inherent_a(&self, data: &'f u32) {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2016 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 we DO NOT warn for a lifetime used twice in an impl method and
|
||||
// header.
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
struct Foo<'f> {
|
||||
data: &'f u32
|
||||
}
|
||||
|
||||
impl<'f> Foo<'f> { //~ ERROR `'f` only used once
|
||||
fn inherent_a<'a>(&self, data: &'a u32) -> &'a u32{
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
error: lifetime parameter `'f` only used once
|
||||
--> $DIR/two-uses-in-inherent-method-argument-and-return.rs:22:6
|
||||
|
|
||||
LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/two-uses-in-inherent-method-argument-and-return.rs:14:9
|
||||
|
|
||||
LL | #![deny(single_use_lifetime)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
32
src/test/ui/single-use-lifetime/two-uses-in-trait-impl.rs
Normal file
32
src/test/ui/single-use-lifetime/two-uses-in-trait-impl.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright 2016 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 we DO NOT warn for a lifetime on an impl used in both
|
||||
// header and in an associated type.
|
||||
//
|
||||
// compile-pass
|
||||
|
||||
#![deny(single_use_lifetime)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
struct Foo<'f> {
|
||||
data: &'f u32
|
||||
}
|
||||
|
||||
impl<'f> Iterator for Foo<'f> {
|
||||
type Item = &'f u32;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
Loading…
Add table
Add a link
Reference in a new issue