ad03e4de18
4493: Provide builtin impls of Fn traits for fn-pointers r=flodiebold a=hban Meant to be, but isn't actually a fix for #2880. Consider this snippet: ```rust use std::marker::PhantomData; use std::ops::Deref; struct Lazy<T, F/* = fn() -> T*/>(F, PhantomData<T>); impl<T, F> Lazy<T, F> { pub fn new(f: F) -> Lazy<T, F> { Lazy(f, PhantomData) } } impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> { type Target = T; fn deref(&self) -> &T { todo!() } } fn test() { let lazy1: Lazy<u32, _> = Lazy::new(|| 0u32); let r1 = lazy1.to_string(); fn make_u32_fn() -> u32 { todo!() } let make_u32_fn_ptr: fn() -> u32 = make_u32_fn; let lazy2: Lazy<u32, _> = Lazy::new(make_u32_fn_ptr); let r2 = lazy2.to_string(); } ``` * On current master: * When type default is commented-out, `r1` is correctly inferred, `r2` in _{unknown}_. * When type default is not commented-out, both `r1` and `r2` are _{unknown}_. * With this PR: * When type default is commented-out, both `r1` and `r2` are correctly inferred. * When type default is not commented-out, both `r1` and `r2` are _{unknown}_. Well, it's a improvement at least. I guess this thing with type defaults is a different problem. I also tried add Fn impls for fn items, but wasn't successful. So this PR only adds those impls for fn pointers. Co-authored-by: Hrvoje Ban <hban@users.noreply.github.com> |
||
---|---|---|
.cargo | ||
.github | ||
.vscode | ||
crates | ||
docs | ||
editors/code | ||
xtask | ||
.gitattributes | ||
.gitignore | ||
bors.toml | ||
Cargo.lock | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md | ||
rustfmt.toml |
rust-analyzer is an experimental modular compiler frontend for the Rust language. It is a part of a larger rls-2.0 effort to create excellent IDE support for Rust. If you want to get involved, check the rls-2.0 working group:
https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0
Work on rust-analyzer is sponsored by
Quick Start
https://rust-analyzer.github.io/manual.html#installation
Documentation
If you want to contribute to rust-analyzer or are just curious about how things work under the hood, check the ./docs/dev folder.
If you want to use rust-analyzer's language server with your editor of choice, check the manual folder. It also contains some tips & tricks to help you be more productive when using rust-analyzer.
Getting in touch
We are on the rust-lang Zulip!
https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frls-2.2E0
Quick Links
- API docs: https://rust-analyzer.github.io/rust-analyzer/ra_ide/
- Website: https://rust-analyzer.github.io/
License
Rust analyzer is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.