Auto merge of #15652 - Veykril:format_to, r=lnicola

minor: Various small fixes
This commit is contained in:
bors 2023-09-22 09:06:06 +00:00
commit 4a8622c8fa
6 changed files with 22 additions and 20 deletions

View File

@ -1,7 +1,6 @@
//! Name resolution for expressions. //! Name resolution for expressions.
use hir_expand::name::Name; use hir_expand::name::Name;
use la_arena::{Arena, Idx, IdxRange, RawIdx}; use la_arena::{Arena, ArenaMap, Idx, IdxRange, RawIdx};
use rustc_hash::FxHashMap;
use triomphe::Arc; use triomphe::Arc;
use crate::{ use crate::{
@ -17,7 +16,7 @@ pub type ScopeId = Idx<ScopeData>;
pub struct ExprScopes { pub struct ExprScopes {
scopes: Arena<ScopeData>, scopes: Arena<ScopeData>,
scope_entries: Arena<ScopeEntry>, scope_entries: Arena<ScopeEntry>,
scope_by_expr: FxHashMap<ExprId, ScopeId>, scope_by_expr: ArenaMap<ExprId, ScopeId>,
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
@ -77,10 +76,10 @@ impl ExprScopes {
} }
pub fn scope_for(&self, expr: ExprId) -> Option<ScopeId> { pub fn scope_for(&self, expr: ExprId) -> Option<ScopeId> {
self.scope_by_expr.get(&expr).copied() self.scope_by_expr.get(expr).copied()
} }
pub fn scope_by_expr(&self) -> &FxHashMap<ExprId, ScopeId> { pub fn scope_by_expr(&self) -> &ArenaMap<ExprId, ScopeId> {
&self.scope_by_expr &self.scope_by_expr
} }
} }
@ -94,7 +93,7 @@ impl ExprScopes {
let mut scopes = ExprScopes { let mut scopes = ExprScopes {
scopes: Arena::default(), scopes: Arena::default(),
scope_entries: Arena::default(), scope_entries: Arena::default(),
scope_by_expr: FxHashMap::default(), scope_by_expr: ArenaMap::with_capacity(body.exprs.len()),
}; };
let mut root = scopes.root_scope(); let mut root = scopes.root_scope();
scopes.add_params_bindings(body, root, &body.params); scopes.add_params_bindings(body, root, &body.params);

View File

@ -1,7 +1,6 @@
//! A map of all publicly exported items in a crate. //! A map of all publicly exported items in a crate.
use std::collections::hash_map::Entry; use std::{collections::hash_map::Entry, fmt, hash::BuildHasherDefault};
use std::{fmt, hash::BuildHasherDefault};
use base_db::CrateId; use base_db::CrateId;
use fst::{self, Streamer}; use fst::{self, Streamer};
@ -11,10 +10,12 @@ use itertools::Itertools;
use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
use triomphe::Arc; use triomphe::Arc;
use crate::item_scope::ImportOrExternCrate;
use crate::{ use crate::{
db::DefDatabase, item_scope::ItemInNs, nameres::DefMap, visibility::Visibility, AssocItemId, db::DefDatabase,
ModuleDefId, ModuleId, TraitId, item_scope::{ImportOrExternCrate, ItemInNs},
nameres::DefMap,
visibility::Visibility,
AssocItemId, ModuleDefId, ModuleId, TraitId,
}; };
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>; type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
@ -94,7 +95,7 @@ fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> FxIndexMap<ItemIn
// We look only into modules that are public(ly reexported), starting with the crate root. // We look only into modules that are public(ly reexported), starting with the crate root.
let root = def_map.module_id(DefMap::ROOT); let root = def_map.module_id(DefMap::ROOT);
let mut worklist = vec![(root, 0)]; let mut worklist = vec![(root, 0u32)];
// Records items' minimum module depth. // Records items' minimum module depth.
let mut depth_map = FxHashMap::default(); let mut depth_map = FxHashMap::default();

View File

@ -499,10 +499,7 @@ impl_from!(Macro2Id, MacroRulesId, ProcMacroId for MacroId);
impl MacroId { impl MacroId {
pub fn is_attribute(self, db: &dyn db::DefDatabase) -> bool { pub fn is_attribute(self, db: &dyn db::DefDatabase) -> bool {
match self { matches!(self, MacroId::ProcMacroId(it) if it.lookup(db).kind == ProcMacroKind::Attr)
MacroId::ProcMacroId(it) => it.lookup(db).kind == ProcMacroKind::Attr,
_ => false,
}
} }
} }

View File

@ -888,7 +888,7 @@ fn scope_for_offset(
.scope_by_expr() .scope_by_expr()
.iter() .iter()
.filter_map(|(id, scope)| { .filter_map(|(id, scope)| {
let InFile { file_id, value } = source_map.expr_syntax(*id).ok()?; let InFile { file_id, value } = source_map.expr_syntax(id).ok()?;
if from_file == file_id { if from_file == file_id {
return Some((value.text_range(), scope)); return Some((value.text_range(), scope));
} }
@ -923,7 +923,7 @@ fn adjust(
.scope_by_expr() .scope_by_expr()
.iter() .iter()
.filter_map(|(id, scope)| { .filter_map(|(id, scope)| {
let source = source_map.expr_syntax(*id).ok()?; let source = source_map.expr_syntax(id).ok()?;
// FIXME: correctly handle macro expansion // FIXME: correctly handle macro expansion
if source.file_id != from_file { if source.file_id != from_file {
return None; return None;

View File

@ -15,7 +15,12 @@ macro_rules! eprintln {
macro_rules! format_to { macro_rules! format_to {
($buf:expr) => (); ($buf:expr) => ();
($buf:expr, $lit:literal $($arg:tt)*) => { ($buf:expr, $lit:literal $($arg:tt)*) => {
{ use ::std::fmt::Write as _; let _ = ::std::write!($buf, $lit $($arg)*); } {
use ::std::fmt::Write as _;
// We can't do ::std::fmt::Write::write_fmt($buf, format_args!($lit $($arg)*))
// unfortunately, as that loses out on autoref behavior.
_ = $buf.write_fmt(format_args!($lit $($arg)*))
}
}; };
} }

View File

@ -23,7 +23,7 @@ pub fn streaming_output(
let idx = if eof { let idx = if eof {
data.len() data.len()
} else { } else {
match data.iter().rposition(|b| *b == b'\n') { match data.iter().rposition(|&b| b == b'\n') {
Some(i) => i + 1, Some(i) => i + 1,
None => return, None => return,
} }