Skip to content

Commit fa0f7d0

Browse files
committed
Auto merge of rust-lang#65495 - Centril:rollup-tguwjt5, r=Centril
Rollup of 8 pull requests Successful merges: - rust-lang#65237 (Move debug_map assertions after check for err) - rust-lang#65316 (make File::try_clone produce non-inheritable handles on Windows) - rust-lang#65319 (InterpCx: make memory field public) - rust-lang#65461 (Don't recommend ONCE_INIT in std::sync::Once) - rust-lang#65465 (Move syntax::ext to a syntax_expand and refactor some attribute logic) - rust-lang#65475 (add example for type_name) - rust-lang#65478 (fmt::Write is about string slices, not byte slices) - rust-lang#65486 (doc: fix typo in OsStrExt and OsStringExt) Failed merges: r? @ghost
2 parents b043380 + 060aedd commit fa0f7d0

File tree

134 files changed

+782
-634
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+782
-634
lines changed

Cargo.lock

+27
Original file line numberDiff line numberDiff line change
@@ -3112,6 +3112,7 @@ dependencies = [
31123112
"serialize",
31133113
"smallvec",
31143114
"syntax",
3115+
"syntax_expand",
31153116
"syntax_pos",
31163117
]
31173118

@@ -3427,6 +3428,7 @@ dependencies = [
34273428
"rustc_target",
34283429
"serialize",
34293430
"syntax",
3431+
"syntax_expand",
34303432
"syntax_pos",
34313433
"tempfile",
34323434
]
@@ -3559,6 +3561,7 @@ dependencies = [
35593561
"serialize",
35603562
"smallvec",
35613563
"syntax",
3564+
"syntax_expand",
35623565
"syntax_ext",
35633566
"syntax_pos",
35643567
"tempfile",
@@ -3630,6 +3633,7 @@ dependencies = [
36303633
"smallvec",
36313634
"stable_deref_trait",
36323635
"syntax",
3636+
"syntax_expand",
36333637
"syntax_pos",
36343638
]
36353639

@@ -3678,6 +3682,7 @@ dependencies = [
36783682
"rustc_index",
36793683
"rustc_target",
36803684
"syntax",
3685+
"syntax_expand",
36813686
"syntax_pos",
36823687
]
36833688

@@ -3695,6 +3700,7 @@ dependencies = [
36953700
"rustc",
36963701
"rustc_metadata",
36973702
"syntax",
3703+
"syntax_expand",
36983704
"syntax_pos",
36993705
]
37003706

@@ -3723,6 +3729,7 @@ dependencies = [
37233729
"rustc_metadata",
37243730
"smallvec",
37253731
"syntax",
3732+
"syntax_expand",
37263733
"syntax_pos",
37273734
]
37283735

@@ -4336,6 +4343,25 @@ dependencies = [
43364343
"syntax_pos",
43374344
]
43384345

4346+
[[package]]
4347+
name = "syntax_expand"
4348+
version = "0.0.0"
4349+
dependencies = [
4350+
"bitflags",
4351+
"lazy_static 1.3.0",
4352+
"log",
4353+
"rustc_data_structures",
4354+
"rustc_errors",
4355+
"rustc_index",
4356+
"rustc_lexer",
4357+
"rustc_target",
4358+
"scoped-tls",
4359+
"serialize",
4360+
"smallvec",
4361+
"syntax",
4362+
"syntax_pos",
4363+
]
4364+
43394365
[[package]]
43404366
name = "syntax_ext"
43414367
version = "0.0.0"
@@ -4347,6 +4373,7 @@ dependencies = [
43474373
"rustc_target",
43484374
"smallvec",
43494375
"syntax",
4376+
"syntax_expand",
43504377
"syntax_pos",
43514378
]
43524379

src/libcore/any.rs

+9
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,15 @@ impl TypeId {
445445
///
446446
/// The current implementation uses the same infrastructure as compiler
447447
/// diagnostics and debuginfo, but this is not guaranteed.
448+
///
449+
/// # Example
450+
///
451+
/// ```rust
452+
/// assert_eq!(
453+
/// std::any::type_name::<Option<String>>(),
454+
/// "core::option::Option<alloc::string::String>",
455+
/// );
456+
/// ```
448457
#[stable(feature = "type_name", since = "1.38.0")]
449458
#[rustc_const_unstable(feature = "const_type_name")]
450459
pub const fn type_name<T: ?Sized>() -> &'static str {

src/libcore/fmt/builders.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,10 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
775775
reason = "recently added",
776776
issue = "62482")]
777777
pub fn key(&mut self, key: &dyn fmt::Debug) -> &mut DebugMap<'a, 'b> {
778-
assert!(!self.has_key, "attempted to begin a new map entry \
779-
without completing the previous one");
780-
781778
self.result = self.result.and_then(|_| {
779+
assert!(!self.has_key, "attempted to begin a new map entry \
780+
without completing the previous one");
781+
782782
if self.is_pretty() {
783783
if !self.has_fields {
784784
self.fmt.write_str("\n")?;
@@ -839,9 +839,9 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
839839
reason = "recently added",
840840
issue = "62482")]
841841
pub fn value(&mut self, value: &dyn fmt::Debug) -> &mut DebugMap<'a, 'b> {
842-
assert!(self.has_key, "attempted to format a map value before its key");
843-
844842
self.result = self.result.and_then(|_| {
843+
assert!(self.has_key, "attempted to format a map value before its key");
844+
845845
if self.is_pretty() {
846846
let mut slot = None;
847847
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut self.state);
@@ -924,9 +924,11 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
924924
/// ```
925925
#[stable(feature = "debug_builders", since = "1.2.0")]
926926
pub fn finish(&mut self) -> fmt::Result {
927-
assert!(!self.has_key, "attempted to finish a map with a partial entry");
927+
self.result.and_then(|_| {
928+
assert!(!self.has_key, "attempted to finish a map with a partial entry");
928929

929-
self.result.and_then(|_| self.fmt.write_str("}"))
930+
self.fmt.write_str("}")
931+
})
930932
}
931933

932934
fn is_pretty(&self) -> bool {

src/libcore/fmt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ pub struct Error;
108108
/// [`io::Write`]: ../../std/io/trait.Write.html
109109
#[stable(feature = "rust1", since = "1.0.0")]
110110
pub trait Write {
111-
/// Writes a slice of bytes into this writer, returning whether the write
111+
/// Writes a string slice into this writer, returning whether the write
112112
/// succeeded.
113113
///
114-
/// This method can only succeed if the entire byte slice was successfully
114+
/// This method can only succeed if the entire string slice was successfully
115115
/// written, and this method will not return until all data has been
116116
/// written or an error occurs.
117117
///

src/libcore/tests/fmt/builders.rs

+40
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,46 @@ mod debug_map {
319319
format!("{:#?}", Bar));
320320
}
321321

322+
#[test]
323+
fn test_entry_err() {
324+
// Ensure errors in a map entry don't trigger panics (#65231)
325+
use std::fmt::Write;
326+
327+
struct ErrorFmt;
328+
329+
impl fmt::Debug for ErrorFmt {
330+
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
331+
Err(fmt::Error)
332+
}
333+
}
334+
335+
struct KeyValue<K, V>(usize, K, V);
336+
337+
impl<K, V> fmt::Debug for KeyValue<K, V>
338+
where
339+
K: fmt::Debug,
340+
V: fmt::Debug,
341+
{
342+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
343+
let mut map = fmt.debug_map();
344+
345+
for _ in 0..self.0 {
346+
map.entry(&self.1, &self.2);
347+
}
348+
349+
map.finish()
350+
}
351+
}
352+
353+
let mut buf = String::new();
354+
355+
assert!(write!(&mut buf, "{:?}", KeyValue(1, ErrorFmt, "bar")).is_err());
356+
assert!(write!(&mut buf, "{:?}", KeyValue(1, "foo", ErrorFmt)).is_err());
357+
358+
assert!(write!(&mut buf, "{:?}", KeyValue(2, ErrorFmt, "bar")).is_err());
359+
assert!(write!(&mut buf, "{:?}", KeyValue(2, "foo", ErrorFmt)).is_err());
360+
}
361+
322362
#[test]
323363
#[should_panic]
324364
fn test_invalid_key_when_entry_is_incomplete() {

src/librustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ rustc_index = { path = "../librustc_index" }
2929
errors = { path = "../librustc_errors", package = "rustc_errors" }
3030
rustc_serialize = { path = "../libserialize", package = "serialize" }
3131
syntax = { path = "../libsyntax" }
32+
syntax_expand = { path = "../libsyntax_expand" }
3233
syntax_pos = { path = "../libsyntax_pos" }
3334
backtrace = "0.3.3"
3435
parking_lot = "0.9"

src/librustc/hir/def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::ty;
66
use crate::util::nodemap::DefIdMap;
77

88
use syntax::ast;
9-
use syntax::ext::base::MacroKind;
9+
use syntax_expand::base::MacroKind;
1010
use syntax::ast::NodeId;
1111
use syntax_pos::Span;
1212
use rustc_macros::HashStable;

src/librustc/hir/lowering.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ use syntax::ast;
6464
use syntax::ptr::P as AstP;
6565
use syntax::ast::*;
6666
use syntax::errors;
67-
use syntax::ext::base::SpecialDerives;
68-
use syntax::ext::hygiene::ExpnId;
67+
use syntax_expand::base::SpecialDerives;
6968
use syntax::print::pprust;
70-
use syntax::tokenstream::{TokenStream, TokenTree};
7169
use syntax::parse::token::{self, Nonterminal, Token};
70+
use syntax::tokenstream::{TokenStream, TokenTree};
7271
use syntax::sess::ParseSess;
7372
use syntax::source_map::{respan, ExpnData, ExpnKind, DesugaringKind, Spanned};
7473
use syntax::symbol::{kw, sym, Symbol};
7574
use syntax::visit::{self, Visitor};
75+
use syntax_pos::hygiene::ExpnId;
7676
use syntax_pos::Span;
7777

7878
const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;

src/librustc/hir/lowering/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use smallvec::SmallVec;
1818
use syntax::attr;
1919
use syntax::ast::*;
2020
use syntax::visit::{self, Visitor};
21-
use syntax::ext::base::SpecialDerives;
21+
use syntax_expand::base::SpecialDerives;
2222
use syntax::source_map::{respan, DesugaringKind, Spanned};
2323
use syntax::symbol::{kw, sym};
2424
use syntax_pos::Span;

src/librustc/hir/map/def_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::hir::map::definitions::*;
22
use crate::hir::def_id::DefIndex;
33

44
use syntax::ast::*;
5-
use syntax::ext::hygiene::ExpnId;
5+
use syntax_expand::hygiene::ExpnId;
66
use syntax::visit;
77
use syntax::symbol::{kw, sym};
88
use syntax::parse::token::{self, Token};

src/librustc/hir/map/definitions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::borrow::Borrow;
1717
use std::fmt::Write;
1818
use std::hash::Hash;
1919
use syntax::ast;
20-
use syntax::ext::hygiene::ExpnId;
20+
use syntax_expand::hygiene::ExpnId;
2121
use syntax::symbol::{Symbol, sym, InternedString};
2222
use syntax_pos::{Span, DUMMY_SP};
2323

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_data_structures::svh::Svh;
2020
use rustc_index::vec::IndexVec;
2121
use syntax::ast::{self, Name, NodeId};
2222
use syntax::source_map::Spanned;
23-
use syntax::ext::base::MacroKind;
23+
use syntax_expand::base::MacroKind;
2424
use syntax_pos::{Span, DUMMY_SP};
2525

2626
pub mod blocks;

src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::cell::RefCell;
1313

1414
use syntax::ast;
1515
use syntax::source_map::SourceMap;
16-
use syntax::ext::hygiene::SyntaxContext;
16+
use syntax_expand::hygiene::SyntaxContext;
1717
use syntax::symbol::Symbol;
1818
use syntax::tokenstream::DelimSpan;
1919
use syntax_pos::{Span, DUMMY_SP};

src/librustc/ich/impls_syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl_stable_hash_for!(enum ::syntax::ast::AsmDialect {
5959
Intel
6060
});
6161

62-
impl_stable_hash_for!(enum ::syntax::ext::base::MacroKind {
62+
impl_stable_hash_for!(enum ::syntax_expand::base::MacroKind {
6363
Bang,
6464
Attr,
6565
Derive,

src/librustc/lint/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use syntax::ast;
3939
use syntax::source_map::{MultiSpan, ExpnKind, DesugaringKind};
4040
use syntax::early_buffered_lints::BufferedEarlyLintId;
4141
use syntax::edition::Edition;
42-
use syntax::ext::base::MacroKind;
42+
use syntax_expand::base::MacroKind;
4343
use syntax::symbol::{Symbol, sym};
4444
use syntax_pos::Span;
4545

src/librustc/session/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use errors::emitter::HumanReadableErrorType;
2424
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
2525
use syntax::ast::{self, NodeId};
2626
use syntax::edition::Edition;
27-
use syntax::ext::allocator::AllocatorKind;
27+
use syntax_expand::allocator::AllocatorKind;
2828
use syntax::feature_gate::{self, AttributeType};
2929
use syntax::json::JsonEmitter;
3030
use syntax::source_map;

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use std::{mem, ptr};
4545
use std::ops::Range;
4646
use syntax::ast::{self, Name, Ident, NodeId};
4747
use syntax::attr;
48-
use syntax::ext::hygiene::ExpnId;
48+
use syntax_expand::hygiene::ExpnId;
4949
use syntax::symbol::{kw, sym, Symbol, InternedString};
5050
use syntax_pos::Span;
5151

src/librustc_codegen_llvm/allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ffi::CString;
33
use crate::attributes;
44
use libc::c_uint;
55
use rustc::ty::TyCtxt;
6-
use syntax::ext::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
6+
use syntax_expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
77

88
use crate::ModuleLlvm;
99
use crate::llvm::{self, False, True};

src/librustc_codegen_llvm/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern crate rustc_driver as _;
3939

4040
#[macro_use] extern crate log;
4141
extern crate syntax;
42+
extern crate syntax_expand;
4243
extern crate syntax_pos;
4344
extern crate rustc_errors as errors;
4445

@@ -48,7 +49,7 @@ use rustc_codegen_ssa::back::lto::{SerializedModule, LtoModuleCodegen, ThinModul
4849
use rustc_codegen_ssa::CompiledModule;
4950
use errors::{FatalError, Handler};
5051
use rustc::dep_graph::WorkProduct;
51-
use syntax::ext::allocator::AllocatorKind;
52+
use syntax_expand::allocator::AllocatorKind;
5253
use syntax_pos::symbol::InternedString;
5354
pub use llvm_util::target_features;
5455
use std::any::Any;

src/librustc_codegen_ssa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tempfile = "3.1"
2121

2222
rustc_serialize = { path = "../libserialize", package = "serialize" }
2323
syntax = { path = "../libsyntax" }
24+
syntax_expand = { path = "../libsyntax_expand" }
2425
syntax_pos = { path = "../libsyntax_pos" }
2526
rustc = { path = "../librustc" }
2627
rustc_apfloat = { path = "../librustc_apfloat" }

src/librustc_codegen_ssa/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc::ty::query::Providers;
1414
use rustc::ty::subst::SubstsRef;
1515
use rustc::util::nodemap::{FxHashMap, DefIdMap};
1616
use rustc_index::vec::IndexVec;
17-
use syntax::ext::allocator::ALLOCATOR_METHODS;
17+
use syntax_expand::allocator::ALLOCATOR_METHODS;
1818

1919
pub type ExportedSymbols = FxHashMap<
2020
CrateNum,

src/librustc_codegen_ssa/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_errors::{Handler, Level, FatalError, DiagnosticId, SourceMapperDyn};
2727
use rustc_errors::emitter::{Emitter};
2828
use rustc_target::spec::MergeFunctions;
2929
use syntax::attr;
30-
use syntax::ext::hygiene::ExpnId;
30+
use syntax_expand::hygiene::ExpnId;
3131
use syntax_pos::symbol::{Symbol, sym};
3232
use jobserver::{Client, Acquired};
3333

src/librustc_codegen_ssa/traits/backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc::ty::TyCtxt;
99
use rustc_codegen_utils::codegen_backend::CodegenBackend;
1010
use std::sync::Arc;
1111
use std::sync::mpsc;
12-
use syntax::ext::allocator::AllocatorKind;
12+
use syntax_expand::allocator::AllocatorKind;
1313
use syntax_pos::symbol::InternedString;
1414

1515
pub trait BackendTypes {

src/librustc_interface/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rayon = { version = "0.3.0", package = "rustc-rayon" }
1515
smallvec = { version = "0.6.7", features = ["union", "may_dangle"] }
1616
syntax = { path = "../libsyntax" }
1717
syntax_ext = { path = "../libsyntax_ext" }
18+
syntax_expand = { path = "../libsyntax_expand" }
1819
syntax_pos = { path = "../libsyntax_pos" }
1920
rustc_serialize = { path = "../libserialize", package = "serialize" }
2021
rustc = { path = "../librustc" }

0 commit comments

Comments
 (0)