-
Notifications
You must be signed in to change notification settings - Fork 14k
simplify check_cfg_arg impl #147570
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
simplify check_cfg_arg impl #147570
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -490,22 +490,13 @@ where | |
| }) | ||
| } | ||
|
|
||
| /// Create a `--check-cfg` argument invocation for a given name | ||
| /// and it's values. | ||
| pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String { | ||
| // Creating a string of the values by concatenating each value: | ||
| // ',values("tvos","watchos")' or '' (nothing) when there are no values. | ||
| let next = match values { | ||
| Some(values) => { | ||
| let mut tmp = values.iter().flat_map(|val| [",", "\"", val, "\""]).collect::<String>(); | ||
|
|
||
| tmp.insert_str(1, "values("); | ||
| tmp.push(')'); | ||
| tmp | ||
| } | ||
| None => "".to_string(), | ||
| }; | ||
| format!("--check-cfg=cfg({name}{next})") | ||
| /// Create a `--check-cfg` argument invocation for a given name and values. | ||
| pub fn check_cfg_arg(name: &str, values: &[&str]) -> String { | ||
| if values.is_empty() { | ||
| format!("--check-cfg=cfg({name})") | ||
| } else { | ||
| format!("--check-cfg=cfg({name},values(\"{}\"))", values.join("\",\"")) | ||
| } | ||
| } | ||
|
Comment on lines
+494
to
500
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not technically correct, having an empty But it doesn't really make sense for bootstrap to be defining such cfgs.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I read about this, but it seems really weird that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
cfgs are always a combination of name+value, if one doesn't pass any values the compiler doesn't know which values are expected. It's useful for cfgs whose values are variable (like Cargo
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought cfgs could also have no value, like
Right, so then perhaps it is good that the function now makes it impossible to define such cfgs? Or did I misunderstand you?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, of course cfgs can have "no value". I was talking about
Your proposed representation indeed makes it impossible to define a cfg in I other words I think |
||
|
|
||
| /// Prepares `BootstrapCommand` that runs git inside the source directory if given. | ||
|
|
||
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.
What do you think about having
&[Option<&str>]for representing the expected values? which would make thenone()part explicit.The generation part would then always be like that
cfg(name, values(...)).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 would allow
&[None, None, None]which seems silly...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.
It would indeed be silly to have multiple
None, but it's better than not having anyNone(to representnone()).