forked from CreepySkeleton/proc-macro-error
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add a cargo feature to automatically detect usage of a nightly compiler. #5
Open
Alextopher
wants to merge
2
commits into
GnomedDev:master
Choose a base branch
from
Alextopher:detect-nightly
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+31
−5
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#[cfg(all(feature = "detect-nightly", not(feature = "nightly")))] | ||
pub fn main() { | ||
let rustc = std::env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string()); | ||
|
||
let rustc_version = std::process::Command::new(rustc) | ||
.arg("--version") | ||
.output() | ||
.map(|c| c.stdout) | ||
.unwrap_or_default(); | ||
|
||
let rustc_version = String::from_utf8(rustc_version).unwrap_or_default(); | ||
if rustc_version.contains("nightly") { | ||
println!("cargo:rustc-cfg=detected_nightly"); | ||
} | ||
} | ||
|
||
#[cfg(not(feature = "detect-nightly"))] | ||
pub fn main() { | ||
// do nothing if the 'detect-nightly' feature is not enabled | ||
} |
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
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.
Is there a good reason not to simplify things by getting rid of both these feature flags and always using the build script?
There is a reason: to ensure compatibility with future nightly
rustc
using an incompatible reporting interface. This seems a moot point since (a) a fix can likely be published quickly as a patch release (no one supports old nightlies thus there will not be any supported working configuration to break), (b)stable
will still work and (c) it shouldn't be that hard to work around using[patch.crates-io.proc-macro-error-2]
.Otherwise...
nightly
feature needs to be forwarded from whatever proc-macro lib uses this crate, and that lib needs to tell its users to add their own feature forwardingnightly
and to use this when developing, as well as to add a CI test which uses this feature and denies warnings. This path is theoretically workable but has a lot of overhead.detect-nightly
feature needs to be forwarded from whatever proc-macro lib uses this crate, and that lib needs to tell its users to enable it (either permanently or with their own feature flag used in testing as above). Since even the crate using the proc-macro crate which uses this crate is probably itself a library, it still is likely in the same situation as this crate about what it may assume.detect-nightly
since this crate doesn't.Further, the crate docs still seem to imply that warnings happen on nightly automatically.
My take: both these feature flags should be removed and detection should be automatic.
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.
That's because this crate is forked from
proc-macro-error
which had build scripts for nightly detection. The authors of this crate removed the scripts on the path tosyn2
.I think the authors of this repo should list out their goals with the project. Namely where does compatibility with pme1 stack up to our own thoughts on build systems?
proc-macro-error
used a build script and we're only here because folks are still using 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.
I agree.
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.
I'm here because (1) this was an easy transition and (2) the alternatives did not support reporting-as-a-side-effect (
emit_*!
).So, yes. And I'm not so happy to see that warnings are no longer being reported (without extra set up on my end that I didn't know I had to do).
The best option would be rustc stabilising rust-lang/rust#54140 or equivalent. The next best option is something like
proc-macro-error
.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.
Also on this topic: SergioBenitez/version_check#23
Clearly some people have good reasons for not wanting any automatic opt-in to nightly features. This goes as far as affecting development of the compiler, since it complicates testing whether a nightly compiler has regressions over stable. To me this is a good argument not to automatically opt in to nightly features.