Skip to content

Commit bcbbdcb

Browse files
committed
Auto merge of #147371 - Zalathar:rollup-897uitw, r=Zalathar
Rollup of 5 pull requests Successful merges: - #144908 (Fix doctest output json) - #147262 (Make #[link="dl"] an FCW rather than an error) - #147364 (update autodiff testcases) - #147367 (Trivial code cleanup in resolve) - #147369 (Fill out AVR target metadata) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e2c96cc + 21b5d6b commit bcbbdcb

File tree

12 files changed

+191
-54
lines changed

12 files changed

+191
-54
lines changed

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,22 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
6565
cx: &'c mut AcceptContext<'_, '_, S>,
6666
args: &'c ArgParser<'_>,
6767
) -> impl IntoIterator<Item = Self::Item> + 'c {
68-
let mut result = None;
69-
let Some(items) = args.list() else {
70-
cx.expected_list(cx.attr_span);
71-
return result;
68+
let items = match args {
69+
ArgParser::List(list) => list,
70+
// This is an edgecase added because making this a hard error would break too many crates
71+
// Specifically `#[link = "dl"]` is accepted with a FCW
72+
// For more information, see https://github.com/rust-lang/rust/pull/143193
73+
ArgParser::NameValue(nv) if nv.value_as_str().is_some_and(|v| v == sym::dl) => {
74+
let suggestions = <Self as CombineAttributeParser<S>>::TEMPLATE
75+
.suggestions(cx.attr_style, "link");
76+
let span = cx.attr_span;
77+
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
78+
return None;
79+
}
80+
_ => {
81+
cx.expected_list(cx.attr_span);
82+
return None;
83+
}
7284
};
7385

7486
let sess = cx.sess();
@@ -113,7 +125,7 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
113125
}
114126
};
115127
if !cont {
116-
return result;
128+
return None;
117129
}
118130
}
119131

@@ -202,7 +214,7 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
202214
}
203215
let Some((name, name_span)) = name else {
204216
cx.emit_err(LinkRequiresName { span: cx.attr_span });
205-
return result;
217+
return None;
206218
};
207219

208220
// Do this outside of the loop so that `import_name_type` can be specified before `kind`.
@@ -218,15 +230,14 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
218230
cx.emit_err(RawDylibNoNul { span: name_span });
219231
}
220232

221-
result = Some(LinkEntry {
233+
Some(LinkEntry {
222234
span: cx.attr_span,
223235
kind: kind.unwrap_or(NativeLibKind::Unspecified),
224236
name,
225237
cfg,
226238
verbatim,
227239
import_name_type,
228-
});
229-
result
240+
})
230241
}
231242
}
232243

