Skip to content

Remove priv from the language #13547

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Apr 16, 2014
Merged

Remove priv from the language #13547

merged 3 commits into from
Apr 16, 2014

Conversation

alexcrichton
Copy link
Member

See RFC 6

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 {
Copy link
Member

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 }?

Copy link
Member Author

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 }

Copy link
Member

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?

Copy link
Member Author

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.

@huonw
Copy link
Member

huonw commented Apr 16, 2014

r=me with the situation with private_variant_1.rs clarified (and its corresponding compile-fail/private_variant_2.rs).

@flaper87
Copy link
Contributor

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
@bors bors closed this Apr 16, 2014
@bors bors merged commit a0347d5 into rust-lang:master Apr 16, 2014
@alexcrichton alexcrichton deleted the remove-priv branch April 16, 2014 16:31
Manishearth added a commit to Manishearth/rust that referenced this pull request May 1, 2015
…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! 🍂 🌊
Manishearth added a commit to Manishearth/rust that referenced this pull request May 1, 2015
…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! 🍂 🌊
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this pull request Nov 16, 2022
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 18, 2024
…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`
flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 21, 2024
…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`
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants