mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Don't add --all-targets to runnables for no-std crates
This commit is contained in:
parent
7c81fff520
commit
bbd9e41606
6 changed files with 47 additions and 13 deletions
|
@ -127,6 +127,8 @@ pub struct DefMap {
|
||||||
unstable_features: FxHashSet<SmolStr>,
|
unstable_features: FxHashSet<SmolStr>,
|
||||||
/// #[rustc_coherence_is_core]
|
/// #[rustc_coherence_is_core]
|
||||||
rustc_coherence_is_core: bool,
|
rustc_coherence_is_core: bool,
|
||||||
|
no_core: bool,
|
||||||
|
no_std: bool,
|
||||||
|
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
recursion_limit: Option<u32>,
|
recursion_limit: Option<u32>,
|
||||||
|
@ -294,6 +296,8 @@ impl DefMap {
|
||||||
unstable_features: FxHashSet::default(),
|
unstable_features: FxHashSet::default(),
|
||||||
diagnostics: Vec::new(),
|
diagnostics: Vec::new(),
|
||||||
rustc_coherence_is_core: false,
|
rustc_coherence_is_core: false,
|
||||||
|
no_core: false,
|
||||||
|
no_std: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,6 +335,10 @@ impl DefMap {
|
||||||
self.rustc_coherence_is_core
|
self.rustc_coherence_is_core
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_no_std(&self) -> bool {
|
||||||
|
self.no_std || self.no_core
|
||||||
|
}
|
||||||
|
|
||||||
pub fn root(&self) -> LocalModuleId {
|
pub fn root(&self) -> LocalModuleId {
|
||||||
self.root
|
self.root
|
||||||
}
|
}
|
||||||
|
@ -528,6 +536,8 @@ impl DefMap {
|
||||||
prelude: _,
|
prelude: _,
|
||||||
root: _,
|
root: _,
|
||||||
rustc_coherence_is_core: _,
|
rustc_coherence_is_core: _,
|
||||||
|
no_core: _,
|
||||||
|
no_std: _,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
extern_prelude.shrink_to_fit();
|
extern_prelude.shrink_to_fit();
|
||||||
|
|
|
@ -291,8 +291,6 @@ impl DefCollector<'_> {
|
||||||
|
|
||||||
let attrs = item_tree.top_level_attrs(self.db, self.def_map.krate);
|
let attrs = item_tree.top_level_attrs(self.db, self.def_map.krate);
|
||||||
|
|
||||||
self.inject_prelude(&attrs);
|
|
||||||
|
|
||||||
// Process other crate-level attributes.
|
// Process other crate-level attributes.
|
||||||
for attr in &*attrs {
|
for attr in &*attrs {
|
||||||
if let Some(cfg) = attr.cfg() {
|
if let Some(cfg) = attr.cfg() {
|
||||||
|
@ -321,6 +319,16 @@ impl DefCollector<'_> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *attr_name == hir_expand::name![no_core] {
|
||||||
|
self.def_map.no_core = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if *attr_name == hir_expand::name![no_std] {
|
||||||
|
self.def_map.no_std = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if attr_name.as_text().as_deref() == Some("rustc_coherence_is_core") {
|
if attr_name.as_text().as_deref() == Some("rustc_coherence_is_core") {
|
||||||
self.def_map.rustc_coherence_is_core = true;
|
self.def_map.rustc_coherence_is_core = true;
|
||||||
continue;
|
continue;
|
||||||
|
@ -359,6 +367,8 @@ impl DefCollector<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.inject_prelude();
|
||||||
|
|
||||||
ModCollector {
|
ModCollector {
|
||||||
def_collector: self,
|
def_collector: self,
|
||||||
macro_depth: 0,
|
macro_depth: 0,
|
||||||
|
@ -517,15 +527,15 @@ impl DefCollector<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inject_prelude(&mut self, crate_attrs: &Attrs) {
|
fn inject_prelude(&mut self) {
|
||||||
// See compiler/rustc_builtin_macros/src/standard_library_imports.rs
|
// See compiler/rustc_builtin_macros/src/standard_library_imports.rs
|
||||||
|
|
||||||
if crate_attrs.by_key("no_core").exists() {
|
if self.def_map.no_core {
|
||||||
// libcore does not get a prelude.
|
// libcore does not get a prelude.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let krate = if crate_attrs.by_key("no_std").exists() {
|
let krate = if self.def_map.no_std {
|
||||||
name![core]
|
name![core]
|
||||||
} else {
|
} else {
|
||||||
let std = name![std];
|
let std = name![std];
|
||||||
|
|
|
@ -366,6 +366,8 @@ pub mod known {
|
||||||
crate_type,
|
crate_type,
|
||||||
derive,
|
derive,
|
||||||
global_allocator,
|
global_allocator,
|
||||||
|
no_core,
|
||||||
|
no_std,
|
||||||
test,
|
test,
|
||||||
test_case,
|
test_case,
|
||||||
recursion_limit,
|
recursion_limit,
|
||||||
|
|
|
@ -531,6 +531,11 @@ impl Analysis {
|
||||||
self.with_db(|db| db.crate_graph()[crate_id].edition)
|
self.with_db(|db| db.crate_graph()[crate_id].edition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if this crate has `no_std` or `no_core` specified.
|
||||||
|
pub fn is_crate_no_std(&self, crate_id: CrateId) -> Cancellable<bool> {
|
||||||
|
self.with_db(|db| hir::db::DefDatabase::crate_def_map(db, crate_id).is_no_std())
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the root file of the given crate.
|
/// Returns the root file of the given crate.
|
||||||
pub fn crate_root(&self, crate_id: CrateId) -> Cancellable<FileId> {
|
pub fn crate_root(&self, crate_id: CrateId) -> Cancellable<FileId> {
|
||||||
self.with_db(|db| db.crate_graph()[crate_id].root_file_id)
|
self.with_db(|db| db.crate_graph()[crate_id].root_file_id)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use cfg::{CfgAtom, CfgExpr};
|
use cfg::{CfgAtom, CfgExpr};
|
||||||
use ide::{Cancellable, FileId, RunnableKind, TestId};
|
use ide::{Cancellable, CrateId, FileId, RunnableKind, TestId};
|
||||||
use project_model::{self, CargoFeatures, ManifestPath, TargetKind};
|
use project_model::{self, CargoFeatures, ManifestPath, TargetKind};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use vfs::AbsPathBuf;
|
use vfs::AbsPathBuf;
|
||||||
|
@ -21,6 +21,7 @@ pub(crate) struct CargoTargetSpec {
|
||||||
pub(crate) package: String,
|
pub(crate) package: String,
|
||||||
pub(crate) target: String,
|
pub(crate) target: String,
|
||||||
pub(crate) target_kind: TargetKind,
|
pub(crate) target_kind: TargetKind,
|
||||||
|
pub(crate) crate_id: CrateId,
|
||||||
pub(crate) required_features: Vec<String>,
|
pub(crate) required_features: Vec<String>,
|
||||||
pub(crate) features: FxHashSet<String>,
|
pub(crate) features: FxHashSet<String>,
|
||||||
}
|
}
|
||||||
|
@ -142,6 +143,7 @@ impl CargoTargetSpec {
|
||||||
target_kind: target_data.kind,
|
target_kind: target_data.kind,
|
||||||
required_features: target_data.required_features.clone(),
|
required_features: target_data.required_features.clone(),
|
||||||
features: package_data.features.keys().cloned().collect(),
|
features: package_data.features.keys().cloned().collect(),
|
||||||
|
crate_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Some(res))
|
Ok(Some(res))
|
||||||
|
|
|
@ -768,20 +768,25 @@ pub(crate) fn handle_runnables(
|
||||||
let config = snap.config.runnables();
|
let config = snap.config.runnables();
|
||||||
match cargo_spec {
|
match cargo_spec {
|
||||||
Some(spec) => {
|
Some(spec) => {
|
||||||
|
let all_targets = !snap.analysis.is_crate_no_std(spec.crate_id)?;
|
||||||
for cmd in ["check", "test"] {
|
for cmd in ["check", "test"] {
|
||||||
|
let mut cargo_args =
|
||||||
|
vec![cmd.to_owned(), "--package".to_owned(), spec.package.clone()];
|
||||||
|
if all_targets {
|
||||||
|
cargo_args.push("--all-targets".to_owned());
|
||||||
|
}
|
||||||
res.push(lsp_ext::Runnable {
|
res.push(lsp_ext::Runnable {
|
||||||
label: format!("cargo {cmd} -p {} --all-targets", spec.package),
|
label: format!(
|
||||||
|
"cargo {cmd} -p {}{all_targets}",
|
||||||
|
spec.package,
|
||||||
|
all_targets = if all_targets { " --all-targets" } else { "" }
|
||||||
|
),
|
||||||
location: None,
|
location: None,
|
||||||
kind: lsp_ext::RunnableKind::Cargo,
|
kind: lsp_ext::RunnableKind::Cargo,
|
||||||
args: lsp_ext::CargoRunnable {
|
args: lsp_ext::CargoRunnable {
|
||||||
workspace_root: Some(spec.workspace_root.clone().into()),
|
workspace_root: Some(spec.workspace_root.clone().into()),
|
||||||
override_cargo: config.override_cargo.clone(),
|
override_cargo: config.override_cargo.clone(),
|
||||||
cargo_args: vec![
|
cargo_args,
|
||||||
cmd.to_string(),
|
|
||||||
"--package".to_string(),
|
|
||||||
spec.package.clone(),
|
|
||||||
"--all-targets".to_string(),
|
|
||||||
],
|
|
||||||
cargo_extra_args: config.cargo_extra_args.clone(),
|
cargo_extra_args: config.cargo_extra_args.clone(),
|
||||||
executable_args: Vec::new(),
|
executable_args: Vec::new(),
|
||||||
expect_test: None,
|
expect_test: None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue