Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite1d73c2

Browse files
committed
Revert "Rollup merge ofrust-lang#125362 - joboet:tait_hack, r=Nilstrieb"
This reverts commit1e4bde1, reversingchanges made to4ee97fc.
1 parentf72e4a9 commite1d73c2

File tree

5 files changed

+117
-44
lines changed

5 files changed

+117
-44
lines changed

‎core/src/internal_macros.rs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,47 @@ 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: identimpl$( <$( $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+
&mutself,
106+
($( $arg,)*):($( $ArgTy,)*)
107+
) -> $ReturnTy{
108+
Fn::call(&*self,($( $arg,)*))
109+
}
110+
}
111+
112+
impl $( <$( $lifetime),+>)?FnOnce<($( $ArgTy,)*)>for $Name{
113+
typeOutput = $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+
83124
/// A macro for defining `#[cfg]` if-else statements.
84125
///
85126
/// `cfg_if` is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade

‎core/src/lib.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@
255255
#![feature(trait_alias)]
256256
#![feature(transparent_unions)]
257257
#![feature(try_blocks)]
258-
#![feature(type_alias_impl_trait)]
259258
#![feature(unboxed_closures)]
260259
#![feature(unsized_fn_params)]
261260
#![feature(with_negative_coherence)]

‎core/src/slice/ascii.rs‎

Lines changed: 7 additions & 2 deletions
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
pubfnescape_ascii(&self) ->EscapeAscii<'_>{
111-
EscapeAscii{inner:self.iter().flat_map(|byte| byte.escape_ascii())}
111+
EscapeAscii{inner:self.iter().flat_map(EscapeByte)}
112112
}
113113

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

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

195200
/// An iterator over the escaped version of a byte slice.
196201
///

‎core/src/str/iter.rs‎

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

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

‎core/src/str/mod.rs‎

Lines changed: 67 additions & 37 deletions
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
pubfnsplit_whitespace(&self) ->SplitWhitespace<'_>{
986-
SplitWhitespace{inner:self.split(char::is_whitespace).filter(|s| !s.is_empty())}
986+
SplitWhitespace{inner:self.split(IsWhitespace).filter(IsNotEmpty)}
987987
}
988988

989989
/// Splits a string slice by ASCII whitespace.
@@ -1032,13 +1032,8 @@ impl str {
10321032
#[stable(feature ="split_ascii_whitespace", since ="1.34.0")]
10331033
#[inline]
10341034
pubfnsplit_ascii_whitespace(&self) ->SplitAsciiWhitespace<'_>{
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)});
1035+
let inner =
1036+
self.as_bytes().split(IsAsciiWhitespace).filter(BytesIsNotEmpty).map(UnsafeBytesToStr);
10421037
SplitAsciiWhitespace{ inner}
10431038
}
10441039

@@ -1090,11 +1085,7 @@ impl str {
10901085
#[stable(feature ="rust1", since ="1.0.0")]
10911086
#[inline]
10921087
pubfnlines(&self) ->Lines<'_>{
1093-
Lines(self.split_inclusive('\n').map(|line|{
1094-
letSome(line) = line.strip_suffix('\n')else{return line};
1095-
letSome(line) = line.strip_suffix('\r')else{return line};
1096-
line
1097-
}))
1088+
Lines(self.split_inclusive('\n').map(LinesMap))
10981089
}
10991090

11001091
/// An iterator over the lines of a string.
@@ -2645,19 +2636,14 @@ impl str {
26452636
#[stable(feature ="str_escape", since ="1.34.0")]
26462637
pubfnescape_debug(&self) ->EscapeDebug<'_>{
26472638
letmut chars =self.chars();
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}
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+
}
26612647
}
26622648

