Skip to content

Commit 4501ae8

Browse files
committed
Add and use generics.is_empty() and generics.is_own_empty, rather than using generics' attributes
1 parent 84b9b6d commit 4501ae8

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
@@ -432,7 +432,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
432432
}
433433
let gat_generics = tcx.generics_of(gat_def_id);
434434
// FIXME(jackh726): we can also warn in the more general case
435-
if gat_generics.own_params.is_empty() {
435+
if gat_generics.is_own_empty() {
436436
continue;
437437
}
438438

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ fn generics_args_err_extend<'a>(
14091409
// it was done based on the end of assoc segment but that sometimes
14101410
// led to impossible spans and caused issues like #116473
14111411
let args_span = args.span_ext.with_lo(args.span_ext.lo() - BytePos(2));
1412-
if tcx.generics_of(adt_def.did()).count() == 0 {
1412+
if tcx.generics_of(adt_def.did()).is_empty() {
14131413
// FIXME(estebank): we could also verify that the arguments being
14141414
// work for the `enum`, instead of just looking if it takes *any*.
14151415
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
@@ -412,7 +412,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
412412
// Traits always have `Self` as a generic parameter, which means they will not return early
413413
// here and so associated type bindings will be handled regardless of whether there are any
414414
// non-`Self` generic parameters.
415-
if generics.own_params.is_empty() {
415+
if generics.is_own_empty() {
416416
return (tcx.mk_args(parent_args), arg_count);
417417
}
418418

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
181181
let def_kind = tcx.def_kind(item_def_id);
182182
match def_kind {
183183
DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id),
184-
DefKind::Const if tcx.generics_of(item_def_id).own_params.is_empty() => {
184+
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
185185
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
186186
let cid = GlobalId { instance, promoted: None };
187187
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
@@ -99,7 +99,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
9999
debug!("build_constraints_for_item({})", tcx.def_path_str(def_id));
100100

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

compiler/rustc_hir_analysis/src/variance/mod.rs

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

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

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
451451
// `foo.bar::<u32>(...)` -- the `Self` type here will be the
452452
// type of `foo` (possibly adjusted), but we don't want to
453453
// include that. We want just the `[_, u32]` part.
454-
if !args.is_empty() && !generics.own_params.is_empty() {
454+
if !args.is_empty() && !generics.is_own_empty() {
455455
let user_type_annotation = self.probe(|_| {
456456
let user_args = UserArgs {
457457
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
@@ -279,7 +279,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
279279
if !self_ty_name.contains('<') {
280280
if let ty::Adt(def, _) = self_ty.kind() {
281281
let generics = self.tcx.generics_of(def.did());
282-
if !generics.own_params.is_empty() {
282+
if !generics.is_own_empty() {
283283
let counts = generics.own_counts();
284284
self_ty_name += &format!(
285285
"<{}>",

compiler/rustc_hir_typeck/src/method/probe.rs

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

1757-
let xform_fn_sig = if generics.own_params.is_empty() {
1757+
let xform_fn_sig = if generics.is_own_empty() {
17581758
fn_sig.instantiate(self.tcx, args)
17591759
} else {
17601760
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
@@ -391,6 +391,14 @@ impl<'tcx> Generics {
391391
}
392392
false
393393
}
394+
395+
pub fn is_empty(&'tcx self) -> bool {
396+
self.count() == 0
397+
}
398+
399+
pub fn is_own_empty(&'tcx self) -> bool {
400+
self.own_params.is_empty()
401+
}
394402
}
395403

396404
/// Bounds on generics.

0 commit comments

Comments
 (0)