Skip to content

Commit e461b81

Browse files
committed
Auto merge of #80180 - JohnTitor:rollup-a31s996, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #78083 (Stabilize or_insert_with_key) - #79211 (Add the "async" and "promise" doc aliases to `core::future::Future`) - #79612 (Switch some links in compiler/ to intra-doc links) - #80068 (Add `&mut` as an alias for 'reference' primitive) - #80129 (docs: Edit rustc_ast::token::Token) - #80133 (Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere) - #80155 (Fix typo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3d9ada6 + b27c783 commit e461b81

File tree

15 files changed

+42
-32
lines changed

15 files changed

+42
-32
lines changed

compiler/rustc_ast/src/token.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl Token {
434434
|| self == &OpenDelim(Paren)
435435
}
436436

437-
/// Returns `true` if the token is any literal
437+
/// Returns `true` if the token is any literal.
438438
pub fn is_lit(&self) -> bool {
439439
match self.kind {
440440
Literal(..) => true,

compiler/rustc_data_structures/src/graph/iterate/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ struct Event<N> {
149149
/// those successors), we will pop off that node's `Settled` event.
150150
///
151151
/// [CLR]: https://en.wikipedia.org/wiki/Introduction_to_Algorithms
152-
/// [`NodeStatus`]: ./enum.NodeStatus.html
153-
/// [`TriColorVisitor::node_examined`]: ./trait.TriColorVisitor.html#method.node_examined
154152
pub struct TriColorDepthFirstSearch<'graph, G>
155153
where
156154
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,

compiler/rustc_data_structures/src/sorted_map/index_map.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ use rustc_index::vec::{Idx, IndexVec};
2424
/// to insert into the middle of the sorted array. Users should avoid mutating this data structure
2525
/// in-place.
2626
///
27-
/// [`IndexVec`]: ../../rustc_index/vec/struct.IndexVec.html
28-
/// [`SortedMap`]: ../sorted_map/struct.SortedMap.html
27+
/// [`SortedMap`]: super::SortedMap
2928
#[derive(Clone, Debug)]
3029
pub struct SortedIndexMultiMap<I: Idx, K, V> {
3130
/// The elements of the map in insertion order.

compiler/rustc_data_structures/src/sso/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const SSO_ARRAY_SIZE: usize = 8;
4040
// into_keys/into_values (unstable)
4141
// all raw_entry-related
4242
// PartialEq/Eq (requires sorting the array)
43-
// Entry::or_insert_with_key (unstable)
43+
// Entry::or_insert_with_key
4444
// Vacant/Occupied entries and related
4545
//
4646
// FIXME: In HashMap most methods accepting key reference

compiler/rustc_errors/src/diagnostic.rs

-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ impl Diagnostic {
138138
///
139139
/// This span is *not* considered a ["primary span"][`MultiSpan`]; only
140140
/// the `Span` supplied when creating the diagnostic is primary.
141-
///
142-
/// [`MultiSpan`]: ../rustc_span/struct.MultiSpan.html
143141
pub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self {
144142
self.span.push_span_label(span, label.into());
145143
self

compiler/rustc_index/src/bit_set.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub const WORD_BITS: usize = WORD_BYTES * 8;
2727
/// to or greater than the domain size. All operations that involve two bitsets
2828
/// will panic if the bitsets have differing domain sizes.
2929
///
30-
/// [`GrowableBitSet`]: struct.GrowableBitSet.html
3130
#[derive(Eq, PartialEq, Decodable, Encodable)]
3231
pub struct BitSet<T> {
3332
domain_size: usize,

compiler/rustc_lexer/src/unescape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn scan_escape(first_char: char, chars: &mut Chars<'_>, mode: Mode) -> Result<ch
201201
return Err(EscapeError::NoBraceInUnicodeEscape);
202202
}
203203

204-
// First characrer must be a hexadecimal digit.
204+
// First character must be a hexadecimal digit.
205205
let mut n_digits = 1;
206206
let mut value: u32 = match chars.next().ok_or(EscapeError::UnclosedUnicodeEscape)? {
207207
'_' => return Err(EscapeError::LeadingUnderscoreUnicodeEscape),

compiler/rustc_mir/src/dataflow/impls/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::dataflow::{AnalysisDomain, Backward, GenKill, GenKillAnalysis};
1111
/// exist. See [this `mir-dataflow` test][flow-test] for an example. You almost never want to use
1212
/// this analysis without also looking at the results of [`MaybeBorrowedLocals`].
1313
///
14-
/// [`MaybeBorrowedLocals`]: ../struct.MaybeBorrowedLocals.html
14+
/// [`MaybeBorrowedLocals`]: super::MaybeBorrowedLocals
1515
/// [flow-test]: https://github.com/rust-lang/rust/blob/a08c47310c7d49cbdc5d7afb38408ba519967ecd/src/test/ui/mir-dataflow/liveness-ptr.rs
1616
/// [liveness]: https://en.wikipedia.org/wiki/Live_variable_analysis
1717
pub struct MaybeLiveLocals;

compiler/rustc_mir/src/transform/check_const_item_mutation.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
6666
location: Location,
6767
decorate: impl for<'b> FnOnce(LintDiagnosticBuilder<'b>) -> DiagnosticBuilder<'b>,
6868
) {
69-
// Don't lint on borrowing/assigning to a dereference
70-
// e.g:
69+
// Don't lint on borrowing/assigning when a dereference is involved.
70+
// If we 'leave' the temporary via a dereference, we must
71+
// be modifying something else
7172
//
7273
// `unsafe { *FOO = 0; *BAR.field = 1; }`
7374
// `unsafe { &mut *FOO }`
74-
if !matches!(place.projection.last(), Some(PlaceElem::Deref)) {
75+
// `unsafe { (*ARRAY)[0] = val; }
76+
if !place.projection.iter().any(|p| matches!(p, PlaceElem::Deref)) {
7577
let source_info = self.body.source_info(location);
7678
let lint_root = self.body.source_scopes[source_info.scope]
7779
.local_data

library/alloc/src/collections/btree/map/entry.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,16 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
116116
}
117117
}
118118

119-
#[unstable(feature = "or_insert_with_key", issue = "71024")]
120-
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
121-
/// which takes the key as its argument, and returns a mutable reference to the value in the
122-
/// entry.
119+
/// Ensures a value is in the entry by inserting, if empty, the result of the default function.
120+
/// This method allows for generating key-derived values for insertion by providing the default
121+
/// function a reference to the key that was moved during the `.entry(key)` method call.
122+
///
123+
/// The reference to the moved key is provided so that cloning or copying the key is
124+
/// unnecessary, unlike with `.or_insert_with(|| ... )`.
123125
///
124126
/// # Examples
125127
///
126128
/// ```
127-
/// #![feature(or_insert_with_key)]
128129
/// use std::collections::BTreeMap;
129130
///
130131
/// let mut map: BTreeMap<&str, usize> = BTreeMap::new();
@@ -134,6 +135,7 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
134135
/// assert_eq!(map["poneyland"], 9);
135136
/// ```
136137
#[inline]
138+
#[stable(feature = "or_insert_with_key", since = "1.50.0")]
137139
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
138140
match self {
139141
Occupied(entry) => entry.into_mut(),

library/std/src/collections/hash/map.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -2219,14 +2219,16 @@ impl<'a, K, V> Entry<'a, K, V> {
22192219
}
22202220
}
22212221

2222-
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
2223-
/// which takes the key as its argument, and returns a mutable reference to the value in the
2224-
/// entry.
2222+
/// Ensures a value is in the entry by inserting, if empty, the result of the default function.
2223+
/// This method allows for generating key-derived values for insertion by providing the default
2224+
/// function a reference to the key that was moved during the `.entry(key)` method call.
2225+
///
2226+
/// The reference to the moved key is provided so that cloning or copying the key is
2227+
/// unnecessary, unlike with `.or_insert_with(|| ... )`.
22252228
///
22262229
/// # Examples
22272230
///
22282231
/// ```
2229-
/// #![feature(or_insert_with_key)]
22302232
/// use std::collections::HashMap;
22312233
///
22322234
/// let mut map: HashMap<&str, usize> = HashMap::new();
@@ -2236,7 +2238,7 @@ impl<'a, K, V> Entry<'a, K, V> {
22362238
/// assert_eq!(map["poneyland"], 9);
22372239
/// ```
22382240
#[inline]
2239-
#[unstable(feature = "or_insert_with_key", issue = "71024")]
2241+
#[stable(feature = "or_insert_with_key", since = "1.50.0")]
22402242
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
22412243
match self {
22422244
Occupied(entry) => entry.into_mut(),

library/std/src/keyword_docs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2196,6 +2196,7 @@ mod where_keyword {}
21962196

21972197
// 2018 Edition keywords
21982198

2199+
#[doc(alias = "promise")]
21992200
#[doc(keyword = "async")]
22002201
//
22012202
/// Return a [`Future`] instead of blocking the current thread.

library/std/src/primitive_docs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ mod prim_usize {}
924924

925925
#[doc(primitive = "reference")]
926926
#[doc(alias = "&")]
927+
#[doc(alias = "&mut")]
927928
//
928929
/// References, both shared and mutable.
929930
///

src/test/ui/lint/lint-const-item-mutation.rs

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const MUTABLE: Mutable = Mutable { msg: "" };
3030
const MUTABLE2: Mutable2 = Mutable2 { msg: "", other: String::new() };
3131
const VEC: Vec<i32> = Vec::new();
3232
const PTR: *mut () = 1 as *mut _;
33+
const PTR_TO_ARRAY: *mut [u32; 4] = 0x12345678 as _;
34+
const ARRAY_OF_PTR: [*mut u32; 1] = [1 as *mut _];
3335

3436
fn main() {
3537
ARRAY[0] = 5; //~ WARN attempting to modify
@@ -55,4 +57,10 @@ fn main() {
5557
// Test that we don't warn when converting a raw pointer
5658
// into a mutable reference
5759
unsafe { &mut *PTR };
60+
61+
// Test that we don't warn when there's a dereference involved.
62+
// If we ever 'leave' the const via a deference, we're going
63+
// to end up modifying something other than the temporary
64+
unsafe { (*PTR_TO_ARRAY)[0] = 1 };
65+
unsafe { *ARRAY_OF_PTR[0] = 25; }
5866
}

src/test/ui/lint/lint-const-item-mutation.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: attempting to modify a `const` item
2-
--> $DIR/lint-const-item-mutation.rs:35:5
2+
--> $DIR/lint-const-item-mutation.rs:37:5
33
|
44
LL | ARRAY[0] = 5;
55
| ^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL | const ARRAY: [u8; 1] = [25];
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

1515
warning: attempting to modify a `const` item
16-
--> $DIR/lint-const-item-mutation.rs:36:5
16+
--> $DIR/lint-const-item-mutation.rs:38:5
1717
|
1818
LL | MY_STRUCT.field = false;
1919
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727

2828
warning: attempting to modify a `const` item
29-
--> $DIR/lint-const-item-mutation.rs:37:5
29+
--> $DIR/lint-const-item-mutation.rs:39:5
3030
|
3131
LL | MY_STRUCT.inner_array[0] = 'b';
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -39,7 +39,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4040

4141
warning: taking a mutable reference to a `const` item
42-
--> $DIR/lint-const-item-mutation.rs:38:5
42+
--> $DIR/lint-const-item-mutation.rs:40:5
4343
|
4444
LL | MY_STRUCT.use_mut();
4545
| ^^^^^^^^^^^^^^^^^^^
@@ -58,7 +58,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
5858
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5959

6060
warning: taking a mutable reference to a `const` item
61-
--> $DIR/lint-const-item-mutation.rs:39:5
61+
--> $DIR/lint-const-item-mutation.rs:41:5
6262
|
6363
LL | &mut MY_STRUCT;
6464
| ^^^^^^^^^^^^^^
@@ -72,7 +72,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7373

7474
warning: taking a mutable reference to a `const` item
75-
--> $DIR/lint-const-item-mutation.rs:40:5
75+
--> $DIR/lint-const-item-mutation.rs:42:5
7676
|
7777
LL | (&mut MY_STRUCT).use_mut();
7878
| ^^^^^^^^^^^^^^^^
@@ -86,7 +86,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787

8888
warning: attempting to modify a `const` item
89-
--> $DIR/lint-const-item-mutation.rs:52:5
89+
--> $DIR/lint-const-item-mutation.rs:54:5
9090
|
9191
LL | MUTABLE2.msg = "wow";
9292
| ^^^^^^^^^^^^^^^^^^^^
@@ -99,7 +99,7 @@ LL | const MUTABLE2: Mutable2 = Mutable2 { msg: "", other: String::new() };
9999
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100100

101101
warning: taking a mutable reference to a `const` item
102-
--> $DIR/lint-const-item-mutation.rs:53:5
102+
--> $DIR/lint-const-item-mutation.rs:55:5
103103
|
104104
LL | VEC.push(0);
105105
| ^^^^^^^^^^^

0 commit comments

Comments
 (0)