Skip to content

Commit

Permalink
Auto merge of #118370 - TaKO8Ki:rollup-qfilq2w, r=TaKO8Ki
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #118095 (Enable the Arm Cortex-A53 errata mitigation on aarch64-unknown-none)
 - #118340 (Use helper functions in `pretty.rs` instead of accessing the `Cell`s manually)
 - #118358 (make const tests independent of std debug assertions)
 - #118359 (Suggest swapping the order of `ref` and `box`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 27, 2023
2 parents aa33051 + 215d84a commit 9f15a88
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 244 deletions.
20 changes: 10 additions & 10 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
/// from at least one local module, and returns `true`. If the crate defining `def_id` is
/// declared with an `extern crate`, the path is guaranteed to use the `extern crate`.
fn try_print_visible_def_path(&mut self, def_id: DefId) -> Result<bool, PrintError> {
if NO_VISIBLE_PATH.with(|flag| flag.get()) {
if with_no_visible_paths() {
return Ok(false);
}

Expand Down Expand Up @@ -367,16 +367,16 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {

/// Try to see if this path can be trimmed to a unique symbol name.
fn try_print_trimmed_def_path(&mut self, def_id: DefId) -> Result<bool, PrintError> {
if FORCE_TRIMMED_PATH.with(|flag| flag.get()) {
if with_forced_trimmed_paths() {
let trimmed = self.force_print_trimmed_def_path(def_id)?;
if trimmed {
return Ok(true);
}
}
if !self.tcx().sess.opts.unstable_opts.trim_diagnostic_paths
|| matches!(self.tcx().sess.opts.trimmed_def_paths, TrimmedDefPaths::Never)
|| NO_TRIMMED_PATH.with(|flag| flag.get())
|| SHOULD_PREFIX_WITH_CRATE.with(|flag| flag.get())
|| with_no_trimmed_paths()
|| with_crate_prefix()
{
return Ok(false);
}
Expand Down Expand Up @@ -861,7 +861,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
p!("@", print_def_path(did.to_def_id(), args));
} else {
let span = self.tcx().def_span(did);
let preference = if FORCE_TRIMMED_PATH.with(|flag| flag.get()) {
let preference = if with_forced_trimmed_paths() {
FileNameDisplayPreference::Short
} else {
FileNameDisplayPreference::Remapped
Expand Down Expand Up @@ -1102,7 +1102,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
write!(self, "Sized")?;
}

if !FORCE_TRIMMED_PATH.with(|flag| flag.get()) {
if !with_forced_trimmed_paths() {
for re in lifetimes {
write!(self, " + ")?;
self.print_region(re)?;
Expand Down Expand Up @@ -1886,7 +1886,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
// available, and filename/line-number is mostly uninteresting.
let use_types = !def_id.is_local() || {
// Otherwise, use filename/line-number if forced.
let force_no_types = FORCE_IMPL_FILENAME_LINE.with(|f| f.get());
let force_no_types = with_forced_impl_filename_line();
!force_no_types
};

Expand Down Expand Up @@ -1951,7 +1951,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
if cnum == LOCAL_CRATE {
if self.tcx.sess.at_least_rust_2018() {
// We add the `crate::` keyword on Rust 2018, only when desired.
if SHOULD_PREFIX_WITH_CRATE.with(|flag| flag.get()) {
if with_crate_prefix() {
write!(self, "{}", kw::Crate)?;
self.empty_path = false;
}
Expand Down Expand Up @@ -2154,7 +2154,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
return true;
}

if FORCE_TRIMMED_PATH.with(|flag| flag.get()) {
if with_forced_trimmed_paths() {
return false;
}

Expand Down Expand Up @@ -2437,7 +2437,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
} else {
let tcx = self.tcx;

let trim_path = FORCE_TRIMMED_PATH.with(|flag| flag.get());
let trim_path = with_forced_trimmed_paths();
// Closure used in `RegionFolder` to create names for anonymous late-bound
// regions. We use two `DebruijnIndex`es (one for the currently folded
// late-bound region and the other for the binder level) to determine
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ parse_sugg_wrap_pattern_in_parens = wrap the pattern in parentheses
parse_switch_mut_let_order =
switch the order of `mut` and `let`
parse_switch_ref_box_order = switch the order of `ref` and `box`
.suggestion = swap them
parse_ternary_operator = Rust has no ternary operator
.help = use an `if-else` expression instead
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ pub(crate) enum InvalidVariableDeclarationSub {
UseLetNotVar(#[primary_span] Span),
}

#[derive(Diagnostic)]
#[diag(parse_switch_ref_box_order)]
pub(crate) struct SwitchRefBoxOrder {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = "box ref")]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(parse_invalid_comparison_operator)]
pub(crate) struct InvalidComparisonOperator {
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::errors::{
ExpectedCommaAfterPatternField, GenericArgsInPatRequireTurbofishSyntax,
InclusiveRangeExtraEquals, InclusiveRangeMatchArrow, InclusiveRangeNoEnd, InvalidMutInPattern,
PatternOnWrongSideOfAt, RefMutOrderIncorrect, RemoveLet, RepeatedMutInPattern,
TopLevelOrPatternNotAllowed, TopLevelOrPatternNotAllowedSugg, TrailingVertNotAllowed,
UnexpectedLifetimeInPattern, UnexpectedVertVertBeforeFunctionParam,
SwitchRefBoxOrder, TopLevelOrPatternNotAllowed, TopLevelOrPatternNotAllowedSugg,
TrailingVertNotAllowed, UnexpectedLifetimeInPattern, UnexpectedVertVertBeforeFunctionParam,
UnexpectedVertVertInPattern,
};
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
Expand Down Expand Up @@ -374,6 +374,12 @@ impl<'a> Parser<'a> {
} else if self.eat_keyword(kw::Mut) {
self.parse_pat_ident_mut(syntax_loc)?
} else if self.eat_keyword(kw::Ref) {
if self.check_keyword(kw::Box) {
// Suggest `box ref` and quit parsing pattern to prevent series of
// misguided diagnostics from later stages of the compiler.
let span = self.prev_token.span.to(self.token.span);
return Err(self.sess.create_err(SwitchRefBoxOrder { span }));
}
// Parse ref ident @ pat / ref mut ident @ pat
let mutbl = self.parse_mutability();
self.parse_pat_ident(BindingAnnotation(ByRef::Yes, mutbl), syntax_loc)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ pub fn target() -> Target {
let opts = TargetOptions {
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
// Enable the Cortex-A53 errata 843419 mitigation by default
pre_link_args: TargetOptions::link_args(
LinkerFlavor::Gnu(Cc::No, Lld::No),
&["--fix-cortex-a53-843419"],
),
features: "+v8a,+strict-align,+neon,+fp-armv8".into(),
supported_sanitizers: SanitizerSet::KCFI | SanitizerSet::KERNELADDRESS,
relocation_model: RelocModel::Static,
Expand Down
Loading

0 comments on commit 9f15a88

Please sign in to comment.