Skip to content

Commit 2848e15

Browse files
authored
Rollup merge of #54789 - scalexm:unnormalized, r=nikomatsakis
Introduce `TyKind::UnnormalizedProjection` Introduce a new variant used for lazy normalization in chalk integration. Mostly `bug!` everywhere. r? @nikomatsakis
2 parents db548ea + edb3f97 commit 2848e15

File tree

28 files changed

+58
-11
lines changed

28 files changed

+58
-11
lines changed

src/librustc/ich/impls_ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,8 @@ for ty::TyKind<'gcx>
873873
Tuple(inner_tys) => {
874874
inner_tys.hash_stable(hcx, hasher);
875875
}
876-
Projection(ref projection_ty) => {
877-
projection_ty.hash_stable(hcx, hasher);
876+
Projection(ref data) | UnnormalizedProjection(ref data) => {
877+
data.hash_stable(hcx, hasher);
878878
}
879879
Opaque(def_id, substs) => {
880880
def_id.hash_stable(hcx, hasher);

src/librustc/infer/canonical/canonicalizer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
283283
| ty::Never
284284
| ty::Tuple(..)
285285
| ty::Projection(..)
286+
| ty::UnnormalizedProjection(..)
286287
| ty::Foreign(..)
287288
| ty::Param(..)
288289
| ty::Opaque(..) => {

src/librustc/infer/freshen.rs

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
193193
ty::Never |
194194
ty::Tuple(..) |
195195
ty::Projection(..) |
196+
ty::UnnormalizedProjection(..) |
196197
ty::Foreign(..) |
197198
ty::Param(..) |
198199
ty::Closure(..) |

src/librustc/traits/coherence.rs

+1
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ fn ty_is_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> bool {
475475

476476
ty::Error => true,
477477

478+
ty::UnnormalizedProjection(..) |
478479
ty::Closure(..) |
479480
ty::Generator(..) |
480481
ty::GeneratorWitness(..) |

src/librustc/traits/error_reporting.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
269269
ty::Generator(..) => Some(18),
270270
ty::Foreign(..) => Some(19),
271271
ty::GeneratorWitness(..) => Some(20),
272-
ty::Infer(..) | ty::Error => None
272+
ty::Infer(..) | ty::Error => None,
273+
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
273274
}
274275
}
275276

src/librustc/traits/query/dropck_outlives.rs

+2
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'_, '_, 'tcx>, ty: Ty<'tcx>) ->
253253
| ty::Opaque(..)
254254
| ty::Infer(_)
255255
| ty::Generator(..) => false,
256+
257+
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
256258
}
257259
}

src/librustc/traits/select.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
22832283
ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => None,
22842284
ty::Infer(ty::TyVar(_)) => Ambiguous,
22852285

2286+
ty::UnnormalizedProjection(..) |
22862287
ty::Infer(ty::CanonicalTy(_)) |
22872288
ty::Infer(ty::FreshTy(_)) |
22882289
ty::Infer(ty::FreshIntTy(_)) |
@@ -2355,6 +2356,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
23552356
Ambiguous
23562357
}
23572358

2359+
ty::UnnormalizedProjection(..) |
23582360
ty::Infer(ty::CanonicalTy(_)) |
23592361
ty::Infer(ty::FreshTy(_)) |
23602362
ty::Infer(ty::FreshIntTy(_)) |
@@ -2393,6 +2395,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
23932395
Vec::new()
23942396
}
23952397

2398+
ty::UnnormalizedProjection(..) |
23962399
ty::Dynamic(..) |
23972400
ty::Param(..) |
23982401
ty::Foreign(..) |

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
22662266
self,
22672267
Adt, Array, Slice, RawPtr, Ref, FnDef, FnPtr,
22682268
Generator, GeneratorWitness, Dynamic, Closure, Tuple,
2269-
Param, Infer, Projection, Opaque, Foreign);
2269+
Param, Infer, UnnormalizedProjection, Projection, Opaque, Foreign);
22702270

22712271
println!("Substs interner: #{}", self.interners.substs.borrow().len());
22722272
println!("Region interner: #{}", self.interners.region.borrow().len());

