Skip to content

Rollup of 7 pull requests #140355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
12dd4a1
Stabilise c_str_module
clarfonthey Feb 22, 2025
6be84b1
Somehow these stability attributes were able to be omitted before?
clarfonthey Feb 22, 2025
3536324
Fix detection of `main` function if there are expressions around it
GuillaumeGomez Apr 23, 2025
81438c0
Add regression ui test for #140162 and for #139651
GuillaumeGomez Apr 23, 2025
8cd12bf
check types of const param default
lcnr Apr 10, 2025
70c389e
Correctly display stdout and stderr in case a doctest is failing
GuillaumeGomez Apr 25, 2025
c44068b
Add rustdoc-ui regression test for #140289
GuillaumeGomez Apr 25, 2025
3ededc1
Improve code
GuillaumeGomez Apr 25, 2025
3ef98a5
If there is a `;` alone, we consider that the doctest needs to be put…
GuillaumeGomez Apr 25, 2025
59b6cf5
uefi: Update r-efi
Ayush1325 Mar 20, 2025
43d8d89
clarified bootstrap optimization agrs
Kivooeo Apr 26, 2025
9112c86
Update example to use `CStr::to_string_lossy`
shepmaster Apr 25, 2025
aa69e3a
Fix bad handling of macros if there is already a `main` function
GuillaumeGomez Apr 26, 2025
1e295a2
Rollup merge of #137439 - clarfonthey:c-str-module, r=tgross35
tgross35 Apr 27, 2025
2e6c07b
Rollup merge of #138737 - Ayush1325:r-efi-update, r=tgross35
tgross35 Apr 27, 2025
2b7287e
Rollup merge of #139646 - lcnr:default-is-fully-concrete, r=BoxyUwU
tgross35 Apr 27, 2025
6900ea5
Rollup merge of #140220 - GuillaumeGomez:doctest-main-wrapping, r=fmease
tgross35 Apr 27, 2025
8ad1816
Rollup merge of #140291 - GuillaumeGomez:doctest-2024-stdout, r=notri…
tgross35 Apr 27, 2025
d3321a9
Rollup merge of #140297 - shepmaster:cstr-lossy, r=joboet
tgross35 Apr 27, 2025
64bb69a
Rollup merge of #140330 - Kivooeo:new-fix-five, r=clubby789
tgross35 Apr 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bootstrap.example.toml
Original file line number Diff line number Diff line change
@@ -500,7 +500,7 @@
# building without optimizations takes much longer than optimizing. Further, some platforms
# fail to build without this optimization (c.f. #65352).
# The valid options are:
# true - Enable optimizations.
# true - Enable optimizations (same as 3).
# false - Disable optimizations.
# 0 - Disable optimizations.
# 1 - Basic optimizations.
33 changes: 33 additions & 0 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
@@ -1483,6 +1483,39 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
.then(|| WellFormedLoc::Ty(param.def_id.expect_local())),
default.as_term().unwrap(),
);
} else {
// If we've got a generic const parameter we still want to check its
// type is correct in case both it and the param type are fully concrete.
let GenericArgKind::Const(ct) = default.unpack() else {
continue;
};

let ct_ty = match ct.kind() {
ty::ConstKind::Infer(_)
| ty::ConstKind::Placeholder(_)
| ty::ConstKind::Bound(_, _) => unreachable!(),
ty::ConstKind::Error(_) | ty::ConstKind::Expr(_) => continue,
ty::ConstKind::Value(cv) => cv.ty,
ty::ConstKind::Unevaluated(uv) => {
infcx.tcx.type_of(uv.def).instantiate(infcx.tcx, uv.args)
}
ty::ConstKind::Param(param_ct) => param_ct.find_ty_from_env(wfcx.param_env),
};

let param_ty = tcx.type_of(param.def_id).instantiate_identity();
if !ct_ty.has_param() && !param_ty.has_param() {
let cause = traits::ObligationCause::new(
tcx.def_span(param.def_id),
wfcx.body_def_id,
ObligationCauseCode::WellFormed(None),
);
wfcx.register_obligation(Obligation::new(
tcx,
cause,
wfcx.param_env,
ty::ClauseKind::ConstArgHasType(ct, param_ty),
));
}
}
}
}
8 changes: 4 additions & 4 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
@@ -257,19 +257,19 @@ dependencies = [

[[package]]
name = "r-efi"
version = "4.5.0"
version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9e935efc5854715dfc0a4c9ef18dc69dee0ec3bf9cc3ab740db831c0fdd86a3"
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-core",
]

