Skip to content

Commit c955f48

Browse files
committed
Auto merge of #140356 - tgross35:rollup-cvqvrg4, r=tgross35
Rollup of 8 pull requests Successful merges: - #137439 (Stabilise `std::ffi::c_str`) - #139031 (Use char::is_whitespace directly in str::trim*) - #139090 (fix docs for `Peekable::next_if{_eq}`) - #140220 (Fix detection of main function if there are expressions around it) - #140297 (Update example to use CStr::to_string_lossy) - #140330 (Clarified bootstrap optimization "true" argument) - #140339 (session: Cleanup `CanonicalizedPath::new`) - #140348 (Update lint-docs to default to Rust 2024) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 496145b + c718a63 commit c955f48

File tree

24 files changed

+112
-72
lines changed

24 files changed

+112
-72
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_interface/src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(rustc::bad_opt_access)]
2-
use std::collections::{BTreeMap, BTreeSet};
2+
use std::collections::BTreeMap;
33
use std::num::NonZero;
4-
use std::path::{Path, PathBuf};
4+
use std::path::PathBuf;
55
use std::sync::atomic::AtomicBool;
66

77
use rustc_abi::Align;
@@ -89,8 +89,8 @@ where
8989
S: Into<String>,
9090
I: IntoIterator<Item = S>,
9191
{
92-
let locations: BTreeSet<CanonicalizedPath> =
93-
locations.into_iter().map(|s| CanonicalizedPath::new(Path::new(&s.into()))).collect();
92+
let locations =
93+
locations.into_iter().map(|s| CanonicalizedPath::new(PathBuf::from(s.into()))).collect();
9494

9595
ExternEntry {
9696
location: ExternLocation::ExactPaths(locations),

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ declare_lint! {
948948
///
949949
/// ### Example
950950
///
951-
/// ```rust,compile_fail
951+
/// ```rust,compile_fail,edition2021
952952
/// #[no_mangle]
953953
/// const FOO: i32 = 5;
954954
/// ```

compiler/rustc_lint/src/impl_trait_overcaptures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ declare_lint! {
4141
///
4242
/// ### Example
4343
///
44-
/// ```rust,compile_fail
44+
/// ```rust,compile_fail,edition2021
4545
/// # #![deny(impl_trait_overcaptures)]
4646
/// # use std::fmt::Display;
4747
/// let mut x = vec![];

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ declare_lint! {
14241424
///
14251425
/// ### Example
14261426
///
1427-
/// ```rust,compile_fail
1427+
/// ```rust,compile_fail,edition2021
14281428
/// macro_rules! foo {
14291429
/// () => {};
14301430
/// ($name) => { };
@@ -4128,7 +4128,7 @@ declare_lint! {
41284128
///
41294129
/// ### Example
41304130
///
4131-
/// ```rust,compile_fail
4131+
/// ```rust,compile_fail,edition2021
41324132
/// #![deny(dependency_on_unit_never_type_fallback)]
41334133
/// fn main() {
41344134
/// if true {

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,14 +2323,13 @@ pub fn parse_externs(
23232323
let ExternOpt { crate_name: name, path, options } =
23242324
split_extern_opt(early_dcx, unstable_opts, &arg).unwrap_or_else(|e| e.emit());
23252325

2326-
let path = path.map(|p| CanonicalizedPath::new(p.as_path()));
2327-
23282326
let entry = externs.entry(name.to_owned());
23292327

23302328
use std::collections::btree_map::Entry;
23312329

23322330
let entry = if let Some(path) = path {
23332331
// --extern prelude_name=some_file.rlib
2332+
let path = CanonicalizedPath::new(path);
23342333
match entry {
23352334
Entry::Vacant(vacant) => {
23362335
let files = BTreeSet::from_iter(iter::once(path));

compiler/rustc_session/src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::PathBuf;
22
use std::sync::OnceLock;
33

44
use rustc_data_structures::profiling::VerboseTimingGuard;
@@ -104,8 +104,8 @@ pub struct CanonicalizedPath {
104104
}
105105

106106
impl CanonicalizedPath {
107-
pub fn new(path: &Path) -> Self {
108-
Self { original: path.to_owned(), canonicalized: try_canonicalize(path).ok() }
107+
pub fn new(path: PathBuf) -> Self {
108+
Self { canonicalized: try_canonicalize(&path).ok(), original: path }
109109
}
110110

111111
pub fn canonicalized(&self) -> &PathBuf {

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());

0 commit comments

Comments
 (0)