Skip to content

Commit 48fa913

Browse files
authored
Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu
Match <OsString as Debug>::fmt to that of str Fixes#114583.
2 parents 8b74790 + eb84efc commit 48fa913

8 files changed

Lines changed: 25 additions & 55 deletions

File tree

‎library/core/src/str/lossy.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usesuper::char::EscapeDebugExtArgs;
12
usesuper::from_utf8_unchecked;
23
usesuper::validations::utf8_char_width;
34
usecrate::fmt;
@@ -121,7 +122,11 @@ impl fmt::Debug for Debug<'_> {
121122
let valid = chunk.valid();
122123
letmut from = 0;
123124
for(i, c)in valid.char_indices(){
124-
let esc = c.escape_debug();
125+
let esc = c.escape_debug_ext(EscapeDebugExtArgs{
126+
escape_grapheme_extended:true,
127+
escape_single_quote:false,
128+
escape_double_quote:true,
129+
});
125130
// If char needs escaping, flush backlog so far and write, else skip
126131
if esc.len() != 1{
127132
f.write_str(&valid[from..i])?;

‎library/core/src/wtf8.rs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// implementations, so, we'll have to add more doc(hidden)s anyway
2020
#![doc(hidden)]
2121

22-
usecrate::char::encode_utf16_raw;
22+
usecrate::char::{EscapeDebugExtArgs,encode_utf16_raw};
2323
usecrate::clone::CloneToUninit;
2424
usecrate::fmt::{self,Write};
2525
usecrate::hash::{Hash,Hasher};
@@ -144,14 +144,20 @@ impl AsRef<[u8]> for Wtf8 {
144144
impl fmt::DebugforWtf8{
145145
fnfmt(&self,formatter:&mut fmt::Formatter<'_>) -> fmt::Result{
146146
fnwrite_str_escaped(f:&mut fmt::Formatter<'_>,s:&str) -> fmt::Result{
147-
usecrate::fmt::Write;
148-
for c in s.chars().flat_map(|c| c.escape_debug()){
147+
usecrate::fmt::Writeas _;
148+
for c in s.chars().flat_map(|c| {
149+
c.escape_debug_ext(EscapeDebugExtArgs{
150+
escape_grapheme_extended:true,
151+
escape_single_quote:false,
152+
escape_double_quote:true,
153+
})
154+
}){
149155
f.write_char(c)?
150156
}
151157
Ok(())
152158
}
153159

154-
formatter.write_str("\"")?;
160+
formatter.write_char('"')?;
155161
letmut pos = 0;
156162
whileletSome((surrogate_pos, surrogate)) = self.next_surrogate(pos){
157163
// SAFETY: next_surrogate provides an index for a range of valid UTF-8 bytes.
@@ -164,7 +170,7 @@ impl fmt::Debug for Wtf8 {
164170

165171
// SAFETY: after next_surrogate returns None, the remainder is valid UTF-8.
166172
write_str_escaped(formatter,unsafe{ str::from_utf8_unchecked(&self.bytes[pos..])})?;
167-
formatter.write_str("\"")
173+
formatter.write_char('"')
168174
}
169175
}
170176

‎library/coretests/tests/str_lossy.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ fn debug() {
8080
b"Hello\xC0\x80 There\xE6\x83 Goodbye\xf4\x8d\x93\xaa".utf8_chunks().debug(),
8181
),
8282
);
83+
assert_eq!("\"'\"",&format!("{:?}",b"'".utf8_chunks().debug()));
8384
}

‎library/std/src/env.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Iterator for Vars {
170170
impl fmt::DebugforVars{
171171
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
172172
letSelf{inner:VarsOs{ inner }} = self;
173-
f.debug_struct("Vars").field("inner",&inner.str_debug()).finish()
173+
f.debug_struct("Vars").field("inner", inner).finish()
174174
}
175175
}
176176

‎library/std/src/ffi/os_str/tests.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,9 @@ fn clone_to_uninit() {
303303
unsafe{ a.clone_to_uninit(ptr::from_mut::<OsStr>(&mut b).cast())};
304304
assert_eq!(a,&*b);
305305
}
306+
307+
#[test]
308+
fndebug(){
309+
let s = "'single quotes'";
310+
assert_eq!(format!("{:?}",OsStr::new(s)), format!("{:?}", s));
311+
}

‎library/std/src/sys/env/common.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,10 @@ pub struct Env {
55
iter: vec::IntoIter<(OsString,OsString)>,
66
}
77

8-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
9-
pubstructEnvStrDebug<'a>{
10-
slice:&'a[(OsString,OsString)],
11-
}
12-
13-
impl fmt::DebugforEnvStrDebug<'_>{
14-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
15-
f.debug_list()
16-
.entries(self.slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
17-
.finish()
18-
}
19-
}
20-
218
implEnv{
229
pub(super)fnnew(env:Vec<(OsString,OsString)>) -> Self{
2310
Env{iter: env.into_iter()}
2411
}
25-
26-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
27-
EnvStrDebug{slice:self.iter.as_slice()}
28-
}
2912
}
3013

3114
impl fmt::DebugforEnv{

‎library/std/src/sys/env/unsupported.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ use crate::{fmt, io};
33

44
pubstructEnv(!);
55

6-
implEnv{
7-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
8-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
9-
self.0
10-
}
11-
}
12-
136
impl fmt::DebugforEnv{
147
fnfmt(&self, _:&mut fmt::Formatter<'_>) -> fmt::Result{
158
self.0

‎library/std/src/sys/env/windows.rs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,6 @@ pub struct Env {
88
iter:EnvIterator,
99
}
1010

11-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
12-
pubstructEnvStrDebug<'a>{
13-
iter:&'aEnvIterator,
14-
}
15-
16-
impl fmt::DebugforEnvStrDebug<'_>{
17-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
18-
letSelf{ iter } = self;
19-
let iter:EnvIterator = (*iter).clone();
20-
letmut list = f.debug_list();
21-
for(a, b)in iter {
22-
list.entry(&(a.to_str().unwrap(), b.to_str().unwrap()));
23-
}
24-
list.finish()
25-
}
26-
}
27-
28-
implEnv{
29-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
30-
letSelf{base: _, iter } = self;
31-
EnvStrDebug{ iter }
32-
}
33-
}
34-
3511
impl fmt::DebugforEnv{
3612
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
3713
letSelf{base: _, iter } = self;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu · rust-lang/rust@48fa913 · GitHub
Skip to content

Commit 48fa913

Browse files
authored
Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu
Match <OsString as Debug>::fmt to that of str Fixes#114583.
2 parents 8b74790 + eb84efc commit 48fa913

8 files changed

Lines changed: 25 additions & 55 deletions

File tree

‎library/core/src/str/lossy.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usesuper::char::EscapeDebugExtArgs;
12
usesuper::from_utf8_unchecked;
23
usesuper::validations::utf8_char_width;
34
usecrate::fmt;
@@ -121,7 +122,11 @@ impl fmt::Debug for Debug<'_> {
121122
let valid = chunk.valid();
122123
letmut from = 0;
123124
for(i, c)in valid.char_indices(){
124-
let esc = c.escape_debug();
125+
let esc = c.escape_debug_ext(EscapeDebugExtArgs{
126+
escape_grapheme_extended:true,
127+
escape_single_quote:false,
128+
escape_double_quote:true,
129+
});
125130
// If char needs escaping, flush backlog so far and write, else skip
126131
if esc.len() != 1{
127132
f.write_str(&valid[from..i])?;

‎library/core/src/wtf8.rs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// implementations, so, we'll have to add more doc(hidden)s anyway
2020
#![doc(hidden)]
2121

22-
usecrate::char::encode_utf16_raw;
22+
usecrate::char::{EscapeDebugExtArgs,encode_utf16_raw};
2323
usecrate::clone::CloneToUninit;
2424
usecrate::fmt::{self,Write};
2525
usecrate::hash::{Hash,Hasher};
@@ -144,14 +144,20 @@ impl AsRef<[u8]> for Wtf8 {
144144
impl fmt::DebugforWtf8{
145145
fnfmt(&self,formatter:&mut fmt::Formatter<'_>) -> fmt::Result{
146146
fnwrite_str_escaped(f:&mut fmt::Formatter<'_>,s:&str) -> fmt::Result{
147-
usecrate::fmt::Write;
148-
for c in s.chars().flat_map(|c| c.escape_debug()){
147+
usecrate::fmt::Writeas _;
148+
for c in s.chars().flat_map(|c| {
149+
c.escape_debug_ext(EscapeDebugExtArgs{
150+
escape_grapheme_extended:true,
151+
escape_single_quote:false,
152+
escape_double_quote:true,
153+
})
154+
}){
149155
f.write_char(c)?
150156
}
151157
Ok(())
152158
}
153159

154-
formatter.write_str("\"")?;
160+
formatter.write_char('"')?;
155161
letmut pos = 0;
156162
whileletSome((surrogate_pos, surrogate)) = self.next_surrogate(pos){
157163
// SAFETY: next_surrogate provides an index for a range of valid UTF-8 bytes.
@@ -164,7 +170,7 @@ impl fmt::Debug for Wtf8 {
164170

165171
// SAFETY: after next_surrogate returns None, the remainder is valid UTF-8.
166172
write_str_escaped(formatter,unsafe{ str::from_utf8_unchecked(&self.bytes[pos..])})?;
167-
formatter.write_str("\"")
173+
formatter.write_char('"')
168174
}
169175
}
170176

‎library/coretests/tests/str_lossy.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ fn debug() {
8080
b"Hello\xC0\x80 There\xE6\x83 Goodbye\xf4\x8d\x93\xaa".utf8_chunks().debug(),
8181
),
8282
);
83+
assert_eq!("\"'\"",&format!("{:?}",b"'".utf8_chunks().debug()));
8384
}

‎library/std/src/env.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Iterator for Vars {
170170
impl fmt::DebugforVars{
171171
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
172172
letSelf{inner:VarsOs{ inner }} = self;
173-
f.debug_struct("Vars").field("inner",&inner.str_debug()).finish()
173+
f.debug_struct("Vars").field("inner", inner).finish()
174174
}
175175
}
176176

‎library/std/src/ffi/os_str/tests.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,9 @@ fn clone_to_uninit() {
303303
unsafe{ a.clone_to_uninit(ptr::from_mut::<OsStr>(&mut b).cast())};
304304
assert_eq!(a,&*b);
305305
}
306+
307+
#[test]
308+
fndebug(){
309+
let s = "'single quotes'";
310+
assert_eq!(format!("{:?}",OsStr::new(s)), format!("{:?}", s));
311+
}

‎library/std/src/sys/env/common.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,10 @@ pub struct Env {
55
iter: vec::IntoIter<(OsString,OsString)>,
66
}
77

8-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
9-
pubstructEnvStrDebug<'a>{
10-
slice:&'a[(OsString,OsString)],
11-
}
12-
13-
impl fmt::DebugforEnvStrDebug<'_>{
14-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
15-
f.debug_list()
16-
.entries(self.slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
17-
.finish()
18-
}
19-
}
20-
218
implEnv{
229
pub(super)fnnew(env:Vec<(OsString,OsString)>) -> Self{
2310
Env{iter: env.into_iter()}
2411
}
25-
26-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
27-
EnvStrDebug{slice:self.iter.as_slice()}
28-
}
2912
}
3013

3114
impl fmt::DebugforEnv{

‎library/std/src/sys/env/unsupported.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ use crate::{fmt, io};
33

44
pubstructEnv(!);
55

6-
implEnv{
7-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
8-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
9-
self.0
10-
}
11-
}
12-
136
impl fmt::DebugforEnv{
147
fnfmt(&self, _:&mut fmt::Formatter<'_>) -> fmt::Result{
158
self.0

‎library/std/src/sys/env/windows.rs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,6 @@ pub struct Env {
88
iter:EnvIterator,
99
}
1010

11-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
12-
pubstructEnvStrDebug<'a>{
13-
iter:&'aEnvIterator,
14-
}
15-
16-
impl fmt::DebugforEnvStrDebug<'_>{
17-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
18-
letSelf{ iter } = self;
19-
let iter:EnvIterator = (*iter).clone();
20-
letmut list = f.debug_list();
21-
for(a, b)in iter {
22-
list.entry(&(a.to_str().unwrap(), b.to_str().unwrap()));
23-
}
24-
list.finish()
25-
}
26-
}
27-
28-
implEnv{
29-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
30-
letSelf{base: _, iter } = self;
31-
EnvStrDebug{ iter }
32-
}
33-
}
34-
3511
impl fmt::DebugforEnv{
3612
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
3713
letSelf{base: _, iter } = self;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu · rust-lang/rust@48fa913 · GitHub
Skip to content

Commit 48fa913

Browse files
authored
Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu
Match <OsString as Debug>::fmt to that of str Fixes#114583.
2 parents 8b74790 + eb84efc commit 48fa913

8 files changed

Lines changed: 25 additions & 55 deletions

File tree

‎library/core/src/str/lossy.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usesuper::char::EscapeDebugExtArgs;
12
usesuper::from_utf8_unchecked;
23
usesuper::validations::utf8_char_width;
34
usecrate::fmt;
@@ -121,7 +122,11 @@ impl fmt::Debug for Debug<'_> {
121122
let valid = chunk.valid();
122123
letmut from = 0;
123124
for(i, c)in valid.char_indices(){
124-
let esc = c.escape_debug();
125+
let esc = c.escape_debug_ext(EscapeDebugExtArgs{
126+
escape_grapheme_extended:true,
127+
escape_single_quote:false,
128+
escape_double_quote:true,
129+
});
125130
// If char needs escaping, flush backlog so far and write, else skip
126131
if esc.len() != 1{
127132
f.write_str(&valid[from..i])?;

‎library/core/src/wtf8.rs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// implementations, so, we'll have to add more doc(hidden)s anyway
2020
#![doc(hidden)]
2121

22-
usecrate::char::encode_utf16_raw;
22+
usecrate::char::{EscapeDebugExtArgs,encode_utf16_raw};
2323
usecrate::clone::CloneToUninit;
2424
usecrate::fmt::{self,Write};
2525
usecrate::hash::{Hash,Hasher};
@@ -144,14 +144,20 @@ impl AsRef<[u8]> for Wtf8 {
144144
impl fmt::DebugforWtf8{
145145
fnfmt(&self,formatter:&mut fmt::Formatter<'_>) -> fmt::Result{
146146
fnwrite_str_escaped(f:&mut fmt::Formatter<'_>,s:&str) -> fmt::Result{
147-
usecrate::fmt::Write;
148-
for c in s.chars().flat_map(|c| c.escape_debug()){
147+
usecrate::fmt::Writeas _;
148+
for c in s.chars().flat_map(|c| {
149+
c.escape_debug_ext(EscapeDebugExtArgs{
150+
escape_grapheme_extended:true,
151+
escape_single_quote:false,
152+
escape_double_quote:true,
153+
})
154+
}){
149155
f.write_char(c)?
150156
}
151157
Ok(())
152158
}
153159

154-
formatter.write_str("\"")?;
160+
formatter.write_char('"')?;
155161
letmut pos = 0;
156162
whileletSome((surrogate_pos, surrogate)) = self.next_surrogate(pos){
157163
// SAFETY: next_surrogate provides an index for a range of valid UTF-8 bytes.
@@ -164,7 +170,7 @@ impl fmt::Debug for Wtf8 {
164170

165171
// SAFETY: after next_surrogate returns None, the remainder is valid UTF-8.
166172
write_str_escaped(formatter,unsafe{ str::from_utf8_unchecked(&self.bytes[pos..])})?;
167-
formatter.write_str("\"")
173+
formatter.write_char('"')
168174
}
169175
}
170176

‎library/coretests/tests/str_lossy.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ fn debug() {
8080
b"Hello\xC0\x80 There\xE6\x83 Goodbye\xf4\x8d\x93\xaa".utf8_chunks().debug(),
8181
),
8282
);
83+
assert_eq!("\"'\"",&format!("{:?}",b"'".utf8_chunks().debug()));
8384
}

‎library/std/src/env.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Iterator for Vars {
170170
impl fmt::DebugforVars{
171171
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
172172
letSelf{inner:VarsOs{ inner }} = self;
173-
f.debug_struct("Vars").field("inner",&inner.str_debug()).finish()
173+
f.debug_struct("Vars").field("inner", inner).finish()
174174
}
175175
}
176176

‎library/std/src/ffi/os_str/tests.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,9 @@ fn clone_to_uninit() {
303303
unsafe{ a.clone_to_uninit(ptr::from_mut::<OsStr>(&mut b).cast())};
304304
assert_eq!(a,&*b);
305305
}
306+
307+
#[test]
308+
fndebug(){
309+
let s = "'single quotes'";
310+
assert_eq!(format!("{:?}",OsStr::new(s)), format!("{:?}", s));
311+
}

‎library/std/src/sys/env/common.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,10 @@ pub struct Env {
55
iter: vec::IntoIter<(OsString,OsString)>,
66
}
77

8-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
9-
pubstructEnvStrDebug<'a>{
10-
slice:&'a[(OsString,OsString)],
11-
}
12-
13-
impl fmt::DebugforEnvStrDebug<'_>{
14-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
15-
f.debug_list()
16-
.entries(self.slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
17-
.finish()
18-
}
19-
}
20-
218
implEnv{
229
pub(super)fnnew(env:Vec<(OsString,OsString)>) -> Self{
2310
Env{iter: env.into_iter()}
2411
}
25-
26-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
27-
EnvStrDebug{slice:self.iter.as_slice()}
28-
}
2912
}
3013

3114
impl fmt::DebugforEnv{

‎library/std/src/sys/env/unsupported.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ use crate::{fmt, io};
33

44
pubstructEnv(!);
55

6-
implEnv{
7-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
8-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
9-
self.0
10-
}
11-
}
12-
136
impl fmt::DebugforEnv{
147
fnfmt(&self, _:&mut fmt::Formatter<'_>) -> fmt::Result{
158
self.0

‎library/std/src/sys/env/windows.rs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,6 @@ pub struct Env {
88
iter:EnvIterator,
99
}
1010

11-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
12-
pubstructEnvStrDebug<'a>{
13-
iter:&'aEnvIterator,
14-
}
15-
16-
impl fmt::DebugforEnvStrDebug<'_>{
17-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
18-
letSelf{ iter } = self;
19-
let iter:EnvIterator = (*iter).clone();
20-
letmut list = f.debug_list();
21-
for(a, b)in iter {
22-
list.entry(&(a.to_str().unwrap(), b.to_str().unwrap()));
23-
}
24-
list.finish()
25-
}
26-
}
27-
28-
implEnv{
29-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
30-
letSelf{base: _, iter } = self;
31-
EnvStrDebug{ iter }
32-
}
33-
}
34-
3511
impl fmt::DebugforEnv{
3612
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
3713
letSelf{base: _, iter } = self;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu · rust-lang/rust@48fa913 · GitHub
Skip to content

Commit 48fa913

Browse files
authored
Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu
Match <OsString as Debug>::fmt to that of str Fixes#114583.
2 parents 8b74790 + eb84efc commit 48fa913

8 files changed

Lines changed: 25 additions & 55 deletions

File tree

‎library/core/src/str/lossy.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usesuper::char::EscapeDebugExtArgs;
12
usesuper::from_utf8_unchecked;
23
usesuper::validations::utf8_char_width;
34
usecrate::fmt;
@@ -121,7 +122,11 @@ impl fmt::Debug for Debug<'_> {
121122
let valid = chunk.valid();
122123
letmut from = 0;
123124
for(i, c)in valid.char_indices(){
124-
let esc = c.escape_debug();
125+
let esc = c.escape_debug_ext(EscapeDebugExtArgs{
126+
escape_grapheme_extended:true,
127+
escape_single_quote:false,
128+
escape_double_quote:true,
129+
});
125130
// If char needs escaping, flush backlog so far and write, else skip
126131
if esc.len() != 1{
127132
f.write_str(&valid[from..i])?;

‎library/core/src/wtf8.rs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// implementations, so, we'll have to add more doc(hidden)s anyway
2020
#![doc(hidden)]
2121

22-
usecrate::char::encode_utf16_raw;
22+
usecrate::char::{EscapeDebugExtArgs,encode_utf16_raw};
2323
usecrate::clone::CloneToUninit;
2424
usecrate::fmt::{self,Write};
2525
usecrate::hash::{Hash,Hasher};
@@ -144,14 +144,20 @@ impl AsRef<[u8]> for Wtf8 {
144144
impl fmt::DebugforWtf8{
145145
fnfmt(&self,formatter:&mut fmt::Formatter<'_>) -> fmt::Result{
146146
fnwrite_str_escaped(f:&mut fmt::Formatter<'_>,s:&str) -> fmt::Result{
147-
usecrate::fmt::Write;
148-
for c in s.chars().flat_map(|c| c.escape_debug()){
147+
usecrate::fmt::Writeas _;
148+
for c in s.chars().flat_map(|c| {
149+
c.escape_debug_ext(EscapeDebugExtArgs{
150+
escape_grapheme_extended:true,
151+
escape_single_quote:false,
152+
escape_double_quote:true,
153+
})
154+
}){
149155
f.write_char(c)?
150156
}
151157
Ok(())
152158
}
153159

154-
formatter.write_str("\"")?;
160+
formatter.write_char('"')?;
155161
letmut pos = 0;
156162
whileletSome((surrogate_pos, surrogate)) = self.next_surrogate(pos){
157163
// SAFETY: next_surrogate provides an index for a range of valid UTF-8 bytes.
@@ -164,7 +170,7 @@ impl fmt::Debug for Wtf8 {
164170

165171
// SAFETY: after next_surrogate returns None, the remainder is valid UTF-8.
166172
write_str_escaped(formatter,unsafe{ str::from_utf8_unchecked(&self.bytes[pos..])})?;
167-
formatter.write_str("\"")
173+
formatter.write_char('"')
168174
}
169175
}
170176

‎library/coretests/tests/str_lossy.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ fn debug() {
8080
b"Hello\xC0\x80 There\xE6\x83 Goodbye\xf4\x8d\x93\xaa".utf8_chunks().debug(),
8181
),
8282
);
83+
assert_eq!("\"'\"",&format!("{:?}",b"'".utf8_chunks().debug()));
8384
}

‎library/std/src/env.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Iterator for Vars {
170170
impl fmt::DebugforVars{
171171
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
172172
letSelf{inner:VarsOs{ inner }} = self;
173-
f.debug_struct("Vars").field("inner",&inner.str_debug()).finish()
173+
f.debug_struct("Vars").field("inner", inner).finish()
174174
}
175175
}
176176

‎library/std/src/ffi/os_str/tests.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,9 @@ fn clone_to_uninit() {
303303
unsafe{ a.clone_to_uninit(ptr::from_mut::<OsStr>(&mut b).cast())};
304304
assert_eq!(a,&*b);
305305
}
306+
307+
#[test]
308+
fndebug(){
309+
let s = "'single quotes'";
310+
assert_eq!(format!("{:?}",OsStr::new(s)), format!("{:?}", s));
311+
}

‎library/std/src/sys/env/common.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,10 @@ pub struct Env {
55
iter: vec::IntoIter<(OsString,OsString)>,
66
}
77

8-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
9-
pubstructEnvStrDebug<'a>{
10-
slice:&'a[(OsString,OsString)],
11-
}
12-
13-
impl fmt::DebugforEnvStrDebug<'_>{
14-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
15-
f.debug_list()
16-
.entries(self.slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
17-
.finish()
18-
}
19-
}
20-
218
implEnv{
229
pub(super)fnnew(env:Vec<(OsString,OsString)>) -> Self{
2310
Env{iter: env.into_iter()}
2411
}
25-
26-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
27-
EnvStrDebug{slice:self.iter.as_slice()}
28-
}
2912
}
3013

3114
impl fmt::DebugforEnv{

‎library/std/src/sys/env/unsupported.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ use crate::{fmt, io};
33

44
pubstructEnv(!);
55

6-
implEnv{
7-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
8-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
9-
self.0
10-
}
11-
}
12-
136
impl fmt::DebugforEnv{
147
fnfmt(&self, _:&mut fmt::Formatter<'_>) -> fmt::Result{
158
self.0

‎library/std/src/sys/env/windows.rs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,6 @@ pub struct Env {
88
iter:EnvIterator,
99
}
1010

11-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
12-
pubstructEnvStrDebug<'a>{
13-
iter:&'aEnvIterator,
14-
}
15-
16-
impl fmt::DebugforEnvStrDebug<'_>{
17-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
18-
letSelf{ iter } = self;
19-
let iter:EnvIterator = (*iter).clone();
20-
letmut list = f.debug_list();
21-
for(a, b)in iter {
22-
list.entry(&(a.to_str().unwrap(), b.to_str().unwrap()));
23-
}
24-
list.finish()
25-
}
26-
}
27-
28-
implEnv{
29-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
30-
letSelf{base: _, iter } = self;
31-
EnvStrDebug{ iter }
32-
}
33-
}
34-
3511
impl fmt::DebugforEnv{
3612
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
3713
letSelf{base: _, iter } = self;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu · rust-lang/rust@48fa913 · GitHub
Skip to content

Commit 48fa913

Browse files
authored
Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu
Match <OsString as Debug>::fmt to that of str Fixes#114583.
2 parents 8b74790 + eb84efc commit 48fa913

8 files changed

Lines changed: 25 additions & 55 deletions

File tree

‎library/core/src/str/lossy.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usesuper::char::EscapeDebugExtArgs;
12
usesuper::from_utf8_unchecked;
23
usesuper::validations::utf8_char_width;
34
usecrate::fmt;
@@ -121,7 +122,11 @@ impl fmt::Debug for Debug<'_> {
121122
let valid = chunk.valid();
122123
letmut from = 0;
123124
for(i, c)in valid.char_indices(){
124-
let esc = c.escape_debug();
125+
let esc = c.escape_debug_ext(EscapeDebugExtArgs{
126+
escape_grapheme_extended:true,
127+
escape_single_quote:false,
128+
escape_double_quote:true,
129+
});
125130
// If char needs escaping, flush backlog so far and write, else skip
126131
if esc.len() != 1{
127132
f.write_str(&valid[from..i])?;

‎library/core/src/wtf8.rs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// implementations, so, we'll have to add more doc(hidden)s anyway
2020
#![doc(hidden)]
2121

22-
usecrate::char::encode_utf16_raw;
22+
usecrate::char::{EscapeDebugExtArgs,encode_utf16_raw};
2323
usecrate::clone::CloneToUninit;
2424
usecrate::fmt::{self,Write};
2525
usecrate::hash::{Hash,Hasher};
@@ -144,14 +144,20 @@ impl AsRef<[u8]> for Wtf8 {
144144
impl fmt::DebugforWtf8{
145145
fnfmt(&self,formatter:&mut fmt::Formatter<'_>) -> fmt::Result{
146146
fnwrite_str_escaped(f:&mut fmt::Formatter<'_>,s:&str) -> fmt::Result{
147-
usecrate::fmt::Write;
148-
for c in s.chars().flat_map(|c| c.escape_debug()){
147+
usecrate::fmt::Writeas _;
148+
for c in s.chars().flat_map(|c| {
149+
c.escape_debug_ext(EscapeDebugExtArgs{
150+
escape_grapheme_extended:true,
151+
escape_single_quote:false,
152+
escape_double_quote:true,
153+
})
154+
}){
149155
f.write_char(c)?
150156
}
151157
Ok(())
152158
}
153159

154-
formatter.write_str("\"")?;
160+
formatter.write_char('"')?;
155161
letmut pos = 0;
156162
whileletSome((surrogate_pos, surrogate)) = self.next_surrogate(pos){
157163
// SAFETY: next_surrogate provides an index for a range of valid UTF-8 bytes.
@@ -164,7 +170,7 @@ impl fmt::Debug for Wtf8 {
164170

165171
// SAFETY: after next_surrogate returns None, the remainder is valid UTF-8.
166172
write_str_escaped(formatter,unsafe{ str::from_utf8_unchecked(&self.bytes[pos..])})?;
167-
formatter.write_str("\"")
173+
formatter.write_char('"')
168174
}
169175
}
170176

‎library/coretests/tests/str_lossy.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ fn debug() {
8080
b"Hello\xC0\x80 There\xE6\x83 Goodbye\xf4\x8d\x93\xaa".utf8_chunks().debug(),
8181
),
8282
);
83+
assert_eq!("\"'\"",&format!("{:?}",b"'".utf8_chunks().debug()));
8384
}

‎library/std/src/env.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Iterator for Vars {
170170
impl fmt::DebugforVars{
171171
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
172172
letSelf{inner:VarsOs{ inner }} = self;
173-
f.debug_struct("Vars").field("inner",&inner.str_debug()).finish()
173+
f.debug_struct("Vars").field("inner", inner).finish()
174174
}
175175
}
176176

‎library/std/src/ffi/os_str/tests.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,9 @@ fn clone_to_uninit() {
303303
unsafe{ a.clone_to_uninit(ptr::from_mut::<OsStr>(&mut b).cast())};
304304
assert_eq!(a,&*b);
305305
}
306+
307+
#[test]
308+
fndebug(){
309+
let s = "'single quotes'";
310+
assert_eq!(format!("{:?}",OsStr::new(s)), format!("{:?}", s));
311+
}

‎library/std/src/sys/env/common.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,10 @@ pub struct Env {
55
iter: vec::IntoIter<(OsString,OsString)>,
66
}
77

8-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
9-
pubstructEnvStrDebug<'a>{
10-
slice:&'a[(OsString,OsString)],
11-
}
12-
13-
impl fmt::DebugforEnvStrDebug<'_>{
14-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
15-
f.debug_list()
16-
.entries(self.slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
17-
.finish()
18-
}
19-
}
20-
218
implEnv{
229
pub(super)fnnew(env:Vec<(OsString,OsString)>) -> Self{
2310
Env{iter: env.into_iter()}
2411
}
25-
26-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
27-
EnvStrDebug{slice:self.iter.as_slice()}
28-
}
2912
}
3013

3114
impl fmt::DebugforEnv{

‎library/std/src/sys/env/unsupported.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ use crate::{fmt, io};
33

44
pubstructEnv(!);
55

6-
implEnv{
7-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
8-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
9-
self.0
10-
}
11-
}
12-
136
impl fmt::DebugforEnv{
147
fnfmt(&self, _:&mut fmt::Formatter<'_>) -> fmt::Result{
158
self.0

‎library/std/src/sys/env/windows.rs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,6 @@ pub struct Env {
88
iter:EnvIterator,
99
}
1010

11-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
12-
pubstructEnvStrDebug<'a>{
13-
iter:&'aEnvIterator,
14-
}
15-
16-
impl fmt::DebugforEnvStrDebug<'_>{
17-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
18-
letSelf{ iter } = self;
19-
let iter:EnvIterator = (*iter).clone();
20-
letmut list = f.debug_list();
21-
for(a, b)in iter {
22-
list.entry(&(a.to_str().unwrap(), b.to_str().unwrap()));
23-
}
24-
list.finish()
25-
}
26-
}
27-
28-
implEnv{
29-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
30-
letSelf{base: _, iter } = self;
31-
EnvStrDebug{ iter }
32-
}
33-
}
34-
3511
impl fmt::DebugforEnv{
3612
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
3713
letSelf{base: _, iter } = self;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu · rust-lang/rust@48fa913 · GitHub
Skip to content

Commit 48fa913

Browse files
authored
Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu
Match <OsString as Debug>::fmt to that of str Fixes#114583.
2 parents 8b74790 + eb84efc commit 48fa913

8 files changed

Lines changed: 25 additions & 55 deletions

File tree

‎library/core/src/str/lossy.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usesuper::char::EscapeDebugExtArgs;
12
usesuper::from_utf8_unchecked;
23
usesuper::validations::utf8_char_width;
34
usecrate::fmt;
@@ -121,7 +122,11 @@ impl fmt::Debug for Debug<'_> {
121122
let valid = chunk.valid();
122123
letmut from = 0;
123124
for(i, c)in valid.char_indices(){
124-
let esc = c.escape_debug();
125+
let esc = c.escape_debug_ext(EscapeDebugExtArgs{
126+
escape_grapheme_extended:true,
127+
escape_single_quote:false,
128+
escape_double_quote:true,
129+
});
125130
// If char needs escaping, flush backlog so far and write, else skip
126131
if esc.len() != 1{
127132
f.write_str(&valid[from..i])?;

‎library/core/src/wtf8.rs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// implementations, so, we'll have to add more doc(hidden)s anyway
2020
#![doc(hidden)]
2121

22-
usecrate::char::encode_utf16_raw;
22+
usecrate::char::{EscapeDebugExtArgs,encode_utf16_raw};
2323
usecrate::clone::CloneToUninit;
2424
usecrate::fmt::{self,Write};
2525
usecrate::hash::{Hash,Hasher};
@@ -144,14 +144,20 @@ impl AsRef<[u8]> for Wtf8 {
144144
impl fmt::DebugforWtf8{
145145
fnfmt(&self,formatter:&mut fmt::Formatter<'_>) -> fmt::Result{
146146
fnwrite_str_escaped(f:&mut fmt::Formatter<'_>,s:&str) -> fmt::Result{
147-
usecrate::fmt::Write;
148-
for c in s.chars().flat_map(|c| c.escape_debug()){
147+
usecrate::fmt::Writeas _;
148+
for c in s.chars().flat_map(|c| {
149+
c.escape_debug_ext(EscapeDebugExtArgs{
150+
escape_grapheme_extended:true,
151+
escape_single_quote:false,
152+
escape_double_quote:true,
153+
})
154+
}){
149155
f.write_char(c)?
150156
}
151157
Ok(())
152158
}
153159

154-
formatter.write_str("\"")?;
160+
formatter.write_char('"')?;
155161
letmut pos = 0;
156162
whileletSome((surrogate_pos, surrogate)) = self.next_surrogate(pos){
157163
// SAFETY: next_surrogate provides an index for a range of valid UTF-8 bytes.
@@ -164,7 +170,7 @@ impl fmt::Debug for Wtf8 {
164170

165171
// SAFETY: after next_surrogate returns None, the remainder is valid UTF-8.
166172
write_str_escaped(formatter,unsafe{ str::from_utf8_unchecked(&self.bytes[pos..])})?;
167-
formatter.write_str("\"")
173+
formatter.write_char('"')
168174
}
169175
}
170176

‎library/coretests/tests/str_lossy.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ fn debug() {
8080
b"Hello\xC0\x80 There\xE6\x83 Goodbye\xf4\x8d\x93\xaa".utf8_chunks().debug(),
8181
),
8282
);
83+
assert_eq!("\"'\"",&format!("{:?}",b"'".utf8_chunks().debug()));
8384
}

‎library/std/src/env.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Iterator for Vars {
170170
impl fmt::DebugforVars{
171171
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
172172
letSelf{inner:VarsOs{ inner }} = self;
173-
f.debug_struct("Vars").field("inner",&inner.str_debug()).finish()
173+
f.debug_struct("Vars").field("inner", inner).finish()
174174
}
175175
}
176176

‎library/std/src/ffi/os_str/tests.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,9 @@ fn clone_to_uninit() {
303303
unsafe{ a.clone_to_uninit(ptr::from_mut::<OsStr>(&mut b).cast())};
304304
assert_eq!(a,&*b);
305305
}
306+
307+
#[test]
308+
fndebug(){
309+
let s = "'single quotes'";
310+
assert_eq!(format!("{:?}",OsStr::new(s)), format!("{:?}", s));
311+
}

‎library/std/src/sys/env/common.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,10 @@ pub struct Env {
55
iter: vec::IntoIter<(OsString,OsString)>,
66
}
77

8-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
9-
pubstructEnvStrDebug<'a>{
10-
slice:&'a[(OsString,OsString)],
11-
}
12-
13-
impl fmt::DebugforEnvStrDebug<'_>{
14-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
15-
f.debug_list()
16-
.entries(self.slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
17-
.finish()
18-
}
19-
}
20-
218
implEnv{
229
pub(super)fnnew(env:Vec<(OsString,OsString)>) -> Self{
2310
Env{iter: env.into_iter()}
2411
}
25-
26-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
27-
EnvStrDebug{slice:self.iter.as_slice()}
28-
}
2912
}
3013

3114
impl fmt::DebugforEnv{

‎library/std/src/sys/env/unsupported.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ use crate::{fmt, io};
33

44
pubstructEnv(!);
55

6-
implEnv{
7-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
8-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
9-
self.0
10-
}
11-
}
12-
136
impl fmt::DebugforEnv{
147
fnfmt(&self, _:&mut fmt::Formatter<'_>) -> fmt::Result{
158
self.0

‎library/std/src/sys/env/windows.rs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,6 @@ pub struct Env {
88
iter:EnvIterator,
99
}
1010

11-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
12-
pubstructEnvStrDebug<'a>{
13-
iter:&'aEnvIterator,
14-
}
15-
16-
impl fmt::DebugforEnvStrDebug<'_>{
17-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
18-
letSelf{ iter } = self;
19-
let iter:EnvIterator = (*iter).clone();
20-
letmut list = f.debug_list();
21-
for(a, b)in iter {
22-
list.entry(&(a.to_str().unwrap(), b.to_str().unwrap()));
23-
}
24-
list.finish()
25-
}
26-
}
27-
28-
implEnv{
29-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
30-
letSelf{base: _, iter } = self;
31-
EnvStrDebug{ iter }
32-
}
33-
}
34-
3511
impl fmt::DebugforEnv{
3612
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
3713
letSelf{base: _, iter } = self;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu · rust-lang/rust@48fa913 · GitHub
Skip to content

Commit 48fa913

Browse files
authored
Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu
Match <OsString as Debug>::fmt to that of str Fixes#114583.
2 parents 8b74790 + eb84efc commit 48fa913

8 files changed

Lines changed: 25 additions & 55 deletions

File tree

‎library/core/src/str/lossy.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usesuper::char::EscapeDebugExtArgs;
12
usesuper::from_utf8_unchecked;
23
usesuper::validations::utf8_char_width;
34
usecrate::fmt;
@@ -121,7 +122,11 @@ impl fmt::Debug for Debug<'_> {
121122
let valid = chunk.valid();
122123
letmut from = 0;
123124
for(i, c)in valid.char_indices(){
124-
let esc = c.escape_debug();
125+
let esc = c.escape_debug_ext(EscapeDebugExtArgs{
126+
escape_grapheme_extended:true,
127+
escape_single_quote:false,
128+
escape_double_quote:true,
129+
});
125130
// If char needs escaping, flush backlog so far and write, else skip
126131
if esc.len() != 1{
127132
f.write_str(&valid[from..i])?;

‎library/core/src/wtf8.rs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// implementations, so, we'll have to add more doc(hidden)s anyway
2020
#![doc(hidden)]
2121

22-
usecrate::char::encode_utf16_raw;
22+
usecrate::char::{EscapeDebugExtArgs,encode_utf16_raw};
2323
usecrate::clone::CloneToUninit;
2424
usecrate::fmt::{self,Write};
2525
usecrate::hash::{Hash,Hasher};
@@ -144,14 +144,20 @@ impl AsRef<[u8]> for Wtf8 {
144144
impl fmt::DebugforWtf8{
145145
fnfmt(&self,formatter:&mut fmt::Formatter<'_>) -> fmt::Result{
146146
fnwrite_str_escaped(f:&mut fmt::Formatter<'_>,s:&str) -> fmt::Result{
147-
usecrate::fmt::Write;
148-
for c in s.chars().flat_map(|c| c.escape_debug()){
147+
usecrate::fmt::Writeas _;
148+
for c in s.chars().flat_map(|c| {
149+
c.escape_debug_ext(EscapeDebugExtArgs{
150+
escape_grapheme_extended:true,
151+
escape_single_quote:false,
152+
escape_double_quote:true,
153+
})
154+
}){
149155
f.write_char(c)?
150156
}
151157
Ok(())
152158
}
153159

154-
formatter.write_str("\"")?;
160+
formatter.write_char('"')?;
155161
letmut pos = 0;
156162
whileletSome((surrogate_pos, surrogate)) = self.next_surrogate(pos){
157163
// SAFETY: next_surrogate provides an index for a range of valid UTF-8 bytes.
@@ -164,7 +170,7 @@ impl fmt::Debug for Wtf8 {
164170

165171
// SAFETY: after next_surrogate returns None, the remainder is valid UTF-8.
166172
write_str_escaped(formatter,unsafe{ str::from_utf8_unchecked(&self.bytes[pos..])})?;
167-
formatter.write_str("\"")
173+
formatter.write_char('"')
168174
}
169175
}
170176

‎library/coretests/tests/str_lossy.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ fn debug() {
8080
b"Hello\xC0\x80 There\xE6\x83 Goodbye\xf4\x8d\x93\xaa".utf8_chunks().debug(),
8181
),
8282
);
83+
assert_eq!("\"'\"",&format!("{:?}",b"'".utf8_chunks().debug()));
8384
}

‎library/std/src/env.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Iterator for Vars {
170170
impl fmt::DebugforVars{
171171
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
172172
letSelf{inner:VarsOs{ inner }} = self;
173-
f.debug_struct("Vars").field("inner",&inner.str_debug()).finish()
173+
f.debug_struct("Vars").field("inner", inner).finish()
174174
}
175175
}
176176

‎library/std/src/ffi/os_str/tests.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,9 @@ fn clone_to_uninit() {
303303
unsafe{ a.clone_to_uninit(ptr::from_mut::<OsStr>(&mut b).cast())};
304304
assert_eq!(a,&*b);
305305
}
306+
307+
#[test]
308+
fndebug(){
309+
let s = "'single quotes'";
310+
assert_eq!(format!("{:?}",OsStr::new(s)), format!("{:?}", s));
311+
}

‎library/std/src/sys/env/common.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,10 @@ pub struct Env {
55
iter: vec::IntoIter<(OsString,OsString)>,
66
}
77

8-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
9-
pubstructEnvStrDebug<'a>{
10-
slice:&'a[(OsString,OsString)],
11-
}
12-
13-
impl fmt::DebugforEnvStrDebug<'_>{
14-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
15-
f.debug_list()
16-
.entries(self.slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
17-
.finish()
18-
}
19-
}
20-
218
implEnv{
229
pub(super)fnnew(env:Vec<(OsString,OsString)>) -> Self{
2310
Env{iter: env.into_iter()}
2411
}
25-
26-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
27-
EnvStrDebug{slice:self.iter.as_slice()}
28-
}
2912
}
3013

3114
impl fmt::DebugforEnv{

‎library/std/src/sys/env/unsupported.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ use crate::{fmt, io};
33

44
pubstructEnv(!);
55

6-
implEnv{
7-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
8-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
9-
self.0
10-
}
11-
}
12-
136
impl fmt::DebugforEnv{
147
fnfmt(&self, _:&mut fmt::Formatter<'_>) -> fmt::Result{
158
self.0

‎library/std/src/sys/env/windows.rs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,6 @@ pub struct Env {
88
iter:EnvIterator,
99
}
1010

11-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
12-
pubstructEnvStrDebug<'a>{
13-
iter:&'aEnvIterator,
14-
}
15-
16-
impl fmt::DebugforEnvStrDebug<'_>{
17-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
18-
letSelf{ iter } = self;
19-
let iter:EnvIterator = (*iter).clone();
20-
letmut list = f.debug_list();
21-
for(a, b)in iter {
22-
list.entry(&(a.to_str().unwrap(), b.to_str().unwrap()));
23-
}
24-
list.finish()
25-
}
26-
}
27-
28-
implEnv{
29-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
30-
letSelf{base: _, iter } = self;
31-
EnvStrDebug{ iter }
32-
}
33-
}
34-
3511
impl fmt::DebugforEnv{
3612
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
3713
letSelf{base: _, iter } = self;

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu · rust-lang/rust@48fa913 · GitHub
Skip to content

Commit 48fa913

Browse files
authored
Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu
Match <OsString as Debug>::fmt to that of str Fixes#114583.
2 parents 8b74790 + eb84efc commit 48fa913

8 files changed

Lines changed: 25 additions & 55 deletions

File tree

‎library/core/src/str/lossy.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usesuper::char::EscapeDebugExtArgs;
12
usesuper::from_utf8_unchecked;
23
usesuper::validations::utf8_char_width;
34
usecrate::fmt;
@@ -121,7 +122,11 @@ impl fmt::Debug for Debug<'_> {
121122
let valid = chunk.valid();
122123
letmut from = 0;
123124
for(i, c)in valid.char_indices(){
124-
let esc = c.escape_debug();
125+
let esc = c.escape_debug_ext(EscapeDebugExtArgs{
126+
escape_grapheme_extended:true,
127+
escape_single_quote:false,
128+
escape_double_quote:true,
129+
});
125130
// If char needs escaping, flush backlog so far and write, else skip
126131
if esc.len() != 1{
127132
f.write_str(&valid[from..i])?;

‎library/core/src/wtf8.rs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// implementations, so, we'll have to add more doc(hidden)s anyway
2020
#![doc(hidden)]
2121

22-
usecrate::char::encode_utf16_raw;
22+
usecrate::char::{EscapeDebugExtArgs,encode_utf16_raw};
2323
usecrate::clone::CloneToUninit;
2424
usecrate::fmt::{self,Write};
2525
usecrate::hash::{Hash,Hasher};
@@ -144,14 +144,20 @@ impl AsRef<[u8]> for Wtf8 {
144144
impl fmt::DebugforWtf8{
145145
fnfmt(&self,formatter:&mut fmt::Formatter<'_>) -> fmt::Result{
146146
fnwrite_str_escaped(f:&mut fmt::Formatter<'_>,s:&str) -> fmt::Result{
147-
usecrate::fmt::Write;
148-
for c in s.chars().flat_map(|c| c.escape_debug()){
147+
usecrate::fmt::Writeas _;
148+
for c in s.chars().flat_map(|c| {
149+
c.escape_debug_ext(EscapeDebugExtArgs{
150+
escape_grapheme_extended:true,
151+
escape_single_quote:false,
152+
escape_double_quote:true,
153+
})
154+
}){
149155
f.write_char(c)?
150156
}
151157
Ok(())
152158
}
153159

154-
formatter.write_str("\"")?;
160+
formatter.write_char('"')?;
155161
letmut pos = 0;
156162
whileletSome((surrogate_pos, surrogate)) = self.next_surrogate(pos){
157163
// SAFETY: next_surrogate provides an index for a range of valid UTF-8 bytes.
@@ -164,7 +170,7 @@ impl fmt::Debug for Wtf8 {
164170

165171
// SAFETY: after next_surrogate returns None, the remainder is valid UTF-8.
166172
write_str_escaped(formatter,unsafe{ str::from_utf8_unchecked(&self.bytes[pos..])})?;
167-
formatter.write_str("\"")
173+
formatter.write_char('"')
168174
}
169175
}
170176

‎library/coretests/tests/str_lossy.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ fn debug() {
8080
b"Hello\xC0\x80 There\xE6\x83 Goodbye\xf4\x8d\x93\xaa".utf8_chunks().debug(),
8181
),
8282
);
83+
assert_eq!("\"'\"",&format!("{:?}",b"'".utf8_chunks().debug()));
8384
}

‎library/std/src/env.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Iterator for Vars {
170170
impl fmt::DebugforVars{
171171
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
172172
letSelf{inner:VarsOs{ inner }} = self;
173-
f.debug_struct("Vars").field("inner",&inner.str_debug()).finish()
173+
f.debug_struct("Vars").field("inner", inner).finish()
174174
}
175175
}
176176

‎library/std/src/ffi/os_str/tests.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,9 @@ fn clone_to_uninit() {
303303
unsafe{ a.clone_to_uninit(ptr::from_mut::<OsStr>(&mut b).cast())};
304304
assert_eq!(a,&*b);
305305
}
306+
307+
#[test]
308+
fndebug(){
309+
let s = "'single quotes'";
310+
assert_eq!(format!("{:?}",OsStr::new(s)), format!("{:?}", s));
311+
}

‎library/std/src/sys/env/common.rs‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,10 @@ pub struct Env {
55
iter: vec::IntoIter<(OsString,OsString)>,
66
}
77

8-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
9-
pubstructEnvStrDebug<'a>{
10-
slice:&'a[(OsString,OsString)],
11-
}
12-
13-
impl fmt::DebugforEnvStrDebug<'_>{
14-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
15-
f.debug_list()
16-
.entries(self.slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap())))
17-
.finish()
18-
}
19-
}
20-
218
implEnv{
229
pub(super)fnnew(env:Vec<(OsString,OsString)>) -> Self{
2310
Env{iter: env.into_iter()}
2411
}
25-
26-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
27-
EnvStrDebug{slice:self.iter.as_slice()}
28-
}
2912
}
3013