src/librustc/ty/error.rs

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
222222
ty::Infer(ty::FreshIntTy(_)) => "skolemized integral type".to_string(),
223223
ty::Infer(ty::FreshFloatTy(_)) => "skolemized floating-point type".to_string(),
224224
ty::Projection(_) => "associated type".to_string(),
225+
ty::UnnormalizedProjection(_) => "non-normalized associated type".to_string(),
225226
ty::Param(ref p) => {
226227
if p.is_self() {
227228
"Self".to_string()

src/librustc/ty/fast_reject.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
103103
ty::FnPtr(ref f) => {
104104
Some(FunctionSimplifiedType(f.skip_binder().inputs().len()))
105105
}
106+
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
106107
ty::Projection(_) | ty::Param(_) => {
107108
if can_simplify_params {
108109
// In normalized types, projections don't unify with

src/librustc/ty/flags.rs

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ impl FlagComputation {
150150
self.add_projection_ty(data);
151151
}
152152

153+
&ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
154+
153155
&ty::Opaque(_, substs) => {
154156
self.add_flags(TypeFlags::HAS_PROJECTION);
155157
self.add_substs(substs);

src/librustc/ty/item_path.rs

+1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
463463
ty::Str |
464464
ty::FnPtr(_) |
465465
ty::Projection(_) |
466+
ty::UnnormalizedProjection(..) |
466467
ty::Param(_) |
467468
ty::Opaque(..) |
468469
ty::Infer(_) |

src/librustc/ty/layout.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
11231123
}
11241124
tcx.layout_raw(param_env.and(normalized))?
11251125
}
1126-
ty::GeneratorWitness(..) | ty::Infer(_) => {
1126+
ty::UnnormalizedProjection(..) | ty::GeneratorWitness(..) | ty::Infer(_) => {
11271127
bug!("LayoutDetails::compute: unexpected type `{}`", ty)
11281128
}
11291129
ty::Param(_) | ty::Error => {
@@ -1702,8 +1702,8 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
17021702
}
17031703
}
17041704

1705-
ty::Projection(_) | ty::Opaque(..) | ty::Param(_) |
1706-
ty::Infer(_) | ty::Error => {
1705+
ty::Projection(_) | ty::UnnormalizedProjection(..) |
1706+
ty::Opaque(..) | ty::Param(_) | ty::Infer(_) | ty::Error => {
17071707
bug!("TyLayout::field_type: unexpected type `{}`", this.ty)
17081708
}
17091709
})

src/librustc/ty/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,8 @@ impl<'a, 'gcx, 'tcx> AdtDef {
23392339
vec![ty]
23402340
}
23412341

2342+
UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
2343+
23422344
Param(..) => {
23432345
// perf hack: if there is a `T: Sized` bound, then
23442346
// we know that `T` is Sized and do not need to check

src/librustc/ty/outlives.rs

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
124124
}
125125
}
126126

127+
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
128+
127129
// We assume that inference variables are fully resolved.
128130
// So, if we encounter an inference variable, just record
129131
// the unresolved variable as a component.

src/librustc/ty/structural_impls.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,9 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
876876
ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)),
877877
ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)),
878878
ty::Projection(ref data) => ty::Projection(data.fold_with(folder)),
879+
ty::UnnormalizedProjection(ref data) => {
880+
ty::UnnormalizedProjection(data.fold_with(folder))
881+
}
879882
ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)),
880883
ty::Bool | ty::Char | ty::Str | ty::Int(_) |
881884
ty::Uint(_) | ty::Float(_) | ty::Error | ty::Infer(_) |
@@ -910,7 +913,9 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
910913
}
911914
ty::GeneratorWitness(ref types) => types.visit_with(visitor),
912915
ty::Closure(_did, ref substs) => substs.visit_with(visitor),
913-
ty::Projection(ref data) => data.visit_with(visitor),
916+
ty::Projection(ref data) | ty::UnnormalizedProjection(ref data) => {
917+
data.visit_with(visitor)
918+
}
914919
ty::Opaque(_, ref substs) => substs.visit_with(visitor),
915920
ty::Bool | ty::Char | ty::Str | ty::Int(_) |
916921
ty::Uint(_) | ty::Float(_) | ty::Error | ty::Infer(_) |

