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

unsafe: check uses of static variables #1417

Merged
merged 3 commits into from
Jul 27, 2022

Conversation

CohenArthur
Copy link
Member

Addresses #1411

Accessing an extern static or a mut static is unsafe and requires an unsafe function or block

This allows us to perform checks and dispatch when getting an HIR::Item*
from Mappings::lookup_hir_item()
Using a mutable static or an extern static requires an unsafe function
or block
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

Nice work. LGTM

Something we might start to think about doing is for every error diagnostic have some kind of class for them all, so we can enforce good error messages so for example we might have:

class ErrorDiagnostics {
static void EStaticMutableUnsafe(Location) { }
}

NodeId ref_node_id;
HirId definition_id;

if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
Copy link
Member

Choose a reason for hiding this comment

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

This is good, ideally this pass should be permissive of saw_errors eventually but we need to have the safe interface for the type context to return error nodes instead of nullptr to do that properly.

@CohenArthur
Copy link
Member Author

Nice work. LGTM

Something we might start to think about doing is for every error diagnostic have some kind of class for them all, so we can enforce good error messages so for example we might have:

class ErrorDiagnostics { static void EStaticMutableUnsafe(Location) { } }

Yeah, this will definitely come in handy when adding error codes as well! I'll open up an issue regarding this

@CohenArthur
Copy link
Member Author

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 27, 2022

Build succeeded:

@bors bors bot merged commit 2050960 into Rust-GCC:master Jul 27, 2022
@CohenArthur CohenArthur deleted the unsafe-check-static-uses branch July 28, 2022 07:00
@CohenArthur CohenArthur mentioned this pull request Jul 29, 2022
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants