rust/tests/ui/rust-2018/edition-lint-infer-outlives-macro.rs

138 lines
3.9 KiB
Rust
Raw Normal View History

2022-05-07 06:08:04 -05:00
// edition:2018
// aux-build:edition-lint-infer-outlives-macro.rs
2022-12-25 15:16:04 -06:00
// run-rustfix
2022-05-07 06:08:04 -05:00
#![deny(explicit_outlives_requirements)]
2022-12-25 15:16:04 -06:00
#![allow(dead_code)]
2022-05-07 06:08:04 -05:00
#[macro_use]
extern crate edition_lint_infer_outlives_macro;
2022-12-25 15:16:04 -06:00
// Test that the lint does not fire if the predicate is from the local crate,
// but all the bounds are from an external macro.
2022-05-07 06:08:04 -05:00
macro_rules! make_foo {
($a:tt) => {
2022-12-25 15:16:04 -06:00
struct Foo<$a, 'b: $a> {
2022-05-07 06:08:04 -05:00
foo: &$a &'b (),
}
2022-12-25 15:16:04 -06:00
struct FooWhere<$a, 'b> where 'b: $a {
foo: &$a &'b (),
}
2022-12-25 15:16:04 -06:00
}
2022-05-07 06:08:04 -05:00
}
gimme_a! {make_foo!}
struct Bar<'a, 'b: 'a> {
//~^ ERROR: outlives requirements can be inferred
bar: &'a &'b (),
}
2022-12-25 15:16:04 -06:00
struct BarWhere<'a, 'b> where 'b: 'a {
//~^ ERROR: outlives requirements can be inferred
bar: &'a &'b (),
}
// Test that the lint *does* fire if the predicate is contained in a local macro.
mod everything_inside {
macro_rules! m {
('b: 'a) => {
struct Foo<'a, 'b: 'a>(&'a &'b ());
//~^ ERROR: outlives requirements can be inferred
2022-12-25 15:16:04 -06:00
struct Bar<'a, 'b>(&'a &'b ()) where 'b: 'a;
//~^ ERROR: outlives requirements can be inferred
struct Baz<'a, 'b>(&'a &'b ()) where (): Sized, 'b: 'a;
//~^ ERROR: outlives requirements can be inferred
};
}
m!('b: 'a);
}
2022-12-25 15:16:04 -06:00
mod inner_lifetime_outside_colon_inside {
macro_rules! m {
($b:lifetime: 'a) => {
struct Foo<'a, $b: 'a>(&'a &$b ());
//~^ ERROR: outlives requirements can be inferred
2022-12-25 15:16:04 -06:00
struct Bar<'a, $b>(&'a &$b ()) where $b: 'a;
//~^ ERROR: outlives requirements can be inferred
struct Baz<'a, $b>(&'a &$b ()) where (): Sized, $b: 'a;
//~^ ERROR: outlives requirements can be inferred
}
}
m!('b: 'a);
}
mod outer_lifetime_outside_colon_inside {
macro_rules! m {
('b: $a:lifetime) => {
struct Foo<$a, 'b: $a>(&$a &'b ());
struct Bar<$a, 'b>(&$a &'b ()) where 'b: $a;
struct Baz<$a, 'b>(&$a &'b ()) where (): Sized, 'b: $a;
}
2022-12-25 15:16:04 -06:00
}
m!('b: 'a);
}
2022-12-25 15:16:04 -06:00
mod both_lifetimes_outside_colon_inside {
macro_rules! m {
($b:lifetime: $a:lifetime) => {
struct Foo<$a, $b: $a>(&$a &$b ());
struct Bar<$a, $b>(&$a &$b ()) where $b: $a;
struct Baz<$a, $b>(&$a &$b ()) where (): Sized, $b: $a;
}
}
m!('b: 'a);
}
2022-12-25 15:16:04 -06:00
mod everything_outside {
macro_rules! m {
($b:lifetime $colon:tt $a:lifetime) => {
struct Foo<$a, $b $colon $a>(&$a &$b ());
struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a;
struct Baz<$a, $b>(&$a &$b ()) where (): Sized, $b $colon $a;
}
2022-12-25 15:16:04 -06:00
}
m!('b: 'a);
}
2022-12-25 15:16:04 -06:00
mod everything_outside_with_tt_inner {
macro_rules! m {
($b:tt $colon:tt $a:lifetime) => {
struct Foo<$a, $b $colon $a>(&$a &$b ());
struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a;
struct Baz<$a, $b>(&$a &$b ()) where (): Sized, $b $colon $a;
}
2022-12-25 15:16:04 -06:00
}
m!('b: 'a);
}
2022-12-25 15:16:04 -06:00
// FIXME: These should be consistent.
mod everything_outside_with_tt_outer {
macro_rules! m {
($b:lifetime $colon:tt $a:tt) => {
struct Foo<$a, $b $colon $a>(&$a &$b ());
//~^ ERROR: outlives requirements can be inferred
struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a;
struct Baz<$a, $b>(&$a &$b ()) where (): Sized, $b $colon $a;
}
}
m!('b: 'a);
}
2022-12-25 15:16:04 -06:00
mod everything_outside_with_tt_both {
macro_rules! m {
($b:tt $colon:tt $a:tt) => {
struct Foo<$a, $b $colon $a>(&$a &$b ());
//~^ ERROR: outlives requirements can be inferred
struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a;
//~^ ERROR: outlives requirements can be inferred
struct Baz<$a, $b>(&$a &$b ()) where (): Sized, $b $colon $a;
//~^ ERROR: outlives requirements can be inferred
}
}
m!('b: 'a);
}
2022-05-07 06:08:04 -05:00
fn main() {}