Skip to content
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

Rollup of 10 pull requests #64137

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a0ab5a3
Add Result::cloned{,_err} and Result::copied{,_err}
ksqsf Jul 31, 2019
c784720
Fix issue and impl
ksqsf Jul 31, 2019
5a36b0d
Make these methods public
ksqsf Jul 31, 2019
6c13081
Rename {copied,cloned} to {copied,cloned}_ok, and add {copied,cloned}…
ksqsf Jul 31, 2019
4b2f598
Revert "cloned/copied"
ksqsf Aug 1, 2019
9733f0d
Fix doc tests
ksqsf Aug 1, 2019
61e5286
Remove Err variants of cloned and copied
ksqsf Aug 2, 2019
b2b9b81
Account for doc comments coming from proc macros without spans
estebank Aug 27, 2019
7ed542d
add regression test
estebank Aug 27, 2019
820aa5b
Stabilize pin_into_inner in 1.39.0
ghedo Aug 28, 2019
5da1123
Update zx_time_t to an i64
tmandry Aug 30, 2019
403701f
Don't try to use /dev/null on Fuchsia
tmandry Aug 30, 2019
7bfa2be
fuchsia: Don't fail to spawn if no stdin exists
tmandry Aug 31, 2019
5f91ad0
fuchsia: Fix default environment behavior when spawning
tmandry Aug 31, 2019
3c4d157
Fix unlock ordering in SGX synchronization primitives
Aug 31, 2019
754a875
Add some more tests for underscore imports
matthewjasper Aug 31, 2019
b0bb301
Update xLTO compatibility table in rustc book.
michaelwoerister Sep 2, 2019
8c74eb7
Move path parsing earlier.
nnethercote Sep 3, 2019
23c76ff
Added warning around code with reference to uninit bytes
Sep 3, 2019
b03d3dc
Changed comment to better reflect std's exceptional situation
Sep 3, 2019
fa893a3
use TokenStream rather than &[TokenTree] for built-in macros
matklad Aug 31, 2019
6136495
use consistent naming for buildin expansion functions
matklad Sep 3, 2019
091e975
Rollup merge of #63166 - ksqsf:master, r=alexcrichton
Centril Sep 4, 2019
128baa4
Rollup merge of #63930 - estebank:rustdoc-ice, r=GuillaumeGomez
Centril Sep 4, 2019
820a380
Rollup merge of #63985 - ghedo:stabilize_pin_into_inner, r=alexcrichton
Centril Sep 4, 2019
e9160d0
Rollup merge of #64023 - tmandry:libstd-fuchsia-fixes, r=cramertj
Centril Sep 4, 2019
7d45eaf
Rollup merge of #64030 - jethrogb:jb/sgx-sync-issues, r=alexcrichton
Centril Sep 4, 2019
c334526
Rollup merge of #64041 - matklad:token-stream-tt, r=petrochenkov
Centril Sep 4, 2019
04bf85d
Rollup merge of #64043 - matthewjasper:underscore-import-tests, r=ale…
Centril Sep 4, 2019
2df6c7b
Rollup merge of #64092 - michaelwoerister:update-xlto-table-rustc-boo…
Centril Sep 4, 2019
7cd097e
Rollup merge of #64120 - nnethercote:move-path-parsing-earlier, r=pet…
Centril Sep 4, 2019
3a68bee
Rollup merge of #64123 - danielhenrymantilla:add_comment_about_uninit…
Centril Sep 4, 2019
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
1 change: 1 addition & 0 deletions src/doc/rustc/src/linker-plugin-lto.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ The following table shows known good combinations of toolchain versions.
| Rust 1.34 | ✗ | ✓ |
| Rust 1.35 | ✗ | ✓ |
| Rust 1.36 | ✗ | ✓ |
| Rust 1.37 | ✗ | ✓ |

Note that the compatibility policy for this feature might change in the future.
6 changes: 3 additions & 3 deletions src/doc/unstable-book/src/language-features/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ extern crate rustc;
extern crate rustc_driver;

use syntax::parse::token::{self, Token};
use syntax::tokenstream::TokenTree;
use syntax::tokenstream::{TokenTree, TokenStream};
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
use syntax_pos::Span;
use rustc_driver::plugin::Registry;

fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: TokenStream)
-> Box<dyn MacResult + 'static> {

static NUMERALS: &'static [(&'static str, usize)] = &[
Expand All @@ -78,7 +78,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
return DummyResult::any(sp);
}

let text = match args[0] {
let text = match args.into_trees().next().unwrap() {
TokenTree::Token(Token { kind: token::Ident(s, _), .. }) => s.to_string(),
_ => {
cx.span_err(sp, "argument should be a single identifier");
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
/// can ignore the pinning invariants when unwrapping it.
///
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
#[unstable(feature = "pin_into_inner", issue = "60245")]
#[stable(feature = "pin_into_inner", since = "1.39.0")]
#[inline(always)]
pub fn into_inner(pin: Pin<P>) -> P {
pin.pointer
Expand Down Expand Up @@ -569,7 +569,7 @@ impl<P: Deref> Pin<P> {
///
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
/// [`Pin::into_inner`]: #method.into_inner
#[unstable(feature = "pin_into_inner", issue = "60245")]
#[stable(feature = "pin_into_inner", since = "1.39.0")]
#[inline(always)]
pub unsafe fn into_inner_unchecked(pin: Pin<P>) -> P {
pin.pointer
Expand Down
81 changes: 81 additions & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,87 @@ impl<T, E> Result<T, E> {
}
}

impl<T: Copy, E> Result<&T, E> {
/// Maps a `Result<&T, E>` to a `Result<T, E>` by copying the contents of the
/// `Ok` part.
///
/// # Examples
///
/// ```
/// #![feature(result_copied)]
/// let val = 12;
/// let x: Result<&i32, i32> = Ok(&val);
/// assert_eq!(x, Ok(&12));
/// let copied = x.copied();
/// assert_eq!(copied, Ok(12));
/// ```
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
pub fn copied(self) -> Result<T, E> {
self.map(|&t| t)
}
}

impl<T: Copy, E> Result<&mut T, E> {
/// Maps a `Result<&mut T, E>` to a `Result<T, E>` by copying the contents of the
/// `Ok` part.
///
/// # Examples
///
/// ```
/// #![feature(result_copied)]
/// let mut val = 12;
/// let x: Result<&mut i32, i32> = Ok(&mut val);
/// assert_eq!(x, Ok(&mut 12));
/// let copied = x.copied();
/// assert_eq!(copied, Ok(12));
/// ```
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
pub fn copied(self) -> Result<T, E> {
self.map(|&mut t| t)
}
}

impl<T: Clone, E> Result<&T, E> {
/// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
/// `Ok` part.
///
/// # Examples
///
/// ```
/// #![feature(result_cloned)]
/// let val = 12;
/// let x: Result<&i32, i32> = Ok(&val);
/// assert_eq!(x, Ok(&12));
/// let cloned = x.cloned();
/// assert_eq!(cloned, Ok(12));
/// ```
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
pub fn cloned(self) -> Result<T, E> {
self.map(|t| t.clone())
}
}

impl<T: Clone, E> Result<&mut T, E> {
/// Maps a `Result<&mut T, E>` to a `Result<T, E>` by cloning the contents of the
/// `Ok` part.
///
/// # Examples
///
/// ```
/// #![feature(result_cloned)]
/// let mut val = 12;
/// let x: Result<&mut i32, i32> = Ok(&mut val);
/// assert_eq!(x, Ok(&mut 12));
/// let cloned = x.cloned();
/// assert_eq!(cloned, Ok(12));
/// ```
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
pub fn cloned(self) -> Result<T, E> {
self.map(|t| t.clone())
}
}


impl<T, E: fmt::Debug> Result<T, E> {
/// Unwraps a result, yielding the content of an [`Ok`].
///
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ impl EncodeContext<'tcx> {
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id);
Entry {
kind: EntryKind::MacroDef(self.lazy(MacroDef {
body: pprust::tokens_to_string(macro_def.body.clone()),
body: pprust::tts_to_string(macro_def.body.clone()),
legacy: macro_def.legacy,
})),
visibility: self.lazy(ty::Visibility::Public),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/check_code_block_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
// We couldn't calculate the span of the markdown block that had the error, so our
// diagnostics are going to be a bit lacking.
let mut diag = self.cx.sess().struct_span_warn(
super::span_of_attrs(&item.attrs),
super::span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
"doc comment contains an invalid Rust code block",
);

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ fn resolution_failure(
}
};
let attrs = &item.attrs;
let sp = span_of_attrs(attrs);
let sp = span_of_attrs(attrs).unwrap_or(item.source.span());

let mut diag = cx.tcx.struct_span_lint_hir(
lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
Expand Down Expand Up @@ -517,7 +517,7 @@ fn ambiguity_error(
}
};
let attrs = &item.attrs;
let sp = span_of_attrs(attrs);
let sp = span_of_attrs(attrs).unwrap_or(item.source.span());

let mut msg = format!("`{}` is ", path_str);

Expand Down
21 changes: 11 additions & 10 deletions src/librustdoc/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ pub fn look_for_tests<'tcx>(
find_testable_code(&dox, &mut tests, ErrorCodes::No);

if check_missing_code == true && tests.found_tests == 0 {
let sp = span_of_attrs(&item.attrs).substitute_dummy(item.source.span());
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
let mut diag = cx.tcx.struct_span_lint_hir(
lint::builtin::MISSING_DOC_CODE_EXAMPLES,
hir_id,
Expand All @@ -352,20 +352,23 @@ pub fn look_for_tests<'tcx>(
let mut diag = cx.tcx.struct_span_lint_hir(
lint::builtin::PRIVATE_DOC_TESTS,
hir_id,
span_of_attrs(&item.attrs),
span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
"Documentation test in private item");
diag.emit();
}
}

/// Returns a span encompassing all the given attributes.
crate fn span_of_attrs(attrs: &clean::Attributes) -> Span {
crate fn span_of_attrs(attrs: &clean::Attributes) -> Option<Span> {
if attrs.doc_strings.is_empty() {
return DUMMY_SP;
return None;
}
let start = attrs.doc_strings[0].span();
if start == DUMMY_SP {
return None;
}
let end = attrs.doc_strings.last().expect("No doc strings provided").span();
start.to(end)
Some(start.to(end))
}

/// Attempts to match a range of bytes from parsed markdown to a `Span` in the source code.
Expand All @@ -391,7 +394,7 @@ crate fn source_span_for_markdown_range(
let snippet = cx
.sess()
.source_map()
.span_to_snippet(span_of_attrs(attrs))
.span_to_snippet(span_of_attrs(attrs)?)
.ok()?;

let starting_line = markdown[..md_range.start].matches('\n').count();
Expand Down Expand Up @@ -441,10 +444,8 @@ crate fn source_span_for_markdown_range(
}
}

let sp = span_of_attrs(attrs).from_inner(InnerSpan::new(
Some(span_of_attrs(attrs)?.from_inner(InnerSpan::new(
md_range.start + start_bytes,
md_range.end + start_bytes + end_bytes,
));

Some(sp)
)))
}
8 changes: 8 additions & 0 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ where
loop {
if g.len == g.buf.len() {
unsafe {
// FIXME(danielhenrymantilla): #42788
//
// - This creates a (mut) reference to a slice of
// _uninitialized_ integers, which is **undefined behavior**
//
// - Only the standard library gets to soundly "ignore" this,
// based on its privileged knowledge of unstable rustc
// internals;
g.buf.reserve(reservation_size(r));
let capacity = g.buf.capacity();
g.buf.set_len(capacity);
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/sys/sgx/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ impl Condvar {

pub unsafe fn wait(&self, mutex: &Mutex) {
let guard = self.inner.lock();
mutex.unlock();
WaitQueue::wait(guard);
WaitQueue::wait(guard, || mutex.unlock());
mutex.lock()
}

Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/sgx/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Mutex {
let mut guard = self.inner.lock();
if *guard.lock_var() {
// Another thread has the lock, wait
WaitQueue::wait(guard)
WaitQueue::wait(guard, ||{})
// Another thread has passed the lock to us
} else {
// We are just now obtaining the lock
Expand Down Expand Up @@ -83,7 +83,7 @@ impl ReentrantMutex {
match guard.lock_var().owner {
Some(tcs) if tcs != thread::current() => {
// Another thread has the lock, wait
WaitQueue::wait(guard);
WaitQueue::wait(guard, ||{});
// Another thread has passed the lock to us
},
_ => {
Expand Down
34 changes: 20 additions & 14 deletions src/libstd/sys/sgx/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl RWLock {
if *wguard.lock_var() || !wguard.queue_empty() {
// Another thread has or is waiting for the write lock, wait
drop(wguard);
WaitQueue::wait(rguard);
WaitQueue::wait(rguard, ||{});
// Another thread has passed the lock to us
} else {
// No waiting writers, acquire the read lock
Expand Down Expand Up @@ -62,7 +62,7 @@ impl RWLock {
if *wguard.lock_var() || rguard.lock_var().is_some() {
// Another thread has the lock, wait
drop(rguard);
WaitQueue::wait(wguard);
WaitQueue::wait(wguard, ||{});
// Another thread has passed the lock to us
} else {
// We are just now obtaining the lock
Expand Down Expand Up @@ -97,6 +97,7 @@ impl RWLock {
if let Ok(mut wguard) = WaitQueue::notify_one(wguard) {
// A writer was waiting, pass the lock
*wguard.lock_var_mut() = true;
wguard.drop_after(rguard);
} else {
// No writers were waiting, the lock is released
rtassert!(rguard.queue_empty());
Expand All @@ -117,21 +118,26 @@ impl RWLock {
rguard: SpinMutexGuard<'_, WaitVariable<Option<NonZeroUsize>>>,
wguard: SpinMutexGuard<'_, WaitVariable<bool>>,
) {
if let Err(mut wguard) = WaitQueue::notify_one(wguard) {
// No writers waiting, release the write lock
*wguard.lock_var_mut() = false;
if let Ok(mut rguard) = WaitQueue::notify_all(rguard) {
// One or more readers were waiting, pass the lock to them
if let NotifiedTcs::All { count } = rguard.notified_tcs() {
*rguard.lock_var_mut() = Some(count)
match WaitQueue::notify_one(wguard) {
Err(mut wguard) => {
// No writers waiting, release the write lock
*wguard.lock_var_mut() = false;
if let Ok(mut rguard) = WaitQueue::notify_all(rguard) {
// One or more readers were waiting, pass the lock to them
if let NotifiedTcs::All { count } = rguard.notified_tcs() {
*rguard.lock_var_mut() = Some(count)
} else {
unreachable!() // called notify_all
}
rguard.drop_after(wguard);
} else {
unreachable!() // called notify_all
// No readers waiting, the lock is released
}
} else {
// No readers waiting, the lock is released
},
Ok(wguard) => {
// There was a thread waiting for write, just pass the lock
wguard.drop_after(rguard);
}
} else {
// There was a thread waiting for write, just pass the lock
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/libstd/sys/sgx/waitqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ impl<'a, T> WaitGuard<'a, T> {
pub fn notified_tcs(&self) -> NotifiedTcs {
self.notified_tcs
}

/// Drop this `WaitGuard`, after dropping another `guard`.
pub fn drop_after<U>(self, guard: U) {
drop(guard);
drop(self);
}
}

impl<'a, T> Deref for WaitGuard<'a, T> {
Expand Down Expand Up @@ -140,7 +146,7 @@ impl WaitQueue {
/// until a wakeup event.
///
/// This function does not return until this thread has been awoken.
pub fn wait<T>(mut guard: SpinMutexGuard<'_, WaitVariable<T>>) {
pub fn wait<T, F: FnOnce()>(mut guard: SpinMutexGuard<'_, WaitVariable<T>>, before_wait: F) {
// very unsafe: check requirements of UnsafeList::push
unsafe {
let mut entry = UnsafeListEntry::new(SpinMutex::new(WaitEntry {
Expand All @@ -149,6 +155,7 @@ impl WaitQueue {
}));
let entry = guard.queue.inner.push(&mut entry);
drop(guard);
before_wait();
while !entry.lock().wake {
// don't panic, this would invalidate `entry` during unwinding
let eventset = rtunwrap!(Ok, usercalls::wait(EV_UNPARK, WAIT_INDEFINITE));
Expand Down Expand Up @@ -545,7 +552,7 @@ mod tests {
assert!(WaitQueue::notify_one(wq2.lock()).is_ok());
});

WaitQueue::wait(locked);
WaitQueue::wait(locked, ||{});

t1.join().unwrap();
}
Expand Down
Loading