Skip to content

Commit 7792b9a

Browse files
committed
Fix pretty print tests
Also add a check that the API works as expected for drivers calling name on an std enum.
1 parent 8072264 commit 7792b9a

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

compiler/rustc_public/src/ty.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,9 @@ pub struct VariantDef {
876876
}
877877

878878
impl VariantDef {
879+
/// The name of the variant, struct or union.
880+
///
881+
/// This will not include the name of the enum or qualified path.
879882
pub fn name(&self) -> Symbol {
880883
with(|cx| cx.variant_name(*self))
881884
}

tests/ui-fulldeps/rustc_public/check_def_ty.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ extern crate rustc_middle;
1515
extern crate rustc_driver;
1616
extern crate rustc_interface;
1717
extern crate rustc_public;
18+
extern crate rustc_public_bridge;
1819

19-
use rustc_public::ty::{ForeignItemKind, Ty};
20+
use rustc_public::ty::VariantIdx;
21+
use rustc_public::ty::{ForeignItemKind, RigidTy, Ty};
2022
use rustc_public::*;
23+
use rustc_public_bridge::IndexedVal;
2124
use std::io::Write;
2225
use std::ops::ControlFlow;
2326

@@ -32,6 +35,14 @@ fn test_def_tys() -> ControlFlow<()> {
3235
match item.trimmed_name().as_str() {
3336
"STATIC_STR" => assert!(ty.kind().is_ref()),
3437
"CONST_U32" => assert!(ty.kind().is_integral()),
38+
"NONE" => {
39+
let RigidTy::Adt(adt, _) = *ty.kind().rigid().unwrap() else { panic!() };
40+
// Definition names include the entire path.
41+
assert_eq!(adt.name(), "std::option::Option");
42+
// Variant name only includes the actual variant name.
43+
// I know, probably not the best name schema. o.O
44+
assert_eq!(adt.variant(VariantIdx::to_val(0)).unwrap().name(), "None");
45+
}
3546
"main" => check_fn_def(ty),
3647
_ => unreachable!("Unexpected item: `{item:?}`"),
3748
}
@@ -92,6 +103,7 @@ fn generate_input(path: &str) -> std::io::Result<()> {
92103
r#"
93104
static STATIC_STR: &str = "foo";
94105
const CONST_U32: u32 = 0u32;
106+
static NONE: Option<i32> = Option::None;
95107
96108
fn main() {{
97109
let _c = core::char::from_u32(99);

tests/ui/rustc_public-ir-print/async-closure.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn foo::{closure#0}::{closure#0}(_1: Pin<&mut {async closure body@$DIR/async-clo
5656
_3 = (*_4);
5757
_5 = ();
5858
StorageDead(_3);
59-
_0 = std::task::Poll::Ready(move _5);
59+
_0 = Poll::Ready(move _5);
6060
discriminant((*_7)) = 1;
6161
return;
6262
}
@@ -88,7 +88,7 @@ fn foo::{closure#0}::{synthetic#0}(_1: Pin<&mut {async closure body@$DIR/async-c
8888
_3 = (*_4);
8989
_5 = ();
9090
StorageDead(_3);
91-
_0 = std::task::Poll::Ready(move _5);
91+
_0 = Poll::Ready(move _5);
9292
discriminant((*_7)) = 1;
9393
return;
9494
}

tests/ui/rustc_public-ir-print/operands.stdout

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn operands(_1: u8) -> () {
219219
_27 = &(*_16);
220220
_26 = &(*_27);
221221
StorageLive(_28);
222-
_28 = std::option::Option::None;
222+
_28 = Option::None;
223223
_22 = core::panicking::assert_failed::<u8, u8>(move _23, move _24, move _26, move _28) -> unwind unreachable;
224224
}
225225
bb6: {
@@ -281,7 +281,7 @@ fn operands(_1: u8) -> () {
281281
_47 = &(*_36);
282282
_46 = &(*_47);
283283
StorageLive(_48);
284-
_48 = std::option::Option::None;
284+
_48 = Option::None;
285285
_42 = core::panicking::assert_failed::<u8, u8>(move _43, move _44, move _46, move _48) -> unwind unreachable;
286286
}
287287
bb8: {
@@ -318,7 +318,7 @@ fn operands(_1: u8) -> () {
318318
_70 = &(*_59);
319319
_69 = &(*_70);
320320
StorageLive(_71);
321-
_71 = std::option::Option::None;
321+
_71 = Option::None;
322322
_65 = core::panicking::assert_failed::<u8, u8>(move _66, move _67, move _69, move _71) -> unwind unreachable;
323323
}
324324
bb10: {
@@ -393,7 +393,7 @@ fn operands(_1: u8) -> () {
393393
_94 = &(*_83);
394394
_93 = &(*_94);
395395
StorageLive(_95);
396-
_95 = std::option::Option::None;
396+
_95 = Option::None;
397397
_89 = core::panicking::assert_failed::<usize, usize>(move _90, move _91, move _93, move _95) -> unwind unreachable;
398398
}
399399
}

0 commit comments

Comments
 (0)