Skip to content

deps: Update syntex_syntax to 0.31.0 #971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ regex = "0.1"
term = "0.4"
strings = "0.0.1"
diff = "0.1"
syntex_syntax = "0.30"
syntex_syntax = "0.31"
log = "0.3"
env_logger = "0.3"
getopts = "0.2"
65 changes: 29 additions & 36 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a> FmtVisitor<'a> {
// These are not actually rust functions,
// but we format them as such.
abi::Abi::Rust,
item.vis,
&item.vis,
span,
false,
false);
Expand All @@ -148,7 +148,7 @@ impl<'a> FmtVisitor<'a> {
""
};
let prefix = format!("{}static {}{}: ",
format_visibility(item.vis),
format_visibility(&item.vis),
mut_str,
item.ident);
let offset = self.block_indent + prefix.len();
Expand Down Expand Up @@ -179,7 +179,7 @@ impl<'a> FmtVisitor<'a> {
unsafety: ast::Unsafety,
constness: ast::Constness,
abi: abi::Abi,
vis: ast::Visibility,
vis: &ast::Visibility,
span: Span,
block: &ast::Block)
-> Option<String> {
Expand Down Expand Up @@ -244,7 +244,7 @@ impl<'a> FmtVisitor<'a> {
sig.unsafety,
sig.constness,
sig.abi,
ast::Visibility::Inherited,
&ast::Visibility::Inherited,
span,
false,
false));
Expand Down Expand Up @@ -303,7 +303,7 @@ impl<'a> FmtVisitor<'a> {

pub fn visit_enum(&mut self,
ident: ast::Ident,
vis: ast::Visibility,
vis: &ast::Visibility,
enum_def: &ast::EnumDef,
generics: &ast::Generics,
span: Span) {
Expand Down Expand Up @@ -414,7 +414,7 @@ impl<'a> FmtVisitor<'a> {
format_struct(&context,
"",
field.node.name,
ast::Visibility::Inherited,
&ast::Visibility::Inherited,
&field.node.data,
None,
field.span,
Expand Down Expand Up @@ -451,7 +451,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
ref self_ty,
ref items) = item.node {
let mut result = String::new();
result.push_str(format_visibility(item.vis));
result.push_str(format_visibility(&item.vis));
result.push_str(format_unsafety(unsafety));
result.push_str("impl");

Expand Down Expand Up @@ -583,7 +583,7 @@ fn is_impl_single_line(context: &RewriteContext,
pub fn format_struct(context: &RewriteContext,
item_name: &str,
ident: ast::Ident,
vis: ast::Visibility,
vis: &ast::Visibility,
struct_def: &ast::VariantData,
generics: Option<&ast::Generics>,
span: Span,
Expand Down Expand Up @@ -619,7 +619,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
item.node {
let mut result = String::new();
let header = format!("{}{}trait {}",
format_visibility(item.vis),
format_visibility(&item.vis),
format_unsafety(unsafety),
item.ident);

Expand Down Expand Up @@ -741,7 +741,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
}
}

fn format_unit_struct(item_name: &str, ident: ast::Ident, vis: ast::Visibility) -> Option<String> {
fn format_unit_struct(item_name: &str, ident: ast::Ident, vis: &ast::Visibility) -> Option<String> {
let mut result = String::with_capacity(1024);

let header_str = format_header(item_name, ident, vis);
Expand All @@ -754,7 +754,7 @@ fn format_unit_struct(item_name: &str, ident: ast::Ident, vis: ast::Visibility)
fn format_struct_struct(context: &RewriteContext,
item_name: &str,
ident: ast::Ident,
vis: ast::Visibility,
vis: &ast::Visibility,
fields: &[ast::StructField],
generics: Option<&ast::Generics>,
span: Span,
Expand Down Expand Up @@ -804,13 +804,13 @@ fn format_struct_struct(context: &RewriteContext,
"}",
|field| {
// Include attributes and doc comments, if present
if !field.node.attrs.is_empty() {
field.node.attrs[0].span.lo
if !field.attrs.is_empty() {
field.attrs[0].span.lo
} else {
field.span.lo
}
},
|field| field.node.ty.span.hi,
|field| field.ty.span.hi,
|field| field.rewrite(context, item_budget, item_indent),
context.codemap.span_after(span, "{"),
span.hi);
Expand All @@ -835,7 +835,7 @@ fn format_struct_struct(context: &RewriteContext,
fn format_tuple_struct(context: &RewriteContext,
item_name: &str,
ident: ast::Ident,
vis: ast::Visibility,
vis: &ast::Visibility,
fields: &[ast::StructField],
generics: Option<&ast::Generics>,
span: Span,
Expand Down Expand Up @@ -890,13 +890,13 @@ fn format_tuple_struct(context: &RewriteContext,
")",
|field| {
// Include attributes and doc comments, if present
if !field.node.attrs.is_empty() {
field.node.attrs[0].span.lo
if !field.attrs.is_empty() {
field.attrs[0].span.lo
} else {
field.span.lo
}
},
|field| field.node.ty.span.hi,
|field| field.ty.span.hi,
|field| field.rewrite(context, item_budget, item_indent),
context.codemap.span_after(span, "("),
span.hi);
Expand Down Expand Up @@ -924,12 +924,12 @@ pub fn rewrite_type_alias(context: &RewriteContext,
ident: ast::Ident,
ty: &ast::Ty,
generics: &ast::Generics,
vis: ast::Visibility,
vis: &ast::Visibility,
span: Span)
-> Option<String> {
let mut result = String::new();

result.push_str(&format_visibility(vis));
result.push_str(&format_visibility(&vis));
result.push_str("type ");
result.push_str(&ident.to_string());

Expand Down Expand Up @@ -991,21 +991,14 @@ pub fn rewrite_type_alias(context: &RewriteContext,

impl Rewrite for ast::StructField {
fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
if contains_skip(&self.node.attrs) {
let span = context.snippet(mk_sp(self.node.attrs[0].span.lo, self.span.hi));
if contains_skip(&self.attrs) {
let span = context.snippet(mk_sp(self.attrs[0].span.lo, self.span.hi));
return wrap_str(span, context.config.max_width, width, offset);
}

let name = match self.node.kind {
ast::StructFieldKind::NamedField(ident, _) => Some(ident.to_string()),
ast::StructFieldKind::UnnamedField(_) => None,
};
let vis = match self.node.kind {
ast::StructFieldKind::NamedField(_, vis) |
ast::StructFieldKind::UnnamedField(vis) => format_visibility(vis),
};
let mut attr_str = try_opt!(self.node
.attrs
let name = self.ident;
let vis = format_visibility(&self.vis);
let mut attr_str = try_opt!(self.attrs
.rewrite(context, context.config.max_width - offset.width(), offset));
if !attr_str.is_empty() {
attr_str.push('\n');
Expand All @@ -1019,13 +1012,13 @@ impl Rewrite for ast::StructField {

let last_line_width = last_line_width(&result);
let budget = try_opt!(width.checked_sub(last_line_width));
let rewrite = try_opt!(self.node.ty.rewrite(context, budget, offset + last_line_width));
let rewrite = try_opt!(self.ty.rewrite(context, budget, offset + last_line_width));
Some(result + &rewrite)
}
}

pub fn rewrite_static(prefix: &str,
vis: ast::Visibility,
vis: &ast::Visibility,
ident: ast::Ident,
ty: &ast::Ty,
mutability: ast::Mutability,
Expand Down Expand Up @@ -1239,7 +1232,7 @@ fn rewrite_fn_base(context: &RewriteContext,
unsafety: ast::Unsafety,
constness: ast::Constness,
abi: abi::Abi,
vis: ast::Visibility,
vis: &ast::Visibility,
span: Span,
newline_brace: bool,
has_body: bool)
Expand Down Expand Up @@ -1808,7 +1801,7 @@ fn rewrite_where_clause(context: &RewriteContext,
}
}

fn format_header(item_name: &str, ident: ast::Ident, vis: ast::Visibility) -> String {
fn format_header(item_name: &str, ident: ast::Ident, vis: &ast::Visibility) -> String {
format!("{}{}{}", format_visibility(vis), item_name, ident)
}

Expand Down
7 changes: 5 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ pub fn extra_offset(text: &str, offset: Indent) -> usize {
}

#[inline]
pub fn format_visibility(vis: Visibility) -> &'static str {
match vis {
pub fn format_visibility(vis: &Visibility) -> &'static str {
match *vis {
Visibility::Public => "pub ",
Visibility::Inherited => "",
// TODO(#970): Handle new visibility types.
Visibility::Crate => unimplemented!(),
Visibility::Restricted { .. } => unimplemented!(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we handle these by returning None and then skipping the item, falling back to the missing spans? That is better than panicking, I think.

Also, (nit) if there is an issue number, prefer FIXME to TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

}
}

Expand Down
28 changes: 14 additions & 14 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<'a> FmtVisitor<'a> {
sig.unsafety,
sig.constness,
sig.abi,
vis.unwrap_or(ast::Visibility::Inherited),
vis.unwrap_or(&ast::Visibility::Inherited),
codemap::mk_sp(s.lo, b.span.lo),
&b)
}
Expand Down Expand Up @@ -198,7 +198,7 @@ impl<'a> FmtVisitor<'a> {

match item.node {
ast::ItemKind::Use(ref vp) => {
self.format_import(item.vis, vp, item.span);
self.format_import(&item.vis, vp, item.span);
}
ast::ItemKind::Impl(..) => {
self.format_missing_with_indent(item.span.lo);
Expand Down Expand Up @@ -229,7 +229,7 @@ impl<'a> FmtVisitor<'a> {
::items::format_struct(&context,
"struct ",
item.ident,
item.vis,
&item.vis,
def,
Some(generics),
item.span,
Expand All @@ -245,12 +245,12 @@ impl<'a> FmtVisitor<'a> {
}
ast::ItemKind::Enum(ref def, ref generics) => {
self.format_missing_with_indent(item.span.lo);
self.visit_enum(item.ident, item.vis, def, generics, item.span);
self.visit_enum(item.ident, &item.vis, def, generics, item.span);
self.last_pos = item.span.hi;
}
ast::ItemKind::Mod(ref module) => {
self.format_missing_with_indent(item.span.lo);
self.format_mod(module, item.vis, item.span, item.ident);
self.format_mod(module, &item.vis, item.span, item.ident);
}
ast::ItemKind::Mac(ref mac) => {
self.format_missing_with_indent(item.span.lo);
Expand All @@ -262,7 +262,7 @@ impl<'a> FmtVisitor<'a> {
}
ast::ItemKind::Static(ref ty, mutability, ref expr) => {
let rewrite = rewrite_static("static",
item.vis,
&item.vis,
item.ident,
ty,
mutability,
Expand All @@ -272,7 +272,7 @@ impl<'a> FmtVisitor<'a> {
}
ast::ItemKind::Const(ref ty, ref expr) => {
let rewrite = rewrite_static("const",
item.vis,
&item.vis,
item.ident,
ty,
ast::Mutability::Immutable,
Expand All @@ -289,7 +289,7 @@ impl<'a> FmtVisitor<'a> {
unsafety,
constness,
abi,
item.vis),
&item.vis),
decl,
body,
item.span,
Expand All @@ -301,7 +301,7 @@ impl<'a> FmtVisitor<'a> {
item.ident,
ty,
generics,
item.vis,
&item.vis,
item.span);
self.push_rewrite(item.span, rewrite);
}
Expand All @@ -316,7 +316,7 @@ impl<'a> FmtVisitor<'a> {
match ti.node {
ast::TraitItemKind::Const(ref ty, ref expr_opt) => {
let rewrite = rewrite_static("const",
ast::Visibility::Inherited,
&ast::Visibility::Inherited,
ti.ident,
ty,
ast::Mutability::Immutable,
Expand Down Expand Up @@ -354,15 +354,15 @@ impl<'a> FmtVisitor<'a> {

match ii.node {
ast::ImplItemKind::Method(ref sig, ref body) => {
self.visit_fn(visit::FnKind::Method(ii.ident, sig, Some(ii.vis)),
self.visit_fn(visit::FnKind::Method(ii.ident, sig, Some(&ii.vis)),
&sig.decl,
body,
ii.span,
ii.id);
}
ast::ImplItemKind::Const(ref ty, ref expr) => {
let rewrite = rewrite_static("const",
ii.vis,
&ii.vis,
ii.ident,
ty,
ast::Mutability::Immutable,
Expand Down Expand Up @@ -462,7 +462,7 @@ impl<'a> FmtVisitor<'a> {
}
}

fn format_mod(&mut self, m: &ast::Mod, vis: ast::Visibility, s: Span, ident: ast::Ident) {
fn format_mod(&mut self, m: &ast::Mod, vis: &ast::Visibility, s: Span, ident: ast::Ident) {
// Decide whether this is an inline mod or an external mod.
let local_file_name = self.codemap.span_to_filename(s);
let is_internal = local_file_name == self.codemap.span_to_filename(m.inner);
Expand Down Expand Up @@ -501,7 +501,7 @@ impl<'a> FmtVisitor<'a> {
self.format_missing(filemap.end_pos);
}

fn format_import(&mut self, vis: ast::Visibility, vp: &ast::ViewPath, span: Span) {
fn format_import(&mut self, vis: &ast::Visibility, vp: &ast::ViewPath, span: Span) {
let vis = utils::format_visibility(vis);
let mut offset = self.block_indent;
offset.alignment += vis.len() + "use ".len();
Expand Down