Skip to content

Commit 7e0afda

Browse files
committed
Auto merge of #63940 - Centril:rollup-47qe9gn, r=Centril
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
2 parents 0444b9f + 23116ba commit 7e0afda

38 files changed

+468
-240
lines changed

src/libproc_macro/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919

2020
#![feature(nll)]
2121
#![feature(staged_api)]
22+
#![feature(allow_internal_unstable)]
2223
#![feature(const_fn)]
24+
#![feature(decl_macro)]
2325
#![feature(extern_types)]
2426
#![feature(in_band_lifetimes)]
2527
#![feature(optin_builtin_traits)]
2628
#![feature(mem_take)]
2729
#![feature(non_exhaustive)]
30+
#![feature(rustc_attrs)]
2831
#![feature(specialization)]
2932

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

231233
#[unstable(feature = "proc_macro_internals", issue = "27812")]
232234
#[doc(hidden)]

src/libproc_macro/quote.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ macro_rules! quote {
5757
}
5858

5959
/// Quote a `TokenStream` into a `TokenStream`.
60-
/// This is the actual `quote!()` proc macro.
60+
/// This is the actual implementation of the `quote!()` proc macro.
6161
///
62-
/// It is manually loaded in `CStore::load_macro_untracked`.
62+
/// It is loaded by the compiler in `register_builtin_macros`.
6363
#[unstable(feature = "proc_macro_quote", issue = "54722")]
6464
pub fn quote(stream: TokenStream) -> TokenStream {
6565
if stream.is_empty() {

src/librustc_metadata/cstore.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ pub struct CrateMetadata {
9595
pub raw_proc_macros: Option<&'static [ProcMacro]>,
9696
}
9797

98-
pub struct FullProcMacro {
99-
pub name: ast::Name,
100-
pub ext: Lrc<SyntaxExtension>
101-
}
102-
10398
pub struct CStore {
10499
metas: RwLock<IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>>,
105100
/// Map from NodeId's of local extern crate statements to crate numbers
@@ -109,7 +104,7 @@ pub struct CStore {
109104

110105
pub enum LoadedMacro {
111106
MacroDef(ast::Item),
112-
ProcMacro(Lrc<SyntaxExtension>),
107+
ProcMacro(SyntaxExtension),
113108
}
114109

115110
impl CStore {

src/librustc_metadata/cstore_impl.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ use syntax::ast;
3030
use syntax::attr;
3131
use syntax::source_map;
3232
use syntax::edition::Edition;
33-
use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind};
34-
use syntax::ext::proc_macro::BangProcMacro;
3533
use syntax::parse::source_file_to_stream;
3634
use syntax::parse::parser::emit_unclosed_delims;
37-
use syntax::symbol::{Symbol, sym};
35+
use syntax::symbol::Symbol;
3836
use syntax_pos::{Span, FileName};
3937
use rustc_data_structures::bit_set::BitSet;
4038

@@ -436,15 +434,7 @@ impl cstore::CStore {
436434
pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
437435
let data = self.get_crate_data(id.krate);
438436
if data.is_proc_macro_crate() {
439-
return LoadedMacro::ProcMacro(data.get_proc_macro(id.index, sess).ext);
440-
} else if data.name == sym::proc_macro && data.item_name(id.index) == sym::quote {
441-
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
442-
let kind = SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client }));
443-
let ext = SyntaxExtension {
444-
allow_internal_unstable: Some([sym::proc_macro_def_site][..].into()),
445-
..SyntaxExtension::default(kind, data.root.edition)
446-
};
447-
return LoadedMacro::ProcMacro(Lrc::new(ext));
437+
return LoadedMacro::ProcMacro(data.load_proc_macro(id.index, sess));
448438
}
449439

450440
let def = data.get_macro(id.index);

src/librustc_metadata/decoder.rs

+17-32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Decoding metadata from a single crate's metadata
22

3-
use crate::cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule, FullProcMacro};
3+
use crate::cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary, ForeignModule};
44
use crate::schema::*;
55

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

