Commit graph

1238 commits

Author SHA1 Message Date
bors
c2a408840a Auto merge of #87688 - camsteffen:let-else, r=cjgillot
Introduce `let...else`

Tracking issue: #87335

The trickiest part for me was enforcing the diverging else block with clear diagnostics. Perhaps the obvious solution is to expand to `let _: ! = ..`, but I decided against this because, when a "mismatched type" error is found in typeck, there is no way to trace where in the HIR the expected type originated, AFAICT. In order to pass down this information, I believe we should introduce `Expectation::LetElseNever(HirId)` or maybe add `HirId` to `Expectation::HasType`, but I left that as a future enhancement. For now, I simply assert that the block is `!` with a custom `ObligationCauseCode`, and I think this is clear enough, at least to start. The downside here is that the error points at the entire block rather than the specific expression with the wrong type. I left a todo to this effect.

Overall, I believe this PR is feature-complete with regard to the RFC.
2021-09-01 01:02:42 +00:00
Mara Bos
13f6d7e4cc
Rollup merge of #88504 - m-ou-se:turbofish-please-stay, r=oli-obk
Keep turbofish in prelude collision lint.

Fixes https://github.com/rust-lang/rust/issues/88442
2021-08-31 17:55:00 +02:00
Mara Bos
7c0479bd8c Use and_then instead of unwrap_or_default. 2021-08-31 16:26:27 +02:00
Mara Bos
a15dab9ce2 Use right span in prelude collision suggestions with macros. 2021-08-31 16:25:51 +02:00
Mara Bos
2a06daa863 Pull Span::find_ancestor_inside loop into its own function. 2021-08-31 16:25:51 +02:00
Mara Bos
feafda8cd3
Rollup merge of #88509 - m-ou-se:dyn-no-left-shift-right-shift-just-single-angle-brackets-please-thanks, r=petrochenkov
Don't suggest extra <> in dyn suggestion.

Fixes https://github.com/rust-lang/rust/issues/88508
2021-08-31 10:41:30 +02:00
Mara Bos
caca256b52
Rollup merge of #88503 - m-ou-se:array-into-inter-ambiguous, r=cjgillot
Warn when [T; N].into_iter() is ambiguous in the new edition.

Fixes https://github.com/rust-lang/rust/issues/88475

In https://github.com/rust-lang/rust/issues/88475, a situation was found where `[T; N].into_iter()` becomes *ambiguous* in the new edition. This is different than the case where `(&[T; N]).into_iter()` resolves differently, which was the only case handled by the `array_into_iter` lint. This is almost identical to the new-traits-in-the-prelude problem. Effectively, due to the array-into-iter hack disappearing in Rust 2021, we effectively added `IntoIterator` to the 'prelude' in Rust 2021 specifically for arrays.

This modifies the prelude collisions lint to detect that case and emit a `array_into_iter` lint in that case.
2021-08-31 10:41:29 +02:00
Mara Bos
db44069482
Rollup merge of #88497 - m-ou-se:prelude-collision-glob, r=nikomatsakis
Fix prelude collision suggestions for glob imported traits.

Fixes https://github.com/rust-lang/rust/issues/88471

cc `@nikomatsakis`
2021-08-31 10:41:28 +02:00
Mara Bos
fdf9c09c50
Rollup merge of #88496 - m-ou-se:prelude-collision-lifetime-generics, r=petrochenkov
Fix prelude collision lint suggestion for generics with lifetimes

Fixes https://github.com/rust-lang/rust/issues/88470

cc `@nikomatsakis`
2021-08-31 10:41:27 +02:00
bors
d4f263a558 Auto merge of #88467 - sexxi-goose:issue-88431, r=nikomatsakis
2229: Drop any deref in move closure

Fixes: #88431

r? `@nikomatsakis`
2021-08-31 06:01:52 +00:00
bors
1e37e83dc0 Auto merge of #88414 - Aaron1011:guess-foreign-head-span, r=estebank
Don't use `guess_head_span` in `predicates_of` for foreign span

Previously, the result of `predicates_of` for a foreign trait
would depend on the *current* state of the corresponding source
file in the foreign crate. This could lead to ICEs during incremental
compilation, since the on-disk contents of the upstream source file
could potentially change without the upstream crate being recompiled.

