Skip to content

Commit 01fe91a

Browse files
committed
Auto merge of #51504 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
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:
2 parents 0b7c9e7 + 8e32eb3 commit 01fe91a

File tree

11 files changed

+130
-6
lines changed

11 files changed

+130
-6
lines changed

src/liballoc/boxed.rs

+18
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,24 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<PinBox<U>> for PinBox<T> {}
914914
#[unstable(feature = "pin", issue = "49150")]
915915
impl<T: ?Sized> Unpin for PinBox<T> {}
916916

917+
#[unstable(feature = "futures_api", issue = "50547")]
918+
impl<'a, F: ?Sized + Future + Unpin> Future for Box<F> {
919+
type Output = F::Output;
920+
921+
fn poll(mut self: PinMut<Self>, cx: &mut Context) -> Poll<Self::Output> {
922+
PinMut::new(&mut **self).poll(cx)
923+
}
924+
}
925+
926+
#[unstable(feature = "futures_api", issue = "50547")]
927+
impl<'a, F: ?Sized + Future> Future for PinBox<F> {
928+
type Output = F::Output;
929+
930+
fn poll(mut self: PinMut<Self>, cx: &mut Context) -> Poll<Self::Output> {
931+
self.as_pin_mut().poll(cx)
932+
}
933+
}
934+
917935
#[unstable(feature = "futures_api", issue = "50547")]
918936
unsafe impl<F: Future<Output = ()> + Send + 'static> UnsafePoll for PinBox<F> {
919937
fn into_raw(self) -> *mut () {

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#![cfg_attr(test, feature(rand, test))]
8181
#![feature(allocator_api)]
8282
#![feature(allow_internal_unstable)]
83+
#![feature(arbitrary_self_types)]
8384
#![feature(ascii_ctype)]
8485
#![feature(box_into_raw_non_null)]
8586
#![feature(box_patterns)]

src/libcore/future.rs

+17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//! Asynchronous values.
1616
1717
use mem::PinMut;
18+
use marker::Unpin;
1819
use task::{self, Poll};
1920

2021
/// A future represents an asychronous computation.
@@ -91,3 +92,19 @@ pub trait Future {
9192
/// about the behavior of `poll` after a future has completed.
9293
fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output>;
9394
}
95+
96+
impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F {
97+
type Output = F::Output;
98+
99+
fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> {
100+
F::poll(PinMut::new(&mut **self), cx)
101+
}
102+
}
103+
104+
impl<'a, F: ?Sized + Future> Future for PinMut<'a, F> {
105+
type Output = F::Output;
106+
107+
fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> {
108+
F::poll((*self).reborrow(), cx)
109+
}
110+
}

src/libcore/task.rs

+55
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,61 @@ pub enum Poll<T> {
3232
Pending,
3333
}
3434

35+
impl<T> Poll<T> {
36+
/// Change the ready value of this `Poll` with the closure provided
37+
pub fn map<U, F>(self, f: F) -> Poll<U>
38+
where F: FnOnce(T) -> U
39+
{
40+
match self {
41+
Poll::Ready(t) => Poll::Ready(f(t)),
42+
Poll::Pending => Poll::Pending,
43+
}
44+
}
45+
46+
/// Returns whether this is `Poll::Ready`
47+
pub fn is_ready(&self) -> bool {
48+
match *self {
49+
Poll::Ready(_) => true,
50+
Poll::Pending => false,
51+
}
52+
}
53+
54+
/// Returns whether this is `Poll::Pending`
55+
pub fn is_pending(&self) -> bool {
56+
!self.is_ready()
57+
}
58+
}
59+
60+
impl<T, E> Poll<Result<T, E>> {
61+
/// Change the success value of this `Poll` with the closure provided
62+
pub fn map_ok<U, F>(self, f: F) -> Poll<Result<U, E>>
63+
where F: FnOnce(T) -> U
64+
{
65+
match self {
66+
Poll::Ready(Ok(t)) => Poll::Ready(Ok(f(t))),
67+
Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
68+
Poll::Pending => Poll::Pending,
69+
}
70+
}
71+
72+
/// Change the error value of this `Poll` with the closure provided
73+
pub fn map_err<U, F>(self, f: F) -> Poll<Result<T, U>>
74+
where F: FnOnce(E) -> U
75+
{
76+
match self {
77+
Poll::Ready(Ok(t)) => Poll::Ready(Ok(t)),
78+
Poll::Ready(Err(e)) => Poll::Ready(Err(f(e))),
79+
Poll::Pending => Poll::Pending,
80+
}
81+
}
82+
}
83+
84+
impl<T> From<T> for Poll<T> {
85+
fn from(t: T) -> Poll<T> {
86+
Poll::Ready(t)
87+
}
88+
}
89+
3590
/// A `Waker` is a handle for waking up a task by notifying its executor that it
3691
/// is ready to be run.
3792
///

src/librustc/session/config.rs

+7
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,13 @@ impl Input {
494494
Input::Str { .. } => "rust_out".to_string(),
495495
}
496496
}
497+
498+
pub fn get_input(&mut self) -> Option<&mut String> {
499+
match *self {
500+
Input::File(_) => None,
501+
Input::Str { ref mut input, .. } => Some(input),
502+
}
503+
}
497504
}
498505

