Auto merge of #93695 - matthiaskrgr:rollup-zslgooo, r=matthiaskrgr
Rollup of 2 pull requests Successful merges: - #90998 (Require const stability attribute on all stable functions that are `const`) - #93489 (Mark the panic_no_unwind lang item as nounwind) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
7b43cfc9b2
@ -577,17 +577,21 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_missing_const_stability(&self, def_id: LocalDefId, span: Span) {
|
fn check_missing_const_stability(&self, def_id: LocalDefId, span: Span) {
|
||||||
let stab_map = self.tcx.stability();
|
if !self.tcx.features().staged_api {
|
||||||
let stab = stab_map.local_stability(def_id);
|
return;
|
||||||
if stab.map_or(false, |stab| stab.level.is_stable()) {
|
|
||||||
let const_stab = stab_map.local_const_stability(def_id);
|
|
||||||
if const_stab.is_none() {
|
|
||||||
self.tcx.sess.span_err(
|
|
||||||
span,
|
|
||||||
"`#[stable]` const functions must also be either \
|
|
||||||
`#[rustc_const_stable]` or `#[rustc_const_unstable]`",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let is_const = self.tcx.is_const_fn(def_id.to_def_id());
|
||||||
|
let is_stable = self
|
||||||
|
.tcx
|
||||||
|
.lookup_stability(def_id)
|
||||||
|
.map_or(false, |stability| stability.level.is_stable());
|
||||||
|
let missing_const_stability_attribute = self.tcx.lookup_const_stability(def_id).is_none();
|
||||||
|
let is_reachable = self.access_levels.is_reachable(def_id);
|
||||||
|
|
||||||
|
if is_const && is_stable && missing_const_stability_attribute && is_reachable {
|
||||||
|
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
|
||||||
|
self.tcx.sess.span_err(span, &format!("{descr} has missing const stability attribute"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -612,13 +616,8 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
|
|||||||
self.check_missing_stability(i.def_id, i.span);
|
self.check_missing_stability(i.def_id, i.span);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure `const fn` that are `stable` have one of `rustc_const_unstable` or
|
// Ensure stable `const fn` have a const stability attribute.
|
||||||
// `rustc_const_stable`.
|
|
||||||
if self.tcx.features().staged_api
|
|
||||||
&& matches!(&i.kind, hir::ItemKind::Fn(sig, ..) if sig.header.is_const())
|
|
||||||
{
|
|
||||||
self.check_missing_const_stability(i.def_id, i.span);
|
self.check_missing_const_stability(i.def_id, i.span);
|
||||||
}
|
|
||||||
|
|
||||||
intravisit::walk_item(self, i)
|
intravisit::walk_item(self, i)
|
||||||
}
|
}
|
||||||
@ -632,6 +631,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
|
|||||||
let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id());
|
let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id());
|
||||||
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
|
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
|
||||||
self.check_missing_stability(ii.def_id, ii.span);
|
self.check_missing_stability(ii.def_id, ii.span);
|
||||||
|
self.check_missing_const_stability(ii.def_id, ii.span);
|
||||||
}
|
}
|
||||||
intravisit::walk_impl_item(self, ii);
|
intravisit::walk_impl_item(self, ii);
|
||||||
}
|
}
|
||||||
|
@ -2778,6 +2778,13 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The panic_no_unwind function called by TerminatorKind::Abort will never
|
||||||
|
// unwind. If the panic handler that it invokes unwind then it will simply
|
||||||
|
// call the panic handler again.
|
||||||
|
if Some(id) == tcx.lang_items().panic_no_unwind() {
|
||||||
|
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND;
|
||||||
|
}
|
||||||
|
|
||||||
let supported_target_features = tcx.supported_target_features(LOCAL_CRATE);
|
let supported_target_features = tcx.supported_target_features(LOCAL_CRATE);
|
||||||
|
|
||||||
let mut inline_span = None;
|
let mut inline_span = None;
|
||||||
|
@ -512,6 +512,7 @@ impl<T, const N: usize> [T; N] {
|
|||||||
|
|
||||||
/// Returns a slice containing the entire array. Equivalent to `&s[..]`.
|
/// Returns a slice containing the entire array. Equivalent to `&s[..]`.
|
||||||
#[stable(feature = "array_as_slice", since = "1.57.0")]
|
#[stable(feature = "array_as_slice", since = "1.57.0")]
|
||||||
|
#[rustc_const_stable(feature = "array_as_slice", since = "1.57.0")]
|
||||||
pub const fn as_slice(&self) -> &[T] {
|
pub const fn as_slice(&self) -> &[T] {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -1959,6 +1959,7 @@ impl<T: ?Sized> UnsafeCell<T> {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[stable(feature = "unsafe_cell_raw_get", since = "1.56.0")]
|
#[stable(feature = "unsafe_cell_raw_get", since = "1.56.0")]
|
||||||
|
#[rustc_const_stable(feature = "unsafe_cell_raw_get", since = "1.56.0")]
|
||||||
pub const fn raw_get(this: *const Self) -> *mut T {
|
pub const fn raw_get(this: *const Self) -> *mut T {
|
||||||
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
|
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
|
||||||
// #[repr(transparent)]. This exploits libstd's special status, there is
|
// #[repr(transparent)]. This exploits libstd's special status, there is
|
||||||
|
@ -1064,6 +1064,7 @@ macro_rules! int_impl {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "saturating_div", since = "1.58.0")]
|
#[stable(feature = "saturating_div", since = "1.58.0")]
|
||||||
|
#[rustc_const_stable(feature = "saturating_div", since = "1.58.0")]
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -972,6 +972,7 @@ macro_rules! nonzero_unsigned_is_power_of_two {
|
|||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
|
#[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
|
||||||
|
#[rustc_const_stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn is_power_of_two(self) -> bool {
|
pub const fn is_power_of_two(self) -> bool {
|
||||||
// LLVM 11 normalizes `unchecked_sub(x, 1) & x == 0` to the implementation seen here.
|
// LLVM 11 normalizes `unchecked_sub(x, 1) & x == 0` to the implementation seen here.
|
||||||
|
@ -1132,6 +1132,7 @@ macro_rules! uint_impl {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "saturating_div", since = "1.58.0")]
|
#[stable(feature = "saturating_div", since = "1.58.0")]
|
||||||
|
#[rustc_const_stable(feature = "saturating_div", since = "1.58.0")]
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -136,6 +136,10 @@ impl<'a> PanicInfo<'a> {
|
|||||||
/// This is true for most kinds of panics with the exception of panics
|
/// This is true for most kinds of panics with the exception of panics
|
||||||
/// caused by trying to unwind out of a `Drop` implementation or a function
|
/// caused by trying to unwind out of a `Drop` implementation or a function
|
||||||
/// whose ABI does not support unwinding.
|
/// whose ABI does not support unwinding.
|
||||||
|
///
|
||||||
|
/// It is safe for a panic handler to unwind even when this function returns
|
||||||
|
/// true, however this will simply cause the panic handler to be called
|
||||||
|
/// again.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[unstable(feature = "panic_can_unwind", issue = "92988")]
|
#[unstable(feature = "panic_can_unwind", issue = "92988")]
|
||||||
pub fn can_unwind(&self) -> bool {
|
pub fn can_unwind(&self) -> bool {
|
||||||
|
@ -1,12 +1,26 @@
|
|||||||
#![feature(staged_api)]
|
#![feature(staged_api)]
|
||||||
|
#![feature(const_trait_impl)]
|
||||||
|
#![stable(feature = "stable", since = "1.0.0")]
|
||||||
|
|
||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "stable", since = "1.0.0")]
|
||||||
|
pub const fn foo() {} //~ ERROR function has missing const stability attribute
|
||||||
|
|
||||||
#[stable(feature = "foo", since = "1.0.0")]
|
#[unstable(feature = "unstable", issue = "none")]
|
||||||
pub const fn foo() {}
|
pub const fn bar() {} // ok because function is unstable
|
||||||
//~^ ERROR rustc_const_stable
|
|
||||||
|
|
||||||
#[unstable(feature = "bar", issue = "none")]
|
#[stable(feature = "stable", since = "1.0.0")]
|
||||||
pub const fn bar() {} // ok
|
pub struct Foo;
|
||||||
|
impl Foo {
|
||||||
|
#[stable(feature = "stable", since = "1.0.0")]
|
||||||
|
pub const fn foo() {} //~ ERROR associated function has missing const stability attribute
|
||||||
|
|
||||||
|
#[unstable(feature = "unstable", issue = "none")]
|
||||||
|
pub const fn bar() {} // ok because function is unstable
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME Once #![feature(const_trait_impl)] is allowed to be stable, add a test
|
||||||
|
// for const trait impls. Right now, a "trait methods cannot be stable const fn"
|
||||||
|
// error is emitted. This occurs prior to the lint being tested here, such that
|
||||||
|
// the lint cannot currently be tested on this use case.
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
error: `#[stable]` const functions must also be either `#[rustc_const_stable]` or `#[rustc_const_unstable]`
|
error: function has missing const stability attribute
|
||||||
--> $DIR/missing-const-stability.rs:6:1
|
--> $DIR/missing-const-stability.rs:6:1
|
||||||
|
|
|
|
||||||
LL | pub const fn foo() {}
|
LL | pub const fn foo() {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: associated function has missing const stability attribute
|
||||||
|
--> $DIR/missing-const-stability.rs:15:5
|
||||||
|
|
|
||||||
|
LL | pub const fn foo() {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user