Additionally, this ensure that that the metadata we produce for a crate
only depends on its *compiled* upstream dependencies (e.g an rlib or
rmeta file), *not* the current on-disk state of the upstream crate
source files.
2021-08-31 03:34:22 +00:00
Cameron Steffen
2f4e86b9ef Enforce diverging let...else 2021-08-30 20:18:42 -05:00
bors
6f388bb369 Auto merge of #88369 - lcnr:cec-rename, r=oli-obk
update const generics feature gates

**tl;dr: split const generics into three features: `adt_const_params`, `const_generics_defaults` and `generic_const_exprs`**

continuing the work of `@BoxyUwU` in #88324, this PR
- renames `feature(const_evaluatable_checked)` to `feature(generic_const_exprs)` which now doesn't need any other feature gate to work. Previously `feature(const_evaluatable_checked)` was only useful in combination with `feature(const_generics)`.
- completely removes `feature(lazy_normalization_consts)`. This feature only supplied the parents generics to anonymous constants, which is pretty useless as generic anon consts are only allowed with `feature(generic_const_exprs)` anyways.
- moves the ability to use additional const param types from `feature(const_generics)` into `feature(adt_const_params)`. As `feature(const_generics)` is now mostly useless without `feature(generic_const_exprs)` we also remove that feature flag.
- updates tests, removing duplicates and unnecessary revisions in some cases and also deletes all unused `*.stderr` files.

I not also remove the ordering restriction for const and type parameters if any of the three const generics features is active.
This ordering restriction feels like the only "real" use of the current `feature(const_generics)` right now so this change isn't a perfect solution, but as I intend to stabilize the ordering - and `feature(const_generics_defaults)` -  in the very near future, I think this is acceptable for now.

---

cc `@rust-lang/project-const-generics` about the new feature names and this change in general.

I don't think we need any external approval for this change but I do intend to publish an update to the const generics tracking issue the day this PR lands, so I don't want this merged yet.

Apologies to whoever ends up reviewing this PR 😅 ❤️

r? rust-lang/project-const-generics
2021-08-30 22:21:01 +00:00
Mara Bos
ac93ca3b94 Turn to ifs into a match. 2021-08-30 23:57:16 +02:00
Mara Bos
23d2cb8435 Don't suggest extra <> in dyn suggestion. 2021-08-30 22:34:34 +02:00
Mara Bos
4986bbf135 Keep turbofish in prelude collision lint. 2021-08-30 21:55:10 +02:00
Mara Bos
336f31432d Warn when [T; N].into_iter() is ambiguous in the new edition. 2021-08-30 21:27:31 +02:00
bors
5d6804469d Auto merge of #88466 - sexxi-goose:issue-88372, r=nikomatsakis
2229: Handle update to capture kind properly

Fixes: #88372

r? `@nikomatsakis`
2021-08-30 18:27:54 +00:00
Mara Bos
51e4fbaed1 Fix prelude collision suggestions for glob imported traits. 2021-08-30 19:21:22 +02:00
Mara Bos
e2abf06890 Fix lifetime generics in <T<..> as Trait>::try_from suggestion. 2021-08-30 19:02:06 +02:00
Mara Bos
a4f6d3e5c2 Fix lifetime generics in <T as Trait<..>>::try_from suggestion. 2021-08-30 19:01:34 +02:00
lcnr
87e781799a feature(const_param_types) -> feature(adt_const_params) 2021-08-30 12:07:36 +02:00
lcnr
0c28e028b6 feature(const_generics) -> feature(const_param_types) 2021-08-30 11:00:21 +02:00
Ellen
fcc2badf9b rename const_evaluatable_checked to generic_const_exprs
2021-08-30 11:00:21 +02:00
Aman Arora
793fbc73e8 2229: Drop any deref in move closure 2021-08-29 16:28:58 -04:00
bors
2f662b1403 Auto merge of #88280 - sexxi-goose:non-exhaustive, r=nikomatsakis
Handle match statements with non exhaustive variants in closures

This PR ensures that the behavior for match statements with non exhaustive variants is the same inside and outside closures.

If we have a non-exhaustive SingleVariant which is defined in a different crate, then we should handle the case the same way we would handle a MultiVariant: borrow the match discriminant.

