This replaces the ad-hoc tuples used in the different feature gate files
and unifies their content into a common type, leading to more readable
matches and other good stuff that comes from having named fields. It
also contains the description of each feature as extracted from the doc
comment.
typeck: refactor patterns => `pat.rs` + make the `def_bm` algo more declarative
Spurred by the relative difficulty I had in working up an explanation of how default match bindings work in https://github.com/rust-lang/rust/pull/63118#issuecomment-524161584, this PR refactors the type checking of patterns into `pat.rs`.
The PR is probably best read commit-by-commit and includes various changes beyond the following, which are the most important highlights:
- The algorithm for determining `def_bm` is encoded in a more declarative fashion now with important sub-steps divided into functions that make sense as logical units (and as described in the reference). This is done starting with *"extract `is_no_ref_pat`."* to *"extract `calc_default_binding_mode`"*.
- Dedicated functions like `check_pat_{lit,range,ident,tuple,box,ref,slice}` are then introduced for the various kinds of patterns to make things overall more readable.
- `fn check_pat_top(...)` becomes the sole entry point to type checking patterns.
This will take care of initializing the default binding mode (hence: `def_bm`) to `BindByValue` and is called by all contexts that have a pattern that needs to be type checked (functions, `match`, `if let`, `let`, ...). The overall result is that the notion of `def_bm` is internal to checking patterns.
- Various diagnostics are extracted to dedicated functions to disturb the flow of type checking logic less.
r? @oli-obk
Rollup of 6 pull requests
Successful merges:
- #62744 (Refactor `TinyList::contains` and `len` to iterate instead of recurse)
- #63813 (Do not suggest `.try_into()` on `i32::from(x)`)
- #63833 (Suggest calling closure with resolved return type when appropriate)
- #63839 (Ensure miri can do bit ops on pointer values)
- #63854 (Modifies how Arg, Arm, Field, FieldPattern and Variant are visited)
- #63859 (Don't unwrap the result of `span_to_snippet`)
Failed merges:
r? @ghost
Suggest calling closure with resolved return type when appropriate
Follow up to #63337. CC #63100.
```
error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:46:20
|
LL | let closure = || 42;
| -- closure defined here
LL | let _: usize = closure;
| ^^^^^^^
| |
| expected usize, found closure
| help: use parentheses to call this closure: `closure()`
|
= note: expected type `usize`
found type `[closure@$DIR/fn-or-tuple-struct-without-args.rs:45:19: 45:24]`
```