Skip to content

Commit 28fd1b0

Browse files
committed
Stop well-formedness checking unreachable code.
This commit stops well-formedness checking applying to unreachable code and therefore stops some of the ICEs that the intended solution taken by this PR causes. By disabling these checks, we can land the other fixes and larger refactors that this PR includes.
1 parent 95c1838 commit 28fd1b0

File tree

13 files changed

+70
-245
lines changed

13 files changed

+70
-245
lines changed

src/librustc/dep_graph/dep_node.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ use syntax_pos::symbol::InternedString;
6262
use traits;
6363
use traits::query::{
6464
CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
65-
CanonicalTypeOpAscribeUserTypeWellFormedGoal, CanonicalTypeOpEqGoal,
66-
CanonicalTypeOpSubtypeGoal, CanonicalPredicateGoal,
65+
CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal, CanonicalPredicateGoal,
6766
CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpNormalizeGoal,
6867
};
6968
use ty::{TyCtxt, FnSig, Instance, InstanceDef,
@@ -651,7 +650,6 @@ define_dep_nodes!( <'tcx>
651650
[] EvaluateObligation(CanonicalPredicateGoal<'tcx>),
652651
[] EvaluateGoal(traits::ChalkCanonicalGoal<'tcx>),
653652
[] TypeOpAscribeUserType(CanonicalTypeOpAscribeUserTypeGoal<'tcx>),
654-
[] TypeOpAscribeUserTypeWellFormed(CanonicalTypeOpAscribeUserTypeWellFormedGoal<'tcx>),
655653
[] TypeOpEq(CanonicalTypeOpEqGoal<'tcx>),
656654
[] TypeOpSubtype(CanonicalTypeOpSubtypeGoal<'tcx>),
657655
[] TypeOpProvePredicate(CanonicalTypeOpProvePredicateGoal<'tcx>),

src/librustc/traits/query/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ pub type CanonicalPredicateGoal<'tcx> =
2828
pub type CanonicalTypeOpAscribeUserTypeGoal<'tcx> =
2929
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::ascribe_user_type::AscribeUserType<'tcx>>>;
3030

31-
pub type CanonicalTypeOpAscribeUserTypeWellFormedGoal<'tcx> =
32-
Canonical<'tcx, ty::ParamEnvAnd<'tcx,
33-
type_op::ascribe_user_type::AscribeUserTypeWellFormed<'tcx>>>;
34-
3531
pub type CanonicalTypeOpEqGoal<'tcx> =
3632
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::eq::Eq<'tcx>>>;
3733

src/librustc/traits/query/type_op/ascribe_user_type.rs

+1-57
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, Que
22
use traits::query::Fallible;
33
use hir::def_id::DefId;
44
use mir::ProjectionKind;
5-
use ty::{self, ParamEnvAnd, Ty, TyCtxt, UserTypeAnnotation};
5+
use ty::{self, ParamEnvAnd, Ty, TyCtxt};
66
use ty::subst::UserSubsts;
77

88
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
@@ -68,59 +68,3 @@ impl_stable_hash_for! {
6868
mir_ty, variance, def_id, user_substs, projs
6969
}
7070
}
71-
72-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
73-
pub struct AscribeUserTypeWellFormed<'tcx> {
74-
pub user_type_annotation: UserTypeAnnotation<'tcx>,
75-
}
76-
77-
impl<'tcx> AscribeUserTypeWellFormed<'tcx> {
78-
pub fn new(
79-
user_type_annotation: UserTypeAnnotation<'tcx>,
80-
) -> Self {
81-
Self { user_type_annotation, }
82-
}
83-
}
84-
85-
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for AscribeUserTypeWellFormed<'tcx> {
86-
type QueryResponse = ();
87-
88-
fn try_fast_path(
89-
_tcx: TyCtxt<'_, 'gcx, 'tcx>,
90-
_key: &ParamEnvAnd<'tcx, Self>,
91-
) -> Option<Self::QueryResponse> {
92-
None
93-
}
94-
95-
fn perform_query(
96-
tcx: TyCtxt<'_, 'gcx, 'tcx>,
97-
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
98-
) -> Fallible<CanonicalizedQueryResponse<'gcx, ()>> {
99-
tcx.type_op_ascribe_user_type_well_formed(canonicalized)
100-
}
101-
102-
fn shrink_to_tcx_lifetime(
103-
v: &'a CanonicalizedQueryResponse<'gcx, ()>,
104-
) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
105-
v
106-
}
107-
}
108-
109-
BraceStructTypeFoldableImpl! {
110-
impl<'tcx> TypeFoldable<'tcx> for AscribeUserTypeWellFormed<'tcx> {
111-
user_type_annotation
112-
}
113-
}
114-
115-
BraceStructLiftImpl! {
116-
impl<'a, 'tcx> Lift<'tcx> for AscribeUserTypeWellFormed<'a> {
117-
type Lifted = AscribeUserTypeWellFormed<'tcx>;
118-
user_type_annotation
119-
}
120-
}
121-
122-
impl_stable_hash_for! {
123-
struct AscribeUserTypeWellFormed<'tcx> {
124-
user_type_annotation
125-
}
126-
}

src/librustc/ty/query/config.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use mir::interpret::GlobalId;
55
use traits;
66
use traits::query::{
77
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
8-
CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpAscribeUserTypeWellFormedGoal,
9-
CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
8+
CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
109
CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
1110
};
1211
use ty::{self, ParamEnvAnd, Ty, TyCtxt};
@@ -125,15 +124,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::type_op_ascribe_user_type<'tcx> {
125124
}
126125
}
127126

128-
impl<'tcx> QueryDescription<'tcx> for queries::type_op_ascribe_user_type_well_formed<'tcx> {
129-
fn describe(
130-
_tcx: TyCtxt<'_, '_, '_>,
131-
goal: CanonicalTypeOpAscribeUserTypeWellFormedGoal<'tcx>,
132-
) -> Cow<'static, str> {
133-
format!("evaluating `type_op_ascribe_user_type_well_formed` `{:?}`", goal).into()
134-
}
135-
}
136-
137127
impl<'tcx> QueryDescription<'tcx> for queries::type_op_eq<'tcx> {
138128
fn describe(_tcx: TyCtxt<'_, '_, '_>, goal: CanonicalTypeOpEqGoal<'tcx>) -> Cow<'static, str> {
139129
format!("evaluating `type_op_eq` `{:?}`", goal).into()

src/librustc/ty/query/mod.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ use traits::{self, Vtable};
2727
use traits::query::{
2828
CanonicalPredicateGoal, CanonicalProjectionGoal,
2929
CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
30-
CanonicalTypeOpAscribeUserTypeWellFormedGoal, CanonicalTypeOpEqGoal,
31-
CanonicalTypeOpSubtypeGoal, CanonicalTypeOpProvePredicateGoal,
30+
CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal, CanonicalTypeOpProvePredicateGoal,
3231
CanonicalTypeOpNormalizeGoal, NoSolution,
3332
};
3433
use traits::query::method_autoderef::MethodAutoderefStepsResult;
@@ -610,14 +609,6 @@ define_queries! { <'tcx>
610609
NoSolution,
611610
>,
612611

613-
/// Do not call this query directly: part of the `Eq` type-op
614-
[] fn type_op_ascribe_user_type_well_formed: TypeOpAscribeUserTypeWellFormed(
615-
CanonicalTypeOpAscribeUserTypeWellFormedGoal<'tcx>
616-
) -> Result<
617-
Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
618-
NoSolution,
619-
>,
620-
621612
/// Do not call this query directly: part of the `Eq` type-op
622613
[] fn type_op_eq: TypeOpEq(
623614
CanonicalTypeOpEqGoal<'tcx>

src/librustc/ty/query/plumbing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
12081208
DepKind::EvaluateObligation |
12091209
DepKind::EvaluateGoal |
12101210
DepKind::TypeOpAscribeUserType |
1211-
DepKind::TypeOpAscribeUserTypeWellFormed |
12121211
DepKind::TypeOpEq |
12131212
DepKind::TypeOpSubtype |
12141213
DepKind::TypeOpProvePredicate |

src/librustc/ty/wf.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
289289
self.out.extend(obligations);
290290
}
291291

292+
ty::FnDef(did, substs) => {
293+
let obligations = self.nominal_obligations(did, substs);
294+
self.out.extend(obligations);
295+
}
296+
292297
ty::Ref(r, rty, _) => {
293298
// WfReference
294299
if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() {
@@ -349,7 +354,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
349354
}
350355
}
351356

352-
ty::FnDef(..) | ty::FnPtr(_) => {
357+
ty::FnPtr(_) => {
353358
// let the loop iterate into the argument/return
354359
// types appearing in the fn signature
355360
}

src/librustc_mir/borrow_check/nll/type_check/mod.rs

-53
Original file line numberDiff line numberDiff line change
@@ -928,37 +928,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
928928
);
929929
}
930930

931-
/// Check that user type annotations are well formed.
932-
fn check_user_type_annotations_are_well_formed(&mut self) {
933-
for index in self.mir.user_type_annotations.indices() {
934-
let (span, _) = &self.mir.user_type_annotations[index];
935-
let type_annotation = self.instantiated_type_annotations[&index];
936-
match type_annotation {
937-
// We can't check the well-formedness of a `UserTypeAnnotation::Ty` here, it will
938-
// cause ICEs (see comment in `relate_type_and_user_type`).
939-
UserTypeAnnotation::TypeOf(..) => {
940-
if let Err(terr) = self.fully_perform_op(
941-
Locations::All(*span),
942-
ConstraintCategory::Assignment,
943-
self.param_env.and(
944-
type_op::ascribe_user_type::AscribeUserTypeWellFormed::new(
945-
type_annotation,
946-
)
947-
),
948-
) {
949-
span_mirbug!(
950-
self,
951-
type_annotation,
952-
"bad user type annotation: {:?}",
953-
terr,
954-
);
955-
}
956-
},
957-
_ => {},
958-
}
959-
}
960-
}
961-
962931
/// Given some operation `op` that manipulates types, proves
963932
/// predicates, or otherwise uses the inference context, executes
964933
/// `op` and then executes all the further obligations that `op`
@@ -1127,27 +1096,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11271096
if let Ok(projected_ty) = curr_projected_ty {
11281097
let ty = projected_ty.to_ty(tcx);
11291098
self.relate_types(ty, v1, a, locations, category)?;
1130-
1131-
// We'll get an ICE if we check for well-formedness of a
1132-
// `UserTypeAnnotation::Ty` that hasn't had types related.
1133-
//
1134-
// Doing this without the types having been related will result in
1135-
// `probe_ty_var` failing in the canonicalizer - in practice, this
1136-
// results in three run-pass tests failing. You can work around that
1137-
// by keeping an vec of projections instead of annotations and performing
1138-
// the projections before storing into `instantiated_type_annotations`
1139-
// but that still fails in dead code.
1140-
self.fully_perform_op(
1141-
locations,
1142-
category,
1143-
self.param_env.and(
1144-
type_op::ascribe_user_type::AscribeUserTypeWellFormed::new(
1145-
UserTypeAnnotation::Ty(ty),
1146-
)
1147-
),
1148-
)?;
11491099
}
1150-
11511100
}
11521101
UserTypeAnnotation::TypeOf(def_id, user_substs) => {
11531102
let projs = self.infcx.tcx.intern_projs(&user_ty.projs);
@@ -2453,8 +2402,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
24532402
self.check_terminator(mir, block_data.terminator(), location);
24542403
self.check_iscleanup(mir, block_data);
24552404
}
2456-
2457-
self.check_user_type_annotations_are_well_formed();
24582405
}
24592406

24602407
fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T

0 commit comments

Comments
 (0)