Skip to content

Commit

Permalink
Auto merge of #63940 - Centril:rollup-47qe9gn, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #62600 (libtest: add --show-output flag to print stdout of successful tests)
 - #63698 (Fixed floating point issue with asinh function)
 - #63761 (Propagate spans and attributes from proc macro definitions)
 - #63917 (Error when generator trait is not found)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Aug 27, 2019
2 parents 0444b9f + 23116ba commit 7e0afda
Show file tree
Hide file tree
Showing 38 changed files with 468 additions and 240 deletions.
10 changes: 6 additions & 4 deletions src/libproc_macro/lib.rs
Expand Up @@ -19,12 +19,15 @@

#![feature(nll)]
#![feature(staged_api)]
#![feature(allow_internal_unstable)]
#![feature(const_fn)]
#![feature(decl_macro)]
#![feature(extern_types)]
#![feature(in_band_lifetimes)]
#![feature(optin_builtin_traits)]
#![feature(mem_take)]
#![feature(non_exhaustive)]
#![feature(rustc_attrs)]
#![feature(specialization)]

#![recursion_limit="256"]
Expand Down Expand Up @@ -222,11 +225,10 @@ pub mod token_stream {
///
/// Unquoting is done with `$`, and works by taking the single next ident as the unquoted term.
/// To quote `$` itself, use `$$`.
///
/// This is a dummy macro, the actual implementation is in `quote::quote`.`
#[unstable(feature = "proc_macro_quote", issue = "54722")]
#[macro_export]
macro_rules! quote { () => {} }
#[allow_internal_unstable(proc_macro_def_site)]
#[cfg_attr(not(bootstrap), rustc_builtin_macro)]
pub macro quote ($($t:tt)*) { /* compiler built-in */ }

#[unstable(feature = "proc_macro_internals", issue = "27812")]
#[doc(hidden)]
Expand Down
4 changes: 2 additions & 2 deletions src/libproc_macro/quote.rs
Expand Up @@ -57,9 +57,9 @@ macro_rules! quote {
}

/// Quote a `TokenStream` into a `TokenStream`.
/// This is the actual `quote!()` proc macro.
/// This is the actual implementation of the `quote!()` proc macro.
///
/// It is manually loaded in `CStore::load_macro_untracked`.
/// It is loaded by the compiler in `register_builtin_macros`.
#[unstable(feature = "proc_macro_quote", issue = "54722")]
pub fn quote(stream: TokenStream) -> TokenStream {
if stream.is_empty() {
Expand Down
7 changes: 1 addition & 6 deletions src/librustc_metadata/cstore.rs
Expand Up @@ -95,11 +95,6 @@ pub struct CrateMetadata {
pub raw_proc_macros: Option<&'static [ProcMacro]>,
}

pub struct FullProcMacro {
pub name: ast::Name,
pub ext: Lrc<SyntaxExtension>
}

pub struct CStore {
metas: RwLock<IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>>,
/// Map from NodeId's of local extern crate statements to crate numbers
Expand All @@ -109,7 +104,7 @@ pub struct CStore {

pub enum LoadedMacro {
MacroDef(ast::Item),
ProcMacro(Lrc<SyntaxExtension>),
ProcMacro(SyntaxExtension),
}

impl CStore {
Expand Down
14 changes: 2 additions & 12 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -30,11 +30,9 @@ use syntax::ast;
use syntax::attr;
use syntax::source_map;
use syntax::edition::Edition;
use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind};
use syntax::ext::proc_macro::BangProcMacro;
use syntax::parse::source_file_to_stream;
use syntax::parse::parser::emit_unclosed_delims;
use syntax::symbol::{Symbol, sym};
use syntax::symbol::Symbol;
use syntax_pos::{Span, FileName};
use rustc_data_structures::bit_set::BitSet;

Expand Down Expand Up @@ -436,15 +434,7 @@ impl cstore::CStore {
pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
let data = self.get_crate_data(id.krate);
if data.is_proc_macro_crate() {
return LoadedMacro::ProcMacro(data.get_proc_macro(id.index, sess).ext);
} else if data.name == sym::proc_macro && data.item_name(id.index) == sym::quote {
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
let kind = SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client }));
let ext = SyntaxExtension {
allow_internal_unstable: Some([sym::proc_macro_def_site][..].into()),
..SyntaxExtension::default(kind, data.root.edition)
};
return LoadedMacro::ProcMacro(Lrc::new(ext));
return LoadedMacro::ProcMacro(data.load_proc_macro(id.index, sess));
}

let def = data.get_macro(id.index);
Expand Down
49 changes: 17 additions & 32 deletions src/librustc_metadata/decoder.rs
@@ -1,6 +1,6 @@
// Decoding metadata from a single crate's metadata

use crate::cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule, FullProcMacro};
use crate::cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule};
use crate::schema::*;

use rustc_data_structures::indexed_vec::IndexVec;
Expand Down Expand Up @@ -512,27 +512,8 @@ impl<'a, 'tcx> CrateMetadata {
self.entry(index).span.decode((self, sess))
}


pub fn get_proc_macro(&self, id: DefIndex, sess: &Session) -> FullProcMacro {
if sess.opts.debugging_opts.dual_proc_macros {
let host_lib = self.host_lib.as_ref().unwrap();
self.load_proc_macro(
&host_lib.metadata.get_root(),
id,
sess
)
} else {
self.load_proc_macro(&self.root, id, sess)
}
}

fn load_proc_macro(&self, root: &CrateRoot<'_>,
id: DefIndex,
sess: &Session)
-> FullProcMacro {

let raw_macro = self.raw_proc_macro(id);
let (name, kind, helper_attrs) = match *raw_macro {
crate fn load_proc_macro(&self, id: DefIndex, sess: &Session) -> SyntaxExtension {
let (name, kind, helper_attrs) = match *self.raw_proc_macro(id) {
ProcMacro::CustomDerive { trait_name, attributes, client } => {
let helper_attrs =
attributes.iter().cloned().map(Symbol::intern).collect::<Vec<_>>();
Expand All @@ -551,17 +532,21 @@ impl<'a, 'tcx> CrateMetadata {
name, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })), Vec::new()
)
};
let edition = if sess.opts.debugging_opts.dual_proc_macros {
self.host_lib.as_ref().unwrap().metadata.get_root().edition
} else {
self.root.edition
};

let span = self.get_span(id, sess);

FullProcMacro {
name: Symbol::intern(name),
ext: Lrc::new(SyntaxExtension {
span,
helper_attrs,
..SyntaxExtension::default(kind, root.edition)
})
}
SyntaxExtension::new(
&sess.parse_sess,
kind,
self.get_span(id, sess),
helper_attrs,
edition,
Symbol::intern(name),
&self.get_attributes(&self.entry(id), sess),
)
}

pub fn get_trait_def(&self, item_id: DefIndex, sess: &Session) -> ty::TraitDef {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -150,12 +150,12 @@ impl<'a> Resolver<'a> {
return Some(ext.clone());
}

let macro_def = match self.cstore.load_macro_untracked(def_id, &self.session) {
LoadedMacro::MacroDef(macro_def) => macro_def,
LoadedMacro::ProcMacro(ext) => return Some(ext),
};
let ext = Lrc::new(match self.cstore.load_macro_untracked(def_id, &self.session) {
LoadedMacro::MacroDef(item) =>
self.compile_macro(&item, self.cstore.crate_edition_untracked(def_id.krate)),
LoadedMacro::ProcMacro(ext) => ext,
});

let ext = self.compile_macro(&macro_def, self.cstore.crate_edition_untracked(def_id.krate));
self.macro_map.insert(def_id, ext.clone());
Some(ext)
}
Expand Down Expand Up @@ -1104,7 +1104,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let expansion = parent_scope.expansion;
let (ext, ident, span, is_legacy) = match &item.node {
ItemKind::MacroDef(def) => {
let ext = self.r.compile_macro(item, self.r.session.edition());
let ext = Lrc::new(self.r.compile_macro(item, self.r.session.edition()));
(ext, item.ident, item.span, def.legacy)
}
ItemKind::Fn(..) => match Self::proc_macro_stub(item) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/macros.rs
Expand Up @@ -800,7 +800,7 @@ impl<'a> Resolver<'a> {

/// Compile the macro into a `SyntaxExtension` and possibly replace it with a pre-defined
/// extension partially or entirely for built-in macros and legacy plugin macros.
crate fn compile_macro(&mut self, item: &ast::Item, edition: Edition) -> Lrc<SyntaxExtension> {
crate fn compile_macro(&mut self, item: &ast::Item, edition: Edition) -> SyntaxExtension {
let mut result = macro_rules::compile(
&self.session.parse_sess, self.session.features_untracked(), item, edition
);
Expand All @@ -822,6 +822,6 @@ impl<'a> Resolver<'a> {
}
}

Lrc::new(result)
result
}
}
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/closure.rs
Expand Up @@ -3,7 +3,7 @@
use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};

use crate::astconv::AstConv;
use crate::middle::region;
use crate::middle::{lang_items, region};
use rustc::hir::def_id::DefId;
use rustc::infer::{InferOk, InferResult};
use rustc::infer::LateBoundRegionConversionTime;
Expand Down Expand Up @@ -266,7 +266,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let trait_ref = projection.to_poly_trait_ref(tcx);

let is_fn = tcx.lang_items().fn_trait_kind(trait_ref.def_id()).is_some();
let gen_trait = tcx.lang_items().gen_trait().unwrap();
let gen_trait = tcx.require_lang_item(lang_items::GeneratorTraitLangItem);
let is_gen = gen_trait == trait_ref.def_id();
if !is_fn && !is_gen {
debug!("deduce_sig_from_projection: not fn or generator");
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/markdown.rs
Expand Up @@ -154,6 +154,6 @@ pub fn test(mut options: Options, diag: &errors::Handler) -> i32 {

options.test_args.insert(0, "rustdoctest".to_string());
testing::test_main(&options.test_args, collector.tests,
testing::Options::new().display_output(options.display_warnings));
Some(testing::Options::new().display_output(options.display_warnings)));
0
}
2 changes: 1 addition & 1 deletion src/librustdoc/test.rs
Expand Up @@ -120,7 +120,7 @@ pub fn run(options: Options) -> i32 {
testing::test_main(
&test_args,
tests,
testing::Options::new().display_output(display_warnings)
Some(testing::Options::new().display_output(display_warnings))
);

0
Expand Down
10 changes: 6 additions & 4 deletions src/libstd/f32.rs
Expand Up @@ -910,7 +910,7 @@ impl f32 {
if self == NEG_INFINITY {
NEG_INFINITY
} else {
(self + ((self * self) + 1.0).sqrt()).ln()
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
}
}

Expand All @@ -931,9 +931,10 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn acosh(self) -> f32 {
match self {
x if x < 1.0 => crate::f32::NAN,
x => (x + ((x * x) - 1.0).sqrt()).ln(),
if self < 1.0 {
crate::f32::NAN
} else {
(self + ((self * self) - 1.0).sqrt()).ln()
}
}

Expand Down Expand Up @@ -1487,6 +1488,7 @@ mod tests {
assert_eq!(inf.asinh(), inf);
assert_eq!(neg_inf.asinh(), neg_inf);
assert!(nan.asinh().is_nan());
assert!((-0.0f32).asinh().is_sign_negative()); // issue 63271
assert_approx_eq!(2.0f32.asinh(), 1.443635475178810342493276740273105f32);
assert_approx_eq!((-2.0f32).asinh(), -1.443635475178810342493276740273105f32);
}
Expand Down
33 changes: 18 additions & 15 deletions src/libstd/f64.rs
Expand Up @@ -244,7 +244,7 @@ impl f64 {
pub fn div_euclid(self, rhs: f64) -> f64 {
let q = (self / rhs).trunc();
if self % rhs < 0.0 {
return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }
return if rhs > 0.0 { q - 1.0 } else { q + 1.0 };
}
q
}
Expand Down Expand Up @@ -437,9 +437,9 @@ impl f64 {
pub fn log2(self) -> f64 {
self.log_wrapper(|n| {
#[cfg(target_os = "android")]
return crate::sys::android::log2f64(n);
return crate::sys::android::log2f64(n);
#[cfg(not(target_os = "android"))]
return unsafe { intrinsics::log2f64(n) };
return unsafe { intrinsics::log2f64(n) };
})
}

Expand Down Expand Up @@ -481,16 +481,16 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
#[rustc_deprecated(since = "1.10.0",
reason = "you probably meant `(self - other).abs()`: \
reason = "you probably meant `(self - other).abs()`: \
this operation is `(self - other).max(0.0)` \
except that `abs_sub` also propagates NaNs (also \
known as `fdim` in C). If you truly need the positive \
difference, consider using that expression or the C function \
`fdim`, depending on how you wish to handle NaN (please consider \
filing an issue describing your use-case too).")]
pub fn abs_sub(self, other: f64) -> f64 {
unsafe { cmath::fdim(self, other) }
}
pub fn abs_sub(self, other: f64) -> f64 {
unsafe { cmath::fdim(self, other) }
}

/// Takes the cubic root of a number.
///
Expand Down Expand Up @@ -833,7 +833,7 @@ impl f64 {
if self == NEG_INFINITY {
NEG_INFINITY
} else {
(self + ((self * self) + 1.0).sqrt()).ln()
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
}
}

Expand All @@ -852,9 +852,10 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn acosh(self) -> f64 {
match self {
x if x < 1.0 => NAN,
x => (x + ((x * x) - 1.0).sqrt()).ln(),
if self < 1.0 {
NAN
} else {
(self + ((self * self) - 1.0).sqrt()).ln()
}
}

Expand Down Expand Up @@ -1187,7 +1188,7 @@ mod tests {
assert_eq!((-0f64).abs(), 0f64);
assert_eq!((-1f64).abs(), 1f64);
assert_eq!(NEG_INFINITY.abs(), INFINITY);
assert_eq!((1f64/NEG_INFINITY).abs(), 0f64);
assert_eq!((1f64 / NEG_INFINITY).abs(), 0f64);
assert!(NAN.abs().is_nan());
}

Expand All @@ -1199,7 +1200,7 @@ mod tests {
assert_eq!((-0f64).signum(), -1f64);
assert_eq!((-1f64).signum(), -1f64);
assert_eq!(NEG_INFINITY.signum(), -1f64);
assert_eq!((1f64/NEG_INFINITY).signum(), -1f64);
assert_eq!((1f64 / NEG_INFINITY).signum(), -1f64);
assert!(NAN.signum().is_nan());
}

Expand All @@ -1211,7 +1212,7 @@ mod tests {
assert!(!(-0f64).is_sign_positive());
assert!(!(-1f64).is_sign_positive());
assert!(!NEG_INFINITY.is_sign_positive());
assert!(!(1f64/NEG_INFINITY).is_sign_positive());
assert!(!(1f64 / NEG_INFINITY).is_sign_positive());
assert!(NAN.is_sign_positive());
assert!(!(-NAN).is_sign_positive());
}
Expand All @@ -1224,7 +1225,7 @@ mod tests {
assert!((-0f64).is_sign_negative());
assert!((-1f64).is_sign_negative());
assert!(NEG_INFINITY.is_sign_negative());
assert!((1f64/NEG_INFINITY).is_sign_negative());
assert!((1f64 / NEG_INFINITY).is_sign_negative());
assert!(!NAN.is_sign_negative());
assert!((-NAN).is_sign_negative());
}
Expand Down Expand Up @@ -1433,6 +1434,8 @@ mod tests {
assert_eq!(inf.asinh(), inf);
assert_eq!(neg_inf.asinh(), neg_inf);
assert!(nan.asinh().is_nan());
assert!((-0.0f64).asinh().is_sign_negative());
// issue 63271
assert_approx_eq!(2.0f64.asinh(), 1.443635475178810342493276740273105f64);
assert_approx_eq!((-2.0f64).asinh(), -1.443635475178810342493276740273105f64);
}
Expand Down

0 comments on commit 7e0afda

Please sign in to comment.