Skip to content

Commit 13d22e8

Browse files
committed
Remove 'static requirement on try_as_dyn
1 parent 92c7010 commit 13d22e8

39 files changed

Lines changed: 383 additions & 31 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
@@ -377,6 +377,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
377377
match key.typing_env.typing_mode() {
378378
ty::TypingMode::PostAnalysis => {}
379379
ty::TypingMode::Coherence
380+
| ty::TypingMode::Reflection
380381
| ty::TypingMode::Analysis { .. }
381382
| ty::TypingMode::Borrowck { .. }
382383
| ty::TypingMode::PostBorrowckAnalysis { .. } => {

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
240240
match typing_env.typing_mode() {
241241
ty::TypingMode::PostAnalysis => {}
242242
ty::TypingMode::Coherence
243+
| ty::TypingMode::Reflection
243244
| ty::TypingMode::Analysis { .. }
244245
| ty::TypingMode::Borrowck { .. }
245246
| ty::TypingMode::PostBorrowckAnalysis { .. } => {

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
246246
match typing_env.typing_mode() {
247247
TypingMode::PostAnalysis => {}
248248
TypingMode::Coherence
249+
| TypingMode::Reflection
249250
| TypingMode::Analysis { .. }
250251
| TypingMode::Borrowck { .. }
251252
| TypingMode::PostBorrowckAnalysis { .. } => {

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_hir_analysis/src/collect.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub(crate) fn provide(providers: &mut Providers) {
8787
adt_def,
8888
fn_sig,
8989
impl_trait_header,
90+
impl_is_fully_generic_for_reflection,
9091
coroutine_kind,
9192
coroutine_for_closure,
9293
opaque_ty_origin,
@@ -1370,6 +1371,11 @@ pub fn suggest_impl_trait<'tcx>(
13701371
None
13711372
}
13721373

1374+
fn impl_is_fully_generic_for_reflection(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1375+
tcx.impl_trait_header(def_id).is_fully_generic_for_reflection()
1376+
&& tcx.explicit_predicates_of(def_id).is_fully_generic_for_reflection()
1377+
}
1378+
13731379
fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader<'_> {
13741380
let icx = ItemCtxt::new(tcx, def_id);
13751381
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
@@ -664,6 +664,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
664664
defining_opaque_types_and_generators
665665
}
666666
ty::TypingMode::Coherence
667+
| ty::TypingMode::Reflection
667668
| ty::TypingMode::Borrowck { .. }
668669
| ty::TypingMode::PostBorrowckAnalysis { .. }
669670
| 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::Borrowck { .. }
107108
| ty::TypingMode::PostBorrowckAnalysis { .. }
108109
| ty::TypingMode::PostAnalysis => {

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,7 @@ impl<'tcx> InferCtxt<'tcx> {
10751075
// and post-borrowck analysis mode. We may need to modify its uses
10761076
// to support PostBorrowckAnalysis in the old solver as well.
10771077
TypingMode::Coherence
1078+
| TypingMode::Reflection
10781079
| TypingMode::PostBorrowckAnalysis { .. }
10791080
| TypingMode::PostAnalysis => false,
10801081
}
@@ -1406,6 +1407,7 @@ impl<'tcx> InferCtxt<'tcx> {
14061407
}
14071408
mode @ (ty::TypingMode::Coherence
14081409
| ty::TypingMode::PostBorrowckAnalysis { .. }
1410+
| ty::TypingMode::Reflection
14091411
| ty::TypingMode::PostAnalysis) => mode,
14101412
};
14111413
ty::TypingEnv::new(param_env, typing_mode)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ impl<'tcx> InferCtxt<'tcx> {
281281
.map(|obligation| obligation.as_goal()),
282282
);
283283
}
284-
mode @ (ty::TypingMode::PostBorrowckAnalysis { .. } | ty::TypingMode::PostAnalysis) => {
284+
mode @ (ty::TypingMode::PostBorrowckAnalysis { .. }
285+
| ty::TypingMode::PostAnalysis
286+
| ty::TypingMode::Reflection) => {
285287
bug!("insert hidden type in {mode:?}")
286288
}
287289
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ provide! { tcx, def_id, other, cdata,
237237
fn_sig => { table }
238238
codegen_fn_attrs => { table }
239239
impl_trait_header => { table }
240+
impl_is_fully_generic_for_reflection => { table_direct }
240241
const_param_default => { table }
241242
object_lifetime_default => { table }
242243
thir_abstract_const => { table }

0 commit comments

Comments
 (0)