From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/nll/user-annotations/normalization-2.rs | 152 +++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 tests/ui/nll/user-annotations/normalization-2.rs (limited to 'tests/ui/nll/user-annotations/normalization-2.rs') diff --git a/tests/ui/nll/user-annotations/normalization-2.rs b/tests/ui/nll/user-annotations/normalization-2.rs new file mode 100644 index 000000000..be23c3b74 --- /dev/null +++ b/tests/ui/nll/user-annotations/normalization-2.rs @@ -0,0 +1,152 @@ +// Make sure we honor region constraints when normalizing type annotations. + +// check-fail + +#![feature(more_qualified_paths)] + +trait Trait { + type Assoc; +} + +impl Trait for T +where + T: 'static, +{ + type Assoc = MyTy<()>; +} + +enum MyTy { + Unit, + Tuple(), + Struct {}, + Dumb(T), +} + +impl MyTy { + const CONST: () = (); + fn method() {} + fn method2(&self) {} +} + +trait TraitAssoc { + const TRAIT_CONST: (); + fn trait_method(&self); +} +impl TraitAssoc for T { + const TRAIT_CONST: () = (); + fn trait_method(&self) {} +} + +type Ty<'a> = <&'a () as Trait>::Assoc; + +fn test_local<'a>() { + let _: Ty<'a> = MyTy::Unit; + //~^ ERROR lifetime may not live long enough +} + +fn test_closure_sig<'a, 'b>() { + |_: Ty<'a>| {}; + //~^ ERROR lifetime may not live long enough + || -> Option> { None }; + //~^ ERROR lifetime may not live long enough +} + +fn test_path<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h>() { + >::method::>; + //~^ ERROR lifetime may not live long enough + >::method::>; + //~^ ERROR lifetime may not live long enough + + >::trait_method::>; + //~^ ERROR lifetime may not live long enough + >::trait_method::>; + //~^ ERROR lifetime may not live long enough + + >::CONST; + //~^ ERROR lifetime may not live long enough + >::TRAIT_CONST; + //~^ ERROR lifetime may not live long enough + + >::method::>; + >::trait_method::>; + >::CONST; + >::TRAIT_CONST; + + MyTy::Unit::>; + //~^ ERROR lifetime may not live long enough + MyTy::>::Unit; + //~^ ERROR lifetime may not live long enough +} + +fn test_call<'a, 'b, 'c>() { + >::method::>(); + //~^ ERROR lifetime may not live long enough + >::method::>(); + //~^ ERROR lifetime may not live long enough +} + +fn test_variants<'a, 'b, 'c>() { + >::Struct {}; + //~^ ERROR lifetime may not live long enough + >::Tuple(); + //~^ ERROR lifetime may not live long enough + >::Unit; + //~^ ERROR lifetime may not live long enough +} + +fn test_method_call<'a, 'b>(x: MyTy<()>) { + x.method2::>(); + //~^ ERROR lifetime may not live long enough + x.trait_method::>(); + //~^ ERROR lifetime may not live long enough +} + +fn test_struct_path<'a, 'b, 'c, 'd>() { + struct Struct { x: Option, } + + trait Project { + type Struct; + type Enum; + } + impl Project for T { + type Struct = Struct<()>; + type Enum = MyTy<()>; + } + + // Resolves to enum variant + MyTy::>::Struct {}; // without SelfTy + //~^ ERROR lifetime may not live long enough + as Project>::Enum::Struct {}; // with SelfTy + //~^ ERROR lifetime may not live long enough + + // Resolves to struct and associated type respectively + Struct::> { x: None, }; // without SelfTy + //~^ ERROR lifetime may not live long enough + as Project>::Struct { x: None, }; // with SelfTy + //~^ ERROR lifetime may not live long enough +} + +fn test_pattern<'a, 'b, 'c, 'd, 'e, 'f>() { + use MyTy::*; + match MyTy::Unit { + Struct::> {..} => {}, + //~^ ERROR lifetime may not live long enough + Tuple::> (..) => {}, + //~^ ERROR lifetime may not live long enough + Unit::> => {}, + //~^ ERROR lifetime may not live long enough + Dumb(_) => {}, + }; + match MyTy::Unit { + >::Struct {..} => {}, + //~^ ERROR lifetime may not live long enough + >::Tuple (..) => {}, + //~^ ERROR lifetime may not live long enough + >::Unit => {}, + //~^ ERROR lifetime may not live long enough + Dumb(_) => {}, + }; +} + + +fn main() {} -- cgit v1.2.3