Skip to content

Commit

Permalink
query-fy type_name
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-i-m committed Jun 3, 2019
1 parent b7f5eab commit 0f822d7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2684,7 +2684,6 @@ dependencies = [
"rustc_errors 0.0.0",
"rustc_fs_util 0.0.0",
"rustc_incremental 0.0.0",
"rustc_mir 0.0.0",
"rustc_target 0.0.0",
"serialize 0.0.0",
"syntax 0.0.0",
Expand Down
9 changes: 9 additions & 0 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ rustc_queries! {
no_force
desc { "extract field of const" }
}

/// Produces an absolute path representation of the given type. See also the documentation
/// on `std::any::type_name`.
query type_name(key: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
eval_always
no_force
desc { "get absolute path of type" }
}

}

TypeChecking {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
}
"type_name" => {
let tp_ty = substs.type_at(0);
let ty_name = rustc_mir::interpret::type_name(self.tcx, tp_ty);
let ty_name = self.tcx.type_name(tp_ty);
OperandRef::from_const(self, ty_name).immediate_or_packed_pair(self)
}
"type_id" => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ pub use self::visitor::{ValueVisitor, MutValueVisitor};

pub use self::validity::RefTracking;

pub use self::intrinsics::type_name;
pub(super) use self::intrinsics::type_name;
1 change: 1 addition & 0 deletions src/librustc_mir/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub fn provide(providers: &mut Providers<'_>) {
let (param_env, (value, field)) = param_env_and_value.into_parts();
const_eval::const_field(tcx, param_env, None, field, value)
};
providers.type_name = interpret::type_name;
}

__build_diagnostic_array! { librustc_mir, DIAGNOSTICS }

0 comments on commit 0f822d7

Please sign in to comment.