Skip to content

Rollup of 8 pull requests #85486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
67e8f12
Expose `Concurrent` (private type in public i'face)
eggyal May 14, 2021
1960503
adding time complexity for partition_in_place iter method
May 15, 2021
85e4177
adding algorithm explanation for partition_in_place iter method and b…
May 18, 2021
d730cc6
Add diagnostic item to `CStr`
mgacek8 May 18, 2021
24480de
Add method-toggle to <details> for methods.
jsha May 10, 2021
f9752b4
Fix UB in documented example for `ptr::swap`
steffahn May 19, 2021
ec32bcf
Fix invalid CSS rules for a:hover
GuillaumeGomez May 19, 2021
50a9f00
CTFE Machine: do not expose Allocation
RalfJung May 19, 2021
39441bb
Make a ui test to take the role of libproc_macro #[test] tests
dtolnay Apr 29, 2021
3c16c0e
Move proc_macro tests to ui test
dtolnay Apr 29, 2021
faad7e2
Make a more meaningful test for Punct eq
dtolnay Apr 29, 2021
965bce4
Add proc macro Literal parse test
dtolnay Apr 29, 2021
34585cb
impl FromStr for proc_macro::Literal
dtolnay Apr 29, 2021
a1ac372
Rollup merge of #84717 - dtolnay:literalfromstr, r=petrochenkov
RalfJung May 19, 2021
4217430
Rollup merge of #85169 - jsha:hoist-classes, r=GuillaumeGomez
RalfJung May 19, 2021
a552b5b
Rollup merge of #85287 - eggyal:expose-test-concurrent, r=m-ou-se
RalfJung May 19, 2021
c1c4cd5
Rollup merge of #85315 - satylogin:master, r=yaahc
RalfJung May 19, 2021
1207b7f
Rollup merge of #85439 - mgacek8:add_diagnostic_item_to_CStr_type, r=…
RalfJung May 19, 2021
2065c4b
Rollup merge of #85464 - steffahn:fix_ub_in_ptr_swap_docs, r=dtolnay
RalfJung May 19, 2021
b2becf0
Rollup merge of #85470 - GuillaumeGomez:fix-css-rules, r=jsha
RalfJung May 19, 2021
9fa15ff
Rollup merge of #85472 - RalfJung:allocation, r=oli-obk
RalfJung May 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::base::{ExtCtxt, ResolverExpand};

use rustc_ast as ast;
use rustc_ast::token;
use rustc_ast::token::Nonterminal;
use rustc_ast::token::NtIdent;
use rustc_ast::token::{self, Nonterminal, NtIdent, TokenKind};
use rustc_ast::tokenstream::{self, CanSynthesizeMissingTokens};
use rustc_ast::tokenstream::{DelimSpan, Spacing::*, TokenStream, TreeAndSpacing};
use rustc_ast_pretty::pprust;
Expand Down Expand Up @@ -541,6 +539,33 @@ impl server::Ident for Rustc<'_> {
}

