Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_public_bridge/src/context/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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_resolve_crate_name};
use rustc_middle::ty::util::Discr;
use rustc_middle::ty::{
AdtDef, AdtKind, AssocItem, Binder, ClosureKind, CoroutineArgsExt, EarlyBinder,
Expand Down Expand Up @@ -264,7 +264,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!(self.tcx.def_path_str(def_id))
}
}

Expand Down Expand Up @@ -719,7 +720,7 @@ 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!(
self.tcx.def_path_str_with_args(instance.def_id(), instance.args)
)
}
Expand Down
10 changes: 5 additions & 5 deletions tests/ui-fulldeps/rustc_public/check_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions tests/ui-fulldeps/rustc_public/check_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/check_assoc_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn test_assoc_items() -> ControlFlow<()> {
/// Note that order doesn't matter.
fn check_items<T: CrateDef>(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);
}

Expand Down
11 changes: 4 additions & 7 deletions tests/ui-fulldeps/rustc_public/check_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 6 additions & 13 deletions tests/ui-fulldeps/rustc_public/check_coroutine_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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() {
Expand Down
19 changes: 11 additions & 8 deletions tests/ui-fulldeps/rustc_public/check_crate_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"<dummy::PrivateStruct as std::ops::Drop>::drop",
"DummyTrait::method",
"<T as DummyTrait>::method",
"crate_defs::top_level",
"crate_defs::dummy::public_fn",
"crate_defs::dummy::private_fn",
"crate_defs::dummy::PrivateStruct::new",
"<crate_defs::dummy::PrivateStruct as std::ops::Drop>::drop",
"crate_defs::DummyTrait::method",
"<T as crate_defs::DummyTrait>::method",
],
);

Expand Down
12 changes: 6 additions & 6 deletions tests/ui-fulldeps/rustc_public/check_def_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern crate rustc_driver;
extern crate rustc_interface;
extern crate rustc_public;

use rustc_public::ty::{Ty, ForeignItemKind};
use rustc_public::ty::{ForeignItemKind, Ty};
use rustc_public::*;
use std::io::Write;
use std::ops::ControlFlow;
Expand All @@ -29,11 +29,11 @@ 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:?}`")
"main" => check_fn_def(ty),
_ => unreachable!("Unexpected item: `{item:?}`"),
}
}

Expand All @@ -42,7 +42,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");
Expand All @@ -54,7 +54,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:?}"),
};
}

Expand Down
32 changes: 15 additions & 17 deletions tests/ui-fulldeps/rustc_public/check_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
Expand Down Expand Up @@ -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:?}"),
}
}

Expand All @@ -89,19 +87,19 @@ fn test_vec_new(instance: mir::mono::Instance) {

/// Inspect the instance body
fn get_instances(body: mir::Body) -> Vec<Instance> {
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::<Vec<_>>()
_ => None,
})
.collect::<Vec<_>>()
}

/// This test will generate and analyze a dummy crate using the stable mir.
Expand Down
4 changes: 2 additions & 2 deletions tests/ui-fulldeps/rustc_public/check_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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(..)),
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/check_item_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 10 additions & 9 deletions tests/ui-fulldeps/rustc_public/check_trait_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<HashSet<_>>();
let impl_names =
local_impls.iter().map(|trait_impl| trait_impl.trimmed_name()).collect::<HashSet<_>>();
assert_impl(&impl_names, "<Positive as Max>");
assert_impl(&impl_names, "<Positive as std::marker::Copy>");
assert_impl(&impl_names, "<Positive as std::clone::Clone>");
assert_impl(&impl_names, "<Positive as std::fmt::Debug>");
assert_impl(&impl_names, "<Positive as std::cmp::PartialEq>");
assert_impl(&impl_names, "<Positive as std::cmp::Eq>");
assert_impl(&impl_names, "<Positive as std::convert::TryFrom<u64>>");
assert_impl(&impl_names, "<Positive as Copy>");
assert_impl(&impl_names, "<Positive as Clone>");
assert_impl(&impl_names, "<Positive as Debug>");
assert_impl(&impl_names, "<Positive as PartialEq>");
assert_impl(&impl_names, "<Positive as Eq>");
assert_impl(&impl_names, "<Positive as TryFrom<u64>>");
assert_impl(&impl_names, "<u64 as Max>");
assert_impl(&impl_names, "<impl std::convert::From<Positive> for u64>");
assert_impl(&impl_names, "<impl From<Positive> for u64>");

let all_traits = rustc_public::all_trait_decls();
assert!(all_traits.len() > local_traits.len());
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/check_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/check_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/closure-generic-body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/closure_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading
Loading