diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-07-05 16:32:15 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-07-10 07:12:28 -0400 |
| commit | 59b161c7c84e48b9379fbed877a2fa5c13db0526 (patch) | |
| tree | 14e5578a6615211925dd7357a97223c905b52b1f /src | |
| parent | a573d143a2b7ef9d04a8fe6904667762e47157bc (diff) | |
| download | rust-59b161c7c84e48b9379fbed877a2fa5c13db0526.tar.gz rust-59b161c7c84e48b9379fbed877a2fa5c13db0526.zip | |
Stop Option-wrapping comments
We always check against the length before indexing anyway.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/hir/print.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 24 |
2 files changed, 14 insertions, 18 deletions
diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 137f20d6c32..9acf6d895e3 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -72,7 +72,7 @@ impl PpAnn for hir::Crate { pub struct State<'a> { pub s: pp::Printer<'a>, cm: Option<&'a SourceMap>, - comments: Option<Vec<comments::Comment>>, + comments: Vec<comments::Comment>, cur_cmnt: usize, ann: &'a (dyn PpAnn + 'a), } @@ -82,7 +82,7 @@ impl<'a> PrintState<'a> for State<'a> { &mut self.s } - fn comments(&mut self) -> &mut Option<Vec<comments::Comment>> { + fn comments(&mut self) -> &mut Vec<comments::Comment> { &mut self.comments } @@ -134,7 +134,7 @@ impl<'a> State<'a> { State { s: pp::mk_printer(out), cm: Some(cm), - comments, + comments: comments.unwrap_or_default(), cur_cmnt: 0, ann, } @@ -149,7 +149,7 @@ pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String let mut printer = State { s: pp::mk_printer(&mut wr), cm: None, - comments: None, + comments: Vec::new(), cur_cmnt: 0, ann, }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 4c86300b805..460c4434712 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -46,7 +46,7 @@ impl PpAnn for NoAnn {} pub struct State<'a> { pub s: pp::Printer<'a>, cm: Option<&'a SourceMap>, - comments: Option<Vec<comments::Comment>>, + comments: Vec<comments::Comment>, cur_cmnt: usize, ann: &'a (dyn PpAnn+'a), is_expanded: bool @@ -110,7 +110,7 @@ impl<'a> State<'a> { State { s: pp::mk_printer(out), cm: Some(cm), - comments, + comments: comments.unwrap_or_default(), cur_cmnt: 0, ann, is_expanded, @@ -126,7 +126,7 @@ pub fn to_string<F>(f: F) -> String where let mut printer = State { s: pp::mk_printer(&mut wr), cm: None, - comments: None, + comments: Vec::new(), cur_cmnt: 0, ann: &NoAnn, is_expanded: false @@ -423,7 +423,7 @@ fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String { pub trait PrintState<'a> { fn writer(&mut self) -> &mut pp::Printer<'a>; - fn comments(&mut self) -> &mut Option<Vec<comments::Comment>>; + fn comments(&mut self) -> &mut Vec<comments::Comment>; fn cur_cmnt(&mut self) -> &mut usize; fn word_space<S: Into<Cow<'static, str>>>(&mut self, w: S) { @@ -550,15 +550,11 @@ pub trait PrintState<'a> { fn next_comment(&mut self) -> Option<comments::Comment> { let cur_cmnt = *self.cur_cmnt(); - match *self.comments() { - Some(ref cmnts) => { - if cur_cmnt < cmnts.len() { - Some(cmnts[cur_cmnt].clone()) - } else { - None - } - } - _ => None + let cmnts = &*self.comments(); + if cur_cmnt < cmnts.len() { + Some(cmnts[cur_cmnt].clone()) + } else { + None } } @@ -756,7 +752,7 @@ impl<'a> PrintState<'a> for State<'a> { &mut self.s } - fn comments(&mut self) -> &mut Option<Vec<comments::Comment>> { + fn comments(&mut self) -> &mut Vec<comments::Comment> { &mut self.comments } |
