Skip to content

Commit e7575f9

Browse files
committed
Auto merge of #95315 - compiler-errors:pointee-fix, r=pnkfelix
when checking pointee metadata, canonicalize the `Sized` check Use `infcx.predicate_must_hold_modulo_regions` with a `Sized` obligation instead of just calling `ty.is_sized`, because the latter does not canonicalize region and type vars (and in the test case I added in this PR, there's a region var in the `ParamEnv`). Fixes #95311
2 parents e371eeb + 3624f1c commit e7575f9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use super::{Normalized, NormalizedTy, ProjectionCacheEntry, ProjectionCacheKey};
1919
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
2020
use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
2121
use crate::traits::error_reporting::InferCtxtExt as _;
22+
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
2223
use crate::traits::select::ProjectionMatchesProjection;
2324
use rustc_data_structures::sso::SsoHashSet;
2425
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -1562,7 +1563,16 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
15621563
// type parameters, opaques, and unnormalized projections have pointer
15631564
// metadata if they're known (e.g. by the param_env) to be sized
15641565
ty::Param(_) | ty::Projection(..) | ty::Opaque(..)
1565-
if tail.is_sized(selcx.tcx().at(obligation.cause.span), obligation.param_env) =>
1566+
if selcx.infcx().predicate_must_hold_modulo_regions(
1567+
&obligation.with(
1568+
ty::Binder::dummy(ty::TraitRef::new(
1569+
selcx.tcx().require_lang_item(LangItem::Sized, None),
1570+
selcx.tcx().mk_substs_trait(self_ty, &[]),
1571+
))
1572+
.without_const()
1573+
.to_predicate(selcx.tcx()),
1574+
),
1575+
) =>
15661576
{
15671577
true
15681578
}

src/test/ui/traits/issue-95311.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check-pass
2+
3+
// Test to check that pointee trait doesn't let region variables escape into the cache
4+
5+
#![feature(ptr_metadata)]
6+
7+
trait Bar: Sized + 'static {}
8+
9+
struct Foo<B: Bar> {
10+
marker: std::marker::PhantomData<B>,
11+
}
12+
13+
impl<B: Bar> Foo<B> {
14+
fn foo<T: ?Sized>(value: &T) {
15+
std::ptr::metadata(value);
16+
}
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)