Skip to content

Commit 59b161c

Browse files
Stop Option-wrapping comments
We always check against the length before indexing anyway.
1 parent a573d14 commit 59b161c

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/librustc/hir/print.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl PpAnn for hir::Crate {
7272
pub struct State<'a> {
7373
pub s: pp::Printer<'a>,
7474
cm: Option<&'a SourceMap>,
75-
comments: Option<Vec<comments::Comment>>,
75+
comments: Vec<comments::Comment>,
7676
cur_cmnt: usize,
7777
ann: &'a (dyn PpAnn + 'a),
7878
}
@@ -82,7 +82,7 @@ impl<'a> PrintState<'a> for State<'a> {
8282
&mut self.s
8383
}
8484

85-
fn comments(&mut self) -> &mut Option<Vec<comments::Comment>> {
85+
fn comments(&mut self) -> &mut Vec<comments::Comment> {
8686
&mut self.comments
8787
}
8888

@@ -134,7 +134,7 @@ impl<'a> State<'a> {
134134
State {
135135
s: pp::mk_printer(out),
136136
cm: Some(cm),
137-
comments,
137+
comments: comments.unwrap_or_default(),
138138
cur_cmnt: 0,
139139
ann,
140140
}
@@ -149,7 +149,7 @@ pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
149149
let mut printer = State {
150150
s: pp::mk_printer(&mut wr),
151151
cm: None,
152-
comments: None,
152+
comments: Vec::new(),
153153
cur_cmnt: 0,
154154
ann,
155155
};

src/libsyntax/print/pprust.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl PpAnn for NoAnn {}
4646
pub struct State<'a> {
4747
pub s: pp::Printer<'a>,
4848
cm: Option<&'a SourceMap>,
49-
comments: Option<Vec<comments::Comment>>,
49+
comments: Vec<comments::Comment>,
5050
cur_cmnt: usize,
5151
ann: &'a (dyn PpAnn+'a),
5252
is_expanded: bool
@@ -110,7 +110,7 @@ impl<'a> State<'a> {
110110
State {
111111
s: pp::mk_printer(out),
112112
cm: Some(cm),
113-
comments,
113+
comments: comments.unwrap_or_default(),
114114
cur_cmnt: 0,
115115
ann,
116116
is_expanded,
@@ -126,7 +126,7 @@ pub fn to_string<F>(f: F) -> String where
126126
let mut printer = State {
127127
s: pp::mk_printer(&mut wr),
128128
cm: None,
129-
comments: None,
129+
comments: Vec::new(),
130130
cur_cmnt: 0,
131131
ann: &NoAnn,
132132
is_expanded: false
@@ -423,7 +423,7 @@ fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String {
423423

424424
pub trait PrintState<'a> {
425425
fn writer(&mut self) -> &mut pp::Printer<'a>;
426-
fn comments(&mut self) -> &mut Option<Vec<comments::Comment>>;
426+
fn comments(&mut self) -> &mut Vec<comments::Comment>;
427427
fn cur_cmnt(&mut self) -> &mut usize;
428428

429429
fn word_space<S: Into<Cow<'static, str>>>(&mut self, w: S) {
@@ -550,15 +550,11 @@ pub trait PrintState<'a> {
550550

551551
fn next_comment(&mut self) -> Option<comments::Comment> {
552552
let cur_cmnt = *self.cur_cmnt();
553-
match *self.comments() {
554-
Some(ref cmnts) => {
555-
if cur_cmnt < cmnts.len() {
556-
Some(cmnts[cur_cmnt].clone())
557-
} else {
558-
None
559-
}
560-
}
561-
_ => None
553+
let cmnts = &*self.comments();
554+
if cur_cmnt < cmnts.len() {
555+
Some(cmnts[cur_cmnt].clone())
556+
} else {
557+
None
562558
}
563559
}
564560

@@ -756,7 +752,7 @@ impl<'a> PrintState<'a> for State<'a> {
756752
&mut self.s
757753
}
758754

759-
fn comments(&mut self) -> &mut Option<Vec<comments::Comment>> {
755+
fn comments(&mut self) -> &mut Vec<comments::Comment> {
760756
&mut self.comments
761757
}
762758

0 commit comments

Comments
 (0)