1
Fork 0

Track if a where bound comes from a impl Trait desugar

With #93803 `impl Trait` function arguments get desugared to hidden
where bounds. However, Clippy needs to know if a bound was originally a
impl Trait or an actual bound. This adds a field to the
`WhereBoundPredicate` struct to keep track of this information during
HIR lowering.
This commit is contained in:
flip1995 2022-05-05 15:50:11 +01:00 committed by flip1995
parent f47d2b3ad6
commit dd1ff405e3
No known key found for this signature in database
GPG key ID: 2CEFCDB27ED0BE79
7 changed files with 34 additions and 12 deletions

View file

@ -11,6 +11,7 @@ use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_hir::PredicateOrigin;
use rustc_index::vec::{Idx, IndexVec};
use rustc_session::utils::NtToTokenstream;
use rustc_session::Session;
@ -1346,7 +1347,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let mut predicates = SmallVec::new();
predicates.extend(generics.params.iter().filter_map(|param| {
let bounds = self.lower_param_bounds(&param.bounds, itctx.reborrow());
self.lower_generic_bound_predicate(param.ident, param.id, &param.kind, bounds)
self.lower_generic_bound_predicate(
param.ident,
param.id,
&param.kind,
bounds,
PredicateOrigin::GenericParam,
)
}));
predicates.extend(
generics
@ -1380,6 +1387,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
id: NodeId,
kind: &GenericParamKind,
bounds: &'hir [hir::GenericBound<'hir>],
origin: PredicateOrigin,
) -> Option<hir::WherePredicate<'hir>> {
// Do not create a clause if we do not have anything inside it.
if bounds.is_empty() {
@ -1419,7 +1427,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
bounds,
span,
bound_generic_params: &[],
in_where_clause: false,
origin,
}))
}
GenericParamKind::Lifetime => {
@ -1458,7 +1466,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
)
})),
span: self.lower_span(span),
in_where_clause: true,
origin: PredicateOrigin::WhereClause,
}),
WherePredicate::RegionPredicate(WhereRegionPredicate {
ref lifetime,

View file

@ -1298,6 +1298,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
def_node_id,
&GenericParamKind::Type { default: None },
hir_bounds,
hir::PredicateOrigin::ImplTrait,
) {
in_band_ty_bounds.push(preds)
}