mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
Fix trailing commas in where clauses
This commit is contained in:
parent
40be79304e
commit
decafbbaea
@ -88,9 +88,6 @@ impl<'a> FmtVisitor<'a> {
|
||||
result.len() + indent + ret_str.len() > MAX_WIDTH {
|
||||
let indent = match FN_RETURN_INDENT {
|
||||
ReturnIndent::WithWhereClause => indent + 4,
|
||||
ReturnIndent::WithWhereClauseOrArgs if where_clause.predicates.len() > 0 => {
|
||||
indent + 4
|
||||
}
|
||||
// TODO we might want to check that using the arg indent doesn't
|
||||
// blow our budget, and if it does, then fallback to the where
|
||||
// clause indent.
|
||||
@ -254,7 +251,8 @@ impl<'a> FmtVisitor<'a> {
|
||||
// The fix is comments in the AST or a span for the closing paren.
|
||||
let snippet = self.snippet(codemap::mk_sp(prev_end, next_span_start));
|
||||
let snippet = snippet.trim();
|
||||
let snippet = &snippet[..snippet.find(terminator).unwrap_or(snippet.len())];
|
||||
let snippet = &snippet[..snippet.find(terminator)
|
||||
.unwrap_or(snippet.find(separator).unwrap_or(snippet.len()))];
|
||||
let snippet = snippet.trim();
|
||||
result.push(snippet.to_string());
|
||||
|
||||
|
@ -68,7 +68,7 @@ const MAX_WIDTH: usize = 100;
|
||||
const MIN_STRING: usize = 10;
|
||||
const TAB_SPACES: usize = 4;
|
||||
const FN_BRACE_STYLE: BraceStyle = BraceStyle::SameLineWhere;
|
||||
const FN_RETURN_INDENT: ReturnIndent = ReturnIndent::WithWhereClauseOrArgs;
|
||||
const FN_RETURN_INDENT: ReturnIndent = ReturnIndent::WithArgs;
|
||||
// When we get scoped annotations, we should have rustfmt::skip.
|
||||
const SKIP_ANNOTATION: &'static str = "rustfmt_skip";
|
||||
|
||||
@ -99,8 +99,6 @@ enum ReturnIndent {
|
||||
WithArgs,
|
||||
// Aligned with the where clause
|
||||
WithWhereClause,
|
||||
// Aligned with the where clause if there is one, otherwise the args.
|
||||
WithWhereClauseOrArgs,
|
||||
}
|
||||
|
||||
// Formatting which depends on the AST.
|
||||
|
@ -1,5 +1,12 @@
|
||||
// Test attributes and doc comments are preserved.
|
||||
|
||||
extern crate Foo;
|
||||
#[Attr1]
|
||||
extern crate Bar;
|
||||
#[Attr2]
|
||||
#[Attr2]
|
||||
extern crate Baz;
|
||||
|
||||
/// Blah blah blah.
|
||||
impl Bar {
|
||||
/// Blah blah blooo.
|
||||
|
@ -9,7 +9,7 @@ fn foo<F, G>(a: aaaaaaaaaaaaa, // A comment
|
||||
// A multi line comment
|
||||
// between args.
|
||||
e: eeeeeeeeeeeee /* comment before paren*/)
|
||||
-> bar
|
||||
-> bar
|
||||
where F: Foo, // COmment after where clause
|
||||
G: Goo /* final comment */
|
||||
{
|
||||
|
42
tests/idem/fn.rs
Normal file
42
tests/idem/fn.rs
Normal file
@ -0,0 +1,42 @@
|
||||
// Tests different fns
|
||||
|
||||
fn foo(a: AAAA, b: BBB, c: CCC) -> RetType {
|
||||
|
||||
}
|
||||
|
||||
fn foo(a: AAAA, b: BBB, c: CCC) -> RetType
|
||||
where T: Blah
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
fn foo(a: AAA)
|
||||
where T: Blah
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
fn foo(a: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
|
||||
b: BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB)
|
||||
-> RetType
|
||||
where T: Blah
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
fn foo<U, T>(a: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
|
||||
b: BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB)
|
||||
-> RetType
|
||||
where T: Blah,
|
||||
U: dsfasdfasdfasd
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
fn with_no_errors<T, F>(&mut self, f: F) -> T
|
||||
where F: FnOnce(&mut Resolver) -> T
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user