Skip to content

Commit 1d834cb

Browse files
opaque types may also be sized
1 parent ef0ba1d commit 1d834cb

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

compiler/rustc_middle/src/ty/sty.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2282,19 +2282,18 @@ impl<'tcx> Ty<'tcx> {
22822282
ty::Str | ty::Slice(_) => (tcx.types.usize, false),
22832283
ty::Dynamic(..) => {
22842284
let dyn_metadata = tcx.lang_items().dyn_metadata().unwrap();
2285-
(tcx.type_of(dyn_metadata).subst(tcx, &[self.into()]), false)
2285+
(tcx.type_of(dyn_metadata).subst(tcx, &[tail.into()]), false)
22862286
},
22872287

22882288
// type parameters only have unit metadata if they're sized, so return true
22892289
// to make sure we double check this during confirmation
2290-
ty::Param(_) | ty::Projection(_) => (tcx.types.unit, true),
2290+
ty::Param(_) | ty::Projection(_) | ty::Opaque(..) => (tcx.types.unit, true),
22912291

2292-
ty::Opaque(..)
2293-
| ty::Infer(ty::TyVar(_))
2292+
ty::Infer(ty::TyVar(_))
22942293
| ty::Bound(..)
22952294
| ty::Placeholder(..)
22962295
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
2297-
bug!("`ptr_metadata_ty` applied to unexpected type: {:?}", self)
2296+
bug!("`ptr_metadata_ty` applied to unexpected type: {:?} (tail = {:?})", self, tail)
22982297
}
22992298
}
23002299
}

compiler/rustc_trait_selection/src/traits/project.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1439,10 +1439,18 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
14391439
// Integers and floats are always Sized, and so have unit type metadata.
14401440
| ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(..)) => true,
14411441

1442-
// type parameters and unnormalized projections have pointer metadata if they're still known to be sized
1443-
ty::Param(_) | ty::Projection(..) => tail.is_sized(selcx.tcx().at(obligation.cause.span), obligation.param_env),
1442+
// type parameters, opaques, and unnormalized projections have pointer
1443+
// metadata if they're known (e.g. by the param_env) to be sized
1444+
ty::Param(_) | ty::Projection(..) | ty::Opaque(..)
1445+
if tail.is_sized(selcx.tcx().at(obligation.cause.span), obligation.param_env) =>
1446+
{
1447+
true
1448+
}
14441449

1445-
ty::Opaque(..)
1450+
// FIXME(compiler-errors): are Bound and Placeholder types ever known sized?
1451+
ty::Param(_)
1452+
| ty::Projection(..)
1453+
| ty::Opaque(..)
14461454
| ty::Bound(..)
14471455
| ty::Placeholder(..)
14481456
| ty::Infer(..)
@@ -1451,7 +1459,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
14511459
candidate_set.mark_ambiguous();
14521460
}
14531461
false
1454-
},
1462+
}
14551463
}
14561464
}
14571465
super::ImplSource::Param(..) => {
+20-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
// check-pass
2+
// edition:2018
23

34
#![feature(ptr_metadata)]
5+
#![feature(type_alias_impl_trait)]
6+
7+
type Opaque = impl std::future::Future;
8+
9+
fn opaque() -> Opaque {
10+
async {}
11+
}
412

513
fn a<T>() {
6-
b::<T>();
7-
b::<std::cell::Cell<T>>();
14+
// type parameter T is known to be sized
15+
is_thin::<T>();
16+
// tail of ADT (which is a type param) is known to be sized
17+
is_thin::<std::cell::Cell<T>>();
18+
// opaque type is known to be sized
19+
is_thin::<Opaque>();
20+
}
21+
22+
fn a2<T: Iterator>() {
23+
// associated type is known to be sized
24+
is_thin::<T::Item>();
825
}
926

10-
fn b<T: std::ptr::Pointee<Metadata = ()>>() {}
27+
fn is_thin<T: std::ptr::Pointee<Metadata = ()>>() {}
1128

1229
fn main() {}

0 commit comments

Comments
 (0)