diff --git a/src/types.rs b/src/types.rs index 6180a4dac13..0054f76ca4f 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,34 @@ 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; + shape.indent = shape.indent.block_indent(context.config).block_only(); + result.insert_str(0, &shape.indent.to_string_with_newline(context.config)); + 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..589e2e8624f --- /dev/null +++ b/tests/source/long_type_path.rs @@ -0,0 +1,25 @@ +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(); +} + +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/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..f49bc98527d --- /dev/null +++ b/tests/target/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(); +} + +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::>>(); +} 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, }