File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,11 @@ impl TypeRef {
93
93
}
94
94
ast:: TypeRef :: PlaceholderType ( _inner) => TypeRef :: Placeholder ,
95
95
ast:: TypeRef :: FnPointerType ( inner) => {
96
- let ret_ty = TypeRef :: from_ast_opt ( inner. ret_type ( ) . and_then ( |rt| rt. type_ref ( ) ) ) ;
96
+ let ret_ty = inner
97
+ . ret_type ( )
98
+ . and_then ( |rt| rt. type_ref ( ) )
99
+ . map ( TypeRef :: from_ast)
100
+ . unwrap_or_else ( || TypeRef :: Tuple ( Vec :: new ( ) ) ) ;
97
101
let mut params = if let Some ( pl) = inner. param_list ( ) {
98
102
pl. params ( ) . map ( |p| p. ascribed_type ( ) ) . map ( TypeRef :: from_ast_opt) . collect ( )
99
103
} else {
Original file line number Diff line number Diff line change @@ -1729,3 +1729,29 @@ fn foo() -> u32 {
1729
1729
"###
1730
1730
) ;
1731
1731
}
1732
+
1733
+ #[ test]
1734
+ fn fn_pointer_return ( ) {
1735
+ assert_snapshot ! (
1736
+ infer( r#"
1737
+ struct Vtable {
1738
+ method: fn(),
1739
+ }
1740
+
1741
+ fn main() {
1742
+ let vtable = Vtable { method: || {} };
1743
+ let m = vtable.method;
1744
+ }
1745
+ "# ) ,
1746
+ @r###"
1747
+ [48; 121) '{ ...hod; }': ()
1748
+ [58; 64) 'vtable': Vtable
1749
+ [67; 91) 'Vtable...| {} }': Vtable
1750
+ [84; 89) '|| {}': || -> ()
1751
+ [87; 89) '{}': ()
1752
+ [101; 102) 'm': fn() -> ()
1753
+ [105; 111) 'vtable': Vtable
1754
+ [105; 118) 'vtable.method': fn() -> ()
1755
+ "###
1756
+ ) ;
1757
+ }
You can’t perform that action at this time.
0 commit comments