Skip to content

Commit c72a979

Browse files
committed
move unsafety checking to MIR
No functional changes intended.
1 parent 8c7500f commit c72a979

24 files changed

+662
-388
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ define_dep_nodes!( <'tcx>
445445
[] BorrowCheckKrate,
446446
[] BorrowCheck(DefId),
447447
[] MirBorrowCheck(DefId),
448+
[] UnsafetyViolations(DefId),
448449

449450
[] RvalueCheck(DefId),
450451
[] Reachability,

src/librustc/diagnostics.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -479,40 +479,6 @@ fn main() {
479479
```
480480
"##,
481481

482-
E0133: r##"
483-
Unsafe code was used outside of an unsafe function or block.
484-
485-
Erroneous code example:
486-
487-
```compile_fail,E0133
488-
unsafe fn f() { return; } // This is the unsafe code
489-
490-
fn main() {
491-
f(); // error: call to unsafe function requires unsafe function or block
492-
}
493-
```
494-
495-
Using unsafe functionality is potentially dangerous and disallowed by safety
496-
checks. Examples:
497-
498-
* Dereferencing raw pointers
499-
* Calling functions via FFI
500-
* Calling functions marked unsafe
501-
502-
These safety checks can be relaxed for a section of the code by wrapping the
503-
unsafe instructions with an `unsafe` block. For instance:
504-
505-
```
506-
unsafe fn f() { return; }
507-
508-
fn main() {
509-
unsafe { f(); } // ok!
510-
}
511-
```
512-
513-
See also https://doc.rust-lang.org/book/first-edition/unsafe.html
514-
"##,
515-
516482
// This shouldn't really ever trigger since the repeated value error comes first
517483
E0136: r##"
518484
A binary can only have one entry point, and by default that entry point is the

src/librustc/ich/impls_mir.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> {
3333
});
3434
impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, by_ref });
3535
impl_stable_hash_for!(struct mir::BasicBlockData<'tcx> { statements, terminator, is_cleanup });
36+
impl_stable_hash_for!(struct mir::UnsafetyViolation { source_info, description, lint_node_id });
3637

3738
impl<'gcx> HashStable<StableHashingContext<'gcx>>
3839
for mir::Terminator<'gcx> {
@@ -364,7 +365,26 @@ for mir::ProjectionElem<'gcx, V, T>
364365
}
365366

366367
impl_stable_hash_for!(struct mir::VisibilityScopeData { span, parent_scope });
367-
impl_stable_hash_for!(struct mir::VisibilityScopeInfo { lint_root });
368+
impl_stable_hash_for!(struct mir::VisibilityScopeInfo {
369+
lint_root, safety
370+
});
371+
372+
impl<'gcx> HashStable<StableHashingContext<'gcx>> for mir::Safety {
373+
fn hash_stable<W: StableHasherResult>(&self,
374+
hcx: &mut StableHashingContext<'gcx>,
375+
hasher: &mut StableHasher<W>) {
376+
mem::discriminant(self).hash_stable(hcx, hasher);
377+
378+
match *self {
379+
mir::Safety::Safe |
380+
mir::Safety::BuiltinUnsafe |
381+
mir::Safety::FnUnsafe => {}
382+
mir::Safety::ExplicitUnsafe(node_id) => {
383+
node_id.hash_stable(hcx, hasher);
384+
}
385+
}
386+
}
387+
}
368388

369389
impl<'gcx> HashStable<StableHashingContext<'gcx>> for mir::Operand<'gcx> {
370390
fn hash_stable<W: StableHasherResult>(&self,

src/librustc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ pub mod middle {
111111
pub mod dataflow;
112112
pub mod dead;
113113
pub mod dependency_format;
114-
pub mod effect;
115114
pub mod entry;
116115
pub mod exported_symbols;
117116
pub mod free_region;

0 commit comments

Comments
 (0)