Skip to content

Implemented 'unstable options' command line option #1998

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

Merged
merged 1 commit into from
Oct 29, 2017

Conversation

tmahmood
Copy link

@tmahmood tmahmood commented Sep 26, 2017

Hello,

This is my first contribution to any open source project, so any advice would be awesome and thank you for being nice :)

  • add the flag itself
  • ensure the flag can be set programmatically when rustfmt is used as a library
  • decide what should be unstable (this can be ongoing, but needs to be done by the time we use Rustup)
  • for each unstable feature, ensure that you need the --unstable-features flag. This includes any unstable configuration options (we would need some mechanism for marking options as stable or unstable)
  • only allow the flag to be set if we are run with nightly *
    I am checking CFG_RELEASE_CHANNEL environment option to see if we are running on nightly version, I am not confident about this solution. There's must be a better way that I've missed.

All the tests are passing, I've added 2 tests to verify if my changes are working, which are also passing.

Thank you

@tmahmood tmahmood changed the title Implemented add 'unstable options' command line option Implemented 'unstable options' command line option Sep 26, 2017
@nrc
Copy link
Member

nrc commented Sep 29, 2017

Great, thank you for the PR! Sorry it took me a while to get to it, I'm mostly on parental leave right now and only checking notifications intermittently.

@nrc
Copy link
Member

nrc commented Sep 29, 2017

It would be good if you could squash your commits (I find git rebase -i the easiest way to do this), thanks!

@@ -122,6 +122,12 @@ fn make_opts() -> Options {

opts.optflag(
"",
"unstable-features",
"Enables unstable features. Only available in rust nightlies",
Copy link
Member

Choose a reason for hiding this comment

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

nit: could you change the text here to end with Only available on the nightly channel please

src/config.rs Outdated
#[derive(Clone)]
pub struct Config {
// are we using unstable features or not
unstable_features: bool,
Copy link
Member

Choose a reason for hiding this comment

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

Could we use a macro generated option for this like the other options? I think that would simplify things a bit

src/config.rs Outdated
}
)+
}

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to be able to set whether each option is stable or unstable, so I don't think we need these getter/setters. A client only needs to be able to set the unstable-features flag itself, which I think it can do with the existing setters.

Copy link
Author

@tmahmood tmahmood Sep 30, 2017

Choose a reason for hiding this comment

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

I implemented this setter/getter, considering this

(we would need some mechanism for marking options as stable or unstable)"

Copy link
Member

Choose a reason for hiding this comment

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

That is covered where you added a flag to each option for whether it is stable or unstable.

@tmahmood
Copy link
Author

Hello, Sorry about the delayed reply, I was out of town, I've gone through your review and updating my changes accordingly.

@tmahmood
Copy link
Author

tmahmood commented Oct 1, 2017

Sorry, about the extra commits again.

@nrc
Copy link
Member

nrc commented Oct 5, 2017

Most of the changes look good, thanks, but you've removed the 'stable-ness' bool for each option, which I think was a good idea, sorry for the miscommunication there. We should also check when an option is set that if it is unstable, then the unstable features option is set.

@tmahmood tmahmood force-pushed the master branch 2 times, most recently from b001937 to 7bcd6dd Compare October 8, 2017 14:53
@tmahmood
Copy link
Author

tmahmood commented Oct 8, 2017

No problems, I can understand the awesome feelings and the sleepless nights your going through as a parent :)

I think I got most of it correctly this time.

src/config.rs Outdated
@@ -254,7 +263,15 @@ macro_rules! create_config {
impl<'a> ConfigSetter<'a> {
$(
pub fn $i(&mut self, value: $ty) {
(self.0).$i.2 = value;
// we check if we are using nightly channel
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to check for nightly channel here - if a program is usinf Rustfmt as a library, then it is up to them to enforce the instability invariants.

Copy link
Member

Choose a reason for hiding this comment

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

However, we should check this when we parse unstable_options from the toml file (there might be macro hygiene problems with this though).

Copy link
Author

Choose a reason for hiding this comment

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

Haven't faced any problems with macro hygiene hopefully I've understood you correctly and is on the right track.

@nrc
Copy link
Member

nrc commented Oct 26, 2017

@tmahmood hi, sorry it's taken so long to get back to this. I'm back at work now and should be much quicker to respond. The changes to the unstable features flag looks good. However, it looks like you've pulled in some other commits here (changes to Cargo.*, some other changes to config.rs, etc.). I expect this was a rebasing issue. You can probably use git reflog to get back to a state before the rebase. If you need some help with rebasing or other Git stuff, let me know.

@tmahmood tmahmood force-pushed the master branch 4 times, most recently from b3030a2 to acdf1bb Compare October 28, 2017 03:29
@tmahmood
Copy link
Author

Good to hear from you.
I've fixed commit issues. Thank you for the help

@nrc
Copy link
Member

nrc commented Oct 29, 2017

Awesome, thanks!

@nrc nrc merged commit cf0d494 into rust-lang:master Oct 29, 2017
@nrc
Copy link
Member

nrc commented Oct 29, 2017

@tmahmood if you'd like more rustfmt stuff to work on, then a good follow-up would be to extend the unstable-features flag so that it can apply to command line options and write modes. Each option and write mode could be marked stable or unstable and if unstable, then can only be used if the unstable features flag is set.

@tmahmood
Copy link
Author

tmahmood commented Oct 30, 2017

Awesome! I would love to continue working. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants