compiler: Check safety requirements through safe resolver helpers
997083ce12087526d1dec3fa506a8a2c26da342723133e8fa6cf6536a2a88cec
1 parent
318bd58c
lib/std/lang/resolver.rad
+4 -4
| 3541 | 3541 | } |
|
| 3542 | 3542 | } |
|
| 3543 | 3543 | } |
|
| 3544 | 3544 | ||
| 3545 | 3545 | /// Require an unsafe function or block. |
|
| 3546 | - | unsafe fn requireUnsafe 'arena (self: &mut Resolver 'arena, node: *ast::Node) throws (ResolveError) { |
|
| 3546 | + | fn requireUnsafe 'arena (self: &mut Resolver 'arena, node: *ast::Node) throws (ResolveError) { |
|
| 3547 | 3547 | if not self.inUnsafeContext { |
|
| 3548 | 3548 | throw emitError(self, node, ErrorKind::UnsafeOperation); |
|
| 3549 | 3549 | } |
|
| 3550 | 3550 | } |
|
| 3551 | 3551 | ||
| 3552 | 3552 | /// Require an unsafe context for any access to an unsafe static. |
|
| 3553 | - | unsafe fn checkStaticAccess 'arena (self: &mut Resolver 'arena, node: *ast::Node, sym: &Symbol) |
|
| 3553 | + | fn checkStaticAccess 'arena (self: &mut Resolver 'arena, node: *ast::Node, sym: &Symbol) |
|
| 3554 | 3554 | throws (ResolveError) |
|
| 3555 | 3555 | { |
|
| 3556 | 3556 | if let case ast::NodeValue::StaticDecl(_) = sym.node.value { |
|
| 3557 | 3557 | if ast::hasAttribute(sym.attrs, ast::Attribute::Unsafe) { |
|
| 3558 | 3558 | try requireUnsafe(self, node); |
|
| 3559 | 3559 | } |
|
| 3560 | 3560 | } |
|
| 3561 | 3561 | } |
|
| 3562 | 3562 | ||
| 3563 | 3563 | /// Reject calls from safe code through unsafe function types. |
|
| 3564 | - | unsafe fn checkUnsafeCall 'arena (self: &mut Resolver 'arena, node: *ast::Node, info: *FnType) |
|
| 3564 | + | fn checkUnsafeCall 'arena (self: &mut Resolver 'arena, node: *ast::Node, info: *FnType) |
|
| 3565 | 3565 | throws (ResolveError) |
|
| 3566 | 3566 | { |
|
| 3567 | 3567 | if info.isUnsafe and not self.inUnsafeContext { |
|
| 3568 | 3568 | throw emitError(self, node, ErrorKind::UnsafeCall); |
|
| 3569 | 3569 | } |
| 3889 | 3889 | } |
|
| 3890 | 3890 | return mask; |
|
| 3891 | 3891 | } |
|
| 3892 | 3892 | ||
| 3893 | 3893 | /// Ensure the `default` attribute is only applied to functions. |
|
| 3894 | - | unsafe fn ensureDefaultAttrNotAllowed 'arena (self: &mut Resolver 'arena, node: *ast::Node, attrs: u32) |
|
| 3894 | + | fn ensureDefaultAttrNotAllowed 'arena (self: &mut Resolver 'arena, node: *ast::Node, attrs: u32) |
|
| 3895 | 3895 | throws (ResolveError) |
|
| 3896 | 3896 | { |
|
| 3897 | 3897 | let defaultBit = ast::Attribute::Default as u32; |
|
| 3898 | 3898 | if (attrs & defaultBit) <> 0 { |
|
| 3899 | 3899 | throw emitError(self, node, ErrorKind::DefaultAttrOnlyOnFn); |