Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2107,28 +2107,44 @@ fn rewrite_static(
static_parts: &StaticParts<'_>,
offset: Indent,
) -> Option<String> {
// For now, if this static (or const) has generics, then bail.
// For now, if this static (or const) has a where clause, then bail.
if static_parts
.generics
.is_some_and(|g| !g.params.is_empty() || !g.where_clause.is_empty())
.is_some_and(|g| !g.where_clause.is_empty())
{
return None;
}

let gen = static_parts
.generics
.and_then(|g| {
format_generics(
context,
&g,
context.config.brace_style(),
BracePos::None,
offset,
// make a span that starts right after `const x<n>`
mk_sp(static_parts.ident.span.hi(), static_parts.ty.span.lo()),
offset.block_indent + 1,
)
})
.map_or("".into(), |x| format!("{x}"));
let colon = colon_spaces(context.config);
let mut prefix = format!(
"{}{}{}{} {}{}{}",
"{}{}{}{} {}{}{}{}",
format_visibility(context, static_parts.vis),
static_parts.defaultness.map_or("", format_defaultness),
format_safety(static_parts.safety),
static_parts.prefix,
format_mutability(static_parts.mutability),
rewrite_ident(context, static_parts.ident),
colon,
gen,
colon
);

// 2 = " =".len()
let ty_shape =
Shape::indented(offset.block_only(), context.config).offset_left_opt(prefix.len() + 2)?;
let ty_shape = Shape::indented(offset.block_only(), context.config)
.offset_left_opt(last_line_width(&prefix) + 2)?;
let ty_str = match static_parts.ty.rewrite(context, ty_shape) {
Some(ty_str) => ty_str,
None => {
Expand Down
6 changes: 6 additions & 0 deletions tests/source/static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ impl Color {
pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: NTSTATUS = 0 as usize;

pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: Yyyyyyyyyyyyyyyyyyyyyyyyyyyy = 1;



pub const SORT<T:Copy+'static,const SET: &'static[T]>:
&[T]= const { 4};

2 changes: 2 additions & 0 deletions tests/target/static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:
Yyyyyyyyyyyyyyyyyyyyyyyyyyyy = 1;

pub const SORT<T: Copy + 'static, const SET: &'static [T]>: &[T] = const { 4 };
Loading