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
46 changes: 37 additions & 9 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions tests/source/long_type_path.rs
Original file line number Diff line number Diff line change
@@ -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)|
<<Runtime as pallet_im_online::Config>::ValidatorSet as ValidatorSetWithIdentification<
sp_runtime::AccountId32>>::IdentificationOf::convert(id.clone()).map(|full_id| (id, full_id)))
.collect::<Vec<IdentificationTuple<Runtime>>>();
}
3 changes: 2 additions & 1 deletion tests/target/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
12 changes: 9 additions & 3 deletions tests/target/issue-3741.rs
Original file line number Diff line number Diff line change
@@ -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,
}
6 changes: 2 additions & 4 deletions tests/target/issue_4579.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ macro_rules! main {
#[spirv(fragment)]
pub fn main_fs(
mut out_color: ::spirv_std::storage_class::Output<Vec4>,
#[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]>,
) {
}
};
Expand Down
15 changes: 15 additions & 0 deletions tests/target/long_type_path.rs
Original file line number Diff line number Diff line change
@@ -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)|
<<Runtime as pallet_im_online::Config>::ValidatorSet as ValidatorSetWithIdentification<
sp_runtime::AccountId32>>::IdentificationOf::convert(id.clone()).map(|full_id| (id, full_id)))
.collect::<Vec<IdentificationTuple<Runtime>>>();
}
4 changes: 2 additions & 2 deletions tests/target/match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
Loading