mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Add internal attribute and tests.
This commit is contained in:
parent
d2dc4276fd
commit
ab171c5279
@ -603,6 +603,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||
rustc_attr!(TEST, rustc_dump_program_clauses, AssumedUsed, template!(Word)),
|
||||
rustc_attr!(TEST, rustc_dump_env_program_clauses, AssumedUsed, template!(Word)),
|
||||
rustc_attr!(TEST, rustc_object_lifetime_default, AssumedUsed, template!(Word)),
|
||||
rustc_attr!(TEST, rustc_dump_vtable, AssumedUsed, template!(Word)),
|
||||
rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/)),
|
||||
gated!(
|
||||
omit_gdb_pretty_printer_section, AssumedUsed, template!(Word),
|
||||
|
@ -1047,6 +1047,7 @@ symbols! {
|
||||
rustc_dump_env_program_clauses,
|
||||
rustc_dump_program_clauses,
|
||||
rustc_dump_user_substs,
|
||||
rustc_dump_vtable,
|
||||
rustc_error,
|
||||
rustc_evaluate_where_clauses,
|
||||
rustc_expected_cgu_reuse,
|
||||
|
@ -34,7 +34,7 @@ use rustc_middle::ty::{
|
||||
self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, VtblEntry, WithConstness,
|
||||
COMMON_VTABLE_ENTRIES,
|
||||
};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{sym, Span};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use std::fmt::Debug;
|
||||
@ -614,6 +614,11 @@ fn prepare_vtable_segments<'tcx, T>(
|
||||
}
|
||||
}
|
||||
|
||||
fn dump_vtable_entries<'tcx>(tcx: TyCtxt<'tcx>, entries: &[VtblEntry<'tcx>]) {
|
||||
let msg = format!("Vtable Entries: {:#?}", entries);
|
||||
tcx.sess.struct_span_err(rustc_span::DUMMY_SP, &msg).emit();
|
||||
}
|
||||
|
||||
/// Given a trait `trait_ref`, iterates the vtable entries
|
||||
/// that come from `trait_ref`, including its supertraits.
|
||||
fn vtable_entries<'tcx>(
|
||||
@ -691,6 +696,11 @@ fn vtable_entries<'tcx>(
|
||||
};
|
||||
|
||||
let _ = prepare_vtable_segments(tcx, trait_ref, vtable_segment_callback);
|
||||
|
||||
if tcx.has_attr(trait_ref.def_id(), sym::rustc_dump_vtable) {
|
||||
dump_vtable_entries(tcx, &entries);
|
||||
}
|
||||
|
||||
tcx.arena.alloc_from_iter(entries.into_iter())
|
||||
}
|
||||
|
||||
|
39
src/test/ui/traits/vtable/vtable-diamond.rs
Normal file
39
src/test/ui/traits/vtable/vtable-diamond.rs
Normal file
@ -0,0 +1,39 @@
|
||||
// build-fail
|
||||
//~^ error Vtable
|
||||
//~^^ error Vtable
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#[rustc_dump_vtable]
|
||||
trait A {
|
||||
fn foo_a(&self) {}
|
||||
}
|
||||
|
||||
#[rustc_dump_vtable]
|
||||
trait B: A {
|
||||
fn foo_b(&self) {}
|
||||
}
|
||||
|
||||
#[rustc_dump_vtable]
|
||||
trait C: A {
|
||||
fn foo_c(&self) {}
|
||||
}
|
||||
|
||||
#[rustc_dump_vtable]
|
||||
trait D: B + C {
|
||||
fn foo_d(&self) {}
|
||||
}
|
||||
|
||||
struct S;
|
||||
|
||||
impl A for S {}
|
||||
impl B for S {}
|
||||
impl C for S {}
|
||||
impl D for S {}
|
||||
|
||||
fn foo(d: &dyn D) {
|
||||
d.foo_d();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo(&S);
|
||||
}
|
56
src/test/ui/traits/vtable/vtable-diamond.stderr
Normal file
56
src/test/ui/traits/vtable/vtable-diamond.stderr
Normal file
@ -0,0 +1,56 @@
|
||||
error: Vtable Entries: [
|
||||
MetadataDropInPlace,
|
||||
MetadataSize,
|
||||
MetadataAlign,
|
||||
Method(
|
||||
DefId(0:4 ~ vtable_diamond[4564]::A::foo_a),
|
||||
[
|
||||
S,
|
||||
],
|
||||
),
|
||||
Method(
|
||||
DefId(0:6 ~ vtable_diamond[4564]::B::foo_b),
|
||||
[
|
||||
S,
|
||||
],
|
||||
),
|
||||
Method(
|
||||
DefId(0:8 ~ vtable_diamond[4564]::C::foo_c),
|
||||
[
|
||||
S,
|
||||
],
|
||||
),
|
||||
TraitVPtr(
|
||||
Binder(
|
||||
C,
|
||||
[],
|
||||
),
|
||||
),
|
||||
Method(
|
||||
DefId(0:10 ~ vtable_diamond[4564]::D::foo_d),
|
||||
[
|
||||
S,
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
error: Vtable Entries: [
|
||||
MetadataDropInPlace,
|
||||
MetadataSize,
|
||||
MetadataAlign,
|
||||
Method(
|
||||
DefId(0:4 ~ vtable_diamond[4564]::A::foo_a),
|
||||
[
|
||||
S,
|
||||
],
|
||||
),
|
||||
Method(
|
||||
DefId(0:8 ~ vtable_diamond[4564]::C::foo_c),
|
||||
[
|
||||
S,
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
31
src/test/ui/traits/vtable/vtable-multiple.rs
Normal file
31
src/test/ui/traits/vtable/vtable-multiple.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// build-fail
|
||||
//~^ error Vtable
|
||||
//~^^ error Vtable
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#[rustc_dump_vtable]
|
||||
trait A {
|
||||
fn foo_a(&self) {}
|
||||
}
|
||||
|
||||
#[rustc_dump_vtable]
|
||||
trait B {
|
||||
fn foo_b(&self) {}
|
||||
}
|
||||
|
||||
#[rustc_dump_vtable]
|
||||
trait C: A + B {
|
||||
fn foo_c(&self) {}
|
||||
}
|
||||
|
||||
struct S;
|
||||
|
||||
impl A for S {}
|
||||
impl B for S {}
|
||||
impl C for S {}
|
||||
|
||||
fn foo(c: &dyn C) {}
|
||||
|
||||
fn main() {
|
||||
foo(&S);
|
||||
}
|
44
src/test/ui/traits/vtable/vtable-multiple.stderr
Normal file
44
src/test/ui/traits/vtable/vtable-multiple.stderr
Normal file
@ -0,0 +1,44 @@
|
||||
error: Vtable Entries: [
|
||||
MetadataDropInPlace,
|
||||
MetadataSize,
|
||||
MetadataAlign,
|
||||
Method(
|
||||
DefId(0:4 ~ vtable_multiple[5246]::A::foo_a),
|
||||
[
|
||||
S,
|
||||
],
|
||||
),
|
||||
Method(
|
||||
DefId(0:6 ~ vtable_multiple[5246]::B::foo_b),
|
||||
[
|
||||
S,
|
||||
],
|
||||
),
|
||||
TraitVPtr(
|
||||
Binder(
|
||||
B,
|
||||
[],
|
||||
),
|
||||
),
|
||||
Method(
|
||||
DefId(0:8 ~ vtable_multiple[5246]::C::foo_c),
|
||||
[
|
||||
S,
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
error: Vtable Entries: [
|
||||
MetadataDropInPlace,
|
||||
MetadataSize,
|
||||
MetadataAlign,
|
||||
Method(
|
||||
DefId(0:6 ~ vtable_multiple[5246]::B::foo_b),
|
||||
[
|
||||
S,
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user