Skip to content

Commit 4a8622c

Browse files
committed
Auto merge of #15652 - Veykril:format_to, r=lnicola
minor: Various small fixes
2 parents 609bdbc + 556f0c6 commit 4a8622c

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

crates/hir-def/src/body/scope.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Name resolution for expressions.
22
use hir_expand::name::Name;
3-
use la_arena::{Arena, Idx, IdxRange, RawIdx};
4-
use rustc_hash::FxHashMap;
3+
use la_arena::{Arena, ArenaMap, Idx, IdxRange, RawIdx};
54
use triomphe::Arc;
65

76
use crate::{
@@ -17,7 +16,7 @@ pub type ScopeId = Idx<ScopeData>;
1716
pub struct ExprScopes {
1817
scopes: Arena<ScopeData>,
1918
scope_entries: Arena<ScopeEntry>,
20-
scope_by_expr: FxHashMap<ExprId, ScopeId>,
19+
scope_by_expr: ArenaMap<ExprId, ScopeId>,
2120
}
2221

2322
#[derive(Debug, PartialEq, Eq)]
@@ -77,10 +76,10 @@ impl ExprScopes {
7776
}
7877

7978
pub fn scope_for(&self, expr: ExprId) -> Option<ScopeId> {
80-
self.scope_by_expr.get(&expr).copied()
79+
self.scope_by_expr.get(expr).copied()
8180
}
8281

83-
pub fn scope_by_expr(&self) -> &FxHashMap<ExprId, ScopeId> {
82+
pub fn scope_by_expr(&self) -> &ArenaMap<ExprId, ScopeId> {
8483
&self.scope_by_expr
8584
}
8685
}
@@ -94,7 +93,7 @@ impl ExprScopes {
9493
let mut scopes = ExprScopes {
9594
scopes: Arena::default(),
9695
scope_entries: Arena::default(),
97-
scope_by_expr: FxHashMap::default(),
96+
scope_by_expr: ArenaMap::with_capacity(body.exprs.len()),
9897
};
9998
let mut root = scopes.root_scope();
10099
scopes.add_params_bindings(body, root, &body.params);

crates/hir-def/src/import_map.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! A map of all publicly exported items in a crate.
22
3-
use std::collections::hash_map::Entry;
4-
use std::{fmt, hash::BuildHasherDefault};
3+
use std::{collections::hash_map::Entry, fmt, hash::BuildHasherDefault};
54

65
use base_db::CrateId;
76
use fst::{self, Streamer};
@@ -11,10 +10,12 @@ use itertools::Itertools;
1110
use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
1211
use triomphe::Arc;
1312

14-
use crate::item_scope::ImportOrExternCrate;
1513
use crate::{
16-
db::DefDatabase, item_scope::ItemInNs, nameres::DefMap, visibility::Visibility, AssocItemId,
17-
ModuleDefId, ModuleId, TraitId,
14+
db::DefDatabase,
15+
item_scope::{ImportOrExternCrate, ItemInNs},
16+
nameres::DefMap,
17+
visibility::Visibility,
18+
AssocItemId, ModuleDefId, ModuleId, TraitId,
1819
};
1920

2021
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
@@ -94,7 +95,7 @@ fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> FxIndexMap<ItemIn
9495

9596
// We look only into modules that are public(ly reexported), starting with the crate root.
9697
let root = def_map.module_id(DefMap::ROOT);
97-
let mut worklist = vec![(root, 0)];
98+
let mut worklist = vec![(root, 0u32)];
9899
// Records items' minimum module depth.
99100
let mut depth_map = FxHashMap::default();
100101

crates/hir-def/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,7 @@ impl_from!(Macro2Id, MacroRulesId, ProcMacroId for MacroId);
499499

500500
impl MacroId {
501501
pub fn is_attribute(self, db: &dyn db::DefDatabase) -> bool {
502-
match self {
503-
MacroId::ProcMacroId(it) => it.lookup(db).kind == ProcMacroKind::Attr,
504-
_ => false,
505-
}
502+
matches!(self, MacroId::ProcMacroId(it) if it.lookup(db).kind == ProcMacroKind::Attr)
506503
}
507504
}
508505

crates/hir/src/source_analyzer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ fn scope_for_offset(
888888
.scope_by_expr()
889889
.iter()
890890
.filter_map(|(id, scope)| {
891-
let InFile { file_id, value } = source_map.expr_syntax(*id).ok()?;
891+
let InFile { file_id, value } = source_map.expr_syntax(id).ok()?;
892892
if from_file == file_id {
893893
return Some((value.text_range(), scope));
894894
}
@@ -923,7 +923,7 @@ fn adjust(
923923
.scope_by_expr()
924924
.iter()
925925
.filter_map(|(id, scope)| {
926-
let source = source_map.expr_syntax(*id).ok()?;
926+
let source = source_map.expr_syntax(id).ok()?;
927927
// FIXME: correctly handle macro expansion
928928
if source.file_id != from_file {
929929
return None;

crates/stdx/src/macros.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ macro_rules! eprintln {
1515
macro_rules! format_to {
1616
($buf:expr) => ();
1717
($buf:expr, $lit:literal $($arg:tt)*) => {
18-
{ use ::std::fmt::Write as _; let _ = ::std::write!($buf, $lit $($arg)*); }
18+
{
19+
use ::std::fmt::Write as _;
20+
// We can't do ::std::fmt::Write::write_fmt($buf, format_args!($lit $($arg)*))
21+
// unfortunately, as that loses out on autoref behavior.
22+
_ = $buf.write_fmt(format_args!($lit $($arg)*))
23+
}
1924
};
2025
}
2126

crates/stdx/src/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn streaming_output(
2323
let idx = if eof {
2424
data.len()
2525
} else {
26-
match data.iter().rposition(|b| *b == b'\n') {
26+
match data.iter().rposition(|&b| b == b'\n') {
2727
Some(i) => i + 1,
2828
None => return,
2929
}

0 commit comments

Comments
 (0)