]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obk
authorYuki Okushi <huyuumi.dev@gmail.com>
Sun, 25 Oct 2020 09:43:40 +0000 (18:43 +0900)
committerGitHub <noreply@github.com>
Sun, 25 Oct 2020 09:43:40 +0000 (18:43 +0900)
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s

`#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks.
While it was originally only meant to be used only on macros, its use was expanded to `const fn`s.

This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s.

This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540).

Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'.

Closes rust-lang/rust#69399

r? @oli-obk

1  2 
compiler/rustc_feature/src/active.rs
compiler/rustc_mir/src/transform/check_consts/mod.rs
compiler/rustc_mir/src/transform/check_consts/validation.rs
compiler/rustc_passes/src/check_attr.rs
compiler/rustc_span/src/symbol.rs
library/alloc/src/lib.rs
library/alloc/src/raw_vec.rs
library/core/src/slice/mod.rs
library/std/src/lib.rs

Simple merge
index b93d63b4fddb9335d2bdf731f3bce6e1b0e073b0,1eb06c0ef65e2db88899c7f207794d8eeb4c8e9b..ba7bea4ac54e15b1a206055a7ae9d1c26c43f462
@@@ -74,14 -74,16 +74,18 @@@ impl ConstCx<'mir, 'tcx> 
  
  /// Returns `true` if this `DefId` points to one of the official `panic` lang items.
  pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
 -    Some(def_id) == tcx.lang_items().panic_fn() || Some(def_id) == tcx.lang_items().begin_panic_fn()
 +    Some(def_id) == tcx.lang_items().panic_fn()
 +        || Some(def_id) == tcx.lang_items().panic_str()
 +        || Some(def_id) == tcx.lang_items().begin_panic_fn()
  }
  
- pub fn allow_internal_unstable(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool {
+ pub fn rustc_allow_const_fn_unstable(
+     tcx: TyCtxt<'tcx>,
+     def_id: DefId,
+     feature_gate: Symbol,
+ ) -> bool {
      let attrs = tcx.get_attrs(def_id);
-     attr::allow_internal_unstable(&tcx.sess, attrs)
+     attr::rustc_allow_const_fn_unstable(&tcx.sess, attrs)
          .map_or(false, |mut features| features.any(|name| name == feature_gate))
  }
  
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge