Skip to content

Conversation

@anforowicz
Copy link
Contributor

This PR is an implementation of the RFC tracked in #151425

@rustbot
Copy link
Collaborator

rustbot commented Jan 20, 2026

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

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 20, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 20, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 20, 2026

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Kivooeo
Copy link
Member

Kivooeo commented Jan 20, 2026

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

@JonathanBrouwer
Copy link
Contributor

Would like to take a look, will do so tomorrow :)

@rust-bors

This comment has been minimized.

Copy link
Contributor

@JonathanBrouwer JonathanBrouwer left a 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 :)

View changes since this review

return None;
};
let Ok(visibility) = ExportVisibilityAttrValue::from_str(sv.as_str()) else {
cx.emit_err(InvalidExportVisibility {
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am also not sure. Right now the new attribute expects a string literal as an argument (e.g. #[export_visibility = "target_default"] - this is the syntax that has been used so far by the RFC) . And it seems that expected_specific_argument_strings is meant to be used with symbols rather than with string literals (e.g. #[export_visibility = target_default]). Do you think the new attribute should use the latter syntax?

export_visibility_span,
"#[export_visibility = ...]` will be ignored without \
`export_name`, `no_mangle`, or similar attribute",
);
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please help me understand what you mean by "struct errors"? Can you point at a piece of code that I should mimic?

Are you asking me to hoist the error string into impl DiagMessage for NewStructForThisParticularError?

EiiImpls(..) => No,
ExportName { .. } => Yes,
ExportStable => No,
ExportVisibility { .. } => Yes,
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am also not sure. I think if #[export_name = ...] needs to be exported, then so does #[export_visibility = ...] although I can't really convincingly point to a specific scenario where this is needed.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 21, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 21, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Comment on lines +26 to +32
// Exact LLVM IR differs depending on the target triple (e.g. `hidden constant`
// vs `internal constant` vs `constant`). Because of this, we only apply the
// specific test expectations below to one specific target triple. If needed,
// additional targets can be covered by adding copies of this test file with
// a different `only-X` directive.
//
//@ only-x86_64-unknown-linux-gnu
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to use add-minicore here so it gets checked on all targets:

//@ add-minicore
//@ compile-flags: --target x86_64-unknown-linux-gnu

#![feature(no_core)]
#![no_core]

Possibly also roll this into the revisions so different targets wouldn't need different files.

//@ revisions: LINUX-X86-HIDDEN LINUX-X86-PROTECTED
//@ [LINUX-X86-HIDDEN,LINUX-X86-PROTECTED] compile-flags: --target x86_64-unknown-linux-gnu
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding //@ add-minicore + #![feature(no_core)] + #![no_core] results in build errors of the test code:

error: cannot find macro `line` in this scope
  --> /usr/local/google/home/lukasza/src/github/rust/tests/codegen-llvm/export-visibility.rs:82:5
   |
82 |     line!()
   |     ^^^^

And also another error that I don't quite understand:

error: requires `sized` lang_item
  --> /usr/local/google/home/lukasza/src/github/rust/tests/codegen-llvm/export-visibility.rs:43:1
   |
43 | pub static TEST_STATIC_NO_ATTR: [u8; 7] = *b"static1";
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I think I'd rather avoid multiplying test expectations and revisions by multiple target platforms. I think focusing on x86_64 in this test is ok. FWIW I tried explaining this in the comment in the new test file:

// Exact LLVM IR differs depending on the target triple (e.g. `hidden constant`  
// vs `internal constant` vs `constant`).  Because of this, we only apply the
// specific test expectations below to one specific target triple.  If needed,
// additional targets can be covered by adding copies of this test file with
// a different `only-X` directive.
//
//@     only-x86_64-unknown-linux-gnu

For now maybe I can leave things as-is here, but also try to add make-based, end-to-end tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding //@ add-minicore + #![feature(no_core)] + #![no_core] results in build errors of the test code:

error: cannot find macro `line` in this scope
  --> /usr/local/google/home/lukasza/src/github/rust/tests/codegen-llvm/export-visibility.rs:82:5
   |
82 |     line!()
   |     ^^^^

Could it just return a different int rather than line!()?

And also another error that I don't quite understand:

error: requires `sized` lang_item
  --> /usr/local/google/home/lukasza/src/github/rust/tests/codegen-llvm/export-visibility.rs:43:1
   |
43 | pub static TEST_STATIC_NO_ATTR: [u8; 7] = *b"static1";
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Huh, this definitely happened with //@ add-minicore? Minicore should pull it in

#[lang = "sized"]
#[diagnostic::on_unimplemented(
message = "the size for values of type `{Self}` cannot be known at compilation time",
label = "doesn't have a size known at compile-time"
)]
pub trait Sized: MetaSized {}
. If you push, I can take a look.

For reference https://github.com/rust-lang/rust/blob/d222ddc4d90743dfc1e53b610be8fc9d95893d2c/src/doc/rustc-dev-guide/src/tests/minicore.md

I think I'd rather avoid multiplying test expectations and revisions by multiple target platforms. I think focusing on x86_64 in this test is ok. FWIW I tried explaining this in the comment in the new test file:

I agree that testing only a x86-64 target is good. But only- restricts the host in addition to the target, so my suggestions were intended to drop it and use --target with minicore instead (just a convenience so anyone can run the tests easy, even if they're not on an x64 Linux machine).

Copy link
Contributor

Choose a reason for hiding this comment

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

Because of how complex and target-specific everything linker-related is, I think an end-to-end test in tests/run-make would be great to cover an ELF/PE/Mach-O target. Then you have access to the object crate via run_make_support for checking symbol visibility.

To allow each object file type to be built on all platforms with just --target, the test can use a minicore like

(unfortunately there is nothing convenient like what codegen tests have with //@ add-minicore).

@rustbot
Copy link
Collaborator

rustbot commented Jan 24, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants