Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #122670 (Fix bug where `option_env!` would return `None` when env var is present but not valid Unicode) - #131095 (Use environment variables instead of command line arguments for merged doctests) - #131339 (Expand set_ptr_value / with_metadata_of docs) - #131652 (Move polarity into `PolyTraitRef` rather than storing it on the side) - #131675 (Update lint message for ABI not supported) - #131681 (Fix up-to-date checking for run-make tests) - #131702 (Suppress import errors for traits that couldve applied for method lookup error) - #131703 (Resolved python deprecation warning in publish_toolstate.py) - #131710 (Remove `'apostrophes'` from `rustc_parse_format`) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
c16ba359b5
@ -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()
|
||||
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -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);
|
||||
}
|
||||
},
|
||||
|
@ -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
|
||||
|
@ -40,7 +40,6 @@ struct Bound<'tcx> {
|
||||
ident: Ident,
|
||||
|
||||
trait_bound: &'tcx PolyTraitRef<'tcx>,
|
||||
modifier: TraitBoundModifier,
|
||||
|
||||
predicate_pos: usize,
|
||||
bound_pos: usize,
|
||||
@ -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,
|
||||
}),
|
||||
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
};
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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 { .. }))
|
||||
|
@ -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)
|
||||
})
|
||||
@ -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,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user