Skip to content

Commit 1d1283e

Browse files
committed
Auto merge of rust-lang#125006 - spastorino:generics-is-empty, r=compiler-errors
Add and use generics.is_empty() and generics.is_own_empty, rather than using generics' attributes r? `@compiler-errors` Related to rust-lang#123929
2 parents 959a67a + 4501ae8 commit 1d1283e

File tree

18 files changed

+25
-17
lines changed

18 files changed

+25
-17
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+8
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.

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

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

compiler/rustc_monomorphize/src/collector.rs

+1-1
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

+1-1
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

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

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

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17811781
// FIXME(generic-associated-types): This only detects one layer of inference,
17821782
// which is probably not what we actually want, but fixing it causes some ambiguity:
17831783
// <https://github.com/rust-lang/rust/issues/125196>.
1784-
if !generics.own_params.is_empty()
1784+
if !generics.is_own_empty()
17851785
&& obligation.predicate.args[generics.parent_count..].iter().any(|&p| {
17861786
p.has_non_region_infer()
17871787
&& match p.unpack() {

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

+1-1
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

+1-1
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)