Skip to content

Commit 50e3369

Browse files
committed
Remove 'static requirement on try_as_dyn
1 parent f28ac76 commit 50e3369

40 files changed

Lines changed: 432 additions & 50 deletions

File tree

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fn retry_codegen_mode_with_postanalysis<'tcx, K: TypeVisitable<TyCtxt<'tcx>>, V>
4444
| ty::TypingMode::Typeck { .. }
4545
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
4646
| ty::TypingMode::PostBorrowck { .. }
47+
| ty::TypingMode::Reflection
4748
| ty::TypingMode::PostAnalysis => {}
4849
}
4950

compiler/rustc_const_eval/src/interpret/util.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ pub(crate) fn type_implements_dyn_trait<'tcx, M: Machine<'tcx>>(
2929
);
3030
};
3131

32-
let (infcx, param_env) = ecx.tcx.infer_ctxt().build_with_typing_env(ecx.typing_env);
32+
let (infcx, param_env) = ecx.tcx.infer_ctxt().build_with_typing_env(ty::TypingEnv::new(
33+
ecx.typing_env.param_env,
34+
ty::TypingMode::Reflection,
35+
));
3336

3437
let ocx = ObligationCtxt::new(&infcx);
3538
ocx.register_obligations(preds.iter().map(|pred: PolyExistentialPredicate<'_>| {

compiler/rustc_const_eval/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn assert_typing_mode(typing_mode: ty::TypingMode<'_>) {
3333
// `InterpCx::new` for more details.
3434
ty::TypingMode::Coherence
3535
| ty::TypingMode::Typeck { .. }
36+
| ty::TypingMode::Reflection
3637
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
3738
| ty::TypingMode::PostBorrowck { .. } => bug!(
3839
"Const eval should always happens in PostAnalysis or Codegen mode. See the comment on `assert_typing_mode` for more details."

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub(crate) fn provide(providers: &mut Providers) {
8585
adt_def,
8686
fn_sig,
8787
impl_trait_header,
88+
impl_is_fully_generic_for_reflection,
8889
coroutine_kind,
8990
coroutine_for_closure,
9091
opaque_ty_origin,
@@ -1390,6 +1391,11 @@ pub fn suggest_impl_trait<'tcx>(
13901391
None
13911392
}
13921393

1394+
fn impl_is_fully_generic_for_reflection(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1395+
tcx.impl_trait_header(def_id).is_fully_generic_for_reflection()
1396+
&& tcx.explicit_predicates_of(def_id).is_fully_generic_for_reflection()
1397+
}
1398+
13931399
fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader<'_> {
13941400
let icx = ItemCtxt::new(tcx, def_id);
13951401
let item = tcx.hir_expect_item(def_id);

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
661661
defining_opaque_types_and_generators
662662
}
663663
ty::TypingMode::Coherence
664+
| ty::TypingMode::Reflection
664665
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
665666
| ty::TypingMode::PostBorrowck { .. }
666667
| ty::TypingMode::PostAnalysis

compiler/rustc_hir_typeck/src/opaque_types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
103103
defining_opaque_types_and_generators
104104
}
105105
ty::TypingMode::Coherence
106+
| ty::TypingMode::Reflection
106107
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
107108
| ty::TypingMode::PostBorrowck { .. }
108109
| ty::TypingMode::PostAnalysis

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ impl<'tcx> Drop for InferCtxt<'tcx> {
354354
TypingMode::Coherence
355355
| TypingMode::Typeck { .. }
356356
| TypingMode::PostBorrowck { .. }
357+
| TypingMode::Reflection
357358
| TypingMode::PostAnalysis
358359
| TypingMode::Codegen => {}
359360
// In erased mode, the opaque type storage is always empty
@@ -1161,6 +1162,7 @@ impl<'tcx> InferCtxt<'tcx> {
11611162
// and post-borrowck analysis mode. We may need to modify its uses
11621163
// to support PostBorrowck in the old solver as well.
11631164
TypingMode::Coherence
1165+
| TypingMode::Reflection
11641166
| TypingMode::PostBorrowck { .. }
11651167
| TypingMode::PostAnalysis
11661168
| TypingMode::Codegen => false,
@@ -1494,6 +1496,7 @@ impl<'tcx> InferCtxt<'tcx> {
14941496
mode @ (ty::TypingMode::Coherence
14951497
| ty::TypingMode::PostBorrowck { .. }
14961498
| ty::TypingMode::PostAnalysis
1499+
| ty::TypingMode::Reflection
14971500
| ty::TypingMode::Codegen) => mode,
14981501
ty::TypingMode::ErasedNotCoherence(MayBeErased) => unreachable!(),
14991502
};

compiler/rustc_infer/src/infer/opaque_types/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ impl<'tcx> InferCtxt<'tcx> {
285285
}
286286
mode @ (ty::TypingMode::PostBorrowck { .. }
287287
| ty::TypingMode::PostAnalysis
288-
| ty::TypingMode::Codegen) => {
288+
| ty::TypingMode::Codegen
289+
| ty::TypingMode::Reflection) => {
289290
bug!("insert hidden type in {mode:?}")
290291
}
291292
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ provide! { tcx, def_id, other, cdata,
232232
fn_sig => { table }
233233
codegen_fn_attrs => { table }
234234
impl_trait_header => { table }
235+
impl_is_fully_generic_for_reflection => { table_direct }
235236
const_param_default => { table }
236237
object_lifetime_default => { table }
237238
thir_abstract_const => { table }

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
21982198
let header = tcx.impl_trait_header(def_id);
21992199
record!(self.tables.impl_trait_header[def_id] <- header);
22002200

2201+
let impl_is_fully_generic_for_reflection =
2202+
tcx.impl_is_fully_generic_for_reflection(def_id);
2203+
self.tables
2204+
.impl_is_fully_generic_for_reflection
2205+
.set(def_id.index, impl_is_fully_generic_for_reflection);
2206+
22012207
self.tables.defaultness.set(def_id.index, tcx.defaultness(def_id));
22022208

22032209
let trait_ref = header.trait_ref.instantiate_identity().skip_norm_wip();

0 commit comments

Comments
 (0)