mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 02:23:20 +00:00
Merge pull request #762 from ConnorGBrewster/fix-#760
Where clause is on same line as fn if fn is empty Fixes #760
This commit is contained in:
commit
bdcc815b18
15
src/items.rs
15
src/items.rs
@ -21,6 +21,7 @@ use comment::{FindUncommented, contains_comment};
|
||||
use visitor::FmtVisitor;
|
||||
use rewrite::{Rewrite, RewriteContext};
|
||||
use config::{Config, BlockIndentStyle, Density, ReturnIndent, BraceStyle, StructLitStyle};
|
||||
use syntax::codemap;
|
||||
|
||||
use syntax::{ast, abi};
|
||||
use syntax::codemap::{Span, BytePos, mk_sp};
|
||||
@ -180,6 +181,10 @@ impl<'a> FmtVisitor<'a> {
|
||||
let mut newline_brace = newline_for_brace(self.config, &generics.where_clause);
|
||||
let context = self.get_context();
|
||||
|
||||
let block_snippet = self.snippet(codemap::mk_sp(block.span.lo, block.span.hi));
|
||||
let has_body = !block_snippet[1..block_snippet.len() - 1].trim().is_empty() ||
|
||||
!context.config.fn_empty_single_line;
|
||||
|
||||
let (mut result, force_newline_brace) = try_opt!(rewrite_fn_base(&context,
|
||||
indent,
|
||||
ident,
|
||||
@ -192,7 +197,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
vis,
|
||||
span,
|
||||
newline_brace,
|
||||
true));
|
||||
has_body));
|
||||
|
||||
if self.config.fn_brace_style != BraceStyle::AlwaysNextLine && !result.contains('\n') {
|
||||
newline_brace = false;
|
||||
@ -1196,7 +1201,7 @@ fn rewrite_fn_base(context: &RewriteContext,
|
||||
(context.config.fn_args_layout == StructLitStyle::Block &&
|
||||
ret_str.is_empty()) ||
|
||||
(context.config.where_density == Density::CompressedIfEmpty &&
|
||||
!has_body) {
|
||||
!has_body && !result.contains('\n')) {
|
||||
Density::Compressed
|
||||
} else {
|
||||
Density::Tall
|
||||
@ -1213,6 +1218,12 @@ fn rewrite_fn_base(context: &RewriteContext,
|
||||
where_density,
|
||||
"{",
|
||||
Some(span.hi)));
|
||||
|
||||
if last_line_width(&result) + where_clause_str.len() > context.config.max_width &&
|
||||
!where_clause_str.contains('\n') {
|
||||
result.push('\n');
|
||||
}
|
||||
|
||||
result.push_str(&where_clause_str);
|
||||
|
||||
Some((result, force_new_line_for_brace))
|
||||
|
@ -74,3 +74,6 @@ trait CoolTypes {
|
||||
trait CoolerTypes { fn dummy(&self) {
|
||||
}
|
||||
}
|
||||
|
||||
fn Foo<T>() where T: Bar {
|
||||
}
|
||||
|
@ -61,3 +61,5 @@ trait CoolTypes {
|
||||
trait CoolerTypes {
|
||||
fn dummy(&self) {}
|
||||
}
|
||||
|
||||
fn Foo<T>() where T: Bar {}
|
||||
|
@ -2,17 +2,9 @@
|
||||
|
||||
fn foo(a: AAAA, b: BBB, c: CCC) -> RetType {}
|
||||
|
||||
fn foo(a: AAAA, b: BBB /* some, weird, inline comment */, c: CCC) -> RetType
|
||||
where T: Blah
|
||||
{
|
||||
fn foo(a: AAAA, b: BBB /* some, weird, inline comment */, c: CCC) -> RetType where T: Blah {}
|
||||
|
||||
}
|
||||
|
||||
fn foo(a: AAA /* (comment) */)
|
||||
where T: Blah
|
||||
{
|
||||
|
||||
}
|
||||
fn foo(a: AAA /* (comment) */) where T: Blah {}
|
||||
|
||||
fn foo(a: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
|
||||
b: BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB)
|
||||
@ -35,10 +27,7 @@ fn foo<U, T>(a: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
|
||||
fn foo<U: Fn(A) -> B /* paren inside generics */>() {}
|
||||
|
||||
impl Foo {
|
||||
fn with_no_errors<T, F>(&mut self, f: F) -> T
|
||||
where F: FnOnce(&mut Resolver) -> T
|
||||
{
|
||||
}
|
||||
fn with_no_errors<T, F>(&mut self, f: F) -> T where F: FnOnce(&mut Resolver) -> T {}
|
||||
|
||||
fn foo(mut self, mut bar: u32) {}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user