2 // Test that we can't ignore lifetimes by going through Any.
6 struct Foo<'a>(&'a str);
8 fn good(s: &String) -> Foo { Foo(s) }
10 fn bad1(s: String) -> Option<&'static str> {
11 let a: Box<dyn Any> = Box::new(good as fn(&String) -> Foo);
12 a.downcast_ref::<fn(&String) -> Foo<'static>>().map(|f| f(&s).0)
16 fn get(&'a self) -> &'b str;
19 impl<'a> AsStr<'a, 'a> for String {
20 fn get(&'a self) -> &'a str { self }
23 fn bad2(s: String) -> Option<&'static str> {
24 let a: Box<dyn Any> = Box::new(Box::new(s) as Box<dyn for<'a> AsStr<'a, 'a>>);
25 a.downcast_ref::<Box<dyn for<'a> AsStr<'a, 'static>>>().map(|x| x.get())
29 assert_eq!(bad1(String::from("foo")), None);
30 assert_eq!(bad2(String::from("bar")), None);