Skip to content

Commit 4556e85

Browse files
committed
reorder: use versionsort for item names
1 parent e0f1b01 commit 4556e85

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

rustfmt-core/rustfmt-lib/src/items.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::expr::{
2323
use crate::lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
2424
use crate::macros::{rewrite_macro, MacroPosition};
2525
use crate::overflow;
26+
use crate::reorder::compare_as_versions;
2627
use crate::rewrite::{Rewrite, RewriteContext};
2728
use crate::shape::{Indent, Shape};
2829
use crate::source_map::{LineRangeUtils, SpanUtils};
@@ -701,10 +702,10 @@ impl<'a> FmtVisitor<'a> {
701702
(TyAlias(_, _, _, ref lty), TyAlias(_, _, _, ref rty))
702703
if both_type(lty, rty) || both_opaque(lty, rty) =>
703704
{
704-
a.ident.as_str().cmp(&b.ident.as_str())
705+
compare_as_versions(&a.ident.as_str(), &b.ident.as_str())
705706
}
706707
(Const(..), Const(..)) | (MacCall(..), MacCall(..)) => {
707-
a.ident.as_str().cmp(&b.ident.as_str())
708+
compare_as_versions(&a.ident.as_str(), &b.ident.as_str())
708709
}
709710
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
710711
(TyAlias(_, _, _, ref ty), _) if is_type(ty) => Ordering::Less,

rustfmt-core/rustfmt-lib/tests/source/issue-2863.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ impl<T> IntoIterator for SafeVec<T> {
2222
type E = impl Trait;
2323
const AnotherConst: i32 = 100;
2424
fn foo8() {println!("hello, world");}
25+
const AnyConst10: i32 = 100;
26+
const AnyConst2: i32 = 100;
2527
}

rustfmt-core/rustfmt-lib/tests/target/issue-2863.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ impl<T> IntoIterator for SafeVec<T> {
1313
type F = impl Trait;
1414

1515
const AnotherConst: i32 = 100;
16+
const AnyConst2: i32 = 100;
17+
const AnyConst10: i32 = 100;
1618
const SomeConst: i32 = 100;
1719

1820
// comment on foo()

0 commit comments

Comments
 (0)