Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 38a76f3

Browse files
committed
Auto merge of rust-lang#106984 - Dylan-DPC:rollup-xce8263, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#101698 (Constify `TypeId` ordering impls) - rust-lang#106148 (Fix unused_parens issue for higher ranked function pointers) - rust-lang#106922 (Avoid unsafe code in `to_ascii_[lower/upper]case()`) - rust-lang#106951 (Remove ineffective run of SimplifyConstCondition) - rust-lang#106962 (Fix use suggestion span) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f34cc65 + e6e7c39 commit 38a76f3

37 files changed

+310
-106
lines changed

compiler/rustc_lint/src/early.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
248248
}
249249

250250
fn visit_where_predicate(&mut self, p: &'a ast::WherePredicate) {
251+
lint_callback!(self, enter_where_predicate, p);
251252
ast_visit::walk_where_predicate(self, p);
253+
lint_callback!(self, exit_where_predicate, p);
252254
}
253255

254256
fn visit_poly_trait_ref(&mut self, t: &'a ast::PolyTraitRef) {

compiler/rustc_lint/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ early_lint_methods!(
145145
[
146146
pub BuiltinCombinedEarlyLintPass,
147147
[
148-
UnusedParens: UnusedParens,
148+
UnusedParens: UnusedParens::new(),
149149
UnusedBraces: UnusedBraces,
150150
UnusedImportBraces: UnusedImportBraces,
151151
UnsafeCode: UnsafeCode,

compiler/rustc_lint/src/passes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ macro_rules! early_lint_methods {
171171

172172
/// Counterpart to `enter_lint_attrs`.
173173
fn exit_lint_attrs(a: &[ast::Attribute]);
174+
175+
fn enter_where_predicate(a: &ast::WherePredicate);
176+
fn exit_where_predicate(a: &ast::WherePredicate);
174177
]);
175178
)
176179
}

compiler/rustc_lint/src/unused.rs

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,17 @@ declare_lint! {
824824
"`if`, `match`, `while` and `return` do not need parentheses"
825825
}
826826

827-
declare_lint_pass!(UnusedParens => [UNUSED_PARENS]);
827+
pub struct UnusedParens {
828+
with_self_ty_parens: bool,
829+
}
830+
831+
impl UnusedParens {
832+
pub fn new() -> Self {
833+
Self { with_self_ty_parens: false }
834+
}
835+
}
836+
837+
impl_lint_pass!(UnusedParens => [UNUSED_PARENS]);
828838

829839
impl UnusedDelimLint for UnusedParens {
830840
const DELIM_STR: &'static str = "parentheses";
@@ -999,36 +1009,58 @@ impl EarlyLintPass for UnusedParens {
9991009
}
10001010

10011011
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
1002-
if let ast::TyKind::Paren(r) = &ty.kind {
1003-
match &r.kind {
1004-
ast::TyKind::TraitObject(..) => {}
1005-
ast::TyKind::BareFn(b) if b.generic_params.len() > 0 => {}
1006-
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
1007-
ast::TyKind::Array(_, len) => {
1008-
self.check_unused_delims_expr(
1009-
cx,
1010-
&len.value,
1011-
UnusedDelimsCtx::ArrayLenExpr,
1012-
false,
1013-
None,
1014-
None,
1015-
);
1016-
}
1017-
_ => {
1018-
let spans = if let Some(r) = r.span.find_ancestor_inside(ty.span) {
1019-
Some((ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())))
1020-
} else {
1021-
None
1022-
};
1023-
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false));
1012+
match &ty.kind {
1013+
ast::TyKind::Array(_, len) => {
1014+
self.check_unused_delims_expr(
1015+
cx,
1016+
&len.value,
1017+
UnusedDelimsCtx::ArrayLenExpr,
1018+
false,
1019+
None,
1020+
None,
1021+
);
1022+
}
1023+
ast::TyKind::Paren(r) => {
1024+
match &r.kind {
1025+
ast::TyKind::TraitObject(..) => {}
1026+
ast::TyKind::BareFn(b)
1027+
if self.with_self_ty_parens && b.generic_params.len() > 0 => {}
1028+
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
1029+
_ => {
1030+
let spans = if let Some(r) = r.span.find_ancestor_inside(ty.span) {
1031+
Some((ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())))
1032+
} else {
1033+
None
1034+
};
1035+
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false));
1036+
}
10241037
}
1038+
self.with_self_ty_parens = false;
10251039
}
1040+
_ => {}
10261041
}
10271042
}
10281043

