Skip to content

Commit

Permalink
Auto merge of #51504 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #50617 (Fix extern prelude failure in rustdoc)
 - #51442 ([futures] add a few blanket impls to std)
 - #51498 (Make parse_ident public)
 - #51502 (Make parse_seq_to_end and parse_path public)

Failed merges:
  • Loading branch information
bors committed Jun 11, 2018
2 parents 0b7c9e7 + 8e32eb3 commit 01fe91a
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 6 deletions.
18 changes: 18 additions & 0 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,24 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<PinBox<U>> for PinBox<T> {}
#[unstable(feature = "pin", issue = "49150")]
impl<T: ?Sized> Unpin for PinBox<T> {}

#[unstable(feature = "futures_api", issue = "50547")]
impl<'a, F: ?Sized + Future + Unpin> Future for Box<F> {
type Output = F::Output;

fn poll(mut self: PinMut<Self>, cx: &mut Context) -> Poll<Self::Output> {
PinMut::new(&mut **self).poll(cx)
}
}

#[unstable(feature = "futures_api", issue = "50547")]
impl<'a, F: ?Sized + Future> Future for PinBox<F> {
type Output = F::Output;

fn poll(mut self: PinMut<Self>, cx: &mut Context) -> Poll<Self::Output> {
self.as_pin_mut().poll(cx)
}
}

#[unstable(feature = "futures_api", issue = "50547")]
unsafe impl<F: Future<Output = ()> + Send + 'static> UnsafePoll for PinBox<F> {
fn into_raw(self) -> *mut () {
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#![cfg_attr(test, feature(rand, test))]
#![feature(allocator_api)]
#![feature(allow_internal_unstable)]
#![feature(arbitrary_self_types)]
#![feature(ascii_ctype)]
#![feature(box_into_raw_non_null)]
#![feature(box_patterns)]
Expand Down
17 changes: 17 additions & 0 deletions src/libcore/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//! Asynchronous values.
use mem::PinMut;
use marker::Unpin;
use task::{self, Poll};

/// A future represents an asychronous computation.
Expand Down Expand Up @@ -91,3 +92,19 @@ pub trait Future {
/// about the behavior of `poll` after a future has completed.
fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output>;
}

impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F {
type Output = F::Output;

fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> {
F::poll(PinMut::new(&mut **self), cx)
}
}

impl<'a, F: ?Sized + Future> Future for PinMut<'a, F> {
type Output = F::Output;

fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> {
F::poll((*self).reborrow(), cx)
}
}
55 changes: 55 additions & 0 deletions src/libcore/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,61 @@ pub enum Poll<T> {
Pending,
}

impl<T> Poll<T> {
/// Change the ready value of this `Poll` with the closure provided
pub fn map<U, F>(self, f: F) -> Poll<U>
where F: FnOnce(T) -> U
{
match self {
Poll::Ready(t) => Poll::Ready(f(t)),
Poll::Pending => Poll::Pending,
}
}

/// Returns whether this is `Poll::Ready`
pub fn is_ready(&self) -> bool {
match *self {
Poll::Ready(_) => true,
Poll::Pending => false,
}
}

/// Returns whether this is `Poll::Pending`
pub fn is_pending(&self) -> bool {
!self.is_ready()
}
}

impl<T, E> Poll<Result<T, E>> {
/// Change the success value of this `Poll` with the closure provided
pub fn map_ok<U, F>(self, f: F) -> Poll<Result<U, E>>
where F: FnOnce(T) -> U
{
match self {
Poll::Ready(Ok(t)) => Poll::Ready(Ok(f(t))),
Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
Poll::Pending => Poll::Pending,
}
}

/// Change the error value of this `Poll` with the closure provided
pub fn map_err<U, F>(self, f: F) -> Poll<Result<T, U>>
where F: FnOnce(E) -> U
{
match self {
Poll::Ready(Ok(t)) => Poll::Ready(Ok(t)),
Poll::Ready(Err(e)) => Poll::Ready(Err(f(e))),
Poll::Pending => Poll::Pending,
}
}
}

impl<T> From<T> for Poll<T> {
fn from(t: T) -> Poll<T> {
Poll::Ready(t)
}
}

/// A `Waker` is a handle for waking up a task by notifying its executor that it
/// is ready to be run.
///
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ impl Input {
Input::Str { .. } => "rust_out".to_string(),
}
}

pub fn get_input(&mut self) -> Option<&mut String> {
match *self {
Input::File(_) => None,
Input::Str { ref mut input, .. } => Some(input),
}
}
}

