Skip to content

Use the bitflags! macro to implement FlagV1 #45079

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
wants to merge 4 commits into from

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Oct 7, 2017

Closes #15738.

This currently doesn't compile, and I don't really understand why:

error[E0463]: can't find crate for `core`

error: aborting due to previous error

error: Could not compile `bitflags`.

Sorry @alexcrichton, I think you're probably still the most knowledgable person on this :(

Full log:

$ ./x.py --incremental --stage 0 build src/libcore --verbose
Updating submodules
running: git submodule -q sync
running: git submodule update --init --recursive src/llvm src/rt/hoedown src/jemalloc src/tools/rust-installer src/liblibc src/doc/nomicon src/tools/cargo src/doc/reference src/doc/book src/tools/rls src/libcompiler_builtins src/tools/clippy src/tools/rustfmt src/tools/miri
running: git submodule -q foreach git reset -q --hard
running: git submodule -q foreach git clean -qdfx
running: /Users/tamird/src/rust/build/x86_64-apple-darwin/stage0/bin/cargo build --manifest-path /Users/tamird/src/rust/src/bootstrap/Cargo.toml --verbose
       Fresh cc v1.0.0
       Fresh quote v0.3.15
       Fresh serde v1.0.15
       Fresh unicode-xid v0.0.4
       Fresh itoa v0.3.4
       Fresh num-traits v0.1.40
       Fresh dtoa v0.4.2
       Fresh getopts v0.2.15
       Fresh lazy_static v0.2.8
       Fresh libc v0.2.31
       Fresh cmake v0.1.26
       Fresh toml v0.4.5
       Fresh synom v0.11.3
       Fresh serde_json v1.0.3
       Fresh num_cpus v1.6.2
       Fresh filetime v0.1.12
       Fresh syn v0.11.11
       Fresh build_helper v0.1.0 (file:///Users/tamird/src/rust/src/build_helper)
       Fresh serde_derive_internals v0.16.0
       Fresh serde_derive v1.0.15
       Fresh bootstrap v0.0.0 (file:///Users/tamird/src/rust/src/bootstrap)
    Finished dev [unoptimized] target(s) in 0.0 secs
running: /Users/tamird/src/rust/build/bootstrap/debug/bootstrap --incremental --stage 0 build src/libcore --verbose
finding compilers
CC_x86_64-apple-darwin = "cc"
AR_x86_64-apple-darwin = "ar"
CC_x86_64-apple-darwin = "cc"
AR_x86_64-apple-darwin = "ar"
CC_x86_64-apple-darwin = "cc"
AR_x86_64-apple-darwin = "ar"
CXX_x86_64-apple-darwin = "c++"
CXX_x86_64-apple-darwin = "c++"
running sanity check
learning about cargo
> Assemble { target_compiler: Compiler { stage: 0, host: "x86_64-apple-darwin" } }
< Assemble { target_compiler: Compiler { stage: 0, host: "x86_64-apple-darwin" } }
> Std { target: "x86_64-apple-darwin", compiler: Compiler { stage: 0, host: "x86_64-apple-darwin" } }
  > StartupObjects { compiler: Compiler { stage: 0, host: "x86_64-apple-darwin" }, target: "x86_64-apple-darwin" }
  < StartupObjects { compiler: Compiler { stage: 0, host: "x86_64-apple-darwin" }, target: "x86_64-apple-darwin" }
Building stage0 std artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
  > Sysroot { compiler: Compiler { stage: 0, host: "x86_64-apple-darwin" } }
  < Sysroot { compiler: Compiler { stage: 0, host: "x86_64-apple-darwin" } }
running: "/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0/bin/cargo" "build" "--target" "x86_64-apple-darwin" "-j" "4" "-v" "--release" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/Users/tamird/src/rust/src/libstd/Cargo.toml" "--message-format" "json"
       Fresh cc v1.0.0
   Compiling bitflags v1.0.0
       Fresh libc v0.2.31
     Running `/Users/tamird/src/rust/build/bootstrap/debug/rustc --crate-name bitflags /Users/tamird/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bitflags-1.0.0/src/lib.rs --error-format json --crate-type lib --emit=dep-info,link -C opt-level=2 --cfg 'feature="default"' --cfg 'feature="example_generated"' -C metadata=c9c6946b58ad8fa6 -C extra-filename=-c9c6946b58ad8fa6 --out-dir /Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/deps --target x86_64-apple-darwin -L dependency=/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/deps -L dependency=/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/release/deps --cap-lints allow`
       Fresh cmake v0.1.26
       Fresh filetime v0.1.12
       Fresh build_helper v0.1.0 (file:///Users/tamird/src/rust/src/build_helper)
error[E0463]: can't find crate for `core`

error: aborting due to previous error

error: Could not compile `bitflags`.

Caused by:
  process didn't exit successfully: `/Users/tamird/src/rust/build/bootstrap/debug/rustc --crate-name bitflags /Users/tamird/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bitflags-1.0.0/src/lib.rs --error-format json --crate-type lib --emit=dep-info,link -C opt-level=2 --cfg feature="default" --cfg feature="example_generated" -C metadata=c9c6946b58ad8fa6 -C extra-filename=-c9c6946b58ad8fa6 --out-dir /Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/deps --target x86_64-apple-darwin -L dependency=/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/deps -L dependency=/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0-std/release/deps --cap-lints allow` (exit code: 101)
thread 'main' panicked at 'command did not execute successfully: "/Users/tamird/src/rust/build/x86_64-apple-darwin/stage0/bin/cargo" "build" "--target" "x86_64-apple-darwin" "-j" "4" "-v" "--release" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/Users/tamird/src/rust/src/libstd/Cargo.toml" "--message-format" "json"
expected success, got: exit code: 101', src/bootstrap/compile.rs:883:8
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Traceback (most recent call last):
  File "./x.py", line 20, in <module>
    bootstrap.main()
  File "/Users/tamird/src/rust/src/bootstrap/bootstrap.py", line 756, in main
    bootstrap()
  File "/Users/tamird/src/rust/src/bootstrap/bootstrap.py", line 747, in bootstrap
    run(args, env=env, verbose=build.verbose)
  File "/Users/tamird/src/rust/src/bootstrap/bootstrap.py", line 148, in run
    raise RuntimeError(err)
RuntimeError: failed to run: /Users/tamird/src/rust/build/bootstrap/debug/bootstrap --incremental --stage 0 build src/libcore --verbose

@rust-highfive
Copy link
Contributor

r? @dtolnay

(rust_highfive has picked a reviewer for you, use r? to override)

@kennytm
Copy link
Member

kennytm commented Oct 7, 2017

bitflags depends on the core crate. I don't think you can make core depends on the current bitflags (circular dependency).

// Re-export libcore using an alias so that the macros can work without
// requiring `extern crate core` downstream.
#[doc(hidden)]
pub extern crate core as _core;

https://github.com/rust-lang-nursery/bitflags/blob/29e60b23708123121a540fa9bde3254260952511/src/lib.rs#L228-L231

@tamird
Copy link
Contributor Author

tamird commented Oct 7, 2017

@kennytm understood, but why is bitflags being compiled with stage 0's libcore rather than the bootstrap compiler's?

@alexcrichton
Copy link
Member

Yes libcore cannot have any dependencies, so we won't be able to do this.

@tamird
Copy link
Contributor Author

tamird commented Oct 7, 2017

Can you help me understand why? I think it'd be worthwhile to document.

@alexcrichton
Copy link
Member

Sorry I don't really have the time to explain it right now, but you can certainly try to fix up all the errors and see what happens. The gymnastics required will basically make it not worth it.

@carols10cents carols10cents added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 9, 2017
@shepmaster
Copy link
Member

@tamird from the sound of it, it sounds like this PR should be closed as "impossible by design" — do you have any further plans for it?

@arielb1
Copy link
Contributor

arielb1 commented Oct 15, 2017

@tamird

I think the reason @alexcrichton wanted to talk about is that you need a single libcore, because it defines a number of core traits, which the compiler requires in order to perform type-checking. However, the bitflags crate is macro-only, and therefore doesn't actually require any type-checking to be done, so that's not the reason it could not be marked as #![no_core]

However, bitflags does currently depend on core:
https://github.com/rust-lang-nursery/bitflags/blob/862582d107bb74ce4c7b505b2490eb815bc3a8c2/src/lib.rs#L231

which is used in e.g.
https://github.com/rust-lang-nursery/bitflags/blob/862582d107bb74ce4c7b505b2490eb815bc3a8c2/src/lib.rs#L365

However, if you really wanted to, you could change the __impl_bitflags macro to take core as an extra path parameter, which the default bitflags macro would assign $crate::_core while a custom bitflags_custom_core macro where you could pass a custom path for your libcore.

@tamird
Copy link
Contributor Author

tamird commented Oct 17, 2017

Thanks, @arielb1. I'll update this PR when the necessary changes have been made upstream!

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

I filed bitflags/bitflags#130 to track this change on bitflags' side. Let's open another PR here when the implementation is no longer blocked on bitflags.

@dtolnay dtolnay closed this Oct 22, 2017
@tamird tamird deleted the fmt-bitflags branch November 18, 2017 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants