mirror of https://github.com/rust-lang/rust.git
Stabilize `LazyCell` and `LazyLock` (`lazy_cell`)
This commit is contained in:
parent
0b2f194b83
commit
4913ab8f77
|
@ -309,7 +309,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
|||
}
|
||||
|
||||
if let ConstContext::Static(_) = ccx.const_kind() {
|
||||
err.note("consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell");
|
||||
err.note("consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`");
|
||||
}
|
||||
|
||||
err
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#![feature(extend_one)]
|
||||
#![feature(hash_raw_entry)]
|
||||
#![feature(hasher_prefixfree_extras)]
|
||||
#![feature(lazy_cell)]
|
||||
#![feature(lint_reasons)]
|
||||
#![feature(macro_metavar_expr)]
|
||||
#![feature(map_try_insert)]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#![doc(rust_logo)]
|
||||
#![feature(rustdoc_internals)]
|
||||
#![feature(lazy_cell)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![allow(internal_features)]
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#![allow(internal_features)]
|
||||
#![feature(rustdoc_internals)]
|
||||
#![doc(rust_logo)]
|
||||
#![feature(lazy_cell)]
|
||||
|
||||
mod accepted;
|
||||
mod builtin_attrs;
|
||||
|
|
|
@ -68,7 +68,6 @@ This API is completely unstable and subject to change.
|
|||
#![feature(iter_intersperse)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(never_type)]
|
||||
#![feature(lazy_cell)]
|
||||
#![feature(slice_partition_dedup)]
|
||||
#![feature(try_blocks)]
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#![feature(decl_macro)]
|
||||
#![feature(lazy_cell)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(thread_spawn_unchecked)]
|
||||
#![feature(try_blocks)]
|
||||
|
|
|
@ -1316,10 +1316,8 @@ declare_lint! {
|
|||
/// * If you are trying to perform a one-time initialization of a global:
|
||||
/// * If the value can be computed at compile-time, consider using
|
||||
/// const-compatible values (see [Constant Evaluation]).
|
||||
/// * For more complex single-initialization cases, consider using a
|
||||
/// third-party crate, such as [`lazy_static`] or [`once_cell`].
|
||||
/// * If you are using the [nightly channel], consider the new
|
||||
/// [`lazy`] module in the standard library.
|
||||
/// * For more complex single-initialization cases, consider using
|
||||
/// [`std::sync::LazyLock`].
|
||||
/// * If you truly need a mutable global, consider using a [`static`],
|
||||
/// which has a variety of options:
|
||||
/// * Simple data types can be directly defined and mutated with an
|
||||
|
@ -1334,9 +1332,7 @@ declare_lint! {
|
|||
/// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
|
||||
/// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
|
||||
/// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
|
||||
/// [`lazy`]: https://doc.rust-lang.org/nightly/std/lazy/index.html
|
||||
/// [`lazy_static`]: https://crates.io/crates/lazy_static
|
||||
/// [`once_cell`]: https://crates.io/crates/once_cell
|
||||
/// [`std::sync::LazyLock`]: https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html
|
||||
/// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
|
||||
/// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
|
||||
pub CONST_ITEM_MUTATION,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#![feature(let_chains)]
|
||||
#![feature(lazy_cell)]
|
||||
#![feature(option_get_or_insert_default)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(map_many_mut)]
|
||||
|
|
|
@ -245,7 +245,7 @@ use crate::ptr::{self, NonNull};
|
|||
mod lazy;
|
||||
mod once;
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub use lazy::LazyCell;
|
||||
#[stable(feature = "once_cell", since = "1.70.0")]
|
||||
pub use once::OnceCell;
|
||||
|
|
|
@ -18,8 +18,6 @@ enum State<T, F> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(lazy_cell)]
|
||||
///
|
||||
/// use std::cell::LazyCell;
|
||||
///
|
||||
/// let lazy: LazyCell<i32> = LazyCell::new(|| {
|
||||
|
@ -36,7 +34,7 @@ enum State<T, F> {
|
|||
/// // 92
|
||||
/// // 92
|
||||
/// ```
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub struct LazyCell<T, F = fn() -> T> {
|
||||
state: UnsafeCell<State<T, F>>,
|
||||
}
|
||||
|
@ -47,8 +45,6 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(lazy_cell)]
|
||||
///
|
||||
/// use std::cell::LazyCell;
|
||||
///
|
||||
/// let hello = "Hello, World!".to_string();
|
||||
|
@ -58,7 +54,8 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
|
|||
/// assert_eq!(&*lazy, "HELLO, WORLD!");
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_const_stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub const fn new(f: F) -> LazyCell<T, F> {
|
||||
LazyCell { state: UnsafeCell::new(State::Uninit(f)) }
|
||||
}
|
||||
|
@ -70,7 +67,6 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(lazy_cell)]
|
||||
/// #![feature(lazy_cell_consume)]
|
||||
///
|
||||
/// use std::cell::LazyCell;
|
||||
|
@ -99,8 +95,6 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(lazy_cell)]
|
||||
///
|
||||
/// use std::cell::LazyCell;
|
||||
///
|
||||
/// let lazy = LazyCell::new(|| 92);
|
||||
|
@ -109,7 +103,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
|
|||
/// assert_eq!(&*lazy, &92);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub fn force(this: &LazyCell<T, F>) -> &T {
|
||||
// SAFETY:
|
||||
// This invalidates any mutable references to the data. The resulting
|
||||
|
@ -173,7 +167,7 @@ impl<T, F> LazyCell<T, F> {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> {
|
||||
type Target = T;
|
||||
#[inline]
|
||||
|
@ -182,7 +176,7 @@ impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T: Default> Default for LazyCell<T> {
|
||||
/// Creates a new lazy value using `Default` as the initializing function.
|
||||
#[inline]
|
||||
|
@ -191,7 +185,7 @@ impl<T: Default> Default for LazyCell<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T: fmt::Debug, F> fmt::Debug for LazyCell<T, F> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut d = f.debug_tuple("LazyCell");
|
||||
|
|
|
@ -96,7 +96,6 @@
|
|||
#![feature(pointer_is_aligned_to)]
|
||||
#![feature(portable_simd)]
|
||||
#![feature(ptr_metadata)]
|
||||
#![feature(lazy_cell)]
|
||||
#![feature(unsized_tuple_coercion)]
|
||||
#![feature(const_option)]
|
||||
#![feature(const_option_ext)]
|
||||
|
|
|
@ -395,7 +395,6 @@
|
|||
#![feature(edition_panic)]
|
||||
#![feature(format_args_nl)]
|
||||
#![feature(get_many_mut)]
|
||||
#![feature(lazy_cell)]
|
||||
#![feature(log_syntax)]
|
||||
#![feature(test)]
|
||||
#![feature(trace_macros)]
|
||||
|
|
|
@ -31,8 +31,6 @@ union Data<T, F> {
|
|||
/// Initialize static variables with `LazyLock`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(lazy_cell)]
|
||||
///
|
||||
/// use std::collections::HashMap;
|
||||
///
|
||||
/// use std::sync::LazyLock;
|
||||
|
@ -61,8 +59,6 @@ union Data<T, F> {
|
|||
/// ```
|
||||
/// Initialize fields with `LazyLock`.
|
||||
/// ```
|
||||
/// #![feature(lazy_cell)]
|
||||
///
|
||||
/// use std::sync::LazyLock;
|
||||
///
|
||||
/// #[derive(Debug)]
|
||||
|
@ -76,8 +72,7 @@ union Data<T, F> {
|
|||
/// println!("{}", *data.number);
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub struct LazyLock<T, F = fn() -> T> {
|
||||
once: Once,
|
||||
data: UnsafeCell<Data<T, F>>,
|
||||
|
@ -85,8 +80,21 @@ pub struct LazyLock<T, F = fn() -> T> {
|
|||
|
||||
impl<T, F: FnOnce() -> T> LazyLock<T, F> {
|
||||
/// Creates a new lazy value with the given initializing function.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::sync::LazyLock;
|
||||
///
|
||||
/// let hello = "Hello, World!".to_string();
|
||||
///
|
||||
/// let lazy = LazyLock::new(|| hello.to_uppercase());
|
||||
///
|
||||
/// assert_eq!(&*lazy, "HELLO, WORLD!");
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_const_stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub const fn new(f: F) -> LazyLock<T, F> {
|
||||
LazyLock { once: Once::new(), data: UnsafeCell::new(Data { f: ManuallyDrop::new(f) }) }
|
||||
}
|
||||
|
@ -107,7 +115,6 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(lazy_cell)]
|
||||
/// #![feature(lazy_cell_consume)]
|
||||
///
|
||||
/// use std::sync::LazyLock;
|
||||
|
@ -145,8 +152,6 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(lazy_cell)]
|
||||
///
|
||||
/// use std::sync::LazyLock;
|
||||
///
|
||||
/// let lazy = LazyLock::new(|| 92);
|
||||
|
@ -155,7 +160,7 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
|
|||
/// assert_eq!(&*lazy, &92);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub fn force(this: &LazyLock<T, F>) -> &T {
|
||||
this.once.call_once(|| {
|
||||
// SAFETY: `call_once` only runs this closure once, ever.
|
||||
|
@ -191,7 +196,7 @@ impl<T, F> LazyLock<T, F> {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T, F> Drop for LazyLock<T, F> {
|
||||
fn drop(&mut self) {
|
||||
match self.once.state() {
|
||||
|
@ -204,7 +209,7 @@ impl<T, F> Drop for LazyLock<T, F> {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
|
||||
type Target = T;
|
||||
|
||||
|
@ -219,7 +224,7 @@ impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T: Default> Default for LazyLock<T> {
|
||||
/// Creates a new lazy value using `Default` as the initializing function.
|
||||
#[inline]
|
||||
|
@ -228,7 +233,7 @@ impl<T: Default> Default for LazyLock<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut d = f.debug_tuple("LazyLock");
|
||||
|
@ -242,13 +247,13 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
|
|||
|
||||
// We never create a `&F` from a `&LazyLock<T, F>` so it is fine
|
||||
// to not impl `Sync` for `F`.
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
unsafe impl<T: Sync + Send, F: Send> Sync for LazyLock<T, F> {}
|
||||
// auto-derived `Send` impl is OK.
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T: RefUnwindSafe + UnwindSafe, F: UnwindSafe> RefUnwindSafe for LazyLock<T, F> {}
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T: UnwindSafe, F: UnwindSafe> UnwindSafe for LazyLock<T, F> {}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -179,7 +179,7 @@ pub use self::rwlock::{MappedRwLockReadGuard, MappedRwLockWriteGuard};
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
|
||||
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub use self::lazy_lock::LazyLock;
|
||||
#[stable(feature = "once_cell", since = "1.70.0")]
|
||||
pub use self::once_lock::OnceLock;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#![feature(if_let_guard)]
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(lazy_cell)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(never_type)]
|
||||
#![feature(round_char_boundary)]
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(lazy_cell)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(rustc_private)]
|
||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#![allow(rustc::untranslatable_diagnostic)]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(lazy_cell)]
|
||||
#![feature(lint_reasons)]
|
||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||
// warn on lints, that are included in `rust-lang/rust`s bootstrap
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(lazy_cell)]
|
||||
#![feature(is_sorted)]
|
||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
//!
|
||||
//! See [Eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) for context
|
||||
|
||||
#![feature(lazy_cell)]
|
||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(lazy_cell)]
|
||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(lazy_cell)]
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use test_utils::{CARGO_CLIPPY_PATH, IS_RUSTC_TEST_SUITE};
|
||||
|
|
|
@ -14,7 +14,7 @@ LL | static settings_dir: String = format!("");
|
|||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0507]: cannot move out of static item `settings_dir`
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X);
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/issue-16538.rs:11:22
|
||||
|
|
|
@ -13,7 +13,7 @@ LL | invalid();
|
|||
| ^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
|
||||
error[E0015]: cannot call non-const fn `invalid` in statics
|
||||
--> $DIR/issue-32829-2.rs:54:9
|
||||
|
@ -22,7 +22,7 @@ LL | invalid();
|
|||
| ^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | static foo: Foo = bar();
|
|||
| ^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ note: impl defined here, but it is not `const`
|
|||
LL | impl Deref for A {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
|
||||
LL + #![feature(const_trait_impl)]
|
||||
|
|
|
@ -18,7 +18,7 @@ LL | static boxed: Box<RefCell<isize>> = Box::new(RefCell::new(0));
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(lazy_cell)]
|
||||
#![deny(suspicious_double_ref_op, noop_method_call)]
|
||||
|
||||
use std::borrow::Borrow;
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
error: using `.clone()` on a double reference, which returns `&Vec<i32>` instead of cloning the inner type
|
||||
--> $DIR/suspicious-double-ref-op.rs:15:23
|
||||
--> $DIR/suspicious-double-ref-op.rs:14:23
|
||||
|
|
||||
LL | let z: &Vec<_> = y.clone();
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/suspicious-double-ref-op.rs:2:9
|
||||
--> $DIR/suspicious-double-ref-op.rs:1:9
|
||||
|
|
||||
LL | #![deny(suspicious_double_ref_op, noop_method_call)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: using `.clone()` on a double reference, which returns `&CloneType<u32>` instead of cloning the inner type
|
||||
--> $DIR/suspicious-double-ref-op.rs:33:63
|
||||
--> $DIR/suspicious-double-ref-op.rs:32:63
|
||||
|
|
||||
LL | let clone_type_ref_clone: &CloneType<u32> = clone_type_ref.clone();
|
||||
| ^^^^^^^^
|
||||
|
||||
error: using `.deref()` on a double reference, which returns `&PlainType<u32>` instead of dereferencing the inner type
|
||||
--> $DIR/suspicious-double-ref-op.rs:37:63
|
||||
--> $DIR/suspicious-double-ref-op.rs:36:63
|
||||
|
|
||||
LL | let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
|
||||
| ^^^^^^^^
|
||||
|
||||
error: using `.clone()` on a double reference, which returns `&str` instead of cloning the inner type
|
||||
--> $DIR/suspicious-double-ref-op.rs:41:44
|
||||
--> $DIR/suspicious-double-ref-op.rs:40:44
|
||||
|
|
||||
LL | let _v: Vec<&str> = xs.iter().map(|x| x.clone()).collect(); // could use `*x` instead
|
||||
| ^^^^^^^^
|
||||
|
|
|
@ -352,7 +352,7 @@ LL | static bar: &[i32] = &(&[1,2,3] as &[i32][0..1]);
|
|||
| ^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
|
||||
LL + #![feature(const_trait_impl)]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//@ check-pass
|
||||
|
||||
#![feature(const_trait_impl, lazy_cell)]
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | static mut a: Box<isize> = Box::new(3);
|
|||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | static a: [isize; 2] = [foo(); 2];
|
|||
| ^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ LL | static STATIC11: Vec<MyOwned> = vec![MyOwned];
|
|||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0015]: cannot call non-const fn `<str as ToString>::to_string` in statics
|
||||
|
@ -36,7 +36,7 @@ LL | field2: SafeEnum::Variant4("str".to_string()),
|
|||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
|
||||
LL + #![feature(const_trait_impl)]
|
||||
|
@ -57,7 +57,7 @@ LL | vec![MyOwned],
|
|||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0010]: allocations are not allowed in statics
|
||||
|
@ -75,7 +75,7 @@ LL | vec![MyOwned],
|
|||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0010]: allocations are not allowed in statics
|
||||
|
@ -93,7 +93,7 @@ LL | &vec![MyOwned],
|
|||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0010]: allocations are not allowed in statics
|
||||
|
@ -111,7 +111,7 @@ LL | &vec![MyOwned],
|
|||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0010]: allocations are not allowed in statics
|
||||
|
@ -129,7 +129,7 @@ LL | static STATIC19: Vec<isize> = vec![3];
|
|||
| ^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0010]: allocations are not allowed in statics
|
||||
|
@ -147,7 +147,7 @@ LL | static x: Vec<isize> = vec![3];
|
|||
| ^^^^^^^
|
||||
|
|
||||
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
|
||||
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
|
||||
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0507]: cannot move out of static item `x`
|
||||
|
|
Loading…
Reference in New Issue