499506
#[derive(Clone)]

src/librustc_resolve/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,9 @@ pub struct Resolver<'a> {
14371437
current_type_ascription: Vec<Span>,
14381438

14391439
injected_crate: Option<Module<'a>>,
1440+
1441+
/// Only supposed to be used by rustdoc, otherwise should be false.
1442+
pub ignore_extern_prelude_feature: bool,
14401443
}
14411444

14421445
/// Nothing really interesting here, it just provides memory for the rest of the crate.
@@ -1718,6 +1721,7 @@ impl<'a> Resolver<'a> {
17181721
unused_macros: FxHashSet(),
17191722
current_type_ascription: Vec::new(),
17201723
injected_crate: None,
1724+
ignore_extern_prelude_feature: false,
17211725
}
17221726
}
17231727

@@ -1891,7 +1895,8 @@ impl<'a> Resolver<'a> {
18911895
if !module.no_implicit_prelude {
18921896
// `record_used` means that we don't try to load crates during speculative resolution
18931897
if record_used && ns == TypeNS && self.extern_prelude.contains(&ident.name) {
1894-
if !self.session.features_untracked().extern_prelude {
1898+
if !self.session.features_untracked().extern_prelude &&
1899+
!self.ignore_extern_prelude_feature {
18951900
feature_err(&self.session.parse_sess, "extern_prelude",
18961901
ident.span, GateIssue::Language,
18971902
"access to extern crates through prelude is experimental").emit();

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
11031103
// early return and try looking for the trait
11041104
let value = match result.def {
11051105
Def::Method(_) | Def::AssociatedConst(_) => true,
1106-
Def::AssociatedTy(_) => false,
1106+
Def::AssociatedTy(_) => false,
11071107
Def::Variant(_) => return handle_variant(cx, result.def),
11081108
// not a trait item, just return what we found
11091109
_ => return Ok((result.def, None))

src/librustdoc/core.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,12 @@ pub fn run_core(search_paths: SearchPaths,
250250
|_| Ok(()));
251251
let driver::InnerExpansionResult {
252252
mut hir_forest,
253-
resolver,
253+
mut resolver,
254254
..
255255
} = abort_on_err(result, &sess);
256256

257+
resolver.ignore_extern_prelude_feature = true;
258+
257259
// We need to hold on to the complete resolver, so we clone everything
258260
// for the analysis passes to use. Suboptimal, but necessary in the
259261
// current architecture.

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
#![feature(allow_internal_unsafe)]
240240
#![feature(allow_internal_unstable)]
241241
#![feature(align_offset)]
242+
#![feature(arbitrary_self_types)]
242243
#![feature(array_error_internals)]
243244
#![feature(ascii_ctype)]
244245
#![feature(asm)]

src/libstd/panic.rs

+18
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
use any::Any;
1616
use cell::UnsafeCell;
1717
use fmt;
18+
use future::Future;
19+
use mem::PinMut;
1820
use ops::{Deref, DerefMut};
1921
use panicking;
2022
use ptr::{Unique, NonNull};
2123
use rc::Rc;
2224
use sync::{Arc, Mutex, RwLock, atomic};
25+
use task::{self, Poll};
2326
use thread::Result;
2427

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

321+
#[unstable(feature = "futures_api", issue = "50547")]
322+
impl<'a, F: Future> Future for AssertUnwindSafe<F> {
323+
type Output = F::Output;
324+
325+
fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> {
326+
unsafe {
327+
let pinned_field = PinMut::new_unchecked(
328+
&mut PinMut::get_mut(self.reborrow()).0
329+
);
330+
331+
pinned_field.poll(cx)
332+
}
333+
}
334+
}
335+
318336
/// Invokes a closure, capturing the cause of an unwinding panic if one occurs.
319337
///
320338
/// This function will return `Ok` with the closure's result if the closure

src/libsyntax/parse/parser.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ impl<'a> Parser<'a> {
760760
err
761761
}
762762

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

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

0 commit comments

Comments
 (0)