diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 06744ae6e2426..6a4122ad67176 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -105,7 +105,7 @@ define_helper!( /// /// Overrides `with_crate_prefix`. - // This function is not currently used in-tree, but it's used by a downstream rustc-driver in + // This function is used by `rustc_public` and downstream rustc-driver in // Ferrocene. Please check with them before removing it. fn with_resolve_crate_name(CrateNamePrefixGuard, SHOULD_PREFIX_WITH_CRATE_NAME); /// Adds the `crate::` prefix to paths where appropriate. diff --git a/compiler/rustc_public/src/mir/pretty.rs b/compiler/rustc_public/src/mir/pretty.rs index d80e227f5a9ce..08e4e0c7e0f9e 100644 --- a/compiler/rustc_public/src/mir/pretty.rs +++ b/compiler/rustc_public/src/mir/pretty.rs @@ -412,7 +412,7 @@ fn pretty_aggregate( } AggregateKind::Adt(def, var, _, _, _) => { if def.kind() == AdtKind::Enum { - write!(writer, "{}::{}", def.name(), def.variant(*var).unwrap().name())?; + write!(writer, "{}::{}", def.trimmed_name(), def.variant(*var).unwrap().name())?; } else { write!(writer, "{}", def.variant(*var).unwrap().name())?; } diff --git a/compiler/rustc_public/src/ty.rs b/compiler/rustc_public/src/ty.rs index f24d98f7e5521..14656a2e594ad 100644 --- a/compiler/rustc_public/src/ty.rs +++ b/compiler/rustc_public/src/ty.rs @@ -876,6 +876,9 @@ pub struct VariantDef { } impl VariantDef { + /// The name of the variant, struct or union. + /// + /// This will not include the name of the enum or qualified path. pub fn name(&self) -> Symbol { with(|cx| cx.variant_name(*self)) } diff --git a/compiler/rustc_public_bridge/src/context/impls.rs b/compiler/rustc_public_bridge/src/context/impls.rs index 25be9e7b30415..c2a5d861925bc 100644 --- a/compiler/rustc_public_bridge/src/context/impls.rs +++ b/compiler/rustc_public_bridge/src/context/impls.rs @@ -10,7 +10,9 @@ use rustc_hir::{Attribute, LangItem}; use rustc_middle::mir::interpret::{AllocId, ConstAllocation, ErrorHandled, GlobalAlloc, Scalar}; use rustc_middle::mir::{BinOp, Body, Const as MirConst, ConstValue, UnOp}; use rustc_middle::ty::layout::{FnAbiOf, LayoutOf}; -use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths}; +use rustc_middle::ty::print::{ + with_forced_trimmed_paths, with_no_trimmed_paths, with_resolve_crate_name, +}; use rustc_middle::ty::util::Discr; use rustc_middle::ty::{ AdtDef, AdtKind, AssocItem, Binder, ClosureKind, CoroutineArgsExt, EarlyBinder, @@ -264,7 +266,8 @@ impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> { if trimmed { with_forced_trimmed_paths!(self.tcx.def_path_str(def_id)) } else { - with_no_trimmed_paths!(self.tcx.def_path_str(def_id)) + // For local definitions, we need to prepend with crate name. + with_resolve_crate_name!(with_no_trimmed_paths!(self.tcx.def_path_str(def_id))) } } @@ -719,9 +722,9 @@ impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> { self.tcx.def_path_str_with_args(instance.def_id(), instance.args) ) } else { - with_no_trimmed_paths!( + with_resolve_crate_name!(with_no_trimmed_paths!( self.tcx.def_path_str_with_args(instance.def_id(), instance.args) - ) + )) } } diff --git a/tests/ui-fulldeps/rustc_public/check_abi.rs b/tests/ui-fulldeps/rustc_public/check_abi.rs index 57c8377ea3675..b3519a2c60eda 100644 --- a/tests/ui-fulldeps/rustc_public/check_abi.rs +++ b/tests/ui-fulldeps/rustc_public/check_abi.rs @@ -9,10 +9,10 @@ #![feature(assert_matches)] #![feature(ascii_char, ascii_char_variants)] -extern crate rustc_hir; -extern crate rustc_middle; extern crate rustc_driver; +extern crate rustc_hir; extern crate rustc_interface; +extern crate rustc_middle; #[macro_use] extern crate rustc_public; @@ -39,7 +39,7 @@ fn test_stable_mir() -> ControlFlow<()> { let items = rustc_public::all_local_items(); // Test fn_abi - let target_fn = *get_item(&items, (ItemKind::Fn, "fn_abi")).unwrap(); + let target_fn = *get_item(&items, (ItemKind::Fn, "input::fn_abi")).unwrap(); let instance = Instance::try_from(target_fn).unwrap(); let fn_abi = instance.fn_abi().unwrap(); assert_eq!(fn_abi.conv, CallConvention::Rust); @@ -51,11 +51,11 @@ fn test_stable_mir() -> ControlFlow<()> { check_result(&fn_abi.ret); // Test variadic function. - let variadic_fn = *get_item(&items, (ItemKind::Fn, "variadic_fn")).unwrap(); + let variadic_fn = *get_item(&items, (ItemKind::Fn, "input::variadic_fn")).unwrap(); check_variadic(variadic_fn); // Extract function pointers. - let fn_ptr_holder = *get_item(&items, (ItemKind::Fn, "fn_ptr_holder")).unwrap(); + let fn_ptr_holder = *get_item(&items, (ItemKind::Fn, "input::fn_ptr_holder")).unwrap(); let fn_ptr_holder_instance = Instance::try_from(fn_ptr_holder).unwrap(); let body = fn_ptr_holder_instance.body().unwrap(); let args = body.arg_locals(); diff --git a/tests/ui-fulldeps/rustc_public/check_allocation.rs b/tests/ui-fulldeps/rustc_public/check_allocation.rs index 70e4ee3fe3477..3a0a2382be728 100644 --- a/tests/ui-fulldeps/rustc_public/check_allocation.rs +++ b/tests/ui-fulldeps/rustc_public/check_allocation.rs @@ -40,11 +40,11 @@ const CRATE_NAME: &str = "input"; fn test_stable_mir() -> ControlFlow<()> { // Find items in the local crate. let items = rustc_public::all_local_items(); - check_foo(*get_item(&items, (ItemKind::Static, "FOO")).unwrap()); - check_bar(*get_item(&items, (ItemKind::Static, "BAR")).unwrap()); - check_len(*get_item(&items, (ItemKind::Static, "LEN")).unwrap()); - check_cstr(*get_item(&items, (ItemKind::Static, "C_STR")).unwrap()); - check_other_consts(*get_item(&items, (ItemKind::Fn, "other_consts")).unwrap()); + check_foo(*get_item(&items, (ItemKind::Static, "input::FOO")).unwrap()); + check_bar(*get_item(&items, (ItemKind::Static, "input::BAR")).unwrap()); + check_len(*get_item(&items, (ItemKind::Static, "input::LEN")).unwrap()); + check_cstr(*get_item(&items, (ItemKind::Static, "input::C_STR")).unwrap()); + check_other_consts(*get_item(&items, (ItemKind::Fn, "input::other_consts")).unwrap()); ControlFlow::Continue(()) } diff --git a/tests/ui-fulldeps/rustc_public/check_assoc_items.rs b/tests/ui-fulldeps/rustc_public/check_assoc_items.rs index 1557991f8cabf..194d6be88a764 100644 --- a/tests/ui-fulldeps/rustc_public/check_assoc_items.rs +++ b/tests/ui-fulldeps/rustc_public/check_assoc_items.rs @@ -77,7 +77,7 @@ fn test_assoc_items() -> ControlFlow<()> { /// Note that order doesn't matter. fn check_items(items: &[T], expected: &[&str]) { let expected: HashSet<_> = expected.iter().map(|s| s.to_string()).collect(); - let item_names: HashSet<_> = items.iter().map(|item| item.name()).collect(); + let item_names: HashSet<_> = items.iter().map(|item| item.trimmed_name()).collect(); assert_eq!(item_names, expected); } diff --git a/tests/ui-fulldeps/rustc_public/check_attribute.rs b/tests/ui-fulldeps/rustc_public/check_attribute.rs index 0c34ac4dfe957..393ff4c63c5ad 100644 --- a/tests/ui-fulldeps/rustc_public/check_attribute.rs +++ b/tests/ui-fulldeps/rustc_public/check_attribute.rs @@ -38,16 +38,13 @@ fn test_tool(items: &CrateItems) { assert_eq!(rustfmt_attrs[0].as_str(), "#[rustfmt::skip]\n"); let clippy_fn = *get_item(&items, "complex_fn").unwrap(); - let clippy_attrs = clippy_fn.tool_attrs(&["clippy".to_string(), - "cyclomatic_complexity".to_string()]); + let clippy_attrs = + clippy_fn.tool_attrs(&["clippy".to_string(), "cyclomatic_complexity".to_string()]); assert_eq!(clippy_attrs[0].as_str(), "#[clippy::cyclomatic_complexity = \"100\"]\n"); } -fn get_item<'a>( - items: &'a CrateItems, - name: &str, -) -> Option<&'a rustc_public::CrateItem> { - items.iter().find(|crate_item| crate_item.name() == name) +fn get_item<'a>(items: &'a CrateItems, name: &str) -> Option<&'a rustc_public::CrateItem> { + items.iter().find(|crate_item| crate_item.trimmed_name() == name) } /// This test will generate and analyze a dummy crate using the stable mir. diff --git a/tests/ui-fulldeps/rustc_public/check_coroutine_body.rs b/tests/ui-fulldeps/rustc_public/check_coroutine_body.rs index 725b538b0fe51..75f4f1f5bf4c0 100644 --- a/tests/ui-fulldeps/rustc_public/check_coroutine_body.rs +++ b/tests/ui-fulldeps/rustc_public/check_coroutine_body.rs @@ -29,11 +29,7 @@ fn test_coroutine_body() -> ControlFlow<()> { if let Some(body) = crate_items.iter().find_map(|item| { let item_ty = item.ty(); if let TyKind::RigidTy(RigidTy::Coroutine(def, ..)) = &item_ty.kind() { - if def.0.name() == "gbc::{closure#0}".to_string() { - def.body() - } else { - None - } + if def.0.trimmed_name() == "gbc::{closure#0}".to_string() { def.body() } else { None } } else { None } @@ -51,26 +47,23 @@ fn check_coroutine_body(body: Body) { let local_3 = &body.locals()[3].ty; let local_4 = &body.locals()[4].ty; - let TyKind::RigidTy(RigidTy::Adt(def, ..)) = &ret_ty.kind() - else { + let TyKind::RigidTy(RigidTy::Adt(def, ..)) = &ret_ty.kind() else { panic!("Expected RigidTy::Adt, got: {:#?}", ret_ty); }; assert_eq!("std::task::Poll", def.0.name()); - let TyKind::RigidTy(RigidTy::Coroutine(def, ..)) = &local_3.kind() - else { + let TyKind::RigidTy(RigidTy::Coroutine(def, ..)) = &local_3.kind() else { panic!("Expected RigidTy::Coroutine, got: {:#?}", local_3); }; - assert_eq!("gbc::{closure#0}::{closure#0}", def.0.name()); + assert_eq!("crate_coroutine_body::gbc::{closure#0}::{closure#0}", def.0.name()); - let TyKind::RigidTy(RigidTy::Coroutine(def, ..)) = &local_4.kind() - else { + let TyKind::RigidTy(RigidTy::Coroutine(def, ..)) = &local_4.kind() else { panic!("Expected RigidTy::Coroutine, got: {:#?}", local_4); }; - assert_eq!("gbc::{closure#0}::{closure#0}", def.0.name()); + assert_eq!("crate_coroutine_body::gbc::{closure#0}::{closure#0}", def.0.name()); } fn main() { diff --git a/tests/ui-fulldeps/rustc_public/check_crate_defs.rs b/tests/ui-fulldeps/rustc_public/check_crate_defs.rs index 3ca8b66e58dca..7d949eae39106 100644 --- a/tests/ui-fulldeps/rustc_public/check_crate_defs.rs +++ b/tests/ui-fulldeps/rustc_public/check_crate_defs.rs @@ -27,17 +27,20 @@ const CRATE_NAME: &str = "crate_defs"; fn test_stable_mir() -> ControlFlow<()> { // Find items in the local crate. let local = rustc_public::local_crate(); - check_items(&local.statics(), &["PRIVATE_STATIC", "dummy::PUBLIC_STATIC"]); + check_items( + &local.statics(), + &["crate_defs::PRIVATE_STATIC", "crate_defs::dummy::PUBLIC_STATIC"], + ); check_items( &local.fn_defs(), &[ - "top_level", - "dummy::public_fn", - "dummy::private_fn", - "dummy::PrivateStruct::new", - "::drop", - "DummyTrait::method", - "::method", + "crate_defs::top_level", + "crate_defs::dummy::public_fn", + "crate_defs::dummy::private_fn", + "crate_defs::dummy::PrivateStruct::new", + "::drop", + "crate_defs::DummyTrait::method", + "::method", ], ); diff --git a/tests/ui-fulldeps/rustc_public/check_def_ty.rs b/tests/ui-fulldeps/rustc_public/check_def_ty.rs index 4a45bb6daa5f4..5984d6f8821a9 100644 --- a/tests/ui-fulldeps/rustc_public/check_def_ty.rs +++ b/tests/ui-fulldeps/rustc_public/check_def_ty.rs @@ -15,9 +15,12 @@ extern crate rustc_middle; extern crate rustc_driver; extern crate rustc_interface; extern crate rustc_public; +extern crate rustc_public_bridge; -use rustc_public::ty::{Ty, ForeignItemKind}; +use rustc_public::ty::VariantIdx; +use rustc_public::ty::{ForeignItemKind, RigidTy, Ty}; use rustc_public::*; +use rustc_public_bridge::IndexedVal; use std::io::Write; use std::ops::ControlFlow; @@ -29,11 +32,19 @@ fn test_def_tys() -> ControlFlow<()> { for item in &items { // Type from crate items. let ty = item.ty(); - match item.name().as_str() { + match item.trimmed_name().as_str() { "STATIC_STR" => assert!(ty.kind().is_ref()), "CONST_U32" => assert!(ty.kind().is_integral()), - "main" => { check_fn_def(ty) } - _ => unreachable!("Unexpected item: `{item:?}`") + "NONE" => { + let RigidTy::Adt(adt, _) = *ty.kind().rigid().unwrap() else { panic!() }; + // Definition names include the entire path. + assert_eq!(adt.name(), "std::option::Option"); + // Variant name only includes the actual variant name. + // I know, probably not the best name schema. o.O + assert_eq!(adt.variant(VariantIdx::to_val(0)).unwrap().name(), "None"); + } + "main" => check_fn_def(ty), + _ => unreachable!("Unexpected item: `{item:?}`"), } } @@ -42,7 +53,7 @@ fn test_def_tys() -> ControlFlow<()> { // Type from foreign items. let ty = item.ty(); let item_kind = item.kind(); - let name = item.name(); + let name = item.trimmed_name(); match item_kind { ForeignItemKind::Fn(fn_def) => { assert_eq!(&name, "extern_fn"); @@ -54,7 +65,7 @@ fn test_def_tys() -> ControlFlow<()> { assert_eq!(ty, def.ty()); assert!(ty.kind().is_integral()) } - _ => unreachable!("Unexpected kind: {item_kind:?}") + _ => unreachable!("Unexpected kind: {item_kind:?}"), }; } @@ -92,6 +103,7 @@ fn generate_input(path: &str) -> std::io::Result<()> { r#" static STATIC_STR: &str = "foo"; const CONST_U32: u32 = 0u32; + static NONE: Option = Option::None; fn main() {{ let _c = core::char::from_u32(99); diff --git a/tests/ui-fulldeps/rustc_public/check_defs.rs b/tests/ui-fulldeps/rustc_public/check_defs.rs index 0c45859a132a9..e6f9fb9972b0f 100644 --- a/tests/ui-fulldeps/rustc_public/check_defs.rs +++ b/tests/ui-fulldeps/rustc_public/check_defs.rs @@ -15,11 +15,11 @@ extern crate rustc_driver; extern crate rustc_interface; extern crate rustc_public; -use std::assert_matches::assert_matches; -use mir::{mono::Instance, TerminatorKind::*}; +use mir::{TerminatorKind::*, mono::Instance}; use rustc_public::mir::mono::InstanceKind; -use rustc_public::ty::{RigidTy, TyKind, Ty, UintTy}; +use rustc_public::ty::{RigidTy, Ty, TyKind, UintTy}; use rustc_public::*; +use std::assert_matches::assert_matches; use std::io::Write; use std::ops::ControlFlow; @@ -29,7 +29,7 @@ const CRATE_NAME: &str = "input"; fn test_stable_mir() -> ControlFlow<()> { let entry = rustc_public::entry_fn().unwrap(); let main_fn = Instance::try_from(entry).unwrap(); - assert_eq!(main_fn.name(), "main"); + assert_eq!(main_fn.name(), "input::main"); assert_eq!(main_fn.trimmed_name(), "main"); let instances = get_instances(main_fn.body().unwrap()); @@ -65,10 +65,8 @@ fn test_fn(instance: Instance, expected_trimmed: &str, expected_qualified: &str, fn extract_elem_ty(ty: Ty) -> Ty { match ty.kind() { - TyKind::RigidTy(RigidTy::Adt(_, args)) => { - *args.0[0].expect_ty() - } - _ => unreachable!("Expected Vec ADT, but found: {ty:?}") + TyKind::RigidTy(RigidTy::Adt(_, args)) => *args.0[0].expect_ty(), + _ => unreachable!("Expected Vec ADT, but found: {ty:?}"), } } @@ -89,19 +87,19 @@ fn test_vec_new(instance: mir::mono::Instance) { /// Inspect the instance body fn get_instances(body: mir::Body) -> Vec { - body.blocks.iter().filter_map(|bb| { - match &bb.terminator.kind { + body.blocks + .iter() + .filter_map(|bb| match &bb.terminator.kind { Call { func, .. } => { - let TyKind::RigidTy(ty) = func.ty(body.locals()).unwrap().kind() else { unreachable! - () }; + let TyKind::RigidTy(ty) = func.ty(body.locals()).unwrap().kind() else { + unreachable!() + }; let RigidTy::FnDef(def, args) = ty else { unreachable!() }; Instance::resolve(def, &args).ok() } - _ => { - None - } - } - }).collect::>() + _ => None, + }) + .collect::>() } /// This test will generate and analyze a dummy crate using the stable mir. diff --git a/tests/ui-fulldeps/rustc_public/check_foreign.rs b/tests/ui-fulldeps/rustc_public/check_foreign.rs index 78b62594c6188..bd34fb5cf8a88 100644 --- a/tests/ui-fulldeps/rustc_public/check_foreign.rs +++ b/tests/ui-fulldeps/rustc_public/check_foreign.rs @@ -13,8 +13,8 @@ extern crate rustc_middle; extern crate rustc_driver; extern crate rustc_interface; -extern crate rustc_span; extern crate rustc_public; +extern crate rustc_span; use rustc_public::{ ty::{Abi, ForeignItemKind}, @@ -40,7 +40,7 @@ fn test_foreign() -> ControlFlow<()> { assert_eq!(c_items.len(), 3); for item in c_items { let kind = item.kind(); - match item.name().as_str() { + match item.trimmed_name().as_str() { "foo" => assert_matches!(kind, ForeignItemKind::Fn(..)), "bar" => assert_matches!(kind, ForeignItemKind::Static(..)), "Baz" => assert_matches!(kind, ForeignItemKind::Type(..)), diff --git a/tests/ui-fulldeps/rustc_public/check_item_kind.rs b/tests/ui-fulldeps/rustc_public/check_item_kind.rs index b759628f1a42d..c687b3af1c632 100644 --- a/tests/ui-fulldeps/rustc_public/check_item_kind.rs +++ b/tests/ui-fulldeps/rustc_public/check_item_kind.rs @@ -27,7 +27,7 @@ fn test_item_kind() -> ControlFlow<()> { assert_eq!(items.len(), 4); // Constructor item. for item in items { - let expected_kind = match item.name().as_str() { + let expected_kind = match item.trimmed_name().as_str() { "Dummy" => ItemKind::Ctor(CtorKind::Fn), "dummy" => ItemKind::Fn, "unit" => ItemKind::Fn, diff --git a/tests/ui-fulldeps/rustc_public/check_trait_queries.rs b/tests/ui-fulldeps/rustc_public/check_trait_queries.rs index 0dd13044fcce8..5603add82f591 100644 --- a/tests/ui-fulldeps/rustc_public/check_trait_queries.rs +++ b/tests/ui-fulldeps/rustc_public/check_trait_queries.rs @@ -28,19 +28,20 @@ fn test_traits() -> ControlFlow<()> { let local_crate = rustc_public::local_crate(); let local_traits = local_crate.trait_decls(); assert_eq!(local_traits.len(), 1, "Expected `Max` trait, but found {:?}", local_traits); - assert_eq!(&local_traits[0].name(), "Max"); + assert_eq!(&local_traits[0].trimmed_name(), "Max"); let local_impls = local_crate.trait_impls(); - let impl_names = local_impls.iter().map(|trait_impl| trait_impl.name()).collect::>(); + let impl_names = + local_impls.iter().map(|trait_impl| trait_impl.trimmed_name()).collect::>(); assert_impl(&impl_names, ""); - assert_impl(&impl_names, ""); - assert_impl(&impl_names, ""); - assert_impl(&impl_names, ""); - assert_impl(&impl_names, ""); - assert_impl(&impl_names, ""); - assert_impl(&impl_names, ">"); + assert_impl(&impl_names, ""); + assert_impl(&impl_names, ""); + assert_impl(&impl_names, ""); + assert_impl(&impl_names, ""); + assert_impl(&impl_names, ""); + assert_impl(&impl_names, ">"); assert_impl(&impl_names, ""); - assert_impl(&impl_names, " for u64>"); + assert_impl(&impl_names, " for u64>"); let all_traits = rustc_public::all_trait_decls(); assert!(all_traits.len() > local_traits.len()); diff --git a/tests/ui-fulldeps/rustc_public/check_transform.rs b/tests/ui-fulldeps/rustc_public/check_transform.rs index b30d98c3b26f5..900bb4014d543 100644 --- a/tests/ui-fulldeps/rustc_public/check_transform.rs +++ b/tests/ui-fulldeps/rustc_public/check_transform.rs @@ -34,7 +34,7 @@ fn test_transform() -> ControlFlow<()> { let items = rustc_public::all_local_items(); // Test fn_abi - let target_fn = *get_item(&items, (ItemKind::Fn, "dummy")).unwrap(); + let target_fn = *get_item(&items, (ItemKind::Fn, "input::dummy")).unwrap(); let instance = Instance::try_from(target_fn).unwrap(); let body = instance.body().unwrap(); check_msg(&body, "oops"); diff --git a/tests/ui-fulldeps/rustc_public/check_variant.rs b/tests/ui-fulldeps/rustc_public/check_variant.rs index 9ed16f2357c0e..9bdd0c9d80ba4 100644 --- a/tests/ui-fulldeps/rustc_public/check_variant.rs +++ b/tests/ui-fulldeps/rustc_public/check_variant.rs @@ -97,7 +97,7 @@ fn check_adt_poly2() { } fn get_fn(name: &str) -> CrateItem { - rustc_public::all_local_items().into_iter().find(|it| it.name().eq(name)).unwrap() + rustc_public::all_local_items().into_iter().find(|it| it.trimmed_name().eq(name)).unwrap() } fn check_statement_is_aggregate_assign( diff --git a/tests/ui-fulldeps/rustc_public/closure-generic-body.rs b/tests/ui-fulldeps/rustc_public/closure-generic-body.rs index e5f910fbda115..46aeca76ba650 100644 --- a/tests/ui-fulldeps/rustc_public/closure-generic-body.rs +++ b/tests/ui-fulldeps/rustc_public/closure-generic-body.rs @@ -52,7 +52,7 @@ fn check_incr_closure_body(body: Body) { panic!("expected FnDef"); }; - assert_eq!(def_id.name(), "id"); + assert_eq!(def_id.trimmed_name(), "id"); } fn main() { diff --git a/tests/ui-fulldeps/rustc_public/closure_body.rs b/tests/ui-fulldeps/rustc_public/closure_body.rs index f5f9f23ad126d..43cbca8baab87 100644 --- a/tests/ui-fulldeps/rustc_public/closure_body.rs +++ b/tests/ui-fulldeps/rustc_public/closure_body.rs @@ -52,7 +52,7 @@ fn check_incr_closure_body(body: Body) { panic!("expected FnDef"); }; - assert_eq!(def_id.name(), "incr"); + assert_eq!(def_id.name(), "crate_closure_body::incr"); } fn main() { diff --git a/tests/ui-fulldeps/rustc_public/crate-info.rs b/tests/ui-fulldeps/rustc_public/crate-info.rs index 19082d7394abe..06cbbfcd69ec7 100644 --- a/tests/ui-fulldeps/rustc_public/crate-info.rs +++ b/tests/ui-fulldeps/rustc_public/crate-info.rs @@ -38,12 +38,12 @@ fn test_stable_mir() -> ControlFlow<()> { // Find items in the local crate. let items = rustc_public::all_local_items(); - assert!(get_item(&items, (DefKind::Fn, "foo::bar")).is_some()); + assert!(get_item(&items, (DefKind::Fn, "input::foo::bar")).is_some()); // Find the `std` crate and assert that there is only one of it. assert!(rustc_public::find_crates("std").len() == 1); - let bar = get_item(&items, (DefKind::Fn, "bar")).unwrap(); + let bar = get_item(&items, (DefKind::Fn, "input::bar")).unwrap(); let body = bar.expect_body(); assert_eq!(body.locals().len(), 2); assert_eq!(body.blocks.len(), 1); @@ -58,7 +58,7 @@ fn test_stable_mir() -> ControlFlow<()> { other => panic!("{other:?}"), } - let foo_bar = get_item(&items, (DefKind::Fn, "foo_bar")).unwrap(); + let foo_bar = get_item(&items, (DefKind::Fn, "input::foo_bar")).unwrap(); let body = foo_bar.expect_body(); assert_eq!(body.locals().len(), 5); assert_eq!(body.blocks.len(), 4); @@ -68,7 +68,7 @@ fn test_stable_mir() -> ControlFlow<()> { other => panic!("{other:?}"), } - let types = get_item(&items, (DefKind::Fn, "types")).unwrap(); + let types = get_item(&items, (DefKind::Fn, "input::types")).unwrap(); let body = types.expect_body(); assert_eq!(body.locals().len(), 6); assert_matches!( @@ -85,15 +85,15 @@ fn test_stable_mir() -> ControlFlow<()> { ); assert_matches!( body.locals()[3].ty.kind(), - rustc_public::ty::TyKind::RigidTy( - rustc_public::ty::RigidTy::Int(rustc_public::ty::IntTy::I32) - ) + rustc_public::ty::TyKind::RigidTy(rustc_public::ty::RigidTy::Int( + rustc_public::ty::IntTy::I32 + )) ); assert_matches!( body.locals()[4].ty.kind(), - rustc_public::ty::TyKind::RigidTy( - rustc_public::ty::RigidTy::Uint(rustc_public::ty::UintTy::U64) - ) + rustc_public::ty::TyKind::RigidTy(rustc_public::ty::RigidTy::Uint( + rustc_public::ty::UintTy::U64 + )) ); assert_matches!( body.locals()[5].ty.kind(), @@ -102,7 +102,7 @@ fn test_stable_mir() -> ControlFlow<()> { )) ); - let drop = get_item(&items, (DefKind::Fn, "drop")).unwrap(); + let drop = get_item(&items, (DefKind::Fn, "input::drop")).unwrap(); let body = drop.expect_body(); assert_eq!(body.blocks.len(), 2); let block = &body.blocks[0]; @@ -111,7 +111,7 @@ fn test_stable_mir() -> ControlFlow<()> { other => panic!("{other:?}"), } - let assert = get_item(&items, (DefKind::Fn, "assert")).unwrap(); + let assert = get_item(&items, (DefKind::Fn, "input::assert")).unwrap(); let body = assert.expect_body(); assert_eq!(body.blocks.len(), 2); let block = &body.blocks[0]; @@ -120,7 +120,7 @@ fn test_stable_mir() -> ControlFlow<()> { other => panic!("{other:?}"), } - let monomorphic = get_item(&items, (DefKind::Fn, "monomorphic")).unwrap(); + let monomorphic = get_item(&items, (DefKind::Fn, "input::monomorphic")).unwrap(); let instance = Instance::try_from(monomorphic.clone()).unwrap(); for block in instance.body().unwrap().blocks { match &block.terminator.kind { @@ -140,11 +140,11 @@ fn test_stable_mir() -> ControlFlow<()> { } } - let foo_const = get_item(&items, (DefKind::Const, "FOO")).unwrap(); + let foo_const = get_item(&items, (DefKind::Const, "input::FOO")).unwrap(); // Ensure we don't panic trying to get the body of a constant. foo_const.expect_body(); - let locals_fn = get_item(&items, (DefKind::Fn, "locals")).unwrap(); + let locals_fn = get_item(&items, (DefKind::Fn, "input::locals")).unwrap(); let body = locals_fn.expect_body(); assert_eq!(body.locals().len(), 4); assert_matches!( @@ -154,15 +154,15 @@ fn test_stable_mir() -> ControlFlow<()> { assert_eq!(body.arg_locals().len(), 2); assert_matches!( body.arg_locals()[0].ty.kind(), - rustc_public::ty::TyKind::RigidTy( - rustc_public::ty::RigidTy::Int(rustc_public::ty::IntTy::I32) - ) + rustc_public::ty::TyKind::RigidTy(rustc_public::ty::RigidTy::Int( + rustc_public::ty::IntTy::I32 + )) ); assert_matches!( body.arg_locals()[1].ty.kind(), - rustc_public::ty::TyKind::RigidTy( - rustc_public::ty::RigidTy::Uint(rustc_public::ty::UintTy::U64) - ) + rustc_public::ty::TyKind::RigidTy(rustc_public::ty::RigidTy::Uint( + rustc_public::ty::UintTy::U64 + )) ); assert_eq!(body.inner_locals().len(), 1); // If conditions have an extra inner local to hold their results diff --git a/tests/ui-fulldeps/rustc_public/projections.rs b/tests/ui-fulldeps/rustc_public/projections.rs index e0213b4253c7f..c1cdb5374d460 100644 --- a/tests/ui-fulldeps/rustc_public/projections.rs +++ b/tests/ui-fulldeps/rustc_public/projections.rs @@ -136,7 +136,9 @@ fn get_item<'a>( items: &'a rustc_public::CrateItems, item: (ItemKind, &str), ) -> Option<&'a rustc_public::CrateItem> { - items.iter().find(|crate_item| crate_item.kind() == item.0 && crate_item.name() == item.1) + items + .iter() + .find(|crate_item| crate_item.kind() == item.0 && crate_item.trimmed_name() == item.1) } /// This test will generate and analyze a dummy crate using the stable mir. diff --git a/tests/ui/rustc_public-ir-print/async-closure.stdout b/tests/ui/rustc_public-ir-print/async-closure.stdout index 3ec816b657f45..348713ee4ef1b 100644 --- a/tests/ui/rustc_public-ir-print/async-closure.stdout +++ b/tests/ui/rustc_public-ir-print/async-closure.stdout @@ -1,6 +1,6 @@ // WARNING: This is highly experimental output it's intended for rustc_public developers only. // If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir. -fn foo() -> () { +fn async_closure::foo() -> () { let mut _0: (); let _1: i32; let _2: {async closure@$DIR/async-closure.rs:9:13: 9:21}; @@ -21,7 +21,7 @@ fn foo() -> () { return; } } -fn foo::{closure#0}(_1: &{async closure@$DIR/async-closure.rs:9:13: 9:21}) -> {async closure body@$DIR/async-closure.rs:9:22: 11:6} { +fn async_closure::foo::{closure#0}(_1: &{async closure@$DIR/async-closure.rs:9:13: 9:21}) -> {async closure body@$DIR/async-closure.rs:9:22: 11:6} { let mut _0: {async closure body@$DIR/async-closure.rs:9:22: 11:6}; let mut _2: &i32; let mut _3: &i32; @@ -35,7 +35,7 @@ fn foo::{closure#0}(_1: &{async closure@$DIR/async-closure.rs:9:13: 9:21}) -> {a return; } } -fn foo::{closure#0}::{closure#0}(_1: Pin<&mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}>, _2: &mut Context<'_>) -> Poll<()> { +fn async_closure::foo::{closure#0}::{closure#0}(_1: Pin<&mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}>, _2: &mut Context<'_>) -> Poll<()> { let mut _0: Poll<()>; let _3: i32; let mut _4: &i32; @@ -56,7 +56,7 @@ fn foo::{closure#0}::{closure#0}(_1: Pin<&mut {async closure body@$DIR/async-clo _3 = (*_4); _5 = (); StorageDead(_3); - _0 = std::task::Poll::Ready(move _5); + _0 = Poll::Ready(move _5); discriminant((*_7)) = 1; return; } @@ -67,7 +67,7 @@ fn foo::{closure#0}::{closure#0}(_1: Pin<&mut {async closure body@$DIR/async-clo unreachable; } } -fn foo::{closure#0}::{synthetic#0}(_1: Pin<&mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}>, _2: &mut Context<'_>) -> Poll<()> { +fn async_closure::foo::{closure#0}::{synthetic#0}(_1: Pin<&mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}>, _2: &mut Context<'_>) -> Poll<()> { let mut _0: Poll<()>; let _3: i32; let mut _4: &i32; @@ -88,7 +88,7 @@ fn foo::{closure#0}::{synthetic#0}(_1: Pin<&mut {async closure body@$DIR/async-c _3 = (*_4); _5 = (); StorageDead(_3); - _0 = std::task::Poll::Ready(move _5); + _0 = Poll::Ready(move _5); discriminant((*_7)) = 1; return; } diff --git a/tests/ui/rustc_public-ir-print/basic_function.stdout b/tests/ui/rustc_public-ir-print/basic_function.stdout index dc885e009e914..e6a710ecb4c37 100644 --- a/tests/ui/rustc_public-ir-print/basic_function.stdout +++ b/tests/ui/rustc_public-ir-print/basic_function.stdout @@ -1,6 +1,6 @@ // WARNING: This is highly experimental output it's intended for rustc_public developers only. // If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir. -fn foo(_1: i32) -> i32 { +fn basic_function::foo(_1: i32) -> i32 { let mut _0: i32; let mut _2: i32; let mut _3: (i32, bool); @@ -17,7 +17,7 @@ fn foo(_1: i32) -> i32 { return; } } -fn bar(_1: &mut Vec) -> Vec { +fn basic_function::bar(_1: &mut Vec) -> Vec { let mut _0: Vec; let mut _2: Vec; let mut _3: &Vec; @@ -52,7 +52,7 @@ fn bar(_1: &mut Vec) -> Vec { resume; } } -fn demux(_1: u8) -> u8 { +fn basic_function::demux(_1: u8) -> u8 { let mut _0: u8; debug input => _1; bb0: { @@ -78,7 +78,7 @@ fn demux(_1: u8) -> u8 { return; } } -fn main() -> () { +fn basic_function::main() -> () { let mut _0: (); bb0: { _0 = (); diff --git a/tests/ui/rustc_public-ir-print/operands.stdout b/tests/ui/rustc_public-ir-print/operands.stdout index b7775416af85c..ca2cba8a3b327 100644 --- a/tests/ui/rustc_public-ir-print/operands.stdout +++ b/tests/ui/rustc_public-ir-print/operands.stdout @@ -1,6 +1,6 @@ // WARNING: This is highly experimental output it's intended for rustc_public developers only. // If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir. -fn operands(_1: u8) -> () { +fn operands::operands(_1: u8) -> () { let mut _0: (); let _2: [u8; 10]; let mut _3: u8; @@ -206,7 +206,7 @@ fn operands(_1: u8) -> () { StorageDead(_19); StorageDead(_18); StorageLive(_21); - _21 = core::panicking::AssertKind::Eq; + _21 = AssertKind::Eq; StorageLive(_22); StorageLive(_23); _23 = move _21; @@ -219,7 +219,7 @@ fn operands(_1: u8) -> () { _27 = &(*_16); _26 = &(*_27); StorageLive(_28); - _28 = std::option::Option::None; + _28 = Option::None; _22 = core::panicking::assert_failed::(move _23, move _24, move _26, move _28) -> unwind unreachable; } bb6: { @@ -268,7 +268,7 @@ fn operands(_1: u8) -> () { StorageDead(_39); StorageDead(_38); StorageLive(_41); - _41 = core::panicking::AssertKind::Eq; + _41 = AssertKind::Eq; StorageLive(_42); StorageLive(_43); _43 = move _41; @@ -281,7 +281,7 @@ fn operands(_1: u8) -> () { _47 = &(*_36); _46 = &(*_47); StorageLive(_48); - _48 = std::option::Option::None; + _48 = Option::None; _42 = core::panicking::assert_failed::(move _43, move _44, move _46, move _48) -> unwind unreachable; } bb8: { @@ -305,7 +305,7 @@ fn operands(_1: u8) -> () { StorageDead(_62); StorageDead(_61); StorageLive(_64); - _64 = core::panicking::AssertKind::Eq; + _64 = AssertKind::Eq; StorageLive(_65); StorageLive(_66); _66 = move _64; @@ -318,7 +318,7 @@ fn operands(_1: u8) -> () { _70 = &(*_59); _69 = &(*_70); StorageLive(_71); - _71 = std::option::Option::None; + _71 = Option::None; _65 = core::panicking::assert_failed::(move _66, move _67, move _69, move _71) -> unwind unreachable; } bb10: { @@ -380,7 +380,7 @@ fn operands(_1: u8) -> () { StorageDead(_86); StorageDead(_85); StorageLive(_88); - _88 = core::panicking::AssertKind::Eq; + _88 = AssertKind::Eq; StorageLive(_89); StorageLive(_90); _90 = move _88; @@ -393,11 +393,11 @@ fn operands(_1: u8) -> () { _94 = &(*_83); _93 = &(*_94); StorageLive(_95); - _95 = std::option::Option::None; + _95 = Option::None; _89 = core::panicking::assert_failed::(move _90, move _91, move _93, move _95) -> unwind unreachable; } } -fn more_operands() -> [Ctors; 3] { +fn operands::more_operands() -> [Ctors; 3] { let mut _0: [Ctors; 3]; let _1: Dummy; let _2: Ctors; @@ -440,7 +440,7 @@ fn more_operands() -> [Ctors; 3] { return; } } -fn closures(_1: bool, _2: bool) -> {closure@$DIR/operands.rs:47:5: 47:19} { +fn operands::closures(_1: bool, _2: bool) -> {closure@$DIR/operands.rs:47:5: 47:19} { let mut _0: {closure@$DIR/operands.rs:47:5: 47:19}; debug x => _1; debug z => _2; @@ -449,7 +449,7 @@ fn closures(_1: bool, _2: bool) -> {closure@$DIR/operands.rs:47:5: 47:19} { return; } } -fn closures::{closure#0}(_1: {closure@$DIR/operands.rs:47:5: 47:19}, _2: bool) -> bool { +fn operands::closures::{closure#0}(_1: {closure@$DIR/operands.rs:47:5: 47:19}, _2: bool) -> bool { let mut _0: bool; let mut _3: bool; let mut _4: bool; @@ -483,7 +483,7 @@ fn closures::{closure#0}(_1: {closure@$DIR/operands.rs:47:5: 47:19}, _2: bool) - return; } } -fn Ctors::TupLike(_1: bool) -> Ctors { +fn operands::Ctors::TupLike(_1: bool) -> Ctors { let mut _0: Ctors; bb0: { _0 = Ctors::TupLike(move _1);