mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-12 20:16:49 +00:00
Use recover_comment_removed in rewrite_static
This commit is contained in:
parent
6f1cb950d6
commit
d54634bd7c
15
src/items.rs
15
src/items.rs
@ -18,7 +18,7 @@ use utils::{format_mutability, format_visibility, contains_skip, end_typaram, wr
|
||||
use lists::{write_list, itemize_list, ListItem, ListFormatting, SeparatorTactic, list_helper,
|
||||
DefinitiveListTactic, ListTactic, definitive_tactic, format_item_list};
|
||||
use expr::{is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, type_annotation_separator};
|
||||
use comment::{FindUncommented, contains_comment, rewrite_comment};
|
||||
use comment::{FindUncommented, contains_comment, rewrite_comment, recover_comment_removed};
|
||||
use visitor::FmtVisitor;
|
||||
use rewrite::{Rewrite, RewriteContext};
|
||||
use config::{Config, IndentStyle, Density, ReturnIndent, BraceStyle, Style, TypeDensity};
|
||||
@ -1299,6 +1299,7 @@ pub fn rewrite_static(prefix: &str,
|
||||
mutability: ast::Mutability,
|
||||
expr_opt: Option<&ptr::P<ast::Expr>>,
|
||||
offset: Indent,
|
||||
span: Span,
|
||||
context: &RewriteContext)
|
||||
-> Option<String> {
|
||||
let type_annotation_spacing = type_annotation_spacing(context.config);
|
||||
@ -1325,7 +1326,17 @@ pub fn rewrite_static(prefix: &str,
|
||||
lhs,
|
||||
expr,
|
||||
Shape::legacy(remaining_width, offset.block_only()))
|
||||
.map(|s| s + ";")
|
||||
.and_then(|res| {
|
||||
recover_comment_removed(res,
|
||||
span,
|
||||
context,
|
||||
Shape {
|
||||
width: context.config.max_width(),
|
||||
indent: offset,
|
||||
offset: offset.alignment,
|
||||
})
|
||||
})
|
||||
.map(|s| if s.ends_with(';') { s } else { s + ";" })
|
||||
} else {
|
||||
let lhs = format!("{}{};", prefix, ty_str);
|
||||
Some(lhs)
|
||||
|
@ -322,6 +322,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
mutability,
|
||||
Some(expr),
|
||||
self.block_indent,
|
||||
item.span,
|
||||
&self.get_context());
|
||||
self.push_rewrite(item.span, rewrite);
|
||||
}
|
||||
@ -333,6 +334,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
ast::Mutability::Immutable,
|
||||
Some(expr),
|
||||
self.block_indent,
|
||||
item.span,
|
||||
&self.get_context());
|
||||
self.push_rewrite(item.span, rewrite);
|
||||
}
|
||||
@ -383,6 +385,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
ast::Mutability::Immutable,
|
||||
expr_opt.as_ref(),
|
||||
self.block_indent,
|
||||
ti.span,
|
||||
&self.get_context());
|
||||
self.push_rewrite(ti.span, rewrite);
|
||||
}
|
||||
@ -434,6 +437,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
ast::Mutability::Immutable,
|
||||
Some(expr),
|
||||
self.block_indent,
|
||||
ii.span,
|
||||
&self.get_context());
|
||||
self.push_rewrite(ii.span, rewrite);
|
||||
}
|
||||
|
9
tests/target/comment-inside-const.rs
Normal file
9
tests/target/comment-inside-const.rs
Normal file
@ -0,0 +1,9 @@
|
||||
fn issue982() {
|
||||
const SOME_CONSTANT: u32 =
|
||||
// Explanation why SOME_CONSTANT needs FLAG_A to be set.
|
||||
FLAG_A |
|
||||
// Explanation why SOME_CONSTANT needs FLAG_B to be set.
|
||||
FLAG_B |
|
||||
// Explanation why SOME_CONSTANT needs FLAG_C to be set.
|
||||
FLAG_C;
|
||||
}
|
Loading…
Reference in New Issue
Block a user