Skip to content

Commit 7b9a4e6

Browse files
committed
Use a correct span for fn with pub(crate) syntax
1 parent 560b054 commit 7b9a4e6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/items.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,12 +1771,18 @@ fn rewrite_fn_base(
17711771
result.push(' ')
17721772
}
17731773

1774+
// Skip `pub(crate)`.
1775+
let lo_after_visibility = if let ast::Visibility::Crate(s) = fn_sig.visibility {
1776+
context.codemap.span_after(mk_sp(s.hi(), span.hi()), ")")
1777+
} else {
1778+
span.lo()
1779+
};
17741780
// A conservative estimation, to goal is to be over all parens in generics
17751781
let args_start = fn_sig
17761782
.generics
17771783
.ty_params
17781784
.last()
1779-
.map_or(span.lo(), |tp| end_typaram(tp));
1785+
.map_or(lo_after_visibility, |tp| end_typaram(tp));
17801786
let args_end = if fd.inputs.is_empty() {
17811787
context
17821788
.codemap

tests/source/fn-simple.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ mod foo {
5959
foo();
6060
}
6161
}
62+
63+
// #2082
64+
pub(crate) fn init() {}

tests/target/fn-simple.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,6 @@ mod foo {
101101
foo();
102102
}
103103
}
104+
105+
// #2082
106+
pub(crate) fn init() {}

0 commit comments

Comments
 (0)