mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Auto merge of #15652 - Veykril:format_to, r=lnicola
minor: Various small fixes
This commit is contained in:
commit
4a8622c8fa
@ -1,7 +1,6 @@
|
||||
//! Name resolution for expressions.
|
||||
use hir_expand::name::Name;
|
||||
use la_arena::{Arena, Idx, IdxRange, RawIdx};
|
||||
use rustc_hash::FxHashMap;
|
||||
use la_arena::{Arena, ArenaMap, Idx, IdxRange, RawIdx};
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::{
|
||||
@ -17,7 +16,7 @@ pub type ScopeId = Idx<ScopeData>;
|
||||
pub struct ExprScopes {
|
||||
scopes: Arena<ScopeData>,
|
||||
scope_entries: Arena<ScopeEntry>,
|
||||
scope_by_expr: FxHashMap<ExprId, ScopeId>,
|
||||
scope_by_expr: ArenaMap<ExprId, ScopeId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
@ -77,10 +76,10 @@ impl ExprScopes {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -94,7 +93,7 @@ impl ExprScopes {
|
||||
let mut scopes = ExprScopes {
|
||||
scopes: 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();
|
||||
scopes.add_params_bindings(body, root, &body.params);
|
||||
|
@ -1,7 +1,6 @@
|
||||
//! A map of all publicly exported items in a crate.
|
||||
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::{fmt, hash::BuildHasherDefault};
|
||||
use std::{collections::hash_map::Entry, fmt, hash::BuildHasherDefault};
|
||||
|
||||
use base_db::CrateId;
|
||||
use fst::{self, Streamer};
|
||||
@ -11,10 +10,12 @@ use itertools::Itertools;
|
||||
use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::item_scope::ImportOrExternCrate;
|
||||
use crate::{
|
||||
db::DefDatabase, item_scope::ItemInNs, nameres::DefMap, visibility::Visibility, AssocItemId,
|
||||
ModuleDefId, ModuleId, TraitId,
|
||||
db::DefDatabase,
|
||||
item_scope::{ImportOrExternCrate, ItemInNs},
|
||||
nameres::DefMap,
|
||||
visibility::Visibility,
|
||||
AssocItemId, ModuleDefId, ModuleId, TraitId,
|
||||
};
|
||||
|
||||
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.
|
||||
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.
|
||||
let mut depth_map = FxHashMap::default();
|
||||
|
||||
|
@ -499,10 +499,7 @@ impl_from!(Macro2Id, MacroRulesId, ProcMacroId for MacroId);
|
||||
|
||||
impl MacroId {
|
||||
pub fn is_attribute(self, db: &dyn db::DefDatabase) -> bool {
|
||||
match self {
|
||||
MacroId::ProcMacroId(it) => it.lookup(db).kind == ProcMacroKind::Attr,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, MacroId::ProcMacroId(it) if it.lookup(db).kind == ProcMacroKind::Attr)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -888,7 +888,7 @@ fn scope_for_offset(
|
||||
.scope_by_expr()
|
||||
.iter()
|
||||
.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 {
|
||||
return Some((value.text_range(), scope));
|
||||
}
|
||||
@ -923,7 +923,7 @@ fn adjust(
|
||||
.scope_by_expr()
|
||||
.iter()
|
||||
.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
|
||||
if source.file_id != from_file {
|
||||
return None;
|
||||
|
@ -15,7 +15,12 @@ macro_rules! eprintln {
|
||||
macro_rules! format_to {
|
||||
($buf:expr) => ();
|
||||
($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)*))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ pub fn streaming_output(
|
||||
let idx = if eof {
|
||||
data.len()
|
||||
} else {
|
||||
match data.iter().rposition(|b| *b == b'\n') {
|
||||
match data.iter().rposition(|&b| b == b'\n') {
|
||||
Some(i) => i + 1,
|
||||
None => return,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user