Skip to content

Commit 39658ed

Browse files
committed
Auto merge of rust-lang#140355 - tgross35:rollup-sean6my, r=tgross35
Rollup of 7 pull requests Successful merges: - rust-lang#137439 (Stabilise `std::ffi::c_str`) - rust-lang#138737 (uefi: Update r-efi) - rust-lang#139646 (check types of const param defaults) - rust-lang#140220 (Fix detection of main function if there are expressions around it) - rust-lang#140291 (Correctly display stdout and stderr in case a doctest is failing) - rust-lang#140297 (Update example to use CStr::to_string_lossy) - rust-lang#140330 (Clarified bootstrap optimization "true" argument) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 43e62a7 + 64bb69a commit 39658ed

24 files changed

+255
-46
lines changed

bootstrap.example.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@
500500
# building without optimizations takes much longer than optimizing. Further, some platforms
501501
# fail to build without this optimization (c.f. #65352).
502502
# The valid options are:
503-
# true - Enable optimizations.
503+
# true - Enable optimizations (same as 3).
504504
# false - Disable optimizations.
505505
# 0 - Disable optimizations.
506506
# 1 - Basic optimizations.

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+33
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,39 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14831483
.then(|| WellFormedLoc::Ty(param.def_id.expect_local())),
14841484
default.as_term().unwrap(),
14851485
);
1486+
} else {
1487+
// If we've got a generic const parameter we still want to check its
1488+
// type is correct in case both it and the param type are fully concrete.
1489+
let GenericArgKind::Const(ct) = default.unpack() else {
1490+
continue;
1491+
};
1492+
1493+
let ct_ty = match ct.kind() {
1494+
ty::ConstKind::Infer(_)
1495+
| ty::ConstKind::Placeholder(_)
1496+
| ty::ConstKind::Bound(_, _) => unreachable!(),
1497+
ty::ConstKind::Error(_) | ty::ConstKind::Expr(_) => continue,
1498+
ty::ConstKind::Value(cv) => cv.ty,
1499+
ty::ConstKind::Unevaluated(uv) => {
1500+
infcx.tcx.type_of(uv.def).instantiate(infcx.tcx, uv.args)
1501+
}
1502+
ty::ConstKind::Param(param_ct) => param_ct.find_ty_from_env(wfcx.param_env),
1503+
};
1504+
1505+
let param_ty = tcx.type_of(param.def_id).instantiate_identity();
1506+
if !ct_ty.has_param() && !param_ty.has_param() {
1507+
let cause = traits::ObligationCause::new(
1508+
tcx.def_span(param.def_id),
1509+
wfcx.body_def_id,
1510+
ObligationCauseCode::WellFormed(None),
1511+
);
1512+
wfcx.register_obligation(Obligation::new(
1513+
tcx,
1514+
cause,
1515+
wfcx.param_env,
1516+
ty::ClauseKind::ConstArgHasType(ct, param_ty),
1517+
));
1518+
}
14861519
}
14871520
}
14881521
}

