rust/compiler
Matthias Krüger 857afc75e6
Rollup merge of #99212 - davidtwco:partial-stability-implies, r=michaelwoerister
introduce `implied_by` in `#[unstable]` attribute

Requested by the library team [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/better.20support.20for.20partial.20stabilizations/near/285581519).

If part of a feature is stabilized and a new feature is added for the remaining parts, then the `implied_by` meta-item can be added to `#[unstable]` to indicate which now-stable feature was used previously.

```diagnostic
error: the feature `foo` has been partially stabilized since 1.62.0 and is succeeded by the feature `foobar`
  --> $DIR/stability-attribute-implies-using-unstable.rs:3:12
   |
LL | #![feature(foo)]
   |            ^^^
   |
note: the lint level is defined here
  --> $DIR/stability-attribute-implies-using-stable.rs:2:9
   |
LL | #![deny(stable_features)]
   |         ^^^^^^^^^^^^^^^
help: if you are using features which are still unstable, change to using `foobar`
   |
LL | #![feature(foobar)]
   |            ~~~~~~
help: if you are using features which are now stable, remove this line
   |
LL - #![feature(foo)]
   |
```

When a `#![feature(..)]` attribute still exists for the now-stable attribute, then there this has two effects:

- There will not be an stability error for uses of items from the implied feature which are still unstable (until the `#![feature(..)]` is removed or updated to the new feature).
- There will be an improved diagnostic for the remaining use of the feature attribute for the now-stable feature.

```rust
        /// If part of a feature is stabilized and a new feature is added for the remaining parts,
        /// then the `implied_by` attribute is used to indicate which now-stable feature previously
        /// contained a item.
        ///
        /// ```pseudo-Rust
        /// #[unstable(feature = "foo", issue = "...")]
        /// fn foo() {}
        /// #[unstable(feature = "foo", issue = "...")]
        /// fn foobar() {}
        /// ```
        ///
        /// ...becomes...
        ///
        /// ```pseudo-Rust
        /// #[stable(feature = "foo", since = "1.XX.X")]
        /// fn foo() {}
        /// #[unstable(feature = "foobar", issue = "...", implied_by = "foo")]
        /// fn foobar() {}
        /// ```
```

In the Zulip discussion, this was envisioned as `implies` on `#[stable]` but I went with `implied_by` on `#[unstable]` because it means that only the unstable attribute needs to be changed in future, not the new stable attribute, which seems less error-prone. It also isn't particularly feasible for me to detect whether items from the implied feature are used and then only suggest updating _or_ removing the `#![feature(..)]` as appropriate, so I always do both.

There's some new information in the cross-crate metadata as a result of this change, that's a little unfortunate, but without requiring that the `#[unstable]` and `#[stable]` attributes both contain the implication information, it's necessary:

```rust
    /// This mapping is necessary unless both the `#[stable]` and `#[unstable]` attributes should
    /// specify their implications (both `implies` and `implied_by`). If only one of the two
    /// attributes do (as in the current implementation, `implied_by` in `#[unstable]`), then this
    /// mapping is necessary for diagnostics. When a "unnecessary feature attribute" error is
    /// reported, only the `#[stable]` attribute information is available, so the map is necessary
    /// to know that the feature implies another feature. If it were reversed, and the `#[stable]`
    /// attribute had an `implies` meta item, then a map would be necessary when avoiding a "use of
    /// unstable feature" error for a feature that was implied.
