Skip to content

Commit 4e99d1b

Browse files
committed
Auto merge of #64137 - Centril:rollup-4am55q3, r=Centril
Rollup of 10 pull requests Successful merges: - #63166 (Add Result::cloned{,_err} and Result::copied{,_err}) - #63930 (Account for doc comments coming from proc macros without spans) - #63985 (Stabilize pin_into_inner in 1.39.0) - #64023 (libstd fuchsia fixes) - #64030 (Fix unlock ordering in SGX synchronization primitives) - #64041 (use TokenStream rather than &[TokenTree] for built-in macros) - #64043 (Add some more tests for underscore imports) - #64092 (Update xLTO compatibility table in rustc book.) - #64120 (Move path parsing earlier) - #64123 (Added warning around code with reference to uninit bytes) Failed merges: r? @ghost
2 parents b9de4ef + 3a68bee commit 4e99d1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+447
-209
lines changed

src/doc/rustc/src/linker-plugin-lto.md

+1
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,6 @@ The following table shows known good combinations of toolchain versions.
105105
| Rust 1.34 |||
106106
| Rust 1.35 |||
107107
| Rust 1.36 |||
108+
| Rust 1.37 |||
108109

109110
Note that the compatibility policy for this feature might change in the future.

src/doc/unstable-book/src/language-features/plugin.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ extern crate rustc;
5757
extern crate rustc_driver;
5858
5959
use syntax::parse::token::{self, Token};
60-
use syntax::tokenstream::TokenTree;
60+
use syntax::tokenstream::{TokenTree, TokenStream};
6161
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
6262
use syntax_pos::Span;
6363
use rustc_driver::plugin::Registry;
6464
65-
fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
65+
fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: TokenStream)
6666
-> Box<dyn MacResult + 'static> {
6767
6868
static NUMERALS: &'static [(&'static str, usize)] = &[
@@ -78,7 +78,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
7878
return DummyResult::any(sp);
7979
}
8080
81-
let text = match args[0] {
81+
let text = match args.into_trees().next().unwrap() {
8282
TokenTree::Token(Token { kind: token::Ident(s, _), .. }) => s.to_string(),
8383
_ => {
8484
cx.span_err(sp, "argument should be a single identifier");

src/libcore/pin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
462462
/// can ignore the pinning invariants when unwrapping it.
463463
///
464464
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
465-
#[unstable(feature = "pin_into_inner", issue = "60245")]
465+
#[stable(feature = "pin_into_inner", since = "1.39.0")]
466466
#[inline(always)]
467467
pub fn into_inner(pin: Pin<P>) -> P {
468468
pin.pointer
@@ -569,7 +569,7 @@ impl<P: Deref> Pin<P> {
569569
///
570570
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
571571
/// [`Pin::into_inner`]: #method.into_inner
572-
#[unstable(feature = "pin_into_inner", issue = "60245")]
572+
#[stable(feature = "pin_into_inner", since = "1.39.0")]
573573
#[inline(always)]
574574
pub unsafe fn into_inner_unchecked(pin: Pin<P>) -> P {
575575
pin.pointer

src/libcore/result.rs

+81
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,87 @@ impl<T, E> Result<T, E> {
820820
}
821821
}
822822

823+
impl<T: Copy, E> Result<&T, E> {
824+
/// Maps a `Result<&T, E>` to a `Result<T, E>` by copying the contents of the
825+
/// `Ok` part.
826+
///
827+
/// # Examples
828+
///
829+
/// ```
830+
/// #![feature(result_copied)]
831+
/// let val = 12;
832+
/// let x: Result<&i32, i32> = Ok(&val);
833+
/// assert_eq!(x, Ok(&12));
834+
/// let copied = x.copied();
835+
/// assert_eq!(copied, Ok(12));
836+
/// ```
837+
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
838+
pub fn copied(self) -> Result<T, E> {
839+
self.map(|&t| t)
840+
}
841+
}
842+
843+
impl<T: Copy, E> Result<&mut T, E> {
844+
/// Maps a `Result<&mut T, E>` to a `Result<T, E>` by copying the contents of the
845+
/// `Ok` part.
846+
///
847+
/// # Examples
848+
///
849+
/// ```
850+
/// #![feature(result_copied)]
851+
/// let mut val = 12;
852+
/// let x: Result<&mut i32, i32> = Ok(&mut val);
853+
/// assert_eq!(x, Ok(&mut 12));
854+
/// let copied = x.copied();
855+
/// assert_eq!(copied, Ok(12));
856+
/// ```
857+
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
858+
pub fn copied(self) -> Result<T, E> {
859+
self.map(|&mut t| t)
860+
}
861+
}
862+
863+
impl<T: Clone, E> Result<&T, E> {
864+
/// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
865+
/// `Ok` part.
866+
///
867+
/// # Examples
868+
///
869+
/// ```
870+
/// #![feature(result_cloned)]
871+
/// let val = 12;
872+
/// let x: Result<&i32, i32> = Ok(&val);
873+
/// assert_eq!(x, Ok(&12));
874+
/// let cloned = x.cloned();
875+
/// assert_eq!(cloned, Ok(12));
876+
/// ```
877+
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
878+
pub fn cloned(self) -> Result<T, E> {
879+
self.map(|t| t.clone())
880+
}
881+
}
882+
883+
impl<T: Clone, E> Result<&mut T, E> {
884+
/// Maps a `Result<&mut T, E>` to a `Result<T, E>` by cloning the contents of the
885+
/// `Ok` part.
886+
///
887+
/// # Examples
888+
///
889+
/// ```
890+
/// #![feature(result_cloned)]
891+
/// let mut val = 12;
892+
/// let x: Result<&mut i32, i32> = Ok(&mut val);
893+
/// assert_eq!(x, Ok(&mut 12));
894+
/// let cloned = x.cloned();
895+
/// assert_eq!(cloned, Ok(12));
896+
/// ```
897+
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
898+
pub fn cloned(self) -> Result<T, E> {
899+
self.map(|t| t.clone())
900+
}
901+
}
902+
903+
823904
impl<T, E: fmt::Debug> Result<T, E> {
824905
/// Unwraps a result, yielding the content of an [`Ok`].
825906
///

src/librustc_metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ impl EncodeContext<'tcx> {
13541354
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id);
13551355
Entry {
13561356
kind: EntryKind::MacroDef(self.lazy(MacroDef {
1357-
body: pprust::tokens_to_string(macro_def.body.clone()),
1357+
body: pprust::tts_to_string(macro_def.body.clone()),
13581358
legacy: macro_def.legacy,
13591359
})),
13601360
visibility: self.lazy(ty::Visibility::Public),

src/librustdoc/passes/check_code_block_syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
8181
// We couldn't calculate the span of the markdown block that had the error, so our
8282
// diagnostics are going to be a bit lacking.
8383
let mut diag = self.cx.sess().struct_span_warn(
84-
super::span_of_attrs(&item.attrs),
84+
super::span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
8585
"doc comment contains an invalid Rust code block",
8686
);
8787

src/librustdoc/passes/collect_intra_doc_links.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ fn resolution_failure(
465465
}
466466
};
467467
let attrs = &item.attrs;
468-
let sp = span_of_attrs(attrs);
468+
let sp = span_of_attrs(attrs).unwrap_or(item.source.span());
469469

470470
let mut diag = cx.tcx.struct_span_lint_hir(
471471
lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
@@ -517,7 +517,7 @@ fn ambiguity_error(
517517
}
518518
};
519519
let attrs = &item.attrs;
520-
let sp = span_of_attrs(attrs);
520+
let sp = span_of_attrs(attrs).unwrap_or(item.source.span());
521521

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

src/librustdoc/passes/mod.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub fn look_for_tests<'tcx>(
339339
find_testable_code(&dox, &mut tests, ErrorCodes::No);
340340

341341
if check_missing_code == true && tests.found_tests == 0 {
342-
let sp = span_of_attrs(&item.attrs).substitute_dummy(item.source.span());
342+
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
343343
let mut diag = cx.tcx.struct_span_lint_hir(
344344
lint::builtin::MISSING_DOC_CODE_EXAMPLES,
345345
hir_id,
@@ -352,20 +352,23 @@ pub fn look_for_tests<'tcx>(
352352
let mut diag = cx.tcx.struct_span_lint_hir(
353353
lint::builtin::PRIVATE_DOC_TESTS,
354354
hir_id,
355-
span_of_attrs(&item.attrs),
355+
span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
356356
"Documentation test in private item");
357357
diag.emit();
358358
}
359359
}
360360

361361
/// Returns a span encompassing all the given attributes.
362-
crate fn span_of_attrs(attrs: &clean::Attributes) -> Span {
362+
crate fn span_of_attrs(attrs: &clean::Attributes) -> Option<Span> {
363363
if attrs.doc_strings.is_empty() {
364-
return DUMMY_SP;
364+
return None;
365365
}
366366
let start = attrs.doc_strings[0].span();
367+
if start == DUMMY_SP {
368+
return None;
369+
}
367370
let end = attrs.doc_strings.last().expect("No doc strings provided").span();
368-
start.to(end)
371+
Some(start.to(end))
369372
}
370373

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

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

444-
let sp = span_of_attrs(attrs).from_inner(InnerSpan::new(
447+
Some(span_of_attrs(attrs)?.from_inner(InnerSpan::new(
445448
md_range.start + start_bytes,
446449
md_range.end + start_bytes + end_bytes,
447-
));
448-
449-
Some(sp)
450+
)))
450451
}

src/libstd/io/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,14 @@ where
371371
loop {
372372
if g.len == g.buf.len() {
373373
unsafe {
374+
// FIXME(danielhenrymantilla): #42788
375+
//
376+
// - This creates a (mut) reference to a slice of
377+
// _uninitialized_ integers, which is **undefined behavior**
378+
//
379+
// - Only the standard library gets to soundly "ignore" this,
380+
// based on its privileged knowledge of unstable rustc
381+
// internals;
374382
g.buf.reserve(reservation_size(r));
375383
let capacity = g.buf.capacity();
376384
g.buf.set_len(capacity);

src/libstd/sys/sgx/condvar.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ impl Condvar {
2727

2828
pub unsafe fn wait(&self, mutex: &Mutex) {
2929
let guard = self.inner.lock();
30-
mutex.unlock();
31-
WaitQueue::wait(guard);
30+
WaitQueue::wait(guard, || mutex.unlock());
3231
mutex.lock()
3332
}
3433

src/libstd/sys/sgx/mutex.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Mutex {
2222
let mut guard = self.inner.lock();
2323
if *guard.lock_var() {
2424
// Another thread has the lock, wait
25-
WaitQueue::wait(guard)
25+
WaitQueue::wait(guard, ||{})
2626
// Another thread has passed the lock to us
2727
} else {
2828
// We are just now obtaining the lock
@@ -83,7 +83,7 @@ impl ReentrantMutex {
8383
match guard.lock_var().owner {
8484
Some(tcs) if tcs != thread::current() => {
8585
// Another thread has the lock, wait
86-
WaitQueue::wait(guard);
86+
WaitQueue::wait(guard, ||{});
8787
// Another thread has passed the lock to us
8888
},
8989
_ => {

src/libstd/sys/sgx/rwlock.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl RWLock {
3131
if *wguard.lock_var() || !wguard.queue_empty() {
3232
// Another thread has or is waiting for the write lock, wait
3333
drop(wguard);
34-
WaitQueue::wait(rguard);
34+
WaitQueue::wait(rguard, ||{});
3535
// Another thread has passed the lock to us
3636
} else {
3737
// No waiting writers, acquire the read lock
@@ -62,7 +62,7 @@ impl RWLock {
6262
if *wguard.lock_var() || rguard.lock_var().is_some() {
6363
// Another thread has the lock, wait
6464
drop(rguard);
65-
WaitQueue::wait(wguard);
65+
WaitQueue::wait(wguard, ||{});
6666
// Another thread has passed the lock to us
6767
} else {
6868
// We are just now obtaining the lock
@@ -97,6 +97,7 @@ impl RWLock {
9797
if let Ok(mut wguard) = WaitQueue::notify_one(wguard) {
9898
// A writer was waiting, pass the lock
9999
*wguard.lock_var_mut() = true;
100+
wguard.drop_after(rguard);
100101
} else {
101102
// No writers were waiting, the lock is released
102103
rtassert!(rguard.queue_empty());
@@ -117,21 +118,26 @@ impl RWLock {
117118
rguard: SpinMutexGuard<'_, WaitVariable<Option<NonZeroUsize>>>,
118119
wguard: SpinMutexGuard<'_, WaitVariable<bool>>,
119120
) {
120-
if let Err(mut wguard) = WaitQueue::notify_one(wguard) {
121-
// No writers waiting, release the write lock
122-
*wguard.lock_var_mut() = false;
123-
if let Ok(mut rguard) = WaitQueue::notify_all(rguard) {
124-
// One or more readers were waiting, pass the lock to them
125-
if let NotifiedTcs::All { count } = rguard.notified_tcs() {
126-
*rguard.lock_var_mut() = Some(count)
121+
match WaitQueue::notify_one(wguard) {
122+
Err(mut wguard) => {
123+
// No writers waiting, release the write lock
124+
*wguard.lock_var_mut() = false;
125+
if let Ok(mut rguard) = WaitQueue::notify_all(rguard) {
126+
// One or more readers were waiting, pass the lock to them
127+
if let NotifiedTcs::All { count } = rguard.notified_tcs() {
128+
*rguard.lock_var_mut() = Some(count)
129+
} else {
130+
unreachable!() // called notify_all
131+
}
132+
rguard.drop_after(wguard);
127133
} else {
128-
unreachable!() // called notify_all
134+
// No readers waiting, the lock is released
129135
}
130-
} else {
131-
// No readers waiting, the lock is released
136+
},
137+
Ok(wguard) => {
138+
// There was a thread waiting for write, just pass the lock
139+
wguard.drop_after(rguard);
132140
}
133-
} else {
134-
// There was a thread waiting for write, just pass the lock
135141
}
136142
}
137143

src/libstd/sys/sgx/waitqueue.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ impl<'a, T> WaitGuard<'a, T> {
9898
pub fn notified_tcs(&self) -> NotifiedTcs {
9999
self.notified_tcs
100100
}
101+
102+
/// Drop this `WaitGuard`, after dropping another `guard`.
103+
pub fn drop_after<U>(self, guard: U) {
104+
drop(guard);
105+
drop(self);
106+
}
101107
}
102108

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

548-
WaitQueue::wait(locked);
555+
WaitQueue::wait(locked, ||{});
549556

550557
t1.join().unwrap();
551558
}

0 commit comments

Comments
 (0)