mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-04 02:54:00 +00:00
Adjust computation of place types to detect more invalid places
This commit is contained in:
parent
dae5c842fc
commit
2f4a7a0742
@ -3,8 +3,8 @@
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_middle::mir::interpret::Scalar;
|
||||
use rustc_middle::mir::traversal;
|
||||
use rustc_middle::mir::visit::{PlaceContext, Visitor};
|
||||
use rustc_middle::mir::{traversal, Place};
|
||||
use rustc_middle::mir::{
|
||||
AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPass, MirPhase, Operand,
|
||||
PlaceElem, PlaceRef, ProjectionElem, Rvalue, SourceScope, Statement, StatementKind, Terminator,
|
||||
@ -240,6 +240,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
||||
self.super_projection_elem(local, proj_base, elem, context, location);
|
||||
}
|
||||
|
||||
fn visit_place(&mut self, place: &Place<'tcx>, _: PlaceContext, location: Location) {
|
||||
// Set off any `bug!`s in the type computation code
|
||||
let ty = place.ty(&self.body.local_decls, self.tcx);
|
||||
if ty.variant_index.is_some() {
|
||||
self.fail(location, "Top level places may not have their variant index set!");
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
|
||||
match &statement.kind {
|
||||
StatementKind::Assign(box (dest, rvalue)) => {
|
||||
|
@ -76,6 +76,9 @@ impl<'tcx> PlaceTy<'tcx> {
|
||||
V: ::std::fmt::Debug,
|
||||
T: ::std::fmt::Debug + Copy,
|
||||
{
|
||||
if self.variant_index.is_some() && !matches!(elem, ProjectionElem::Field(..)) {
|
||||
bug!("cannot use non field projection on downcasted place")
|
||||
}
|
||||
let answer = match *elem {
|
||||
ProjectionElem::Deref => {
|
||||
let ty = self
|
||||
|
Loading…
Reference in New Issue
Block a user