impl server::Literal for Rustc<'_> {
fn from_str(&mut self, s: &str) -> Result<Self::Literal, ()> {
let override_span = None;
let stream = parse_stream_from_source_str(
FileName::proc_macro_source_code(s),
s.to_owned(),
self.sess,
override_span,
);
if stream.len() != 1 {
return Err(());
}
let tree = stream.into_trees().next().unwrap();
let token = match tree {
tokenstream::TokenTree::Token(token) => token,
tokenstream::TokenTree::Delimited { .. } => return Err(()),
};
let span_data = token.span.data();
if (span_data.hi.0 - span_data.lo.0) as usize != s.len() {
// There is a comment or whitespace adjacent to the literal.
return Err(());
}
let lit = match token.kind {
TokenKind::Literal(lit) => lit,
_ => return Err(()),
};
Ok(Literal { lit, span: self.call_site })
}
fn debug_kind(&mut self, literal: &Self::Literal) -> String {
format!("{:?}", literal.lit.kind)
}
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_mir/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
#[inline(always)]
fn memory_read(
_memory_extra: &Self::MemoryExtra,
_alloc: &Allocation<Self::PointerTag, Self::AllocExtra>,
_alloc_extra: &Self::AllocExtra,
_ptr: Pointer<Self::PointerTag>,
_size: Size,
) -> InterpResult<'tcx> {
Expand All @@ -324,7 +324,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
#[inline(always)]
fn memory_written(
_memory_extra: &mut Self::MemoryExtra,
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
_alloc_extra: &mut Self::AllocExtra,
_ptr: Pointer<Self::PointerTag>,
_size: Size,
) -> InterpResult<'tcx> {
Expand All @@ -335,8 +335,9 @@ pub trait Machine<'mir, 'tcx>: Sized {
#[inline(always)]
fn memory_deallocated(
_memory_extra: &mut Self::MemoryExtra,
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
_alloc_extra: &mut Self::AllocExtra,
_ptr: Pointer<Self::PointerTag>,
_size: Size,
) -> InterpResult<'tcx> {
Ok(())
}
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_mir/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
}

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

