Skip to content

Commit 18aa5ee

Browse files
committed
Auto merge of #79614 - GuillaumeGomez:rollup-15usd7e, r=GuillaumeGomez
Rollup of 3 pull requests Successful merges: - #79508 (Warn if `dsymutil` returns an error code) - #79509 (Improve attribute message error spans) - #79600 (std::io: Use sendfile for UnixStream) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6645da3 + 9e26fc6 commit 18aa5ee

File tree

13 files changed

+150
-49
lines changed

13 files changed

+150
-49
lines changed

compiler/rustc_ast/src/attr/mod.rs

+31
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ impl NestedMetaItem {
115115
pub fn is_meta_item_list(&self) -> bool {
116116
self.meta_item_list().is_some()
117117
}
118+
119+
pub fn name_value_literal_span(&self) -> Option<Span> {
120+
self.meta_item()?.name_value_literal_span()
121+
}
118122
}
119123

120124
impl Attribute {
@@ -175,6 +179,22 @@ impl Attribute {
175179
pub fn is_value_str(&self) -> bool {
176180
self.value_str().is_some()
177181
}
182+
183+
/// This is used in case you want the value span instead of the whole attribute. Example:
184+
///
185+
/// ```text
186+
/// #[doc(alias = "foo")]
187+
/// ```
188+
///
189+
/// In here, it'll return a span for `"foo"`.
190+
pub fn name_value_literal_span(&self) -> Option<Span> {
191+
match self.kind {
192+
AttrKind::Normal(ref item, _) => {
193+
item.meta(self.span).and_then(|meta| meta.name_value_literal_span())
194+
}
195+
AttrKind::DocComment(..) => None,
196+
}
197+
}
178198
}
179199

180200
impl MetaItem {
@@ -227,6 +247,17 @@ impl MetaItem {
227247
pub fn is_value_str(&self) -> bool {
228248
self.value_str().is_some()
229249
}
250+
251+
/// This is used in case you want the value span instead of the whole attribute. Example:
252+
///
253+
/// ```text
254+
/// #[doc(alias = "foo")]
255+
/// ```
256+
///
257+
/// In here, it'll return a span for `"foo"`.
258+
pub fn name_value_literal_span(&self) -> Option<Span> {
259+
Some(self.name_value_literal()?.span)
260+
}
230261
}
231262

232263
impl AttrItem {

compiler/rustc_attr/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ where
294294
or \"none\"",
295295
)
296296
.span_label(
297-
mi.name_value_literal().unwrap().span,
297+
mi.name_value_literal_span().unwrap(),
298298
msg,
299299
)
300300
.emit();

compiler/rustc_codegen_ssa/src/back/link.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -643,15 +643,16 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
643643
}
644644
}
645645

