impl Display for AttrInput/ImportAlias

This commit is contained in:
Jonas Schievink 2021-05-21 23:45:09 +02:00
parent 5b6c0c1af2
commit 01df4c04d1
2 changed files with 19 additions and 1 deletions

View file

@ -2,7 +2,7 @@
use std::{
convert::{TryFrom, TryInto},
ops,
fmt, ops,
sync::Arc,
};
@ -648,6 +648,15 @@ pub enum AttrInput {
TokenTree(Subtree),
}
impl fmt::Display for AttrInput {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AttrInput::Literal(lit) => write!(f, " = \"{}\"", lit.escape_debug()),
AttrInput::TokenTree(subtree) => subtree.fmt(f),
}
}
}
impl Attr {
fn from_src(
db: &dyn DefDatabase,

View file

@ -46,6 +46,15 @@ pub enum ImportAlias {
Alias(Name),
}
impl Display for ImportAlias {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ImportAlias::Underscore => f.write_str("_"),
ImportAlias::Alias(name) => f.write_str(&name.to_string()),
}
}
}
impl ModPath {
pub fn from_src(db: &dyn DefDatabase, path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> {
let ctx = LowerCtx::with_hygiene(db, hygiene);