Skip to content
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

trait_added_supertrait should check for blanket impls and their bounds #923

Open
obi1kenobi opened this issue Sep 8, 2024 · 0 comments
Open
Labels
A-lint Area: new or existing lint C-enhancement Category: raise the bar on expectations

Comments

@obi1kenobi
Copy link
Owner

The trait_added_supertrait lint (#441, #892) is unable to do precise-enough analysis of supertraits (including foreign traits, blocked on #638) since generics and bounds aren't modeled in our schema yet (#149).

This can cause false-positives in (arguably, relatively pathological) cases such as:

// old:
pub trait Example {}

// new:
pub trait Super {}

impl<T> Super for T {}

pub trait Example: Super {}

Transitive blanket impls can also cause false-positives (an even more-pathological case):

// old:
pub trait Example {}

// new:
pub trait MoreSuper {}

impl<T> MoreSuper for T {}

pub trait Super {}

impl<T: MoreSuper> Super for T {}

pub trait Example: Super {}

In both of these cases, the added supertrait bound is trivially satisfied due to blanket impls, so it's not a major breaking change to add it.

Resolving this issue requires checking (transitively!) for universal blanket impls of the specific ImplementedTrait (trait + generics) that was added in the bound.

It has to be ImplementedTrait ("trait + generics") and not just Trait because it's possible the blanket is only for that specific parameterization of the trait.

For example: impl<T> Blanket<'static, ()> for T {}.

Blankets that don't fit the added supertrait bound don't apply, and in such cases the change is still breaking.

For example: impl<T, U: Copy> Blanket<U> for T {} will not prevent a breaking change if a trait adds a bound like

  • trait Example<T>: Blanket<T>, where T: Copy isn't part of the trait's bounds, or like
  • trait Example: Blanket<String> where String isn't Copy.
@obi1kenobi obi1kenobi added A-lint Area: new or existing lint C-enhancement Category: raise the bar on expectations labels Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: new or existing lint C-enhancement Category: raise the bar on expectations
Projects
None yet
Development

No branches or pull requests

1 participant