diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-04-16 23:34:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-16 23:34:42 +0200 |
| commit | aa0db0bb431b4172c58bdfdf9b748e0933e5bf06 (patch) | |
| tree | 173a2da77478e741e486c6fe4f9fd92f2b575282 /src | |
| parent | c68c71e24e098d617fd1bbb82b6120d03ff3e252 (diff) | |
| parent | 66575c9962188aa2f16df04fa1fef1786f0d216f (diff) | |
| download | rust-aa0db0bb431b4172c58bdfdf9b748e0933e5bf06.tar.gz rust-aa0db0bb431b4172c58bdfdf9b748e0933e5bf06.zip | |
Rollup merge of #71197 - ljedrz:unsafe_unused, r=ecstatic-morse
Don't use the HirId to NodeId map in MIR Another step towards not having to build a `HirId` to `NodeId` map other than for doc and RLS purposes. We are currently sorting `unsafe` blocks by `NodeId` in `check_unsafety`; change it to sorting by `Span` instead; this passes the tests, but better ideas are welcome. In addition, simplify the split between the used and unused `unsafe` blocks for readability and less sorting. cc https://github.com/rust-lang/rust/issues/50928
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/transform/check_unsafety.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 3ce9b875e16..9f6b1963ce7 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -641,13 +641,19 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { } } - let mut unsafe_blocks: Vec<_> = unsafe_blocks.iter().collect(); - unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_id_to_node_id(*hir_id)); - let used_unsafe: FxHashSet<_> = - unsafe_blocks.iter().flat_map(|&&(id, used)| used.then_some(id)).collect(); - for &(block_id, is_used) in unsafe_blocks { - if !is_used { - report_unused_unsafe(tcx, &used_unsafe, block_id); + let (mut unsafe_used, mut unsafe_unused): (FxHashSet<_>, Vec<_>) = Default::default(); + for &(block_id, is_used) in unsafe_blocks.iter() { + if is_used { + unsafe_used.insert(block_id); + } else { + unsafe_unused.push(block_id); } } + // The unused unsafe blocks might not be in source order; sort them so that the unused unsafe + // error messages are properly aligned and the issue-45107 and lint-unused-unsafe tests pass. + unsafe_unused.sort_by_cached_key(|hir_id| tcx.hir().span(*hir_id)); + + for &block_id in &unsafe_unused { + report_unused_unsafe(tcx, &unsafe_used, block_id); + } } |
