【问题标题】:How can rustfmt be configured to not emit aligning spaces for the match unsafe block pattern?如何将 rustfmt 配置为不为匹配不安全块模式发出对齐空格?
【发布时间】:2017-07-06 21:47:14
【问题描述】:

我的rustfmt 配置当前将以下代码格式化为对齐空格,如下所示。在下面的代码中,我用. 替换了空格,用---> 替换了制表符。

fn main() {
--->match unsafe {
--->--->......0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
--->--->.....} {
--->--->0 => println!("0"),
--->--->_ => println!("not 0 or 1"),
--->}
}

我的rustfmt 配置(rustfmt.toml 文件)产生了上述代码示例:

tab_spaces = 4
hard_tabs = true
array_layout = "Block"
reorder_imports = true
newline_style = "Unix"
spaces_within_angle_brackets = false
spaces_within_parens = false
spaces_within_square_brackets = false
fn_args_layout = "Block"
fn_call_style = "Block"
fn_return_indent = "WithArgs"
fn_brace_style = "SameLineWhere"
generics_indent= "Block"
item_brace_style = "PreferSameLine"
control_style = "Rfc"
match_style = "Rfc"
unsafe_style = "Rfc"
where_layout = "Horizontal"
where_pred_indent = "Block"
where_style = "Rfc"

如何将rustfmt 配置为不为前面的代码发出对齐空格(标记为:.),所以rustfmt 只使用制表符缩进如下代码?

fn main() {
--->match unsafe {
--->--->0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
--->--->} {
--->--->0 => println!("0"),
--->--->_ => println!("not 0 or 1"),
--->}
}

【问题讨论】:

  • 如何更新 rustfmt?我得到了未知的配置选项fn_brace_style(在你上面的帖子中)

标签: rust rust-cargo


【解决方案1】:

这是一个错误。我创建了一个PR 来解决这个问题,所以在它被合并后,rustfmt 不会在你的配置中发出空格。

【讨论】:

    猜你喜欢
    • 2017-06-15
    • 1970-01-01
    • 2018-09-23
    • 2011-03-17
    • 1970-01-01
    • 2019-12-03
    • 2012-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多