Skip to content

"error: module has missing stability attribute" is insufficiently explained #103668

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

Closed
jruderman opened this issue Oct 28, 2022 · 4 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-stability Area: `#[stable]`, `#[unstable]` etc. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-staged_api `#![feature(staged_api)]` P-low Low priority requires-internal-features This issue requires the use of internal features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

jruderman commented Oct 28, 2022

Given the following code (playground):

#![feature(slice_from_ptr_range)]
#![feature(slice_ptr_get)]
#![feature(staged_api)]
#![feature(stmt_expr_attributes)]
#![feature(strict_provenance)]

fn foo() {}
fn bar() {}

The current output points to the entire file and doesn't tell me what I did wrong:

error: module has missing stability attribute
 --> src/lib.rs:1:1
  |
1 | / #![feature(slice_from_ptr_range)]
2 | | #![feature(slice_ptr_get)]
3 | | #![feature(staged_api)]
4 | | #![feature(stmt_expr_attributes)]
... |
7 | | fn foo() {}
8 | | fn bar() {}
  | |___________^

If I understand the feature correctly, the output should be:

error: expected at least one pub item in this module to be marked as stable or unstable
note: expected because of `#![feature(staged_api)]` on line 3
@jruderman jruderman added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 28, 2022
@fmease
Copy link
Member

fmease commented Oct 28, 2022

If I understand the feature correctly, the output should be: error: expected at least one pub item in this module to be marked as stable or unstable

No, with module has missing stability attribute the compiler means the current module (in this case the root module, the crate root). E.g. if you add #![stable(feature = "…", since = "…")] below or above the other inner attributes, the error will go away.

How is this used? For example, libtest is unconditionally unstable, libstd is stable unless restricted_std is enabled.

Not sure how the current error message could be improved since it is correct and relatively clear already.

@jruderman
Copy link
Contributor Author

Well, it confused me! I had to binary-search to even figure out that #![feature(staged_api)] was the line triggering it.

@fmease
Copy link
Member

fmease commented Oct 28, 2022

Well, it confused me!

Can't argue against that. Admittedly, the massive span is a bit useless / misleading, even though it's technically correct.

I remember this used to be the same problem with E0601 (missing main function) which used to highlight the entire file. Nowadays, we shrink the span to an empty one in this case and add a label suggesting to add a function.

We could basically do the same for the staged_api case.

@rustbot claim

@estebank estebank added D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Nov 11, 2022
@fmease fmease added requires-internal-features This issue requires the use of internal features. A-stability Area: `#[stable]`, `#[unstable]` etc. labels Sep 6, 2023
@fmease fmease added the P-low Low priority label Mar 22, 2024
@fmease fmease added the F-staged_api `#![feature(staged_api)]` label Dec 14, 2024
@fmease fmease removed their assignment Apr 15, 2025
@fmease
Copy link
Member

fmease commented Apr 15, 2025

Any (uncaught) misuses of internal feature are considered to be the fault of the user and not a bug in rustc. I'm closing this as works as intended / not planned as per MCP 620.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-stability Area: `#[stable]`, `#[unstable]` etc. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-staged_api `#![feature(staged_api)]` P-low Low priority requires-internal-features This issue requires the use of internal features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants