Skip to content

Commit

Permalink
Auto merge of #107372 - JohnTitor:rollup-zkl2ges, r=JohnTitor
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jan 27, 2023
2 parents 7919ef0 + c64f4c4 commit ef98292
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 128 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3672,6 +3672,7 @@ name = "rustc_ast"
version = "0.0.0"
dependencies = [
"bitflags",
"memchr",
"rustc_data_structures",
"rustc_index",
"rustc_lexer",
Expand Down Expand Up @@ -5215,9 +5216,9 @@ checksum = "cc88c725d61fc6c3132893370cac4a0200e3fedf5da8331c570664b1987f5ca2"

[[package]]
name = "snap"
version = "1.0.1"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da73c8f77aebc0e40c300b93f0a5f1bece7a248a36eee287d4e095f35c7b7d6e"
checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831"

[[package]]
name = "snapbox"
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
bitflags = "1.2.1"
memchr = "2.5.0"
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_index = { path = "../rustc_index" }
rustc_lexer = { path = "../rustc_lexer" }
Expand Down
26 changes: 24 additions & 2 deletions compiler/rustc_ast/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,30 @@ pub struct FormatOptions {
pub alignment: Option<FormatAlignment>,
/// The fill character. E.g. the `.` in `{:.>10}`.
pub fill: Option<char>,
/// The `+`, `-`, `0`, `#`, `x?` and `X?` flags.
pub flags: u32,
/// The `+` or `-` flag.
pub sign: Option<FormatSign>,
/// The `#` flag.
pub alternate: bool,
/// The `0` flag. E.g. the `0` in `{:02x}`.
pub zero_pad: bool,
/// The `x` or `X` flag (for `Debug` only). E.g. the `x` in `{:x?}`.
pub debug_hex: Option<FormatDebugHex>,
}

#[derive(Copy, Clone, Encodable, Decodable, Debug, PartialEq, Eq)]
pub enum FormatSign {
/// The `+` flag.
Plus,
/// The `-` flag.
Minus,
}

#[derive(Copy, Clone, Encodable, Decodable, Debug, PartialEq, Eq)]
pub enum FormatDebugHex {
/// The `x` flag in `{:x?}`.
Lower,
/// The `X` flag in `{:X?}`.
Upper,
}

#[derive(Copy, Clone, Encodable, Decodable, Debug, PartialEq, Eq)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#![feature(let_chains)]
#![feature(min_specialization)]
#![feature(negative_impls)]
#![feature(slice_internals)]
#![feature(stmt_expr_attributes)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/util/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn contains_text_flow_control_chars(s: &str) -> bool {
// U+2069 - E2 81 A9
let mut bytes = s.as_bytes();
loop {
match core::slice::memchr::memchr(0xE2, bytes) {
match memchr::memchr(0xE2, bytes) {
Some(idx) => {
// bytes are valid UTF-8 -> E2 must be followed by two bytes
let ch = &bytes[idx..idx + 3];
Expand Down
29 changes: 23 additions & 6 deletions compiler/rustc_ast_lowering/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,43 @@ fn make_format_spec<'hir>(
}
Err(_) => ctx.expr(sp, hir::ExprKind::Err),
};
let fill = ctx.expr_char(sp, placeholder.format_options.fill.unwrap_or(' '));
let &FormatOptions {
ref width,
ref precision,
alignment,
fill,
sign,
alternate,
zero_pad,
debug_hex,
} = &placeholder.format_options;
let fill = ctx.expr_char(sp, fill.unwrap_or(' '));
let align = ctx.expr_lang_item_type_relative(
sp,
hir::LangItem::FormatAlignment,
match placeholder.format_options.alignment {
match alignment {
Some(FormatAlignment::Left) => sym::Left,
Some(FormatAlignment::Right) => sym::Right,
Some(FormatAlignment::Center) => sym::Center,
None => sym::Unknown,
},
);
let flags = ctx.expr_u32(sp, placeholder.format_options.flags);
let prec = make_count(ctx, sp, &placeholder.format_options.precision, argmap);
let width = make_count(ctx, sp, &placeholder.format_options.width, argmap);
// This needs to match `FlagV1` in library/core/src/fmt/mod.rs.
let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32)
| ((sign == Some(FormatSign::Minus)) as u32) << 1
| (alternate as u32) << 2
| (zero_pad as u32) << 3
| ((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4
| ((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5;
let flags = ctx.expr_u32(sp, flags);
let precision = make_count(ctx, sp, &precision, argmap);
let width = make_count(ctx, sp, &width, argmap);
let format_placeholder_new = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
sp,
hir::LangItem::FormatPlaceholder,
sym::new,
));
let args = ctx.arena.alloc_from_iter([position, fill, align, flags, prec, width]);
let args = ctx.arena.alloc_from_iter([position, fill, align, flags, precision, width]);
ctx.expr_call_mut(sp, format_placeholder_new, args)
}

Expand Down
28 changes: 14 additions & 14 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use rustc_ast::token;
use rustc_ast::util::literal::escape_byte_str_symbol;
use rustc_ast::util::parser::{self, AssocOp, Fixity};
use rustc_ast::{self as ast, BlockCheckMode};
use rustc_ast::{FormatAlignment, FormatArgPosition, FormatArgsPiece, FormatCount, FormatTrait};
use rustc_ast::{
FormatAlignment, FormatArgPosition, FormatArgsPiece, FormatCount, FormatDebugHex, FormatSign,
FormatTrait,
};
use std::fmt::Write;

impl<'a> State<'a> {
Expand Down Expand Up @@ -675,17 +678,15 @@ pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> St
Some(FormatAlignment::Center) => template.push_str("^"),
None => {}
}
let flags = p.format_options.flags;
if flags >> (rustc_parse_format::FlagSignPlus as usize) & 1 != 0 {
template.push('+');
}
if flags >> (rustc_parse_format::FlagSignMinus as usize) & 1 != 0 {
template.push('-');
match p.format_options.sign {
Some(FormatSign::Plus) => template.push('+'),
Some(FormatSign::Minus) => template.push('-'),
None => {}
}
if flags >> (rustc_parse_format::FlagAlternate as usize) & 1 != 0 {
if p.format_options.alternate {
template.push('#');
}
if flags >> (rustc_parse_format::FlagSignAwareZeroPad as usize) & 1 != 0 {
if p.format_options.zero_pad {
template.push('0');
}
if let Some(width) = &p.format_options.width {
Expand All @@ -709,11 +710,10 @@ pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> St
}
}
}
if flags >> (rustc_parse_format::FlagDebugLowerHex as usize) & 1 != 0 {
template.push('x');
}
if flags >> (rustc_parse_format::FlagDebugUpperHex as usize) & 1 != 0 {
template.push('X');
match p.format_options.debug_hex {
Some(FormatDebugHex::Lower) => template.push('x'),
Some(FormatDebugHex::Upper) => template.push('X'),
None => {}
}
template.push_str(match p.format_trait {
FormatTrait::Display => "",
Expand Down
13 changes: 11 additions & 2 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{
Expr, ExprKind, FormatAlignment, FormatArgPosition, FormatArgPositionKind, FormatArgs,
FormatArgsPiece, FormatArgument, FormatArgumentKind, FormatArguments, FormatCount,
FormatOptions, FormatPlaceholder, FormatTrait,
FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait,
};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{pluralize, Applicability, MultiSpan, PResult};
Expand Down Expand Up @@ -435,7 +435,16 @@ pub fn make_format_args(
format_options: FormatOptions {
fill: format.fill,
alignment,
flags: format.flags,
sign: format.sign.map(|s| match s {
parse::Sign::Plus => FormatSign::Plus,
parse::Sign::Minus => FormatSign::Minus,
}),
alternate: format.alternate,
zero_pad: format.zero_pad,
debug_hex: format.debug_hex.map(|s| match s {
parse::DebugHex::Lower => FormatDebugHex::Lower,
parse::DebugHex::Upper => FormatDebugHex::Upper,
}),
precision,
width,
},
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator
) {
return None;
} else if ignore_unused_generics
&& tcx.generics_of(def_id).requires_monomorphization(tcx)
{
}
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {
return None;
}
Some(local_def_id.to_def_id())
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0587.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ You cannot use `packed` and `align` hints on a same type. If you want to pack a
type to a given size, you should provide a size to packed:

```
#[repr(packed)] // ok!
#[repr(packed(8))] // ok!
struct Umbrella(i32);
```
65 changes: 37 additions & 28 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

pub use Alignment::*;
pub use Count::*;
pub use Flag::*;
pub use Piece::*;
pub use Position::*;

Expand Down Expand Up @@ -111,8 +110,14 @@ pub struct FormatSpec<'a> {
pub fill: Option<char>,
/// Optionally specified alignment.
pub align: Alignment,
/// Packed version of various flags provided.
pub flags: u32,
/// The `+` or `-` flag.
pub sign: Option<Sign>,
/// The `#` flag.
pub alternate: bool,
/// The `0` flag.
pub zero_pad: bool,
/// The `x` or `X` flag. (Only for `Debug`.)
pub debug_hex: Option<DebugHex>,
/// The integer precision to use.
pub precision: Count<'a>,
/// The span of the precision formatting flag (for diagnostics).
Expand Down Expand Up @@ -162,24 +167,22 @@ pub enum Alignment {
AlignUnknown,
}

/// Various flags which can be applied to format strings. The meaning of these
/// flags is defined by the formatters themselves.
/// Enum for the sign flags.
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Flag {
/// A `+` will be used to denote positive numbers.
FlagSignPlus,
/// A `-` will be used to denote negative numbers. This is the default.
FlagSignMinus,
/// An alternate form will be used for the value. In the case of numbers,
/// this means that the number will be prefixed with the supplied string.
FlagAlternate,
/// For numbers, this means that the number will be padded with zeroes,
/// and the sign (`+` or `-`) will precede them.
FlagSignAwareZeroPad,
/// For Debug / `?`, format integers in lower-case hexadecimal.
FlagDebugLowerHex,
/// For Debug / `?`, format integers in upper-case hexadecimal.
FlagDebugUpperHex,
pub enum Sign {
/// The `+` flag.
Plus,
/// The `-` flag.
Minus,
}

/// Enum for the debug hex flags.
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum DebugHex {
/// The `x` flag in `{:x?}`.
Lower,
/// The `X` flag in `{:X?}`.
Upper,
}

/// A count is used for the precision and width parameters of an integer, and
Expand Down Expand Up @@ -597,7 +600,10 @@ impl<'a> Parser<'a> {
let mut spec = FormatSpec {
fill: None,
align: AlignUnknown,
flags: 0,
sign: None,
alternate: false,
zero_pad: false,
debug_hex: None,
precision: CountImplied,
precision_span: None,
width: CountImplied,
Expand Down Expand Up @@ -626,13 +632,13 @@ impl<'a> Parser<'a> {
}
// Sign flags
if self.consume('+') {
spec.flags |= 1 << (FlagSignPlus as u32);
spec.sign = Some(Sign::Plus);
} else if self.consume('-') {
spec.flags |= 1 << (FlagSignMinus as u32);
spec.sign = Some(Sign::Minus);
}
// Alternate marker
if self.consume('#') {
spec.flags |= 1 << (FlagAlternate as u32);
spec.alternate = true;
}
// Width and precision
let mut havewidth = false;
Expand All @@ -647,7 +653,7 @@ impl<'a> Parser<'a> {
spec.width_span = Some(self.span(end - 1, end + 1));
havewidth = true;
} else {
spec.flags |= 1 << (FlagSignAwareZeroPad as u32);
spec.zero_pad = true;
}
}

Expand Down Expand Up @@ -678,14 +684,14 @@ impl<'a> Parser<'a> {
// Optional radix followed by the actual format specifier
if self.consume('x') {
if self.consume('?') {
spec.flags |= 1 << (FlagDebugLowerHex as u32);
spec.debug_hex = Some(DebugHex::Lower);
spec.ty = "?";
} else {
spec.ty = "x";
}
} else if self.consume('X') {
if self.consume('?') {
spec.flags |= 1 << (FlagDebugUpperHex as u32);
spec.debug_hex = Some(DebugHex::Upper);
spec.ty = "?";
} else {
spec.ty = "X";
Expand All @@ -708,7 +714,10 @@ impl<'a> Parser<'a> {
let mut spec = FormatSpec {
fill: None,
align: AlignUnknown,
flags: 0,
sign: None,
alternate: false,
zero_pad: false,
debug_hex: None,
precision: CountImplied,
precision_span: None,
width: CountImplied,
Expand Down
Loading

0 comments on commit ef98292

Please sign in to comment.