Skip to content

Commit 9d6039c

Browse files
committed
Auto merge of #130755 - workingjubilee:rollup-zpja9b3, r=workingjubilee
Rollup of 7 pull requests Successful merges: - #129201 (std: implement the `random` feature (alternative version)) - #130536 (bootstrap: Set the dylib path when building books with rustdoc) - #130551 (Fix `break_last_token`.) - #130657 (Remove x86_64-fuchsia and aarch64-fuchsia target aliases) - #130721 (Add more test cases for block-no-opening-brace) - #130736 (Add rustfmt 2024 reformatting to git blame ignore) - #130746 (readd `@tgross35` and `@joboet` to the review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 648d024 + c7abc85 commit 9d6039c

59 files changed

Lines changed: 948 additions & 565 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.git-blame-ignore-revs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ ec2cc761bc7067712ecc7734502f703fe3b024c8
2727
84ac80f1921afc243d71fd0caaa4f2838c294102
2828
# bless mir-opt tests to add `copy`
2929
99cb0c6bc399fb94a0ddde7e9b38e9c00d523bad
30+
# reformat with rustfmt edition 2024
31+
c682aa162b0d41e21cc6748f4fecfe01efb69d1f

‎compiler/rustc_ast/src/token.rs‎

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -385,35 +385,41 @@ impl TokenKind {
385385
Literal(Lit::new(kind, symbol, suffix))
386386
}
387387

