-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add and use generics.is_empty()
, rather than checking generics' params vec
#123929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Some changes occurred in src/tools/clippy cc @rust-lang/clippy HIR ty lowering was modified cc @fmease Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, after a self-review it's kind of certain there are more places where it's wrong to use this than right.
@@ -430,7 +430,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.params.is_empty() { | |||
if gat_generics.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, this is wrong!
@@ -450,7 +450,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { | |||
// `foo.bar::<u32>(...)` -- the `Self` type here will be the | |||
// type of `foo` (possibly adjusted), but we don't want to | |||
// include that. We want just the `[_, u32]` part. | |||
if !args.is_empty() && !generics.params.is_empty() { | |||
if !args.is_empty() && !generics.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also wrong
@@ -411,7 +411,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.params.is_empty() { | |||
if generics.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong
@@ -282,7 +282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
if !self_ty_name.contains('<') { | |||
if let Adt(def, _) = self_ty.kind() { | |||
let generics = self.tcx.generics_of(def.did()); | |||
if !generics.params.is_empty() { | |||
if !generics.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong
@@ -1871,7 +1871,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { | |||
let generics = self.tcx.generics_of(method); | |||
assert_eq!(args.len(), generics.parent_count); | |||
|
|||
let xform_fn_sig = if generics.params.is_empty() { | |||
let xform_fn_sig = if generics.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong
@@ -157,7 +157,7 @@ pub trait Printer<'tcx>: Sized { | |||
// If we have any generic arguments to print, we do that | |||
// on top of the same path, but without its own generics. | |||
_ => { | |||
if !generics.params.is_empty() && args.len() >= generics.count() { | |||
if !generics.is_empty() && args.len() >= generics.count() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong
@@ -397,7 +397,7 @@ pub fn object_safety_violations_for_assoc_item( | |||
// Associated types can only be object safe if they have `Self: Sized` bounds. | |||
ty::AssocKind::Type => { | |||
if !tcx.features().generic_associated_types_extended | |||
&& !tcx.generics_of(item.def_id).params.is_empty() | |||
&& !tcx.generics_of(item.def_id).is_empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong
@@ -1773,7 +1773,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | |||
// If this type is a GAT, and of the GAT args resolve to something new, | |||
// that means that we must have newly inferred something about the GAT. | |||
// We should give up in that case. | |||
if !generics.params.is_empty() | |||
if !generics.is_empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong
@@ -225,7 +225,7 @@ impl {self_ty_without_ref} {{ | |||
&& let ImplItemKind::Fn(sig, _) = item.kind | |||
&& let FnRetTy::Return(ret) = sig.decl.output | |||
&& is_nameable_in_impl_trait(ret) | |||
&& cx.tcx.generics_of(item_did).params.is_empty() | |||
&& cx.tcx.generics_of(item_did).is_empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this is wrong
The job Click to see the possible cause of the failure (guessed by this bot)
|
I guess you have decided to not proceed with this change, right?. I was suggesting something like an |
@spastorino: feel free to do the change yourself -- you can use the comments above to figure out where we care about is_own_empty vs is_empty. |
…iler-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
r? spastorino