Skip to content

Commit 1fce3b3

Browse files
committed
Auto merge of rust-lang#125463 - GuillaumeGomez:rollup-287wx4y, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - rust-lang#125263 (rust-lld: fallback to rustc's sysroot if there's no path to the linker in the target sysroot) - rust-lang#125345 (rustc_codegen_llvm: add support for writing summary bitcode) - rust-lang#125362 (Actually use TAIT instead of emulating it) - rust-lang#125412 (Don't suggest adding the unexpected cfgs to the build-script it-self) - rust-lang#125445 (Migrate `run-make/rustdoc-with-short-out-dir-option` to `rmake.rs`) - rust-lang#125452 (Cleanup check-cfg handling in core and std) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2e46495 + e14d824 commit 1fce3b3

File tree

9 files changed

+65
-125
lines changed

9 files changed

+65
-125
lines changed

core/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ check-cfg = [
4646
'cfg(bootstrap)',
4747
'cfg(no_fp_fmt_parse)',
4848
'cfg(stdarch_intel_sde)',
49-
# This matches `EXTRA_CHECK_CFGS` in `src/bootstrap/src/lib.rs`.
49+
# core use #[path] imports to portable-simd `core_simd` crate
50+
# and to stdarch `core_arch` crate which messes-up with Cargo list
51+
# of declared features, we therefor expect any feature cfg
5052
'cfg(feature, values(any()))',
5153
]

core/src/internal_macros.rs

-41
Original file line numberDiff line numberDiff line change
@@ -80,47 +80,6 @@ macro_rules! forward_ref_op_assign {
8080
}
8181
}
8282

83-
/// Create a zero-size type similar to a closure type, but named.
84-
macro_rules! impl_fn_for_zst {
85-
($(
86-
$( #[$attr: meta] )*
87-
struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn =
88-
|$( $arg: ident: $ArgTy: ty ),*| -> $ReturnTy: ty
89-
$body: block;
90-
)+) => {
91-
$(
92-
$( #[$attr] )*
93-
struct $Name;
94-
95-
impl $( <$( $lifetime ),+> )? Fn<($( $ArgTy, )*)> for $Name {
96-
#[inline]
97-
extern "rust-call" fn call(&self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
98-
$body
99-
}
100-
}
101-
102-
impl $( <$( $lifetime ),+> )? FnMut<($( $ArgTy, )*)> for $Name {
103-
#[inline]
104-
extern "rust-call" fn call_mut(
105-
&mut self,
106-
($( $arg, )*): ($( $ArgTy, )*)
107-
) -> $ReturnTy {
108-
Fn::call(&*self, ($( $arg, )*))
109-
}
110-
}
111-
112-
impl $( <$( $lifetime ),+> )? FnOnce<($( $ArgTy, )*)> for $Name {
113-
type Output = $ReturnTy;
114-
115-
#[inline]
116-
extern "rust-call" fn call_once(self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy {
117-
Fn::call(&self, ($( $arg, )*))
118-
}
119-
}
120-
)+
121-
}
122-
}
123-
12483
/// A macro for defining `#[cfg]` if-else statements.
12584
///
12685
/// `cfg_if` is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade

core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@
255255
#![feature(trait_alias)]
256256
#![feature(transparent_unions)]
257257
#![feature(try_blocks)]
258+
#![feature(type_alias_impl_trait)]
258259
#![feature(unboxed_closures)]
259260
#![feature(unsized_fn_params)]
260261
#![feature(with_negative_coherence)]

core/src/slice/ascii.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl [u8] {
108108
without modifying the original"]
109109
#[stable(feature = "inherent_ascii_escape", since = "1.60.0")]
110110
pub fn escape_ascii(&self) -> EscapeAscii<'_> {
111-
EscapeAscii { inner: self.iter().flat_map(EscapeByte) }
111+
EscapeAscii { inner: self.iter().flat_map(|byte| byte.escape_ascii()) }
112112
}
113113

114114
/// Returns a byte slice with leading ASCII whitespace bytes removed.
@@ -190,12 +190,7 @@ impl [u8] {
190190
}
191191
}
192192

193-
impl_fn_for_zst! {
194-
#[derive(Clone)]
195-
struct EscapeByte impl Fn = |byte: &u8| -> ascii::EscapeDefault {
196-
ascii::escape_default(*byte)
197-
};
198-
}
193+
type EscapeByte = impl (Fn(&u8) -> ascii::EscapeDefault) + Copy;
199194

200195
/// An iterator over the escaped version of a byte slice.
201196
///

core/src/str/iter.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1274,8 +1274,10 @@ pub struct SplitWhitespace<'a> {
12741274
#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
12751275
#[derive(Clone, Debug)]
12761276
pub struct SplitAsciiWhitespace<'a> {
1277-
pub(super) inner:
1278-
Map<Filter<SliceSplit<'a, u8, IsAsciiWhitespace>, BytesIsNotEmpty>, UnsafeBytesToStr>,
1277+
pub(super) inner: Map<
1278+
Filter<SliceSplit<'a, u8, IsAsciiWhitespace>, BytesIsNotEmpty<'a>>,
1279+
UnsafeBytesToStr<'a>,
1280+
>,
12791281
}
12801282

12811283
/// An iterator over the substrings of a string,

core/src/str/mod.rs

+37-67
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ impl str {
983983
#[cfg_attr(not(test), rustc_diagnostic_item = "str_split_whitespace")]
984984
#[inline]
985985
pub fn split_whitespace(&self) -> SplitWhitespace<'_> {
986-
SplitWhitespace { inner: self.split(IsWhitespace).filter(IsNotEmpty) }
986+
SplitWhitespace { inner: self.split(char::is_whitespace).filter(|s| !s.is_empty()) }
987987
}
988988

989989
/// Splits a string slice by ASCII whitespace.
@@ -1032,8 +1032,13 @@ impl str {
10321032
#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
10331033
#[inline]
10341034
pub fn split_ascii_whitespace(&self) -> SplitAsciiWhitespace<'_> {
1035-
let inner =
1036-
self.as_bytes().split(IsAsciiWhitespace).filter(BytesIsNotEmpty).map(UnsafeBytesToStr);
1035+
let inner = self
1036+
.as_bytes()
1037+
.split(u8::is_ascii_whitespace)
1038+
.filter(|s| !s.is_empty())
1039+
// SAFETY: the byte slice came from a string and was only split
1040+
// along character boundaries, so the resulting slices are strings.
1041+
.map(|bytes| unsafe { from_utf8_unchecked(bytes) });
10371042
SplitAsciiWhitespace { inner }
10381043
}
10391044

@@ -1085,7 +1090,11 @@ impl str {
10851090
#[stable(feature = "rust1", since = "1.0.0")]
10861091
#[inline]
10871092
pub fn lines(&self) -> Lines<'_> {
1088-
Lines(self.split_inclusive('\n').map(LinesMap))
1093+
Lines(self.split_inclusive('\n').map(|line| {
1094+
let Some(line) = line.strip_suffix('\n') else { return line };
1095+
let Some(line) = line.strip_suffix('\r') else { return line };
1096+
line
1097+
}))
10891098
}
10901099

10911100
/// An iterator over the lines of a string.
@@ -2636,14 +2645,19 @@ impl str {
26362645
#[stable(feature = "str_escape", since = "1.34.0")]
26372646
pub fn escape_debug(&self) -> EscapeDebug<'_> {
26382647
let mut chars = self.chars();
2639-
EscapeDebug {
2640-
inner: chars
2641-
.next()
2642-
.map(|first| first.escape_debug_ext(EscapeDebugExtArgs::ESCAPE_ALL))
2643-
.into_iter()
2644-
.flatten()
2645-
.chain(chars.flat_map(CharEscapeDebugContinue)),
2646-
}
2648+
let first = chars
2649+
.next()
2650+
.map(|first| first.escape_debug_ext(EscapeDebugExtArgs::ESCAPE_ALL))
2651+
.into_iter()
2652+
.flatten();
2653+
let inner = first.chain(chars.flat_map(|c| {
2654+
c.escape_debug_ext(EscapeDebugExtArgs {
2655+
escape_grapheme_extended: false,
2656+
escape_single_quote: true,
2657+
escape_double_quote: true,
2658+
})
2659+
}));
2660+
EscapeDebug { inner }
26472661
}
26482662

26492663
/// Return an iterator that escapes each char in `self` with [`char::escape_default`].
@@ -2681,7 +2695,7 @@ impl str {
26812695
without modifying the original"]
26822696
#[stable(feature = "str_escape", since = "1.34.0")]
26832697
pub fn escape_default(&self) -> EscapeDefault<'_> {
2684-
EscapeDefault { inner: self.chars().flat_map(CharEscapeDefault) }
2698+
EscapeDefault { inner: self.chars().flat_map(char::escape_default) }
26852699
}
26862700

26872701
/// Return an iterator that escapes each char in `self` with [`char::escape_unicode`].
@@ -2719,7 +2733,7 @@ impl str {
27192733
without modifying the original"]
27202734
#[stable(feature = "str_escape", since = "1.34.0")]
27212735
pub fn escape_unicode(&self) -> EscapeUnicode<'_> {
2722-
EscapeUnicode { inner: self.chars().flat_map(CharEscapeUnicode) }
2736+
EscapeUnicode { inner: self.chars().flat_map(char::escape_unicode) }
27232737
}
27242738
}
27252739