515-
516-
pub fn get_proc_macro(&self, id: DefIndex, sess: &Session) -> FullProcMacro {
517-
if sess.opts.debugging_opts.dual_proc_macros {
518-
let host_lib = self.host_lib.as_ref().unwrap();
519-
self.load_proc_macro(
520-
&host_lib.metadata.get_root(),
521-
id,
522-
sess
523-
)
524-
} else {
525-
self.load_proc_macro(&self.root, id, sess)
526-
}
527-
}
528-
529-
fn load_proc_macro(&self, root: &CrateRoot<'_>,
530-
id: DefIndex,
531-
sess: &Session)
532-
-> FullProcMacro {
533-
534-
let raw_macro = self.raw_proc_macro(id);
535-
let (name, kind, helper_attrs) = match *raw_macro {
515+
crate fn load_proc_macro(&self, id: DefIndex, sess: &Session) -> SyntaxExtension {
516+
let (name, kind, helper_attrs) = match *self.raw_proc_macro(id) {
536517
ProcMacro::CustomDerive { trait_name, attributes, client } => {
537518
let helper_attrs =
538519
attributes.iter().cloned().map(Symbol::intern).collect::<Vec<_>>();
@@ -551,17 +532,21 @@ impl<'a, 'tcx> CrateMetadata {
551532
name, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })), Vec::new()
552533
)
553534
};
535+
let edition = if sess.opts.debugging_opts.dual_proc_macros {
536+
self.host_lib.as_ref().unwrap().metadata.get_root().edition
537+
} else {
538+
self.root.edition
539+
};
554540

555-
let span = self.get_span(id, sess);
556-
557-
FullProcMacro {
558-
name: Symbol::intern(name),
559-
ext: Lrc::new(SyntaxExtension {
560-
span,
561-
helper_attrs,
562-
..SyntaxExtension::default(kind, root.edition)
563-
})
564-
}
541+
SyntaxExtension::new(
542+
&sess.parse_sess,
543+
kind,
544+
self.get_span(id, sess),
545+
helper_attrs,
546+
edition,
547+
Symbol::intern(name),
548+
&self.get_attributes(&self.entry(id), sess),
549+
)
565550
}
566551

