Skip to content

Commit 31ed77a

Browse files
committed
fix
1 parent c6c8159 commit 31ed77a

9 files changed

+90
-34
lines changed

src/modules.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,17 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> {
391391
}
392392
match Parser::parse_file_as_module(self.psess, &file_path, sub_mod.span) {
393393
Ok((ref attrs, _, _)) if contains_skip(attrs) => Ok(None),
394-
Ok((attrs, items, span)) if outside_mods_empty => {
395-
Ok(Some(SubModKind::External(
396-
file_path,
397-
dir_ownership,
398-
Module::new(
399-
span,
400-
Some(Cow::Owned(ast::ModKind::Unloaded)),
401-
Cow::Owned(items),
402-
Cow::Owned(attrs),
403-
),
404-
)))
405-
}
394+
Ok((attrs, items, span)) if outside_mods_empty => Ok(Some(SubModKind::
395+
External(
396+
file_path,
397+
dir_ownership,
398+
Module::new(
399+
span,
400+
Some(Cow::Owned(ast::ModKind::Unloaded)),
401+
Cow::Owned(items),
402+
Cow::Owned(attrs),
403+
),
404+
))),
406405
Ok((attrs, items, span)) => {
407406
mods_outside_ast.push((
408407
file_path.clone(),

src/parse/session.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ impl ParseSess {
194194
pub(crate) fn is_file_parsed(&self, path: &Path) -> bool {
195195
self.raw_psess
196196
.source_map()
197-
.get_source_file(&rustc_span::FileName::Real(
198-
rustc_span::RealFileName::LocalPath(path.to_path_buf()),
199-
))
197+
.get_source_file(&rustc_span::FileName::Real(rustc_span::RealFileName::
198+
LocalPath(
199+
path.to_path_buf()
200+
)))
200201
.is_some()
201202
}
202203

src/types.rs

+40-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub(crate) enum PathContext {
3434
Import,
3535
}
3636

37-
// Does not wrap on simple segments.
3837
pub(crate) fn rewrite_path(
3938
context: &RewriteContext<'_>,
4039
path_context: PathContext,
@@ -115,24 +114,35 @@ where
115114
if segment.ident.name == kw::PathRoot {
116115
continue;
117116
}
118-
if first {
119-
first = false;
120-
} else {
117+
118+
if !first {
121119
buffer.push_str("::");
122120
}
123121

124-
let extra_offset = extra_offset(&buffer, shape);
125-
let new_shape = shape.shrink_left(extra_offset, mk_sp(span_lo, span_hi))?;
122+
let new_shape = match shape.shrink_left_opt(extra_offset(&buffer, shape)) {
123+
Some(s) => s,
124+
None => {
125+
buffer.push('\n');
126+
shape.shrink_left(extra_offset(&buffer, shape), mk_sp(span_lo, span_hi))?
127+
}
128+
};
129+
126130
let segment_string = rewrite_segment(
127131
path_context,
128132
segment,
129133
&mut span_lo,
130134
span_hi,
131135
context,
136+
shape,
132137
new_shape,
138+
first,
133139
)?;
134140

135141
buffer.push_str(&segment_string);
142+
143+
if first {
144+
first = false;
145+
}
136146
}
137147

138148
Ok(buffer)
@@ -270,16 +280,37 @@ fn rewrite_segment(
270280
span_hi: BytePos,
271281
context: &RewriteContext<'_>,
272282
shape: Shape,
283+
new_shape: Shape,
284+
first: bool,
273285
) -> RewriteResult {
274286
let mut result = String::with_capacity(128);
275287
result.push_str(rewrite_ident(context, segment.ident));
276288

277289
let ident_len = result.len();
290+
278291
let span = mk_sp(*span_lo, span_hi);
279-
let shape = if context.use_block_indent() {
280-
shape.offset_left(ident_len, span)?
292+
293+
let new_shape = if context.use_block_indent() {
294+
new_shape.offset_left(ident_len, span)
295+
} else {
296+
new_shape.shrink_left(ident_len, span)
297+
};
298+
299+
let shape = if first {
300+
new_shape?
281301
} else {
282-
shape.shrink_left(ident_len, span)?
302+
match new_shape {
303+
Ok(s) => s,
304+
Err(_) => {
305+
let mut shape = shape;
306+
// dbg!(&shape);
307+
shape.indent = shape.indent.block_indent(context.config).block_only();
308+
// dbg!(&result, shape);
309+
result.insert_str(0, &shape.indent.to_string_with_newline(context.config));
310+
// dbg!(&result);
311+
shape
312+
}
313+
}
283314
};
284315

285316
if let Some(ref args) = segment.args {

tests/source/long_type_path.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fn test() {
2+
let a: long_type_path::
3+
long_type_path::long_type_path::long_type_path
4+
5+
6+
7+
::long_type_path
8+
9+
10+
::long_type_path::long_type_path::long_type_path::long_type_path::long_type_path
11+
12+
13+
::Long =
14+
Default::default();
15+
}

tests/target/enum.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ enum Bar {}
269269
enum PublishedFileVisibility {
270270
Public =
271271
sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPublic,
272-
FriendsOnly = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly,
272+
FriendsOnly = sys::
273+
ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly,
273274
Private =
274275
sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate,
275276
}

tests/target/issue-3741.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
pub enum PublishedFileVisibility {
2-
Public = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPublic as i32,
3-
FriendsOnly = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly as i32,
4-
Private = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate as i32,
2+
Public = sys::
3+
ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPublic
4+
as i32,
5+
FriendsOnly = sys::
6+
ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly
7+
as i32,
8+
Private = sys::
9+
ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate
10+
as i32,
511
}

tests/target/issue_4579.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ macro_rules! main {
66
#[spirv(fragment)]
77
pub fn main_fs(
88
mut out_color: ::spirv_std::storage_class::Output<Vec4>,
9-
#[spirv(descriptor_set = 1)]
10-
iChannelResolution: ::spirv_std::storage_class::UniformConstant<
11-
[::spirv_std::glam::Vec3A; 4],
12-
>,
9+
#[spirv(descriptor_set = 1)] iChannelResolution: ::spirv_std::storage_class::
10+
UniformConstant<[::spirv_std::glam::Vec3A; 4]>,
1311
) {
1412
}
1513
};

tests/target/long_type_path.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn test() {
2+
let a: long_type_path::long_type_path::long_type_path::long_type_path::long_type_path::
3+
long_type_path::long_type_path::long_type_path::long_type_path::long_type_path::Long =
4+
Default::default();
5+
}

tests/target/match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ fn issue507() {
257257
fn issue508() {
258258
match s.type_id() {
259259
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
260-
HTMLElementTypeId::HTMLCanvasElement,
260+
HTMLElementTypeId::HTMLCanvasElement
261261
))) => true,
262262
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
263-
HTMLElementTypeId::HTMLObjectElement,
263+
HTMLElementTypeId::HTMLObjectElement
264264
))) => s.has_object_data(),
265265
Some(NodeTypeId::Element(_)) => false,
266266
}

0 commit comments

Comments
 (0)