Commit Graph

722 Commits

Author SHA1 Message Date
Takayuki Maeda
f9a924d3c9 remove an unnecessary format macro 2022-06-11 18:35:10 +09:00
Dylan DPC
dfbedf5692
Rollup merge of #97967 - BoxyUwU:at_docs_mention_trace, r=compiler-errors
Mention `infer::Trace` methods on `infer::At` methods' docs

I missed that you could do `infcx.at(...).trace(...).eq(a, b)` when `a` and `b` dont implement `ToTrace` but does implement `Relate` these docs would have helped see that 😅
2022-06-11 07:42:16 +02:00
Dylan DPC
59c2ff532d
Rollup merge of #97703 - lcnr:post-89862, r=estebank
some additional `need_type_info.rs` cleanup

also fixes #97698, fixes #97806

cc `@estebank`
2022-06-11 07:42:13 +02:00
Ellen
9f1d3702a4 the day that i make a PR without a tidy error.. 2022-06-10 21:47:00 +01:00
Ellen
5d91e9e941 a 2022-06-10 21:26:53 +01:00
lcnr
efdf948f43 use FxHashMap instead of BTreeMap 2022-06-10 14:24:36 +02:00
lcnr
3d26f5a000 eagerly check whether we replace any bound vars 2022-06-10 10:09:50 +02:00
lcnr
e61807c6bf update higher_ranked_sub docs 2022-06-10 10:09:50 +02:00
lcnr
cc013e05b4 bound_vars -> infer: don't return lt map 2022-06-10 10:09:50 +02:00
lcnr
543ca7d9e7 replace bound vars: make caching explicit 2022-06-10 10:09:50 +02:00
lcnr
36a4490271 rewrite combine doc comment 2022-06-09 10:45:41 +02:00
lcnr
d6b28f377c add test + don't warn on Res::SelfTy 2022-06-08 18:00:08 +02:00
lcnr
f8e73ede83 need_type_info: don't ICE when detected ty alias
fixes #97698
2022-06-08 10:13:02 +02:00
lcnr
2ea468e386 dedup diagnostics default params handling 2022-06-08 10:13:00 +02:00
bors
64a7aa7016 Auto merge of #97447 - nnethercote:improve-folding, r=jackh726
Folding revamp

r? `@ghost`
2022-06-08 05:36:40 +00:00
Nicholas Nethercote
90db033955 Folding revamp.
This commit makes type folding more like the way chalk does it.

Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods.
- `fold_with` is the standard entry point, and defaults to calling
  `super_fold_with`.
- `super_fold_with` does the actual work of traversing a type.
- For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead
  calls into a `TypeFolder`, which can then call back into
  `super_fold_with`.

With the new approach, `TypeFoldable` has `fold_with` and
`TypeSuperFoldable` has `super_fold_with`.
- `fold_with` is still the standard entry point, *and* it does the
  actual work of traversing a type, for all types except types of
  interest.
- `super_fold_with` is only implemented for the types of interest.

Benefits of the new model.
- I find it easier to understand. The distinction between types of
  interest and other types is clearer, and `super_fold_with` doesn't
  exist for most types.
- With the current model is easy to get confused and implement a
  `super_fold_with` method that should be left defaulted. (Some of the
  precursor commits fixed such cases.)
- With the current model it's easy to call `super_fold_with` within
  `TypeFolder` impls where `fold_with` should be called. The new
  approach makes this mistake impossible, and this commit fixes a number
  of such cases.
- It's potentially faster, because it avoids the `fold_with` ->
  `super_fold_with` call in all cases except types of interest. A lot of
  the time the compile would inline those away, but not necessarily
  always.
