Skip to content

Commit 633ba3a

Browse files
committed
Auto merge of #156808 - JonathanBrouwer:rollup-FwxmQQj, r=JonathanBrouwer
Rollup of 3 pull requests Successful merges: - #155307 (Stabilize `--remap-path-prefix` in rustdoc) - #152112 (Use strongly typed wrapped indices in `VecDeque`) - #156797 (Suggest adding quotation marks to identifiers in attributes)
2 parents e96c36b + b0b82ac commit 633ba3a

25 files changed

Lines changed: 416 additions & 202 deletions

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_ast::{
1212
AttrArgs, Expr, ExprKind, LitKind, MetaItemLit, Path, PathSegment, StmtKind, UnOp,
1313
};
1414
use rustc_ast_pretty::pprust;
15-
use rustc_errors::{Diag, PResult};
15+
use rustc_errors::{Applicability, Diag, PResult};
1616
use rustc_hir::{self as hir, AttrPath};
1717
use rustc_parse::exp;
1818
use rustc_parse::parser::{ForceCollect, Parser, PathStyle, Recovery, token_descr};
@@ -410,7 +410,20 @@ fn expr_to_lit<'sess>(
410410
// - `#[foo = include_str!("nonexistent-file.rs")]`:
411411
// results in `ast::ExprKind::Err`.
412412
let msg = "attribute value must be a literal";
413-
let err = psess.dcx().struct_span_err(span, msg);
413+
let mut err = psess.dcx().struct_span_err(span, msg);
414+
415+
// Suggest adding quotation marks to turn an identifier into a string literal
416+
if let ExprKind::Path(None, ref path) = expr.kind
417+
&& let [segment] = path.segments.as_slice()
418+
{
419+
err.span_suggestion(
420+
expr.span,
421+
"try adding quotation marks",
422+
&format!("\"{}\"", segment.ident),
423+
Applicability::MaybeIncorrect,
424+
);
425+
}
426+
414427
Err(err)
415428
}
416429
}

library/alloc/src/collections/vec_deque/drain.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use core::ptr::NonNull;
55
use core::{fmt, ptr};
66

77
use super::VecDeque;
8+
use super::index::WrappedIndex;
89
use crate::alloc::{Allocator, Global};
910

1011
/// A draining iterator over the elements of a `VecDeque`.
@@ -203,11 +204,11 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
203204
let (src, dst, len);
204205
if head_len < tail_len {
205206
src = source_deque.head;
206-
dst = source_deque.to_physical_idx(drain_len);
207+
dst = source_deque.to_wrapped_index(drain_len);
207208
len = head_len;
208209
} else {
209-
src = source_deque.to_physical_idx(head_len + drain_len);
210-
dst = source_deque.to_physical_idx(head_len);
210+
src = source_deque.to_wrapped_index(head_len + drain_len);
211+
dst = source_deque.to_wrapped_index(head_len);
211212
len = tail_len;
212213
};
213214

@@ -220,10 +221,10 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
220221
if new_len == 0 {
221222
// Special case: If the entire deque was drained, reset the head back to 0,
222223
// like `.clear()` does.
223-
source_deque.head = 0;
224+
source_deque.head = WrappedIndex::zero();
224225
} else if head_len < tail_len {
225226
// If we moved the head above, then we need to adjust the head index here.
226-
source_deque.head = source_deque.to_physical_idx(drain_len);
227+
source_deque.head = source_deque.to_wrapped_index(drain_len);
227228
}
228229
source_deque.len = new_len;
229230
}
@@ -240,7 +241,7 @@ impl<T, A: Allocator> Iterator for Drain<'_, T, A> {
240241
if self.remaining == 0 {
241242
return None;
242243
}
243-
let wrapped_idx = unsafe { self.deque.as_ref().to_physical_idx(self.idx) };
244+
let wrapped_idx = unsafe { self.deque.as_ref().to_wrapped_index(self.idx) };
244245
self.idx += 1;
245246
self.remaining -= 1;
246247
Some(unsafe { self.deque.as_mut().buffer_read(wrapped_idx) })
@@ -261,7 +262,8 @@ impl<T, A: Allocator> DoubleEndedIterator for Drain<'_, T, A> {
261262
return None;
262263
}
263264
self.remaining -= 1;
264-
let wrapped_idx = unsafe { self.deque.as_ref().to_physical_idx(self.idx + self.remaining) };
265+
let wrapped_idx =
266+
unsafe { self.deque.as_ref().to_wrapped_index(self.idx + self.remaining) };
265267
Some(unsafe { self.deque.as_mut().buffer_read(wrapped_idx) })
266268
}
267269
}

