typeck: suggest use of match_default_bindings feature
Fixes#45383.
Updates #42640.
r? @nikomatsakis
cc @tschottdorf
This needs a UI test, but thought I'd get some early feedback.
Improve display of error E0308
Ref. Forgetting to call a variant constructor causes a confusing error message #35241.
This PR modifies [`note_type_err`](b7041bfab3/src/librustc/infer/error_reporting/mod.rs (L669-L674)) to display a `help` message when a `TyFnPtr` or `TyFnDef` are found and the return type, of the function or function pointer, is the same as the type that is expected.
The output of compiling
```rust
struct Foo(u32);
fn test() -> Foo { Foo }
fn main() {}
```
is now
```bash
$ rustc src/test/ui/issue-35241.rs
error[E0308]: mismatched types
--> src/test/ui/issue-35241.rs:13:20
|
13 | fn test() -> Foo { Foo }
| --- ^^^ expected struct `Foo`, found fn item
| |
| expected `Foo` because of return type
|
= help: did you mean `Foo { /* fields */ }`?
= note: expected type `Foo`
found type `fn(u32) -> Foo {Foo::{{constructor}}}`
error: aborting due to previous error
```
Bring back slice::ref_slice as slice::from_ref.
These functions were deprecated and removed in 1.5, but such simple
functionality shouldn't require using unsafe code, and it isn't
cluttering libstd too much.
The original removal was quite contentious (see #27774), since then
we've had precedent for including such nuggets of functionality (see rust-lang/rfcs#1789),
and @nikomatsakis has provided a lot of use cases in https://github.com/rust-lang/rfcs/pull/1789#issuecomment-314640034.
Hence this PR.
I'm not too sure what to do with stability, feel free to correct me.
It seems pointless to go through stabilization for these functions though.
cc @aturon
This special cases the function type sugar in paths and deals with traits bounds as just the path parts. That required refactoring the path collector to distinguish between variable decls and references in patterns, basically just to please the borrow checker.
cc https://github.com/nrc/rls-analysis/issues/37
enable non-lexical lifetimes in the MIR borrow checker
This PR, joint work with @spastorino, fills out the NLL infrastructure and integrates it with the borrow checker. **Don't get too excited:** it includes still a number of hacks (the subtyping code is particularly hacky). However, it *does* kinda' work. =)
The final commit demonstrates this by including a test that -- with both the AST borrowck and MIR borrowck -- reports an error by default. But if you pass `-Znll`, you only get an error from the AST borrowck, demonstrating that the integration succeeds:
```
struct MyStruct {
field: String
}
fn main() {
let mut my_struct = MyStruct { field: format!("Hello") };
let value = &my_struct.field;
if value.is_empty() {
my_struct.field.push_str("Hello, world!");
//~^ ERROR cannot borrow (Ast)
}
}
```
incr.comp.: Implement compiler diagnostic persistence.
This PR implements storing and loading diagnostics that the compiler generates and thus allows for emitting warnings during incremental compilation without actually re-evaluating the thing the warning originally came from. It also lays some groundwork for storing and loading type information and MIR in the incr. comp. cache.
~~It is still work in progress:~~
- ~~There's still some documentation to be added.~~
- ~~The way anonymous queries are handled might lead to duplicated emissions of warnings. Not sure if there is a better way or how frequent such duplication would be in practice.~~
Diagnostic message duplication is addressed separately in #45519.
r? @nikomatsakis
Currently, the compiler requires `T` to also be `Send`. There is no reason for
that. `&Rw{Read,Write}LockGuard` only provides a shared referenced to `T`, sending
that across threads is safe if `T` is `Sync`.