1 // Test that we are imposing the requirement that every associated
2 // type of a bound that appears in the where clause on a struct must
3 // outlive the location in which the type appears, even when the
4 // associted type is in a supertype. Issue #22246.
6 // revisions: migrate nll
7 //[nll]compile-flags: -Z borrowck=mir
9 // Since we are testing nll (and migration) explicitly as a separate
10 // revisions, don't worry about the --compare-mode=nll on this test.
12 // ignore-compare-mode-nll
20 pub trait TheSubTrait : TheTrait {
23 pub struct TheType<'b> {
27 impl<'b> TheTrait for TheType<'b> {
28 type TheAssocType = &'b ();
31 impl<'b> TheSubTrait for TheType<'b> {
34 pub struct WithAssoc<T:TheSubTrait> {
38 fn with_assoc<'a,'b>() {
39 // For this type to be valid, the rules require that all
40 // associated types of traits that appear in `WithAssoc` must
41 // outlive 'a. In this case, that means TheType<'b>::TheAssocType,
42 // which is &'b (), must outlive 'a.
44 let _: &'a WithAssoc<TheType<'b>> = loop { };
45 //[migrate]~^ ERROR reference has a longer lifetime
46 //[nll]~^^ ERROR lifetime may not live long enough