Implementation of the const_static_lifetime lint.
This commit is contained in:
parent
9293188b65
commit
322effe415
4 changed files with 120 additions and 2 deletions
33
tests/ui/const_static_lifetime.rs
Normal file
33
tests/ui/const_static_lifetime.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#![feature(plugin)]
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Foo {}
|
||||
|
||||
const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.
|
||||
|
||||
const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning.
|
||||
|
||||
const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
|
||||
|
||||
const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
|
||||
|
||||
const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
|
||||
|
||||
const VAR_SIX: &'static u8 = &5;
|
||||
|
||||
const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
|
||||
|
||||
const VAR_HEIGHT: &'static Foo = &Foo {};
|
||||
|
||||
fn main() {
|
||||
let false_positive: &'static str = "test";
|
||||
println!("{}", VAR_ONE);
|
||||
println!("{}", VAR_TWO);
|
||||
println!("{:?}", VAR_THREE);
|
||||
println!("{:?}", VAR_FOUR);
|
||||
println!("{:?}", VAR_FIVE);
|
||||
println!("{:?}", VAR_SIX);
|
||||
println!("{:?}", VAR_SEVEN);
|
||||
println!("{:?}", VAR_HEIGHT);
|
||||
println!("{}", false_positive);
|
||||
}
|
||||
|
|
@ -9,8 +9,8 @@ extern crate regex;
|
|||
use regex::{Regex, RegexSet, RegexBuilder};
|
||||
use regex::bytes::{Regex as BRegex, RegexSet as BRegexSet, RegexBuilder as BRegexBuilder};
|
||||
|
||||
const OPENING_PAREN : &'static str = "(";
|
||||
const NOT_A_REAL_REGEX : &'static str = "foobar";
|
||||
const OPENING_PAREN: &str = "(";
|
||||
const NOT_A_REAL_REGEX: &str = "foobar";
|
||||
|
||||
fn syntax_error() {
|
||||
let pipe_in_wrong_position = Regex::new("|");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue