iomentum / cargo-breaking

Mozilla Public License 2.0
112 stars 7 forks source link

Trait items in definition changes are too restrictive #3

Open scrabsha opened 3 years ago

scrabsha commented 3 years ago

API extracted from trait definition are a near-verbatim of the original AST. As a result, any change in the AST of the trait impl block is detected as a breaking change. See an example of incorrectly-detect breaking change at the end of the issue.

To fix this, we must reduce the amount of data we take "as is" from the AST. For instance, instead of taking a full TraitItemMethod, we should store the method signature and wheter if it is provided or not. Most of the changes should be done in the public_api::trait_defs module, particularly in the fields of TraitDefMetadata.

Example of incorrect breaking change

Initial code
pub trait T {
    fn f() { 42 }
}
Modified code
pub trait T {
    fn f() { 101 }
}
Diagnosis from cargo-breaking

≠ T::f