@@ -2750,59 +2764,15 @@ impl Default for &mut str {
27502764
}
27512765
}
27522766

2753-
impl_fn_for_zst! {
2754-
/// A nameable, cloneable fn type
2755-
#[derive(Clone)]
2756-
struct LinesMap impl<'a> Fn = |line: &'a str| -> &'a str {
2757-
let Some(line) = line.strip_suffix('\n') else { return line };
2758-
let Some(line) = line.strip_suffix('\r') else { return line };
2759-
line
2760-
};
2761-
2762-
#[derive(Clone)]
2763-
struct CharEscapeDebugContinue impl Fn = |c: char| -> char::EscapeDebug {
2764-
c.escape_debug_ext(EscapeDebugExtArgs {
2765-
escape_grapheme_extended: false,
2766-
escape_single_quote: true,
2767-
escape_double_quote: true
2768-
})
2769-
};
2770-
2771-
#[derive(Clone)]
2772-
struct CharEscapeUnicode impl Fn = |c: char| -> char::EscapeUnicode {
2773-
c.escape_unicode()
2774-
};
2775-
#[derive(Clone)]
2776-
struct CharEscapeDefault impl Fn = |c: char| -> char::EscapeDefault {
2777-
c.escape_default()
2778-
};
2779-
2780-
#[derive(Clone)]
2781-
struct IsWhitespace impl Fn = |c: char| -> bool {
2782-
c.is_whitespace()
2783-
};
2784-
2785-
#[derive(Clone)]
2786-
struct IsAsciiWhitespace impl Fn = |byte: &u8| -> bool {
2787-
byte.is_ascii_whitespace()
2788-
};
2789-
2790-
#[derive(Clone)]
2791-
struct IsNotEmpty impl<'a, 'b> Fn = |s: &'a &'b str| -> bool {
2792-
!s.is_empty()
2793-
};
2794-
2795-
#[derive(Clone)]
2796-
struct BytesIsNotEmpty impl<'a, 'b> Fn = |s: &'a &'b [u8]| -> bool {
2797-
!s.is_empty()
2798-
};
2799-
2800-
#[derive(Clone)]
2801-
struct UnsafeBytesToStr impl<'a> Fn = |bytes: &'a [u8]| -> &'a str {
2802-
// SAFETY: not safe
2803-
unsafe { from_utf8_unchecked(bytes) }
2804-
};
2805-
}
2767+
type LinesMap = impl (Fn(&str) -> &str) + Copy;
2768+
type CharEscapeDebugContinue = impl (FnMut(char) -> char::EscapeDebug) + Copy;
2769+
type CharEscapeUnicode = impl (Fn(char) -> char::EscapeUnicode) + Copy;
2770+
type CharEscapeDefault = impl (Fn(char) -> char::EscapeDefault) + Copy;
2771+
type IsWhitespace = impl (Fn(char) -> bool) + Copy;
2772+
type IsAsciiWhitespace = impl (Fn(&u8) -> bool) + Copy;
2773+
type IsNotEmpty = impl (Fn(&&str) -> bool) + Copy;
2774+
type BytesIsNotEmpty<'a> = impl (FnMut(&&'a [u8]) -> bool) + Copy;
2775+
type UnsafeBytesToStr<'a> = impl (FnMut(&'a [u8]) -> &'a str) + Copy;
28062776

