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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 81 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 11 additions & 10 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 1 addition & 2 deletions
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

0 commit comments

Comments
 (0)