1
Fork 0

Add and use generics.is_empty() and generics.is_own_empty, rather than using generics' attributes

This commit is contained in:
Santiago Pastorino 2024-05-11 11:46:25 +02:00
parent 84b9b6d16c
commit 4501ae89f1
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
18 changed files with 25 additions and 17 deletions

View file

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

View file

@ -1409,7 +1409,7 @@ fn generics_args_err_extend<'a>(
// it was done based on the end of assoc segment but that sometimes
// led to impossible spans and caused issues like #116473
let args_span = args.span_ext.with_lo(args.span_ext.lo() - BytePos(2));
if tcx.generics_of(adt_def.did()).count() == 0 {
if tcx.generics_of(adt_def.did()).is_empty() {
// FIXME(estebank): we could also verify that the arguments being
// work for the `enum`, instead of just looking if it takes *any*.
err.span_suggestion_verbose(

View file

@ -412,7 +412,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// Traits always have `Self` as a generic parameter, which means they will not return early
// here and so associated type bindings will be handled regardless of whether there are any
// non-`Self` generic parameters.
if generics.own_params.is_empty() {
if generics.is_own_empty() {
return (tcx.mk_args(parent_args), arg_count);
}

View file

@ -181,7 +181,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
let def_kind = tcx.def_kind(item_def_id);
match def_kind {
DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id),
DefKind::Const if tcx.generics_of(item_def_id).own_params.is_empty() => {
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
let cid = GlobalId { instance, promoted: None };
let param_env = ty::ParamEnv::reveal_all();

View file

@ -99,7 +99,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
debug!("build_constraints_for_item({})", tcx.def_path_str(def_id));
// Skip items with no generics - there's nothing to infer in them.
if tcx.generics_of(def_id).count() == 0 {
if tcx.generics_of(def_id).is_empty() {
return;
}

View file

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