mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
Merge #3857
3857: Fix inference of function pointer return types r=flodiebold a=lnicola Fixes #3852. r? @flodiebold Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
3431312418
2 changed files with 31 additions and 1 deletions
|
@ -93,7 +93,11 @@ impl TypeRef {
|
||||||
}
|
}
|
||||||
ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder,
|
ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder,
|
||||||
ast::TypeRef::FnPointerType(inner) => {
|
ast::TypeRef::FnPointerType(inner) => {
|
||||||
let ret_ty = TypeRef::from_ast_opt(inner.ret_type().and_then(|rt| rt.type_ref()));
|
let ret_ty = inner
|
||||||
|
.ret_type()
|
||||||
|
.and_then(|rt| rt.type_ref())
|
||||||
|
.map(TypeRef::from_ast)
|
||||||
|
.unwrap_or_else(|| TypeRef::Tuple(Vec::new()));
|
||||||
let mut params = if let Some(pl) = inner.param_list() {
|
let mut params = if let Some(pl) = inner.param_list() {
|
||||||
pl.params().map(|p| p.ascribed_type()).map(TypeRef::from_ast_opt).collect()
|
pl.params().map(|p| p.ascribed_type()).map(TypeRef::from_ast_opt).collect()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1729,3 +1729,29 @@ fn foo() -> u32 {
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fn_pointer_return() {
|
||||||
|
assert_snapshot!(
|
||||||
|
infer(r#"
|
||||||
|
struct Vtable {
|
||||||
|
method: fn(),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let vtable = Vtable { method: || {} };
|
||||||
|
let m = vtable.method;
|
||||||
|
}
|
||||||
|
"#),
|
||||||
|
@r###"
|
||||||
|
[48; 121) '{ ...hod; }': ()
|
||||||
|
[58; 64) 'vtable': Vtable
|
||||||
|
[67; 91) 'Vtable...| {} }': Vtable
|
||||||
|
[84; 89) '|| {}': || -> ()
|
||||||
|
[87; 89) '{}': ()
|
||||||
|
[101; 102) 'm': fn() -> ()
|
||||||
|
[105; 111) 'vtable': Vtable
|
||||||
|
[105; 118) 'vtable.method': fn() -> ()
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue