Skip to content

Commit 76eeee1

Browse files
committed
Add and use generics.is_empty() and generics.is_own_empty, rather than using generics' attributes
1 parent cf77474 commit 76eeee1

File tree

18 files changed

+25
-17
lines changed

18 files changed

+25
-17
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
431431
}
432432
let gat_generics = tcx.generics_of(gat_def_id);
433433
// FIXME(jackh726): we can also warn in the more general case
434-
if gat_generics.own_params.is_empty() {
434+
if gat_generics.is_own_empty() {
435435
continue;
436436
}
437437

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ fn generics_args_err_extend<'a>(
14151415
// it was done based on the end of assoc segment but that sometimes
14161416
// led to impossible spans and caused issues like #116473
14171417
let args_span = args.span_ext.with_lo(args.span_ext.lo() - BytePos(2));
1418-
if tcx.generics_of(adt_def.did()).count() == 0 {
1418+
if tcx.generics_of(adt_def.did()).is_empty() {
14191419
// FIXME(estebank): we could also verify that the arguments being
14201420
// work for the `enum`, instead of just looking if it takes *any*.
14211421
err.span_suggestion_verbose(

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
411411
// Traits always have `Self` as a generic parameter, which means they will not return early
412412
// here and so associated type bindings will be handled regardless of whether there are any
413413
// non-`Self` generic parameters.
414-
if generics.own_params.is_empty() {
414+
if generics.is_own_empty() {
415415
return (tcx.mk_args(parent_args), arg_count);
416416
}
417417

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
184184
let def_kind = tcx.def_kind(item_def_id);
185185
match def_kind {
186186
DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id),
187-
DefKind::Const if tcx.generics_of(item_def_id).own_params.is_empty() => {
187+
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
188188
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
189189
let cid = GlobalId { instance, promoted: None };
190190
let param_env = ty::ParamEnv::reveal_all();

compiler/rustc_hir_analysis/src/variance/constraints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
9898
debug!("build_constraints_for_item({})", tcx.def_path_str(def_id));
9999

100100
// Skip items with no generics - there's nothing to infer in them.
101-
if tcx.generics_of(def_id).count() == 0 {
101+
if tcx.generics_of(def_id).is_empty() {
102102
return;
103103
}
104104

compiler/rustc_hir_analysis/src/variance/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn crate_variances(tcx: TyCtxt<'_>, (): ()) -> CrateVariancesMap<'_> {
4040

4141
fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
4242
// Skip items with no generics - there's nothing to infer in them.
43-
if tcx.generics_of(item_def_id).count() == 0 {
43+
if tcx.generics_of(item_def_id).is_empty() {
4444
return &[];
4545
}
4646

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
450450
// `foo.bar::<u32>(...)` -- the `Self` type here will be the
451451
// type of `foo` (possibly adjusted), but we don't want to
452452
// include that. We want just the `[_, u32]` part.
453-
if !args.is_empty() && !generics.own_params.is_empty() {
453+
if !args.is_empty() && !generics.is_own_empty() {
454454
let user_type_annotation = self.probe(|_| {
455455
let user_args = UserArgs {
456456
args: GenericArgs::for_item(self.tcx, pick.item.def_id, |param, _| {

compiler/rustc_hir_typeck/src/method/prelude2021.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
278278
if !self_ty_name.contains('<') {
279279
if let ty::Adt(def, _) = self_ty.kind() {
280280
let generics = self.tcx.generics_of(def.did());
281-
if !generics.own_params.is_empty() {
281+
if !generics.is_own_empty() {
282282
let counts = generics.own_counts();
283283
self_ty_name += &format!(
284284
"<{}>",

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17351735
let generics = self.tcx.generics_of(method);
17361736
assert_eq!(args.len(), generics.parent_count);
17371737

1738-
let xform_fn_sig = if generics.own_params.is_empty() {
1738+
let xform_fn_sig = if generics.is_own_empty() {
17391739
fn_sig.instantiate(self.tcx, args)
17401740
} else {
17411741
let args = GenericArgs::for_item(self.tcx, method, |param, _| {

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ impl<'tcx> Generics {
385385
}
386386
false
387387
}
388+
389+
pub fn is_empty(&'tcx self) -> bool {
390+
self.count() == 0
391+
}
392+
393+
pub fn is_own_empty(&'tcx self) -> bool {
394+
self.own_params.is_empty()
395+
}
388396
}
389397

390398
/// Bounds on generics.

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub trait Printer<'tcx>: Sized {
157157
// If we have any generic arguments to print, we do that
158158
// on top of the same path, but without its own generics.
159159
_ => {
160-
if !generics.own_params.is_empty() && args.len() >= generics.count() {
160+
if !generics.is_own_empty() && args.len() >= generics.count() {
161161
let args = generics.own_args_no_defaults(self.tcx(), args);
162162
return self.path_generic_args(
163163
|cx| cx.print_def_path(def_id, parent_args),

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ impl<'v> RootCollector<'_, 'v> {
14291429
match self.tcx.def_kind(id.owner_id) {
14301430
DefKind::Enum | DefKind::Struct | DefKind::Union => {
14311431
if self.strategy == MonoItemCollectionStrategy::Eager
1432-
&& self.tcx.generics_of(id.owner_id).count() == 0
1432+
&& self.tcx.generics_of(id.owner_id).is_empty()
14331433
{
14341434
debug!("RootCollector: ADT drop-glue for `{id:?}`",);
14351435

compiler/rustc_monomorphize/src/polymorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn unused_generic_params<'tcx>(
5151
debug!(?generics);
5252

5353
// Exit early when there are no parameters to be unused.
54-
if generics.count() == 0 {
54+
if generics.is_empty() {
5555
return UnusedGenericParams::new_all_used();
5656
}
5757

compiler/rustc_trait_selection/src/traits/object_safety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ pub fn object_safety_violations_for_assoc_item(
397397
// Associated types can only be object safe if they have `Self: Sized` bounds.
398398
ty::AssocKind::Type => {
399399
if !tcx.features().generic_associated_types_extended
400-
&& !tcx.generics_of(item.def_id).own_params.is_empty()
400+
&& !tcx.generics_of(item.def_id).is_own_empty()
401401
&& !item.is_impl_trait_in_trait()
402402
{
403403
vec![ObjectSafetyViolation::GAT(item.name, item.ident(tcx).span)]

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
618618
// higher-ranked things.
619619
// Prevent, e.g., `dyn Iterator<Item = str>`.
620620
for bound in self.tcx().item_bounds(assoc_type).transpose_iter() {
621-
let arg_bound = if defs.count() == 0 {
621+
let arg_bound = if defs.is_empty() {
622622
bound.instantiate(tcx, trait_predicate.trait_ref.args)
623623
} else {
624624
let mut args = smallvec::SmallVec::with_capacity(defs.count());

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17771777
// If this type is a GAT, and of the GAT args resolve to something new,
17781778
// that means that we must have newly inferred something about the GAT.
17791779
// We should give up in that case.
1780-
if !generics.own_params.is_empty()
1780+
if !generics.is_own_empty()
17811781
&& obligation.predicate.args[generics.parent_count..].iter().any(|&p| {
17821782
p.has_non_region_infer() && self.infcx.resolve_vars_if_possible(p) != p
17831783
})

src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl {self_ty_without_ref} {{
225225
&& let ImplItemKind::Fn(sig, _) = item.kind
226226
&& let FnRetTy::Return(ret) = sig.decl.output
227227
&& is_nameable_in_impl_trait(ret)
228-
&& cx.tcx.generics_of(item_did).own_params.is_empty()
228+
&& cx.tcx.generics_of(item_did).is_own_empty()
229229
&& sig.decl.implicit_self == expected_implicit_self
230230
&& sig.decl.inputs.len() == 1
231231
&& let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id())

src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn qpath_certainty(cx: &LateContext<'_>, qpath: &QPath<'_>, resolves_to_type: bo
176176
.get(*lang_item)
177177
.map_or(Certainty::Uncertain, |def_id| {
178178
let generics = cx.tcx.generics_of(def_id);
179-
if generics.parent_count == 0 && generics.own_params.is_empty() {
179+
if generics.is_empty() {
180180
Certainty::Certain(if resolves_to_type { Some(def_id) } else { None })
181181
} else {
182182
Certainty::Uncertain

0 commit comments

Comments
 (0)