[[package]]
name = "r-efi-alloc"
version = "1.0.0"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31d6f09fe2b6ad044bc3d2c34ce4979796581afd2f1ebc185837e02421e02fd7"
checksum = "e43c53ff1a01d423d1cb762fd991de07d32965ff0ca2e4f80444ac7804198203"
dependencies = [
"compiler_builtins",
"r-efi",
2 changes: 2 additions & 0 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
@@ -818,6 +818,7 @@ impl From<Vec<NonZero<u8>>> for CString {
}
}

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

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

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

2 changes: 1 addition & 1 deletion library/alloc/src/ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -87,5 +87,5 @@ pub use self::c_str::CString;
#[stable(feature = "alloc_c_string", since = "1.64.0")]
pub use self::c_str::{FromVecWithNulError, IntoStringError, NulError};

#[unstable(feature = "c_str_module", issue = "112134")]
#[stable(feature = "c_str_module", since = "CURRENT_RUSTC_VERSION")]
pub mod c_str;
5 changes: 3 additions & 2 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
@@ -79,8 +79,9 @@ use crate::{fmt, ops, slice, str};
///
/// fn my_string_safe() -> String {
/// let cstr = unsafe { CStr::from_ptr(my_string()) };
/// // Get copy-on-write Cow<'_, str>, then guarantee a freshly-owned String allocation
/// String::from_utf8_lossy(cstr.to_bytes()).to_string()
/// // Get a copy-on-write Cow<'_, str>, then extract the
/// // allocated String (or allocate a fresh one if needed).
/// cstr.to_string_lossy().into_owned()
/// }
///
/// println!("string: {}", my_string_safe());
2 changes: 1 addition & 1 deletion library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ pub use self::c_str::FromBytesUntilNulError;
pub use self::c_str::FromBytesWithNulError;
use crate::fmt;

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

#[unstable(
4 changes: 2 additions & 2 deletions library/std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -83,8 +83,8 @@ wasi = { version = "0.11.0", features = [
], default-features = false }

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

