Auto merge of #16389 - davidsemakula:order-use-tree-raw-ident, r=lnicola

internal: properly order raw idents when ordering use trees

Follow up to #16352 to properly order raw identifiers.
This commit is contained in:
bors 2024-01-17 20:23:21 +00:00
commit 9d9b34354d
2 changed files with 82 additions and 11 deletions

View File

@ -137,6 +137,16 @@ fn insert_start_indent() {
use std::bar::B;
use std::bar::C;",
);
check_none(
"std::bar::r#AA",
r"
use std::bar::B;
use std::bar::C;",
r"
use std::bar::r#AA;
use std::bar::B;
use std::bar::C;",
);
}
#[test]
@ -173,7 +183,21 @@ fn insert_middle_indent() {
use std::bar::EE;
use std::bar::F;
use std::bar::G;",
)
);
check_none(
"std::bar::r#EE",
r"
use std::bar::A;
use std::bar::D;
use std::bar::F;
use std::bar::G;",
r"
use std::bar::A;
use std::bar::D;
use std::bar::r#EE;
use std::bar::F;
use std::bar::G;",
);
}
#[test]
@ -210,7 +234,21 @@ fn insert_end_indent() {
use std::bar::F;
use std::bar::G;
use std::bar::ZZ;",
)
);
check_none(
"std::bar::r#ZZ",
r"
use std::bar::A;
use std::bar::D;
use std::bar::F;
use std::bar::G;",
r"
use std::bar::A;
use std::bar::D;
use std::bar::F;
use std::bar::G;
use std::bar::r#ZZ;",
);
}
#[test]
@ -228,7 +266,21 @@ use std::bar::EE;
use std::bar::{D, Z}; // example of weird imports due to user
use std::bar::F;
use std::bar::G;",
)
);
check_none(
"std::bar::r#EE",
r"
use std::bar::A;
use std::bar::{D, Z}; // example of weird imports due to user
use std::bar::F;
use std::bar::G;",
r"
use std::bar::A;
use std::bar::r#EE;
use std::bar::{D, Z}; // example of weird imports due to user
use std::bar::F;
use std::bar::G;",
);
}
#[test]
@ -596,7 +648,16 @@ fn merge_groups_full() {
#[test]
fn merge_groups_long_full() {
check_crate("std::foo::bar::Baz", r"use std::foo::bar::Qux;", r"use std::foo::bar::{Baz, Qux};")
check_crate(
"std::foo::bar::Baz",
r"use std::foo::bar::Qux;",
r"use std::foo::bar::{Baz, Qux};",
);
check_crate(
"std::foo::bar::r#Baz",
r"use std::foo::bar::Qux;",
r"use std::foo::bar::{r#Baz, Qux};",
);
}
#[test]
@ -614,7 +675,12 @@ fn merge_groups_long_full_list() {
"std::foo::bar::Baz",
r"use std::foo::bar::{Qux, Quux};",
r"use std::foo::bar::{Baz, Quux, Qux};",
)
);
check_crate(
"std::foo::bar::r#Baz",
r"use std::foo::bar::{Qux, Quux};",
r"use std::foo::bar::{r#Baz, Quux, Qux};",
);
}
#[test]
@ -632,7 +698,12 @@ fn merge_groups_long_full_nested() {
"std::foo::bar::Baz",
r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
r"use std::foo::bar::{quux::{Fez, Fizz}, Baz, Qux};",
)
);
check_crate(
"std::foo::bar::r#Baz",
r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
r"use std::foo::bar::{quux::{Fez, Fizz}, r#Baz, Qux};",
);
}
#[test]

View File

@ -9,7 +9,7 @@ use syntax::{
algo,
ast::{self, make, AstNode, HasAttrs, HasName, HasVisibility, PathSegmentKind},
ted::{self, Position},
Direction, TokenText,
Direction,
};
use crate::syntax_helpers::node_ext::vis_eq;
@ -339,8 +339,8 @@ fn path_segment_cmp(a: &ast::PathSegment, b: &ast::PathSegment) -> Ordering {
(None, Some(_)) => Ordering::Less,
(Some(a_name), Some(b_name)) => {
// snake_case < CamelCase < UPPER_SNAKE_CASE
let a_text = a_name.as_str();
let b_text = b_name.as_str();
let a_text = a_name.as_str().trim_start_matches("r#");
let b_text = b_name.as_str().trim_start_matches("r#");
if a_text.starts_with(char::is_lowercase)
&& b_text.starts_with(char::is_uppercase)
{
@ -388,14 +388,14 @@ fn use_tree_cmp_by_tree_list_glob_or_alias(
.as_ref()
.map(ast::Name::text)
.as_ref()
.map_or("_", TokenText::as_str)
.map_or("_", |a_name| a_name.as_str().trim_start_matches("r#"))
.cmp(
b_rename
.name()
.as_ref()
.map(ast::Name::text)
.as_ref()
.map_or("_", TokenText::as_str),
.map_or("_", |b_name| b_name.as_str().trim_start_matches("r#")),
),
},
};