-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Add new unstable attribute: #[export_visibility = ...].
#151431
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
base: main
Are you sure you want to change the base?
Conversation
|
Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing |
|
r? @chenyukang rustbot has assigned @chenyukang. Use |
|
i had a quick look, mostly looks good, but i'd like to maybe @JonathanBrouwer take a look on this as well, i may overlooked something r? JonathanBrouwer |
|
Would like to take a look, will do so tomorrow :) |
|
☔ The latest upstream changes (presumably #151436) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
Some minor questions, looks good on a high level :)
| const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; | ||
| const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; | ||
| const ALLOWED_TARGETS: AllowedTargets = | ||
| AllowedTargets::AllowListWarnRest(&[Allow(Target::Fn), Allow(Target::Static)]); |
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 reason you choose WarnRest here?
I'd prefer for new attributes to default to AllowedTargets::AllowList.
| return None; | ||
| }; | ||
| let Ok(visibility) = ExportVisibilityAttrValue::from_str(sv.as_str()) else { | ||
| cx.emit_err(InvalidExportVisibility { |
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.
Could this use cx.expected_specific_argument_strings instead?
(not sure)
| export_visibility_span, | ||
| "#[export_visibility = ...]` will be ignored without \ | ||
| `export_name`, `no_mangle`, or similar attribute", | ||
| ); |
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.
Can we make these struct errors?
In my opinion these are still nicer for simple errors like this. If you strongly disagree feel free to keep them like this
| fn from_str(s: &str) -> Result<ExportVisibilityAttrValue, Self::Err> { | ||
| match s { | ||
| "target_default" => Ok(ExportVisibilityAttrValue::TargetDefault), | ||
| _ => Err(format!("'{s}' is not a valid value for #[export_visibility = ...]",)), |
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 this string used anywhere? If not, could we make the Err type ()?
| EiiImpls(..) => No, | ||
| ExportName { .. } => Yes, | ||
| ExportStable => No, | ||
| ExportVisibility { .. } => Yes, |
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 exporting this attribute needed? (Not sure, genuine question)
|
Reminder, once the PR becomes ready for a review, use |
This PR is an implementation of the RFC tracked in #151425