Skip to content

Commit 90c0f70

Browse files
committed
Merge pull request #971 from kamalmarhubi/update-syntex-syntax
deps: Update syntex_syntax to 0.31.0
2 parents c696dcf + 6285d53 commit 90c0f70

File tree

5 files changed

+74
-69
lines changed

5 files changed

+74
-69
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ regex = "0.1"
2121
term = "0.4"
2222
strings = "0.0.1"
2323
diff = "0.1"
24-
syntex_syntax = "0.30"
24+
syntex_syntax = "0.31"
2525
log = "0.3"
2626
env_logger = "0.3"
2727
getopts = "0.2"

src/items.rs

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a> FmtVisitor<'a> {
126126
// These are not actually rust functions,
127127
// but we format them as such.
128128
abi::Abi::Rust,
129-
item.vis,
129+
&item.vis,
130130
span,
131131
false,
132132
false);
@@ -142,15 +142,16 @@ impl<'a> FmtVisitor<'a> {
142142
ast::ForeignItemKind::Static(ref ty, is_mutable) => {
143143
// FIXME(#21): we're dropping potential comments in between the
144144
// function keywords here.
145+
let vis = match format_visibility(&item.vis) {
146+
Some(s) => s,
147+
None => return,
148+
};
145149
let mut_str = if is_mutable {
146150
"mut "
147151
} else {
148152
""
149153
};
150-
let prefix = format!("{}static {}{}: ",
151-
format_visibility(item.vis),
152-
mut_str,
153-
item.ident);
154+
let prefix = format!("{}static {}{}: ", vis, mut_str, item.ident);
154155
let offset = self.block_indent + prefix.len();
155156
// 1 = ;
156157
let width = self.config.max_width - offset.width() - 1;
@@ -179,7 +180,7 @@ impl<'a> FmtVisitor<'a> {
179180
unsafety: ast::Unsafety,
180181
constness: ast::Constness,
181182
abi: abi::Abi,
182-
vis: ast::Visibility,
183+
vis: &ast::Visibility,
183184
span: Span,
184185
block: &ast::Block)
185186
-> Option<String> {
@@ -244,7 +245,7 @@ impl<'a> FmtVisitor<'a> {
244245
sig.unsafety,
245246
sig.constness,
246247
sig.abi,
247-
ast::Visibility::Inherited,
248+
&ast::Visibility::Inherited,
248249
span,
249250
false,
250251
false));
@@ -303,11 +304,14 @@ impl<'a> FmtVisitor<'a> {
303304

304305
pub fn visit_enum(&mut self,
305306
ident: ast::Ident,
306-
vis: ast::Visibility,
307+
vis: &ast::Visibility,
307308
enum_def: &ast::EnumDef,
308309
generics: &ast::Generics,
309310
span: Span) {
310-
let header_str = format_header("enum ", ident, vis);
311+
let header_str = match format_header("enum ", ident, vis) {
312+
Some(s) => s,
313+
None => return,
314+
};
311315
self.buffer.push_str(&header_str);
312316

313317
let enum_snippet = self.snippet(span);
@@ -414,7 +418,7 @@ impl<'a> FmtVisitor<'a> {
414418
format_struct(&context,
415419
"",
416420
field.node.name,
417-
ast::Visibility::Inherited,
421+
&ast::Visibility::Inherited,
418422
&field.node.data,
419423
None,
420424
field.span,
@@ -451,7 +455,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
451455
ref self_ty,
452456
ref items) = item.node {
453457
let mut result = String::new();
454-
result.push_str(format_visibility(item.vis));
458+
result.push_str(try_opt!(format_visibility(&item.vis)));
455459
result.push_str(format_unsafety(unsafety));
456460
result.push_str("impl");
457461

@@ -583,7 +587,7 @@ fn is_impl_single_line(context: &RewriteContext,
583587
pub fn format_struct(context: &RewriteContext,
584588
item_name: &str,
585589
ident: ast::Ident,
586-
vis: ast::Visibility,
590+
vis: &ast::Visibility,
587591
struct_def: &ast::VariantData,
588592
generics: Option<&ast::Generics>,
589593
span: Span,
@@ -619,7 +623,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
619623
item.node {
620624
let mut result = String::new();
621625
let header = format!("{}{}trait {}",
622-
format_visibility(item.vis),
626+
try_opt!(format_visibility(&item.vis)),
623627
format_unsafety(unsafety),
624628
item.ident);
625629

@@ -741,10 +745,10 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
741745
}
742746
}
743747

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

747-
let header_str = format_header(item_name, ident, vis);
751+
let header_str = try_opt!(format_header(item_name, ident, vis));
748752
result.push_str(&header_str);
749753
result.push(';');
750754

@@ -754,15 +758,15 @@ fn format_unit_struct(item_name: &str, ident: ast::Ident, vis: ast::Visibility)
754758
fn format_struct_struct(context: &RewriteContext,
755759
item_name: &str,
756760
ident: ast::Ident,
757-
vis: ast::Visibility,
761+
vis: &ast::Visibility,
758762
fields: &[ast::StructField],
759763
generics: Option<&ast::Generics>,
760764
span: Span,
761765
offset: Indent)
762766
-> Option<String> {
763767
let mut result = String::with_capacity(1024);
764768

765-
let header_str = format_header(item_name, ident, vis);
769+
let header_str = try_opt!(format_header(item_name, ident, vis));
766770
result.push_str(&header_str);
767771

768772
let body_lo = context.codemap.span_after(span, "{");
@@ -804,13 +808,13 @@ fn format_struct_struct(context: &RewriteContext,
804808
"}",
805809
|field| {
806810
// Include attributes and doc comments, if present
807-
if !field.node.attrs.is_empty() {
808-
field.node.attrs[0].span.lo
811+
if !field.attrs.is_empty() {
812+
field.attrs[0].span.lo
809813
} else {
810814
field.span.lo
811815
}
812816
},
813-
|field| field.node.ty.span.hi,
817+
|field| field.ty.span.hi,
814818
|field| field.rewrite(context, item_budget, item_indent),
815819
context.codemap.span_after(span, "{"),
816820
span.hi);
@@ -835,15 +839,15 @@ fn format_struct_struct(context: &RewriteContext,
835839
fn format_tuple_struct(context: &RewriteContext,
836840
item_name: &str,
837841
ident: ast::Ident,
838-
vis: ast::Visibility,
842+
vis: &ast::Visibility,
839843
fields: &[ast::StructField],
840844
generics: Option<&ast::Generics>,
841845
span: Span,
842846
offset: Indent)
843847
-> Option<String> {
844848
let mut result = String::with_capacity(1024);
845849

846-
let header_str = format_header(item_name, ident, vis);
850+
let header_str = try_opt!(format_header(item_name, ident, vis));
847851
result.push_str(&header_str);
848852

849853
// FIXME(#919): don't lose comments on empty tuple structs.
@@ -890,13 +894,13 @@ fn format_tuple_struct(context: &RewriteContext,
890894
")",
891895
|field| {
892896
// Include attributes and doc comments, if present
893-
if !field.node.attrs.is_empty() {
894-
field.node.attrs[0].span.lo
897+
if !field.attrs.is_empty() {
898+
field.attrs[0].span.lo
895899
} else {
896900
field.span.lo
897901
}
898902
},
899-
|field| field.node.ty.span.hi,
903+
|field| field.ty.span.hi,
900904
|field| field.rewrite(context, item_budget, item_indent),
901905
context.codemap.span_after(span, "("),
902906
span.hi);
@@ -924,12 +928,12 @@ pub fn rewrite_type_alias(context: &RewriteContext,
924928
ident: ast::Ident,
925929
ty: &ast::Ty,
926930
generics: &ast::Generics,
927-
vis: ast::Visibility,
931+
vis: &ast::Visibility,
928932
span: Span)
929933
-> Option<String> {
930934
let mut result = String::new();
931935

932-
result.push_str(&format_visibility(vis));
936+
result.push_str(&try_opt!(format_visibility(&vis)));
933937
result.push_str("type ");
934938
result.push_str(&ident.to_string());
935939

@@ -991,21 +995,14 @@ pub fn rewrite_type_alias(context: &RewriteContext,
991995

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

999-
let name = match self.node.kind {
1000-
ast::StructFieldKind::NamedField(ident, _) => Some(ident.to_string()),
1001-
ast::StructFieldKind::UnnamedField(_) => None,
1002-
};
1003-
let vis = match self.node.kind {
1004-
ast::StructFieldKind::NamedField(_, vis) |
1005-
ast::StructFieldKind::UnnamedField(vis) => format_visibility(vis),
1006-
};
1007-
let mut attr_str = try_opt!(self.node
1008-
.attrs
1003+
let name = self.ident;
1004+
let vis = try_opt!(format_visibility(&self.vis));
1005+
let mut attr_str = try_opt!(self.attrs
10091006
.rewrite(context, context.config.max_width - offset.width(), offset));
10101007
if !attr_str.is_empty() {
10111008
attr_str.push('\n');
@@ -1019,21 +1016,21 @@ impl Rewrite for ast::StructField {
10191016

10201017
let last_line_width = last_line_width(&result);
10211018
let budget = try_opt!(width.checked_sub(last_line_width));
1022-
let rewrite = try_opt!(self.node.ty.rewrite(context, budget, offset + last_line_width));
1019+
let rewrite = try_opt!(self.ty.rewrite(context, budget, offset + last_line_width));
10231020
Some(result + &rewrite)
10241021
}
10251022
}
10261023

10271024
pub fn rewrite_static(prefix: &str,
1028-
vis: ast::Visibility,
1025+
vis: &ast::Visibility,
10291026
ident: ast::Ident,
10301027
ty: &ast::Ty,
10311028
mutability: ast::Mutability,
10321029
expr_opt: Option<&ptr::P<ast::Expr>>,
10331030
context: &RewriteContext)
10341031
-> Option<String> {
10351032
let prefix = format!("{}{} {}{}: ",
1036-
format_visibility(vis),
1033+
try_opt!(format_visibility(vis)),
10371034
prefix,
10381035
format_mutability(mutability),
10391036
ident);
@@ -1239,7 +1236,7 @@ fn rewrite_fn_base(context: &RewriteContext,
12391236
unsafety: ast::Unsafety,
12401237
constness: ast::Constness,
12411238
abi: abi::Abi,
1242-
vis: ast::Visibility,
1239+
vis: &ast::Visibility,
12431240
span: Span,
12441241
newline_brace: bool,
12451242
has_body: bool)
@@ -1252,7 +1249,7 @@ fn rewrite_fn_base(context: &RewriteContext,
12521249

12531250
let mut result = String::with_capacity(1024);
12541251
// Vis unsafety abi.
1255-
result.push_str(format_visibility(vis));
1252+
result.push_str(try_opt!(format_visibility(vis)));
12561253

12571254
if let ast::Constness::Const = constness {
12581255
result.push_str("const ");
@@ -1808,8 +1805,8 @@ fn rewrite_where_clause(context: &RewriteContext,
18081805
}
18091806
}
18101807

1811-
fn format_header(item_name: &str, ident: ast::Ident, vis: ast::Visibility) -> String {
1812-
format!("{}{}{}", format_visibility(vis), item_name, ident)
1808+
fn format_header(item_name: &str, ident: ast::Ident, vis: &ast::Visibility) -> Option<String> {
1809+
Some(format!("{}{}{}", try_opt!(format_visibility(vis)), item_name, ident))
18131810
}
18141811

18151812
fn format_generics(context: &RewriteContext,

src/utils.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ pub fn extra_offset(text: &str, offset: Indent) -> usize {
6767
}
6868

6969
#[inline]
70-
pub fn format_visibility(vis: Visibility) -> &'static str {
71-
match vis {
72-
Visibility::Public => "pub ",
73-
Visibility::Inherited => "",
70+
pub fn format_visibility(vis: &Visibility) -> Option<&'static str> {
71+
match *vis {
72+
Visibility::Public => Some("pub "),
73+
Visibility::Inherited => Some(""),
74+
// FIXME(#970): Handle new visibility types.
75+
Visibility::Crate => None,
76+
Visibility::Restricted { .. } => None,
7477
}
7578
}
7679

0 commit comments

Comments
 (0)