Auto merge of #137927 - matthiaskrgr:rollup-yj463ns, r=matthiaskrgr

Rollup of 9 pull requests

Successful merges:

 - #132388 (Implement `#[cfg]` in `where` clauses)
 - #134900 (Fix parsing of ranges after unary operators)
 - #136938 (Remove `:` from `stack-protector-heuristics-effect.rs` Filecheck Pattern)
 - #137054 (Make phantom variance markers transparent)
 - #137525 (Simplify parallelization in test-float-parse)
 - #137618 (Skip `tidy` in pre-push hook if the user is deleting a remote branch)
 - #137741 (Stop using `hash_raw_entry` in `CodegenCx::const_str`)
 - #137849 (Revert "Remove Win SDK 10.0.26100.0 from CI")
 - #137862 (ensure we always print all --print options in help)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2025-03-03 22:57:01 +00:00
commit 2010bba886
59 changed files with 3607 additions and 411 deletions

View file

@ -682,19 +682,20 @@ pub fn eq_generics(l: &Generics, r: &Generics) -> bool {
pub fn eq_where_predicate(l: &WherePredicate, r: &WherePredicate) -> bool {
use WherePredicateKind::*;
match (&l.kind, &r.kind) {
(BoundPredicate(l), BoundPredicate(r)) => {
over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {
eq_generic_param(l, r)
}) && eq_ty(&l.bounded_ty, &r.bounded_ty)
&& over(&l.bounds, &r.bounds, eq_generic_bound)
},
(RegionPredicate(l), RegionPredicate(r)) => {
eq_id(l.lifetime.ident, r.lifetime.ident) && over(&l.bounds, &r.bounds, eq_generic_bound)
},
(EqPredicate(l), EqPredicate(r)) => eq_ty(&l.lhs_ty, &r.lhs_ty) && eq_ty(&l.rhs_ty, &r.rhs_ty),
_ => false,
}
over(&l.attrs, &r.attrs, eq_attr)
&& match (&l.kind, &r.kind) {
(BoundPredicate(l), BoundPredicate(r)) => {
over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {
eq_generic_param(l, r)
}) && eq_ty(&l.bounded_ty, &r.bounded_ty)
&& over(&l.bounds, &r.bounds, eq_generic_bound)
},
(RegionPredicate(l), RegionPredicate(r)) => {
eq_id(l.lifetime.ident, r.lifetime.ident) && over(&l.bounds, &r.bounds, eq_generic_bound)
},
(EqPredicate(l), EqPredicate(r)) => eq_ty(&l.lhs_ty, &r.lhs_ty) && eq_ty(&l.rhs_ty, &r.rhs_ty),
_ => false,
}
}
pub fn eq_use_tree(l: &UseTree, r: &UseTree) -> bool {

View file

@ -58,6 +58,7 @@ implement_spanned!(ast::ExprField);
implement_spanned!(ast::ForeignItem);
implement_spanned!(ast::Item);
implement_spanned!(ast::Local);
implement_spanned!(ast::WherePredicate);
impl Spanned for ast::Stmt {
fn span(&self) -> Span {
@ -149,12 +150,6 @@ impl Spanned for ast::FieldDef {
}
}
impl Spanned for ast::WherePredicate {
fn span(&self) -> Span {
self.span
}
}
impl Spanned for ast::FnRetTy {
fn span(&self) -> Span {
match *self {

View file

@ -463,8 +463,9 @@ impl Rewrite for ast::WherePredicate {
}
fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
let attrs_str = self.attrs.rewrite_result(context, shape)?;
// FIXME: dead spans?
let result = match self.kind {
let pred_str = &match self.kind {
ast::WherePredicateKind::BoundPredicate(ast::WhereBoundPredicate {
ref bound_generic_params,
ref bounded_ty,
@ -499,6 +500,38 @@ impl Rewrite for ast::WherePredicate {
}
};
let mut result = String::with_capacity(attrs_str.len() + pred_str.len() + 1);
result.push_str(&attrs_str);
let pred_start = self.span.lo();
let line_len = last_line_width(&attrs_str) + 1 + first_line_width(&pred_str);
if let Some(last_attr) = self.attrs.last().filter(|last_attr| {
contains_comment(context.snippet(mk_sp(last_attr.span.hi(), pred_start)))
}) {
result = combine_strs_with_missing_comments(
context,
&result,
&pred_str,
mk_sp(last_attr.span.hi(), pred_start),
Shape {
width: shape.width.min(context.config.inline_attribute_width()),
..shape
},
!last_attr.is_doc_comment(),
)?;
} else {
if !self.attrs.is_empty() {
if context.config.inline_attribute_width() < line_len
|| self.attrs.len() > 1
|| self.attrs.last().is_some_and(|a| a.is_doc_comment())
{
result.push_str(&shape.indent.to_string_with_newline(context.config));
} else {
result.push(' ');
}
}
result.push_str(&pred_str);
}
Ok(result)
}
}

View file

@ -0,0 +1,116 @@
// rustfmt-inline_attribute_width: 40
#![crate_type = "lib"]
#![feature(cfg_attribute_in_where)]
use std::marker::PhantomData;
#[cfg(a)]
trait TraitA {}
#[cfg(b)]
trait TraitB {}
trait A<T>
where
#[cfg = a_very_long_attribute_name]
T: TraitA,
#[cfg = another_very_long_attribute_name]
T: TraitB,
{
type B<U>
where
#[cfg = a]
// line comment after the attribute
U: TraitA,
#[cfg = b]
/* block comment after the attribute */
U: TraitB,
#[cfg = a] // short
U: TraitA,
#[cfg = b] /* short */ U: TraitB;
fn foo<U>(&self)
where
/// line doc comment before the attribute
U: TraitA,
/** line doc block comment before the attribute */
U: TraitB;
}
impl<T> A<T> for T
where
#[doc = "line doc before the attribute"]
T: TraitA,
/** short doc */
T: TraitB,
{
type B<U>
= ()
where
#[doc = "short"] U: TraitA,
#[doc = "short"]
#[cfg = a]
U: TraitB;
fn foo<U>(&self)
where
#[cfg = a]
#[cfg = b]
U: TraitA,
/// line doc
#[cfg = c]
U: TraitB,
{
}
}
struct C<T>
where
#[cfg = a] T: TraitA,
#[cfg = b] T: TraitB,
{
_t: PhantomData<T>,
}
union D<T>
where
#[cfg = a] T: TraitA,
#[cfg = b] T: TraitB,
{
_t: PhantomData<T>,
}
enum E<T>
where
#[cfg = a] T: TraitA,
#[cfg = b] T: TraitB,
{
E(PhantomData<T>),
}
#[allow(type_alias_bounds)]
type F<T>
where
#[cfg = a] T: TraitA,
#[cfg = b] T: TraitB,
= T;
impl<T> C<T>
where
#[cfg = a] T: TraitA,
#[cfg = b] T: TraitB,
{
fn new<U>()
where
#[cfg = a] U: TraitA,
#[cfg = b] U: TraitB,
{
}
}
fn foo<T>()
where
#[cfg = a] T: TraitA,
#[cfg = b] T: TraitB,
{
}