-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Allow enum discriminants to not be uint, and use smallest possible size by default. #9613
Merged
+967
−198
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f1124a2
Add parser for `#[repr(...)]`; nothing uses it yet.
jld 01740ac
Initial implementation of enum discrimnant sizing.
jld 25f9534
Lint non-FFI-safe enums.
jld ac311ec
Fix multiple mistakes in adt::is_ffi_safe
jld c8c0876
Add repr attributes in various places that need them.
jld a027f16
Check repr attribute consistency at check time, not translation.
jld 01097cb
Unbreak the debuginfo tests.
jld 727731f
Assorted cleanups suggested by reviewers.
jld 92109b1
Yet more neatening
jld fcfbfde
Adjust reflection for the possibility of discriminants larger than int.
jld afab330
C-like enums are not always immediate
jld de9bb97
Add tests for enum discriminant sizing.
jld 472d798
Work around const_eval issues by changing signed integer `min_value`s.
jld ac4644d
Add another discriminant-size-related test, this time with fields.
jld 49f851c
Fix type_of for enums to not lose data in some cases when immediate.
jld c0190a9
Prevent unoptimized rustpkg tests from running out of stack.
jld 86a710e
Fix check-fast breakage in new enum test.
jld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,7 @@ mod test { | |
use enum_set::*; | ||
|
||
#[deriving(Eq)] | ||
#[repr(uint)] | ||
enum Foo { | ||
A, B, C | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
//! Context itself, span_lint should be used instead of add_lint. | ||
|
||
use driver::session; | ||
use middle::trans::adt; // for `adt::is_ffi_safe` | ||
use middle::ty; | ||
use middle::pat_util; | ||
use metadata::csearch; | ||
|
@@ -627,6 +628,14 @@ fn check_item_ctypes(cx: &Context, it: &ast::item) { | |
"found rust type `uint` in foreign module, while \ | ||
libc::c_uint or libc::c_ulong should be used"); | ||
} | ||
ast::DefTy(def_id) => { | ||
if !adt::is_ffi_safe(cx.tcx, def_id) { | ||
cx.span_lint(ctypes, ty.span, | ||
"found enum type without foreign-function-safe \ | ||
representation annotation in foreign module"); | ||
// NOTE this message could be more helpful | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this is definitely worthy of a |
||
} | ||
} | ||
_ => () | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are these (and some related tags) all still necessary? It looks like the enum should be automatically sized so this shouldn't be necessary?
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.
There's a transmute from
uint
to that enum a few lines farther down, in theenum_set::CLike
impl; without the attribute, it won't compile.