Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
90d6fe2
Imply outlives-bounds on lazy type aliases
fmease Dec 27, 2023
3ab43e5
Allow emitting diagnostics from the `#[diagnostic]` namespace without a
weiznich Dec 21, 2023
cd9425b
Replace some usage of `#[rustc_on_unimplemented]` with
weiznich Dec 22, 2023
eabf4df
Add a test that emitting diagnostics does not require the crate to use
weiznich Dec 23, 2023
cc31adc
Fix a rustdoc test
weiznich Dec 29, 2023
fdd991f
Add support for shell argfiles
djkoloski Dec 6, 2023
505c137
Rename some `Diagnostic` setters.
nnethercote Dec 23, 2023
5fe5d5d
Remove lots of `rustc_errors::` qualifiers in `lints.rs`.
nnethercote Jan 2, 2024
096b844
Remove forward for `downgrade_to_delayed_bug`.
nnethercote Jan 3, 2024
caefa55
Fix up `forward!` decls.
nnethercote Jan 3, 2024
b4a6239
Fix `forward!` so it doesn't require trailing commas in some cases.
nnethercote Jan 3, 2024
1e92223
Remove unused `DiagnosticBuilder::struct_almost_fatal`.
nnethercote Jan 3, 2024
9560c58
Avoid some `rustc_errors::` qualifiers.
nnethercote Jan 4, 2024
4d35981
Remove unused `struct_error` function.
nnethercote Jan 4, 2024
8e6bca6
Inline and remove `StringReader::struct_fatal_span_char`.
nnethercote Jan 4, 2024
1d48f69
Check yield terminator's resume type in borrowck
compiler-errors Jan 4, 2024
8388112
Remove `is_lint` field from `Level::Error`.
nnethercote Jan 4, 2024
4bc3552
cstore: Remove unnecessary locking from `CrateMetadata`
petrochenkov Jan 4, 2024
12b92c8
Visit only reachable blocks in MIR lint
tmiasko Dec 30, 2023
a084e06
Fix validation and linting of injected MIR
tmiasko Jan 1, 2024
df116ec
Migrate memory overlap check from validator to lint
tmiasko Jan 4, 2024
c1096a9
Rollup merge of #118680 - djkoloski:shell_argfiles, r=compiler-errors
matthiaskrgr Jan 5, 2024
4a96e9f
Rollup merge of #119216 - weiznich:use_diagnostic_namespace_in_stdlib…
matthiaskrgr Jan 5, 2024
b87e4e9
Rollup merge of #119350 - fmease:lazy-ty-aliases-implied-bounds, r=co…
matthiaskrgr Jan 5, 2024
a12f1d8
Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-er…
matthiaskrgr Jan 5, 2024
16d90e7
Rollup merge of #119563 - compiler-errors:coroutine-resume, r=oli-obk
matthiaskrgr Jan 5, 2024
3974467
Rollup merge of #119577 - tmiasko:lint, r=oli-obk
matthiaskrgr Jan 5, 2024
6880711
Rollup merge of #119589 - petrochenkov:cdatalock, r=Mark-Simulacrum
matthiaskrgr Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Visit only reachable blocks in MIR lint
No functional changes - all checks have been emitted conditionally on
block being rechable already.
  • Loading branch information
tmiasko committed Jan 4, 2024
commit 12b92c8a87c041416dfec8cdd61c7f14c1cd9d2b
27 changes: 12 additions & 15 deletions compiler/rustc_mir_transform/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_mir_dataflow::{Analysis, ResultsCursor};
use std::borrow::Cow;

pub fn lint_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, when: String) {
let reachable_blocks = traversal::reachable_as_bitset(body);
let always_live_locals = &always_storage_live_locals(body);

let maybe_storage_live = MaybeStorageLive::new(Cow::Borrowed(always_live_locals))
Expand All @@ -24,17 +23,18 @@ pub fn lint_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, when: String) {
.iterate_to_fixpoint()
.into_results_cursor(body);

Lint {
let mut lint = Lint {
tcx,
when,
body,
is_fn_like: tcx.def_kind(body.source.def_id()).is_fn_like(),
always_live_locals,
reachable_blocks,
maybe_storage_live,
maybe_storage_dead,
};
for (bb, data) in traversal::reachable(body) {
lint.visit_basic_block_data(bb, data);
}
.visit_body(body);
}

struct Lint<'a, 'tcx> {
Expand All @@ -43,7 +43,6 @@ struct Lint<'a, 'tcx> {
body: &'a Body<'tcx>,
is_fn_like: bool,
always_live_locals: &'a BitSet<Local>,
reachable_blocks: BitSet<BasicBlock>,
maybe_storage_live: ResultsCursor<'a, 'tcx, MaybeStorageLive<'a>>,
maybe_storage_dead: ResultsCursor<'a, 'tcx, MaybeStorageDead<'a>>,
}
Expand All @@ -67,7 +66,7 @@ impl<'a, 'tcx> Lint<'a, 'tcx> {

impl<'a, 'tcx> Visitor<'tcx> for Lint<'a, 'tcx> {
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
if self.reachable_blocks.contains(location.block) && context.is_use() {
if context.is_use() {
self.maybe_storage_dead.seek_after_primary_effect(location);
if self.maybe_storage_dead.get().contains(local) {
self.fail(location, format!("use of local {local:?}, which has no storage here"));
Expand All @@ -78,14 +77,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Lint<'a, 'tcx> {
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
match statement.kind {
StatementKind::StorageLive(local) => {
if self.reachable_blocks.contains(location.block) {
self.maybe_storage_live.seek_before_primary_effect(location);
if self.maybe_storage_live.get().contains(local) {
self.fail(
location,
format!("StorageLive({local:?}) which already has storage here"),
);
}
self.maybe_storage_live.seek_before_primary_effect(location);
if self.maybe_storage_live.get().contains(local) {
self.fail(
location,
format!("StorageLive({local:?}) which already has storage here"),
);
}
}
_ => {}
Expand All @@ -97,7 +94,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Lint<'a, 'tcx> {
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
match terminator.kind {
TerminatorKind::Return => {
if self.is_fn_like && self.reachable_blocks.contains(location.block) {
if self.is_fn_like {
self.maybe_storage_live.seek_after_primary_effect(location);
for local in self.maybe_storage_live.get().iter() {
if !self.always_live_locals.contains(local) {
Expand Down