567552
pub fn get_trait_def(&self, item_id: DefIndex, sess: &Session) -> ty::TraitDef {

src/librustc_resolve/build_reduced_graph.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ impl<'a> Resolver<'a> {
150150
return Some(ext.clone());
151151
}
152152

153-
let macro_def = match self.cstore.load_macro_untracked(def_id, &self.session) {
154-
LoadedMacro::MacroDef(macro_def) => macro_def,
155-
LoadedMacro::ProcMacro(ext) => return Some(ext),
156-
};
153+
let ext = Lrc::new(match self.cstore.load_macro_untracked(def_id, &self.session) {
154+
LoadedMacro::MacroDef(item) =>
155+
self.compile_macro(&item, self.cstore.crate_edition_untracked(def_id.krate)),
156+
LoadedMacro::ProcMacro(ext) => ext,
157+
});
157158

158-
let ext = self.compile_macro(&macro_def, self.cstore.crate_edition_untracked(def_id.krate));
159159
self.macro_map.insert(def_id, ext.clone());
160160
Some(ext)
161161
}
@@ -1104,7 +1104,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11041104
let expansion = parent_scope.expansion;
11051105
let (ext, ident, span, is_legacy) = match &item.node {
11061106
ItemKind::MacroDef(def) => {
1107-
let ext = self.r.compile_macro(item, self.r.session.edition());
1107+
let ext = Lrc::new(self.r.compile_macro(item, self.r.session.edition()));
11081108
(ext, item.ident, item.span, def.legacy)
11091109
}
11101110
ItemKind::Fn(..) => match Self::proc_macro_stub(item) {

src/librustc_resolve/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ impl<'a> Resolver<'a> {
800800

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

825-
Lrc::new(result)
825+
result
826826
}
827827
}

src/librustc_typeck/check/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
44

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

268268
let is_fn = tcx.lang_items().fn_trait_kind(trait_ref.def_id()).is_some();
269-
let gen_trait = tcx.lang_items().gen_trait().unwrap();
269+
let gen_trait = tcx.require_lang_item(lang_items::GeneratorTraitLangItem);
270270
let is_gen = gen_trait == trait_ref.def_id();
271271
if !is_fn && !is_gen {
272272
debug!("deduce_sig_from_projection: not fn or generator");

src/librustdoc/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ pub fn test(mut options: Options, diag: &errors::Handler) -> i32 {
154154

155155
options.test_args.insert(0, "rustdoctest".to_string());
156156
testing::test_main(&options.test_args, collector.tests,
157-
testing::Options::new().display_output(options.display_warnings));
157+
Some(testing::Options::new().display_output(options.display_warnings)));
158158
0
159159
}

src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn run(options: Options) -> i32 {
120120
testing::test_main(
121121
&test_args,
122122
tests,
123-
testing::Options::new().display_output(display_warnings)
123+
Some(testing::Options::new().display_output(display_warnings))
124124
);
125125

126126
0

src/libstd/f32.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ impl f32 {
910910
if self == NEG_INFINITY {
911911
NEG_INFINITY
912912
} else {
913-
(self + ((self * self) + 1.0).sqrt()).ln()
913+
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
914914
}
915915
}
916916

@@ -931,9 +931,10 @@ impl f32 {
931931
#[stable(feature = "rust1", since = "1.0.0")]
932932
#[inline]
933933
pub fn acosh(self) -> f32 {
934-
match self {
935-
x if x < 1.0 => crate::f32::NAN,
936-
x => (x + ((x * x) - 1.0).sqrt()).ln(),
934+
if self < 1.0 {
935+
crate::f32::NAN
936+
} else {
937+
(self + ((self * self) - 1.0).sqrt()).ln()
937938
}
938939
}
939940

@@ -1487,6 +1488,7 @@ mod tests {
14871488
assert_eq!(inf.asinh(), inf);
14881489
assert_eq!(neg_inf.asinh(), neg_inf);
14891490
assert!(nan.asinh().is_nan());
1491+
assert!((-0.0f32).asinh().is_sign_negative()); // issue 63271
14901492
assert_approx_eq!(2.0f32.asinh(), 1.443635475178810342493276740273105f32);
14911493
assert_approx_eq!((-2.0f32).asinh(), -1.443635475178810342493276740273105f32);
14921494
}

src/libstd/f64.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl f64 {
244244
pub fn div_euclid(self, rhs: f64) -> f64 {
245245
let q = (self / rhs).trunc();
246246
if self % rhs < 0.0 {
247-
return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }
247+
return if rhs > 0.0 { q - 1.0 } else { q + 1.0 };
248248
}
249249
q
250250
}
@@ -437,9 +437,9 @@ impl f64 {
437437
pub fn log2(self) -> f64 {
438438
self.log_wrapper(|n| {
439439
#[cfg(target_os = "android")]
440-
return crate::sys::android::log2f64(n);
440+
return crate::sys::android::log2f64(n);
441441
#[cfg(not(target_os = "android"))]
442-
return unsafe { intrinsics::log2f64(n) };
442+
return unsafe { intrinsics::log2f64(n) };
443443
})
444444
}
445445

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

495495
/// Takes the cubic root of a number.
496496
///
@@ -833,7 +833,7 @@ impl f64 {
833833
if self == NEG_INFINITY {
834834
NEG_INFINITY
835835
} else {
836-
(self + ((self * self) + 1.0).sqrt()).ln()
836+
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
837837
}
838838
}
839839

@@ -852,9 +852,10 @@ impl f64 {
852852
#[stable(feature = "rust1", since = "1.0.0")]
853853
#[inline]
854854
pub fn acosh(self) -> f64 {
855-
match self {
856-
x if x < 1.0 => NAN,
857-
x => (x + ((x * x) - 1.0).sqrt()).ln(),
855+
if self < 1.0 {
856+
NAN
857+
} else {
858+
(self + ((self * self) - 1.0).sqrt()).ln()
858859
}
859860
}
860861

@@ -1187,7 +1188,7 @@ mod tests {
11871188
assert_eq!((-0f64).abs(), 0f64);
11881189
assert_eq!((-1f64).abs(), 1f64);
11891190
assert_eq!(NEG_INFINITY.abs(), INFINITY);
1190-
assert_eq!((1f64/NEG_INFINITY).abs(), 0f64);
1191+
assert_eq!((1f64 / NEG_INFINITY).abs(), 0f64);
11911192
assert!(NAN.abs().is_nan());
11921193
}
11931194

@@ -1199,7 +1200,7 @@ mod tests {
11991200
assert_eq!((-0f64).signum(), -1f64);
12001201
assert_eq!((-1f64).signum(), -1f64);
12011202
assert_eq!(NEG_INFINITY.signum(), -1f64);
1202-
assert_eq!((1f64/NEG_INFINITY).signum(), -1f64);
1203+
assert_eq!((1f64 / NEG_INFINITY).signum(), -1f64);
12031204
assert!(NAN.signum().is_nan());
12041205
}
12051206

@@ -1211,7 +1212,7 @@ mod tests {
12111212
assert!(!(-0f64).is_sign_positive());
12121213
assert!(!(-1f64).is_sign_positive());
12131214
assert!(!NEG_INFINITY.is_sign_positive());
1214-
assert!(!(1f64/NEG_INFINITY).is_sign_positive());
1215+
assert!(!(1f64 / NEG_INFINITY).is_sign_positive());
12151216
assert!(NAN.is_sign_positive());
12161217
assert!(!(-NAN).is_sign_positive());
12171218
}
@@ -1224,7 +1225,7 @@ mod tests {
12241225
assert!((-0f64).is_sign_negative());
12251226
assert!((-1f64).is_sign_negative());
12261227
assert!(NEG_INFINITY.is_sign_negative());
1227-
assert!((1f64/NEG_INFINITY).is_sign_negative());
1228+
assert!((1f64 / NEG_INFINITY).is_sign_negative());
12281229
assert!(!NAN.is_sign_negative());
12291230
assert!((-NAN).is_sign_negative());
12301231
}
@@ -1433,6 +1434,8 @@ mod tests {
14331434
assert_eq!(inf.asinh(), inf);
14341435
assert_eq!(neg_inf.asinh(), neg_inf);
14351436
assert!(nan.asinh().is_nan());
1437+
assert!((-0.0f64).asinh().is_sign_negative());
1438+
// issue 63271
14361439
assert_approx_eq!(2.0f64.asinh(), 1.443635475178810342493276740273105f64);
14371440
assert_approx_eq!((-2.0f64).asinh(), -1.443635475178810342493276740273105f64);
14381441
}

0 commit comments

Comments
 (0)