1
Fork 0

Remove unnecessary sigils around Ident::as_str() calls.

This commit is contained in:
Nicholas Nethercote 2021-12-15 16:13:11 +11:00
parent 056d48a2c9
commit b1c934ebb8
31 changed files with 41 additions and 42 deletions

View file

@ -580,8 +580,7 @@ impl<'a> AstValidator<'a> {
/// An item in `extern { ... }` cannot use non-ascii identifier. /// An item in `extern { ... }` cannot use non-ascii identifier.
fn check_foreign_item_ascii_only(&self, ident: Ident) { fn check_foreign_item_ascii_only(&self, ident: Ident) {
let symbol_str = ident.as_str(); if !ident.as_str().is_ascii() {
if !symbol_str.is_ascii() {
let n = 83942; let n = 83942;
self.err_handler() self.err_handler()
.struct_span_err( .struct_span_err(

View file

@ -1922,7 +1922,7 @@ enum VariantInfo<'a, 'tcx> {
impl<'tcx> VariantInfo<'_, 'tcx> { impl<'tcx> VariantInfo<'_, 'tcx> {
fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R { fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
match self { match self {
VariantInfo::Adt(variant) => f(&variant.ident.as_str()), VariantInfo::Adt(variant) => f(variant.ident.as_str()),
VariantInfo::Generator { variant_index, .. } => { VariantInfo::Generator { variant_index, .. } => {
f(&GeneratorSubsts::variant_name(*variant_index)) f(&GeneratorSubsts::variant_name(*variant_index))
} }

View file

@ -103,10 +103,10 @@ crate fn mod_dir_path(
if let DirOwnership::Owned { relative } = &mut dir_ownership { if let DirOwnership::Owned { relative } = &mut dir_ownership {
if let Some(ident) = relative.take() { if let Some(ident) = relative.take() {
// Remove the relative offset. // Remove the relative offset.
dir_path.push(&*ident.as_str()); dir_path.push(ident.as_str());
} }
} }
dir_path.push(&*ident.as_str()); dir_path.push(ident.as_str());
(dir_path, dir_ownership) (dir_path, dir_ownership)
} }

View file

@ -2444,7 +2444,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
CtorKind::Fictive => { CtorKind::Fictive => {
let mut struct_fmt = fmt.debug_struct(&name); let mut struct_fmt = fmt.debug_struct(&name);
for (field, place) in iter::zip(&variant_def.fields, places) { for (field, place) in iter::zip(&variant_def.fields, places) {
struct_fmt.field(&field.ident.as_str(), place); struct_fmt.field(field.ident.as_str(), place);
} }
struct_fmt.finish() struct_fmt.finish()
} }

View file

@ -1185,7 +1185,7 @@ impl<'a> Resolver<'a> {
("", " from prelude") ("", " from prelude")
} else if b.is_extern_crate() } else if b.is_extern_crate()
&& !b.is_import() && !b.is_import()
&& self.session.opts.externs.get(&ident.as_str()).is_some() && self.session.opts.externs.get(ident.as_str()).is_some()
{ {
("", " passed with `--extern`") ("", " passed with `--extern`")
} else if add_built_in { } else if add_built_in {

View file

@ -231,7 +231,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
let is_assoc_fn = self.self_type_is_available(span); let is_assoc_fn = self.self_type_is_available(span);
// Emit help message for fake-self from other languages (e.g., `this` in Javascript). // Emit help message for fake-self from other languages (e.g., `this` in Javascript).
if ["this", "my"].contains(&&*item_str.as_str()) && is_assoc_fn { if ["this", "my"].contains(&item_str.as_str()) && is_assoc_fn {
err.span_suggestion_short( err.span_suggestion_short(
span, span,
"you might have meant to use `self` here instead", "you might have meant to use `self` here instead",
@ -1372,7 +1372,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
fn likely_rust_type(path: &[Segment]) -> Option<Symbol> { fn likely_rust_type(path: &[Segment]) -> Option<Symbol> {
let name = path[path.len() - 1].ident.as_str(); let name = path[path.len() - 1].ident.as_str();
// Common Java types // Common Java types
Some(match &*name { Some(match name {
"byte" => sym::u8, // In Java, bytes are signed, but in practice one almost always wants unsigned bytes. "byte" => sym::u8, // In Java, bytes are signed, but in practice one almost always wants unsigned bytes.
"short" => sym::i16, "short" => sym::i16,
"boolean" => sym::bool, "boolean" => sym::bool,

View file

@ -105,7 +105,7 @@ fn fast_print_path(path: &ast::Path) -> Symbol {
path_str.push_str("::"); path_str.push_str("::");
} }
if segment.ident.name != kw::PathRoot { if segment.ident.name != kw::PathRoot {
path_str.push_str(&segment.ident.as_str()) path_str.push_str(segment.ident.as_str())
} }
} }
Symbol::intern(&path_str) Symbol::intern(&path_str)

View file

@ -616,7 +616,7 @@ impl<'hir> Sig for hir::Generics<'hir> {
if let hir::GenericParamKind::Const { .. } = param.kind { if let hir::GenericParamKind::Const { .. } = param.kind {
param_text.push_str("const "); param_text.push_str("const ");
} }
param_text.push_str(&param.name.ident().as_str()); param_text.push_str(param.name.ident().as_str());
defs.push(SigElement { defs.push(SigElement {
id: id_from_hir_id(param.hir_id, scx), id: id_from_hir_id(param.hir_id, scx),
start: offset + text.len(), start: offset + text.len(),

View file

@ -560,7 +560,7 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> {
ty::ExistentialPredicate::Projection(projection) => { ty::ExistentialPredicate::Projection(projection) => {
let name = cx.tcx.associated_item(projection.item_def_id).ident; let name = cx.tcx.associated_item(projection.item_def_id).ident;
cx.push("p"); cx.push("p");
cx.push_ident(&name.as_str()); cx.push_ident(name.as_str());
cx = projection.ty.print(cx)?; cx = projection.ty.print(cx)?;
} }
ty::ExistentialPredicate::AutoTrait(def_id) => { ty::ExistentialPredicate::AutoTrait(def_id) => {

View file

@ -1908,7 +1908,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
.associated_items(def_id) .associated_items(def_id)
.in_definition_order() .in_definition_order()
.filter(|x| { .filter(|x| {
let dist = lev_distance(&*name.as_str(), &x.ident.as_str()); let dist = lev_distance(name.as_str(), x.ident.as_str());
x.kind.namespace() == Namespace::ValueNS && dist > 0 && dist <= max_dist x.kind.namespace() == Namespace::ValueNS && dist > 0 && dist <= max_dist
}) })
.copied() .copied()

View file

@ -167,7 +167,7 @@ crate fn qpath_to_string(p: &hir::QPath<'_>) -> String {
s.push_str("::"); s.push_str("::");
} }
if seg.ident.name != kw::PathRoot { if seg.ident.name != kw::PathRoot {
s.push_str(&seg.ident.as_str()); s.push_str(seg.ident.as_str());
} }
} }
s s

View file

@ -21,7 +21,7 @@ declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
impl<'tcx> LateLintPass<'tcx> for Pass { impl<'tcx> LateLintPass<'tcx> for Pass {
fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) { fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
match &*it.ident.as_str() { match it.ident.as_str() {
"lintme" => cx.lint(TEST_LINT, |lint| { "lintme" => cx.lint(TEST_LINT, |lint| {
lint.build("item is named 'lintme'").set_span(it.span).emit() lint.build("item is named 'lintme'").set_span(it.span).emit()
}), }),

View file

@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for DurationSubsec {
if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION); if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION);
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right); if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right);
then { then {
let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) { let suggested_fn = match (method_path.ident.as_str(), divisor) {
("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis", ("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis",
("subsec_nanos", 1_000) => "subsec_micros", ("subsec_nanos", 1_000) => "subsec_micros",
_ => return, _ => return,

View file

@ -599,7 +599,7 @@ fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>
return method_name_a.as_str() == method_name_b.as_str() && return method_name_a.as_str() == method_name_b.as_str() &&
args_a.len() == args_b.len() && args_a.len() == args_b.len() &&
( (
["ln", "log2", "log10"].contains(&&*method_name_a.as_str()) || ["ln", "log2", "log10"].contains(&method_name_a.as_str()) ||
method_name_a.as_str() == "log" && args_a.len() == 2 && eq_expr_value(cx, &args_a[1], &args_b[1]) method_name_a.as_str() == "log" && args_a.len() == 2 && eq_expr_value(cx, &args_a[1], &args_b[1])
); );
} }

View file

@ -659,7 +659,7 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used
if let ExprKind::MethodCall(method, _, [self_arg], _) = arg.kind { if let ExprKind::MethodCall(method, _, [self_arg], _) = arg.kind {
let method_name = &*method.ident.as_str(); let method_name = method.ident.as_str();
// check for looping over x.iter() or x.iter_mut(), could use &x or &mut x // check for looping over x.iter() or x.iter_mut(), could use &x or &mut x
match method_name { match method_name {
"iter" | "iter_mut" => explicit_iter_loop::check(cx, self_arg, arg, method_name), "iter" | "iter_mut" => explicit_iter_loop::check(cx, self_arg, arg, method_name),

View file

@ -95,7 +95,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchExprVisitor<'a, 'tcx> {
fn visit_expr(&mut self, ex: &'tcx Expr<'_>) { fn visit_expr(&mut self, ex: &'tcx Expr<'_>) {
match ex.kind { match ex.kind {
ExprKind::MethodCall(segment, _, [receiver], _) ExprKind::MethodCall(segment, _, [receiver], _)
if self.case_altered(&*segment.ident.as_str(), receiver) => {}, if self.case_altered(segment.ident.as_str(), receiver) => {},
_ => walk_expr(self, ex), _ => walk_expr(self, ex),
} }
} }

View file

@ -1127,7 +1127,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
if let CommonPrefixSearcher::Path(path_prefix) = path_prefix { if let CommonPrefixSearcher::Path(path_prefix) = path_prefix {
let mut s = String::new(); let mut s = String::new();
for seg in path_prefix { for seg in path_prefix {
s.push_str(&seg.ident.as_str()); s.push_str(seg.ident.as_str());
s.push_str("::"); s.push_str("::");
} }
s s

View file

@ -81,7 +81,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option<M
if args.is_empty(); if args.is_empty();
if let hir::ExprKind::Path(hir::QPath::TypeRelative(_, segment)) = &func.kind; if let hir::ExprKind::Path(hir::QPath::TypeRelative(_, segment)) = &func.kind;
then { then {
match &*segment.ident.as_str() { match segment.ident.as_str() {
"max_value" => return Some(MinMax::Max), "max_value" => return Some(MinMax::Max),
"min_value" => return Some(MinMax::Min), "min_value" => return Some(MinMax::Min),
_ => {} _ => {}

View file

@ -1999,8 +1999,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
from_iter_instead_of_collect::check(cx, expr, args, func); from_iter_instead_of_collect::check(cx, expr, args, func);
}, },
hir::ExprKind::MethodCall(method_call, ref method_span, args, _) => { hir::ExprKind::MethodCall(method_call, ref method_span, args, _) => {
or_fun_call::check(cx, expr, *method_span, &method_call.ident.as_str(), args); or_fun_call::check(cx, expr, *method_span, method_call.ident.as_str(), args);
expect_fun_call::check(cx, expr, *method_span, &method_call.ident.as_str(), args); expect_fun_call::check(cx, expr, *method_span, method_call.ident.as_str(), args);
clone_on_copy::check(cx, expr, method_call.ident.name, args); clone_on_copy::check(cx, expr, method_call.ident.name, args);
clone_on_ref_ptr::check(cx, expr, method_call.ident.name, args); clone_on_ref_ptr::check(cx, expr, method_call.ident.name, args);
inefficient_to_string::check(cx, expr, method_call.ident.name, args); inefficient_to_string::check(cx, expr, method_call.ident.name, args);

View file

@ -140,7 +140,7 @@ fn parse_iter_usage(
let did = cx.typeck_results().type_dependent_def_id(e.hir_id)?; let did = cx.typeck_results().type_dependent_def_id(e.hir_id)?;
let iter_id = cx.tcx.get_diagnostic_item(sym::Iterator)?; let iter_id = cx.tcx.get_diagnostic_item(sym::Iterator)?;
match (&*name.ident.as_str(), args) { match (name.ident.as_str(), args) {
("next", []) if cx.tcx.trait_of_item(did) == Some(iter_id) => { ("next", []) if cx.tcx.trait_of_item(did) == Some(iter_id) => {
if reverse { if reverse {
(IterUsageKind::Second, e.span) (IterUsageKind::Second, e.span)
@ -298,7 +298,7 @@ fn check_iter(
if let Some(did) = cx.typeck_results().type_dependent_def_id(e.hir_id); if let Some(did) = cx.typeck_results().type_dependent_def_id(e.hir_id);
if let Some(iter_id) = cx.tcx.get_diagnostic_item(sym::Iterator); if let Some(iter_id) = cx.tcx.get_diagnostic_item(sym::Iterator);
then { then {
match (&*name.ident.as_str(), args) { match (name.ident.as_str(), args) {
("next", []) if cx.tcx.trait_of_item(did) == Some(iter_id) => { ("next", []) if cx.tcx.trait_of_item(did) == Some(iter_id) => {
return true; return true;
}, },

View file

@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap(); let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap();
let substs = cx.typeck_results().node_substs(e.hir_id); let substs = cx.typeck_results().node_substs(e.hir_id);
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
check_arguments(cx, arguments, method_type, &path.ident.as_str(), "method"); check_arguments(cx, arguments, method_type, path.ident.as_str(), "method");
}, },
_ => (), _ => (),
} }

View file

@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref {
if is_type_diagnostic_item(cx,outer_ty,sym::Option); if is_type_diagnostic_item(cx,outer_ty,sym::Option);
if let ExprKind::MethodCall(path, _, [sub_expr], _) = expr.kind; if let ExprKind::MethodCall(path, _, [sub_expr], _) = expr.kind;
let symbol = path.ident.as_str(); let symbol = path.ident.as_str();
if symbol=="as_deref" || symbol=="as_deref_mut"; if symbol == "as_deref" || symbol == "as_deref_mut";
if TyS::same_type( outer_ty, typeck.expr_ty(sub_expr) ); if TyS::same_type( outer_ty, typeck.expr_ty(sub_expr) );
then{ then{
span_lint_and_sugg( span_lint_and_sugg(

View file

@ -82,7 +82,7 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec
_ => Argument::Unknown, _ => Argument::Unknown,
}; };
match &*path.ident.as_str() { match path.ident.as_str() {
"create" => { "create" => {
options.push((OpenOption::Create, argument_option)); options.push((OpenOption::Create, argument_option));
}, },

View file

@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for SerdeApi {
let mut seen_str = None; let mut seen_str = None;
let mut seen_string = None; let mut seen_string = None;
for item in items { for item in items {
match &*item.ident.as_str() { match item.ident.as_str() {
"visit_str" => seen_str = Some(item.span), "visit_str" => seen_str = Some(item.span),
"visit_string" => seen_string = Some(item.span), "visit_string" => seen_string = Some(item.span),
_ => {}, _ => {},

View file

@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
check_map_error(cx, res, expr); check_map_error(cx, res, expr);
} }
}, },
hir::ExprKind::MethodCall(path, _, [ref arg_0, ..], _) => match &*path.ident.as_str() { hir::ExprKind::MethodCall(path, _, [ref arg_0, ..], _) => match path.ident.as_str() {
"expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => { "expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => {
check_map_error(cx, arg_0, expr); check_map_error(cx, arg_0, expr);
}, },
@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) {
let mut call = call; let mut call = call;
while let hir::ExprKind::MethodCall(path, _, args, _) = call.kind { while let hir::ExprKind::MethodCall(path, _, args, _) = call.kind {
if matches!(&*path.ident.as_str(), "or" | "or_else" | "ok") { if matches!(path.ident.as_str(), "or" | "or_else" | "ok") {
call = &args[0]; call = &args[0];
} else { } else {
break; break;
@ -82,7 +82,7 @@ fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<
fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) { fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) {
if let hir::ExprKind::MethodCall(path, _, _, _) = call.kind { if let hir::ExprKind::MethodCall(path, _, _, _) = call.kind {
let symbol = &*path.ident.as_str(); let symbol = path.ident.as_str();
let read_trait = match_trait_method(cx, call, &paths::IO_READ); let read_trait = match_trait_method(cx, call, &paths::IO_READ);
let write_trait = match_trait_method(cx, call, &paths::IO_WRITE); let write_trait = match_trait_method(cx, call, &paths::IO_WRITE);

View file

@ -158,7 +158,7 @@ fn collect_unwrap_info<'tcx>(
if let Some(local_id) = path_to_local(&args[0]); if let Some(local_id) = path_to_local(&args[0]);
let ty = cx.typeck_results().expr_ty(&args[0]); let ty = cx.typeck_results().expr_ty(&args[0]);
let name = method_name.ident.as_str(); let name = method_name.ident.as_str();
if is_relevant_option_call(cx, ty, &name) || is_relevant_result_call(cx, ty, &name); if is_relevant_option_call(cx, ty, name) || is_relevant_result_call(cx, ty, name);
then { then {
assert!(args.len() == 1); assert!(args.len() == 1);
let unwrappable = match name.as_ref() { let unwrappable = match name.as_ref() {

View file

@ -79,7 +79,7 @@ fn correct_ident(ident: &str) -> String {
fn check_ident(cx: &LateContext<'_>, ident: &Ident, be_aggressive: bool) { fn check_ident(cx: &LateContext<'_>, ident: &Ident, be_aggressive: bool) {
let span = ident.span; let span = ident.span;
let ident = &ident.as_str(); let ident = ident.as_str();
let corrected = correct_ident(ident); let corrected = correct_ident(ident);
// warn if we have pure-uppercase idents // warn if we have pure-uppercase idents
// assume that two-letter words are some kind of valid abbreviation like FP for false positive // assume that two-letter words are some kind of valid abbreviation like FP for false positive

View file

@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
}, },
ExprKind::MethodCall(name, .., args, _) => { ExprKind::MethodCall(name, .., args, _) => {
if is_trait_method(cx, e, sym::Into) && &*name.ident.as_str() == "into" { if is_trait_method(cx, e, sym::Into) && name.ident.as_str() == "into" {
let a = cx.typeck_results().expr_ty(e); let a = cx.typeck_results().expr_ty(e);
let b = cx.typeck_results().expr_ty(&args[0]); let b = cx.typeck_results().expr_ty(&args[0]);
if same_type_and_consts(a, b) { if same_type_and_consts(a, b) {

View file

@ -616,10 +616,10 @@ impl<'a> FmtVisitor<'a> {
(TyAlias(lty), TyAlias(rty)) (TyAlias(lty), TyAlias(rty))
if both_type(&lty.ty, &rty.ty) || both_opaque(&lty.ty, &rty.ty) => if both_type(&lty.ty, &rty.ty) || both_opaque(&lty.ty, &rty.ty) =>
{ {
a.ident.as_str().cmp(&b.ident.as_str()) a.ident.as_str().cmp(b.ident.as_str())
} }
(Const(..), Const(..)) | (MacCall(..), MacCall(..)) => { (Const(..), Const(..)) | (MacCall(..), MacCall(..)) => {
a.ident.as_str().cmp(&b.ident.as_str()) a.ident.as_str().cmp(b.ident.as_str())
} }
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()), (Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
(TyAlias(ty), _) if is_type(&ty.ty) => Ordering::Less, (TyAlias(ty), _) if is_type(&ty.ty) => Ordering::Less,
@ -1029,7 +1029,7 @@ pub(crate) fn format_trait(
if !bounds.is_empty() { if !bounds.is_empty() {
let ident_hi = context let ident_hi = context
.snippet_provider .snippet_provider
.span_after(item.span, &item.ident.as_str()); .span_after(item.span, item.ident.as_str());
let bound_hi = bounds.last().unwrap().span().hi(); let bound_hi = bounds.last().unwrap().span().hi();
let snippet = context.snippet(mk_sp(ident_hi, bound_hi)); let snippet = context.snippet(mk_sp(ident_hi, bound_hi));
if contains_comment(snippet) { if contains_comment(snippet) {

View file

@ -467,10 +467,10 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
if let DirectoryOwnership::Owned { relative } = &mut self.directory.ownership { if let DirectoryOwnership::Owned { relative } = &mut self.directory.ownership {
if let Some(ident) = relative.take() { if let Some(ident) = relative.take() {
// remove the relative offset // remove the relative offset
self.directory.path.push(&*ident.as_str()); self.directory.path.push(ident.as_str());
} }
} }
self.directory.path.push(&*id.as_str()); self.directory.path.push(id.as_str());
} }
} }

View file

@ -26,7 +26,7 @@ use crate::visitor::FmtVisitor;
fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering { fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
match (&a.kind, &b.kind) { match (&a.kind, &b.kind) {
(&ast::ItemKind::Mod(..), &ast::ItemKind::Mod(..)) => { (&ast::ItemKind::Mod(..), &ast::ItemKind::Mod(..)) => {
a.ident.as_str().cmp(&b.ident.as_str()) a.ident.as_str().cmp(b.ident.as_str())
} }
(&ast::ItemKind::ExternCrate(ref a_name), &ast::ItemKind::ExternCrate(ref b_name)) => { (&ast::ItemKind::ExternCrate(ref a_name), &ast::ItemKind::ExternCrate(ref b_name)) => {
// `extern crate foo as bar;` // `extern crate foo as bar;`
@ -44,7 +44,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
(Some(..), None) => Ordering::Greater, (Some(..), None) => Ordering::Greater,
(None, Some(..)) => Ordering::Less, (None, Some(..)) => Ordering::Less,
(None, None) => Ordering::Equal, (None, None) => Ordering::Equal,
(Some(..), Some(..)) => a.ident.as_str().cmp(&b.ident.as_str()), (Some(..), Some(..)) => a.ident.as_str().cmp(b.ident.as_str()),
} }
} }
_ => unreachable!(), _ => unreachable!(),