compiler/rustc_resolve/src/imports.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,14 +741,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
741741
errors.retain(|(_import, err)| match err.module {
742742
// Skip `use` errors for `use foo::Bar;` if `foo.rs` has unrecovered parse errors.
743743
Some(def_id) if self.mods_with_parse_errors.contains(&def_id) => false,
744-
_ => true,
745-
});
746-
errors.retain(|(_import, err)| {
747744
// If we've encountered something like `use _;`, we've already emitted an error stating
748745
// that `_` is not a valid identifier, so we ignore that resolve error.
749-
err.segment != Some(kw::Underscore)
746+
_ => err.segment != Some(kw::Underscore),
750747
});
751-
752748
if errors.is_empty() {
753749
self.tcx.dcx().delayed_bug("expected a parse or \"`_` can't be an identifier\" error");
754750
return;

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ symbols! {
874874
div,
875875
div_assign,
876876
diverging_block_default,
877+
dl,
877878
do_not_recommend,
878879
doc,
879880
doc_alias,

compiler/rustc_target/src/spec/targets/avr_none.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ pub(crate) fn target() -> Target {
55
arch: "avr".into(),
66
metadata: crate::spec::TargetMetadata {
77
description: None,
8-
tier: None,
9-
host_tools: None,
10-
std: None,
8+
tier: Some(3),
9+
host_tools: Some(false),
10+
std: Some(false),
1111
},
1212
data_layout: "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8:16-a:8".into(),
1313
llvm_target: "avr-unknown-unknown".into(),

src/librustdoc/doctest.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::process::{self, Command, Stdio};
1212
use std::sync::atomic::{AtomicUsize, Ordering};
1313
use std::sync::{Arc, Mutex};
1414
use std::time::{Duration, Instant};
15-
use std::{fmt, panic, str};
15+
use std::{panic, str};
1616

1717
pub(crate) use make::{BuildDocTestBuilder, DocTestBuilder};
1818
pub(crate) use markdown::test as test_markdown;
@@ -60,24 +60,15 @@ impl MergedDoctestTimes {
6060
self.added_compilation_times += 1;
6161
}
6262

63-
fn display_times(&self) {
63+
/// Returns `(total_time, compilation_time)`.
64+
fn times_in_secs(&self) -> Option<(f64, f64)> {
6465
// If no merged doctest was compiled, then there is nothing to display since the numbers
6566
// displayed by `libtest` for standalone tests are already accurate (they include both
6667
// compilation and runtime).
67-
if self.added_compilation_times > 0 {
68-
println!("{self}");
68+
if self.added_compilation_times == 0 {
69+
return None;
6970
}
70-
}
71-
}
72-
73-
impl fmt::Display for MergedDoctestTimes {
74-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75-
write!(
76-
f,
77-
"all doctests ran in {:.2}s; merged doctests compilation took {:.2}s",
78-
self.total_time.elapsed().as_secs_f64(),
79-
self.compilation_time.as_secs_f64(),
80-
)
71+
Some((self.total_time.elapsed().as_secs_f64(), self.compilation_time.as_secs_f64()))
8172
}
8273
}
8374

@@ -402,15 +393,20 @@ pub(crate) fn run_tests(
402393
if ran_edition_tests == 0 || !standalone_tests.is_empty() {
403394
standalone_tests.sort_by(|a, b| a.desc.name.as_slice().cmp(b.desc.name.as_slice()));
404395
test::test_main_with_exit_callback(&test_args, standalone_tests, None, || {
396+
let times = times.times_in_secs();
405397
// We ensure temp dir destructor is called.
406398
std::mem::drop(temp_dir.take());
407-
times.display_times();
399+
if let Some((total_time, compilation_time)) = times {
400+
test::print_merged_doctests_times(&test_args, total_time, compilation_time);
401+
}
408402
});
409403
} else {
410404
// If the first condition branch exited successfully, `test_main_with_exit_callback` will
411405
// not exit the process. So to prevent displaying the times twice, we put it behind an
412406
// `else` condition.
413-
times.display_times();
407+
if let Some((total_time, compilation_time)) = times.times_in_secs() {
408+
test::print_merged_doctests_times(&test_args, total_time, compilation_time);
409+
}
414410
}
415411
// We ensure temp dir destructor is called.
416412
std::mem::drop(temp_dir);

tests/codegen-llvm/autodiff/autodiffv2.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,14 @@
1818
// but each shadow argument is `width` times larger (thus 16 and 20 elements here).
1919
// `d_square3` instead takes `width` (4) shadow arguments, which are all the same size as the
2020
// original function arguments.
21-
//
22-
// FIXME(autodiff): We currently can't test `d_square1` and `d_square3` in the same file, since they
23-
// generate the same dummy functions which get merged by LLVM, breaking pieces of our pipeline which
24-
// try to rewrite the dummy functions later. We should consider to change to pure declarations both
25-
// in our frontend and in the llvm backend to avoid these issues.
2621

2722
#![feature(autodiff)]
2823

2924
use std::autodiff::autodiff_forward;
3025

3126
// CHECK: ;
3227
#[no_mangle]
33-
//#[autodiff(d_square1, Forward, Dual, Dual)]
28+
#[autodiff_forward(d_square1, Dual, Dual)]
3429
#[autodiff_forward(d_square2, 4, Dualv, Dualv)]
3530
#[autodiff_forward(d_square3, 4, Dual, Dual)]
3631
fn square(x: &[f32], y: &mut [f32]) {
@@ -79,25 +74,25 @@ fn main() {
7974
let mut dy3_4 = std::hint::black_box(vec![0.0; 5]);
8075

8176
// scalar.
82-
//d_square1(&x1, &z1, &mut y1, &mut dy1_1);
83-
//d_square1(&x1, &z2, &mut y2, &mut dy1_2);
84-
//d_square1(&x1, &z3, &mut y3, &mut dy1_3);
85-
//d_square1(&x1, &z4, &mut y4, &mut dy1_4);
77+
d_square1(&x1, &z1, &mut y1, &mut dy1_1);
78+
d_square1(&x1, &z2, &mut y2, &mut dy1_2);
79+
d_square1(&x1, &z3, &mut y3, &mut dy1_3);
80+
d_square1(&x1, &z4, &mut y4, &mut dy1_4);
8681

8782
// assert y1 == y2 == y3 == y4
88-
//for i in 0..5 {
89-
// assert_eq!(y1[i], y2[i]);
90-
// assert_eq!(y1[i], y3[i]);
91-
// assert_eq!(y1[i], y4[i]);
92-
//}
83+
for i in 0..5 {
84+
assert_eq!(y1[i], y2[i]);
85+
assert_eq!(y1[i], y3[i]);
86+
assert_eq!(y1[i], y4[i]);
87+
}
9388

9489
// batch mode A)
9590
d_square2(&x1, &z5, &mut y5, &mut dy2);
9691

9792
// assert y1 == y2 == y3 == y4 == y5
98-
//for i in 0..5 {
99-
// assert_eq!(y1[i], y5[i]);
100-
//}
93+
for i in 0..5 {
94+
assert_eq!(y1[i], y5[i]);
95+
}
10196

10297
// batch mode B)
10398
d_square3(&x1, &z1, &z2, &z3, &z4, &mut y6, &mut dy3_1, &mut dy3_2, &mut dy3_3, &mut dy3_4);

tests/codegen-llvm/autodiff/identical_fnc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ fn square2(x: &f64) -> f64 {
3232
// CHECK-NOT:br
3333
// CHECK-NOT:ret
3434
// CHECK:; call identical_fnc::d_square
35-
// CHECK-NEXT:call fastcc void @_ZN13identical_fnc8d_square17hcb5768e95528c35fE(double %x.val, ptr noalias noundef align 8 dereferenceable(8) %dx1)
35+
// CHECK-NEXT:call fastcc void @_ZN13identical_fnc8d_square[[HASH:.+]](double %x.val, ptr noalias noundef align 8 dereferenceable(8) %dx1)
3636
// CHECK:; call identical_fnc::d_square
37-
// CHECK-NEXT:call fastcc void @_ZN13identical_fnc8d_square17hcb5768e95528c35fE(double %x.val, ptr noalias noundef align 8 dereferenceable(8) %dx2)
37+
// CHECK-NEXT:call fastcc void @_ZN13identical_fnc8d_square[[HASH]](double %x.val, ptr noalias noundef align 8 dereferenceable(8) %dx2)
3838

3939
fn main() {
4040
let x = std::hint::black_box(3.0);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! ```
2+
//! let x = 12;
3+
//! ```
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//! Regression test to ensure that the output format is respected for doctests.
2+
//!
3+
//! Regression test for <https://github.com/rust-lang/rust/issues/144798>.
4+
5+
//@ ignore-cross-compile
6+
7+
use run_make_support::{rustdoc, serde_json};
8+
9+
fn run_test(edition: &str, format: Option<&str>) -> String {
10+
let mut r = rustdoc();
11+
r.input("file.rs").edition(edition).arg("--test");
12+
if let Some(format) = format {
13+
r.args(&[
14+
"--test-args",
15+
"-Zunstable-options",
16+
"--test-args",
17+
"--format",
18+
"--test-args",
19+
format,
20+
]);
21+
}
22+
r.run().stdout_utf8()
23+
}
24+
25+
fn check_json_output(edition: &str, expected_reports: usize) {
26+
let out = run_test(edition, Some("json"));
27+
let mut found_report = 0;
28+
for (line_nb, line) in out.lines().enumerate() {
29+
match serde_json::from_str::<serde_json::Value>(&line) {
30+
Ok(value) => {
31+
if value.get("type") == Some(&serde_json::json!("report")) {
32+
found_report += 1;
33+
}
34+
}
35+
Err(error) => panic!(
36+
"failed for {edition} edition (json format) at line {}: non-JSON value: {error}\n\
37+
====== output ======\n{out}",
38+
line_nb + 1,
39+
),
40+
}
41+
}
42+
if found_report != expected_reports {
43+
panic!(
44+
"failed for {edition} edition (json format): expected {expected_reports} doctest \
45+
time `report`, found {found_report}\n====== output ======\n{out}",
46+
);
47+
}
48+
}
49+
50+
fn check_non_json_output(edition: &str, expected_reports: usize) {
51+
let out = run_test(edition, None);
52+
let mut found_report = 0;
53+
for (line_nb, line) in out.lines().enumerate() {
54+
if line.starts_with('{') && serde_json::from_str::<serde_json::Value>(&line).is_ok() {
55+
panic!(
56+
"failed for {edition} edition: unexpected json at line {}: `{line}`\n\
57+
====== output ======\n{out}",
58+
line_nb + 1
59+
);
60+
}
61+
if line.starts_with("all doctests ran in")
62+
&& line.contains("; merged doctests compilation took ")
63+
{
64+
found_report += 1;
65+
}
66+
}
67+
if found_report != expected_reports {
68+
panic!(
69+
"failed for {edition} edition: expected {expected_reports} doctest time `report`, \
70+
found {found_report}\n====== output ======\n{out}",
71+
);
72+
}
73+
}
74+
75+
fn main() {
76+
// Only the merged doctests generate the "times report".
77+
check_json_output("2021", 0);
78+
check_json_output("2024", 1);
79+
80+
// Only the merged doctests generate the "times report".
81+
check_non_json_output("2021", 0);
82+
check_non_json_output("2024", 1);
83+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Future incompatibility report: Future breakage diagnostic:
2+
warning: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", wasm_import_module = "...")]`
3+
--> $DIR/link-dl.rs:14:1
4+
|
5+
LL | #[link="dl"]
6+
| ^^^^^^^^^^^^
7+
|
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
10+

0 commit comments

Comments
 (0)