28072777
// This is required to make `impl From<&str> for Box<dyn Error>` and `impl<E> From<E> for Box<dyn Error>` not overlap.
28082778
#[stable(feature = "rust1", since = "1.0.0")]

std/Cargo.toml

+7-3
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ test = true
100100

101101
[lints.rust.unexpected_cfgs]
102102
level = "warn"
103+
# x.py uses beta cargo, so `check-cfg` entries do not yet take effect
104+
# for rust-lang/rust. But for users of `-Zbuild-std` it does.
105+
# The unused warning is waiting for rust-lang/cargo#13925 to reach beta.
103106
check-cfg = [
104107
'cfg(bootstrap)',
105-
'cfg(backtrace_in_libstd)',
106-
'cfg(netbsd10)',
107108
'cfg(target_arch, values("xtensa"))',
108-
'cfg(feature, values("std", "as_crate"))',
109+
# std use #[path] imports to portable-simd `std_float` crate
110+
# and to the `backtrace` crate which messes-up with Cargo list
111+
# of declared features, we therefor expect any feature cfg
112+
'cfg(feature, values(any()))',
109113
]

std/build.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ fn main() {
77
let target_vendor =
88
env::var("CARGO_CFG_TARGET_VENDOR").expect("CARGO_CFG_TARGET_VENDOR was not set");
99
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set");
10+
11+
println!("cargo:rustc-check-cfg=cfg(netbsd10)");
1012
if target_os == "netbsd" && env::var("RUSTC_STD_NETBSD10").is_ok() {
1113
println!("cargo:rustc-cfg=netbsd10");
1214
}
15+
16+
println!("cargo:rustc-check-cfg=cfg(restricted_std)");
1317
if target_os == "linux"
1418
|| target_os == "android"
1519
|| target_os == "netbsd"
@@ -59,8 +63,11 @@ fn main() {
5963
// - arch=avr
6064
// - JSON targets
6165
// - Any new targets that have not been explicitly added above.
62-
println!("cargo:rustc-cfg=feature=\"restricted-std\"");
66+
println!("cargo:rustc-cfg=restricted_std");
6367
}
64-
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
68+
69+
println!("cargo:rustc-check-cfg=cfg(backtrace_in_libstd)");
6570
println!("cargo:rustc-cfg=backtrace_in_libstd");
71+
72+
println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap());
6673
}

std/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@
213213
//! [array]: prim@array
214214
//! [slice]: prim@slice
215215
216-
#![cfg_attr(not(feature = "restricted-std"), stable(feature = "rust1", since = "1.0.0"))]
216+
#![cfg_attr(not(restricted_std), stable(feature = "rust1", since = "1.0.0"))]
217217
#![cfg_attr(
218-
feature = "restricted-std",
218+
restricted_std,
219219
unstable(
220220
feature = "restricted_std",
221221
issue = "none",

0 commit comments

Comments
 (0)