2022-06-08 09:24:03 +10:00
Nicholas Nethercote
7480b501b4 Avoid some unnecessary returns. 2022-06-08 09:22:23 +10:00
Nicholas Nethercote
28be201d2f Use super_visit_with in a couple of visit_binder methods.
Because it's equivalent but simpler to what's currently there.
2022-06-08 09:22:23 +10:00
bors
b17e9d76f2 Auto merge of #97081 - oli-obk:outlives_query_fast_path, r=jackh726
Re-use the type op instead of calling the implied_outlives_bounds query directly

r? `@ghost`
2022-06-07 21:44:40 +00:00
bors
bb55bd449e Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis
Remove migrate borrowck mode

Closes #58781
Closes #43234

# Stabilization proposal

This PR proposes the stabilization of `#![feature(nll)]` and the removal of `-Z borrowck`. Current borrow checking behavior of item bodies is currently done by first infering regions *lexically* and reporting any errors during HIR type checking. If there *are* any errors, then MIR borrowck (NLL) never occurs. If there *aren't* any errors, then MIR borrowck happens and any errors there would be reported. This PR removes the lexical region check of item bodies entirely and only uses MIR borrowck. Because MIR borrowck could never *not* be run for a compiled program, this should not break any programs. It does, however, change diagnostics significantly and allows a slightly larger set of programs to compile.

Tracking issue: #43234
RFC: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md
Version: 1.63 (2022-06-30 => beta, 2022-08-11 => stable).

## Motivation

Over time, the Rust borrow checker has become "smarter" and thus allowed more programs to compile. There have been three different implementations: AST borrowck, MIR borrowck, and polonius (well, in progress). Additionally, there is the "lexical region resolver", which (roughly) solves the constraints generated through HIR typeck. It is not a full borrow checker, but does emit some errors.

The AST borrowck was the original implementation of the borrow checker and was part of the initially stabilized Rust 1.0. In mid 2017, work began to implement the current MIR borrow checker and that effort ompleted by the end of 2017, for the most part. During 2018, efforts were made to migrate away from the AST borrow checker to the MIR borrow checker - eventually culminating into "migrate" mode - where HIR typeck with lexical region resolving following by MIR borrow checking - being active by default in the 2018 edition.

In early 2019, migrate mode was turned on by default in the 2015 edition as well, but with MIR borrowck errors emitted as warnings. By late 2019, these warnings were upgraded to full errors. This was followed by the complete removal of the AST borrow checker.

In the period since, various errors emitted by the MIR borrow checker have been improved to the point that they are mostly the same or better than those emitted by the lexical region resolver.