Closes https://github.com/rust-lang/project-rfc-2229/issues/59
r? `@nikomatsakis`
2021-08-29 20:27:14 +00:00
Aman Arora
fbd775ff29 2229: Handle update to capture kind properly 2021-08-29 15:37:03 -04:00
Guillaume Gomez
b7388024eb
Rollup merge of #88411 - Aaron1011:remove-session-if-let, r=estebank
Remove `Session.if_let_suggestions`

We can instead if either the LHS or RHS types contain
`TyKind::Error`. In addition to covering the case where
we would have previously updated `if_let_suggestions`, this might
also prevent redundant errors in other cases as well.
2021-08-29 16:25:35 +02:00
bors
59ce765484 Auto merge of #88312 - jackh726:issue-87748, r=nikomatsakis
Treat types in unnormalized function signatures as well-formed

Fixes #87748

r? `@nikomatsakis`
2021-08-29 10:12:54 +00:00
Roxane
20de556a26 Handle match with non axhaustive variants in closures 2021-08-28 19:27:32 -04:00
bors
42a2a53ec1 Auto merge of #88390 - sexxi-goose:missing-case, r=nikomatsakis
Add missing const edge case

We don't "process" const so we need to check for additional cases when the PatKind is a Path. We need to make sure that if there is only one variant that there is no field. If there is one or more field, we will want to borrow the match scrutinee

Closes https://github.com/rust-lang/rust/issues/88331
r? `@nikomatsakis`
2021-08-28 15:36:38 +00:00
inquisitivecrystal
8c62fa0575 Treat macros as HIR items 2021-08-28 00:16:34 -07:00
Aaron Hill
c9157efad6
Don't use guess_head_span in predicates_of for foreign span
Previously, the result of `predicates_of` for a foreign trait
would depend on the *current* state of the corresponding source
file in the foreign crate. This could lead to ICEs during incremental
compilation, since the on-disk contents of the upstream source file
could potentially change without the upstream crate being recompiled.

Additionally, this ensure that that the metadata we produce for a crate
only depends on its *compiled* upstream dependencies (e.g an rlib or
rmeta file), *not* the current on-disk state of the upstream crate
source files.
2021-08-27 23:19:49 -05:00
Aaron Hill
672d370764
Remove Session.if_let_suggestions
We can instead if either the LHS or RHS types contain
`TyKind::Error`. In addition to covering the case where
we would have previously updated `if_let_suggestions`, this might
also prevent redundant errors in other cases as well.
2021-08-27 18:28:22 -05:00
Niko Matsakis
c4dba5a64e use |= 2021-08-27 17:13:41 -04:00
Niko Matsakis
f34909d68f simplify the logic and document 2021-08-27 16:30:45 -04:00
Roxane
110a9b3b1c Add comment and fix fmt issue 2021-08-27 09:00:50 -04:00
Roxane
8fcfd6e136 Add missing const edge case 2021-08-27 08:25:06 -04:00
Deadbeef
f3d96e9391
fmt 2021-08-27 08:09:00 +00:00
Deadbeef
80e1ee5aee
Add ty::BoundConstness 2021-08-27 06:49:18 +00:00
Deadbeef
703c557aaa
Fix more tests 2021-08-27 05:07:38 +00:00
Deadbeef
8660832086
Introduce ~const
- [x] Removed `?const` and change uses of `?const`
 - [x] Added `~const` to the AST. It is gated behind const_trait_impl.
 - [x] Validate `~const` in ast_validation.
 - [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and
 `ConstIfConst` allowing future extensions)
 - [ ] Adjust trait selection and pre-existing code to use `BoundConstness`.
 - [ ] Optional steps (*for this PR, obviously*)
      - [ ] Fix #88155
      - [ ] Do something with constness bounds in chalk
2021-08-27 05:07:37 +00:00
bors
d5cd3205fd Auto merge of #88371 - Manishearth:rollup-pkkjsme, r=Manishearth
Rollup of 11 pull requests