646+
fn escape_string(s: &[u8]) -> String {
647+
str::from_utf8(s).map(|s| s.to_owned()).unwrap_or_else(|_| {
648+
let mut x = "Non-UTF-8 output: ".to_string();
649+
x.extend(s.iter().flat_map(|&b| ascii::escape_default(b)).map(char::from));
650+
x
651+
})
652+
}
653+
646654
match prog {
647655
Ok(prog) => {
648-
fn escape_string(s: &[u8]) -> String {
649-
str::from_utf8(s).map(|s| s.to_owned()).unwrap_or_else(|_| {
650-
let mut x = "Non-UTF-8 output: ".to_string();
651-
x.extend(s.iter().flat_map(|&b| ascii::escape_default(b)).map(char::from));
652-
x
653-
})
654-
}
655656
if !prog.status.success() {
656657
let mut output = prog.stderr.clone();
657658
output.extend_from_slice(&prog.stdout);
@@ -760,8 +761,21 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
760761
&& sess.opts.debuginfo != DebugInfo::None
761762
&& !preserve_objects_for_their_debuginfo(sess)
762763
{
763-
if let Err(e) = Command::new("dsymutil").arg(out_filename).output() {
764-
sess.fatal(&format!("failed to run dsymutil: {}", e))
764+
let prog = Command::new("dsymutil").arg(out_filename).output();
765+
match prog {
766+
Ok(prog) => {
767+
if !prog.status.success() {
768+
let mut output = prog.stderr.clone();
769+
output.extend_from_slice(&prog.stdout);
770+
sess.struct_warn(&format!(
771+
"processing debug info with `dsymutil` failed: {}",
772+
prog.status
773+
))
774+
.note(&escape_string(&output))
775+
.emit();
776+
}
777+
}
778+
Err(e) => sess.fatal(&format!("unable to run `dsymutil`: {}", e)),
765779
}
766780
}
767781
}

compiler/rustc_expand/src/expand.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1603,23 +1603,22 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
16031603
items.push(ast::NestedMetaItem::MetaItem(item));
16041604
}
16051605
Err(e) => {
1606-
let lit =
1607-
it.meta_item().and_then(|item| item.name_value_literal()).unwrap();
1606+
let lit_span = it.name_value_literal_span().unwrap();
16081607

16091608
if e.kind() == ErrorKind::InvalidData {
16101609
self.cx
16111610
.struct_span_err(
1612-
lit.span,
1611+
lit_span,
16131612
&format!("{} wasn't a utf-8 file", filename.display()),
16141613
)
1615-
.span_label(lit.span, "contains invalid utf-8")
1614+
.span_label(lit_span, "contains invalid utf-8")
16161615
.emit();
16171616
} else {
16181617
let mut err = self.cx.struct_span_err(
1619-
lit.span,
1618+
lit_span,
16201619
&format!("couldn't read {}: {}", filename.display(), e),
16211620
);
1622-
err.span_label(lit.span, "couldn't read file");
1621+
err.span_label(lit_span, "couldn't read file");
16231622

16241623
err.emit();
16251624
}

compiler/rustc_middle/src/middle/limits.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ fn update_limit(
4343

4444
let value_span = attr
4545
.meta()
46-
.and_then(|meta| meta.name_value_literal().cloned())
47-
.map(|lit| lit.span)
46+
.and_then(|meta| meta.name_value_literal_span())
4847
.unwrap_or(attr.span);
4948

5049
let error_str = match e.kind() {

compiler/rustc_passes/src/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl CheckAttrVisitor<'tcx> {
319319
self.tcx
320320
.sess
321321
.struct_span_err(
322-
meta.span(),
322+
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
323323
&format!(
324324
"{:?} character isn't allowed in `#[doc(alias = \"...\")]`",
325325
c,
@@ -332,7 +332,7 @@ impl CheckAttrVisitor<'tcx> {
332332
self.tcx
333333
.sess
334334
.struct_span_err(
335-
meta.span(),
335+
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
336336
"`#[doc(alias = \"...\")]` cannot start or end with ' '",
337337
)
338338
.emit();

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub enum SymbolManglingVersion {
214214

215215
impl_stable_hash_via_hash!(SymbolManglingVersion);
216216

217-
#[derive(Clone, Copy, PartialEq, Hash)]
217+
#[derive(Clone, Copy, Debug, PartialEq, Hash)]
218218
pub enum DebugInfo {
219219
None,
220220
Limited,

library/std/src/sys/unix/kernel_copy.rs

+29
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use crate::mem::ManuallyDrop;
5656
use crate::net::TcpStream;
5757
use crate::os::unix::fs::FileTypeExt;
5858
use crate::os::unix::io::{AsRawFd, FromRawFd, RawFd};
59+
use crate::os::unix::net::UnixStream;
5960
use crate::process::{ChildStderr, ChildStdin, ChildStdout};
6061
use crate::ptr;
6162
use crate::sync::atomic::{AtomicBool, Ordering};
@@ -320,6 +321,34 @@ impl CopyWrite for &TcpStream {
320321
}
321322
}
322323

324+
impl CopyRead for UnixStream {
325+
fn properties(&self) -> CopyParams {
326+
// avoid the stat syscall since we can be fairly sure it's a socket
327+
CopyParams(FdMeta::Socket, Some(self.as_raw_fd()))
328+
}
329+
}
330+
331+
impl CopyRead for &UnixStream {
332+
fn properties(&self) -> CopyParams {
333+
// avoid the stat syscall since we can be fairly sure it's a socket
334+
CopyParams(FdMeta::Socket, Some(self.as_raw_fd()))
335+
}
336+
}
337+
338+
impl CopyWrite for UnixStream {
339+
fn properties(&self) -> CopyParams {
340+
// avoid the stat syscall since we can be fairly sure it's a socket
341+
CopyParams(FdMeta::Socket, Some(self.as_raw_fd()))
342+
}
343+
}
344+
345+
impl CopyWrite for &UnixStream {
346+
fn properties(&self) -> CopyParams {
347+
// avoid the stat syscall since we can be fairly sure it's a socket
348+
CopyParams(FdMeta::Socket, Some(self.as_raw_fd()))
349+
}
350+
}
351+
323352
impl CopyWrite for ChildStdin {
324353
fn properties(&self) -> CopyParams {
325354
CopyParams(FdMeta::Pipe, Some(self.as_raw_fd()))

library/std/src/sys/unix/kernel_copy/tests.rs

+29
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,35 @@ fn bench_file_to_socket_copy(b: &mut test::Bencher) {
118118
});
119119
}
120120

121+
#[bench]
122+
fn bench_file_to_uds_copy(b: &mut test::Bencher) {
123+
const BYTES: usize = 128 * 1024;
124+
let src_path = temp_dir().join("uds-copy-bench-src");
125+
let mut src = OpenOptions::new()
126+
.create(true)
127+
.truncate(true)
128+
.read(true)
129+
.write(true)
130+
.open(src_path)
131+
.unwrap();
132+
src.write(&vec![0u8; BYTES]).unwrap();
133+
134+
let (mut sink, mut sink_drainer) = crate::os::unix::net::UnixStream::pair().unwrap();
135+
136+
crate::thread::spawn(move || {
137+
let mut sink_buf = vec![0u8; 1024 * 1024];
138+
loop {
139+
sink_drainer.read(&mut sink_buf[..]).unwrap();
140+
}
141+
});
142+
143+
b.bytes = BYTES as u64;
144+
b.iter(|| {
145+
src.seek(SeekFrom::Start(0)).unwrap();
146+
assert_eq!(BYTES as u64, io::copy(&mut src, &mut sink).unwrap());
147+
});
148+
}
149+
121150
#[cfg(any(target_os = "linux", target_os = "android"))]
122151
#[bench]
123152
fn bench_socket_pipe_socket_copy(b: &mut test::Bencher) {

src/test/rustdoc-ui/check-doc-alias-attr.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,42 @@ LL | #[doc(alias("bar"))]
1717
| ^^^^^^^^^^^^
1818

1919
error: '\"' character isn't allowed in `#[doc(alias = "...")]`
20-
--> $DIR/check-doc-alias-attr.rs:9:7
20+
--> $DIR/check-doc-alias-attr.rs:9:15
2121
|
2222
LL | #[doc(alias = "\"")]
23-
| ^^^^^^^^^^^^
23+
| ^^^^
2424

2525
error: '\n' character isn't allowed in `#[doc(alias = "...")]`
26-
--> $DIR/check-doc-alias-attr.rs:10:7
26+
--> $DIR/check-doc-alias-attr.rs:10:15
2727
|
2828
LL | #[doc(alias = "\n")]
29-
| ^^^^^^^^^^^^
29+
| ^^^^
3030

3131
error: '\n' character isn't allowed in `#[doc(alias = "...")]`
32-
--> $DIR/check-doc-alias-attr.rs:11:7
32+
--> $DIR/check-doc-alias-attr.rs:11:15
3333
|
3434
LL | #[doc(alias = "
35-
| _______^
35+
| _______________^
3636
LL | | ")]
3737
| |_^
3838

3939
error: '\t' character isn't allowed in `#[doc(alias = "...")]`
40-
--> $DIR/check-doc-alias-attr.rs:13:7
40+
--> $DIR/check-doc-alias-attr.rs:13:15
4141
|
4242
LL | #[doc(alias = "\t")]
43-
| ^^^^^^^^^^^^
43+
| ^^^^
4444

4545
error: `#[doc(alias = "...")]` cannot start or end with ' '
46-
--> $DIR/check-doc-alias-attr.rs:14:7
46+
--> $DIR/check-doc-alias-attr.rs:14:15
4747
|
4848
LL | #[doc(alias = " hello")]
49-
| ^^^^^^^^^^^^^^^^
49+
| ^^^^^^^^
5050

5151
error: `#[doc(alias = "...")]` cannot start or end with ' '
52-
--> $DIR/check-doc-alias-attr.rs:15:7
52+
--> $DIR/check-doc-alias-attr.rs:15:15
5353
|
5454
LL | #[doc(alias = "hello ")]
55-
| ^^^^^^^^^^^^^^^^
55+
| ^^^^^^^^
5656

5757
error: aborting due to 9 previous errors
5858

src/test/rustdoc-ui/doc-alias-crate-level.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: '\'' character isn't allowed in `#[doc(alias = "...")]`
2-
--> $DIR/doc-alias-crate-level.rs:5:7
2+
--> $DIR/doc-alias-crate-level.rs:5:15
33
|
44
LL | #[doc(alias = "shouldn't work!")]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^
66

77
error: `#![doc(alias = "...")]` isn't allowed as a crate level attribute
88
--> $DIR/doc-alias-crate-level.rs:3:8

src/test/ui/check-doc-alias-attr.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,42 @@ LL | #[doc(alias("bar"))]
1717
| ^^^^^^^^^^^^
1818

1919
error: '\"' character isn't allowed in `#[doc(alias = "...")]`
20-
--> $DIR/check-doc-alias-attr.rs:10:7
20+
--> $DIR/check-doc-alias-attr.rs:10:15
2121
|
2222
LL | #[doc(alias = "\"")]
23-
| ^^^^^^^^^^^^
23+
| ^^^^
2424

2525
error: '\n' character isn't allowed in `#[doc(alias = "...")]`
26-
--> $DIR/check-doc-alias-attr.rs:11:7
26+
--> $DIR/check-doc-alias-attr.rs:11:15
2727
|
2828
LL | #[doc(alias = "\n")]
29-
| ^^^^^^^^^^^^
29+
| ^^^^
3030

3131
error: '\n' character isn't allowed in `#[doc(alias = "...")]`
32-
--> $DIR/check-doc-alias-attr.rs:12:7
32+
--> $DIR/check-doc-alias-attr.rs:12:15
3333
|
3434
LL | #[doc(alias = "
35-
| _______^
35+
| _______________^
3636
LL | | ")]
3737
| |_^
3838

3939
error: '\t' character isn't allowed in `#[doc(alias = "...")]`
40-
--> $DIR/check-doc-alias-attr.rs:14:7
40+
--> $DIR/check-doc-alias-attr.rs:14:15
4141
|
4242
LL | #[doc(alias = "\t")]
43-
| ^^^^^^^^^^^^
43+
| ^^^^
4444

4545
error: `#[doc(alias = "...")]` cannot start or end with ' '
46-
--> $DIR/check-doc-alias-attr.rs:15:7
46+
--> $DIR/check-doc-alias-attr.rs:15:15
4747
|
4848
LL | #[doc(alias = " hello")]
49-
| ^^^^^^^^^^^^^^^^
49+
| ^^^^^^^^
5050

5151
error: `#[doc(alias = "...")]` cannot start or end with ' '
52-
--> $DIR/check-doc-alias-attr.rs:16:7
52+
--> $DIR/check-doc-alias-attr.rs:16:15
5353
|
5454
LL | #[doc(alias = "hello ")]
55-
| ^^^^^^^^^^^^^^^^
55+
| ^^^^^^^^
5656

5757
error: aborting due to 9 previous errors
5858

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: '\'' character isn't allowed in `#[doc(alias = "...")]`
2-
--> $DIR/doc-alias-crate-level.rs:7:8
2+
--> $DIR/doc-alias-crate-level.rs:7:16
33
|
44
LL | #![doc(alias = "shouldn't work!")]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)