Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 33 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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)]

0 commit comments

Comments
 (0)