Successful merges:

 - #87832 (Fix debugger stepping behavior with `match` expressions)
 - #88123 (Make spans for tuple patterns in E0023 more precise)
 - #88215 (Reland #83738: "rustdoc: Don't load all extern crates unconditionally")
 - #88216 (Don't stabilize creation of TryReserveError instances)
 - #88270 (Handle type ascription type ops in NLL HRTB diagnostics)
 - #88289 (Fixes for LLVM change 0f45c16f2caa7c035e5c3edd40af9e0d51ad6ba7)
 - #88320 (type_implements_trait consider obligation failure on overflow)
 - #88332 (Add argument types tait tests)
 - #88340 (Add `c_size_t` and `c_ssize_t` to `std::os::raw`.)
 - #88346 (Revert "Add type of a let tait test impl trait straight in let")
 - #88348 (Add field types tait tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-08-27 01:07:17 +00:00
bors
517c28e421 Auto merge of #87280 - lcnr:lazy-anon-const-default-substs, r=nikomatsakis
lazily "compute" anon const default substs

Continuing the work of #83086, this implements the discussed solution for the [unused substs problem](https://github.com/rust-lang/project-const-generics/blob/master/design-docs/anon-const-substs.md#unused-substs). As of now, anonymous constants inherit all of their parents generics, even if they do not use them, e.g. in `fn foo<T, const N: usize>() -> [T; N + 1]`, the array length has `T` as a generic parameter even though it doesn't use it. These *unused substs* cause some backwards incompatible, and imo incorrect behavior, e.g. #78369.

---
We do not actually filter any generic parameters here and the `default_anon_const_substs` query still a dummy which only checks that
- we now prevent the previously existing query cycles and are able to call `predicates_of(parent)` when computing the substs of anonymous constants
- the default anon consts substs only include the typeflags we assume it does.

Implementing that filtering will be left as future work.

---

The idea of this PR is to delay the creation of the anon const substs until after we've computed `predicates_of` for the parent of the anon const. As the predicates of the parent can however contain the anon const we still have to create a `ty::Const` for it.

We do this by changing the substs field of `ty::Unevaluated` to an option and modifying accesses to instead call the method `unevaluated.substs(tcx)` which returns the substs as before. If the substs - now `substs_` -  of `ty::Unevaluated` are `None`, it means that the anon const currently has its default substs, i.e. the substs it has when first constructed, which are the generic parameters it has available. To be able to call `unevaluated.substs(tcx)` in a `TypeVisitor`, we add the non-defaulted method `fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>>`. In case `tcx_for_anon_const_substs` returns `None`, unknown anon const default substs are skipped entirely.

Even when `substs_` is `None` we still have to treat the constant as if it has its default substs. To do this, `TypeFlags` are modified so that it is clear whether they can still change when *exposing* any anon const default substs. A new flag, `HAS_UNKNOWN_DEFAULT_CONST_SUBSTS`, is added in case some default flags are missing.

The rest of this PR are some smaller changes to either not cause cycles by trying to access the default anon const substs too early or to be able to access the `tcx` in previously unused locations.

cc `@rust-lang/project-const-generics`
r? `@nikomatsakis`
2021-08-26 22:26:23 +00:00
Manish Goregaokar
8aa46e51df
Rollup merge of #88123 - camelid:tup-pat-precise-spans, r=estebank
Make spans for tuple patterns in E0023 more precise

As suggested in #86307. Closes #86307.

r? ````@estebank````
2021-08-26 12:38:06 -07:00
bors
4b9f4b221b Auto merge of #88308 - eddyb:cooked-layouts, r=nagisa
Morph `layout_raw` query into `layout_of`.

Before this PR, `LayoutCx::layout_of` wrapped the `layout_raw` query, to:
* normalize the type, before attempting to compute the layout
* pass the layout to `record_layout_for_printing`, for `-Zprint-type-sizes`

Moving those two responsibilities into the query may reduce overhead (due to cached calls skipping those steps), but I want to do a perf run to know.

One of the changes I had to make was changing the return type of the query, to be able to both get out the type produced by normalizing inside the query *and* to match the signature of the old `TyCtxt::layout_of`. This change may be worse, perf-wise, so that's another reason I want to check.

r? `@nagisa` cc `@oli-obk`
2021-08-26 15:24:01 +00:00
jackh726
97bf80dfda Treat types in unnormalized function signatures as well-formed 2021-08-26 10:59:20 -04:00
lcnr
bc0983df06 add fixme 2021-08-26 11:14:31 +02:00
lcnr
f3996f6a88 review 2021-08-26 11:14:31 +02:00
lcnr
bc0156bace shrink ty::PredicateKind again 2021-08-26 11:00:30 +02:00