1
Fork 0

Rename FnStyle trait to Unsafety.

This commit is contained in:
Niko Matsakis 2014-12-09 10:36:46 -05:00
parent 52f7a4a351
commit 092d04a40a
41 changed files with 254 additions and 273 deletions

View file

@ -32,7 +32,7 @@ use html::render::{cache, CURRENT_LOCATION_KEY};
pub struct VisSpace(pub Option<ast::Visibility>);
/// Similarly to VisSpace, this structure is used to render a function style with a
/// space after it.
pub struct FnStyleSpace(pub ast::FnStyle);
pub struct UnsafetySpace(pub ast::Unsafety);
/// Wrapper struct for properly emitting a method declaration.
pub struct Method<'a>(pub &'a clean::SelfTy, pub &'a clean::FnDecl);
/// Similar to VisSpace, but used for mutability
@ -49,7 +49,7 @@ pub struct WhereClause<'a>(pub &'a clean::Generics);
pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
impl Copy for VisSpace {}
impl Copy for FnStyleSpace {}
impl Copy for UnsafetySpace {}
impl Copy for MutableSpace {}
impl Copy for RawMutableSpace {}
@ -59,9 +59,9 @@ impl VisSpace {
}
}
impl FnStyleSpace {
pub fn get(&self) -> ast::FnStyle {
let FnStyleSpace(v) = *self; v
impl UnsafetySpace {
pub fn get(&self) -> ast::Unsafety {
let UnsafetySpace(v) = *self; v
}
}
@ -404,7 +404,7 @@ impl fmt::Show for clean::Type {
clean::Primitive(prim) => primitive_link(f, prim, prim.to_string()),
clean::Closure(ref decl) => {
write!(f, "{style}{lifetimes}|{args}|{bounds}{arrow}",
style = FnStyleSpace(decl.fn_style),
style = UnsafetySpace(decl.unsafety),
lifetimes = if decl.lifetimes.len() == 0 {
"".to_string()
} else {
@ -433,7 +433,7 @@ impl fmt::Show for clean::Type {
}
clean::Proc(ref decl) => {
write!(f, "{style}{lifetimes}proc({args}){bounds}{arrow}",
style = FnStyleSpace(decl.fn_style),
style = UnsafetySpace(decl.unsafety),
lifetimes = if decl.lifetimes.len() == 0 {
"".to_string()
} else {
@ -454,7 +454,7 @@ impl fmt::Show for clean::Type {
}
clean::BareFunction(ref decl) => {
write!(f, "{}{}fn{}{}",
FnStyleSpace(decl.fn_style),
UnsafetySpace(decl.unsafety),
match decl.abi.as_slice() {
"" => " extern ".to_string(),
"\"Rust\"" => "".to_string(),
@ -584,11 +584,11 @@ impl fmt::Show for VisSpace {
}
}
impl fmt::Show for FnStyleSpace {
impl fmt::Show for UnsafetySpace {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.get() {
ast::UnsafeFn => write!(f, "unsafe "),
ast::NormalFn => Ok(())
ast::Unsafety::Unsafe => write!(f, "unsafe "),
ast::Unsafety::Normal => Ok(())
}
}
}

View file

@ -58,7 +58,7 @@ use rustc::util::nodemap::NodeSet;
use clean;
use doctree;
use fold::DocFolder;
use html::format::{VisSpace, Method, FnStyleSpace, MutableSpace, Stability};
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace, Stability};
use html::format::{ConciseStability, TyParamBounds, WhereClause};
use html::highlight;
use html::item_type::ItemType;
@ -1664,10 +1664,10 @@ fn item_static(w: &mut fmt::Formatter, it: &clean::Item,
fn item_function(w: &mut fmt::Formatter, it: &clean::Item,
f: &clean::Function) -> fmt::Result {
try!(write!(w, "<pre class='rust fn'>{vis}{fn_style}fn \
try!(write!(w, "<pre class='rust fn'>{vis}{unsafety}fn \
{name}{generics}{decl}{where_clause}</pre>",
vis = VisSpace(it.visibility),
fn_style = FnStyleSpace(f.fn_style),
unsafety = UnsafetySpace(f.unsafety),
name = it.name.as_ref().unwrap().as_slice(),
generics = f.generics,
where_clause = WhereClause(&f.generics),
@ -1813,13 +1813,13 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}
fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
fn method(w: &mut fmt::Formatter, it: &clean::Item, fn_style: ast::FnStyle,
fn method(w: &mut fmt::Formatter, it: &clean::Item, unsafety: ast::Unsafety,
g: &clean::Generics, selfty: &clean::SelfTy,
d: &clean::FnDecl) -> fmt::Result {
write!(w, "{}fn <a href='#{ty}.{name}' class='fnname'>{name}</a>\
{generics}{decl}{where_clause}",
match fn_style {
ast::UnsafeFn => "unsafe ",
match unsafety {
ast::Unsafety::Unsafe => "unsafe ",
_ => "",
},
ty = shortty(it),
@ -1841,10 +1841,10 @@ fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
}
match meth.inner {
clean::TyMethodItem(ref m) => {
method(w, meth, m.fn_style, &m.generics, &m.self_, &m.decl)
method(w, meth, m.unsafety, &m.generics, &m.self_, &m.decl)
}
clean::MethodItem(ref m) => {
method(w, meth, m.fn_style, &m.generics, &m.self_, &m.decl)
method(w, meth, m.unsafety, &m.generics, &m.self_, &m.decl)
}
clean::AssociatedTypeItem(ref typ) => {
assoc_type(w, meth, typ)