rustdoc: yeet TypingEnv::from_param_env

This commit is contained in:
lcnr 2024-11-19 18:07:55 +01:00
parent f74951fdf1
commit 4813fda2e6
3 changed files with 11 additions and 18 deletions

View file

@ -9,7 +9,6 @@ use rustc_data_structures::unord::UnordSet;
use rustc_infer::infer::DefineOpaqueTypes; use rustc_infer::infer::DefineOpaqueTypes;
use rustc_middle::ty::{Region, RegionVid}; use rustc_middle::ty::{Region, RegionVid};
use tracing::debug; use tracing::debug;
use ty::TypingMode;
use super::*; use super::*;
use crate::errors::UnableToConstructConstantValue; use crate::errors::UnableToConstructConstantValue;
@ -71,7 +70,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
pub fn find_auto_trait_generics<A>( pub fn find_auto_trait_generics<A>(
&self, &self,
ty: Ty<'tcx>, ty: Ty<'tcx>,
orig_env: ty::ParamEnv<'tcx>, typing_env: ty::TypingEnv<'tcx>,
trait_did: DefId, trait_did: DefId,
mut auto_trait_callback: impl FnMut(AutoTraitInfo<'tcx>) -> A, mut auto_trait_callback: impl FnMut(AutoTraitInfo<'tcx>) -> A,
) -> AutoTraitResult<A> { ) -> AutoTraitResult<A> {
@ -79,7 +78,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
let trait_ref = ty::TraitRef::new(tcx, trait_did, [ty]); let trait_ref = ty::TraitRef::new(tcx, trait_did, [ty]);
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis()); let (infcx, orig_env) = tcx.infer_ctxt().build_with_typing_env(typing_env);
let mut selcx = SelectionContext::new(&infcx); let mut selcx = SelectionContext::new(&infcx);
for polarity in [ty::PredicatePolarity::Positive, ty::PredicatePolarity::Negative] { for polarity in [ty::PredicatePolarity::Positive, ty::PredicatePolarity::Negative] {
let result = selcx.select(&Obligation::new( let result = selcx.select(&Obligation::new(
@ -89,17 +88,13 @@ impl<'tcx> AutoTraitFinder<'tcx> {
ty::TraitPredicate { trait_ref, polarity }, ty::TraitPredicate { trait_ref, polarity },
)); ));
if let Ok(Some(ImplSource::UserDefined(_))) = result { if let Ok(Some(ImplSource::UserDefined(_))) = result {
debug!( debug!("find_auto_trait_generics({trait_ref:?}): manual impl found, bailing out");
"find_auto_trait_generics({:?}): \
manual impl found, bailing out",
trait_ref
);
// If an explicit impl exists, it always takes priority over an auto impl // If an explicit impl exists, it always takes priority over an auto impl
return AutoTraitResult::ExplicitImpl; return AutoTraitResult::ExplicitImpl;
} }
} }
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis()); let (infcx, orig_env) = tcx.infer_ctxt().build_with_typing_env(typing_env);
let mut fresh_preds = FxIndexSet::default(); let mut fresh_preds = FxIndexSet::default();
// Due to the way projections are handled by SelectionContext, we need to run // Due to the way projections are handled by SelectionContext, we need to run

View file

@ -21,7 +21,7 @@ pub(crate) fn synthesize_auto_trait_impls<'tcx>(
item_def_id: DefId, item_def_id: DefId,
) -> Vec<clean::Item> { ) -> Vec<clean::Item> {
let tcx = cx.tcx; let tcx = cx.tcx;
let param_env = tcx.param_env(item_def_id); let typing_env = ty::TypingEnv::non_body_analysis(tcx, item_def_id);
let ty = tcx.type_of(item_def_id).instantiate_identity(); let ty = tcx.type_of(item_def_id).instantiate_identity();
let finder = auto_trait::AutoTraitFinder::new(tcx); let finder = auto_trait::AutoTraitFinder::new(tcx);
@ -34,7 +34,7 @@ pub(crate) fn synthesize_auto_trait_impls<'tcx>(
cx, cx,
ty, ty,
trait_def_id, trait_def_id,
param_env, typing_env,
item_def_id, item_def_id,
&finder, &finder,
DiscardPositiveImpls::No, DiscardPositiveImpls::No,
@ -42,13 +42,13 @@ pub(crate) fn synthesize_auto_trait_impls<'tcx>(
}) })
.collect(); .collect();
// We are only interested in case the type *doesn't* implement the `Sized` trait. // We are only interested in case the type *doesn't* implement the `Sized` trait.
if !ty.is_sized(tcx, ty::TypingEnv::from_param_env(param_env)) if !ty.is_sized(tcx, typing_env)
&& let Some(sized_trait_def_id) = tcx.lang_items().sized_trait() && let Some(sized_trait_def_id) = tcx.lang_items().sized_trait()
&& let Some(impl_item) = synthesize_auto_trait_impl( && let Some(impl_item) = synthesize_auto_trait_impl(
cx, cx,
ty, ty,
sized_trait_def_id, sized_trait_def_id,
param_env, typing_env,
item_def_id, item_def_id,
&finder, &finder,
DiscardPositiveImpls::Yes, DiscardPositiveImpls::Yes,
@ -64,7 +64,7 @@ fn synthesize_auto_trait_impl<'tcx>(
cx: &mut DocContext<'tcx>, cx: &mut DocContext<'tcx>,
ty: Ty<'tcx>, ty: Ty<'tcx>,
trait_def_id: DefId, trait_def_id: DefId,
param_env: ty::ParamEnv<'tcx>, typing_env: ty::TypingEnv<'tcx>,
item_def_id: DefId, item_def_id: DefId,
finder: &auto_trait::AutoTraitFinder<'tcx>, finder: &auto_trait::AutoTraitFinder<'tcx>,
discard_positive_impls: DiscardPositiveImpls, discard_positive_impls: DiscardPositiveImpls,
@ -76,7 +76,7 @@ fn synthesize_auto_trait_impl<'tcx>(
return None; return None;
} }
let result = finder.find_auto_trait_generics(ty, param_env, trait_def_id, |info| { let result = finder.find_auto_trait_generics(ty, typing_env, trait_def_id, |info| {
clean_param_env(cx, item_def_id, info.full_user_env, info.region_data, info.vid_to_region) clean_param_env(cx, item_def_id, info.full_user_env, info.region_data, info.vid_to_region)
}); });

View file

@ -1817,9 +1817,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
let ct = if let hir::ConstArgKind::Anon(hir::AnonConst { def_id, .. }) = let ct = if let hir::ConstArgKind::Anon(hir::AnonConst { def_id, .. }) =
const_arg.kind const_arg.kind
{ {
// Only anon consts can implicitly capture params. let typing_env = ty::TypingEnv::post_analysis(cx.tcx, *def_id);
// FIXME: is this correct behavior?
let typing_env = ty::TypingEnv::from_param_env(cx.tcx.param_env(*def_id));
cx.tcx.normalize_erasing_regions(typing_env, ct) cx.tcx.normalize_erasing_regions(typing_env, ct)
} else { } else {
ct ct