Skip to content

Commit 7a9cdc4

Browse files
committed
Auto merge of #44700 - arielb1:mir-effectck, r=nikomatsakis
Move effect-checking to MIR This allows emitting lints from MIR and moves the effect-checking pass to work on it. I'll make `repr(packed)` misuse unsafe in a separate PR. r? @eddyb
2 parents 48c1c54 + 516534f commit 7a9cdc4

37 files changed

+908
-432
lines changed

src/librustc/dep_graph/dep_node.rs

+1
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

-34
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

+38
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ impl_stable_hash_for!(struct mir::LocalDecl<'tcx> {
2828
name,
2929
source_info,
3030
internal,
31+
lexical_scope,
3132
is_user_variable
3233
});
3334
impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, by_ref });
3435
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 });
3537

3638
impl<'gcx> HashStable<StableHashingContext<'gcx>>
3739
for mir::Terminator<'gcx> {
@@ -75,6 +77,22 @@ for mir::Terminator<'gcx> {
7577
}
7678
}
7779

80+
impl<'gcx, T> HashStable<StableHashingContext<'gcx>> for mir::ClearOnDecode<T>
81+
where T: HashStable<StableHashingContext<'gcx>>
82+
{
83+
#[inline]
84+
fn hash_stable<W: StableHasherResult>(&self,
85+
hcx: &mut StableHashingContext<'gcx>,
86+
hasher: &mut StableHasher<W>) {
87+
mem::discriminant(self).hash_stable(hcx, hasher);
88+
match *self {
89+
mir::ClearOnDecode::Clear => {}
90+
mir::ClearOnDecode::Set(ref value) => {
91+
value.hash_stable(hcx, hasher);
92+
}
93+
}
94+
}
95+
}
7896

7997
impl<'gcx> HashStable<StableHashingContext<'gcx>> for mir::Local {
8098
#[inline]
@@ -347,6 +365,26 @@ for mir::ProjectionElem<'gcx, V, T>
347365
}
348366

349367
impl_stable_hash_for!(struct mir::VisibilityScopeData { span, parent_scope });
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+
}
350388

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

src/librustc/lib.rs

-1
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;

src/librustc/lint/levels.rs

+5
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ impl LintLevelMap {
384384
self.sets.get_lint_level(lint, *idx, None)
385385
})
386386
}
387+
388+
/// Returns if this `id` has lint level information.
389+
pub fn lint_level_set(&self, id: HirId) -> Option<u32> {
390+
self.id_to_set.get(&id).cloned()
391+
}
387392
}
388393

389394
impl<'gcx> HashStable<StableHashingContext<'gcx>> for LintLevelMap {

0 commit comments

Comments
 (0)