rust/crates
bors[bot] ad03e4de18
Merge #4493
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>
2020-05-18 07:44:44 +00:00
..
ra_arena Extract messy tree handling out of profiling code 2020-04-25 21:22:40 +02:00
ra_assists Merge #4273 2020-05-14 14:29:22 +00:00
ra_cfg Move feature desugaring to the right abstraction layer 2020-05-08 02:56:53 +02:00
ra_db Expand fixture documentation a little 2020-05-10 16:51:12 +02:00
ra_flycheck Cleanups 2020-05-15 02:09:30 +02:00
ra_fmt Introduce EffectExpr 2020-05-02 11:21:39 +02:00
ra_hir Add doc comment for resolve_hir_path_qualifier 2020-05-16 20:40:58 +01:00
ra_hir_def Handle Self in values and patterns 2020-05-15 17:25:28 +02:00
ra_hir_expand Store proc-macro result in salsa db 2020-05-14 17:57:51 +08:00
ra_hir_ty Add more tests for Fn traits 2020-05-18 08:07:31 +02:00
ra_ide Merge #4472 2020-05-16 19:49:01 +00:00
ra_ide_db New definition_visibility method 2020-05-11 14:28:14 +03:00
ra_mbe Reuse Vec allocations 2020-05-16 22:20:44 +02:00
ra_parser Shrink ra_parser::Event from 32 bytes to 16 bytes 2020-05-16 22:20:44 +02:00
ra_proc_macro proc_macro: add ability to log to stderr and view output in vscode 2020-04-23 01:57:02 +03:00
ra_proc_macro_srv Remove dbg 2020-05-10 06:39:36 +08:00
ra_prof Simplify profiler impl (bubble up Option and shorten code 2020-04-26 00:55:49 +03:00
ra_project_model Make some stuff public so that they can be reused by other tools 2020-05-14 11:14:46 +02:00
ra_syntax Shrink ra_parser::Event from 32 bytes to 16 bytes 2020-05-16 22:20:44 +02:00
ra_text_edit Make some stuff public so that they can be reused by other tools 2020-05-14 11:14:46 +02:00
ra_toolchain Simplify match 2020-05-09 22:20:11 +03:00
ra_tt Reduce reallocations in ra_tt::buffer::TokenBuffer::new_inner 2020-05-16 22:20:44 +02:00
rust-analyzer Add "rust-analyzer.lens.enable" 2020-05-18 10:27:00 +03:00
stdx Move snake case method to heck 2020-05-03 21:35:21 +03:00
test_utils unindent -> dedent 2020-05-09 14:48:43 +02:00