Skip to content

Commit 3501908

Browse files
author
Lukas Markeffsky
committed
don't consider regions
1 parent f5e53ec commit 3501908

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
23102310
);
23112311
let sized_obligation = obligation.with(tcx, sized_predicate);
23122312
if self_ty == tail
2313-
|| selcx.infcx.predicate_must_hold_considering_regions(&sized_obligation)
2313+
|| selcx.infcx.predicate_must_hold_modulo_regions(&sized_obligation)
23142314
{
23152315
// If the `self_ty` is `Sized`, then the metadata is `()`.
23162316
// We check this before projecting to the metadata of `tail`,

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
4141
/// not entirely accurate if inference variables are involved.
4242
///
4343
/// This version may conservatively fail when outlives obligations
44-
/// are required.
44+
/// are required. Therefore, this version should only be used for
45+
/// optimizations or diagnostics and be treated as if it can always
46+
/// return `false`.
4547
fn predicate_must_hold_considering_regions(
4648
&self,
4749
obligation: &PredicateObligation<'tcx>,

tests/ui/traits/pointee-normalize-equate.rs

-14
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,4 @@ fn wrapper_project<T: ?Sized + Project>(ptr: *const T::Assoc) -> *const WrapperP
3838
cast_same_meta(ptr)
3939
}
4040

41-
// In this example, `WrapperProject<&'a T>` is `Sized` modulo regions,
42-
// but `?Sized` considering regions.
43-
// Normalize `WrapperProject<&'a T>::Metadata` -> `<&'a T as Project>::Assoc::Metadata`
44-
// and don't require `WrapperProject<&'a T>: Sized`.
45-
fn sized_modulo_regions<'a, T: ?Sized + 'static>(
46-
ptr: *const <&'a T as Project>::Assoc,
47-
) -> *const WrapperProject<&'a T>
48-
where
49-
for<'b> &'b T: Project,
50-
WrapperProject<&'static T>: Sized,
51-
{
52-
cast_same_meta(ptr)
53-
}
54-
5541
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![feature(ptr_metadata)]
2+
3+
use std::ptr::{self, Pointee};
4+
5+
fn cast_same_meta<T: ?Sized, U: ?Sized>(ptr: *const T) -> *const U
6+
where
7+
T: Pointee<Metadata = <U as Pointee>::Metadata>,
8+
{
9+
let (thin, meta) = ptr.to_raw_parts();
10+
ptr::from_raw_parts(thin, meta)
11+
}
12+
13+
trait Project {
14+
type Assoc: ?Sized;
15+
}
16+
17+
struct WrapperProject<T: ?Sized + Project>(T::Assoc);
18+
19+
// In this example, `WrapperProject<&'a T>` is `Sized` modulo regions, but `?Sized`
20+
// considering regions.
21+
// Because normalization does not consider regions, `WrapperProject<&'a T>::Metadata`
22+
// is normalized to `()` instead of `<&'a T as Project>::Assoc::Metadata` and requires
23+
// `WrapperProject<&'a T>: Sized` and therefore `'a: 'static`.
24+
fn sized_modulo_regions<'a, T: ?Sized + 'static>(
25+
ptr: *const (),
26+
) -> *const WrapperProject<&'a T>
27+
where
28+
for<'b> &'b T: Project,
29+
WrapperProject<&'static T>: Sized,
30+
{
31+
cast_same_meta(ptr)
32+
}
33+
34+
fn main() {}

0 commit comments

Comments
 (0)