Improve documentation and fix the fixme comment
This commit is contained in:
parent
591b41abb8
commit
b6e977243f
3 changed files with 20 additions and 8 deletions
|
@ -256,6 +256,9 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
||||||
tables.tcx.symbol_name(instance).name.to_string()
|
tables.tcx.symbol_name(instance).name.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieve the instance name for diagnostic messages.
|
||||||
|
///
|
||||||
|
/// This will return the specialized name, e.g., `Vec<char>::new`.
|
||||||
fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol {
|
fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol {
|
||||||
let tables = self.0.borrow_mut();
|
let tables = self.0.borrow_mut();
|
||||||
let instance = tables.instances[def];
|
let instance = tables.instances[def];
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//! Module that define a common trait for things that represent a crate definition.
|
//! Module that define a common trait for things that represent a crate definition,
|
||||||
|
//! such as, a function, a trait, an enum, and any other definitions.
|
||||||
|
|
||||||
use crate::ty::Span;
|
use crate::ty::Span;
|
||||||
use crate::{with, Crate, Symbol};
|
use crate::{with, Crate, Symbol};
|
||||||
|
@ -7,21 +8,23 @@ use crate::{with, Crate, Symbol};
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct DefId(pub(crate) usize);
|
pub struct DefId(pub(crate) usize);
|
||||||
|
|
||||||
/// A trait for retrieving information about a crate definition.
|
/// A trait for retrieving information about a particular definition.
|
||||||
///
|
///
|
||||||
/// Implementors must provide the implementation of `def_id` which will be used to retrieve
|
/// Implementors must provide the implementation of `def_id` which will be used to retrieve
|
||||||
/// information about its definition.
|
/// information about a crate's definition.
|
||||||
pub trait CrateDef {
|
pub trait CrateDef {
|
||||||
/// Retrieve the unique identifier for the given definition.
|
/// Retrieve the unique identifier for the current definition.
|
||||||
fn def_id(&self) -> DefId;
|
fn def_id(&self) -> DefId;
|
||||||
|
|
||||||
/// Return the fully qualified name of the given definition.
|
/// Return the fully qualified name of the current definition.
|
||||||
fn name(&self) -> Symbol {
|
fn name(&self) -> Symbol {
|
||||||
let def_id = self.def_id();
|
let def_id = self.def_id();
|
||||||
with(|cx| cx.def_name(def_id, false))
|
with(|cx| cx.def_name(def_id, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a trimmed name of the given definition.
|
/// Return a trimmed name of this definition.
|
||||||
|
///
|
||||||
|
/// This can be used to print more user friendly diagnostic messages.
|
||||||
///
|
///
|
||||||
/// If a symbol name can only be imported from one place for a type, and as
|
/// If a symbol name can only be imported from one place for a type, and as
|
||||||
/// long as it was not glob-imported anywhere in the current crate, we trim its
|
/// long as it was not glob-imported anywhere in the current crate, we trim its
|
||||||
|
|
|
@ -48,10 +48,16 @@ impl Instance {
|
||||||
with(|context| context.instance_ty(self.def))
|
with(|context| context.instance_ty(self.def))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieve the instance's mangled name used for calling the given instance.
|
||||||
|
///
|
||||||
|
/// This will also look up the correct name of instances from upstream crates.
|
||||||
pub fn mangled_name(&self) -> Symbol {
|
pub fn mangled_name(&self) -> Symbol {
|
||||||
with(|context| context.instance_mangled_name(self.def))
|
with(|context| context.instance_mangled_name(self.def))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieve the instance name for diagnostic messages.
|
||||||
|
///
|
||||||
|
/// This will return the specialized name, e.g., `std::vec::Vec<u8>::new`.
|
||||||
pub fn name(&self) -> Symbol {
|
pub fn name(&self) -> Symbol {
|
||||||
with(|context| context.instance_name(self.def, false))
|
with(|context| context.instance_name(self.def, false))
|
||||||
}
|
}
|
||||||
|
@ -118,8 +124,8 @@ impl TryFrom<CrateItem> for Instance {
|
||||||
|
|
||||||
fn try_from(item: CrateItem) -> Result<Self, Self::Error> {
|
fn try_from(item: CrateItem) -> Result<Self, Self::Error> {
|
||||||
with(|context| {
|
with(|context| {
|
||||||
/// FIXME(celinval):
|
// FIXME(celinval):
|
||||||
/// - Check `has_body`.
|
// - Return `Err` if instance does not have a body.
|
||||||
if !context.requires_monomorphization(item.0) {
|
if !context.requires_monomorphization(item.0) {
|
||||||
Ok(context.mono_instance(item))
|
Ok(context.mono_instance(item))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue