From 352440c2490f8ba11b0aa04d6c59c7601b1983f4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 8 Mar 2025 18:51:50 -0500 Subject: [PATCH 1/2] fix --- src/types.rs | 49 +++++++++++++++++++++++++++------- tests/source/long_type_path.rs | 15 +++++++++++ tests/target/enum.rs | 3 ++- tests/target/issue-3741.rs | 12 ++++++--- tests/target/issue_4579.rs | 6 ++--- tests/target/long_type_path.rs | 5 ++++ tests/target/match.rs | 4 +-- 7 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 tests/source/long_type_path.rs create mode 100644 tests/target/long_type_path.rs diff --git a/src/types.rs b/src/types.rs index 6180a4dac13..5a0a968f1e8 100644 --- a/src/types.rs +++ b/src/types.rs @@ -34,7 +34,6 @@ pub(crate) enum PathContext { Import, } -// Does not wrap on simple segments. pub(crate) fn rewrite_path( context: &RewriteContext<'_>, path_context: PathContext, @@ -115,24 +114,35 @@ where if segment.ident.name == kw::PathRoot { continue; } - if first { - first = false; - } else { + + if !first { buffer.push_str("::"); } - let extra_offset = extra_offset(&buffer, shape); - let new_shape = shape.shrink_left(extra_offset, mk_sp(span_lo, span_hi))?; + let new_shape = match shape.shrink_left_opt(extra_offset(&buffer, shape)) { + Some(s) => s, + None => { + buffer.push('\n'); + shape.shrink_left(extra_offset(&buffer, shape), mk_sp(span_lo, span_hi))? + } + }; + let segment_string = rewrite_segment( path_context, segment, &mut span_lo, span_hi, context, + shape, new_shape, + first, )?; buffer.push_str(&segment_string); + + if first { + first = false; + } } Ok(buffer) @@ -270,16 +280,37 @@ fn rewrite_segment( span_hi: BytePos, context: &RewriteContext<'_>, shape: Shape, + new_shape: Shape, + first: bool, ) -> RewriteResult { let mut result = String::with_capacity(128); result.push_str(rewrite_ident(context, segment.ident)); let ident_len = result.len(); + let span = mk_sp(*span_lo, span_hi); - let shape = if context.use_block_indent() { - shape.offset_left(ident_len, span)? + + let new_shape = if context.use_block_indent() { + new_shape.offset_left(ident_len, span) + } else { + new_shape.shrink_left(ident_len, span) + }; + + let shape = if first { + new_shape? } else { - shape.shrink_left(ident_len, span)? + match new_shape { + Ok(s) => s, + Err(_) => { + let mut shape = shape; + // dbg!(&shape); + shape.indent = shape.indent.block_indent(context.config).block_only(); + // dbg!(&result, shape); + result.insert_str(0, &shape.indent.to_string_with_newline(context.config)); + // dbg!(&result); + shape + } + } }; if let Some(ref args) = segment.args { diff --git a/tests/source/long_type_path.rs b/tests/source/long_type_path.rs new file mode 100644 index 00000000000..ce4366e77dd --- /dev/null +++ b/tests/source/long_type_path.rs @@ -0,0 +1,15 @@ +fn test() { + let a: long_type_path:: + long_type_path::long_type_path::long_type_path + + + + ::long_type_path + + + ::long_type_path::long_type_path::long_type_path::long_type_path::long_type_path + + + ::Long = + Default::default(); +} diff --git a/tests/target/enum.rs b/tests/target/enum.rs index 83b30999725..63c6450e06e 100644 --- a/tests/target/enum.rs +++ b/tests/target/enum.rs @@ -269,7 +269,8 @@ enum Bar {} enum PublishedFileVisibility { Public = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPublic, - FriendsOnly = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly, + FriendsOnly = sys:: + ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly, Private = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate, } diff --git a/tests/target/issue-3741.rs b/tests/target/issue-3741.rs index 34d22dc91eb..1a0826f8930 100644 --- a/tests/target/issue-3741.rs +++ b/tests/target/issue-3741.rs @@ -1,5 +1,11 @@ pub enum PublishedFileVisibility { - Public = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPublic as i32, - FriendsOnly = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly as i32, - Private = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate as i32, + Public = sys:: + ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPublic + as i32, + FriendsOnly = sys:: + ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly + as i32, + Private = sys:: + ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate + as i32, } diff --git a/tests/target/issue_4579.rs b/tests/target/issue_4579.rs index 7b0a5f3a62e..9170fcc92bc 100644 --- a/tests/target/issue_4579.rs +++ b/tests/target/issue_4579.rs @@ -6,10 +6,8 @@ macro_rules! main { #[spirv(fragment)] pub fn main_fs( mut out_color: ::spirv_std::storage_class::Output, - #[spirv(descriptor_set = 1)] - iChannelResolution: ::spirv_std::storage_class::UniformConstant< - [::spirv_std::glam::Vec3A; 4], - >, + #[spirv(descriptor_set = 1)] iChannelResolution: ::spirv_std::storage_class:: + UniformConstant<[::spirv_std::glam::Vec3A; 4]>, ) { } }; diff --git a/tests/target/long_type_path.rs b/tests/target/long_type_path.rs new file mode 100644 index 00000000000..4717869f395 --- /dev/null +++ b/tests/target/long_type_path.rs @@ -0,0 +1,5 @@ +fn test() { + let a: long_type_path::long_type_path::long_type_path::long_type_path::long_type_path:: + long_type_path::long_type_path::long_type_path::long_type_path::long_type_path::Long = + Default::default(); +} diff --git a/tests/target/match.rs b/tests/target/match.rs index 0e7815a814d..46eded50edb 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -257,10 +257,10 @@ fn issue507() { fn issue508() { match s.type_id() { Some(NodeTypeId::Element(ElementTypeId::HTMLElement( - HTMLElementTypeId::HTMLCanvasElement, + HTMLElementTypeId::HTMLCanvasElement ))) => true, Some(NodeTypeId::Element(ElementTypeId::HTMLElement( - HTMLElementTypeId::HTMLObjectElement, + HTMLElementTypeId::HTMLObjectElement ))) => s.has_object_data(), Some(NodeTypeId::Element(_)) => false, } From 6b503e14cf414eaebebb60501e21423cd097cb2e Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 8 Mar 2025 19:02:41 -0500 Subject: [PATCH 2/2] update tests --- src/types.rs | 3 --- tests/source/long_type_path.rs | 10 ++++++++++ tests/target/long_type_path.rs | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/types.rs b/src/types.rs index 5a0a968f1e8..0054f76ca4f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -303,11 +303,8 @@ fn rewrite_segment( Ok(s) => s, Err(_) => { let mut shape = shape; - // dbg!(&shape); shape.indent = shape.indent.block_indent(context.config).block_only(); - // dbg!(&result, shape); result.insert_str(0, &shape.indent.to_string_with_newline(context.config)); - // dbg!(&result); shape } } diff --git a/tests/source/long_type_path.rs b/tests/source/long_type_path.rs index ce4366e77dd..589e2e8624f 100644 --- a/tests/source/long_type_path.rs +++ b/tests/source/long_type_path.rs @@ -13,3 +13,13 @@ fn test() { ::Long = Default::default(); } + +fn test2() { + let offenders = current_validators + .into_iter() + .enumerate() + .filter_map(|(_, id)| + <::ValidatorSet as ValidatorSetWithIdentification< + sp_runtime::AccountId32>>::IdentificationOf::convert(id.clone()).map(|full_id| (id, full_id))) + .collect::>>(); +} \ No newline at end of file diff --git a/tests/target/long_type_path.rs b/tests/target/long_type_path.rs index 4717869f395..f49bc98527d 100644 --- a/tests/target/long_type_path.rs +++ b/tests/target/long_type_path.rs @@ -3,3 +3,13 @@ fn test() { long_type_path::long_type_path::long_type_path::long_type_path::long_type_path::Long = Default::default(); } + +fn test2() { + let offenders = current_validators + .into_iter() + .enumerate() + .filter_map(|(_, id)| + <::ValidatorSet as ValidatorSetWithIdentification< + sp_runtime::AccountId32>>::IdentificationOf::convert(id.clone()).map(|full_id| (id, full_id))) + .collect::>>(); +}