From 27db90a2092eda6749bfc53a7a90d8567234f99c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 10 May 2018 20:13:25 +0200 Subject: [PATCH 1/6] Fix extern prelude failure in rustdoc --- src/librustc/session/config.rs | 7 +++++++ src/librustc_resolve/lib.rs | 7 ++++++- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/core.rs | 4 +++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 245663494ddef..ca363e9a744f2 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -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)] diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 0f931d4374e59..b0f95f42f3314 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1529,6 +1529,9 @@ pub struct Resolver<'a> { current_type_ascription: Vec, injected_crate: Option>, + + /// 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. @@ -1792,6 +1795,7 @@ impl<'a> Resolver<'a> { unused_macros: FxHashSet(), current_type_ascription: Vec::new(), injected_crate: None, + ignore_extern_prelude_feature: false, } } @@ -1972,7 +1976,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(); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7d3ba79282938..61035437a023a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1034,7 +1034,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)) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 6222edd5450f0..1010a309da46a 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -227,10 +227,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. From 6e5c18e8dc94a679126d276884a3ad4b9a3e0934 Mon Sep 17 00:00:00 2001 From: tinaun Date: Fri, 8 Jun 2018 16:45:27 -0400 Subject: [PATCH 2/6] add a few blanket future impls to std --- src/liballoc/boxed.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/liballoc/lib.rs | 1 + src/libcore/future.rs | 17 +++++++++++++++++ src/libcore/task.rs | 6 ++++++ src/libstd/lib.rs | 1 + src/libstd/panic.rs | 18 ++++++++++++++++++ 6 files changed, 82 insertions(+) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index a64b94b651759..896d9dee3ee45 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -914,6 +914,45 @@ impl, U: ?Sized> CoerceUnsized> for PinBox {} #[unstable(feature = "pin", issue = "49150")] impl Unpin for PinBox {} +#[unstable(feature = "futures_api", issue = "50547")] +impl<'a, F: ?Sized + Future + Unpin> Future for Box { + type Output = F::Output; + + fn poll(mut self: PinMut, cx: &mut Context) -> Poll { + PinMut::new(&mut **self).poll(cx) + } +} + +#[unstable(feature = "futures_api", issue = "50547")] +impl<'a, F: ?Sized + Future> Future for PinBox { + type Output = F::Output; + + fn poll(mut self: PinMut, cx: &mut Context) -> Poll { + self.as_pin_mut().poll(cx) + } +} + +#[unstable(feature = "futures_api", issue = "50547")] +unsafe impl + Send + 'static> UnsafePoll for Box { + fn into_raw(self) -> *mut () { + unsafe { + mem::transmute(self) + } + } + + unsafe fn poll(task: *mut (), cx: &mut Context) -> Poll<()> { + let ptr: *mut F = mem::transmute(task); + let pin: PinMut = PinMut::new_unchecked(&mut *ptr); + pin.poll(cx) + } + + unsafe fn drop(task: *mut ()) { + let ptr: *mut F = mem::transmute(task); + let boxed = Box::from_raw(ptr); + drop(boxed) + } +} + #[unstable(feature = "futures_api", issue = "50547")] unsafe impl + Send + 'static> UnsafePoll for PinBox { fn into_raw(self) -> *mut () { diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 242c7d2e70f85..a1139189c9a44 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -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)] diff --git a/src/libcore/future.rs b/src/libcore/future.rs index b4d087f8edb6d..a8c8f69411ea6 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -15,6 +15,7 @@ //! Asynchronous values. use mem::PinMut; +use marker::Unpin; use task::{self, Poll}; /// A future represents an asychronous computation. @@ -91,3 +92,19 @@ pub trait Future { /// about the behavior of `poll` after a future has completed. fn poll(self: PinMut, cx: &mut task::Context) -> Poll; } + +impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F { + type Output = F::Output; + + fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + 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, cx: &mut task::Context) -> Poll { + F::poll((*self).reborrow(), cx) + } +} diff --git a/src/libcore/task.rs b/src/libcore/task.rs index e46a6d41d7acf..ab1c1da57906a 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -32,6 +32,12 @@ pub enum Poll { Pending, } +impl From for Poll { + fn from(t: T) -> Poll { + Poll::Ready(t) + } +} + /// A `Waker` is a handle for waking up a task by notifying its executor that it /// is ready to be run. /// diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 7bbc99b83be56..bb23fe5fa918e 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -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)] diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 229034eb7790b..b70de73991ffe 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -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")] @@ -315,6 +318,21 @@ impl fmt::Debug for AssertUnwindSafe { } } +#[unstable(feature = "futures_api", issue = "50547")] +impl<'a, F: Future> Future for AssertUnwindSafe { + type Output = F::Output; + + fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { + 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 From 49eb754cc0108d8546eae70cdcebf81aaddbece3 Mon Sep 17 00:00:00 2001 From: tinaun Date: Fri, 8 Jun 2018 23:16:51 -0400 Subject: [PATCH 3/6] addressed nits --- src/liballoc/boxed.rs | 21 --------------------- src/libstd/panic.rs | 6 +++--- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 896d9dee3ee45..c794fb8220a9e 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -932,27 +932,6 @@ impl<'a, F: ?Sized + Future> Future for PinBox { } } -#[unstable(feature = "futures_api", issue = "50547")] -unsafe impl + Send + 'static> UnsafePoll for Box { - fn into_raw(self) -> *mut () { - unsafe { - mem::transmute(self) - } - } - - unsafe fn poll(task: *mut (), cx: &mut Context) -> Poll<()> { - let ptr: *mut F = mem::transmute(task); - let pin: PinMut = PinMut::new_unchecked(&mut *ptr); - pin.poll(cx) - } - - unsafe fn drop(task: *mut ()) { - let ptr: *mut F = mem::transmute(task); - let boxed = Box::from_raw(ptr); - drop(boxed) - } -} - #[unstable(feature = "futures_api", issue = "50547")] unsafe impl + Send + 'static> UnsafePoll for PinBox { fn into_raw(self) -> *mut () { diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index b70de73991ffe..8aee15b5eda27 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -326,9 +326,9 @@ impl<'a, F: Future> Future for AssertUnwindSafe { unsafe { let pinned_field = PinMut::new_unchecked( &mut PinMut::get_mut(self.reborrow()).0 - ); - - pinned_field.poll(cx) + ); + + pinned_field.poll(cx) } } } From fb507cadf32e1eacccc07c1c3511636fd6378f7b Mon Sep 17 00:00:00 2001 From: tinaun Date: Fri, 8 Jun 2018 23:24:52 -0400 Subject: [PATCH 4/6] add inherent methods to Poll --- src/libcore/task.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++ src/libstd/panic.rs | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/libcore/task.rs b/src/libcore/task.rs index ab1c1da57906a..bef6d3677d0a3 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -32,6 +32,55 @@ pub enum Poll { Pending, } +impl Poll { + /// Change the ready value of this `Poll` with the closure provided + pub fn map(self, f: F) -> Poll + 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 Poll> { + /// Change the success value of this `Poll` with the closure provided + pub fn map_ok(self, f: F) -> Poll> + 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(self, f: F) -> Poll> + 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 From for Poll { fn from(t: T) -> Poll { Poll::Ready(t) diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 8aee15b5eda27..4b5a063ea73aa 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -327,7 +327,7 @@ impl<'a, F: Future> Future for AssertUnwindSafe { let pinned_field = PinMut::new_unchecked( &mut PinMut::get_mut(self.reborrow()).0 ); - + pinned_field.poll(cx) } } From ed74b0b01685afa9a8c86078131f7d4b9c40ab7c Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Mon, 11 Jun 2018 23:04:11 +0900 Subject: [PATCH 5/6] Make parse_ident public --- src/libsyntax/parse/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 97fcf70f5319d..36ae54a509eec 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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) } From 7e56261fcbdaa8d039ee507911f8e5e886de1e41 Mon Sep 17 00:00:00 2001 From: jeb Date: Mon, 11 Jun 2018 10:40:58 -0600 Subject: [PATCH 6/6] Make parse_seq_to_end and parse_path public --- src/libsyntax/parse/parser.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 97fcf70f5319d..c192dec42fae5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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(&mut self, + pub fn parse_seq_to_end(&mut self, ket: &token::Token, sep: SeqSep, f: F) @@ -1886,7 +1886,7 @@ impl<'a> Parser<'a> { /// `a::b::C::` (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) }