Skip to content

Commit 35bab92

Browse files
committed
Auto merge of rust-lang#85486 - RalfJung:rollup-4ibcxuu, r=RalfJung
Rollup of 8 pull requests Successful merges: - rust-lang#84717 (impl FromStr for proc_macro::Literal) - rust-lang#85169 (Add method-toggle to <details> for methods) - rust-lang#85287 (Expose `Concurrent` (private type in public i'face)) - rust-lang#85315 (adding time complexity for partition_in_place iter method) - rust-lang#85439 (Add diagnostic item to `CStr`) - rust-lang#85464 (Fix UB in documented example for `ptr::swap`) - rust-lang#85470 (Fix invalid CSS rules for a:hover) - rust-lang#85472 (CTFE Machine: do not expose Allocation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5ab0f37 + 9fa15ff commit 35bab92

File tree

19 files changed

+179
-48
lines changed

19 files changed

+179
-48
lines changed

Diff for: compiler/rustc_expand/src/proc_macro_server.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::base::{ExtCtxt, ResolverExpand};
22

33
use rustc_ast as ast;
4-
use rustc_ast::token;
5-
use rustc_ast::token::Nonterminal;
6-
use rustc_ast::token::NtIdent;
4+
use rustc_ast::token::{self, Nonterminal, NtIdent, TokenKind};
75
use rustc_ast::tokenstream::{self, CanSynthesizeMissingTokens};
86
use rustc_ast::tokenstream::{DelimSpan, Spacing::*, TokenStream, TreeAndSpacing};
97
use rustc_ast_pretty::pprust;
@@ -541,6 +539,33 @@ impl server::Ident for Rustc<'_> {
541539
}
542540

543541
impl server::Literal for Rustc<'_> {
542+
fn from_str(&mut self, s: &str) -> Result<Self::Literal, ()> {
543+
let override_span = None;
544+
let stream = parse_stream_from_source_str(
545+
FileName::proc_macro_source_code(s),
546+
s.to_owned(),
547+
self.sess,
548+
override_span,
549+
);
550+
if stream.len() != 1 {
551+
return Err(());
552+
}
553+
let tree = stream.into_trees().next().unwrap();
554+
let token = match tree {
555+
tokenstream::TokenTree::Token(token) => token,
556+
tokenstream::TokenTree::Delimited { .. } => return Err(()),
557+
};
558+
let span_data = token.span.data();
559+
if (span_data.hi.0 - span_data.lo.0) as usize != s.len() {
560+
// There is a comment or whitespace adjacent to the literal.
561+
return Err(());
562+
}
563+
let lit = match token.kind {
564+
TokenKind::Literal(lit) => lit,
565+
_ => return Err(()),
566+
};
567+
Ok(Literal { lit, span: self.call_site })
568+
}
544569
fn debug_kind(&mut self, literal: &Self::Literal) -> String {
545570
format!("{:?}", literal.lit.kind)
546571
}

Diff for: compiler/rustc_mir/src/interpret/machine.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
313313
#[inline(always)]
314314
fn memory_read(
315315
_memory_extra: &Self::MemoryExtra,
316-
_alloc: &Allocation<Self::PointerTag, Self::AllocExtra>,
316+
_alloc_extra: &Self::AllocExtra,
317317
_ptr: Pointer<Self::PointerTag>,
318318
_size: Size,
319319
) -> InterpResult<'tcx> {
@@ -324,7 +324,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
324324
#[inline(always)]
325325
fn memory_written(
326326
_memory_extra: &mut Self::MemoryExtra,
327-
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
327+
_alloc_extra: &mut Self::AllocExtra,
328328
_ptr: Pointer<Self::PointerTag>,
329329
_size: Size,
330330
) -> InterpResult<'tcx> {
@@ -335,8 +335,9 @@ pub trait Machine<'mir, 'tcx>: Sized {
335335
#[inline(always)]
336336
fn memory_deallocated(
337337
_memory_extra: &mut Self::MemoryExtra,
338-
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
338+
_alloc_extra: &mut Self::AllocExtra,
339339
_ptr: Pointer<Self::PointerTag>,
340+
_size: Size,
340341
) -> InterpResult<'tcx> {
341342
Ok(())
342343
}

Diff for: compiler/rustc_mir/src/interpret/memory.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
343343
}
344344