388-
/// An approximation to proc-macro-style single-character operators used by rustc parser.
389-
/// If the operator token can be broken into two tokens, the first of which is single-character,
390-
/// then this function performs that operation, otherwise it returns `None`.
391-
pubfnbreak_two_token_op(&self) -> Option<(TokenKind,TokenKind)>{
392-
Some(match*self{
393-
Le => (Lt,Eq),
394-
EqEq => (Eq,Eq),
395-
Ne => (Not,Eq),
396-
Ge => (Gt,Eq),
397-
AndAnd => (BinOp(And),BinOp(And)),
398-
OrOr => (BinOp(Or),BinOp(Or)),
399-
BinOp(Shl) => (Lt,Lt),
400-
BinOp(Shr) => (Gt,Gt),
401-
BinOpEq(Plus) => (BinOp(Plus),Eq),
402-
BinOpEq(Minus) => (BinOp(Minus),Eq),
403-
BinOpEq(Star) => (BinOp(Star),Eq),
404-
BinOpEq(Slash) => (BinOp(Slash),Eq),
405-
BinOpEq(Percent) => (BinOp(Percent),Eq),
406-
BinOpEq(Caret) => (BinOp(Caret),Eq),
407-
BinOpEq(And) => (BinOp(And),Eq),
408-
BinOpEq(Or) => (BinOp(Or),Eq),
409-
BinOpEq(Shl) => (Lt,Le),
410-
BinOpEq(Shr) => (Gt,Ge),
411-
DotDot => (Dot,Dot),
412-
DotDotDot => (Dot,DotDot),
413-
PathSep => (Colon,Colon),
414-
RArrow => (BinOp(Minus),Gt),
415-
LArrow => (Lt,BinOp(Minus)),
416-
FatArrow => (Eq,Gt),
388+
/// An approximation to proc-macro-style single-character operators used by
389+
/// rustc parser. If the operator token can be broken into two tokens, the
390+
/// first of which has `n` (1 or 2) chars, then this function performs that
391+
/// operation, otherwise it returns `None`.
392+
pubfnbreak_two_token_op(&self,n:u32) -> Option<(TokenKind,TokenKind)>{
393+
assert!(n == 1 || n == 2);
394+
Some(match(self, n){
395+
(Le,1) => (Lt,Eq),
396+
(EqEq,1) => (Eq,Eq),
397+
(Ne,1) => (Not,Eq),
398+
(Ge,1) => (Gt,Eq),
399+
(AndAnd,1) => (BinOp(And),BinOp(And)),
400+
(OrOr,1) => (BinOp(Or),BinOp(Or)),
401+
(BinOp(Shl),1) => (Lt,Lt),
402+
(BinOp(Shr),1) => (Gt,Gt),
403+
(BinOpEq(Plus),1) => (BinOp(Plus),Eq),
404+
(BinOpEq(Minus),1) => (BinOp(Minus),Eq),
405+
(BinOpEq(Star),1) => (BinOp(Star),Eq),
406+
(BinOpEq(Slash),1) => (BinOp(Slash),Eq),
407+
(BinOpEq(Percent),1) => (BinOp(Percent),Eq),
408+
(BinOpEq(Caret),1) => (BinOp(Caret),Eq),
409+
(BinOpEq(And),1) => (BinOp(And),Eq),
410+
(BinOpEq(Or),1) => (BinOp(Or),Eq),
411+
(BinOpEq(Shl),1) => (Lt,Le),// `<` + `<=`
412+
(BinOpEq(Shl),2) => (BinOp(Shl),Eq),// `<<` + `=`
413+
(BinOpEq(Shr),1) => (Gt,Ge),// `>` + `>=`
414+
(BinOpEq(Shr),2) => (BinOp(Shr),Eq),// `>>` + `=`
415+
(DotDot,1) => (Dot,Dot),
416+
(DotDotDot,1) => (Dot,DotDot),// `.` + `..`
417+
(DotDotDot,2) => (DotDot,Dot),// `..` + `.`
418+
(DotDotEq,2) => (DotDot,Eq),
419+
(PathSep,1) => (Colon,Colon),
420+
(RArrow,1) => (BinOp(Minus),Gt),
421+
(LArrow,1) => (Lt,BinOp(Minus)),
422+
(FatArrow,1) => (Eq,Gt),
417423
_ => returnNone,
418424
})
419425
}

‎compiler/rustc_parse/src/parser/attr_wrapper.rs‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct LazyAttrTokenStreamImpl {
108108
start_token:(Token,Spacing),
109109
cursor_snapshot:TokenCursor,
110110
num_calls:u32,
111-
break_last_token:bool,
111+
break_last_token:u32,
112112
node_replacements:Box<[NodeReplacement]>,
113113
}
114114

@@ -339,17 +339,20 @@ impl<'a> Parser<'a> {
339339
let parser_replacements_end = self.capture_state.parser_replacements.len();
340340

341341
assert!(
342-
!(self.break_last_token && matches!(capture_trailing,Trailing::Yes)),
343-
"Cannot set break_last_token and have trailing token"
342+
!(self.break_last_token > 0&& matches!(capture_trailing,Trailing::Yes)),
343+
"Cannot have break_last_token > 0 and have trailing token"
344344
);
345+
assert!(self.break_last_token <= 2,"cannot break token more than twice");
345346

346347
let end_pos = self.num_bump_calls
347348
+ capture_trailing asu32
348-
// If we 'broke' the last token (e.g. breaking a '>>' token to two '>' tokens), then
349-
// extend the range of captured tokens to include it, since the parser was not actually
350-
// bumped past it. When the `LazyAttrTokenStream` gets converted into an
351-
// `AttrTokenStream`, we will create the proper token.
352-
+ self.break_last_tokenasu32;
349+
// If we "broke" the last token (e.g. breaking a `>>` token once into `>` + `>`, or
350+
// breaking a `>>=` token twice into `>` + `>` + `=`), then extend the range of
351+
// captured tokens to include it, because the parser was not actually bumped past it.
352+
// (Even if we broke twice, it was still just one token originally, hence the `1`.)
353+
// When the `LazyAttrTokenStream` gets converted into an `AttrTokenStream`, we will
354+
// rebreak that final token once or twice.
355+
+ ifself.break_last_token == 0{0}else{1};
353356

354357
let num_calls = end_pos - collect_pos.start_pos;
355358

@@ -425,7 +428,7 @@ impl<'a> Parser<'a> {
425428
// for the `#[cfg]` and/or `#[cfg_attr]` attrs. This allows us to run
426429
// eager cfg-expansion on the captured token stream.
427430
if definite_capture_mode {
428-
assert!(!self.break_last_token,"Should not have unglued last token with cfg attr");
431+
assert!(self.break_last_token == 0,"Should not have unglued last token with cfg attr");
429432

430433
// What is the status here when parsing the example code at the top of this method?
431434
//
@@ -471,7 +474,7 @@ impl<'a> Parser<'a> {
471474
/// close delims.
472475
fnmake_attr_token_stream(
473476
iter:implIterator<Item = FlatToken>,
474-
break_last_token:bool,
477+
break_last_token:u32,
475478
) -> AttrTokenStream{
476479
#[derive(Debug)]
477480
structFrameData{
@@ -513,18 +516,17 @@ fn make_attr_token_stream(
513516
}
514517
}
515518

516-
if break_last_token {
519+
if break_last_token > 0{
517520
let last_token = stack_top.inner.pop().unwrap();
518521
ifletAttrTokenTree::Token(last_token, spacing) = last_token {
519-
letunglued_first = last_token.kind.break_two_token_op().unwrap().0;
522+
let(unglued, _)= last_token.kind.break_two_token_op(break_last_token).unwrap();
520523

521-
// An 'unglued' token is always two ASCII characters
524+
// Tokens are always ASCII chars, so we can use byte arithmetic here.
522525
letmut first_span = last_token.span.shrink_to_lo();
523-
first_span = first_span.with_hi(first_span.lo() + rustc_span::BytePos(1));
526+
first_span =
527+
first_span.with_hi(first_span.lo() + rustc_span::BytePos(break_last_token));
524528

525-
stack_top
526-
.inner
527-
.push(AttrTokenTree::Token(Token::new(unglued_first, first_span), spacing));
529+
stack_top.inner.push(AttrTokenTree::Token(Token::new(unglued, first_span), spacing));
528530
}else{
529531
panic!("Unexpected last token {last_token:?}")
530532
}

‎compiler/rustc_parse/src/parser/mod.rs‎

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,25 @@ pub struct Parser<'a> {
146146
token_cursor:TokenCursor,
147147
// The number of calls to `bump`, i.e. the position in the token stream.
148148
num_bump_calls:u32,
149-
// During parsing we may sometimes need to 'unglue' a glued token into two
150-
// component tokens (e.g. '>>' into '>' and '>), so the parser can consume
151-
// them one at a time. This process bypasses the normal capturing mechanism
152-
// (e.g. `num_bump_calls` will not be incremented), since the 'unglued'
153-
// tokens due not exist in the original `TokenStream`.
149+
// During parsing we may sometimes need to "unglue" a glued token into two
150+
// or three component tokens (e.g. `>>` into `>` and `>`, or `>>=` into `>`
151+
// and `>` and `=`), so the parser can consume them one at a time. This
152+
// process bypasses the normal capturing mechanism (e.g. `num_bump_calls`
153+
// will not be incremented), since the "unglued" tokens due not exist in
154+
// the original `TokenStream`.
154155
//
155-
// If we end up consuming both unglued tokens, this is not an issue. We'll
156-
// end up capturing the single 'glued' token.
156+
// If we end up consuming all the component tokens, this is not an issue,
157+
// because we'll end up capturing the single "glued" token.
157158
//
158-
// However, sometimes we may want to capture just the first 'unglued'
159+
// However, sometimes we may want to capture not all of the original
159160
// token. For example, capturing the `Vec<u8>` in `Option<Vec<u8>>`
160161
// requires us to unglue the trailing `>>` token. The `break_last_token`
161-
// field is used to track this token. It gets appended to the captured
162+
// field is used to track these tokens. They get appended to the captured
162163
// stream when we evaluate a `LazyAttrTokenStream`.
163-
break_last_token:bool,
164+
//
165+
// This value is always 0, 1, or 2. It can only reach 2 when splitting
166+
// `>>=` or `<<=`.
167+
break_last_token:u32,
164168
/// This field is used to keep track of how many left angle brackets we have seen. This is
165169
/// required in order to detect extra leading left angle brackets (`<` characters) and error
166170
/// appropriately.
@@ -453,7 +457,7 @@ impl<'a> Parser<'a> {
453457
expected_tokens:Vec::new(),
454458
token_cursor:TokenCursor{tree_cursor: stream.into_trees(),stack:Vec::new()},
455459
num_bump_calls:0,
456-
break_last_token:false,
460+
break_last_token:0,
457461
unmatched_angle_bracket_count:0,
458462
angle_bracket_nesting:0,
459463
last_unexpected_token_span:None,
@@ -773,7 +777,7 @@ impl<'a> Parser<'a> {
773777
self.bump();
774778
returntrue;
775779
}
776-
matchself.token.kind.break_two_token_op(){
780+
matchself.token.kind.break_two_token_op(1){
777781
Some((first, second))if first == expected => {
778782
let first_span = self.psess.source_map().start_point(self.token.span);
779783
let second_span = self.token.span.with_lo(first_span.hi());
@@ -783,8 +787,8 @@ impl<'a> Parser<'a> {
783787
//
784788
// If we consume any additional tokens, then this token
785789
// is not needed (we'll capture the entire 'glued' token),
786-
// and `bump` will set this field to `None`
787-
self.break_last_token= true;
790+
// and `bump` will set this field to 0.
791+
self.break_last_token+= 1;
788792
// Use the spacing of the glued token as the spacing of the
789793
// unglued second token.
790794
self.bump_with((Token::new(second, second_span),self.token_spacing));
@@ -1148,10 +1152,9 @@ impl<'a> Parser<'a> {
11481152
// than `.0`/`.1` access.
11491153
letmut next = self.token_cursor.inlined_next();
11501154
self.num_bump_calls += 1;
1151-
// We've retrieved an token from the underlying
1152-
// cursor, so we no longer need to worry about
1153-
// an unglued token. See `break_and_eat` for more details
1154-
self.break_last_token = false;
1155+
// We got a token from the underlying cursor and no longer need to
1156+
// worry about an unglued token. See `break_and_eat` for more details.
1157+
self.break_last_token = 0;
11551158
if next.0.span.is_dummy(){
11561159
// Tweak the location for better diagnostics, but keep syntactic context intact.
11571160
let fallback_span = self.token.span;

‎compiler/rustc_target/src/spec/mod.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,12 +1690,8 @@ supported_targets! {
16901690
("x86_64h-apple-darwin", x86_64h_apple_darwin),
16911691
("i686-apple-darwin", i686_apple_darwin),
16921692

1693-
// FIXME(#106649): Remove aarch64-fuchsia in favor of aarch64-unknown-fuchsia
1694-
("aarch64-fuchsia", aarch64_fuchsia),
16951693
("aarch64-unknown-fuchsia", aarch64_unknown_fuchsia),
16961694
("riscv64gc-unknown-fuchsia", riscv64gc_unknown_fuchsia),
1697-
// FIXME(#106649): Remove x86_64-fuchsia in favor of x86_64-unknown-fuchsia
1698-
("x86_64-fuchsia", x86_64_fuchsia),
16991695
("x86_64-unknown-fuchsia", x86_64_unknown_fuchsia),
17001696

17011697
("avr-unknown-gnu-atmega328", avr_unknown_gnu_atmega328),

‎compiler/rustc_target/src/spec/targets/aarch64_fuchsia.rs‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎compiler/rustc_target/src/spec/targets/x86_64_fuchsia.rs‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎library/core/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ pub mod panicking;
394394
#[unstable(feature = "core_pattern_types", issue = "123646")]
395395
pubmod pat;
396396
pubmod pin;
397+
#[unstable(feature = "random", issue = "130703")]
398+
pubmod random;
397399
#[unstable(feature = "new_range_api", issue = "125687")]
398400
pubmod range;
399401
pubmod result;

‎library/core/src/random.rs‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//! Random value generation.
2+
//!
3+
//! The [`Random`] trait allows generating a random value for a type using a
4+
//! given [`RandomSource`].
5+
6+
/// A source of randomness.
7+
#[unstable(feature = "random", issue = "130703")]
8+
pubtraitRandomSource{
9+
/// Fills `bytes` with random bytes.
10+
fnfill_bytes(&mutself,bytes:&mut[u8]);
11+
}
12+
13+
/// A trait for getting a random value for a type.
14+
///
15+
/// **Warning:** Be careful when manipulating random values! The
16+
/// [`random`](Random::random) method on integers samples them with a uniform
17+
/// distribution, so a value of 1 is just as likely as [`i32::MAX`]. By using
18+
/// modulo operations, some of the resulting values can become more likely than
19+
/// others. Use audited crates when in doubt.
20+
#[unstable(feature = "random", issue = "130703")]
21+
pubtraitRandom:Sized{
22+
/// Generates a random value.
23+
fnrandom(source:&mut(implRandomSource + ?Sized)) -> Self;
24+
}
25+
26+
implRandomforbool{
27+
fnrandom(source:&mut(implRandomSource + ?Sized)) -> Self{
28+
u8::random(source)&1 == 1
29+
}
30+
}
31+
32+
macro_rules! impl_primitive {
33+
($t:ty) => {
34+
implRandomfor $t {
35+
/// Generates a random value.
36+
///
37+
/// **Warning:** Be careful when manipulating the resulting value! This
38+
/// method samples according to a uniform distribution, so a value of 1 is
39+
/// just as likely as [`MAX`](Self::MAX). By using modulo operations, some
40+
/// values can become more likely than others. Use audited crates when in
41+
/// doubt.
42+
fn random(source:&mut(implRandomSource + ?Sized)) -> Self{
43+
letmut bytes = (0asSelf).to_ne_bytes();
44+
source.fill_bytes(&mut bytes);
45+
Self::from_ne_bytes(bytes)
46+
}
47+
}
48+
};
49+
}
50+
51+
impl_primitive!(u8);
52+
impl_primitive!(i8);
53+
impl_primitive!(u16);
54+
impl_primitive!(i16);
55+
impl_primitive!(u32);
56+
impl_primitive!(i32);
57+
impl_primitive!(u64);
58+
impl_primitive!(i64);
59+
impl_primitive!(u128);
60+
impl_primitive!(i128);
61+
impl_primitive!(usize);
62+
impl_primitive!(isize);

‎library/std/src/hash/random.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#[allow(deprecated)]
1111
usesuper::{BuildHasher,Hasher,SipHasher13};
1212
usecrate::cell::Cell;
13-
usecrate::{fmt, sys};
13+
usecrate::fmt;
14+
usecrate::sys::random::hashmap_random_keys;
1415

1516
/// `RandomState` is the default state for [`HashMap`] types.
1617
///
@@ -65,7 +66,7 @@ impl RandomState {
6566
// increment one of the seeds on every RandomState creation, giving
6667
// every corresponding HashMap a different iteration order.
6768
thread_local!(staticKEYS:Cell<(u64,u64)> = {
68-
Cell::new(sys::hashmap_random_keys())
69+
Cell::new(hashmap_random_keys())
6970
});
7071

7172
KEYS.with(|keys| {

0 commit comments

Comments
 (0)