|
2 | 2 |
|
3 | 3 | use crate::mir::{Body, Promoted}; |
4 | 4 | use crate::ty::{self, Ty, TyCtxt}; |
5 | | -use rustc_data_structures::sync::Lrc; |
| 5 | +use rustc_data_structures::stable_map::FxHashMap; |
6 | 6 | use rustc_data_structures::vec_map::VecMap; |
7 | 7 | use rustc_errors::ErrorReported; |
8 | 8 | use rustc_hir as hir; |
@@ -114,13 +114,32 @@ pub struct UnsafetyViolation { |
114 | 114 | pub details: UnsafetyViolationDetails, |
115 | 115 | } |
116 | 116 |
|
117 | | -#[derive(Clone, TyEncodable, TyDecodable, HashStable, Debug)] |
| 117 | +#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable, Debug)] |
| 118 | +pub enum UnusedUnsafe { |
| 119 | + /// `unsafe` block contains no unsafe operations |
| 120 | + // > ``unnecessary `unsafe` block`` |
| 121 | + Unused, |
| 122 | + // `unsafe` block nested under another (used) `unsafe` block |
| 123 | + // ``… because it's nested under this `unsafe` block`` |
| 124 | + InUnsafeBlock(hir::HirId), |
| 125 | + // `unsafe` block nested under `unsafe` fn |
| 126 | + // ``… because it's nested under this `unsafe` fn`` |
| 127 | + InUnsafeFn(hir::HirId), |
| 128 | +} |
| 129 | + |
| 130 | +#[derive(TyEncodable, TyDecodable, HashStable, Debug)] |
118 | 131 | pub struct UnsafetyCheckResult { |
119 | 132 | /// Violations that are propagated *upwards* from this function. |
120 | | - pub violations: Lrc<[UnsafetyViolation]>, |
121 | | - /// `unsafe` blocks in this function, along with whether they are used. This is |
122 | | - /// used for the "unused_unsafe" lint. |
123 | | - pub unsafe_blocks: Lrc<[(hir::HirId, bool)]>, |
| 133 | + pub violations: Vec<UnsafetyViolation>, |
| 134 | + |
| 135 | + /// Used `unsafe` blocks in this function. This is used for the "unused_unsafe" lint. |
| 136 | + /// |
| 137 | + /// The keys are the used `unsafe` blocks, the boolean flag indicates whether |
| 138 | + /// or not any of the usages happen at a place that doesn't allow `unsafe_op_in_unsafe_fn`. |
| 139 | + pub used_unsafe_blocks: FxHashMap<hir::HirId, bool>, |
| 140 | + |
| 141 | + /// This is `Some` iff the item is not a closure. |
| 142 | + pub unused_unsafe: Option<Vec<(hir::HirId, UnusedUnsafe)>>, |
124 | 143 | } |
125 | 144 |
|
126 | 145 | rustc_index::newtype_index! { |
|
0 commit comments