Skip to content

Commit

Permalink
Implement RTN support in rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 28, 2024
1 parent fabc8f6 commit 55eb7b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/tools/rustfmt/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,21 +484,25 @@ fn rewrite_generic_args(
span: Span,
) -> Option<String> {
match gen_args {
ast::GenericArgs::AngleBracketed(ref data) if !data.args.is_empty() => {
let args = data
.args
.iter()
.map(|x| match x {
ast::AngleBracketedArg::Arg(generic_arg) => {
SegmentParam::from_generic_arg(generic_arg)
}
ast::AngleBracketedArg::Constraint(constraint) => {
SegmentParam::Binding(constraint)
}
})
.collect::<Vec<_>>();
ast::GenericArgs::AngleBracketed(ref data) => {
if data.args.is_empty() {
Some("".to_owned())
} else {
let args = data
.args
.iter()
.map(|x| match x {
ast::AngleBracketedArg::Arg(generic_arg) => {
SegmentParam::from_generic_arg(generic_arg)
}
ast::AngleBracketedArg::Constraint(constraint) => {
SegmentParam::Binding(constraint)
}
})
.collect::<Vec<_>>();

overflow::rewrite_with_angle_brackets(context, "", args.iter(), shape, span)
overflow::rewrite_with_angle_brackets(context, "", args.iter(), shape, span)
}
}
ast::GenericArgs::Parenthesized(ref data) => format_function_type(
data.inputs.iter().map(|x| &**x),
Expand All @@ -508,7 +512,7 @@ fn rewrite_generic_args(
context,
shape,
),
_ => Some("".to_owned()),
ast::GenericArgs::ParenthesizedElided(..) => Some("(..)".to_owned()),
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/tools/rustfmt/tests/target/return-type-notation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn rtn()
where
T: Trait<method(..): Send + 'static>,
T::method(..): Send + 'static,
{
}

fn test() {
let x: T::method(..);
}

0 comments on commit 55eb7b7

Please sign in to comment.