26632649
/// Return an iterator that escapes each char in `self` with [`char::escape_default`].
@@ -2695,7 +2681,7 @@ impl str {
26952681
without modifying the original"]
26962682
#[stable(feature ="str_escape", since ="1.34.0")]
26972683
pubfnescape_default(&self) ->EscapeDefault<'_>{
2698-
EscapeDefault{inner:self.chars().flat_map(char::escape_default)}
2684+
EscapeDefault{inner:self.chars().flat_map(CharEscapeDefault)}
26992685
}
27002686

27012687
/// Return an iterator that escapes each char in `self` with [`char::escape_unicode`].
@@ -2733,7 +2719,7 @@ impl str {
27332719
without modifying the original"]
27342720
#[stable(feature ="str_escape", since ="1.34.0")]
27352721
pubfnescape_unicode(&self) ->EscapeUnicode<'_>{
2736-
EscapeUnicode{inner:self.chars().flat_map(char::escape_unicode)}
2722+
EscapeUnicode{inner:self.chars().flat_map(CharEscapeUnicode)}
27372723
}
27382724
}
27392725

@@ -2764,15 +2750,59 @@ impl Default for &mut str {
27642750
}
27652751
}
27662752

2767-
typeLinesMap =impl(Fn(&str) ->&str) +Copy;
2768-
typeCharEscapeDebugContinue =impl(FnMut(char) -> char::EscapeDebug) +Copy;
2769-
typeCharEscapeUnicode =impl(Fn(char) -> char::EscapeUnicode) +Copy;
2770-
typeCharEscapeDefault =impl(Fn(char) -> char::EscapeDefault) +Copy;
2771-
typeIsWhitespace =impl(Fn(char) ->bool) +Copy;
2772-
typeIsAsciiWhitespace =impl(Fn(&u8) ->bool) +Copy;
2773-
typeIsNotEmpty =impl(Fn(&&str) ->bool) +Copy;
2774-
typeBytesIsNotEmpty<'a> =impl(FnMut(&&'a[u8]) ->bool) +Copy;
2775-
typeUnsafeBytesToStr<'a> =impl(FnMut(&'a[u8]) ->&'astr) +Copy;
2753+
impl_fn_for_zst!{
2754+
/// A nameable, cloneable fn type
2755+
#[derive(Clone)]
2756+
structLinesMapimpl<'a>Fn = |line:&'astr| ->&'astr{
2757+
letSome(line) = line.strip_suffix('\n') else{return line};
2758+
letSome(line) = line.strip_suffix('\r') else{return line};
2759+
line
2760+
};
2761+
2762+
#[derive(Clone)]
2763+
structCharEscapeDebugContinueimplFn = |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+
structCharEscapeUnicodeimplFn = |c:char| ->char::EscapeUnicode{
2773+
c.escape_unicode()
2774+
};
2775+
#[derive(Clone)]
2776+
structCharEscapeDefaultimplFn = |c:char| ->char::EscapeDefault{
2777+
c.escape_default()
2778+
};
2779+
2780+
#[derive(Clone)]
2781+
structIsWhitespaceimplFn = |c:char| ->bool{
2782+
c.is_whitespace()
2783+
};
2784+
2785+
#[derive(Clone)]
2786+
structIsAsciiWhitespaceimplFn = |byte:&u8| ->bool{
2787+
byte.is_ascii_whitespace()
2788+
};
2789+
2790+
#[derive(Clone)]
2791+
structIsNotEmptyimpl<'a,'b>Fn = |s:&'a&'bstr| ->bool{
2792+
!s.is_empty()
2793+
};
2794+
2795+
#[derive(Clone)]
2796+
structBytesIsNotEmptyimpl<'a,'b>Fn = |s:&'a&'b[u8]| ->bool{
2797+
!s.is_empty()
2798+
};
2799+
2800+
#[derive(Clone)]
2801+
structUnsafeBytesToStrimpl<'a>Fn = |bytes:&'a[u8]| ->&'astr{
2802+
// SAFETY: not safe
2803+
unsafe{ from_utf8_unchecked(bytes)}
2804+
};
2805+
}
27762806

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp