Skip to content

Commit

Permalink
Auto merge of rust-lang#131723 - matthiaskrgr:rollup-krcslig, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#122670 (Fix bug where `option_env!` would return `None` when env var is present but not valid Unicode)
 - rust-lang#131095 (Use environment variables instead of command line arguments for merged doctests)
 - rust-lang#131339 (Expand set_ptr_value / with_metadata_of docs)
 - rust-lang#131652 (Move polarity into `PolyTraitRef` rather than storing it on the side)
 - rust-lang#131675 (Update lint message for ABI not supported)
 - rust-lang#131681 (Fix up-to-date checking for run-make tests)
 - rust-lang#131702 (Suppress import errors for traits that couldve applied for method lookup error)
 - rust-lang#131703 (Resolved python deprecation warning in publish_toolstate.py)
 - rust-lang#131710 (Remove `'apostrophes'` from `rustc_parse_format`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 15, 2024
2 parents 66359a7 + 5aa3e11 commit c16ba35
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
6 changes: 4 additions & 2 deletions clippy_lints/src/implied_bounds_in_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ fn collect_supertrait_bounds<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds
bounds
.iter()
.filter_map(|bound| {
if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound
if let GenericBound::Trait(poly_trait) = bound
&& let TraitBoundModifier::None = poly_trait.modifiers
&& let [.., path] = poly_trait.trait_ref.path.segments
&& poly_trait.bound_generic_params.is_empty()
&& let Some(trait_def_id) = path.res.opt_def_id()
Expand Down Expand Up @@ -307,7 +308,8 @@ fn check<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds<'tcx>) {
// This involves some extra logic when generic arguments are present, since
// simply comparing trait `DefId`s won't be enough. We also need to compare the generics.
for (index, bound) in bounds.iter().enumerate() {
if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound
if let GenericBound::Trait(poly_trait) = bound
&& let TraitBoundModifier::None = poly_trait.modifiers
&& let [.., path] = poly_trait.trait_ref.path.segments
&& let implied_args = path.args.map_or([].as_slice(), |a| a.args)
&& let implied_constraints = path.args.map_or([].as_slice(), |a| a.constraints)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/len_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&
if let ty::Alias(_, alias_ty) = ty.kind()
&& let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir().get_if_local(alias_ty.def_id)
&& let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin
&& let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds
&& let [GenericBound::Trait(trait_ref)] = &opaque.bounds
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
&& let Some(generic_args) = segment.args
&& let [constraint] = generic_args.constraints
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn check_fn_inner<'tcx>(
if visitor.lts.iter().any(|lt| matches!(lt.res, LifetimeName::Param(_))) {
return;
}
if let GenericBound::Trait(ref trait_ref, _) = *bound {
if let GenericBound::Trait(ref trait_ref) = *bound {
let params = &trait_ref
.trait_ref
.path
Expand Down Expand Up @@ -438,7 +438,7 @@ impl<'tcx> Visitor<'tcx> for RefVisitor<'_, 'tcx> {
if !lt.is_elided() {
self.unelided_trait_object_lifetime = true;
}
for (bound, _) in bounds {
for bound in bounds {
self.visit_poly_trait_ref(bound);
}
},
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/manual_async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn future_trait_ref<'tcx>(
) -> Option<(&'tcx TraitRef<'tcx>, Vec<LifetimeName>)> {
if let TyKind::OpaqueDef(opaque, bounds) = ty.kind
&& let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| {
if let GenericBound::Trait(poly, _) = bound {
if let GenericBound::Trait(poly) = bound {
Some(&poly.trait_ref)
} else {
None
Expand Down
8 changes: 3 additions & 5 deletions clippy_lints/src/needless_maybe_sized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ struct Bound<'tcx> {
ident: Ident,

trait_bound: &'tcx PolyTraitRef<'tcx>,
modifier: TraitBoundModifier,

predicate_pos: usize,
bound_pos: usize,
Expand All @@ -65,11 +64,10 @@ fn type_param_bounds<'tcx>(generics: &'tcx Generics<'tcx>) -> impl Iterator<Item
.iter()
.enumerate()
.filter_map(move |(bound_pos, bound)| match bound {
&GenericBound::Trait(ref trait_bound, modifier) => Some(Bound {
&GenericBound::Trait(ref trait_bound) => Some(Bound {
param,
ident,
trait_bound,
modifier,
predicate_pos,
bound_pos,
}),
Expand Down Expand Up @@ -120,13 +118,13 @@ impl LateLintPass<'_> for NeedlessMaybeSized {
let maybe_sized_params: DefIdMap<_> = type_param_bounds(generics)
.filter(|bound| {
bound.trait_bound.trait_ref.trait_def_id() == Some(sized_trait)
&& bound.modifier == TraitBoundModifier::Maybe
&& bound.trait_bound.modifiers == TraitBoundModifier::Maybe
})
.map(|bound| (bound.param, bound))
.collect();

for bound in type_param_bounds(generics) {
if bound.modifier == TraitBoundModifier::None
if bound.trait_bound.modifiers == TraitBoundModifier::None
&& let Some(sized_bound) = maybe_sized_params.get(&bound.param)
&& let Some(path) = path_to_sized_bound(cx, bound.trait_bound)
{
Expand Down
15 changes: 8 additions & 7 deletions clippy_lints/src/trait_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {

// Iterate the bounds and add them to our seen hash
// If we haven't yet seen it, add it to the fixed traits
for (bound, _) in bounds {
for bound in bounds {
let Some(def_id) = bound.trait_ref.trait_def_id() else {
continue;
};
Expand All @@ -197,9 +197,9 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
// If the number of unique traits isn't the same as the number of traits in the bounds,
// there must be 1 or more duplicates
if bounds.len() != unique_traits.len() {
let mut bounds_span = bounds[0].0.span;
let mut bounds_span = bounds[0].span;

for (bound, _) in bounds.iter().skip(1) {
for bound in bounds.iter().skip(1) {
bounds_span = bounds_span.to(bound.span);
}

Expand Down Expand Up @@ -229,7 +229,8 @@ impl TraitBounds {
/// this MSRV? See <https://github.com/rust-lang/rust-clippy/issues/8772> for details.
fn cannot_combine_maybe_bound(&self, cx: &LateContext<'_>, bound: &GenericBound<'_>) -> bool {
if !self.msrv.meets(msrvs::MAYBE_BOUND_IN_WHERE)
&& let GenericBound::Trait(tr, TraitBoundModifier::Maybe) = bound
&& let GenericBound::Trait(tr) = bound
&& let TraitBoundModifier::Maybe = tr.modifiers
{
cx.tcx.lang_items().get(LangItem::Sized) == tr.trait_ref.path.res.opt_def_id()
} else {
Expand Down Expand Up @@ -375,11 +376,11 @@ impl Default for ComparableTraitRef {
}

fn get_trait_info_from_bound<'a>(bound: &'a GenericBound<'_>) -> Option<(Res, &'a [PathSegment<'a>], Span)> {
if let GenericBound::Trait(t, tbm) = bound {
if let GenericBound::Trait(t) = bound {
let trait_path = t.trait_ref.path;
let trait_span = {
let path_span = trait_path.span;
if let TraitBoundModifier::Maybe = tbm {
if let TraitBoundModifier::Maybe = t.modifiers {
path_span.with_lo(path_span.lo() - BytePos(1)) // include the `?`
} else {
path_span
Expand Down Expand Up @@ -430,7 +431,7 @@ fn rollup_traits(
let mut repeated_res = false;

let only_comparable_trait_refs = |bound: &GenericBound<'_>| {
if let GenericBound::Trait(t, _) = bound {
if let GenericBound::Trait(t) = bound {
Some((into_comparable_trait_ref(&t.trait_ref), t.span))
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/types/borrowed_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
// Returns true if given type is `Any` trait.
fn is_any_trait(cx: &LateContext<'_>, t: &hir::Ty<'_>) -> bool {
if let TyKind::TraitObject(traits, ..) = t.kind {
return traits.iter().any(|(bound, _)| {
return traits.iter().any(|bound| {
if let Some(trait_did) = bound.trait_ref.trait_def_id()
&& cx.tcx.is_diagnostic_item(sym::Any, trait_did)
{
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/types/type_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
TyKind::TraitObject(param_bounds, _, _) => {
let has_lifetime_parameters = param_bounds.iter().any(|bound| {
bound
.0
.bound_generic_params
.iter()
.any(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
Expand Down
5 changes: 3 additions & 2 deletions clippy_utils/src/ast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,8 @@ pub fn eq_str_lit(l: &StrLit, r: &StrLit) -> bool {
}

pub fn eq_poly_ref_trait(l: &PolyTraitRef, r: &PolyTraitRef) -> bool {
eq_path(&l.trait_ref.path, &r.trait_ref.path)
l.modifiers == r.modifiers
&& eq_path(&l.trait_ref.path, &r.trait_ref.path)
&& over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {
eq_generic_param(l, r)
})
Expand Down Expand Up @@ -820,7 +821,7 @@ pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool {
pub fn eq_generic_bound(l: &GenericBound, r: &GenericBound) -> bool {
use GenericBound::*;
match (l, r) {
(Trait(ptr1, tbm1), Trait(ptr2, tbm2)) => tbm1 == tbm2 && eq_poly_ref_trait(ptr1, ptr2),
(Trait(ptr1), Trait(ptr2)) => eq_poly_ref_trait(ptr1, ptr2),
(Outlives(l), Outlives(r)) => eq_id(l.ident, r.ident),
_ => false,
}
Expand Down

0 comments on commit c16ba35

Please sign in to comment.