Skip to content

#cfg conditional compilation does not work in object expressions #1181

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

Closed
boggle opened this issue Nov 16, 2011 · 2 comments
Closed

#cfg conditional compilation does not work in object expressions #1181

boggle opened this issue Nov 16, 2011 · 2 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)

Comments

@boggle
Copy link
Contributor

boggle commented Nov 16, 2011

Likely, this also holds for non toplevel functions. It is inconvenient and probably should be fixed. Example from io.rs:

obj FILE_writer(f: os::libc::FILE, res: option::t@FILE_res) {
#cfg[target="macos"]
fn fsync() { ret macos_os::fsync(f); }
}

will not compile.

@brson
Copy link
Contributor

brson commented Nov 16, 2011

This is because attributes only work on items, and objects and methods are not items. Probably the best you can do in this situation is define a function inside the fsync method and conditionalize that. I believe that will work.

obj FILE_writer(f: os::libc::FILE, res: option::t<@FILE_res>) {
  fn fsync() {
    fsync_()

    #[cfg(target_os = "macos")]
    fn fsync_() {  macos_os::fsync(f) }

    ...
  }
}

It probably would not be difficult to allow attributes and conditional compilation on methods as well. Attributes on general expressions is harder.

@graydon
Copy link
Contributor

graydon commented Jan 31, 2012

obj doesn't exist anymore, closing.

@graydon graydon closed this as completed Jan 31, 2012
celinval added a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
* Update rust toolchain to nightly-2022-05-03

This compiles but regression is failing due to unimplemented statement.

* Handle change to Box<T> structure

Box<T> now users NonNull<T> instead of raw pointer.

* Handle new statement kind Deinit

We codegen an assignment to non-det value per documentation. See more
information here:
 - rust-lang#95125

* Fix discriminant computation

After the merge, the previous wrapping sub logic was triggering a panic
due to u128 -> i64 conversion. There were also other overflow issues
when trying to convert the `niche_value` to unsigned.

For now, I'm disabling the coversion check which I believe is too
strict. We should consider implementing a more flexible check later that
can be controlled by the user without affecting the internal compiler
codegen.

* Address PR comments:

 - Improve comments.
 - Remove wrong cast to i64.
 - Fix statement location.
 - Create util function to create unsigned type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)
Projects
None yet
Development

No branches or pull requests

3 participants