src/librustc/ty/sty.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ pub enum TyKind<'tcx> {
157157
/// `<T as Trait<..>>::N`.
158158
Projection(ProjectionTy<'tcx>),
159159

160+
/// A placeholder type used when we do not have enough information
161+
/// to normalize the projection of an associated type to an
162+
/// existing concrete type. Currently only used with chalk-engine.
163+
UnnormalizedProjection(ProjectionTy<'tcx>),
164+
160165
/// Opaque (`impl Trait`) type found in a return type.
161166
/// The `DefId` comes either from
162167
/// * the `impl Trait` ast::Ty node,
@@ -1806,7 +1811,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
18061811
Generator(_, GeneratorSubsts { ref substs }, _) => {
18071812
substs.regions().collect()
18081813
}
1809-
Projection(ref data) => {
1814+
Projection(ref data) | UnnormalizedProjection(ref data) => {
18101815
data.substs.regions().collect()
18111816
}
18121817
FnDef(..) |
@@ -1886,6 +1891,8 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
18861891

18871892
ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => false,
18881893

1894+
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
1895+
18891896
ty::Infer(ty::TyVar(_)) => false,
18901897

18911898
ty::Infer(ty::CanonicalTy(_)) |

src/librustc/ty/util.rs

+2
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,8 @@ fn needs_drop_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
958958
ty::Dynamic(..) | ty::Projection(..) | ty::Param(_) |
959959
ty::Opaque(..) | ty::Infer(_) | ty::Error => true,
960960

961+
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
962+
961963
// Structural recursion.
962964
ty::Array(ty, _) | ty::Slice(ty) => needs_drop(ty),
963965

src/librustc/ty/walk.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) {
9797
ty::Ref(_, ty, _) => {
9898
stack.push(ty);
9999
}
100-
ty::Projection(ref data) => {
100+
ty::Projection(ref data) | ty::UnnormalizedProjection(ref data) => {
101101
stack.extend(data.substs.types().rev());
102102
}
103103
ty::Dynamic(ref obj, ..) => {

src/librustc/ty/wf.rs

+2
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
289289
self.compute_projection(data);
290290
}
291291

292+
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
293+
292294
ty::Adt(def, substs) => {
293295
// WfNominalType
294296
let obligations = self.nominal_obligations(def.did, substs);

src/librustc/util/ppaux.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use ty::{Bool, Char, Adt};
1818
use ty::{Error, Str, Array, Slice, Float, FnDef, FnPtr};
1919
use ty::{Param, RawPtr, Ref, Never, Tuple};
2020
use ty::{Closure, Generator, GeneratorWitness, Foreign, Projection, Opaque};
21-
use ty::{Dynamic, Int, Uint, Infer};
21+
use ty::{UnnormalizedProjection, Dynamic, Int, Uint, Infer};
2222
use ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDefKind};
2323
use util::nodemap::FxHashSet;
2424

@@ -1143,6 +1143,11 @@ define_print! {
11431143
}
11441144
Foreign(def_id) => parameterized(f, subst::Substs::empty(), def_id, &[]),
11451145
Projection(ref data) => data.print(f, cx),
1146+
UnnormalizedProjection(ref data) => {
1147+
write!(f, "Unnormalized(")?;
1148+
data.print(f, cx)?;
1149+
write!(f, ")")
1150+
}
11461151
Opaque(def_id, substs) => {
11471152
if cx.is_verbose {
11481153
return write!(f, "Opaque({:?}, {:?})", def_id, substs);

src/librustc_codegen_llvm/debuginfo/type_names.rs

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
173173
}
174174
ty::Error |
175175
ty::Infer(_) |
176+
ty::UnnormalizedProjection(..) |
176177
ty::Projection(..) |
177178
ty::Opaque(..) |
178179
ty::GeneratorWitness(..) |

src/librustc_lint/types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
722722
ty::Closure(..) |
723723
ty::Generator(..) |
724724
ty::GeneratorWitness(..) |
725+
ty::UnnormalizedProjection(..) |
725726
ty::Projection(..) |
726727
ty::Opaque(..) |
727728
ty::FnDef(..) => bug!("Unexpected type in foreign function"),

src/librustc_mir/monomorphize/item.rs

+1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
382382
}
383383
ty::Error |
384384
ty::Infer(_) |
385+
ty::UnnormalizedProjection(..) |
385386
ty::Projection(..) |
386387
ty::Param(_) |
387388
ty::GeneratorWitness(_) |

src/librustc_traits/dropck_outlives.rs

+2
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ fn dtorck_constraint_for_ty<'a, 'gcx, 'tcx>(
272272
overflows: vec![],
273273
}),
274274

275+
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
276+
275277
ty::Infer(..) | ty::Error => {
276278
// By the time this code runs, all type variables ought to
277279
// be fully resolved.

src/librustc_typeck/check/cast.rs

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
124124
ty::Foreign(..) => Some(PointerKind::Thin),
125125
// We should really try to normalize here.
126126
ty::Projection(ref pi) => Some(PointerKind::OfProjection(pi)),
127+
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
127128
ty::Opaque(def_id, substs) => Some(PointerKind::OfOpaque(def_id, substs)),
128129
ty::Param(ref p) => Some(PointerKind::OfParam(p)),
129130
// Insufficient type information.

src/librustc_typeck/variance/constraints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
336336
// types, where we use Error as the Self type
337337
}
338338

339+
ty::UnnormalizedProjection(..) |
339340
ty::GeneratorWitness(..) |
340341
ty::Infer(..) => {
341342
bug!("unexpected type encountered in \

src/librustdoc/clean/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
27372737

27382738
ty::Closure(..) | ty::Generator(..) => Tuple(vec![]), // FIXME(pcwalton)
27392739

2740+
ty::UnnormalizedProjection(..) => panic!("UnnormalizedProjection"),
27402741
ty::GeneratorWitness(..) => panic!("GeneratorWitness"),
27412742
ty::Infer(..) => panic!("Infer"),
27422743
ty::Error => panic!("Error"),

0 commit comments

Comments
 (0)