mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 14:01:51 +00:00
Rollup merge of #129179 - compiler-errors:cfi-erase-transparent, r=davidtwco
CFI: Erase regions when projecting ADT to its transparent non-1zst field The output from `FieldDef::ty` (or `TyCtxt::type_of`) may have free regions (well, `'static`) -- erase it. Fixes #129169 Fixes #123685
This commit is contained in:
commit
7da4b2d82a
@ -146,7 +146,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for TransformTy<'tcx> {
|
||||
!is_zst
|
||||
});
|
||||
if let Some(field) = field {
|
||||
let ty0 = self.tcx.type_of(field.did).instantiate(self.tcx, args);
|
||||
let ty0 = self.tcx.erase_regions(field.ty(self.tcx, args));
|
||||
// Generalize any repr(transparent) user-defined type that is either a
|
||||
// pointer or reference, and either references itself or any other type that
|
||||
// contains or references itself, to avoid a reference cycle.
|
||||
|
18
tests/ui/sanitizer/cfi/transparent-has-regions.rs
Normal file
18
tests/ui/sanitizer/cfi/transparent-has-regions.rs
Normal file
@ -0,0 +1,18 @@
|
||||
//@ needs-sanitizer-cfi
|
||||
//@ compile-flags: -Ccodegen-units=1 -Clto -Ctarget-feature=-crt-static -Zsanitizer=cfi
|
||||
//@ no-prefer-dynamic
|
||||
//@ only-x86_64-unknown-linux-gnu
|
||||
//@ build-pass
|
||||
|
||||
pub trait Trait {}
|
||||
|
||||
impl Trait for i32 {}
|
||||
|
||||
#[repr(transparent)]
|
||||
struct BoxedTrait(Box<dyn Trait + 'static>);
|
||||
|
||||
fn hello(x: BoxedTrait) {}
|
||||
|
||||
fn main() {
|
||||
hello(BoxedTrait(Box::new(1)));
|
||||
}
|
Loading…
Reference in New Issue
Block a user