Skip to content

Commit

Permalink
don't consider regions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Markeffsky committed Jan 27, 2024
1 parent f5e53ec commit 3501908
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2310,7 +2310,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
);
let sized_obligation = obligation.with(tcx, sized_predicate);
if self_ty == tail
|| selcx.infcx.predicate_must_hold_considering_regions(&sized_obligation)
|| selcx.infcx.predicate_must_hold_modulo_regions(&sized_obligation)
{
// If the `self_ty` is `Sized`, then the metadata is `()`.
// We check this before projecting to the metadata of `tail`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
/// not entirely accurate if inference variables are involved.
///
/// This version may conservatively fail when outlives obligations
/// are required.
/// are required. Therefore, this version should only be used for
/// optimizations or diagnostics and be treated as if it can always
/// return `false`.
fn predicate_must_hold_considering_regions(
&self,
obligation: &PredicateObligation<'tcx>,
Expand Down
14 changes: 0 additions & 14 deletions tests/ui/traits/pointee-normalize-equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,4 @@ fn wrapper_project<T: ?Sized + Project>(ptr: *const T::Assoc) -> *const WrapperP
cast_same_meta(ptr)
}

// In this example, `WrapperProject<&'a T>` is `Sized` modulo regions,
// but `?Sized` considering regions.
// Normalize `WrapperProject<&'a T>::Metadata` -> `<&'a T as Project>::Assoc::Metadata`
// and don't require `WrapperProject<&'a T>: Sized`.
fn sized_modulo_regions<'a, T: ?Sized + 'static>(
ptr: *const <&'a T as Project>::Assoc,
) -> *const WrapperProject<&'a T>
where
for<'b> &'b T: Project,
WrapperProject<&'static T>: Sized,
{
cast_same_meta(ptr)
}

fn main() {}
34 changes: 34 additions & 0 deletions tests/ui/traits/pointee-normalize-modulo-regions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#![feature(ptr_metadata)]

use std::ptr::{self, Pointee};

fn cast_same_meta<T: ?Sized, U: ?Sized>(ptr: *const T) -> *const U
where
T: Pointee<Metadata = <U as Pointee>::Metadata>,
{
let (thin, meta) = ptr.to_raw_parts();
ptr::from_raw_parts(thin, meta)
}

trait Project {
type Assoc: ?Sized;
}

struct WrapperProject<T: ?Sized + Project>(T::Assoc);

// In this example, `WrapperProject<&'a T>` is `Sized` modulo regions, but `?Sized`
// considering regions.
// Because normalization does not consider regions, `WrapperProject<&'a T>::Metadata`
// is normalized to `()` instead of `<&'a T as Project>::Assoc::Metadata` and requires
// `WrapperProject<&'a T>: Sized` and therefore `'a: 'static`.
fn sized_modulo_regions<'a, T: ?Sized + 'static>(
ptr: *const (),
) -> *const WrapperProject<&'a T>
where
for<'b> &'b T: Project,
WrapperProject<&'static T>: Sized,
{
cast_same_meta(ptr)
}

fn main() {}

0 comments on commit 3501908

Please sign in to comment.