Skip to content
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

fix: don't report visibility errors when elaborating comptime value #6498

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

asterite
Copy link
Collaborator

Description

Problem

Resolves #6485

Summary

Additional Context

Documentation

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@asterite asterite requested a review from a team November 11, 2024 14:58
@@ -493,3 +493,28 @@ fn does_not_error_if_referring_to_top_level_private_module_via_crate() {
"#;
assert_no_errors(src);
}

#[test]
fn visibility_bug_inside_comptime() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please test that running a function that accesses a private struct member from a comptime context still fails, e.g.

    mod foo {
        pub struct Foo {
            inner: Field,
        }
    }
    
    use foo::Foo;
    
    fn main() {
        let _ = comptime { Foo { inner: 5 } };
    }
  1. Deriving a function that references a private member from comptime, e.g. fn bar(inner: Field) -> Foo { Foo { inner } }, fails with "inner not in scope" when run outside mod foo.

@@ -509,6 +509,10 @@ impl<'context> Elaborator<'context> {
visibility: ItemVisibility,
span: Span,
) {
if self.silence_field_visibility_errors > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could other types of visibility, e.g. for traits, cause similar issues? If so, could you make a follow up issue for them?

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.

Incorrect visibility requirements on comptime functions
2 participants