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

INSP: Add #[repr(...)] quick fix for E0308 error #8087

Merged
merged 1 commit into from Apr 26, 2023

Conversation

serid
Copy link
Contributor

@serid serid commented Nov 8, 2021

Fixes #7894.

changelog: Add a quick fix for type mismatch E0308 error that adds a #[repr(...)] attribute to a enum:

enum Foo {
    FooVariant = 1u16 // Error: expected `isize`, found `u16`
}

=>

#[repr(u16)]
enum Foo {
    FooVariant = 1u16
}

@serid
Copy link
Contributor Author

serid commented Nov 9, 2021

This quick fix was strongly inspired by this commit that added a quick fix for changing function return type.

Would appreciate any recommendations on improving user-facing messages and errors.

@Undin Undin added the feature label Nov 9, 2021
@Undin Undin added this to In Progress in To test via automation Nov 9, 2021
@mchernyavsky mchernyavsky changed the title FIX: Resolves #7894 ACT: Add #[repr(...)] quick fix for E0308 error Dec 1, 2021
if (element.containingCrate?.origin != PackageOrigin.WORKSPACE) return null

// fix only works for integral expressions inside enums. expression type should not be an alias
if (actualTy.isIntegral && actualTy.aliasedBy == null && findEnumOwner(element) != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findEnumOwner(element) != null produces a false-positive in this case:

Screen Shot 2021-12-01 at 06 09 04

@mchernyavsky
Copy link
Member

I have rebased the branch on master and pushed some minor changes.

@vlad20012 vlad20012 changed the title ACT: Add #[repr(...)] quick fix for E0308 error INSP: Add #[repr(...)] quick fix for E0308 error Apr 25, 2023
Copy link
Member

@vlad20012 vlad20012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 26, 2023

Build succeeded:

@bors bors bot merged commit 0b5445f into intellij-rust:master Apr 26, 2023
42 checks passed
To test automation moved this from In Progress to Test Apr 26, 2023
@github-actions github-actions bot added this to the v194 milestone Apr 26, 2023
@serid
Copy link
Contributor Author

serid commented Apr 26, 2023

Congratulations, guys! i tried to finish this a few months ago but couldn't run the test suit, glad you got around to it 😄

@neonaot neonaot self-assigned this May 2, 2023
@neonaot neonaot moved this from Test to Done in To test May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
To test
  
Done
Development

Successfully merging this pull request may close these issues.

Provide Add repr() attribute quick fix for E0308 error
5 participants