Skip to content

Commit 4813fda

Browse files
committed
rustdoc: yeet TypingEnv::from_param_env
1 parent f74951f commit 4813fda

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_data_structures::unord::UnordSet;
99
use rustc_infer::infer::DefineOpaqueTypes;
1010
use rustc_middle::ty::{Region, RegionVid};
1111
use tracing::debug;
12-
use ty::TypingMode;
1312

1413
use super::*;
1514
use crate::errors::UnableToConstructConstantValue;
@@ -71,15 +70,15 @@ impl<'tcx> AutoTraitFinder<'tcx> {
7170
pub fn find_auto_trait_generics<A>(
7271
&self,
7372
ty: Ty<'tcx>,
74-
orig_env: ty::ParamEnv<'tcx>,
73+
typing_env: ty::TypingEnv<'tcx>,
7574
trait_did: DefId,
7675
mut auto_trait_callback: impl FnMut(AutoTraitInfo<'tcx>) -> A,
7776
) -> AutoTraitResult<A> {
7877
let tcx = self.tcx;
7978

8079
let trait_ref = ty::TraitRef::new(tcx, trait_did, [ty]);
8180

82-
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
81+
let (infcx, orig_env) = tcx.infer_ctxt().build_with_typing_env(typing_env);
8382
let mut selcx = SelectionContext::new(&infcx);
8483
for polarity in [ty::PredicatePolarity::Positive, ty::PredicatePolarity::Negative] {
8584
let result = selcx.select(&Obligation::new(
@@ -89,17 +88,13 @@ impl<'tcx> AutoTraitFinder<'tcx> {
8988
ty::TraitPredicate { trait_ref, polarity },
9089
));
9190
if let Ok(Some(ImplSource::UserDefined(_))) = result {
92-
debug!(
93-
"find_auto_trait_generics({:?}): \
94-
manual impl found, bailing out",
95-
trait_ref
96-
);
91+
debug!("find_auto_trait_generics({trait_ref:?}): manual impl found, bailing out");
9792
// If an explicit impl exists, it always takes priority over an auto impl
9893
return AutoTraitResult::ExplicitImpl;
9994
}
10095
}
10196

102-
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
97+
let (infcx, orig_env) = tcx.infer_ctxt().build_with_typing_env(typing_env);
10398
let mut fresh_preds = FxIndexSet::default();
10499

105100
// Due to the way projections are handled by SelectionContext, we need to run

src/librustdoc/clean/auto_trait.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) fn synthesize_auto_trait_impls<'tcx>(
2121
item_def_id: DefId,
2222
) -> Vec<clean::Item> {
2323
let tcx = cx.tcx;
24-
let param_env = tcx.param_env(item_def_id);
24+
let typing_env = ty::TypingEnv::non_body_analysis(tcx, item_def_id);
2525
let ty = tcx.type_of(item_def_id).instantiate_identity();
2626

2727
let finder = auto_trait::AutoTraitFinder::new(tcx);
@@ -34,21 +34,21 @@ pub(crate) fn synthesize_auto_trait_impls<'tcx>(
3434
cx,
3535
ty,
3636
trait_def_id,
37-
param_env,
37+
typing_env,
3838
item_def_id,
3939
&finder,
4040
DiscardPositiveImpls::No,
4141
)
4242
})
4343
.collect();
4444
// We are only interested in case the type *doesn't* implement the `Sized` trait.
45-
if !ty.is_sized(tcx, ty::TypingEnv::from_param_env(param_env))
45+
if !ty.is_sized(tcx, typing_env)
4646
&& let Some(sized_trait_def_id) = tcx.lang_items().sized_trait()
4747
&& let Some(impl_item) = synthesize_auto_trait_impl(
4848
cx,
4949
ty,
5050
sized_trait_def_id,
51-
param_env,
51+
typing_env,
5252
item_def_id,
5353
&finder,
5454
DiscardPositiveImpls::Yes,
@@ -64,7 +64,7 @@ fn synthesize_auto_trait_impl<'tcx>(
6464
cx: &mut DocContext<'tcx>,
6565
ty: Ty<'tcx>,
6666
trait_def_id: DefId,
67-
param_env: ty::ParamEnv<'tcx>,
67+
typing_env: ty::TypingEnv<'tcx>,
6868
item_def_id: DefId,
6969
finder: &auto_trait::AutoTraitFinder<'tcx>,
7070
discard_positive_impls: DiscardPositiveImpls,
@@ -76,7 +76,7 @@ fn synthesize_auto_trait_impl<'tcx>(
7676
return None;
7777
}
7878

79-
let result = finder.find_auto_trait_generics(ty, param_env, trait_def_id, |info| {
79+
let result = finder.find_auto_trait_generics(ty, typing_env, trait_def_id, |info| {
8080
clean_param_env(cx, item_def_id, info.full_user_env, info.region_data, info.vid_to_region)
8181
});
8282

src/librustdoc/clean/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1817,9 +1817,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18171817
let ct = if let hir::ConstArgKind::Anon(hir::AnonConst { def_id, .. }) =
18181818
const_arg.kind
18191819
{
1820-
// Only anon consts can implicitly capture params.
1821-
// FIXME: is this correct behavior?
1822-
let typing_env = ty::TypingEnv::from_param_env(cx.tcx.param_env(*def_id));
1820+
let typing_env = ty::TypingEnv::post_analysis(cx.tcx, *def_id);
18231821
cx.tcx.normalize_erasing_regions(typing_env, ct)
18241822
} else {
18251823
ct

0 commit comments

Comments
 (0)