3114
impl fmt::DebugforEnv{

‎library/std/src/sys/env/unsupported.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ use crate::{fmt, io};
33

44
pubstructEnv(!);
55

6-
implEnv{
7-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
8-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
9-
self.0
10-
}
11-
}
12-
136
impl fmt::DebugforEnv{
147
fnfmt(&self, _:&mut fmt::Formatter<'_>) -> fmt::Result{
158
self.0

‎library/std/src/sys/env/windows.rs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,6 @@ pub struct Env {
88
iter:EnvIterator,
99
}
1010

11-
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
12-
pubstructEnvStrDebug<'a>{
13-
iter:&'aEnvIterator,
14-
}
15-
16-
impl fmt::DebugforEnvStrDebug<'_>{
17-
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
18-
letSelf{ iter } = self;
19-
let iter:EnvIterator = (*iter).clone();
20-
letmut list = f.debug_list();
21-
for(a, b)in iter {
22-
list.entry(&(a.to_str().unwrap(), b.to_str().unwrap()));
23-
}
24-
list.finish()
25-
}
26-
}
27-
28-
implEnv{
29-
pubfnstr_debug(&self) -> impl fmt::Debug + '_{
30-
letSelf{base: _, iter } = self;
31-
EnvStrDebug{ iter }
32-
}
33-
}
34-
3511
impl fmt::DebugforEnv{
3612
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
3713
letSelf{base: _, iter } = self;

0 commit comments

Comments
 (0)