Skip to content

Commit f455dc9

Browse files
committed
Auto merge of #150161 - oli-obk:try_as_dyn_non_static, r=<try>
Remove 'static requirement on try_as_dyn try-job: dist-powerpc64le-linux-gnu
2 parents 2d8fa67 + b111aec commit f455dc9

77 files changed

Lines changed: 1276 additions & 116 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎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/src/lang_items.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ language_item_table! {
194194
CoerceUnsized, sym::coerce_unsized, coerce_unsized_trait, Target::Trait, GenericRequirement::Minimum(1);
195195
DispatchFromDyn, sym::dispatch_from_dyn, dispatch_from_dyn_trait, Target::Trait, GenericRequirement::Minimum(1);
196196

197+
TryAsDyn, sym::try_as_dyn, try_as_dyn, Target::Trait, GenericRequirement::Exact(1);
198+
197199
// lang items relating to transmutability
198200
TransmuteOpts, sym::transmute_opts, transmute_opts, Target::Struct, GenericRequirement::Exact(0);
199201
TransmuteTrait, sym::transmute_trait, transmute_trait, Target::Trait, GenericRequirement::Exact(2);

‎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,
@@ -1395,6 +1396,11 @@ pub fn suggest_impl_trait<'tcx>(
13951396
None
13961397
}
13971398

1399+
fn impl_is_fully_generic_for_reflection(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1400+
tcx.impl_trait_header(def_id).is_fully_generic_for_reflection()
1401+
&& tcx.explicit_predicates_of(def_id).is_fully_generic_for_reflection()
1402+
}
1403+
13981404
fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader<'_> {
13991405
let icx = ItemCtxt::new(tcx, def_id);
14001406
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
@@ -696,6 +696,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
696696
defining_opaque_types_and_generators
697697
}
698698
ty::TypingMode::Coherence
699+
| ty::TypingMode::Reflection
699700
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
700701
| ty::TypingMode::PostBorrowck { .. }
701702
| 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
@@ -1171,6 +1172,7 @@ impl<'tcx> InferCtxt<'tcx> {
11711172
// and post-borrowck analysis mode. We may need to modify its uses
11721173
// to support PostBorrowck in the old solver as well.
11731174
TypingMode::Coherence
1175+
| TypingMode::Reflection
11741176
| TypingMode::PostBorrowck { .. }
11751177
| TypingMode::PostAnalysis
11761178
| TypingMode::Codegen => false,
@@ -1505,6 +1507,7 @@ impl<'tcx> InferCtxt<'tcx> {
15051507
mode @ (ty::TypingMode::Coherence
15061508
| ty::TypingMode::PostBorrowck { .. }
15071509
| ty::TypingMode::PostAnalysis
1510+
| ty::TypingMode::Reflection
15081511
| ty::TypingMode::Codegen) => mode,
15091512
ty::TypingMode::ErasedNotCoherence(MayBeErased) => unreachable!(),
15101513
};

‎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
@@ -241,6 +241,7 @@ provide! { tcx, def_id, other, cdata,
241241
fn_sig => { table }
242242
codegen_fn_attrs => { table }
243243
impl_trait_header => { table }
244+
impl_is_fully_generic_for_reflection => { table_direct }
244245
const_param_default => { table }
245246
object_lifetime_default => { table }
246247
thir_abstract_const => { table }

0 commit comments

Comments
 (0)