```

I also change some comments to documentation comments in the compiler, add a helper for going from a `Span` to a `Span` for the entire line, and fix a incorrect part of the pre-existing stability attribute diagnostics.

cc `@yaahc`
2022-07-20 18:58:14 +02:00
..
rustc Don't rerun the build script for the compiler each time on linux 2022-07-10 23:57:25 -05:00
rustc_apfloat Update smallvec to 1.8.1. 2022-06-27 08:48:55 +10:00
rustc_arena Rollup merge of #97711 - Nilstrieb:rustc-arena-ub, r=wesleywiser 2022-07-07 18:06:49 +05:30
rustc_ast Stabilize let_chains 2022-07-16 20:17:58 -03:00
rustc_ast_lowering Rollup merge of #99401 - TaKO8Ki:avoid-symbol-to-&str-conversions, r=nnethercote 2022-07-19 13:30:46 +02:00
rustc_ast_passes Auto merge of #98180 - notriddle:notriddle/rustdoc-fn, r=petrochenkov,GuillaumeGomez 2022-07-19 19:36:57 +00:00
rustc_ast_pretty Parse closure binders 2022-07-12 16:25:16 +04:00
rustc_attr middle: add implies_by to #[unstable] 2022-07-20 14:53:01 +01:00
rustc_borrowck Auto merge of #99506 - Dylan-DPC:rollup-q3msucx, r=Dylan-DPC 2022-07-20 13:36:59 +00:00
rustc_builtin_macros Don't add attribute to allow unused-qualifications to derive impl's 2022-07-18 22:28:17 -04:00
rustc_codegen_cranelift Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank" 2022-07-20 07:55:58 +00:00
rustc_codegen_gcc Rename debugging_opts to unstable_opts 2022-07-13 17:47:06 -05:00
rustc_codegen_llvm Rollup merge of #99401 - TaKO8Ki:avoid-symbol-to-&str-conversions, r=nnethercote 2022-07-19 13:30:46 +02:00
rustc_codegen_ssa Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank" 2022-07-20 07:55:58 +00:00
rustc_const_eval Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank" 2022-07-20 07:55:58 +00:00
rustc_data_structures use par_for_each_in in par_body_owners and collect_crate_mono_items 2022-07-19 17:00:51 +08:00
rustc_driver Rename debugging_opts to unstable_opts 2022-07-13 17:47:06 -05:00
rustc_error_codes Auto merge of #98180 - notriddle:notriddle/rustdoc-fn, r=petrochenkov,GuillaumeGomez 2022-07-19 19:36:57 +00:00
rustc_error_messages Auto merge of #98180 - notriddle:notriddle/rustdoc-fn, r=petrochenkov,GuillaumeGomez 2022-07-19 19:36:57 +00:00
rustc_errors Mention first and last macro in backtrace 2022-07-19 03:07:54 +00:00
rustc_expand Rollup merge of #99435 - CAD97:revert-dollar-dollar-crate, r=Mark-Simulacrum 2022-07-19 13:30:48 +02:00
rustc_feature Stabilize let_chains 2022-07-16 20:17:58 -03:00
rustc_fs_util
rustc_graphviz Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_hir Rollup merge of #99119 - TaKO8Ki:remove-string-matching-about-methods, r=cjgillot 2022-07-15 15:53:38 +05:30
rustc_hir_pretty use rustc_hir_pretty::qpath_to_string to avoid span_to_snippet when rendering path 2022-07-17 04:58:38 +00:00
rustc_incremental Rename debugging_opts to unstable_opts 2022-07-13 17:47:06 -05:00
rustc_index Use a bitset instead of a hash map in HIR ID validator 2022-07-04 08:30:13 +02:00
rustc_infer Rollup merge of #99383 - ouz-a:issue_57961, r=oli-obk 2022-07-20 16:17:19 +05:30
rustc_interface Add flag to configure noalias on Box<T> 2022-07-19 16:02:59 +02:00
rustc_lexer fix typo in comment 2022-06-28 19:59:09 +05:30
rustc_lint Rollup merge of #99433 - cjgillot:erase-foreign-sig, r=compiler-errors 2022-07-20 11:29:39 +05:30
rustc_lint_defs Only suggest if span is not erroneous 2022-07-15 17:32:34 +00:00
rustc_llvm Auto merge of #98843 - Urgau:check-cfg-stage0, r=Mark-Simulacrum 2022-07-20 04:23:09 +00:00
rustc_log clippy::complexity fixes 2022-05-26 13:14:24 +02:00
rustc_macros macros: support adding warnings to diags 2022-07-15 16:13:49 +01:00
rustc_metadata passes: improved partial stabilization diagnostic 2022-07-20 14:53:01 +01:00
rustc_middle Rollup merge of #99212 - davidtwco:partial-stability-implies, r=michaelwoerister 2022-07-20 18:58:14 +02:00
rustc_mir_build Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank" 2022-07-20 07:55:58 +00:00
rustc_mir_dataflow Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank" 2022-07-20 07:55:58 +00:00
rustc_mir_transform Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank" 2022-07-20 07:55:58 +00:00
rustc_monomorphize use par_for_each_in in par_body_owners and collect_crate_mono_items 2022-07-19 17:00:51 +08:00
rustc_parse Stabilize let_chains 2022-07-16 20:17:58 -03:00
rustc_parse_format Make rustc_parse_format compile on stable 2022-05-03 11:26:58 +02:00
rustc_passes passes: check implied feature exists 2022-07-20 15:50:59 +01:00
rustc_plugin_impl remove currently unused deps 2022-06-13 22:20:51 +03:00
rustc_privacy errors: lint on LintDiagnosticBuilder::build 2022-07-15 16:13:47 +01:00
rustc_query_impl Use constant eval to do strict validity checks 2022-07-14 22:55:17 +01:00
rustc_query_system Rename debugging_opts to unstable_opts 2022-07-13 17:47:06 -05:00
rustc_resolve middle: add implies_by to #[unstable] 2022-07-20 14:53:01 +01:00
rustc_save_analysis Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillot 2022-07-14 14:14:21 +05:30
rustc_serialize use BufReader for counting zero bytes 2022-07-02 22:51:42 +09:00
rustc_session Add flag to configure noalias on Box<T> 2022-07-19 16:02:59 +02:00
rustc_smir Rustfmt 2022-06-02 10:29:00 +00:00
rustc_span span: add span_extend_to_line helper 2022-07-20 14:53:01 +01:00
rustc_symbol_mangling Allow to create definitions inside the query system. 2022-07-06 22:50:55 +02:00
rustc_target Auto merge of #99033 - 5225225:interpreter-validity-checks, r=oli-obk 2022-07-17 19:28:01 +00:00
rustc_trait_selection take opaq types 2022-07-20 12:43:10 +03:00
rustc_traits Update TypeVisitor paths 2022-07-06 06:41:53 +01:00
rustc_ty_utils Rollup merge of #99000 - JulianKnodt:allow_resolve_no_substs, r=lcnr 2022-07-14 19:24:04 +05:30
rustc_type_ir Auto merge of #98614 - oli-obk:take_unsound_opaque_types, r=wesleywiser 2022-07-08 17:55:26 +00:00
rustc_typeck Rollup merge of #99486 - TaKO8Ki:remove-type-string-comparison-in-check-str-addition, r=compiler-errors 2022-07-20 16:17:23 +05:30