library/Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,19 @@ dependencies = [
257257

258258
[[package]]
259259
name = "r-efi"
260-
version = "4.5.0"
260+
version = "5.2.0"
261261
source = "registry+https://github.com/rust-lang/crates.io-index"
262-
checksum = "e9e935efc5854715dfc0a4c9ef18dc69dee0ec3bf9cc3ab740db831c0fdd86a3"
262+
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
263263
dependencies = [
264264
"compiler_builtins",
265265
"rustc-std-workspace-core",
266266
]
267267

268268
[[package]]
269269
name = "r-efi-alloc"
270-
version = "1.0.0"
270+
version = "2.0.0"
271271
source = "registry+https://github.com/rust-lang/crates.io-index"
272-
checksum = "31d6f09fe2b6ad044bc3d2c34ce4979796581afd2f1ebc185837e02421e02fd7"
272+
checksum = "e43c53ff1a01d423d1cb762fd991de07d32965ff0ca2e4f80444ac7804198203"
273273
dependencies = [
274274
"compiler_builtins",
275275
"r-efi",

library/alloc/src/ffi/c_str.rs

+2
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ impl From<Vec<NonZero<u8>>> for CString {
818818
}
819819
}
820820

821+
#[stable(feature = "c_string_from_str", since = "1.85.0")]
821822
impl FromStr for CString {
822823
type Err = NulError;
823824

@@ -830,6 +831,7 @@ impl FromStr for CString {
830831
}
831832
}
832833

834+
#[stable(feature = "c_string_from_str", since = "1.85.0")]
833835
impl TryFrom<CString> for String {
834836
type Error = IntoStringError;
835837

library/alloc/src/ffi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ pub use self::c_str::CString;
8787
#[stable(feature = "alloc_c_string", since = "1.64.0")]
8888
pub use self::c_str::{FromVecWithNulError, IntoStringError, NulError};
8989

90-
#[unstable(feature = "c_str_module", issue = "112134")]
90+
#[stable(feature = "c_str_module", since = "CURRENT_RUSTC_VERSION")]
9191
pub mod c_str;

library/core/src/ffi/c_str.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ use crate::{fmt, ops, slice, str};
7979
///
8080
/// fn my_string_safe() -> String {
8181
/// let cstr = unsafe { CStr::from_ptr(my_string()) };
82-
/// // Get copy-on-write Cow<'_, str>, then guarantee a freshly-owned String allocation
83-
/// String::from_utf8_lossy(cstr.to_bytes()).to_string()
82+
/// // Get a copy-on-write Cow<'_, str>, then extract the
83+
/// // allocated String (or allocate a fresh one if needed).
84+
/// cstr.to_string_lossy().into_owned()
8485
/// }
8586
///
8687
/// println!("string: {}", my_string_safe());

library/core/src/ffi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use self::c_str::FromBytesUntilNulError;
2020
pub use self::c_str::FromBytesWithNulError;
2121
use crate::fmt;
2222

23-
#[unstable(feature = "c_str_module", issue = "112134")]
23+
#[stable(feature = "c_str_module", since = "CURRENT_RUSTC_VERSION")]
2424
pub mod c_str;
2525

2626
#[unstable(

library/std/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ wasi = { version = "0.11.0", features = [
8383
], default-features = false }
8484

8585
[target.'cfg(target_os = "uefi")'.dependencies]
86-
r-efi = { version = "4.5.0", features = ['rustc-dep-of-std'] }
87-
r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std'] }
86+
r-efi = { version = "5.2.0", features = ['rustc-dep-of-std'] }
87+
r-efi-alloc = { version = "2.0.0", features = ['rustc-dep-of-std'] }
8888

8989
[features]
9090
backtrace = [

library/std/src/ffi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
162162
#![stable(feature = "rust1", since = "1.0.0")]
163163

164-
#[unstable(feature = "c_str_module", issue = "112134")]
164+
#[stable(feature = "c_str_module", since = "CURRENT_RUSTC_VERSION")]
165165
pub mod c_str;
166166

167167
#[stable(feature = "core_c_void", since = "1.30.0")]

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@
329329
#![feature(array_chunks)]
330330
#![feature(bstr)]
331331
#![feature(bstr_internals)]
332-
#![feature(c_str_module)]
333332
#![feature(char_internals)]
334333
#![feature(clone_to_uninit)]
335334
#![feature(core_intrinsics)]

src/librustdoc/doctest/make.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -407,17 +407,27 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
407407
push_to_s(&mut info.crate_attrs, source, attr.span, &mut prev_span_hi);
408408
}
409409
}
410+
let mut has_non_items = false;
410411
for stmt in &body.stmts {
411412
let mut is_extern_crate = false;
412413
match stmt.kind {
413414
StmtKind::Item(ref item) => {
414415
is_extern_crate = check_item(&item, &mut info, crate_name);
415416
}
416-
StmtKind::Expr(ref expr) if matches!(expr.kind, ast::ExprKind::Err(_)) => {
417-
reset_error_count(&psess);
418-
return Err(());
417+
StmtKind::Expr(ref expr) => {
418+
if matches!(expr.kind, ast::ExprKind::Err(_)) {
419+
reset_error_count(&psess);
420+
return Err(());
421+
}
422+
has_non_items = true;
419423
}
420-
StmtKind::MacCall(ref mac_call) if !info.has_main_fn => {
424+
// We assume that the macro calls will expand to item(s) even though they could
425+
// expand to statements and expressions. And the simple fact that we're trying
426+
// to retrieve a `main` function inside it is a terrible idea.
427+
StmtKind::MacCall(ref mac_call) => {
428+
if info.has_main_fn {
429+
continue;
430+
}
421431
let mut iter = mac_call.mac.args.tokens.iter();
422432

423433
while let Some(token) = iter.next() {
@@ -437,7 +447,9 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
437447
}
438448
}
439449
}
440-
_ => {}
450+
_ => {
451+
has_non_items = true;
452+
}
441453
}
442454

443455
// Weirdly enough, the `Stmt` span doesn't include its attributes, so we need to
@@ -462,6 +474,11 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
462474
push_to_s(&mut info.crates, source, span, &mut prev_span_hi);
463475
}
464476
}
477+
if has_non_items {
478+
// FIXME: if `info.has_main_fn` is `true`, emit a warning here to mention that
479+
// this code will not be called.
480+
info.has_main_fn = false;
481+
}
465482
Ok(info)
466483
}
467484
Err(e) => {

src/librustdoc/doctest/runner.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,22 @@ mod __doctest_mod {{
131131
.output()
132132
.expect(\"failed to run command\");
133133
if !out.status.success() {{
134-
eprint!(\"{{}}\", String::from_utf8_lossy(&out.stderr));
134+
if let Some(code) = out.status.code() {{
135+
eprintln!(\"Test executable failed (exit status: {{code}}).\");
136+
}} else {{
137+
eprintln!(\"Test executable failed (terminated by signal).\");
138+
}}
139+
if !out.stdout.is_empty() || !out.stderr.is_empty() {{
140+
eprintln!();
141+
}}
142+
if !out.stdout.is_empty() {{
143+
eprintln!(\"stdout:\");
144+
eprintln!(\"{{}}\", String::from_utf8_lossy(&out.stdout));
145+
}}
146+
if !out.stderr.is_empty() {{
147+
eprintln!(\"stderr:\");
148+
eprintln!(\"{{}}\", String::from_utf8_lossy(&out.stderr));
149+
}}
135150
ExitCode::FAILURE
136151
}} else {{
137152
ExitCode::SUCCESS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use std::string::String;

tests/rustdoc-ui/doctest/edition-2024-error-output.stdout

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ test $DIR/edition-2024-error-output.rs - (line 12) ... FAILED
55
failures:
66

77
---- $DIR/edition-2024-error-output.rs - (line 12) stdout ----
8+
Test executable failed (exit status: 101).
9+
10+
stderr:
811

912
thread 'main' panicked at $TMP:6:1:
1013
assertion `left == right` failed
@@ -13,6 +16,7 @@ assertion `left == right` failed
1316
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1417

1518

19+
1620
failures:
1721
$DIR/edition-2024-error-output.rs - (line 12)
1822

tests/rustdoc-ui/doctest/failed-doctest-extra-semicolon-on-item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
//@ compile-flags:--test
55
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
66
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
7-
//@ failure-status: 101
7+
//@ check-pass
88

99
/// <https://github.com/rust-lang/rust/issues/91014>
1010
///
1111
/// ```rust
12-
/// struct S {}; // unexpected semicolon after struct def
12+
/// struct S {};
1313
///
1414
/// fn main() {
1515
/// assert_eq!(0, 1);
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11

22
running 1 test
3-
test $DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) ... FAILED
3+
test $DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) ... ok
44

5-
failures:
6-
7-
---- $DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) stdout ----
8-
error: expected item, found `;`
9-
--> $DIR/failed-doctest-extra-semicolon-on-item.rs:12:12
10-
|
11-
LL | struct S {}; // unexpected semicolon after struct def
12-
| ^
13-
|
14-
= help: braced struct declarations are not followed by a semicolon
15-
help: remove this semicolon
16-
|
17-
LL - struct S {}; // unexpected semicolon after struct def
18-
LL + struct S {} // unexpected semicolon after struct def
19-
|
20-
21-
error: aborting due to 1 previous error
22-
23-
Couldn't compile the test.
24-
25-
failures:
26-
$DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11)
27-
28-
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
5+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
296

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This test checks a corner case where the macro calls used to be skipped,
2+
// making them considered as statement, and therefore some cases where
3+
// `include!` macro was then put into a function body, making the doctest
4+
// compilation fail.
5+
6+
//@ compile-flags:--test
7+
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
8+
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
9+
//@ check-pass
10+
11+
//! ```
12+
//! include!("./auxiliary/macro-after-main.rs");
13+
//!
14+
//! fn main() {}
15+
//! eprintln!();
16+
//! ```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
running 1 test
3+
test $DIR/macro-after-main.rs - (line 11) ... ok
4+
5+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This test ensures that the output is correctly generated when the
2+
// doctest fails. It checks when there is stderr and stdout, no stdout
3+
// and no stderr/stdout.
4+
//
5+
// This is a regression test for <https://github.com/rust-lang/rust/issues/140289>.
6+
7+
//@ edition: 2024
8+
//@ compile-flags:--test --test-args=--test-threads=1
9+
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
10+
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
11+
//@ normalize-stdout: "panicked at .+rs:" -> "panicked at $$TMP:"
12+
//@ failure-status: 101
13+
//@ rustc-env:RUST_BACKTRACE=0
14+
15+
//! ```
16+
//! println!("######## from a DOC TEST ########");
17+
//! assert_eq!("doc", "test");
18+
//! ```
19+
//!
20+
//! ```
21+
//! assert_eq!("doc", "test");
22+
//! ```
23+
//!
24+
//! ```
25+
//! std::process::exit(1);
26+
//! ```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
running 3 tests
3+
test $DIR/stdout-and-stderr.rs - (line 15) ... FAILED
4+
test $DIR/stdout-and-stderr.rs - (line 20) ... FAILED
5+
test $DIR/stdout-and-stderr.rs - (line 24) ... FAILED
6+
7+
failures:
8+
9+
---- $DIR/stdout-and-stderr.rs - (line 15) stdout ----
10+
Test executable failed (exit status: 101).
11+
12+
stdout:
13+
######## from a DOC TEST ########
14+
15+
stderr:
16+
17+
thread 'main' panicked at $TMP:7:1:
18+
assertion `left == right` failed
19+
left: "doc"
20+
right: "test"
21+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
22+
23+
24+
---- $DIR/stdout-and-stderr.rs - (line 20) stdout ----
25+
Test executable failed (exit status: 101).
26+
27+
stderr:
28+
29+
thread 'main' panicked at $TMP:15:1:
30+
assertion `left == right` failed
31+
left: "doc"
32+
right: "test"
33+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34+
35+
36+
---- $DIR/stdout-and-stderr.rs - (line 24) stdout ----
37+
Test executable failed (exit status: 1).
38+
39+
40+
failures:
41+
$DIR/stdout-and-stderr.rs - (line 15)
42+
$DIR/stdout-and-stderr.rs - (line 20)
43+
$DIR/stdout-and-stderr.rs - (line 24)
44+
45+
test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
46+

0 commit comments

Comments
 (0)