Skip to content

Commit 3624f1c

Browse files
when checking pointee metadata, canonicalize the Sized query
1 parent 3fe3b89 commit 3624f1c

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;
@@ -1515,7 +1516,16 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
15151516
// type parameters, opaques, and unnormalized projections have pointer
15161517
// metadata if they're known (e.g. by the param_env) to be sized
15171518
ty::Param(_) | ty::Projection(..) | ty::Opaque(..)
1518-
if tail.is_sized(selcx.tcx().at(obligation.cause.span), obligation.param_env) =>
1519+
if selcx.infcx().predicate_must_hold_modulo_regions(
1520+
&obligation.with(
1521+
ty::Binder::dummy(ty::TraitRef::new(
1522+
selcx.tcx().require_lang_item(LangItem::Sized, None),
1523+
selcx.tcx().mk_substs_trait(self_ty, &[]),
1524+
))
1525+
.without_const()
1526+
.to_predicate(selcx.tcx()),
1527+
),
1528+
) =>
15191529
{
15201530
true
15211531
}

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)