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.

0 commit comments

Comments
 (0)