Skip to content

Ignore Infer sty when relating MIR and user Ty #57887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 19 additions & 8 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ static_assert!(PLACE_TY_IS_3_PTRS_LARGE:
mem::size_of::<PlaceTy<'_>>() <= 24
);

#[derive(Debug)]
pub struct HitTyVar;

impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
pub fn from_ty(ty: Ty<'tcx>) -> PlaceTy<'tcx> {
PlaceTy::Ty { ty }
Expand Down Expand Up @@ -75,7 +78,7 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
elem: &PlaceElem<'tcx>)
-> PlaceTy<'tcx>
{
self.projection_ty_core(tcx, elem, |_, _, ty| -> Result<Ty<'tcx>, ()> { Ok(ty) })
self.projection_ty_core(tcx, elem, |_, _, ty| -> Result<Ty<'tcx>, HitTyVar> { Ok(ty) })
.unwrap()
}

Expand All @@ -84,14 +87,14 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
/// `Ty` or downcast variant corresponding to that projection.
/// The `handle_field` callback must map a `Field` to its `Ty`,
/// (which should be trivial when `T` = `Ty`).
pub fn projection_ty_core<V, T, E>(
pub fn projection_ty_core<V, T>(
self,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
elem: &ProjectionElem<'tcx, V, T>,
mut handle_field: impl FnMut(&Self, &Field, &T) -> Result<Ty<'tcx>, E>)
-> Result<PlaceTy<'tcx>, E>
where
V: ::std::fmt::Debug, T: ::std::fmt::Debug
mut handle_field: impl FnMut(&Self, &Field, &T) -> Result<Ty<'tcx>, HitTyVar>,
) -> Result<PlaceTy<'tcx>, HitTyVar>
where
V: ::std::fmt::Debug, T: ::std::fmt::Debug
{
let answer = match *elem {
ProjectionElem::Deref => {
Expand Down Expand Up @@ -135,8 +138,16 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
substs,
variant_index: index }
}
_ => {
bug!("cannot downcast non-ADT type: `{:?}`", self)
ty::Infer(..) => { // #57866
return Err(HitTyVar);
}
ref sty => {
bug!(
"cannot downcast non-ADT type: `{:?}`, `{:?}`, `{:?}`",
self,
sty,
adt_def1,
);
}
},
ProjectionElem::Field(ref f, ref fty) =>
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rustc::infer::canonical::QueryRegionConstraint;
use rustc::infer::outlives::env::RegionBoundPairs;
use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin};
use rustc::mir::interpret::EvalErrorKind::BoundsCheck;
use rustc::mir::tcx::PlaceTy;
use rustc::mir::tcx::{PlaceTy, HitTyVar};
use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext, NonMutatingUseContext};
use rustc::mir::*;
use rustc::traits::query::type_op;
Expand Down Expand Up @@ -1079,7 +1079,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
//
// if we hit a ty var as we descend, then just skip the
// attempt to relate the mir local with any type.
#[derive(Debug)] struct HitTyVar;
let mut curr_projected_ty: Result<PlaceTy, HitTyVar>;

curr_projected_ty = Ok(PlaceTy::from_ty(ty));
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_traits/type_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc::infer::canonical::{Canonical, QueryResponse};
use rustc::infer::InferCtxt;
use rustc::hir::def_id::DefId;
use rustc::mir::ProjectionKind;
use rustc::mir::tcx::PlaceTy;
use rustc::mir::tcx::{PlaceTy, HitTyVar};
use rustc::traits::query::type_op::ascribe_user_type::AscribeUserType;
use rustc::traits::query::type_op::eq::Eq;
use rustc::traits::query::type_op::normalize::Normalize;
Expand Down Expand Up @@ -133,7 +133,6 @@ impl AscribeUserTypeCx<'me, 'gcx, 'tcx> {
// if we hit a ty var as we descend, then just skip the
// attempt to relate the mir local with any type.

struct HitTyVar;
let mut curr_projected_ty: Result<PlaceTy, HitTyVar>;
curr_projected_ty = Ok(PlaceTy::from_ty(ty));
for proj in projs {
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/issues/issue-57866.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// run-pass

#![feature(type_alias_enum_variants)]

enum Outer<T> {
A(T)
}

enum Inner {
A(i32)
}

type OuterAlias = Outer<Inner>;

fn ice(x: OuterAlias) {
// Fine
match x {
OuterAlias::A(Inner::A(_)) => (),
}
// Not fine
match x {
OuterAlias::A(Inner::A(y)) => (),
}
}

fn main() {}