Skip to content

Commit ef98292

Browse files
committed
Auto merge of #107372 - JohnTitor:rollup-zkl2ges, r=JohnTitor
Rollup of 9 pull requests Successful merges: - #106806 (Replace format flags u32 by enums and bools.) - #107194 (Remove dependency on slice_internals feature in rustc_ast) - #107234 (Revisit fix_is_ci_llvm_available logic) - #107316 (Update snap from `1.0.1` to `1.1.0`) - #107321 (solver comments + remove `TyCtxt::evaluate_goal`) - #107332 (Fix wording from `rustbuild` to `bootstrap`) - #107347 (reduce rightward-drift) - #107352 (compiler: Fix E0587 explanation) - #107357 (Fix infinite loop in rustdoc get_all_import_attributes function) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7919ef0 + c64f4c4 commit ef98292

File tree

21 files changed

+255
-128
lines changed

21 files changed

+255
-128
lines changed

Cargo.lock

+3-2
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,7 @@ name = "rustc_ast"
36723672
version = "0.0.0"
36733673
dependencies = [
36743674
"bitflags",
3675+
"memchr",
36753676
"rustc_data_structures",
36763677
"rustc_index",
36773678
"rustc_lexer",
@@ -5215,9 +5216,9 @@ checksum = "cc88c725d61fc6c3132893370cac4a0200e3fedf5da8331c570664b1987f5ca2"
52155216

52165217
[[package]]
52175218
name = "snap"
5218-
version = "1.0.1"
5219+
version = "1.1.0"
52195220
source = "registry+https://github.com/rust-lang/crates.io-index"
5220-
checksum = "da73c8f77aebc0e40c300b93f0a5f1bece7a248a36eee287d4e095f35c7b7d6e"
5221+
checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831"
52215222

52225223
[[package]]
52235224
name = "snapbox"

compiler/rustc_ast/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
bitflags = "1.2.1"
10+
memchr = "2.5.0"
1011
rustc_data_structures = { path = "../rustc_data_structures" }
1112
rustc_index = { path = "../rustc_index" }
1213
rustc_lexer = { path = "../rustc_lexer" }

compiler/rustc_ast/src/format.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,30 @@ pub struct FormatOptions {
227227
pub alignment: Option<FormatAlignment>,
228228
/// The fill character. E.g. the `.` in `{:.>10}`.
229229
pub fill: Option<char>,
230-
/// The `+`, `-`, `0`, `#`, `x?` and `X?` flags.
231-
pub flags: u32,
230+
/// The `+` or `-` flag.
231+
pub sign: Option<FormatSign>,
232+
/// The `#` flag.
233+
pub alternate: bool,
234+
/// The `0` flag. E.g. the `0` in `{:02x}`.
235+
pub zero_pad: bool,
236+
/// The `x` or `X` flag (for `Debug` only). E.g. the `x` in `{:x?}`.
237+
pub debug_hex: Option<FormatDebugHex>,
238+
}
239+
240+
#[derive(Copy, Clone, Encodable, Decodable, Debug, PartialEq, Eq)]
241+
pub enum FormatSign {
242+
/// The `+` flag.
243+
Plus,
244+
/// The `-` flag.
245+
Minus,
246+
}
247+
248+
#[derive(Copy, Clone, Encodable, Decodable, Debug, PartialEq, Eq)]
249+
pub enum FormatDebugHex {
250+
/// The `x` flag in `{:x?}`.
251+
Lower,
252+
/// The `X` flag in `{:X?}`.
253+
Upper,
232254
}
233255

234256
#[derive(Copy, Clone, Encodable, Decodable, Debug, PartialEq, Eq)]

compiler/rustc_ast/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#![feature(let_chains)]
1717
#![feature(min_specialization)]
1818
#![feature(negative_impls)]
19-
#![feature(slice_internals)]
2019
#![feature(stmt_expr_attributes)]
2120
#![recursion_limit = "256"]
2221
#![deny(rustc::untranslatable_diagnostic)]

compiler/rustc_ast/src/util/unicode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn contains_text_flow_control_chars(s: &str) -> bool {
1717
// U+2069 - E2 81 A9
1818
let mut bytes = s.as_bytes();
1919
loop {
20-
match core::slice::memchr::memchr(0xE2, bytes) {
20+
match memchr::memchr(0xE2, bytes) {
2121
Some(idx) => {
2222
// bytes are valid UTF-8 -> E2 must be followed by two bytes
2323
let ch = &bytes[idx..idx + 3];

compiler/rustc_ast_lowering/src/format.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,43 @@ fn make_format_spec<'hir>(
137137
}
138138
Err(_) => ctx.expr(sp, hir::ExprKind::Err),
139139
};
140-
let fill = ctx.expr_char(sp, placeholder.format_options.fill.unwrap_or(' '));
140+
let &FormatOptions {
141+
ref width,
142+
ref precision,
143+
alignment,
144+
fill,
145+
sign,
146+
alternate,
147+
zero_pad,
148+
debug_hex,
149+
} = &placeholder.format_options;
150+
let fill = ctx.expr_char(sp, fill.unwrap_or(' '));
141151
let align = ctx.expr_lang_item_type_relative(
142152
sp,
143153
hir::LangItem::FormatAlignment,
144-
match placeholder.format_options.alignment {
154+
match alignment {
145155
Some(FormatAlignment::Left) => sym::Left,
146156
Some(FormatAlignment::Right) => sym::Right,
147157
Some(FormatAlignment::Center) => sym::Center,
148158
None => sym::Unknown,
149159
},
150160
);
151-
let flags = ctx.expr_u32(sp, placeholder.format_options.flags);
152-
let prec = make_count(ctx, sp, &placeholder.format_options.precision, argmap);
153-
let width = make_count(ctx, sp, &placeholder.format_options.width, argmap);
161+
// This needs to match `FlagV1` in library/core/src/fmt/mod.rs.
162+
let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32)
163+
| ((sign == Some(FormatSign::Minus)) as u32) << 1
164+
| (alternate as u32) << 2
165+
| (zero_pad as u32) << 3
166+
| ((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4
167+
| ((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5;
168+
let flags = ctx.expr_u32(sp, flags);
169+
let precision = make_count(ctx, sp, &precision, argmap);
170+
let width = make_count(ctx, sp, &width, argmap);
154171
let format_placeholder_new = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
155172
sp,
156173
hir::LangItem::FormatPlaceholder,
157174
sym::new,
158175
));
159-
let args = ctx.arena.alloc_from_iter([position, fill, align, flags, prec, width]);
176+
let args = ctx.arena.alloc_from_iter([position, fill, align, flags, precision, width]);
160177
ctx.expr_call_mut(sp, format_placeholder_new, args)
161178
}
162179

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use rustc_ast::token;
66
use rustc_ast::util::literal::escape_byte_str_symbol;
77
use rustc_ast::util::parser::{self, AssocOp, Fixity};
88
use rustc_ast::{self as ast, BlockCheckMode};
9-
use rustc_ast::{FormatAlignment, FormatArgPosition, FormatArgsPiece, FormatCount, FormatTrait};
9+
use rustc_ast::{
10+
FormatAlignment, FormatArgPosition, FormatArgsPiece, FormatCount, FormatDebugHex, FormatSign,
11+
FormatTrait,
12+
};
1013
use std::fmt::Write;
1114

1215
impl<'a> State<'a> {
@@ -675,17 +678,15 @@ pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> St
675678
Some(FormatAlignment::Center) => template.push_str("^"),
676679
None => {}
677680
}
678-
let flags = p.format_options.flags;
679-
if flags >> (rustc_parse_format::FlagSignPlus as usize) & 1 != 0 {
680-
template.push('+');
681-
}
682-
if flags >> (rustc_parse_format::FlagSignMinus as usize) & 1 != 0 {
683-
template.push('-');
681+
match p.format_options.sign {
682+
Some(FormatSign::Plus) => template.push('+'),
683+
Some(FormatSign::Minus) => template.push('-'),
684+
None => {}
684685
}
685-
if flags >> (rustc_parse_format::FlagAlternate as usize) & 1 != 0 {
686+
if p.format_options.alternate {
686687
template.push('#');
687688
}
688-
if flags >> (rustc_parse_format::FlagSignAwareZeroPad as usize) & 1 != 0 {
689+
if p.format_options.zero_pad {
689690
template.push('0');
690691
}
691692
if let Some(width) = &p.format_options.width {
@@ -709,11 +710,10 @@ pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> St
709710
}
710711
}
711712
}
712-
if flags >> (rustc_parse_format::FlagDebugLowerHex as usize) & 1 != 0 {
713-
template.push('x');
714-
}
715-
if flags >> (rustc_parse_format::FlagDebugUpperHex as usize) & 1 != 0 {
716-
template.push('X');
713+
match p.format_options.debug_hex {
714+
Some(FormatDebugHex::Lower) => template.push('x'),
715+
Some(FormatDebugHex::Upper) => template.push('X'),
716+
None => {}
717717
}
718718
template.push_str(match p.format_trait {
719719
FormatTrait::Display => "",

compiler/rustc_builtin_macros/src/format.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_ast::tokenstream::TokenStream;
44
use rustc_ast::{
55
Expr, ExprKind, FormatAlignment, FormatArgPosition, FormatArgPositionKind, FormatArgs,
66
FormatArgsPiece, FormatArgument, FormatArgumentKind, FormatArguments, FormatCount,
7-
FormatOptions, FormatPlaceholder, FormatTrait,
7+
FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait,
88
};
99
use rustc_data_structures::fx::FxHashSet;
1010
use rustc_errors::{pluralize, Applicability, MultiSpan, PResult};
@@ -435,7 +435,16 @@ pub fn make_format_args(
435435
format_options: FormatOptions {
436436
fill: format.fill,
437437
alignment,
438-
flags: format.flags,
438+
sign: format.sign.map(|s| match s {
439+
parse::Sign::Plus => FormatSign::Plus,
440+
parse::Sign::Minus => FormatSign::Minus,
441+
}),
442+
alternate: format.alternate,
443+
zero_pad: format.zero_pad,
444+
debug_hex: format.debug_hex.map(|s| match s {
445+
parse::DebugHex::Lower => FormatDebugHex::Lower,
446+
parse::DebugHex::Upper => FormatDebugHex::Upper,
447+
}),
439448
precision,
440449
width,
441450
},

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,8 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
295295
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator
296296
) {
297297
return None;
298-
} else if ignore_unused_generics
299-
&& tcx.generics_of(def_id).requires_monomorphization(tcx)
300-
{
298+
}
299+
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {
301300
return None;
302301
}
303302
Some(local_def_id.to_def_id())

compiler/rustc_error_codes/src/error_codes/E0587.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ You cannot use `packed` and `align` hints on a same type. If you want to pack a
1111
type to a given size, you should provide a size to packed:
1212

1313
```
14-
#[repr(packed)] // ok!
14+
#[repr(packed(8))] // ok!
1515
struct Umbrella(i32);
1616
```

compiler/rustc_parse_format/src/lib.rs

+37-28
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
pub use Alignment::*;
1818
pub use Count::*;
19-
pub use Flag::*;
2019
pub use Piece::*;
2120
pub use Position::*;
2221

@@ -111,8 +110,14 @@ pub struct FormatSpec<'a> {
111110
pub fill: Option<char>,
112111
/// Optionally specified alignment.
113112
pub align: Alignment,
114-
/// Packed version of various flags provided.
115-
pub flags: u32,
113+
/// The `+` or `-` flag.
114+
pub sign: Option<Sign>,
115+
/// The `#` flag.
116+
pub alternate: bool,
117+
/// The `0` flag.
118+
pub zero_pad: bool,
119+
/// The `x` or `X` flag. (Only for `Debug`.)
120+
pub debug_hex: Option<DebugHex>,
116121
/// The integer precision to use.
117122
pub precision: Count<'a>,
118123
/// The span of the precision formatting flag (for diagnostics).
@@ -162,24 +167,22 @@ pub enum Alignment {
162167
AlignUnknown,
163168
}
164169

165-
/// Various flags which can be applied to format strings. The meaning of these
166-
/// flags is defined by the formatters themselves.
170+
/// Enum for the sign flags.
167171
#[derive(Copy, Clone, Debug, PartialEq)]
168-
pub enum Flag {
169-
/// A `+` will be used to denote positive numbers.
170-
FlagSignPlus,
171-
/// A `-` will be used to denote negative numbers. This is the default.
172-
FlagSignMinus,
173-
/// An alternate form will be used for the value. In the case of numbers,
174-
/// this means that the number will be prefixed with the supplied string.
175-
FlagAlternate,
176-
/// For numbers, this means that the number will be padded with zeroes,
177-
/// and the sign (`+` or `-`) will precede them.
178-
FlagSignAwareZeroPad,
179-
/// For Debug / `?`, format integers in lower-case hexadecimal.
180-
FlagDebugLowerHex,
181-
/// For Debug / `?`, format integers in upper-case hexadecimal.
182-
FlagDebugUpperHex,
172+
pub enum Sign {
173+
/// The `+` flag.
174+
Plus,
175+
/// The `-` flag.
176+
Minus,
177+
}
178+
179+
/// Enum for the debug hex flags.
180+
#[derive(Copy, Clone, Debug, PartialEq)]
181+
pub enum DebugHex {
182+
/// The `x` flag in `{:x?}`.
183+
Lower,
184+
/// The `X` flag in `{:X?}`.
185+
Upper,
183186
}
184187

185188
/// A count is used for the precision and width parameters of an integer, and
@@ -597,7 +600,10 @@ impl<'a> Parser<'a> {
597600
let mut spec = FormatSpec {
598601
fill: None,
599602
align: AlignUnknown,
600-
flags: 0,
603+
sign: None,
604+
alternate: false,
605+
zero_pad: false,
606+
debug_hex: None,
601607
precision: CountImplied,
602608
precision_span: None,
603609
width: CountImplied,
@@ -626,13 +632,13 @@ impl<'a> Parser<'a> {
626632
}
627633
// Sign flags
628634
if self.consume('+') {
629-
spec.flags |= 1 << (FlagSignPlus as u32);
635+
spec.sign = Some(Sign::Plus);
630636
} else if self.consume('-') {
631-
spec.flags |= 1 << (FlagSignMinus as u32);
637+
spec.sign = Some(Sign::Minus);
632638
}
633639
// Alternate marker
634640
if self.consume('#') {
635-
spec.flags |= 1 << (FlagAlternate as u32);
641+
spec.alternate = true;
636642
}
637643
// Width and precision
638644
let mut havewidth = false;
@@ -647,7 +653,7 @@ impl<'a> Parser<'a> {
647653
spec.width_span = Some(self.span(end - 1, end + 1));
648654
havewidth = true;
649655
} else {
650-
spec.flags |= 1 << (FlagSignAwareZeroPad as u32);
656+
spec.zero_pad = true;
651657
}
652658
}
653659

@@ -678,14 +684,14 @@ impl<'a> Parser<'a> {
678684
// Optional radix followed by the actual format specifier
679685
if self.consume('x') {
680686
if self.consume('?') {
681-
spec.flags |= 1 << (FlagDebugLowerHex as u32);
687+
spec.debug_hex = Some(DebugHex::Lower);
682688
spec.ty = "?";
683689
} else {
684690
spec.ty = "x";
685691
}
686692
} else if self.consume('X') {
687693
if self.consume('?') {
688-
spec.flags |= 1 << (FlagDebugUpperHex as u32);
694+
spec.debug_hex = Some(DebugHex::Upper);
689695
spec.ty = "?";
690696
} else {
691697
spec.ty = "X";
@@ -708,7 +714,10 @@ impl<'a> Parser<'a> {
708714
let mut spec = FormatSpec {
709715
fill: None,
710716
align: AlignUnknown,
711-
flags: 0,
717+
sign: None,
718+
alternate: false,
719+
zero_pad: false,
720+
debug_hex: None,
712721
precision: CountImplied,
713722
precision_span: None,
714723
width: CountImplied,

0 commit comments

Comments
 (0)