Skip to content

Commit b6e9772

Browse files
committed
Improve documentation and fix the fixme comment
1 parent 591b41a commit b6e9772

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
256256
tables.tcx.symbol_name(instance).name.to_string()
257257
}
258258

259+
/// Retrieve the instance name for diagnostic messages.
260+
///
261+
/// This will return the specialized name, e.g., `Vec<char>::new`.
259262
fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol {
260263
let tables = self.0.borrow_mut();
261264
let instance = tables.instances[def];

compiler/stable_mir/src/crate_def.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! Module that define a common trait for things that represent a crate definition.
1+
//! Module that define a common trait for things that represent a crate definition,
2+
//! such as, a function, a trait, an enum, and any other definitions.
23
34
use crate::ty::Span;
45
use crate::{with, Crate, Symbol};
@@ -7,21 +8,23 @@ use crate::{with, Crate, Symbol};
78
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
89
pub struct DefId(pub(crate) usize);
910

10-
/// A trait for retrieving information about a crate definition.
11+
/// A trait for retrieving information about a particular definition.
1112
///
1213
/// Implementors must provide the implementation of `def_id` which will be used to retrieve
13-
/// information about its definition.
14+
/// information about a crate's definition.
1415
pub trait CrateDef {
15-
/// Retrieve the unique identifier for the given definition.
16+
/// Retrieve the unique identifier for the current definition.
1617
fn def_id(&self) -> DefId;
1718

18-
/// Return the fully qualified name of the given definition.
19+
/// Return the fully qualified name of the current definition.
1920
fn name(&self) -> Symbol {
2021
let def_id = self.def_id();
2122
with(|cx| cx.def_name(def_id, false))
2223
}
2324

24-
/// Return a trimmed name of the given definition.
25+
/// Return a trimmed name of this definition.
26+
///
27+
/// This can be used to print more user friendly diagnostic messages.
2528
///
2629
/// If a symbol name can only be imported from one place for a type, and as
2730
/// long as it was not glob-imported anywhere in the current crate, we trim its

compiler/stable_mir/src/mir/mono.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ impl Instance {
4848
with(|context| context.instance_ty(self.def))
4949
}
5050

51+
/// Retrieve the instance's mangled name used for calling the given instance.
52+
///
53+
/// This will also look up the correct name of instances from upstream crates.
5154
pub fn mangled_name(&self) -> Symbol {
5255
with(|context| context.instance_mangled_name(self.def))
5356
}
5457

58+
/// Retrieve the instance name for diagnostic messages.
59+
///
60+
/// This will return the specialized name, e.g., `std::vec::Vec<u8>::new`.
5561
pub fn name(&self) -> Symbol {
5662
with(|context| context.instance_name(self.def, false))
5763
}
@@ -118,8 +124,8 @@ impl TryFrom<CrateItem> for Instance {
118124

119125
fn try_from(item: CrateItem) -> Result<Self, Self::Error> {
120126
with(|context| {
121-
/// FIXME(celinval):
122-
/// - Check `has_body`.
127+
// FIXME(celinval):
128+
// - Return `Err` if instance does not have a body.
123129
if !context.requires_monomorphization(item.0) {
124130
Ok(context.mono_instance(item))
125131
} else {

0 commit comments

Comments
 (0)