mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-21 15:51:46 +00:00
refactor: Remove unnecessary Arc
This commit is contained in:
parent
7edfeb9674
commit
b5eedad8e3
11 changed files with 22 additions and 26 deletions
|
@ -89,7 +89,7 @@ impl ops::Index<CrateBuilderId> for CrateGraphBuilder {
|
||||||
pub struct CrateBuilder {
|
pub struct CrateBuilder {
|
||||||
pub basic: CrateDataBuilder,
|
pub basic: CrateDataBuilder,
|
||||||
pub extra: ExtraCrateData,
|
pub extra: ExtraCrateData,
|
||||||
pub cfg_options: Arc<CfgOptions>,
|
pub cfg_options: CfgOptions,
|
||||||
pub env: Env,
|
pub env: Env,
|
||||||
ws_data: Arc<CrateWorkspaceData>,
|
ws_data: Arc<CrateWorkspaceData>,
|
||||||
}
|
}
|
||||||
|
@ -403,9 +403,8 @@ pub struct Crate {
|
||||||
// This is in `Arc` because it is shared for all crates in a workspace.
|
// This is in `Arc` because it is shared for all crates in a workspace.
|
||||||
#[return_ref]
|
#[return_ref]
|
||||||
pub workspace_data: Arc<CrateWorkspaceData>,
|
pub workspace_data: Arc<CrateWorkspaceData>,
|
||||||
// FIXME: Remove this `Arc`.
|
|
||||||
#[return_ref]
|
#[return_ref]
|
||||||
pub cfg_options: Arc<CfgOptions>,
|
pub cfg_options: CfgOptions,
|
||||||
#[return_ref]
|
#[return_ref]
|
||||||
pub env: Env,
|
pub env: Env,
|
||||||
}
|
}
|
||||||
|
@ -421,7 +420,7 @@ impl CrateGraphBuilder {
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
display_name: Option<CrateDisplayName>,
|
display_name: Option<CrateDisplayName>,
|
||||||
version: Option<String>,
|
version: Option<String>,
|
||||||
cfg_options: Arc<CfgOptions>,
|
cfg_options: CfgOptions,
|
||||||
potential_cfg_options: Option<CfgOptions>,
|
potential_cfg_options: Option<CfgOptions>,
|
||||||
mut env: Env,
|
mut env: Env,
|
||||||
origin: CrateOrigin,
|
origin: CrateOrigin,
|
||||||
|
|
|
@ -11,7 +11,6 @@ use hir_expand::{
|
||||||
};
|
};
|
||||||
use span::{Edition, SyntaxContext};
|
use span::{Edition, SyntaxContext};
|
||||||
use syntax::{Parse, ast};
|
use syntax::{Parse, ast};
|
||||||
use triomphe::Arc;
|
|
||||||
|
|
||||||
use crate::type_ref::{TypesMap, TypesSourceMap};
|
use crate::type_ref::{TypesMap, TypesSourceMap};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -21,7 +20,6 @@ use crate::{
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Expander {
|
pub struct Expander {
|
||||||
cfg_options: Arc<CfgOptions>,
|
|
||||||
span_map: OnceCell<SpanMap>,
|
span_map: OnceCell<SpanMap>,
|
||||||
current_file_id: HirFileId,
|
current_file_id: HirFileId,
|
||||||
pub(crate) module: ModuleId,
|
pub(crate) module: ModuleId,
|
||||||
|
@ -44,7 +42,6 @@ impl Expander {
|
||||||
module,
|
module,
|
||||||
recursion_depth: 0,
|
recursion_depth: 0,
|
||||||
recursion_limit,
|
recursion_limit,
|
||||||
cfg_options: Arc::clone(module.krate.cfg_options(db)),
|
|
||||||
span_map: OnceCell::new(),
|
span_map: OnceCell::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,8 +138,8 @@ impl Expander {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn cfg_options(&self) -> &CfgOptions {
|
pub(crate) fn cfg_options<'db>(&self, db: &'db dyn DefDatabase) -> &'db CfgOptions {
|
||||||
&self.cfg_options
|
self.module.krate.cfg_options(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_file_id(&self) -> HirFileId {
|
pub fn current_file_id(&self) -> HirFileId {
|
||||||
|
|
|
@ -1894,14 +1894,14 @@ impl ExprCollector<'_> {
|
||||||
fn check_cfg(&mut self, owner: &dyn ast::HasAttrs) -> Option<()> {
|
fn check_cfg(&mut self, owner: &dyn ast::HasAttrs) -> Option<()> {
|
||||||
match self.expander.parse_attrs(self.db, owner).cfg() {
|
match self.expander.parse_attrs(self.db, owner).cfg() {
|
||||||
Some(cfg) => {
|
Some(cfg) => {
|
||||||
if self.expander.cfg_options().check(&cfg) != Some(false) {
|
if self.expander.cfg_options(self.db).check(&cfg) != Some(false) {
|
||||||
return Some(());
|
return Some(());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.source_map.diagnostics.push(ExpressionStoreDiagnostics::InactiveCode {
|
self.source_map.diagnostics.push(ExpressionStoreDiagnostics::InactiveCode {
|
||||||
node: self.expander.in_file(SyntaxNodePtr::new(owner.syntax())),
|
node: self.expander.in_file(SyntaxNodePtr::new(owner.syntax())),
|
||||||
cfg,
|
cfg,
|
||||||
opts: self.expander.cfg_options().clone(),
|
opts: self.expander.cfg_options(self.db).clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
None
|
None
|
||||||
|
|
|
@ -167,13 +167,13 @@ impl<'a> AssocItemCollector<'a> {
|
||||||
|
|
||||||
'items: for &item in assoc_items {
|
'items: for &item in assoc_items {
|
||||||
let attrs = item_tree.attrs(self.db, self.module_id.krate, ModItem::from(item).into());
|
let attrs = item_tree.attrs(self.db, self.module_id.krate, ModItem::from(item).into());
|
||||||
if !attrs.is_cfg_enabled(self.expander.cfg_options()) {
|
if !attrs.is_cfg_enabled(self.expander.cfg_options(self.db)) {
|
||||||
self.diagnostics.push(DefDiagnostic::unconfigured_code(
|
self.diagnostics.push(DefDiagnostic::unconfigured_code(
|
||||||
self.module_id.local_id,
|
self.module_id.local_id,
|
||||||
tree_id,
|
tree_id,
|
||||||
ModItem::from(item).into(),
|
ModItem::from(item).into(),
|
||||||
attrs.cfg().unwrap(),
|
attrs.cfg().unwrap(),
|
||||||
self.expander.cfg_options().clone(),
|
self.expander.cfg_options(self.db).clone(),
|
||||||
));
|
));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub const BAZ: u32 = 0;
|
||||||
Edition::CURRENT,
|
Edition::CURRENT,
|
||||||
Some(CrateDisplayName::from_canonical_name(crate_name)),
|
Some(CrateDisplayName::from_canonical_name(crate_name)),
|
||||||
None,
|
None,
|
||||||
Arc::default(),
|
Default::default(),
|
||||||
None,
|
None,
|
||||||
Env::default(),
|
Env::default(),
|
||||||
CrateOrigin::Local { repo: None, name: Some(Symbol::intern(crate_name)) },
|
CrateOrigin::Local { repo: None, name: Some(Symbol::intern(crate_name)) },
|
||||||
|
|
|
@ -1226,7 +1226,7 @@ impl HirDisplay for Ty {
|
||||||
TyKind::Adt(AdtId(def_id), parameters) => {
|
TyKind::Adt(AdtId(def_id), parameters) => {
|
||||||
f.start_location_link((*def_id).into());
|
f.start_location_link((*def_id).into());
|
||||||
match f.display_kind {
|
match f.display_kind {
|
||||||
DisplayKind::Diagnostics { .. } | DisplayKind::Test { .. } => {
|
DisplayKind::Diagnostics | DisplayKind::Test => {
|
||||||
let name = match *def_id {
|
let name = match *def_id {
|
||||||
hir_def::AdtId::StructId(it) => db.struct_data(it).name.clone(),
|
hir_def::AdtId::StructId(it) => db.struct_data(it).name.clone(),
|
||||||
hir_def::AdtId::UnionId(it) => db.union_data(it).name.clone(),
|
hir_def::AdtId::UnionId(it) => db.union_data(it).name.clone(),
|
||||||
|
|
|
@ -276,8 +276,8 @@ impl Crate {
|
||||||
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
|
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cfg(&self, db: &dyn HirDatabase) -> Arc<CfgOptions> {
|
pub fn cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions {
|
||||||
Arc::clone(self.id.cfg_options(db))
|
self.id.cfg_options(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn potential_cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions {
|
pub fn potential_cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions {
|
||||||
|
|
|
@ -250,7 +250,7 @@ impl Analysis {
|
||||||
Edition::CURRENT,
|
Edition::CURRENT,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Arc::new(cfg_options),
|
cfg_options,
|
||||||
None,
|
None,
|
||||||
Env::default(),
|
Env::default(),
|
||||||
CrateOrigin::Local { repo: None, name: None },
|
CrateOrigin::Local { repo: None, name: None },
|
||||||
|
|
|
@ -1051,7 +1051,7 @@ fn project_json_to_crate_graph(
|
||||||
*edition,
|
*edition,
|
||||||
display_name.clone(),
|
display_name.clone(),
|
||||||
version.clone(),
|
version.clone(),
|
||||||
Arc::new(cfg_options),
|
cfg_options,
|
||||||
None,
|
None,
|
||||||
env,
|
env,
|
||||||
if let Some(name) = display_name.clone() {
|
if let Some(name) = display_name.clone() {
|
||||||
|
@ -1341,7 +1341,7 @@ fn detached_file_to_crate_graph(
|
||||||
}
|
}
|
||||||
cfg_options.insert_atom(sym::rust_analyzer.clone());
|
cfg_options.insert_atom(sym::rust_analyzer.clone());
|
||||||
override_cfg.apply(&mut cfg_options, "");
|
override_cfg.apply(&mut cfg_options, "");
|
||||||
let cfg_options = Arc::new(cfg_options);
|
let cfg_options = cfg_options;
|
||||||
|
|
||||||
let file_id = match load(detached_file) {
|
let file_id = match load(detached_file) {
|
||||||
Some(file_id) => file_id,
|
Some(file_id) => file_id,
|
||||||
|
@ -1526,7 +1526,7 @@ fn add_target_crate_root(
|
||||||
edition,
|
edition,
|
||||||
Some(CrateDisplayName::from_canonical_name(cargo_name)),
|
Some(CrateDisplayName::from_canonical_name(cargo_name)),
|
||||||
Some(pkg.version.to_string()),
|
Some(pkg.version.to_string()),
|
||||||
Arc::new(cfg_options),
|
cfg_options,
|
||||||
potential_cfg_options,
|
potential_cfg_options,
|
||||||
env,
|
env,
|
||||||
origin,
|
origin,
|
||||||
|
@ -1680,13 +1680,13 @@ fn sysroot_to_crate_graph(
|
||||||
extend_crate_graph_with_sysroot(crate_graph, sysroot_cg, sysroot_pm)
|
extend_crate_graph_with_sysroot(crate_graph, sysroot_cg, sysroot_pm)
|
||||||
}
|
}
|
||||||
RustLibSrcWorkspace::Stitched(stitched) => {
|
RustLibSrcWorkspace::Stitched(stitched) => {
|
||||||
let cfg_options = Arc::new({
|
let cfg_options = {
|
||||||
let mut cfg_options = CfgOptions::default();
|
let mut cfg_options = CfgOptions::default();
|
||||||
cfg_options.extend(rustc_cfg);
|
cfg_options.extend(rustc_cfg);
|
||||||
cfg_options.insert_atom(sym::debug_assertions.clone());
|
cfg_options.insert_atom(sym::debug_assertions.clone());
|
||||||
cfg_options.insert_atom(sym::miri.clone());
|
cfg_options.insert_atom(sym::miri.clone());
|
||||||
cfg_options
|
cfg_options
|
||||||
});
|
};
|
||||||
let sysroot_crates: FxHashMap<
|
let sysroot_crates: FxHashMap<
|
||||||
crate::sysroot::stitched::RustLibSrcCrate,
|
crate::sysroot::stitched::RustLibSrcCrate,
|
||||||
CrateBuilderId,
|
CrateBuilderId,
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl salsa::Database for LoggerDb {
|
||||||
let event = event();
|
let event = event();
|
||||||
match event.kind {
|
match event.kind {
|
||||||
salsa::EventKind::WillExecute { .. }
|
salsa::EventKind::WillExecute { .. }
|
||||||
| salsa::EventKind::WillCheckCancellation { .. }
|
| salsa::EventKind::WillCheckCancellation
|
||||||
| salsa::EventKind::DidValidateMemoizedValue { .. }
|
| salsa::EventKind::DidValidateMemoizedValue { .. }
|
||||||
| salsa::EventKind::WillDiscardStaleOutput { .. }
|
| salsa::EventKind::WillDiscardStaleOutput { .. }
|
||||||
| salsa::EventKind::DidDiscard { .. } => {
|
| salsa::EventKind::DidDiscard { .. } => {
|
||||||
|
|
|
@ -207,7 +207,7 @@ impl ChangeFixture {
|
||||||
meta.edition,
|
meta.edition,
|
||||||
Some(crate_name.clone().into()),
|
Some(crate_name.clone().into()),
|
||||||
version,
|
version,
|
||||||
From::from(meta.cfg.clone()),
|
meta.cfg.clone(),
|
||||||
Some(meta.cfg),
|
Some(meta.cfg),
|
||||||
meta.env,
|
meta.env,
|
||||||
origin,
|
origin,
|
||||||
|
@ -247,7 +247,7 @@ impl ChangeFixture {
|
||||||
Edition::CURRENT,
|
Edition::CURRENT,
|
||||||
Some(CrateName::new("ra_test_fixture").unwrap().into()),
|
Some(CrateName::new("ra_test_fixture").unwrap().into()),
|
||||||
None,
|
None,
|
||||||
From::from(default_cfg.clone()),
|
default_cfg.clone(),
|
||||||
Some(default_cfg),
|
Some(default_cfg),
|
||||||
default_env,
|
default_env,
|
||||||
CrateOrigin::Local { repo: None, name: None },
|
CrateOrigin::Local { repo: None, name: None },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue