rust/compiler
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
..
rustc Auto merge of #96737 - ChrisDenton:win-manifest, r=wesleywiser 2022-06-02 07:58:29 +00:00
rustc_apfloat Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_arena mark FIXMES for all the places found that are probably offset_from 2022-03-29 20:18:28 -04:00
rustc_ast Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_ast_lowering Compute lifetimes in scope at diagnostic time. 2022-06-04 15:28:15 +02:00
rustc_ast_passes Support the #[expect] attribute on fn parameters (RFC-2383) 2022-06-04 00:50:45 +02:00
rustc_ast_pretty Revert #96682. 2022-06-02 11:22:16 +10:00
rustc_attr RFC3239: Implement compact cfg(target(..)) 2022-05-24 13:51:36 +02:00
rustc_borrowck Rollup merge of #97415 - cjgillot:is-late-bound-solo, r=estebank 2022-06-03 17:10:51 +02:00
rustc_builtin_macros Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_codegen_cranelift add cast kind of from_exposed_addr (int-to-ptr casts) 2022-06-02 10:46:13 -04:00
rustc_codegen_gcc Finish bumping stage0 2022-05-27 07:36:17 -04:00
rustc_codegen_llvm Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_codegen_ssa Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_const_eval Auto merge of #97795 - Dylan-DPC:rollup-dxilagr, r=Dylan-DPC 2022-06-06 16:09:54 +00:00
rustc_data_structures Fix stacked borrows invalidation in rustc_data_structures sip128 2022-06-04 17:46:36 +02:00
rustc_driver Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_error_codes Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_error_messages migrate check_for_for_in_in_typo diagnostic 2022-05-31 16:28:05 -05:00
rustc_errors Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_expand Basic compiler infra 2022-06-02 09:00:04 -03:00
rustc_feature Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_fs_util
rustc_graphviz Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_hir Rollup merge of #97312 - cjgillot:no-path-in-scope, r=compiler-errors 2022-06-06 14:34:55 +02:00
rustc_hir_pretty Compute lifetimes in scope at diagnostic time. 2022-06-04 15:28:15 +02:00
rustc_incremental Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_index Auto merge of #95418 - cjgillot:more-disk, r=davidtwco 2022-05-20 20:49:55 +00:00
rustc_infer Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_interface Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_lexer Reduce max hash in raw strings from u16 to u8 2022-03-23 22:13:55 +01:00
rustc_lint Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_lint_defs Use serde_json for json error messages 2022-06-03 16:46:19 +00:00
rustc_llvm Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_log clippy::complexity fixes 2022-05-26 13:14:24 +02:00
rustc_macros Inline many methods of Encoder 2022-06-03 17:01:53 +00:00
rustc_metadata Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_middle Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_mir_build Replace &Vec<_>s with &[_]s 2022-06-03 20:42:42 +04:00
rustc_mir_dataflow Add a pointer to address cast kind 2022-05-31 00:00:00 +00:00
rustc_mir_transform Auto merge of #97697 - WaffleLapkin:no_ref_vec, r=WaffleLapkin 2022-06-05 09:30:53 +00:00
rustc_monomorphize Auto merge of #97168 - SparrowLii:accesses, r=cjgillot 2022-05-26 11:15:15 +00:00
rustc_parse Add spaces before and after expr in add {} suggestion 2022-06-06 01:40:52 +04:00
rustc_parse_format Make rustc_parse_format compile on stable 2022-05-03 11:26:58 +02:00
rustc_passes Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_plugin_impl Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_privacy Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_query_impl Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_query_system Address review comments. 2022-06-02 12:22:04 +10:00
rustc_resolve Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_save_analysis Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_serialize Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_session Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_span Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_symbol_mangling Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_target Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_trait_selection Rollup merge of #97721 - compiler-errors:issue-97704, r=jackh726 2022-06-06 08:37:01 +02:00
rustc_traits Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_ty_utils Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_type_ir Inline many methods of Encoder 2022-06-03 17:01:53 +00:00
rustc_typeck Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00