fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1// edition:2018 2// aux-build:edition-lint-infer-outlives-macro.rs 3// run-rustfix 4 5#![deny(explicit_outlives_requirements)] 6#![allow(dead_code)] 7 8#[macro_use] 9extern crate edition_lint_infer_outlives_macro; 10 11// Test that the lint does not fire if the predicate is from the local crate, 12// but all the bounds are from an external macro. 13macro_rules! make_foo { 14 ($a:tt) => { 15 struct Foo<$a, 'b: $a> { 16 foo: &$a &'b (), 17 } 18 19 struct FooWhere<$a, 'b> where 'b: $a { 20 foo: &$a &'b (), 21 } 22 } 23} 24 25gimme_a! {make_foo!} 26 27struct Bar<'a, 'b> { 28 //~^ ERROR: outlives requirements can be inferred 29 bar: &'a &'b (), 30} 31 32struct BarWhere<'a, 'b> { 33 //~^ ERROR: outlives requirements can be inferred 34 bar: &'a &'b (), 35} 36 37// Test that the lint *does* fire if the predicate is contained in a local macro. 38mod everything_inside { 39 macro_rules! m { 40 ('b: 'a) => { 41 struct Foo<'a, 'b>(&'a &'b ()); 42 //~^ ERROR: outlives requirements can be inferred 43 struct Bar<'a, 'b>(&'a &'b ()) ; 44 //~^ ERROR: outlives requirements can be inferred 45 struct Baz<'a, 'b>(&'a &'b ()) where (): Sized, ; 46 //~^ ERROR: outlives requirements can be inferred 47 }; 48 } 49 m!('b: 'a); 50} 51 52mod inner_lifetime_outside_colon_inside { 53 macro_rules! m { 54 ($b:lifetime: 'a) => { 55 struct Foo<'a, $b>(&'a &$b ()); 56 //~^ ERROR: outlives requirements can be inferred 57 struct Bar<'a, $b>(&'a &$b ()) ; 58 //~^ ERROR: outlives requirements can be inferred 59 struct Baz<'a, $b>(&'a &$b ()) where (): Sized, ; 60 //~^ ERROR: outlives requirements can be inferred 61 } 62 } 63 m!('b: 'a); 64} 65 66mod outer_lifetime_outside_colon_inside { 67 macro_rules! m { 68 ('b: $a:lifetime) => { 69 struct Foo<$a, 'b: $a>(&$a &'b ()); 70 struct Bar<$a, 'b>(&$a &'b ()) where 'b: $a; 71 struct Baz<$a, 'b>(&$a &'b ()) where (): Sized, 'b: $a; 72 } 73 } 74 m!('b: 'a); 75} 76 77mod both_lifetimes_outside_colon_inside { 78 macro_rules! m { 79 ($b:lifetime: $a:lifetime) => { 80 struct Foo<$a, $b: $a>(&$a &$b ()); 81 struct Bar<$a, $b>(&$a &$b ()) where $b: $a; 82 struct Baz<$a, $b>(&$a &$b ()) where (): Sized, $b: $a; 83 } 84 } 85 m!('b: 'a); 86} 87 88mod everything_outside { 89 macro_rules! m { 90 ($b:lifetime $colon:tt $a:lifetime) => { 91 struct Foo<$a, $b $colon $a>(&$a &$b ()); 92 struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a; 93 struct Baz<$a, $b>(&$a &$b ()) where (): Sized, $b $colon $a; 94 } 95 } 96 m!('b: 'a); 97} 98 99mod everything_outside_with_tt_inner { 100 macro_rules! m { 101 ($b:tt $colon:tt $a:lifetime) => { 102 struct Foo<$a, $b $colon $a>(&$a &$b ()); 103 struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a; 104 struct Baz<$a, $b>(&$a &$b ()) where (): Sized, $b $colon $a; 105 } 106 } 107 m!('b: 'a); 108} 109 110// FIXME: These should be consistent. 111mod everything_outside_with_tt_outer { 112 macro_rules! m { 113 ($b:lifetime $colon:tt $a:tt) => { 114 struct Foo<$a, $b >(&$a &$b ()); 115 //~^ ERROR: outlives requirements can be inferred 116 struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a; 117 struct Baz<$a, $b>(&$a &$b ()) where (): Sized, $b $colon $a; 118 } 119 } 120 m!('b: 'a); 121} 122 123mod everything_outside_with_tt_both { 124 macro_rules! m { 125 ($b:tt $colon:tt $a:tt) => { 126 struct Foo<$a, $b >(&$a &$b ()); 127 //~^ ERROR: outlives requirements can be inferred 128 struct Bar<$a, $b>(&$a &$b ()) where ; 129 //~^ ERROR: outlives requirements can be inferred 130 struct Baz<$a, $b>(&$a &$b ()) where (): Sized, ; 131 //~^ ERROR: outlives requirements can be inferred 132 } 133 } 134 m!('b: 'a); 135} 136 137fn main() {}