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
This commit is contained in:
commit
e461b8137f
15 changed files with 42 additions and 32 deletions
|
@ -434,7 +434,7 @@ impl Token {
|
|||
|| self == &OpenDelim(Paren)
|
||||
}
|
||||
|
||||
/// Returns `true` if the token is any literal
|
||||
/// Returns `true` if the token is any literal.
|
||||
pub fn is_lit(&self) -> bool {
|
||||
match self.kind {
|
||||
Literal(..) => true,
|
||||
|
|
|
@ -149,8 +149,6 @@ struct Event<N> {
|
|||
/// those successors), we will pop off that node's `Settled` event.
|
||||
///
|
||||
/// [CLR]: https://en.wikipedia.org/wiki/Introduction_to_Algorithms
|
||||
/// [`NodeStatus`]: ./enum.NodeStatus.html
|
||||
/// [`TriColorVisitor::node_examined`]: ./trait.TriColorVisitor.html#method.node_examined
|
||||
pub struct TriColorDepthFirstSearch<'graph, G>
|
||||
where
|
||||
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,
|
||||
|
|
|
@ -24,8 +24,7 @@ use rustc_index::vec::{Idx, IndexVec};
|
|||
/// to insert into the middle of the sorted array. Users should avoid mutating this data structure
|
||||
/// in-place.
|
||||
///
|
||||
/// [`IndexVec`]: ../../rustc_index/vec/struct.IndexVec.html
|
||||
/// [`SortedMap`]: ../sorted_map/struct.SortedMap.html
|
||||
/// [`SortedMap`]: super::SortedMap
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SortedIndexMultiMap<I: Idx, K, V> {
|
||||
/// The elements of the map in insertion order.
|
||||
|
|
|
@ -40,7 +40,7 @@ const SSO_ARRAY_SIZE: usize = 8;
|
|||
// into_keys/into_values (unstable)
|
||||
// all raw_entry-related
|
||||
// PartialEq/Eq (requires sorting the array)
|
||||
// Entry::or_insert_with_key (unstable)
|
||||
// Entry::or_insert_with_key
|
||||
// Vacant/Occupied entries and related
|
||||
//
|
||||
// FIXME: In HashMap most methods accepting key reference
|
||||
|
|
|
@ -138,8 +138,6 @@ impl Diagnostic {
|
|||
///
|
||||
/// This span is *not* considered a ["primary span"][`MultiSpan`]; only
|
||||
/// the `Span` supplied when creating the diagnostic is primary.
|
||||
///
|
||||
/// [`MultiSpan`]: ../rustc_span/struct.MultiSpan.html
|
||||
pub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self {
|
||||
self.span.push_span_label(span, label.into());
|
||||
self
|
||||
|
|
|
@ -27,7 +27,6 @@ pub const WORD_BITS: usize = WORD_BYTES * 8;
|
|||
/// to or greater than the domain size. All operations that involve two bitsets
|
||||
/// will panic if the bitsets have differing domain sizes.
|
||||
///
|
||||
/// [`GrowableBitSet`]: struct.GrowableBitSet.html
|
||||
#[derive(Eq, PartialEq, Decodable, Encodable)]
|
||||
pub struct BitSet<T> {
|
||||
domain_size: usize,
|
||||
|
|
|
@ -201,7 +201,7 @@ fn scan_escape(first_char: char, chars: &mut Chars<'_>, mode: Mode) -> Result<ch
|
|||
return Err(EscapeError::NoBraceInUnicodeEscape);
|
||||
}
|
||||
|
||||
// First characrer must be a hexadecimal digit.
|
||||
// First character must be a hexadecimal digit.
|
||||
let mut n_digits = 1;
|
||||
let mut value: u32 = match chars.next().ok_or(EscapeError::UnclosedUnicodeEscape)? {
|
||||
'_' => return Err(EscapeError::LeadingUnderscoreUnicodeEscape),
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::dataflow::{AnalysisDomain, Backward, GenKill, GenKillAnalysis};
|
|||
/// exist. See [this `mir-dataflow` test][flow-test] for an example. You almost never want to use
|
||||
/// this analysis without also looking at the results of [`MaybeBorrowedLocals`].
|
||||
///
|
||||
/// [`MaybeBorrowedLocals`]: ../struct.MaybeBorrowedLocals.html
|
||||
/// [`MaybeBorrowedLocals`]: super::MaybeBorrowedLocals
|
||||
/// [flow-test]: https://github.com/rust-lang/rust/blob/a08c47310c7d49cbdc5d7afb38408ba519967ecd/src/test/ui/mir-dataflow/liveness-ptr.rs
|
||||
/// [liveness]: https://en.wikipedia.org/wiki/Live_variable_analysis
|
||||
pub struct MaybeLiveLocals;
|
||||
|
|
|
@ -66,12 +66,14 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
|
|||
location: Location,
|
||||
decorate: impl for<'b> FnOnce(LintDiagnosticBuilder<'b>) -> DiagnosticBuilder<'b>,
|
||||
) {
|
||||
// Don't lint on borrowing/assigning to a dereference
|
||||
// e.g:
|
||||
// Don't lint on borrowing/assigning when a dereference is involved.
|
||||
// If we 'leave' the temporary via a dereference, we must
|
||||
// be modifying something else
|
||||
//
|
||||
// `unsafe { *FOO = 0; *BAR.field = 1; }`
|
||||
// `unsafe { &mut *FOO }`
|
||||
if !matches!(place.projection.last(), Some(PlaceElem::Deref)) {
|
||||
// `unsafe { (*ARRAY)[0] = val; }
|
||||
if !place.projection.iter().any(|p| matches!(p, PlaceElem::Deref)) {
|
||||
let source_info = self.body.source_info(location);
|
||||
let lint_root = self.body.source_scopes[source_info.scope]
|
||||
.local_data
|
||||
|
|
|
@ -116,15 +116,16 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "or_insert_with_key", issue = "71024")]
|
||||
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
|
||||
/// which takes the key as its argument, and returns a mutable reference to the value in the
|
||||
/// entry.
|
||||
/// Ensures a value is in the entry by inserting, if empty, the result of the default function.
|
||||
/// This method allows for generating key-derived values for insertion by providing the default
|
||||
/// function a reference to the key that was moved during the `.entry(key)` method call.
|
||||
///
|
||||
/// The reference to the moved key is provided so that cloning or copying the key is
|
||||
/// unnecessary, unlike with `.or_insert_with(|| ... )`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(or_insert_with_key)]
|
||||
/// use std::collections::BTreeMap;
|
||||
///
|
||||
/// let mut map: BTreeMap<&str, usize> = BTreeMap::new();
|
||||
|
@ -134,6 +135,7 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
|
|||
/// assert_eq!(map["poneyland"], 9);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "or_insert_with_key", since = "1.50.0")]
|
||||
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
|
||||
match self {
|
||||
Occupied(entry) => entry.into_mut(),
|
||||
|
|
|
@ -2219,14 +2219,16 @@ impl<'a, K, V> Entry<'a, K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
|
||||
/// which takes the key as its argument, and returns a mutable reference to the value in the
|
||||
/// entry.
|
||||
/// Ensures a value is in the entry by inserting, if empty, the result of the default function.
|
||||
/// This method allows for generating key-derived values for insertion by providing the default
|
||||
/// function a reference to the key that was moved during the `.entry(key)` method call.
|
||||
///
|
||||
/// The reference to the moved key is provided so that cloning or copying the key is
|
||||
/// unnecessary, unlike with `.or_insert_with(|| ... )`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(or_insert_with_key)]
|
||||
/// use std::collections::HashMap;
|
||||
///
|
||||
/// let mut map: HashMap<&str, usize> = HashMap::new();
|
||||
|
@ -2236,7 +2238,7 @@ impl<'a, K, V> Entry<'a, K, V> {
|
|||
/// assert_eq!(map["poneyland"], 9);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "or_insert_with_key", issue = "71024")]
|
||||
#[stable(feature = "or_insert_with_key", since = "1.50.0")]
|
||||
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
|
||||
match self {
|
||||
Occupied(entry) => entry.into_mut(),
|
||||
|
|
|
@ -2196,6 +2196,7 @@ mod where_keyword {}
|
|||
|
||||
// 2018 Edition keywords
|
||||
|
||||
#[doc(alias = "promise")]
|
||||
#[doc(keyword = "async")]
|
||||
//
|
||||
/// Return a [`Future`] instead of blocking the current thread.
|
||||
|
|
|
@ -924,6 +924,7 @@ mod prim_usize {}
|
|||
|
||||
#[doc(primitive = "reference")]
|
||||
#[doc(alias = "&")]
|
||||
#[doc(alias = "&mut")]
|
||||
//
|
||||
/// References, both shared and mutable.
|
||||
///
|
||||
|
|
|
@ -30,6 +30,8 @@ const MUTABLE: Mutable = Mutable { msg: "" };
|
|||
const MUTABLE2: Mutable2 = Mutable2 { msg: "", other: String::new() };
|
||||
const VEC: Vec<i32> = Vec::new();
|
||||
const PTR: *mut () = 1 as *mut _;
|
||||
const PTR_TO_ARRAY: *mut [u32; 4] = 0x12345678 as _;
|
||||
const ARRAY_OF_PTR: [*mut u32; 1] = [1 as *mut _];
|
||||
|
||||
fn main() {
|
||||
ARRAY[0] = 5; //~ WARN attempting to modify
|
||||
|
@ -55,4 +57,10 @@ fn main() {
|
|||
// Test that we don't warn when converting a raw pointer
|
||||
// into a mutable reference
|
||||
unsafe { &mut *PTR };
|
||||
|
||||
// Test that we don't warn when there's a dereference involved.
|
||||
// If we ever 'leave' the const via a deference, we're going
|
||||
// to end up modifying something other than the temporary
|
||||
unsafe { (*PTR_TO_ARRAY)[0] = 1 };
|
||||
unsafe { *ARRAY_OF_PTR[0] = 25; }
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
warning: attempting to modify a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:35:5
|
||||
--> $DIR/lint-const-item-mutation.rs:37:5
|
||||
|
|
||||
LL | ARRAY[0] = 5;
|
||||
| ^^^^^^^^^^^^
|
||||
|
@ -13,7 +13,7 @@ LL | const ARRAY: [u8; 1] = [25];
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: attempting to modify a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:36:5
|
||||
--> $DIR/lint-const-item-mutation.rs:38:5
|
||||
|
|
||||
LL | MY_STRUCT.field = false;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -26,7 +26,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: attempting to modify a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:37:5
|
||||
--> $DIR/lint-const-item-mutation.rs:39:5
|
||||
|
|
||||
LL | MY_STRUCT.inner_array[0] = 'b';
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -39,7 +39,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: taking a mutable reference to a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:38:5
|
||||
--> $DIR/lint-const-item-mutation.rs:40:5
|
||||
|
|
||||
LL | MY_STRUCT.use_mut();
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -58,7 +58,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: taking a mutable reference to a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:39:5
|
||||
--> $DIR/lint-const-item-mutation.rs:41:5
|
||||
|
|
||||
LL | &mut MY_STRUCT;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
@ -72,7 +72,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: taking a mutable reference to a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:40:5
|
||||
--> $DIR/lint-const-item-mutation.rs:42:5
|
||||
|
|
||||
LL | (&mut MY_STRUCT).use_mut();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
@ -86,7 +86,7 @@ LL | const MY_STRUCT: MyStruct = MyStruct { field: true, inner_array: ['a'], raw
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: attempting to modify a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:52:5
|
||||
--> $DIR/lint-const-item-mutation.rs:54:5
|
||||
|
|
||||
LL | MUTABLE2.msg = "wow";
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -99,7 +99,7 @@ LL | const MUTABLE2: Mutable2 = Mutable2 { msg: "", other: String::new() };
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: taking a mutable reference to a `const` item
|
||||
--> $DIR/lint-const-item-mutation.rs:53:5
|
||||
--> $DIR/lint-const-item-mutation.rs:55:5
|
||||
|
|
||||
LL | VEC.push(0);
|
||||
| ^^^^^^^^^^^
|
||||
|
|
Loading…
Add table
Reference in a new issue