10291044
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
10301045
<Self as UnusedDelimLint>::check_item(self, cx, item)
10311046
}
1047+
1048+
fn enter_where_predicate(&mut self, _: &EarlyContext<'_>, pred: &ast::WherePredicate) {
1049+
use rustc_ast::{WhereBoundPredicate, WherePredicate};
1050+
if let WherePredicate::BoundPredicate(WhereBoundPredicate {
1051+
bounded_ty,
1052+
bound_generic_params,
1053+
..
1054+
}) = pred &&
1055+
let ast::TyKind::Paren(_) = &bounded_ty.kind &&
1056+
bound_generic_params.is_empty() {
1057+
self.with_self_ty_parens = true;
1058+
}
1059+
}
1060+
1061+
fn exit_where_predicate(&mut self, _: &EarlyContext<'_>, _: &ast::WherePredicate) {
1062+
assert!(!self.with_self_ty_parens);
1063+
}
10321064
}
10331065

10341066
declare_lint! {

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ fn run_analysis_to_runtime_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>
487487
fn run_analysis_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
488488
let passes: &[&dyn MirPass<'tcx>] = &[
489489
&cleanup_post_borrowck::CleanupPostBorrowck,
490-
&simplify_branches::SimplifyConstCondition::new("initial"),
491490
&remove_noop_landing_pads::RemoveNoopLandingPads,
492491
&simplify::SimplifyCfg::new("early-opt"),
493492
&deref_separator::Derefer,

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use rustc_ast::visit::{self, Visitor};
55
use rustc_ast::{self as ast, Crate, ItemKind, ModKind, NodeId, Path, CRATE_NODE_ID};
66
use rustc_ast_pretty::pprust;
77
use rustc_data_structures::fx::FxHashSet;
8-
use rustc_errors::struct_span_err;
98
use rustc_errors::{
109
pluralize, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
1110
};
11+
use rustc_errors::{struct_span_err, SuggestionStyle};
1212
use rustc_feature::BUILTIN_ATTRIBUTES;
1313
use rustc_hir::def::Namespace::{self, *};
1414
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PerNS};
@@ -2418,7 +2418,7 @@ fn show_candidates(
24182418
}
24192419

24202420
if let Some(span) = use_placement_span {
2421-
let add_use = match mode {
2421+
let (add_use, trailing) = match mode {
24222422
DiagnosticMode::Pattern => {
24232423
err.span_suggestions(
24242424
span,
@@ -2428,21 +2428,23 @@ fn show_candidates(
24282428
);
24292429
return;
24302430
}
2431-
DiagnosticMode::Import => "",
2432-
DiagnosticMode::Normal => "use ",
2431+
DiagnosticMode::Import => ("", ""),
2432+
DiagnosticMode::Normal => ("use ", ";\n"),
24332433
};
24342434
for candidate in &mut accessible_path_strings {
24352435
// produce an additional newline to separate the new use statement
24362436
// from the directly following item.
2437-
let additional_newline = if let FoundUse::Yes = found_use { "" } else { "\n" };
2438-
candidate.0 = format!("{add_use}{}{append};\n{additional_newline}", &candidate.0);
2437+
let additional_newline = if let FoundUse::No = found_use && let DiagnosticMode::Normal = mode { "\n" } else { "" };
2438+
candidate.0 =
2439+
format!("{add_use}{}{append}{trailing}{additional_newline}", &candidate.0);
24392440
}
24402441

2441-
err.span_suggestions(
2442+
err.span_suggestions_with_style(
24422443
span,
24432444
&msg,
24442445
accessible_path_strings.into_iter().map(|a| a.0),
24452446
Applicability::MaybeIncorrect,
2447+
SuggestionStyle::ShowAlways,
24462448
);
24472449
if let [first, .., last] = &path[..] {
24482450
let sp = first.ident.span.until(last.ident.span);
@@ -2463,7 +2465,7 @@ fn show_candidates(
24632465
msg.push_str(&candidate.0);
24642466
}
24652467

2466-
err.note(&msg);
2468+
err.help(&msg);
24672469
}
24682470
} else if !matches!(mode, DiagnosticMode::Import) {
24692471
assert!(!inaccessible_path_strings.is_empty());

library/alloc/src/str.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,9 @@ impl str {
559559
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
560560
#[inline]
561561
pub fn to_ascii_uppercase(&self) -> String {
562-
let mut bytes = self.as_bytes().to_vec();
563-
bytes.make_ascii_uppercase();
564-
// make_ascii_uppercase() preserves the UTF-8 invariant.
565-
unsafe { String::from_utf8_unchecked(bytes) }
562+
let mut s = self.to_owned();
563+
s.make_ascii_uppercase();
564+
s
566565
}
567566

568567
/// Returns a copy of this string where each character is mapped to its
@@ -592,10 +591,9 @@ impl str {
592591
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
593592
#[inline]
594593
pub fn to_ascii_lowercase(&self) -> String {
595-
let mut bytes = self.as_bytes().to_vec();
596-
bytes.make_ascii_lowercase();
597-
// make_ascii_lowercase() preserves the UTF-8 invariant.
598-
unsafe { String::from_utf8_unchecked(bytes) }
594+
let mut s = self.to_owned();
595+
s.make_ascii_lowercase();
596+
s
599597
}
600598
}
601599

library/core/src/any.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ impl dyn Any + Send + Sync {
662662
/// While `TypeId` implements `Hash`, `PartialOrd`, and `Ord`, it is worth
663663
/// noting that the hashes and ordering will vary between Rust releases. Beware
664664
/// of relying on them inside of your code!
665-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
665+
#[derive(Clone, Copy, Debug, Hash, Eq)]
666+
#[derive_const(PartialEq, PartialOrd, Ord)]
666667
#[stable(feature = "rust1", since = "1.0.0")]
667668
pub struct TypeId {
668669
t: u64,

library/std/src/io/error/repr_bitpacked.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ static_assert!((TAG_MASK + 1).is_power_of_two());
374374
static_assert!(align_of::<SimpleMessage>() >= TAG_MASK + 1);
375375
static_assert!(align_of::<Custom>() >= TAG_MASK + 1);
376376

377-
static_assert!(@usize_eq: (TAG_MASK & TAG_SIMPLE_MESSAGE), TAG_SIMPLE_MESSAGE);
378-
static_assert!(@usize_eq: (TAG_MASK & TAG_CUSTOM), TAG_CUSTOM);
379-
static_assert!(@usize_eq: (TAG_MASK & TAG_OS), TAG_OS);
380-
static_assert!(@usize_eq: (TAG_MASK & TAG_SIMPLE), TAG_SIMPLE);
377+
static_assert!(@usize_eq: TAG_MASK & TAG_SIMPLE_MESSAGE, TAG_SIMPLE_MESSAGE);
378+
static_assert!(@usize_eq: TAG_MASK & TAG_CUSTOM, TAG_CUSTOM);
379+
static_assert!(@usize_eq: TAG_MASK & TAG_OS, TAG_OS);
380+
static_assert!(@usize_eq: TAG_MASK & TAG_SIMPLE, TAG_SIMPLE);
381381

382382
// This is obviously true (`TAG_CUSTOM` is `0b01`), but in `Repr::new_custom` we
383383
// offset a pointer by this value, and expect it to both be within the same

tests/ui/const-generics/issues/issue-90318.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ impl True for If<true> {}
1212
fn consume<T: 'static>(_val: T)
1313
where
1414
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
15-
//~^ ERROR: can't compare
15+
//~^ overly complex generic constant
1616
{
1717
}
1818

1919
fn test<T: 'static>()
2020
where
2121
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
22-
//~^ ERROR: can't compare
22+
//~^ overly complex generic constant
2323
{
2424
}
2525

0 commit comments

Comments
 (0)