While there do remain some degradations in errors (tracked under the [NLL-diagnostics tag](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-diagnostics), those are sufficiently small and rare enough that increased flexibility of MIR borrow check-only is now a worthwhile tradeoff.

## What is stabilized

As said previously, this does not fundamentally change the landscape of accepted programs. However, there are a [few](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-fixed-by-NLL) cases where programs can compile under `feature(nll)`, but not otherwise.

There are two notable patterns that are "fixed" by this stabilization. First, the `scoped_threads` feature, which is a continutation of a pre-1.0 API, can sometimes emit a [weird lifetime error](https://github.com/rust-lang/rust/issues/95527) without NLL. Second, actually seen in the standard library. In the `Extend` impl for `HashMap`, there is an implied bound of `K: 'a` that is available with NLL on but not without - this is utilized in the impl.

As mentioned before, there are a large number of diagnostic differences. Most of them are better, but some are worse. None are serious or happen often enough to need to block this PR. The biggest change is the loss of error code for a number of lifetime errors in favor of more general "lifetime may not live long enough" error. While this may *seem* bad, the former error codes were just attempts to somewhat-arbitrarily bin together lifetime errors of the same type; however, on paper, they end up being roughly the same with roughly the same kinds of solutions.

## What isn't stabilized

This PR does not completely remove the lexical region resolver. In the future, it may be possible to remove that (while still keeping HIR typeck) or to remove it together with HIR typeck.

## Tests

Many test outputs get updated by this PR. However, there are number of tests specifically geared towards NLL under `src/test/ui/nll`

## History

* On 2017-07-14, [tracking issue opened](https://github.com/rust-lang/rust/issues/43234)
* On 2017-07-20, [initial empty MIR pass added](https://github.com/rust-lang/rust/pull/43271)
* On 2017-08-29, [RFC opened](https://github.com/rust-lang/rfcs/pull/2094)
* On 2017-11-16, [Integrate MIR type-checker with NLL](https://github.com/rust-lang/rust/pull/45825)
* On 2017-12-20, [NLL feature complete](https://github.com/rust-lang/rust/pull/46862)
* On 2018-07-07, [Don't run AST borrowck on mir mode](https://github.com/rust-lang/rust/pull/52083)
* On 2018-07-27, [Add migrate mode](https://github.com/rust-lang/rust/pull/52681)
* On 2019-04-22, [Enable migrate mode on 2015 edition](https://github.com/rust-lang/rust/pull/59114)
* On 2019-08-26, [Don't downgrade errors on 2015 edition](https://github.com/rust-lang/rust/pull/64221)
* On 2019-08-27, [Remove AST borrowck](https://github.com/rust-lang/rust/pull/64790)
2022-06-07 05:04:14 +00:00
Jack Huey
410dcc9674 Fully stabilize NLL 2022-06-03 17:16:41 -04:00
Maybe Waffle
afaa9854fa Replace &Vec<_>s with &[_]s 2022-06-03 20:42:42 +04:00
bors
e40d5e83dc Auto merge of #89862 - lcnr:path-generics-diagnostics, r=estebank
rewrite error handling for unresolved inference vars

Pretty much completely rewrites `fn emit_inference_failure_err`.

This new setup should hopefully be easier to extend and is already a lot better when looking for generic arguments.
Because this is a rewrite there are still some parts which are lacking, these are tracked in #94483 and will be fixed in later PRs.

r? `@estebank` `@petrochenkov`
2022-06-03 12:37:16 +00:00
Dylan DPC
5c041f98fa
Rollup merge of #97023 - cjgillot:uniform-anon, r=estebank
Diagnose anonymous lifetimes errors more uniformly between async and regular fns

Async fns and regular fns are desugared differently.  For the former, we create a generic parameter at HIR level.  For the latter, we just create an anonymous region for typeck.

I plan to migrate regular fns to the async fn desugaring.

Before that, this PR attempts to merge the diagnostics for both cases.

r? ```@estebank```
2022-06-02 11:13:22 +02:00
lcnr
681736a6b2 generic_arg_contains_target: ignore closures 2022-06-02 10:19:15 +02:00
lcnr
69d575e58d eagerly fetch the typeck_results 2022-06-02 10:19:15 +02:00
lcnr
bc0d12cc6c use verbose suggestions 2022-06-02 10:19:15 +02:00
lcnr
3fe346e7a3 add new emit_inference_failure_err 2022-06-02 10:19:15 +02:00
lcnr
721fc73208 remove the old emit_inference_failure_err 2022-06-02 10:19:15 +02:00
Dylan DPC
65bdfe3b41
Rollup merge of #97531 - compiler-errors:for-loop-pat-mismatch, r=davidtwco
Note pattern mismatch coming from `for` loop desugaring

Fixes #97163
2022-05-30 14:33:52 +02:00
Michael Goulet
2e25c2346b Note pattern mismatch coming from for-loop desugaring 2022-05-29 13:01:59 -07:00
bors
bef2b7cd1c Auto merge of #97214 - Mark-Simulacrum:stage0-bump, r=pietroalbini
Finish bumping stage0

It looks like the last time had left some remaining cfg's -- which made me think
that the stage0 bump was actually successful. This brings us to a released 1.62
beta though.

This now brings us to cfg-clean, with the exception of check-cfg-features in bootstrap;
I'd prefer to leave that for a separate PR at this time since it's likely to be more tricky.

cc https://github.com/rust-lang/rust/pull/97147#issuecomment-1132845061

r? `@pietroalbini`
2022-05-29 16:28:21 +00:00
Camille GILLOT
3162b33ce5 Handle anonymous lifetimes properly in diagnostics. 2022-05-29 12:16:09 +02:00
Camille GILLOT
da175c743c Make lifetime errors more precise in the presence of Fresh lifetimes. 2022-05-29 12:16:09 +02:00
Mark Rousskov
b454991ac4 Finish bumping stage0
It looks like the last time had left some remaining cfg's -- which made me think
that the stage0 bump was actually successful. This brings us to a released 1.62
beta though.
2022-05-27 07:36:17 -04:00
b-naber
5f65331b3e suggest constraining dyn trait in impl in NLL 2022-05-25 18:13:17 +02:00
b-naber
c1072d2a9a make TraitObject visitors public 2022-05-25 18:13:16 +02:00
Dylan DPC
f4bf64c3f0
Rollup merge of #97292 - compiler-errors:tcxify-rustc, r=davidtwco
Lifetime variance fixes for rustc

#97287 migrates rustc to a `Ty` type that is invariant over its lifetime `'tcx`, so I need to fix a bunch of places that assume that `Ty<'a>` and `Ty<'b>` can be unified by shortening both to some common lifetime.

This is doable, since many lifetimes are already `'tcx`, so all this PR does is be a bit more explicit that elided lifetimes are actually `'tcx`.

Split out from #97287 so the compiler team can review independently.
2022-05-23 15:11:04 +02:00
Michael Goulet
1784634a39 Lifetime variance fixes for rustc 2022-05-22 14:29:32 -07:00
Jack Huey
683a9c8391 Do leak check after function ptr coercion 2022-05-22 11:18:36 -04:00
Matthias Krüger
76f662c963
Rollup merge of #97109 - TaKO8Ki:fix-misleading-cannot-infer-type-for-type-parameter-error, r=oli-obk
Fix misleading `cannot infer type for type parameter` error

closes #93198
2022-05-20 19:54:39 +02:00
Takayuki Maeda
3d0f9fb544 report ambiguous type parameters when their parents are impl or fn
fix ci error

emit err for `impl_item`
2022-05-20 23:04:44 +09:00
lcnr
4fcf43f67c update comments 2022-05-20 11:49:29 +02:00
Yuki Okushi
13ee094260
Rollup merge of #97080 - lcnr:relate-sus, r=oli-obk
remove the `RelateResultCompare` trait

it's unused
2022-05-17 19:01:33 +09:00
Takayuki Maeda
910979a6d4 fix misleading cannot infer type for type parameter error 2022-05-17 17:34:58 +09:00
bors
c1d65eaa45 Auto merge of #96892 - oli-obk:🐌_obligation_cause_code_🐌, r=estebank
Clean up derived obligation creation

r? `@estebank`

working on fixing the perf regression from https://github.com/rust-lang/rust/pull/91030#issuecomment-1083360210
2022-05-17 01:46:25 +00:00
Oli Scherer
14da30e3e6 Split some logic from a loop into a separate function 2022-05-16 14:23:52 +00:00
Oli Scherer
340e708634 Some tracing cleanups 2022-05-16 14:23:15 +00:00
lcnr
0ea7301fa3 remove the RelateResultCompare trait 2022-05-16 15:41:05 +02:00
bors
2a8a0fc423 Auto merge of #96883 - jackh726:early-binder-2, r=oli-obk
Add EarlyBinder

Chalk has no concept of `Param` (e0ade19d13/chalk-ir/src/lib.rs (L579)) or `ReEarlyBound` (e0ade19d13/chalk-ir/src/lib.rs (L1308)). Everything  is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk.

Either way, tracking when we have or haven't already substituted out these in rustc can be helpful.

As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted.

r? `@nikomatsakis`
2022-05-14 23:53:11 +00:00