[features]
backtrace = [
2 changes: 1 addition & 1 deletion library/std/src/ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@

#![stable(feature = "rust1", since = "1.0.0")]

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

#[stable(feature = "core_c_void", since = "1.30.0")]
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
@@ -329,7 +329,6 @@
#![feature(array_chunks)]
#![feature(bstr)]
#![feature(bstr_internals)]
#![feature(c_str_module)]
#![feature(char_internals)]
#![feature(clone_to_uninit)]
#![feature(core_intrinsics)]
27 changes: 22 additions & 5 deletions src/librustdoc/doctest/make.rs
Original file line number Diff line number Diff line change
@@ -407,17 +407,27 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
push_to_s(&mut info.crate_attrs, source, attr.span, &mut prev_span_hi);
}
}
let mut has_non_items = false;
for stmt in &body.stmts {
let mut is_extern_crate = false;
match stmt.kind {
StmtKind::Item(ref item) => {
is_extern_crate = check_item(&item, &mut info, crate_name);
}
StmtKind::Expr(ref expr) if matches!(expr.kind, ast::ExprKind::Err(_)) => {
reset_error_count(&psess);
return Err(());
StmtKind::Expr(ref expr) => {
if matches!(expr.kind, ast::ExprKind::Err(_)) {
reset_error_count(&psess);
return Err(());
}
has_non_items = true;
}
StmtKind::MacCall(ref mac_call) if !info.has_main_fn => {
// We assume that the macro calls will expand to item(s) even though they could
// expand to statements and expressions. And the simple fact that we're trying
// to retrieve a `main` function inside it is a terrible idea.
StmtKind::MacCall(ref mac_call) => {
if info.has_main_fn {
continue;
}
let mut iter = mac_call.mac.args.tokens.iter();

while let Some(token) = iter.next() {
@@ -437,7 +447,9 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
}
}
}
_ => {}
_ => {
has_non_items = true;
}
}

// 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
push_to_s(&mut info.crates, source, span, &mut prev_span_hi);
}
}
if has_non_items {
// FIXME: if `info.has_main_fn` is `true`, emit a warning here to mention that
// this code will not be called.
info.has_main_fn = false;
}
Ok(info)
}
Err(e) => {
17 changes: 16 additions & 1 deletion src/librustdoc/doctest/runner.rs
Original file line number Diff line number Diff line change
@@ -131,7 +131,22 @@ mod __doctest_mod {{
.output()
.expect(\"failed to run command\");
if !out.status.success() {{
eprint!(\"{{}}\", String::from_utf8_lossy(&out.stderr));
if let Some(code) = out.status.code() {{
eprintln!(\"Test executable failed (exit status: {{code}}).\");
}} else {{
eprintln!(\"Test executable failed (terminated by signal).\");
}}
if !out.stdout.is_empty() || !out.stderr.is_empty() {{
eprintln!();
}}
if !out.stdout.is_empty() {{
eprintln!(\"stdout:\");
eprintln!(\"{{}}\", String::from_utf8_lossy(&out.stdout));
}}
if !out.stderr.is_empty() {{
eprintln!(\"stderr:\");
eprintln!(\"{{}}\", String::from_utf8_lossy(&out.stderr));
}}
ExitCode::FAILURE
}} else {{
ExitCode::SUCCESS
1 change: 1 addition & 0 deletions tests/rustdoc-ui/doctest/auxiliary/macro-after-main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use std::string::String;
4 changes: 4 additions & 0 deletions tests/rustdoc-ui/doctest/edition-2024-error-output.stdout
Original file line number Diff line number Diff line change
@@ -5,6 +5,9 @@ test $DIR/edition-2024-error-output.rs - (line 12) ... FAILED
failures:

---- $DIR/edition-2024-error-output.rs - (line 12) stdout ----
Test executable failed (exit status: 101).

stderr:

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



failures:
$DIR/edition-2024-error-output.rs - (line 12)

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

/// <https://github.com/rust-lang/rust/issues/91014>
///
/// ```rust
/// struct S {}; // unexpected semicolon after struct def
/// struct S {};
///
/// fn main() {
/// assert_eq!(0, 1);
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@

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

failures:

---- $DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) stdout ----
error: expected item, found `;`
--> $DIR/failed-doctest-extra-semicolon-on-item.rs:12:12
|
LL | struct S {}; // unexpected semicolon after struct def
| ^
|
= help: braced struct declarations are not followed by a semicolon
help: remove this semicolon
|
LL - struct S {}; // unexpected semicolon after struct def
LL + struct S {} // unexpected semicolon after struct def
|

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
$DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

16 changes: 16 additions & 0 deletions tests/rustdoc-ui/doctest/macro-after-main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This test checks a corner case where the macro calls used to be skipped,
// making them considered as statement, and therefore some cases where
// `include!` macro was then put into a function body, making the doctest
// compilation fail.

//@ compile-flags:--test
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ check-pass

//! ```
//! include!("./auxiliary/macro-after-main.rs");
//!
//! fn main() {}
//! eprintln!();
//! ```
6 changes: 6 additions & 0 deletions tests/rustdoc-ui/doctest/macro-after-main.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

running 1 test
test $DIR/macro-after-main.rs - (line 11) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

26 changes: 26 additions & 0 deletions tests/rustdoc-ui/doctest/stdout-and-stderr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This test ensures that the output is correctly generated when the
// doctest fails. It checks when there is stderr and stdout, no stdout
// and no stderr/stdout.
//
// This is a regression test for <https://github.com/rust-lang/rust/issues/140289>.

//@ edition: 2024
//@ compile-flags:--test --test-args=--test-threads=1
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ normalize-stdout: "panicked at .+rs:" -> "panicked at $$TMP:"
//@ failure-status: 101
//@ rustc-env:RUST_BACKTRACE=0

//! ```
//! println!("######## from a DOC TEST ########");
//! assert_eq!("doc", "test");
//! ```
//!
//! ```
//! assert_eq!("doc", "test");
//! ```
//!
//! ```
//! std::process::exit(1);
//! ```
46 changes: 46 additions & 0 deletions tests/rustdoc-ui/doctest/stdout-and-stderr.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

running 3 tests
test $DIR/stdout-and-stderr.rs - (line 15) ... FAILED
test $DIR/stdout-and-stderr.rs - (line 20) ... FAILED
test $DIR/stdout-and-stderr.rs - (line 24) ... FAILED

failures:

---- $DIR/stdout-and-stderr.rs - (line 15) stdout ----
Test executable failed (exit status: 101).

stdout:
######## from a DOC TEST ########

stderr:

thread 'main' panicked at $TMP:7:1:
assertion `left == right` failed
left: "doc"
right: "test"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


---- $DIR/stdout-and-stderr.rs - (line 20) stdout ----
Test executable failed (exit status: 101).

stderr:

thread 'main' panicked at $TMP:15:1:
assertion `left == right` failed
left: "doc"
right: "test"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


---- $DIR/stdout-and-stderr.rs - (line 24) stdout ----
Test executable failed (exit status: 1).


failures:
$DIR/stdout-and-stderr.rs - (line 15)
$DIR/stdout-and-stderr.rs - (line 20)
$DIR/stdout-and-stderr.rs - (line 24)

test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

22 changes: 22 additions & 0 deletions tests/rustdoc-ui/doctest/test-main-alongside-exprs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This test ensures that if there is an expression alongside a `main`
// function, it will not consider the entire code to be part of the `main`
// function and will generate its own function to wrap everything.
//
// This is a regression test for:
// * <https://github.com/rust-lang/rust/issues/140162>
// * <https://github.com/rust-lang/rust/issues/139651>
//@ compile-flags:--test
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ check-pass

#![crate_name = "foo"]

//! ```
//! # if cfg!(miri) { return; }
//! use std::ops::Deref;
//!
//! fn main() {
//! println!("Hi!");
//! }
//! ```
6 changes: 6 additions & 0 deletions tests/rustdoc-ui/doctest/test-main-alongside-exprs.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

running 1 test
test $DIR/test-main-alongside-exprs.rs - (line 15) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

13 changes: 13 additions & 0 deletions tests/ui/const-generics/defaults/concrete-const-param-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(generic_const_parameter_types, unsized_const_params, adt_const_params)]
//~^ WARN the feature `generic_const_parameter_types` is incomplete
//~| WARN the feature `unsized_const_params` is incomplete
// Make sure that we test the const param type of default const parameters
// if both the type of the default and the type of the parameter are concrete.

use std::marker::ConstParamTy_;

struct Foo<const N: u32, const M: u64 = N>; //~ ERROR the constant `N` is not of type `u64`
struct Bar<T: ConstParamTy_, const N: T, const M: u64 = N>(T); // ok
struct Baz<T: ConstParamTy_, const N: u32, const M: T = N>(T); // ok

fn main() {}
25 changes: 25 additions & 0 deletions tests/ui/const-generics/defaults/concrete-const-param-type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
warning: the feature `generic_const_parameter_types` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/concrete-const-param-type.rs:1:12
|
LL | #![feature(generic_const_parameter_types, unsized_const_params, adt_const_params)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #137626 <https://github.com/rust-lang/rust/issues/137626> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/concrete-const-param-type.rs:1:43
|
LL | #![feature(generic_const_parameter_types, unsized_const_params, adt_const_params)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information

error: the constant `N` is not of type `u64`
--> $DIR/concrete-const-param-type.rs:9:26
|
LL | struct Foo<const N: u32, const M: u64 = N>;
| ^^^^^^^^^^^^^^^^ expected `u64`, found `u32`

error: aborting due to 1 previous error; 2 warnings emitted