authorbors <bors@rust-lang.org> 2025-12-24 09:31:51 UTC
committerbors <bors@rust-lang.org> 2025-12-24 09:31:51 UTC
logc4aa646f15e40bd3e64ddb5017b7b89b3646ac99
tree06667b695a4299158d5f84c9bc0f19e44810f5a6
parentefa32de15b394620520f24781d8c55d4df6fa106
parentf9e3c618b806c41a4d7bd61200e7787336b244d6

Auto merge of #150334 - jhpratt:rollup-met2i6d, r=jhpratt

Rollup of 3 pull requests Successful merges: - rust-lang/rust#150016 (stabilize `lazy_get`) - rust-lang/rust#150139 (Correct terminology in Clone) - rust-lang/rust#150238 (mir_build: Classify `TestableCase::Constant` into multiple sub-kinds) r? `@ghost` `@rustbot` modify labels: rollup

16 files changed, 141 insertions(+), 102 deletions(-)

compiler/rustc_mir_build/src/builder/matches/buckets.rs+20-10
......@@ -6,8 +6,7 @@ use rustc_middle::span_bug;
66use tracing::debug;
77
88use crate::builder::Builder;
9use crate::builder::matches::test::is_switch_ty;
10use crate::builder::matches::{Candidate, Test, TestBranch, TestKind, TestableCase};
9use crate::builder::matches::{Candidate, PatConstKind, Test, TestBranch, TestKind, TestableCase};
1110
1211/// Output of [`Builder::partition_candidates_into_buckets`].
1312pub(crate) struct PartitionedCandidates<'tcx, 'b, 'c> {
......@@ -157,11 +156,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
157156 //
158157 // FIXME(#29623) we could use PatKind::Range to rule
159158 // things out here, in some cases.
160 //
161 // FIXME(Zalathar): Is the `is_switch_ty` test unnecessary?
162 (TestKind::SwitchInt, &TestableCase::Constant { value })
163 if is_switch_ty(match_pair.pattern_ty) =>
164 {
159 (
160 TestKind::SwitchInt,
161 &TestableCase::Constant { value, kind: PatConstKind::IntOrChar },
162 ) => {
165163 // An important invariant of candidate bucketing is that a candidate
166164 // must not match in multiple branches. For `SwitchInt` tests, adding
167165 // a new value might invalidate that property for range patterns that
......@@ -206,7 +204,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
206204 })
207205 }
208206
209 (TestKind::If, TestableCase::Constant { value }) => {
207 (TestKind::If, TestableCase::Constant { value, kind: PatConstKind::Bool }) => {
210208 fully_matched = true;
211209 let value = value.try_to_bool().unwrap_or_else(|| {
212210 span_bug!(test.span, "expected boolean value but got {value:?}")
......@@ -291,7 +289,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
291289 if !test.overlaps(pat, self.tcx)? { Some(TestBranch::Failure) } else { None }
292290 }
293291 }
294 (TestKind::Range(range), &TestableCase::Constant { value }) => {
292 (
293 TestKind::Range(range),
294 &TestableCase::Constant {
295 value,
296 kind: PatConstKind::Bool | PatConstKind::IntOrChar | PatConstKind::Float,
297 },
298 ) => {
295299 fully_matched = false;
296300 if !range.contains(value, self.tcx)? {
297301 // `value` is not contained in the testing range,
......@@ -302,7 +306,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
302306 }
303307 }
304308
305 (TestKind::Eq { value: test_val, .. }, TestableCase::Constant { value: case_val }) => {
309 (
310 TestKind::Eq { value: test_val, .. },
311 TestableCase::Constant {
312 value: case_val,
313 kind: PatConstKind::Float | PatConstKind::Other,
314 },
315 ) => {
306316 if test_val == case_val {
307317 fully_matched = true;
308318 Some(TestBranch::Success)
compiler/rustc_mir_build/src/builder/matches/match_pair.rs+26-2
......@@ -7,7 +7,9 @@ use rustc_middle::ty::{self, Ty, TypeVisitableExt};
77
88use crate::builder::Builder;
99use crate::builder::expr::as_place::{PlaceBase, PlaceBuilder};
10use crate::builder::matches::{FlatPat, MatchPairTree, PatternExtraData, TestableCase};
10use crate::builder::matches::{
11 FlatPat, MatchPairTree, PatConstKind, PatternExtraData, TestableCase,
12};
1113
1214impl<'a, 'tcx> Builder<'a, 'tcx> {
1315 /// Builds and pushes [`MatchPairTree`] subtrees, one for each pattern in
......@@ -156,7 +158,29 @@ impl<'tcx> MatchPairTree<'tcx> {
156158 }
157159 }
158160
159 PatKind::Constant { value } => Some(TestableCase::Constant { value }),
161 PatKind::Constant { value } => {
162 // CAUTION: The type of the pattern node (`pattern.ty`) is
163 // _often_ the same as the type of the const value (`value.ty`),
164 // but there are some cases where those types differ
165 // (e.g. when `deref!(..)` patterns interact with `String`).
166
167 // Classify the constant-pattern into further kinds, to
168 // reduce the number of ad-hoc type tests needed later on.
169 let pat_ty = pattern.ty;
170 let const_kind = if pat_ty.is_bool() {
171 PatConstKind::Bool
172 } else if pat_ty.is_integral() || pat_ty.is_char() {
173 PatConstKind::IntOrChar
174 } else if pat_ty.is_floating_point() {
175 PatConstKind::Float
176 } else {
177 // FIXME(Zalathar): This still covers several different
178 // categories (e.g. raw pointer, string, pattern-type)
179 // which could be split out into their own kinds.
180 PatConstKind::Other
181 };
182 Some(TestableCase::Constant { value, kind: const_kind })
183 }
160184
161185 PatKind::AscribeUserType {
162186 ascription: Ascription { ref annotation, variance },
compiler/rustc_mir_build/src/builder/matches/mod.rs+23-1
......@@ -1262,7 +1262,7 @@ struct Ascription<'tcx> {
12621262#[derive(Debug, Clone)]
12631263enum TestableCase<'tcx> {
12641264 Variant { adt_def: ty::AdtDef<'tcx>, variant_index: VariantIdx },
1265 Constant { value: ty::Value<'tcx> },
1265 Constant { value: ty::Value<'tcx>, kind: PatConstKind },
12661266 Range(Arc<PatRange<'tcx>>),
12671267 Slice { len: u64, variable_length: bool },
12681268 Deref { temp: Place<'tcx>, mutability: Mutability },
......@@ -1276,6 +1276,28 @@ impl<'tcx> TestableCase<'tcx> {
12761276 }
12771277}
12781278
1279/// Sub-classification of [`TestableCase::Constant`], which helps to avoid
1280/// some redundant ad-hoc checks when preparing and lowering tests.
1281#[derive(Debug, Clone)]
1282enum PatConstKind {
1283 /// The primitive `bool` type, which is like an integer but simpler,
1284 /// having only two values.
1285 Bool,
1286 /// Primitive unsigned/signed integer types, plus `char`.
1287 /// These types interact nicely with `SwitchInt`.
1288 IntOrChar,
1289 /// Floating-point primitives, e.g. `f32`, `f64`.
1290 /// These types don't support `SwitchInt` and require an equality test,
1291 /// but can also interact with range pattern tests.
1292 Float,
1293 /// Any other constant-pattern is usually tested via some kind of equality
1294 /// check. Types that might be encountered here include:
1295 /// - `&str`
1296 /// - raw pointers derived from integer values
1297 /// - pattern types, e.g. `pattern_type!(u32 is 1..)`
1298 Other,
1299}
1300
12791301/// Node in a tree of "match pairs", where each pair consists of a place to be
12801302/// tested, and a test to perform on that place.
12811303///
compiler/rustc_mir_build/src/builder/matches/test.rs+9-9
......@@ -19,7 +19,9 @@ use rustc_span::{DUMMY_SP, Span, Symbol, sym};
1919use tracing::{debug, instrument};
2020
2121use crate::builder::Builder;
22use crate::builder::matches::{MatchPairTree, Test, TestBranch, TestKind, TestableCase};
22use crate::builder::matches::{
23 MatchPairTree, PatConstKind, Test, TestBranch, TestKind, TestableCase,
24};
2325
2426impl<'a, 'tcx> Builder<'a, 'tcx> {
2527 /// Identifies what test is needed to decide if `match_pair` is applicable.
......@@ -32,11 +34,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3234 let kind = match match_pair.testable_case {
3335 TestableCase::Variant { adt_def, variant_index: _ } => TestKind::Switch { adt_def },
3436
35 TestableCase::Constant { .. } if match_pair.pattern_ty.is_bool() => TestKind::If,
36 TestableCase::Constant { .. } if is_switch_ty(match_pair.pattern_ty) => {
37 TestableCase::Constant { value: _, kind: PatConstKind::Bool } => TestKind::If,
38 TestableCase::Constant { value: _, kind: PatConstKind::IntOrChar } => {
3739 TestKind::SwitchInt
3840 }
39 TestableCase::Constant { value } => {
41 TestableCase::Constant { value, kind: PatConstKind::Float } => {
42 TestKind::Eq { value, cast_ty: match_pair.pattern_ty }
43 }
44 TestableCase::Constant { value, kind: PatConstKind::Other } => {
4045 TestKind::Eq { value, cast_ty: match_pair.pattern_ty }
4146 }
4247
......@@ -491,11 +496,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
491496 }
492497}
493498
494/// Returns true if this type be used with [`TestKind::SwitchInt`].
495pub(crate) fn is_switch_ty(ty: Ty<'_>) -> bool {
496 ty.is_integral() || ty.is_char()
497}
498
499499fn trait_method<'tcx>(
500500 tcx: TyCtxt<'tcx>,
501501 trait_def_id: DefId,
library/core/src/cell/lazy.rs+3-8
......@@ -165,7 +165,6 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
165165 /// # Examples
166166 ///
167167 /// ```
168 /// #![feature(lazy_get)]
169168 /// use std::cell::LazyCell;
170169 ///
171170 /// let mut lazy = LazyCell::new(|| 92);
......@@ -176,7 +175,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
176175 /// assert_eq!(*lazy, 44);
177176 /// ```
178177 #[inline]
179 #[unstable(feature = "lazy_get", issue = "129333")]
178 #[stable(feature = "lazy_get", since = "CURRENT_RUSTC_VERSION")]
180179 pub fn force_mut(this: &mut LazyCell<T, F>) -> &mut T {
181180 #[cold]
182181 /// # Safety
......@@ -264,8 +263,6 @@ impl<T, F> LazyCell<T, F> {
264263 /// # Examples
265264 ///
266265 /// ```
267 /// #![feature(lazy_get)]
268 ///
269266 /// use std::cell::LazyCell;
270267 ///
271268 /// let mut lazy = LazyCell::new(|| 92);
......@@ -276,7 +273,7 @@ impl<T, F> LazyCell<T, F> {
276273 /// assert_eq!(*lazy, 44);
277274 /// ```
278275 #[inline]
279 #[unstable(feature = "lazy_get", issue = "129333")]
276 #[stable(feature = "lazy_get", since = "CURRENT_RUSTC_VERSION")]
280277 pub fn get_mut(this: &mut LazyCell<T, F>) -> Option<&mut T> {
281278 let state = this.state.get_mut();
282279 match state {
......@@ -291,8 +288,6 @@ impl<T, F> LazyCell<T, F> {
291288 /// # Examples
292289 ///
293290 /// ```
294 /// #![feature(lazy_get)]
295 ///
296291 /// use std::cell::LazyCell;
297292 ///
298293 /// let lazy = LazyCell::new(|| 92);
......@@ -302,7 +297,7 @@ impl<T, F> LazyCell<T, F> {
302297 /// assert_eq!(LazyCell::get(&lazy), Some(&92));
303298 /// ```
304299 #[inline]
305 #[unstable(feature = "lazy_get", issue = "129333")]
300 #[stable(feature = "lazy_get", since = "CURRENT_RUSTC_VERSION")]
306301 pub fn get(this: &LazyCell<T, F>) -> Option<&T> {
307302 // SAFETY:
308303 // This is sound for the same reason as in `force`: once the state is
library/core/src/clone.rs+5-5
......@@ -52,12 +52,12 @@ mod uninit;
5252/// original.
5353///
5454/// Differs from [`Copy`] in that [`Copy`] is implicit and an inexpensive bit-wise copy, while
55/// `Clone` is always explicit and may or may not be expensive. In order to enforce
56/// these characteristics, Rust does not allow you to reimplement [`Copy`], but you
57/// may reimplement `Clone` and run arbitrary code.
55/// `Clone` is always explicit and may or may not be expensive. [`Copy`] has no methods, so you
56/// cannot change its behavior, but when implementing `Clone`, the `clone` method you provide
57/// may run arbitrary code.
5858///
59/// Since `Clone` is more general than [`Copy`], you can automatically make anything
60/// [`Copy`] be `Clone` as well.
59/// Since `Clone` is a supertrait of [`Copy`], any type that implements `Copy` must also implement
60/// `Clone`.
6161///
6262/// ## Derivable
6363///
library/core/src/lib.rs-1
......@@ -113,7 +113,6 @@
113113#![feature(internal_impls_macro)]
114114#![feature(ip)]
115115#![feature(is_ascii_octdigit)]
116#![feature(lazy_get)]
117116#![feature(link_cfg)]
118117#![feature(offset_of_enum)]
119118#![feature(panic_internals)]
library/coretests/tests/lib.rs-1
......@@ -79,7 +79,6 @@
7979#![feature(iterator_try_collect)]
8080#![feature(iterator_try_reduce)]
8181#![feature(layout_for_ptr)]
82#![feature(lazy_get)]
8382#![feature(maybe_uninit_fill)]
8483#![feature(maybe_uninit_uninit_array_transpose)]
8584#![feature(min_specialization)]
library/std/src/lib.rs-1
......@@ -344,7 +344,6 @@
344344#![feature(hint_must_use)]
345345#![feature(int_from_ascii)]
346346#![feature(ip)]
347#![feature(lazy_get)]
348347#![feature(maybe_uninit_array_assume_init)]
349348#![feature(panic_can_unwind)]
350349#![feature(panic_internals)]
library/std/src/sync/lazy_lock.rs+3-8
......@@ -172,7 +172,6 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
172172 /// # Examples
173173 ///
174174 /// ```
175 /// #![feature(lazy_get)]
176175 /// use std::sync::LazyLock;
177176 ///
178177 /// let mut lazy = LazyLock::new(|| 92);
......@@ -183,7 +182,7 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
183182 /// assert_eq!(*lazy, 44);
184183 /// ```
185184 #[inline]
186 #[unstable(feature = "lazy_get", issue = "129333")]
185 #[stable(feature = "lazy_get", since = "CURRENT_RUSTC_VERSION")]
187186 pub fn force_mut(this: &mut LazyLock<T, F>) -> &mut T {
188187 #[cold]
189188 /// # Safety
......@@ -279,8 +278,6 @@ impl<T, F> LazyLock<T, F> {
279278 /// # Examples
280279 ///
281280 /// ```
282 /// #![feature(lazy_get)]
283 ///
284281 /// use std::sync::LazyLock;
285282 ///
286283 /// let mut lazy = LazyLock::new(|| 92);
......@@ -291,7 +288,7 @@ impl<T, F> LazyLock<T, F> {
291288 /// assert_eq!(*lazy, 44);
292289 /// ```
293290 #[inline]
294 #[unstable(feature = "lazy_get", issue = "129333")]
291 #[stable(feature = "lazy_get", since = "CURRENT_RUSTC_VERSION")]
295292 pub fn get_mut(this: &mut LazyLock<T, F>) -> Option<&mut T> {
296293 // `state()` does not perform an atomic load, so prefer it over `is_complete()`.
297294 let state = this.once.state();
......@@ -309,8 +306,6 @@ impl<T, F> LazyLock<T, F> {
309306 /// # Examples
310307 ///
311308 /// ```
312 /// #![feature(lazy_get)]
313 ///
314309 /// use std::sync::LazyLock;
315310 ///
316311 /// let lazy = LazyLock::new(|| 92);
......@@ -320,7 +315,7 @@ impl<T, F> LazyLock<T, F> {
320315 /// assert_eq!(LazyLock::get(&lazy), Some(&92));
321316 /// ```
322317 #[inline]
323 #[unstable(feature = "lazy_get", issue = "129333")]
318 #[stable(feature = "lazy_get", since = "CURRENT_RUSTC_VERSION")]
324319 #[rustc_should_not_be_called_on_const_items]
325320 pub fn get(this: &LazyLock<T, F>) -> Option<&T> {
326321 if this.once.is_completed() {
library/std/tests/sync/lib.rs-1
......@@ -1,4 +1,3 @@
1#![feature(lazy_get)]
21#![feature(mapped_lock_guards)]
32#![feature(mpmc_channel)]
43#![feature(once_cell_try)]
tests/ui/lint/const-item-interior-mutations-const-cell.rs-1
......@@ -4,7 +4,6 @@
44#![feature(sync_unsafe_cell)]
55#![feature(once_cell_try_insert)]
66#![feature(once_cell_try)]
7#![feature(lazy_get)]
87
98use std::cell::{Cell, RefCell, SyncUnsafeCell, UnsafeCell};
109use std::cell::{LazyCell, OnceCell};
tests/ui/lint/const-item-interior-mutations-const-cell.stderr+22-22
......@@ -1,5 +1,5 @@
11warning: mutation of an interior mutable `const` item with call to `force`
2 --> $DIR/const-item-interior-mutations-const-cell.rs:16:13
2 --> $DIR/const-item-interior-mutations-const-cell.rs:15:13
33 |
44LL | let _ = LazyCell::force(&A);
55 | ^^^^^^^^^^^^^^^^^-^
......@@ -17,7 +17,7 @@ LL + static A: LazyCell<i32> = LazyCell::new(|| 0);
1717 |
1818
1919warning: mutation of an interior mutable `const` item with call to `set`
20 --> $DIR/const-item-interior-mutations-const-cell.rs:23:13
20 --> $DIR/const-item-interior-mutations-const-cell.rs:22:13
2121 |
2222LL | let _ = A.set(10);
2323 | -^^^^^^^^
......@@ -34,7 +34,7 @@ LL + static A: OnceCell<i32> = OnceCell::new();
3434 |
3535
3636warning: mutation of an interior mutable `const` item with call to `try_insert`
37 --> $DIR/const-item-interior-mutations-const-cell.rs:26:13
37 --> $DIR/const-item-interior-mutations-const-cell.rs:25:13
3838 |
3939LL | let _ = A.try_insert(20);
4040 | -^^^^^^^^^^^^^^^
......@@ -51,7 +51,7 @@ LL + static A: OnceCell<i32> = OnceCell::new();
5151 |
5252
5353warning: mutation of an interior mutable `const` item with call to `get_or_init`
54 --> $DIR/const-item-interior-mutations-const-cell.rs:29:13
54 --> $DIR/const-item-interior-mutations-const-cell.rs:28:13
5555 |
5656LL | let _ = A.get_or_init(|| 30);
5757 | -^^^^^^^^^^^^^^^^^^^
......@@ -68,7 +68,7 @@ LL + static A: OnceCell<i32> = OnceCell::new();
6868 |
6969
7070warning: mutation of an interior mutable `const` item with call to `get_or_try_init`
71 --> $DIR/const-item-interior-mutations-const-cell.rs:32:13
71 --> $DIR/const-item-interior-mutations-const-cell.rs:31:13
7272 |
7373LL | let _ = A.get_or_try_init(|| Ok::<_, ()>(40));
7474 | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -85,7 +85,7 @@ LL + static A: OnceCell<i32> = OnceCell::new();
8585 |
8686
8787warning: mutation of an interior mutable `const` item with call to `set`
88 --> $DIR/const-item-interior-mutations-const-cell.rs:39:13
88 --> $DIR/const-item-interior-mutations-const-cell.rs:38:13
8989 |
9090LL | let _ = A.set(1);
9191 | -^^^^^^^
......@@ -102,7 +102,7 @@ LL + static A: Cell<i32> = Cell::new(0);
102102 |
103103
104104warning: mutation of an interior mutable `const` item with call to `swap`
105 --> $DIR/const-item-interior-mutations-const-cell.rs:42:13
105 --> $DIR/const-item-interior-mutations-const-cell.rs:41:13
106106 |
107107LL | let _ = A.swap(&A);
108108 | -^^^^^^^^^
......@@ -119,7 +119,7 @@ LL + static A: Cell<i32> = Cell::new(0);
119119 |
120120
121121warning: mutation of an interior mutable `const` item with call to `replace`
122 --> $DIR/const-item-interior-mutations-const-cell.rs:45:13
122 --> $DIR/const-item-interior-mutations-const-cell.rs:44:13
123123 |
124124LL | let _ = A.replace(2);
125125 | -^^^^^^^^^^^
......@@ -136,7 +136,7 @@ LL + static A: Cell<i32> = Cell::new(0);
136136 |
137137
138138warning: mutation of an interior mutable `const` item with call to `get`
139 --> $DIR/const-item-interior-mutations-const-cell.rs:48:13
139 --> $DIR/const-item-interior-mutations-const-cell.rs:47:13
140140 |
141141LL | let _ = A.get();
142142 | -^^^^^^
......@@ -153,7 +153,7 @@ LL + static A: Cell<i32> = Cell::new(0);
153153 |
154154
155155warning: mutation of an interior mutable `const` item with call to `update`
156 --> $DIR/const-item-interior-mutations-const-cell.rs:51:13
156 --> $DIR/const-item-interior-mutations-const-cell.rs:50:13
157157 |
158158LL | let _ = A.update(|x| x + 1);
159159 | -^^^^^^^^^^^^^^^^^^
......@@ -170,7 +170,7 @@ LL + static A: Cell<i32> = Cell::new(0);
170170 |
171171
172172warning: mutation of an interior mutable `const` item with call to `replace`
173 --> $DIR/const-item-interior-mutations-const-cell.rs:58:13
173 --> $DIR/const-item-interior-mutations-const-cell.rs:57:13
174174 |
175175LL | let _ = A.replace(1);
176176 | -^^^^^^^^^^^
......@@ -187,7 +187,7 @@ LL + static A: RefCell<i32> = RefCell::new(0);
187187 |
188188
189189warning: mutation of an interior mutable `const` item with call to `replace_with`
190 --> $DIR/const-item-interior-mutations-const-cell.rs:61:13
190 --> $DIR/const-item-interior-mutations-const-cell.rs:60:13
191191 |
192192LL | let _ = A.replace_with(|x| *x + 2);
193193 | -^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -204,7 +204,7 @@ LL + static A: RefCell<i32> = RefCell::new(0);
204204 |
205205
206206warning: mutation of an interior mutable `const` item with call to `swap`
207 --> $DIR/const-item-interior-mutations-const-cell.rs:64:13
207 --> $DIR/const-item-interior-mutations-const-cell.rs:63:13
208208 |
209209LL | let _ = A.swap(&A);
210210 | -^^^^^^^^^
......@@ -221,7 +221,7 @@ LL + static A: RefCell<i32> = RefCell::new(0);
221221 |
222222
223223warning: mutation of an interior mutable `const` item with call to `borrow`
224 --> $DIR/const-item-interior-mutations-const-cell.rs:67:13
224 --> $DIR/const-item-interior-mutations-const-cell.rs:66:13
225225 |
226226LL | let _ = A.borrow();
227227 | -^^^^^^^^^
......@@ -238,7 +238,7 @@ LL + static A: RefCell<i32> = RefCell::new(0);
238238 |
239239
240240warning: mutation of an interior mutable `const` item with call to `try_borrow`
241 --> $DIR/const-item-interior-mutations-const-cell.rs:70:13
241 --> $DIR/const-item-interior-mutations-const-cell.rs:69:13
242242 |
243243LL | let _ = A.try_borrow();
244244 | -^^^^^^^^^^^^^
......@@ -255,7 +255,7 @@ LL + static A: RefCell<i32> = RefCell::new(0);
255255 |
256256
257257warning: mutation of an interior mutable `const` item with call to `borrow_mut`
258 --> $DIR/const-item-interior-mutations-const-cell.rs:73:13
258 --> $DIR/const-item-interior-mutations-const-cell.rs:72:13
259259 |
260260LL | let _ = A.borrow_mut();
261261 | -^^^^^^^^^^^^^
......@@ -272,7 +272,7 @@ LL + static A: RefCell<i32> = RefCell::new(0);
272272 |
273273
274274warning: mutation of an interior mutable `const` item with call to `try_borrow_mut`
275 --> $DIR/const-item-interior-mutations-const-cell.rs:76:13
275 --> $DIR/const-item-interior-mutations-const-cell.rs:75:13
276276 |
277277LL | let _ = A.try_borrow_mut();
278278 | -^^^^^^^^^^^^^^^^^
......@@ -289,7 +289,7 @@ LL + static A: RefCell<i32> = RefCell::new(0);
289289 |
290290
291291warning: mutation of an interior mutable `const` item with call to `replace`
292 --> $DIR/const-item-interior-mutations-const-cell.rs:83:22
292 --> $DIR/const-item-interior-mutations-const-cell.rs:82:22
293293 |
294294LL | let _ = unsafe { A.replace(1) };
295295 | -^^^^^^^^^^^
......@@ -306,7 +306,7 @@ LL + static A: UnsafeCell<i32> = UnsafeCell::new(0);
306306 |
307307
308308warning: mutation of an interior mutable `const` item with call to `get`
309 --> $DIR/const-item-interior-mutations-const-cell.rs:86:13
309 --> $DIR/const-item-interior-mutations-const-cell.rs:85:13
310310 |
311311LL | let _ = A.get();
312312 | -^^^^^^
......@@ -323,7 +323,7 @@ LL + static A: UnsafeCell<i32> = UnsafeCell::new(0);
323323 |
324324
325325warning: mutation of an interior mutable `const` item with call to `as_ref_unchecked`
326 --> $DIR/const-item-interior-mutations-const-cell.rs:90:17
326 --> $DIR/const-item-interior-mutations-const-cell.rs:89:17
327327 |
328328LL | let _ = A.as_ref_unchecked();
329329 | -^^^^^^^^^^^^^^^^^^^
......@@ -340,7 +340,7 @@ LL + static A: UnsafeCell<i32> = UnsafeCell::new(0);
340340 |
341341
342342warning: mutation of an interior mutable `const` item with call to `as_mut_unchecked`
343 --> $DIR/const-item-interior-mutations-const-cell.rs:93:17
343 --> $DIR/const-item-interior-mutations-const-cell.rs:92:17
344344 |
345345LL | let _ = A.as_mut_unchecked();
346346 | -^^^^^^^^^^^^^^^^^^^
......@@ -357,7 +357,7 @@ LL + static A: UnsafeCell<i32> = UnsafeCell::new(0);
357357 |
358358
359359warning: mutation of an interior mutable `const` item with call to `get`
360 --> $DIR/const-item-interior-mutations-const-cell.rs:101:13
360 --> $DIR/const-item-interior-mutations-const-cell.rs:100:13
361361 |
362362LL | let _ = A.get();
363363 | -^^^^^^
tests/ui/lint/const-item-interior-mutations-const.fixed-1
......@@ -6,7 +6,6 @@
66#![feature(lock_value_accessors)]
77#![feature(once_cell_try_insert)]
88#![feature(once_cell_try)]
9#![feature(lazy_get)]
109
1110use std::sync::{Condvar, LazyLock, Mutex, Once, OnceLock, RwLock};
1211use std::time::Duration;
tests/ui/lint/const-item-interior-mutations-const.rs-1
......@@ -6,7 +6,6 @@
66#![feature(lock_value_accessors)]
77#![feature(once_cell_try_insert)]
88#![feature(once_cell_try)]
9#![feature(lazy_get)]
109
1110use std::sync::{Condvar, LazyLock, Mutex, Once, OnceLock, RwLock};
1211use std::time::Duration;
tests/ui/lint/const-item-interior-mutations-const.stderr+30-30
......@@ -1,5 +1,5 @@
11warning: mutation of an interior mutable `const` item with call to `set`
2 --> $DIR/const-item-interior-mutations-const.rs:17:14
2 --> $DIR/const-item-interior-mutations-const.rs:16:14
33 |
44LL | let _a = A.set(1);
55 | -^^^^^^^
......@@ -17,7 +17,7 @@ LL + static A: Mutex<i32> = Mutex::new(0);
1717 |
1818
1919warning: mutation of an interior mutable `const` item with call to `replace`
20 --> $DIR/const-item-interior-mutations-const.rs:20:14
20 --> $DIR/const-item-interior-mutations-const.rs:19:14
2121 |
2222LL | let _a = A.replace(2);
2323 | -^^^^^^^^^^^
......@@ -34,7 +34,7 @@ LL + static A: Mutex<i32> = Mutex::new(0);
3434 |
3535
3636warning: mutation of an interior mutable `const` item with call to `lock`
37 --> $DIR/const-item-interior-mutations-const.rs:23:10
37 --> $DIR/const-item-interior-mutations-const.rs:22:10
3838 |
3939LL | drop(A.lock());
4040 | -^^^^^^^
......@@ -51,7 +51,7 @@ LL + static A: Mutex<i32> = Mutex::new(0);
5151 |
5252
5353warning: mutation of an interior mutable `const` item with call to `try_lock`
54 --> $DIR/const-item-interior-mutations-const.rs:26:10
54 --> $DIR/const-item-interior-mutations-const.rs:25:10
5555 |
5656LL | drop(A.try_lock());
5757 | -^^^^^^^^^^^
......@@ -68,7 +68,7 @@ LL + static A: Mutex<i32> = Mutex::new(0);
6868 |
6969
7070warning: mutation of an interior mutable `const` item with call to `clear_poison`
71 --> $DIR/const-item-interior-mutations-const.rs:29:14
71 --> $DIR/const-item-interior-mutations-const.rs:28:14
7272 |
7373LL | let _a = A.clear_poison();
7474 | -^^^^^^^^^^^^^^^
......@@ -85,7 +85,7 @@ LL + static A: Mutex<i32> = Mutex::new(0);
8585 |
8686
8787warning: mutation of an interior mutable `const` item with call to `call_once`
88 --> $DIR/const-item-interior-mutations-const.rs:36:14
88 --> $DIR/const-item-interior-mutations-const.rs:35:14
8989 |
9090LL | let _a = A.call_once(|| {});
9191 | -^^^^^^^^^^^^^^^^^
......@@ -102,7 +102,7 @@ LL + static A: Once = Once::new();
102102 |
103103
104104warning: mutation of an interior mutable `const` item with call to `call_once_force`
105 --> $DIR/const-item-interior-mutations-const.rs:39:14
105 --> $DIR/const-item-interior-mutations-const.rs:38:14
106106 |
107107LL | let _a = A.call_once_force(|_| {});
108108 | -^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -119,7 +119,7 @@ LL + static A: Once = Once::new();
119119 |
120120
121121warning: mutation of an interior mutable `const` item with call to `wait`
122 --> $DIR/const-item-interior-mutations-const.rs:42:14
122 --> $DIR/const-item-interior-mutations-const.rs:41:14
123123 |
124124LL | let _a = A.wait();
125125 | -^^^^^^^
......@@ -136,7 +136,7 @@ LL + static A: Once = Once::new();
136136 |
137137
138138warning: mutation of an interior mutable `const` item with call to `wait_force`
139 --> $DIR/const-item-interior-mutations-const.rs:45:14
139 --> $DIR/const-item-interior-mutations-const.rs:44:14
140140 |
141141LL | let _a = A.wait_force();
142142 | -^^^^^^^^^^^^^
......@@ -153,7 +153,7 @@ LL + static A: Once = Once::new();
153153 |
154154
155155warning: mutation of an interior mutable `const` item with call to `set`
156 --> $DIR/const-item-interior-mutations-const.rs:52:14
156 --> $DIR/const-item-interior-mutations-const.rs:51:14
157157 |
158158LL | let _a = A.set(1);
159159 | -^^^^^^^
......@@ -170,7 +170,7 @@ LL + static A: RwLock<i32> = RwLock::new(0);
170170 |
171171
172172warning: mutation of an interior mutable `const` item with call to `replace`
173 --> $DIR/const-item-interior-mutations-const.rs:55:14
173 --> $DIR/const-item-interior-mutations-const.rs:54:14
174174 |
175175LL | let _a = A.replace(2);
176176 | -^^^^^^^^^^^
......@@ -187,7 +187,7 @@ LL + static A: RwLock<i32> = RwLock::new(0);
187187 |
188188
189189warning: mutation of an interior mutable `const` item with call to `read`
190 --> $DIR/const-item-interior-mutations-const.rs:58:10
190 --> $DIR/const-item-interior-mutations-const.rs:57:10
191191 |
192192LL | drop(A.read());
193193 | -^^^^^^^
......@@ -204,7 +204,7 @@ LL + static A: RwLock<i32> = RwLock::new(0);
204204 |
205205
206206warning: mutation of an interior mutable `const` item with call to `try_read`
207 --> $DIR/const-item-interior-mutations-const.rs:61:10
207 --> $DIR/const-item-interior-mutations-const.rs:60:10
208208 |
209209LL | drop(A.try_read());
210210 | -^^^^^^^^^^^
......@@ -221,7 +221,7 @@ LL + static A: RwLock<i32> = RwLock::new(0);
221221 |
222222
223223warning: mutation of an interior mutable `const` item with call to `write`
224 --> $DIR/const-item-interior-mutations-const.rs:64:10
224 --> $DIR/const-item-interior-mutations-const.rs:63:10
225225 |
226226LL | drop(A.write());
227227 | -^^^^^^^^
......@@ -238,7 +238,7 @@ LL + static A: RwLock<i32> = RwLock::new(0);
238238 |
239239
240240warning: mutation of an interior mutable `const` item with call to `try_write`
241 --> $DIR/const-item-interior-mutations-const.rs:67:10
241 --> $DIR/const-item-interior-mutations-const.rs:66:10
242242 |
243243LL | drop(A.try_write());
244244 | -^^^^^^^^^^^^
......@@ -255,7 +255,7 @@ LL + static A: RwLock<i32> = RwLock::new(0);
255255 |
256256
257257warning: mutation of an interior mutable `const` item with call to `force`
258 --> $DIR/const-item-interior-mutations-const.rs:74:14
258 --> $DIR/const-item-interior-mutations-const.rs:73:14
259259 |
260260LL | let _a = LazyLock::force(&A);
261261 | ^^^^^^^^^^^^^^^^^-^
......@@ -272,7 +272,7 @@ LL + static A: LazyLock<i32> = LazyLock::new(|| 0);
272272 |
273273
274274warning: mutation of an interior mutable `const` item with call to `get`
275 --> $DIR/const-item-interior-mutations-const.rs:77:14
275 --> $DIR/const-item-interior-mutations-const.rs:76:14
276276 |
277277LL | let _a = LazyLock::get(&A);
278278 | ^^^^^^^^^^^^^^^-^
......@@ -289,7 +289,7 @@ LL + static A: LazyLock<i32> = LazyLock::new(|| 0);
289289 |
290290
291291warning: mutation of an interior mutable `const` item with call to `get`
292 --> $DIR/const-item-interior-mutations-const.rs:84:14
292 --> $DIR/const-item-interior-mutations-const.rs:83:14
293293 |
294294LL | let _a = A.get();
295295 | -^^^^^^
......@@ -306,7 +306,7 @@ LL + static A: OnceLock<i32> = OnceLock::new();
306306 |
307307
308308warning: mutation of an interior mutable `const` item with call to `wait`
309 --> $DIR/const-item-interior-mutations-const.rs:87:14
309 --> $DIR/const-item-interior-mutations-const.rs:86:14
310310 |
311311LL | let _a = A.wait();
312312 | -^^^^^^^
......@@ -323,7 +323,7 @@ LL + static A: OnceLock<i32> = OnceLock::new();
323323 |
324324
325325warning: mutation of an interior mutable `const` item with call to `set`
326 --> $DIR/const-item-interior-mutations-const.rs:90:14
326 --> $DIR/const-item-interior-mutations-const.rs:89:14
327327 |
328328LL | let _a = A.set(10);
329329 | -^^^^^^^^
......@@ -340,7 +340,7 @@ LL + static A: OnceLock<i32> = OnceLock::new();
340340 |
341341
342342warning: mutation of an interior mutable `const` item with call to `try_insert`
343 --> $DIR/const-item-interior-mutations-const.rs:93:14
343 --> $DIR/const-item-interior-mutations-const.rs:92:14
344344 |
345345LL | let _a = A.try_insert(20);
346346 | -^^^^^^^^^^^^^^^
......@@ -357,7 +357,7 @@ LL + static A: OnceLock<i32> = OnceLock::new();
357357 |
358358
359359warning: mutation of an interior mutable `const` item with call to `get_or_init`
360 --> $DIR/const-item-interior-mutations-const.rs:96:14
360 --> $DIR/const-item-interior-mutations-const.rs:95:14
361361 |
362362LL | let _a = A.get_or_init(|| 30);
363363 | -^^^^^^^^^^^^^^^^^^^
......@@ -374,7 +374,7 @@ LL + static A: OnceLock<i32> = OnceLock::new();
374374 |
375375
376376warning: mutation of an interior mutable `const` item with call to `get_or_try_init`
377 --> $DIR/const-item-interior-mutations-const.rs:99:14
377 --> $DIR/const-item-interior-mutations-const.rs:98:14
378378 |
379379LL | let _a = A.get_or_try_init(|| Ok::<_, ()>(40));
380380 | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -391,7 +391,7 @@ LL + static A: OnceLock<i32> = OnceLock::new();
391391 |
392392
393393warning: mutation of an interior mutable `const` item with call to `wait`
394 --> $DIR/const-item-interior-mutations-const.rs:109:14
394 --> $DIR/const-item-interior-mutations-const.rs:108:14
395395 |
396396LL | let _a = A.wait(guard);
397397 | -^^^^^^^^^^^^
......@@ -408,7 +408,7 @@ LL + static A: Condvar = Condvar::new();
408408 |
409409
410410warning: mutation of an interior mutable `const` item with call to `wait_while`
411 --> $DIR/const-item-interior-mutations-const.rs:114:14
411 --> $DIR/const-item-interior-mutations-const.rs:113:14
412412 |
413413LL | let _a = A.wait_while(guard, |x| *x == 0);
414414 | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -425,7 +425,7 @@ LL + static A: Condvar = Condvar::new();
425425 |
426426
427427warning: mutation of an interior mutable `const` item with call to `wait_timeout_ms`
428 --> $DIR/const-item-interior-mutations-const.rs:119:14
428 --> $DIR/const-item-interior-mutations-const.rs:118:14
429429 |
430430LL | let _a = A.wait_timeout_ms(guard, 10);
431431 | -^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -442,7 +442,7 @@ LL + static A: Condvar = Condvar::new();
442442 |
443443
444444warning: mutation of an interior mutable `const` item with call to `wait_timeout`
445 --> $DIR/const-item-interior-mutations-const.rs:124:14
445 --> $DIR/const-item-interior-mutations-const.rs:123:14
446446 |
447447LL | let _a = A.wait_timeout(guard, Duration::from_millis(10));
448448 | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -459,7 +459,7 @@ LL + static A: Condvar = Condvar::new();
459459 |
460460
461461warning: mutation of an interior mutable `const` item with call to `wait_timeout_while`
462 --> $DIR/const-item-interior-mutations-const.rs:129:14
462 --> $DIR/const-item-interior-mutations-const.rs:128:14
463463 |
464464LL | let _a = A.wait_timeout_while(guard, Duration::from_millis(10), |x| *x == 0);
465465 | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -476,7 +476,7 @@ LL + static A: Condvar = Condvar::new();
476476 |
477477
478478warning: mutation of an interior mutable `const` item with call to `notify_one`
479 --> $DIR/const-item-interior-mutations-const.rs:132:14
479 --> $DIR/const-item-interior-mutations-const.rs:131:14
480480 |
481481LL | let _a = A.notify_one();
482482 | -^^^^^^^^^^^^^
......@@ -493,7 +493,7 @@ LL + static A: Condvar = Condvar::new();
493493 |
494494
495495warning: mutation of an interior mutable `const` item with call to `notify_all`
496 --> $DIR/const-item-interior-mutations-const.rs:135:14
496 --> $DIR/const-item-interior-mutations-const.rs:134:14
497497 |
498498LL | let _a = A.notify_all();
499499 | -^^^^^^^^^^^^^