@@ -2009,6 +2009,7 @@ pub(crate) struct StaticParts<'a> {
2009
2009
safety: ast::Safety,
2010
2010
vis: &'a ast::Visibility,
2011
2011
ident: symbol::Ident,
2012
+ generics: Option<&'a ast::Generics>,
2012
2013
ty: &'a ast::Ty,
2013
2014
mutability: ast::Mutability,
2014
2015
expr_opt: Option<&'a ptr::P<ast::Expr>>,
@@ -2018,15 +2019,18 @@ pub(crate) struct StaticParts<'a> {
2018
2019
2019
2020
impl<'a> StaticParts<'a> {
2020
2021
pub(crate) fn from_item(item: &'a ast::Item) -> Self {
2021
- let (defaultness, prefix, safety, ty, mutability, expr) = match &item.kind {
2022
- ast::ItemKind::Static(s) => (None, "static", s.safety, &s.ty, s.mutability, &s.expr),
2022
+ let (defaultness, prefix, safety, ty, mutability, expr, generics) = match &item.kind {
2023
+ ast::ItemKind::Static(s) => {
2024
+ (None, "static", s.safety, &s.ty, s.mutability, &s.expr, None)
2025
+ }
2023
2026
ast::ItemKind::Const(c) => (
2024
2027
Some(c.defaultness),
2025
2028
"const",
2026
2029
ast::Safety::Default,
2027
2030
&c.ty,
2028
2031
ast::Mutability::Not,
2029
2032
&c.expr,
2033
+ Some(&c.generics),
2030
2034
),
2031
2035
_ => unreachable!(),
2032
2036
};
@@ -2035,6 +2039,7 @@ impl<'a> StaticParts<'a> {
2035
2039
safety,
2036
2040
vis: &item.vis,
2037
2041
ident: item.ident,
2042
+ generics,
2038
2043
ty,
2039
2044
mutability,
2040
2045
expr_opt: expr.as_ref(),
@@ -2044,15 +2049,16 @@ impl<'a> StaticParts<'a> {
2044
2049
}
2045
2050
2046
2051
pub(crate) fn from_trait_item(ti: &'a ast::AssocItem) -> Self {
2047
- let (defaultness, ty, expr_opt) = match &ti.kind {
2048
- ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
2052
+ let (defaultness, ty, expr_opt, generics ) = match &ti.kind {
2053
+ ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics) ),
2049
2054
_ => unreachable!(),
2050
2055
};
2051
2056
StaticParts {
2052
2057
prefix: "const",
2053
2058
safety: ast::Safety::Default,
2054
2059
vis: &ti.vis,
2055
2060
ident: ti.ident,
2061
+ generics,
2056
2062
ty,
2057
2063
mutability: ast::Mutability::Not,
2058
2064
expr_opt: expr_opt.as_ref(),
@@ -2062,15 +2068,16 @@ impl<'a> StaticParts<'a> {
2062
2068
}
2063
2069
2064
2070
pub(crate) fn from_impl_item(ii: &'a ast::AssocItem) -> Self {
2065
- let (defaultness, ty, expr) = match &ii.kind {
2066
- ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
2071
+ let (defaultness, ty, expr, generics ) = match &ii.kind {
2072
+ ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics) ),
2067
2073
_ => unreachable!(),
2068
2074
};
2069
2075
StaticParts {
2070
2076
prefix: "const",
2071
2077
safety: ast::Safety::Default,
2072
2078
vis: &ii.vis,
2073
2079
ident: ii.ident,
2080
+ generics,
2074
2081
ty,
2075
2082
mutability: ast::Mutability::Not,
2076
2083
expr_opt: expr.as_ref(),
@@ -2085,6 +2092,14 @@ fn rewrite_static(
2085
2092
static_parts: &StaticParts<'_>,
2086
2093
offset: Indent,
2087
2094
) -> Option<String> {
2095
+ // For now, if this static (or const) has generics, then bail.
2096
+ if static_parts
2097
+ .generics
2098
+ .is_some_and(|g| !g.params.is_empty() || !g.where_clause.is_empty())
2099
+ {
2100
+ return None;
2101
+ }
2102
+
2088
2103
let colon = colon_spaces(context.config);
2089
2104
let mut prefix = format!(
2090
2105
"{}{}{}{} {}{}{}",
0 commit comments