library/alloc/src/collections/vec_deque/extract_if.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ where
8383
//
8484
// Note: we can't use `vec.get_mut(i).unwrap()` here since the precondition for that
8585
// function is that i < vec.len, but we've set vec's length to zero.
86-
let idx = self.vec.to_physical_idx(i);
87-
let cur = unsafe { &mut *self.vec.ptr().add(idx) };
86+
let idx = self.vec.to_wrapped_index(i);
87+
let cur = unsafe { &mut *self.vec.ptr().add(idx.as_index()) };
8888
let drained = (self.pred)(cur);
8989
// Update the index *after* the predicate is called. If the index
9090
// is updated prior and the predicate panics, the element at this
@@ -95,7 +95,7 @@ where
9595
// SAFETY: We never touch this element again after returning it.
9696
return Some(unsafe { ptr::read(cur) });
9797
} else if self.del > 0 {
98-
let hole_slot = self.vec.to_physical_idx(i - self.del);
98+
let hole_slot = self.vec.to_wrapped_index(i - self.del);
9999
// SAFETY: `self.del` > 0, so the hole slot must not overlap with current element.
100100
// We use copy for move, and never touch this element again.
101101
unsafe { self.vec.wrap_copy(idx, hole_slot, 1) };
@@ -113,8 +113,8 @@ where
113113
impl<T, F, A: Allocator> Drop for ExtractIf<'_, T, F, A> {
114114
fn drop(&mut self) {
115115
if self.del > 0 {
116-
let src = self.vec.to_physical_idx(self.idx);
117-
let dst = self.vec.to_physical_idx(self.idx - self.del);
116+
let src = self.vec.to_wrapped_index(self.idx);
117+
let dst = self.vec.to_wrapped_index(self.idx - self.del);
118118
let len = self.old_len - self.idx;
119119
// SAFETY: Trailing unchecked items must be valid since we never touch them.
120120
unsafe { self.vec.wrap_copy(src, dst, len) };
@@ -131,7 +131,7 @@ where
131131
{
132132
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133133
let peek = if self.idx < self.end {
134-
let idx = self.vec.to_physical_idx(self.idx);
134+
let idx = self.vec.to_wrapped_index(self.idx);
135135
// This has to use pointer arithmetic as `self.vec[self.idx]` or
136136
// `self.vec.get_unchecked(self.idx)` wouldn't work since we
137137
// temporarily set the length of `self.vec` to zero.
@@ -141,7 +141,7 @@ where
141141
// smaller than `self.old_len`, `idx` is valid for indexing the
142142
// buffer. Also, per the invariant of `self.idx`, this element
143143
// has not been inspected/moved out yet.
144-
Some(unsafe { &*self.vec.ptr().add(idx) })
144+
Some(unsafe { &*self.vec.ptr().add(idx.as_index()) })
145145
} else {
146146
None
147147
};

library/alloc/src/collections/vec_deque/into_iter.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use core::ops::Try;
55
use core::{array, fmt, ptr};
66

77
use super::VecDeque;
8+
use super::index::WrappedIndex;
89
use crate::alloc::{Allocator, Global};
910

1011
/// An owning iterator over the elements of a `VecDeque`.
@@ -86,7 +87,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
8687
impl<'a, T, A: Allocator> Drop for Guard<'a, T, A> {
8788
fn drop(&mut self) {
8889
self.deque.len -= self.consumed;
89-
self.deque.head = self.deque.to_physical_idx(self.consumed);
90+
self.deque.head = self.deque.to_wrapped_index(self.consumed);
9091
}
9192
}
9293

@@ -140,7 +141,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
140141
// SAFETY: By manually adjusting the head and length of the deque, we effectively
141142
// make it forget the first `N` elements, so taking ownership of them is safe.
142143
unsafe { ptr::copy_nonoverlapping(head.as_ptr(), raw_arr_ptr, N) };
143-
self.inner.head = self.inner.to_physical_idx(N);
144+
self.inner.head = self.inner.to_wrapped_index(N);
144145
self.inner.len -= N;
145146
// SAFETY: We initialized the entire array with items from `head`
146147
return Ok(unsafe { raw_arr.transpose().assume_init() });
@@ -155,7 +156,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
155156
unsafe {
156157
ptr::copy_nonoverlapping(tail.as_ptr(), raw_arr_ptr.add(head.len()), remaining)
157158
};
158-
self.inner.head = self.inner.to_physical_idx(N);
159+
self.inner.head = self.inner.to_wrapped_index(N);
159160
self.inner.len -= N;
160161
// SAFETY: We initialized the entire array with items from `head` and `tail`
161162
Ok(unsafe { raw_arr.transpose().assume_init() })
@@ -166,7 +167,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
166167
};
167168
let init = head.len() + tail.len();
168169
// We completely drained all the deques elements.
169-
self.inner.head = 0;
170+
self.inner.head = WrappedIndex::zero();
170171
self.inner.len = 0;
171172
// SAFETY: We copied all elements from both slices to the beginning of the array, so
172173
// the given range is initialized.

0 commit comments

Comments
 (0)