1
Fork 0

Auto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillot

Track if a where bound comes from a impl Trait desugar

With https://github.com/rust-lang/rust/pull/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 AST->HIR lowering.

r? `@cjgillot`

cc `@estebank` (as the reviewer of #93803)
This commit is contained in:
bors 2022-05-08 14:10:12 +00:00
commit ed3164baf0
11 changed files with 40 additions and 34 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)
}