#[derive(Clone)]
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,9 @@ pub struct Resolver<'a> {
current_type_ascription: Vec<Span>,

injected_crate: Option<Module<'a>>,

/// Only supposed to be used by rustdoc, otherwise should be false.
pub ignore_extern_prelude_feature: bool,
}

/// Nothing really interesting here, it just provides memory for the rest of the crate.
Expand Down Expand Up @@ -1718,6 +1721,7 @@ impl<'a> Resolver<'a> {
unused_macros: FxHashSet(),
current_type_ascription: Vec::new(),
injected_crate: None,
ignore_extern_prelude_feature: false,
}
}

Expand Down Expand Up @@ -1891,7 +1895,8 @@ impl<'a> Resolver<'a> {
if !module.no_implicit_prelude {
// `record_used` means that we don't try to load crates during speculative resolution
if record_used && ns == TypeNS && self.extern_prelude.contains(&ident.name) {
if !self.session.features_untracked().extern_prelude {
if !self.session.features_untracked().extern_prelude &&
!self.ignore_extern_prelude_feature {
feature_err(&self.session.parse_sess, "extern_prelude",
ident.span, GateIssue::Language,
"access to extern crates through prelude is experimental").emit();
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
// early return and try looking for the trait
let value = match result.def {
Def::Method(_) | Def::AssociatedConst(_) => true,
Def::AssociatedTy(_) => false,
Def::AssociatedTy(_) => false,
Def::Variant(_) => return handle_variant(cx, result.def),
// not a trait item, just return what we found
_ => return Ok((result.def, None))
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,12 @@ pub fn run_core(search_paths: SearchPaths,
|_| Ok(()));
let driver::InnerExpansionResult {
mut hir_forest,
resolver,
mut resolver,
..
} = abort_on_err(result, &sess);

resolver.ignore_extern_prelude_feature = true;

// We need to hold on to the complete resolver, so we clone everything
// for the analysis passes to use. Suboptimal, but necessary in the
// current architecture.
Expand Down
1 change: 1 addition & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
#![feature(allow_internal_unsafe)]
#![feature(allow_internal_unstable)]
#![feature(align_offset)]
#![feature(arbitrary_self_types)]
#![feature(array_error_internals)]
#![feature(ascii_ctype)]
#![feature(asm)]
Expand Down
18 changes: 18 additions & 0 deletions src/libstd/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
use any::Any;
use cell::UnsafeCell;
use fmt;
use future::Future;
use mem::PinMut;
use ops::{Deref, DerefMut};
use panicking;
use ptr::{Unique, NonNull};
use rc::Rc;
use sync::{Arc, Mutex, RwLock, atomic};
use task::{self, Poll};
use thread::Result;

#[stable(feature = "panic_hooks", since = "1.10.0")]
Expand Down Expand Up @@ -315,6 +318,21 @@ impl<T: fmt::Debug> fmt::Debug for AssertUnwindSafe<T> {
}
}

#[unstable(feature = "futures_api", issue = "50547")]
impl<'a, F: Future> Future for AssertUnwindSafe<F> {
type Output = F::Output;

fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> {
unsafe {
let pinned_field = PinMut::new_unchecked(
&mut PinMut::get_mut(self.reborrow()).0
);

pinned_field.poll(cx)
}
}
}

/// Invokes a closure, capturing the cause of an unwinding panic if one occurs.
///
/// This function will return `Ok` with the closure's result if the closure
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ impl<'a> Parser<'a> {
err
}

fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
pub fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
self.parse_ident_common(true)
}

Expand Down Expand Up @@ -1022,7 +1022,7 @@ impl<'a> Parser<'a> {
/// Parse a sequence, including the closing delimiter. The function
/// f must consume tokens until reaching the next separator or
/// closing bracket.
crate fn parse_seq_to_end<T, F>(&mut self,
pub fn parse_seq_to_end<T, F>(&mut self,
ket: &token::Token,
sep: SeqSep,
f: F)
Expand Down Expand Up @@ -1886,7 +1886,7 @@ impl<'a> Parser<'a> {
/// `a::b::C::<D>` (with disambiguator)
/// `Fn(Args)` (without disambiguator)
/// `Fn::(Args)` (with disambiguator)
crate fn parse_path(&mut self, style: PathStyle) -> PResult<'a, ast::Path> {
pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, ast::Path> {
self.parse_path_common(style, true)
}

Expand Down

0 comments on commit 01fe91a

Please sign in to comment.