-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Remove priv
from the language
#13547
Conversation
This replaces all uses of private enum variants with a struct that has one private field pointing at a private enum. RFC: 0006-remove-priv
@@ -229,8 +229,8 @@ pub mod types { | |||
*/ | |||
#[repr(u8)] | |||
pub enum c_void { |
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.
Could this become pub struct c_void { private: u8 }
?
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.
Sadly I don't think so. I think that this was around primarily for free(malloc(size))
to get optimized away.
pub struct c_void { wut: u8 }
extern {
fn malloc(s: uint) -> *mut c_void;
fn free(s: *mut c_void);
}
fn main() {
unsafe {
let a = malloc(4);
free(a);
}
}
$ rustc foo.rs --emit=ir -o - -O
; ModuleID = '-.rs'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-apple-darwin"
%struct.c_void = type { i8 }
; Function Attrs: nounwind
declare noalias %struct.c_void* @malloc(i64) unnamed_addr #0
; Function Attrs: nounwind
declare void @free(%struct.c_void* nocapture) unnamed_addr #0
; Function Attrs: nounwind uwtable
define internal void @_ZN4main20h1284b3d9a92c1d91yaa4v0.0E() unnamed_addr #1 {
entry-block:
%0 = tail call %struct.c_void* @malloc(i64 4)
tail call void @free(%struct.c_void* %0)
ret void
}
define i64 @main(i64, i8**) unnamed_addr {
top:
%2 = tail call i64 @_ZN10lang_start20he5bbdca974ae42c3eqd9v0.11.preE(i8* bitcast (void ()* @_ZN4main20h1284b3d9a92c1d91yaa4v0.0E to i8*), i64 %0, i8** %1)
ret i64 %2
}
declare i64 @_ZN10lang_start20he5bbdca974ae42c3eqd9v0.11.preE(i8*, i64, i8**) unnamed_addr
attributes #0 = { nounwind }
attributes #1 = { nounwind uwtable }
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.
But the enum works? That seems a little peculiar?
Oh, I guess #[repr(u8)]
is making the enum an actual u8
, rather than just a struct with a u8
in it?
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, I think the problem is
%struct.c_void = type { i8 }
which does not happen with enums because the enum is just an LLVM i8
type.
r=me with the situation with private_variant_1.rs clarified (and its corresponding compile-fail/private_variant_2.rs). |
Yay, 🍰 |
This removes the `priv` keyword from the language and removes private enum variants as a result. The remaining use cases of private enum variants were all updated to be a struct with one private field that is a private enum. RFC: 0006-remove-priv Closes rust-lang#13535
It is no longer used in rust anywhere. RFC: 0006-remove-priv
…lexcrichton Hi! While researching stuff for the reference and the grammar, I came across a few mentions of using the `priv` keyword that was removed in 0.11.0 (rust-lang#13547, rust-lang#8122, rust-lang/rfcs#26, [RFC 0026](https://github.com/rust-lang/rfcs/blob/master/text/0026-remove-priv.md)). One occurrence is a mention in the reference, a few are in comments, and a few are marking test functions. I left the test that makes sure you can't name an ident `priv` since it's still a reserved keyword. I did a little grepping around for `priv `, priv in backticks, `Private` etc and I think the remaining instances are fine, but if anyone knows anywhere in particular I should check for any other lingering mentions of `priv`, please let me know and I would be happy to! 🍂 🌊
…lexcrichton Hi! While researching stuff for the reference and the grammar, I came across a few mentions of using the `priv` keyword that was removed in 0.11.0 (rust-lang#13547, rust-lang#8122, rust-lang/rfcs#26, [RFC 0026](https://github.com/rust-lang/rfcs/blob/master/text/0026-remove-priv.md)). One occurrence is a mention in the reference, a few are in comments, and a few are marking test functions. I left the test that makes sure you can't name an ident `priv` since it's still a reserved keyword. I did a little grepping around for `priv `, priv in backticks, `Private` etc and I think the remaining instances are fine, but if anyone knows anywhere in particular I should check for any other lingering mentions of `priv`, please let me know and I would be happy to! 🍂 🌊
internal: Optimize `apply_document_changes` a bit cc rust-lang/rust-analyzer#13538
…ge-category, r=llogiq Change the category of `manual_is_power_of_two` to `pedantic` Fixes rust-lang#13547. The value being checked might be a bit flag, suggesting `is_power_of_two` for it would make the code unreadable. changelog: [`manual_is_power_of_two`]: Change the category to `pedantic`
…ge-category, r=llogiq Change the category of `manual_is_power_of_two` to `pedantic` Fixes rust-lang#13547. The value being checked might be a bit flag, suggesting `is_power_of_two` for it would make the code unreadable. changelog: [`manual_is_power_of_two`]: Change the category to `pedantic`
See RFC 6