Skip to content

Commit fa0f7d0

Browse files
committed
Auto merge of #65495 - Centril:rollup-tguwjt5, r=Centril
Rollup of 8 pull requests Successful merges: - #65237 (Move debug_map assertions after check for err) - #65316 (make File::try_clone produce non-inheritable handles on Windows) - #65319 (InterpCx: make memory field public) - #65461 (Don't recommend ONCE_INIT in std::sync::Once) - #65465 (Move syntax::ext to a syntax_expand and refactor some attribute logic) - #65475 (add example for type_name) - #65478 (fmt::Write is about string slices, not byte slices) - #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

Lines changed: 27 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 9 additions & 7 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 40 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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};

0 commit comments

Comments
 (0)