Skip to content

when checking pointee metadata, canonicalize the Sized check #95315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use super::{Normalized, NormalizedTy, ProjectionCacheEntry, ProjectionCacheKey};
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
use crate::traits::error_reporting::InferCtxtExt as _;
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
use crate::traits::select::ProjectionMatchesProjection;
use rustc_data_structures::sso::SsoHashSet;
use rustc_data_structures::stack::ensure_sufficient_stack;
Expand Down Expand Up @@ -1515,7 +1516,16 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// type parameters, opaques, and unnormalized projections have pointer
// metadata if they're known (e.g. by the param_env) to be sized
ty::Param(_) | ty::Projection(..) | ty::Opaque(..)
if tail.is_sized(selcx.tcx().at(obligation.cause.span), obligation.param_env) =>
if selcx.infcx().predicate_must_hold_modulo_regions(
&obligation.with(
ty::Binder::dummy(ty::TraitRef::new(
selcx.tcx().require_lang_item(LangItem::Sized, None),
selcx.tcx().mk_substs_trait(self_ty, &[]),
))
.without_const()
.to_predicate(selcx.tcx()),
),
) =>
{
true
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/traits/issue-95311.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check-pass

// Test to check that pointee trait doesn't let region variables escape into the cache

#![feature(ptr_metadata)]

trait Bar: Sized + 'static {}

struct Foo<B: Bar> {
marker: std::marker::PhantomData<B>,
}

impl<B: Bar> Foo<B> {
fn foo<T: ?Sized>(value: &T) {
std::ptr::metadata(value);
}
}

fn main() {}