345345
// Let the machine take some extra action
346-
M::memory_deallocated(&mut self.extra, &mut alloc, ptr)?;
346+
let size = alloc.size();
347+
M::memory_deallocated(&mut self.extra, &mut alloc.extra, ptr, size)?;
347348

348349
// Don't forget to remember size and align of this now-dead allocation
349-
let old = self.dead_alloc_map.insert(ptr.alloc_id, (alloc.size(), alloc.align));
350+
let old = self.dead_alloc_map.insert(ptr.alloc_id, (size, alloc.align));
350351
if old.is_some() {
351352
bug!("Nothing can be deallocated twice");
352353
}
@@ -591,7 +592,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
591592
},
592593
)?;
593594
if let Some((ptr, alloc)) = ptr_and_alloc {
594-
M::memory_read(&self.extra, alloc, ptr, size)?;
595+
M::memory_read(&self.extra, &alloc.extra, ptr, size)?;
595596
let range = alloc_range(ptr.offset, size);
596597
Ok(Some(AllocRef { alloc, range, tcx: self.tcx, alloc_id: ptr.alloc_id }))
597598
} else {
@@ -660,7 +661,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
660661
// FIXME: can we somehow avoid looking up the allocation twice here?
661662
// We cannot call `get_raw_mut` inside `check_and_deref_ptr` as that would duplicate `&mut self`.
662663
let (alloc, extra) = self.get_raw_mut(ptr.alloc_id)?;
663-
M::memory_written(extra, alloc, ptr, size)?;
664+
M::memory_written(extra, &mut alloc.extra, ptr, size)?;
664665
let range = alloc_range(ptr.offset, size);
665666
Ok(Some(AllocRefMut { alloc, range, tcx, alloc_id: ptr.alloc_id }))
666667
} else {
@@ -1029,7 +1030,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
10291030
Some(src_ptr) => src_ptr,
10301031
};
10311032
let src_alloc = self.get_raw(src.alloc_id)?;
1032-
M::memory_read(&self.extra, src_alloc, src, size)?;
1033+
M::memory_read(&self.extra, &src_alloc.extra, src, size)?;
10331034
// We need the `dest` ptr for the next operation, so we get it now.
10341035
// We already did the source checks and called the hooks so we are good to return early.
10351036
let dest = match dest {
@@ -1058,7 +1059,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
10581059

10591060
// Destination alloc preparations and access hooks.
10601061
let (dest_alloc, extra) = self.get_raw_mut(dest.alloc_id)?;
1061-
M::memory_written(extra, dest_alloc, dest, size * num_copies)?;
1062+
M::memory_written(extra, &mut dest_alloc.extra, dest, size * num_copies)?;
10621063
let dest_bytes = dest_alloc
10631064
.get_bytes_mut_ptr(&tcx, alloc_range(dest.offset, size * num_copies))
10641065
.as_mut_ptr();

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ symbols! {
132132
Borrow,
133133
Break,
134134
C,
135+
CStr,
135136
CString,
136137
Center,
137138
Clone,

Diff for: library/core/src/iter/traits/iterator.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,12 @@ pub trait Iterator {
18491849
///
18501850
/// The relative order of partitioned items is not maintained.
18511851
///
1852+
/// # Current implementation
1853+
/// Current algorithms tries finding the first element for which the predicate evaluates
1854+
/// to false, and the last element for which it evaluates to true and repeatedly swaps them.
1855+
///
1856+
/// Time Complexity: *O*(*N*)
1857+
///
18521858
/// See also [`is_partitioned()`] and [`partition()`].
18531859
///
18541860
/// [`is_partitioned()`]: Iterator::is_partitioned

Diff for: library/core/src/ptr/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,12 @@ pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
342342
/// ```
343343
/// use std::ptr;
344344
///
345-
/// let mut array = [0, 1, 2, 3];
345+
/// let mut array: [i32; 4] = [0, 1, 2, 3];
346+
///
347+
/// let array_ptr: *mut i32 = array.as_mut_ptr();
346348
///
347-
/// let x = array[0..].as_mut_ptr() as *mut [u32; 3]; // this is `array[0..3]`
348-
/// let y = array[1..].as_mut_ptr() as *mut [u32; 3]; // this is `array[1..4]`
349+
/// let x = array_ptr as *mut [i32; 3]; // this is `array[0..3]`
350+
/// let y = unsafe { array_ptr.add(1) } as *mut [i32; 3]; // this is `array[1..4]`
349351
///
350352
/// unsafe {
351353
/// ptr::swap(x, y);

Diff for: library/proc_macro/src/bridge/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ macro_rules! with_api {
107107
Literal {
108108
fn drop($self: $S::Literal);
109109
fn clone($self: &$S::Literal) -> $S::Literal;
110+
fn from_str(s: &str) -> Result<$S::Literal, ()>;
110111
fn debug_kind($self: &$S::Literal) -> String;
111112
fn symbol($self: &$S::Literal) -> String;
112113
fn suffix($self: &$S::Literal) -> Option<String>;
@@ -315,6 +316,19 @@ impl<T: Unmark> Unmark for Option<T> {
315316
}
316317
}
317318

319+
impl<T: Mark, E: Mark> Mark for Result<T, E> {
320+
type Unmarked = Result<T::Unmarked, E::Unmarked>;
321+
fn mark(unmarked: Self::Unmarked) -> Self {
322+
unmarked.map(T::mark).map_err(E::mark)
323+
}
324+
}
325+
impl<T: Unmark, E: Unmark> Unmark for Result<T, E> {
326+
type Unmarked = Result<T::Unmarked, E::Unmarked>;
327+
fn unmark(self) -> Self::Unmarked {
328+
self.map(T::unmark).map_err(E::unmark)
329+
}
330+
}
331+
318332
macro_rules! mark_noop {
319333
($($ty:ty),* $(,)?) => {
320334
$(

Diff for: library/proc_macro/src/lib.rs

+28
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ pub struct LexError {
9191
_inner: (),
9292
}
9393

94+
impl LexError {
95+
fn new() -> Self {
96+
LexError { _inner: () }
97+
}
98+
}
99+
94100
#[stable(feature = "proc_macro_lexerror_impls", since = "1.44.0")]
95101
impl fmt::Display for LexError {
96102
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -1171,6 +1177,28 @@ impl Literal {
11711177
}
11721178
}
11731179

1180+
/// Parse a single literal from its stringified representation.
1181+
///
1182+
/// In order to parse successfully, the input string must not contain anything
1183+
/// but the literal token. Specifically, it must not contain whitespace or
1184+
/// comments in addition to the literal.
1185+
///
1186+
/// The resulting literal token will have a `Span::call_site()` span.
1187+
///
1188+
/// NOTE: some errors may cause panics instead of returning `LexError`. We
1189+
/// reserve the right to change these errors into `LexError`s later.
1190+
#[stable(feature = "proc_macro_literal_parse", since = "1.54.0")]
1191+
impl FromStr for Literal {
1192+
type Err = LexError;
1193+
1194+
fn from_str(src: &str) -> Result<Self, LexError> {
1195+
match bridge::client::Literal::from_str(src) {
1196+
Ok(literal) => Ok(Literal(literal)),
1197+
Err(()) => Err(LexError::new()),
1198+
}
1199+
}
1200+
}
1201+
11741202
// N.B., the bridge only provides `to_string`, implement `fmt::Display`
11751203
// based on it (the reverse of the usual relationship between the two).
11761204
#[stable(feature = "proc_macro_lib", since = "1.15.0")]

Diff for: library/std/src/ffi/c_str.rs

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ pub struct CString {
185185
///
186186
/// [`&str`]: prim@str
187187
#[derive(Hash)]
188+
#[cfg_attr(not(test), rustc_diagnostic_item = "CStr")]
188189
#[stable(feature = "rust1", since = "1.0.0")]
189190
// FIXME:
190191
// `fn from` in `impl From<&CStr> for Box<CStr>` current implementation relies

Diff for: library/test/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub mod test {
4949
cli::{parse_opts, TestOpts},
5050
filter_tests,
5151
helpers::metrics::{Metric, MetricMap},
52-
options::{Options, RunIgnored, RunStrategy, ShouldPanic},
52+
options::{Concurrent, Options, RunIgnored, RunStrategy, ShouldPanic},
5353
run_test, test_main, test_main_static,
5454
test_result::{TestResult, TrFailed, TrFailedMsg, TrIgnored, TrOk},
5555
time::{TestExecTime, TestTimeOptions},

Diff for: src/librustdoc/html/render/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,11 @@ fn render_impl(
13521352
}
13531353
let w = if short_documented && trait_.is_some() { interesting } else { boring };
13541354

1355-
if !doc_buffer.is_empty() {
1356-
w.write_str("<details class=\"rustdoc-toggle\" open><summary>");
1355+
let toggled = !doc_buffer.is_empty();
1356+
if toggled {
1357+
let method_toggle_class =
1358+
if item_type == ItemType::Method { " method-toggle" } else { "" };
1359+
write!(w, "<details class=\"rustdoc-toggle{}\" open><summary>", method_toggle_class);
13571360
}
13581361
match *item.kind {
13591362
clean::MethodItem(..) | clean::TyMethodItem(_) => {
@@ -1453,7 +1456,7 @@ fn render_impl(
14531456
}
14541457

14551458
w.push_buffer(info_buffer);
1456-
if !doc_buffer.is_empty() {
1459+
if toggled {
14571460
w.write_str("</summary>");
14581461
w.push_buffer(doc_buffer);
14591462
w.push_str("</details>");

Diff for: src/librustdoc/html/static/main.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -924,24 +924,16 @@ function hideThemeButtonState() {
924924
});
925925
}
926926

927-
if (hideMethodDocs) {
928-
onEachLazy(document.getElementsByClassName("method"), function(e) {
929-
var toggle = e.parentNode;
930-
if (toggle) {
931-
toggle = toggle.parentNode;
932-
}
933-
if (toggle && toggle.tagName === "DETAILS") {
934-
toggle.open = false;
935-
}
936-
});
937-
}
938-
939927
onEachLazy(document.getElementsByTagName("details"), function (e) {
940928
var showLargeItem = !hideLargeItemContents && hasClass(e, "type-contents-toggle");
941929
var showImplementor = !hideImplementors && hasClass(e, "implementors-toggle");
942930
if (showLargeItem || showImplementor) {
943931
e.open = true;
944932
}
933+
if (hideMethodDocs && hasClass(e, "method-toggle")) {
934+
e.open = false;
935+
}
936+
945937
});
946938

947939
var currentType = document.getElementsByClassName("type-decl")[0];

Diff for: src/librustdoc/html/static/themes/ayu.css

+2-5
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,14 @@ pre, .rustdoc.source .example-wrap {
151151
color: #c5c5c5;
152152
}
153153

154-
.content a:hover {
154+
.search-results a:hover {
155155
background-color: #777;
156156
}
157157

158-
.content a:focus {
158+
.search-results a:focus {
159159
color: #000 !important;
160160
background-color: #c6afb3;
161161
}
162-
.content a:focus {
163-
color: #000 !important;
164-
}
165162
.search-results a {
166163
color: #0096cf;
167164
}

Diff for: src/librustdoc/html/static/themes/dark.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ pre, .rustdoc.source .example-wrap {
109109
color: #ddd;
110110
}
111111

112-
.content a:hover {
112+
.search-results a:hover {
113113
background-color: #777;
114114
}
115115

116-
.content a:focus {
116+
.search-results a:focus {
117117
color: #eee !important;
118118
background-color: #616161;
119119
}

Diff for: src/librustdoc/html/static/themes/light.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ pre, .rustdoc.source .example-wrap {
109109
color: #4E4C4C;
110110
}
111111

112-
.content a:hover {
112+
.search-results a:hover {
113113
background-color: #ddd;
114114
}
115115

116-
.content a:focus {
116+
.search-results a:focus {
117117
color: #000 !important;
118118
background-color: #ccc;
119119
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#![feature(proc_macro_span)]
1+
use proc_macro::{LineColumn, Punct, Spacing};
22

3-
use proc_macro::{LineColumn, Punct};
3+
pub fn test() {
4+
test_line_column_ord();
5+
test_punct_eq();
6+
}
47

5-
#[test]
68
fn test_line_column_ord() {
79
let line0_column0 = LineColumn { line: 0, column: 0 };
810
let line0_column1 = LineColumn { line: 0, column: 1 };
@@ -11,10 +13,9 @@ fn test_line_column_ord() {
1113
assert!(line0_column1 < line1_column0);
1214
}
1315

14-
#[test]
1516
fn test_punct_eq() {
16-
// Good enough if it typechecks, since proc_macro::Punct can't exist in a test.
17-
fn _check(punct: Punct) {
18-
let _ = punct == ':';
19-
}
17+
let colon_alone = Punct::new(':', Spacing::Alone);
18+
assert_eq!(colon_alone, ':');
19+
let colon_joint = Punct::new(':', Spacing::Joint);
20+
assert_eq!(colon_joint, ':');
2021
}

0 commit comments

Comments
 (0)