// Don't forget to remember size and align of this now-dead allocation
let old = self.dead_alloc_map.insert(ptr.alloc_id, (alloc.size(), alloc.align));
let old = self.dead_alloc_map.insert(ptr.alloc_id, (size, alloc.align));
if old.is_some() {
bug!("Nothing can be deallocated twice");
}
Expand Down Expand Up @@ -591,7 +592,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
},
)?;
if let Some((ptr, alloc)) = ptr_and_alloc {
M::memory_read(&self.extra, alloc, ptr, size)?;
M::memory_read(&self.extra, &alloc.extra, ptr, size)?;
let range = alloc_range(ptr.offset, size);
Ok(Some(AllocRef { alloc, range, tcx: self.tcx, alloc_id: ptr.alloc_id }))
} else {
Expand Down Expand Up @@ -660,7 +661,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
// FIXME: can we somehow avoid looking up the allocation twice here?
// We cannot call `get_raw_mut` inside `check_and_deref_ptr` as that would duplicate `&mut self`.
let (alloc, extra) = self.get_raw_mut(ptr.alloc_id)?;
M::memory_written(extra, alloc, ptr, size)?;
M::memory_written(extra, &mut alloc.extra, ptr, size)?;
let range = alloc_range(ptr.offset, size);
Ok(Some(AllocRefMut { alloc, range, tcx, alloc_id: ptr.alloc_id }))
} else {
Expand Down Expand Up @@ -1029,7 +1030,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
Some(src_ptr) => src_ptr,
};
let src_alloc = self.get_raw(src.alloc_id)?;
M::memory_read(&self.extra, src_alloc, src, size)?;
M::memory_read(&self.extra, &src_alloc.extra, src, size)?;
// We need the `dest` ptr for the next operation, so we get it now.
// We already did the source checks and called the hooks so we are good to return early.
let dest = match dest {
Expand Down Expand Up @@ -1058,7 +1059,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {

// Destination alloc preparations and access hooks.
let (dest_alloc, extra) = self.get_raw_mut(dest.alloc_id)?;
M::memory_written(extra, dest_alloc, dest, size * num_copies)?;
M::memory_written(extra, &mut dest_alloc.extra, dest, size * num_copies)?;
let dest_bytes = dest_alloc
.get_bytes_mut_ptr(&tcx, alloc_range(dest.offset, size * num_copies))
.as_mut_ptr();
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ symbols! {
Borrow,
Break,
C,
CStr,
CString,
Center,
Clone,
Expand Down
6 changes: 6 additions & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,12 @@ pub trait Iterator {
///
/// The relative order of partitioned items is not maintained.
///
/// # Current implementation
/// Current algorithms tries finding the first element for which the predicate evaluates
/// to false, and the last element for which it evaluates to true and repeatedly swaps them.
///
/// Time Complexity: *O*(*N*)
///
/// See also [`is_partitioned()`] and [`partition()`].
///
/// [`is_partitioned()`]: Iterator::is_partitioned
Expand Down
8 changes: 5 additions & 3 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,12 @@ pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
/// ```
/// use std::ptr;
///
/// let mut array = [0, 1, 2, 3];
/// let mut array: [i32; 4] = [0, 1, 2, 3];
///
/// let array_ptr: *mut i32 = array.as_mut_ptr();
///
/// let x = array[0..].as_mut_ptr() as *mut [u32; 3]; // this is `array[0..3]`
/// let y = array[1..].as_mut_ptr() as *mut [u32; 3]; // this is `array[1..4]`
/// let x = array_ptr as *mut [i32; 3]; // this is `array[0..3]`
/// let y = unsafe { array_ptr.add(1) } as *mut [i32; 3]; // this is `array[1..4]`
///
/// unsafe {
/// ptr::swap(x, y);
Expand Down
14 changes: 14 additions & 0 deletions library/proc_macro/src/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ macro_rules! with_api {
Literal {
fn drop($self: $S::Literal);
fn clone($self: &$S::Literal) -> $S::Literal;
fn from_str(s: &str) -> Result<$S::Literal, ()>;
fn debug_kind($self: &$S::Literal) -> String;
fn symbol($self: &$S::Literal) -> String;
fn suffix($self: &$S::Literal) -> Option<String>;
Expand Down Expand Up @@ -315,6 +316,19 @@ impl<T: Unmark> Unmark for Option<T> {
}
}

impl<T: Mark, E: Mark> Mark for Result<T, E> {
type Unmarked = Result<T::Unmarked, E::Unmarked>;
fn mark(unmarked: Self::Unmarked) -> Self {
unmarked.map(T::mark).map_err(E::mark)
}
}
impl<T: Unmark, E: Unmark> Unmark for Result<T, E> {
type Unmarked = Result<T::Unmarked, E::Unmarked>;
fn unmark(self) -> Self::Unmarked {
self.map(T::unmark).map_err(E::unmark)
}
}

macro_rules! mark_noop {
($($ty:ty),* $(,)?) => {
$(
Expand Down
28 changes: 28 additions & 0 deletions library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ pub struct LexError {
_inner: (),
}

impl LexError {
fn new() -> Self {
LexError { _inner: () }
}
}

#[stable(feature = "proc_macro_lexerror_impls", since = "1.44.0")]
impl fmt::Display for LexError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -1171,6 +1177,28 @@ impl Literal {
}
}

/// Parse a single literal from its stringified representation.
///
/// In order to parse successfully, the input string must not contain anything
/// but the literal token. Specifically, it must not contain whitespace or
/// comments in addition to the literal.
///
/// The resulting literal token will have a `Span::call_site()` span.
///
/// NOTE: some errors may cause panics instead of returning `LexError`. We
/// reserve the right to change these errors into `LexError`s later.
#[stable(feature = "proc_macro_literal_parse", since = "1.54.0")]
impl FromStr for Literal {
type Err = LexError;

fn from_str(src: &str) -> Result<Self, LexError> {
match bridge::client::Literal::from_str(src) {
Ok(literal) => Ok(Literal(literal)),
Err(()) => Err(LexError::new()),
}
}
}

// N.B., the bridge only provides `to_string`, implement `fmt::Display`
// based on it (the reverse of the usual relationship between the two).
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
Expand Down
1 change: 1 addition & 0 deletions library/std/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ pub struct CString {
///
/// [`&str`]: prim@str
#[derive(Hash)]
#[cfg_attr(not(test), rustc_diagnostic_item = "CStr")]
#[stable(feature = "rust1", since = "1.0.0")]
// FIXME:
// `fn from` in `impl From<&CStr> for Box<CStr>` current implementation relies
Expand Down
2 changes: 1 addition & 1 deletion library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub mod test {
cli::{parse_opts, TestOpts},
filter_tests,
helpers::metrics::{Metric, MetricMap},
options::{Options, RunIgnored, RunStrategy, ShouldPanic},
options::{Concurrent, Options, RunIgnored, RunStrategy, ShouldPanic},
run_test, test_main, test_main_static,
test_result::{TestResult, TrFailed, TrFailedMsg, TrIgnored, TrOk},
time::{TestExecTime, TestTimeOptions},
Expand Down
9 changes: 6 additions & 3 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,8 +1352,11 @@ fn render_impl(
}
let w = if short_documented && trait_.is_some() { interesting } else { boring };

if !doc_buffer.is_empty() {
w.write_str("<details class=\"rustdoc-toggle\" open><summary>");
let toggled = !doc_buffer.is_empty();
if toggled {
let method_toggle_class =
if item_type == ItemType::Method { " method-toggle" } else { "" };
write!(w, "<details class=\"rustdoc-toggle{}\" open><summary>", method_toggle_class);
}
match *item.kind {
clean::MethodItem(..) | clean::TyMethodItem(_) => {
Expand Down Expand Up @@ -1453,7 +1456,7 @@ fn render_impl(
}

w.push_buffer(info_buffer);
if !doc_buffer.is_empty() {
if toggled {
w.write_str("</summary>");
w.push_buffer(doc_buffer);
w.push_str("</details>");
Expand Down
16 changes: 4 additions & 12 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,24 +924,16 @@ function hideThemeButtonState() {
});
}

if (hideMethodDocs) {
onEachLazy(document.getElementsByClassName("method"), function(e) {
var toggle = e.parentNode;
if (toggle) {
toggle = toggle.parentNode;
}
if (toggle && toggle.tagName === "DETAILS") {
toggle.open = false;
}
});
}

onEachLazy(document.getElementsByTagName("details"), function (e) {
var showLargeItem = !hideLargeItemContents && hasClass(e, "type-contents-toggle");
var showImplementor = !hideImplementors && hasClass(e, "implementors-toggle");
if (showLargeItem || showImplementor) {
e.open = true;
}
if (hideMethodDocs && hasClass(e, "method-toggle")) {
e.open = false;
}

});

var currentType = document.getElementsByClassName("type-decl")[0];
Expand Down
7 changes: 2 additions & 5 deletions src/librustdoc/html/static/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,14 @@ pre, .rustdoc.source .example-wrap {
color: #c5c5c5;
}

.content a:hover {
.search-results a:hover {
background-color: #777;
}

.content a:focus {
.search-results a:focus {
color: #000 !important;
background-color: #c6afb3;
}
.content a:focus {
color: #000 !important;
}
.search-results a {
color: #0096cf;
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ pre, .rustdoc.source .example-wrap {
color: #ddd;
}

.content a:hover {
.search-results a:hover {
background-color: #777;
}

.content a:focus {
.search-results a:focus {
color: #eee !important;
background-color: #616161;
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ pre, .rustdoc.source .example-wrap {
color: #4E4C4C;
}

.content a:hover {
.search-results a:hover {
background-color: #ddd;
}

.content a:focus {
.search-results a:focus {
color: #000 !important;
background-color: #ccc;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![feature(proc_macro_span)]
use proc_macro::{LineColumn, Punct, Spacing};

use proc_macro::{LineColumn, Punct};
pub fn test() {
test_line_column_ord();
test_punct_eq();
}

#[test]
fn test_line_column_ord() {
let line0_column0 = LineColumn { line: 0, column: 0 };
let line0_column1 = LineColumn { line: 0, column: 1 };
Expand All @@ -11,10 +13,9 @@ fn test_line_column_ord() {
assert!(line0_column1 < line1_column0);
}

#[test]
fn test_punct_eq() {
// Good enough if it typechecks, since proc_macro::Punct can't exist in a test.
fn _check(punct: Punct) {
let _ = punct == ':';
}
let colon_alone = Punct::new(':', Spacing::Alone);
assert_eq!(colon_alone, ':');
let colon_joint = Punct::new(':', Spacing::Joint);
assert_eq!(colon_joint, ':');
}
Loading