mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
internal: Refine CrateOrigin variants
This commit is contained in:
parent
42d671fcb7
commit
31db1fc75f
12 changed files with 343 additions and 235 deletions
|
@ -166,6 +166,7 @@ impl ChangeFixture {
|
|||
.as_deref()
|
||||
.map(Arc::from)
|
||||
.ok_or_else(|| "target_data_layout unset".into()),
|
||||
None,
|
||||
);
|
||||
let prev = crates.insert(crate_name.clone(), crate_id);
|
||||
assert!(prev.is_none());
|
||||
|
@ -200,10 +201,11 @@ impl ChangeFixture {
|
|||
default_cfg,
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
default_target_data_layout
|
||||
.map(|x| x.into())
|
||||
.ok_or_else(|| "target_data_layout unset".into()),
|
||||
None,
|
||||
);
|
||||
} else {
|
||||
for (from, to, prelude) in crate_deps {
|
||||
|
@ -245,6 +247,7 @@ impl ChangeFixture {
|
|||
false,
|
||||
CrateOrigin::Lang(LangCrateOrigin::Core),
|
||||
target_layout.clone(),
|
||||
None,
|
||||
);
|
||||
|
||||
for krate in all_crates {
|
||||
|
@ -281,8 +284,9 @@ impl ChangeFixture {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
true,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
target_layout,
|
||||
None,
|
||||
);
|
||||
proc_macros.insert(proc_macros_crate, Ok(proc_macro));
|
||||
|
||||
|
@ -427,7 +431,7 @@ fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
|
|||
let (version, origin) = match b.split_once(':') {
|
||||
Some(("CratesIo", data)) => match data.split_once(',') {
|
||||
Some((version, url)) => {
|
||||
(version, CrateOrigin::CratesIo { repo: Some(url.to_owned()), name: None })
|
||||
(version, CrateOrigin::Local { repo: Some(url.to_owned()), name: None })
|
||||
}
|
||||
_ => panic!("Bad crates.io parameter: {data}"),
|
||||
},
|
||||
|
@ -435,10 +439,9 @@ fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
|
|||
};
|
||||
(a.to_owned(), origin, Some(version.to_string()))
|
||||
} else {
|
||||
let crate_origin = match &*crate_str {
|
||||
"std" => CrateOrigin::Lang(LangCrateOrigin::Std),
|
||||
"core" => CrateOrigin::Lang(LangCrateOrigin::Core),
|
||||
_ => CrateOrigin::CratesIo { repo: None, name: None },
|
||||
let crate_origin = match LangCrateOrigin::from(&*crate_str) {
|
||||
LangCrateOrigin::Other => CrateOrigin::Local { repo: None, name: None },
|
||||
origin => CrateOrigin::Lang(origin),
|
||||
};
|
||||
(crate_str, crate_origin, None)
|
||||
}
|
||||
|
|
|
@ -135,8 +135,12 @@ impl ops::Deref for CrateName {
|
|||
/// Origin of the crates. It is used in emitting monikers.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum CrateOrigin {
|
||||
/// Crates that are from crates.io official registry,
|
||||
CratesIo { repo: Option<String>, name: Option<String> },
|
||||
/// Crates that are from the rustc workspace
|
||||
Rustc { name: String },
|
||||
/// Crates that are workspace members,
|
||||
Local { repo: Option<String>, name: Option<String> },
|
||||
/// Crates that are non member libraries.
|
||||
Library { repo: Option<String>, name: String },
|
||||
/// Crates that are provided by the language, like std, core, proc-macro, ...
|
||||
Lang(LangCrateOrigin),
|
||||
}
|
||||
|
@ -257,6 +261,32 @@ pub struct ProcMacro {
|
|||
pub expander: Arc<dyn ProcMacroExpander>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum ReleaseChannel {
|
||||
Stable,
|
||||
Beta,
|
||||
Nightly,
|
||||
}
|
||||
|
||||
impl ReleaseChannel {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
ReleaseChannel::Stable => "stable",
|
||||
ReleaseChannel::Beta => "beta",
|
||||
ReleaseChannel::Nightly => "nightly",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_str(str: &str) -> Option<Self> {
|
||||
Some(match str {
|
||||
"stable" => ReleaseChannel::Stable,
|
||||
"beta" => ReleaseChannel::Beta,
|
||||
"nightly" => ReleaseChannel::Nightly,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CrateData {
|
||||
pub root_file_id: FileId,
|
||||
|
@ -271,11 +301,13 @@ pub struct CrateData {
|
|||
pub display_name: Option<CrateDisplayName>,
|
||||
pub cfg_options: CfgOptions,
|
||||
pub potential_cfg_options: CfgOptions,
|
||||
pub target_layout: TargetLayoutLoadResult,
|
||||
pub env: Env,
|
||||
pub dependencies: Vec<Dependency>,
|
||||
pub origin: CrateOrigin,
|
||||
pub is_proc_macro: bool,
|
||||
// FIXME: These things should not be per crate! These are more per workspace crate graph level things
|
||||
pub target_layout: TargetLayoutLoadResult,
|
||||
pub channel: Option<ReleaseChannel>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
|
@ -329,6 +361,7 @@ impl CrateGraph {
|
|||
is_proc_macro: bool,
|
||||
origin: CrateOrigin,
|
||||
target_layout: Result<Arc<str>, Arc<str>>,
|
||||
channel: Option<ReleaseChannel>,
|
||||
) -> CrateId {
|
||||
let data = CrateData {
|
||||
root_file_id,
|
||||
|
@ -342,6 +375,7 @@ impl CrateGraph {
|
|||
origin,
|
||||
target_layout,
|
||||
is_proc_macro,
|
||||
channel,
|
||||
};
|
||||
let crate_id = CrateId(self.arena.len() as u32);
|
||||
let prev = self.arena.insert(crate_id, data);
|
||||
|
@ -653,8 +687,9 @@ mod tests {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
Err("".into()),
|
||||
None,
|
||||
);
|
||||
let crate2 = graph.add_crate_root(
|
||||
FileId(2u32),
|
||||
|
@ -665,8 +700,9 @@ mod tests {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
Err("".into()),
|
||||
None,
|
||||
);
|
||||
let crate3 = graph.add_crate_root(
|
||||
FileId(3u32),
|
||||
|
@ -677,8 +713,9 @@ mod tests {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
Err("".into()),
|
||||
None,
|
||||
);
|
||||
assert!(graph
|
||||
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
|
||||
|
@ -703,8 +740,9 @@ mod tests {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
Err("".into()),
|
||||
None,
|
||||
);
|
||||
let crate2 = graph.add_crate_root(
|
||||
FileId(2u32),
|
||||
|
@ -715,8 +753,9 @@ mod tests {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
Err("".into()),
|
||||
None,
|
||||
);
|
||||
assert!(graph
|
||||
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
|
||||
|
@ -738,8 +777,9 @@ mod tests {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
Err("".into()),
|
||||
None,
|
||||
);
|
||||
let crate2 = graph.add_crate_root(
|
||||
FileId(2u32),
|
||||
|
@ -750,8 +790,9 @@ mod tests {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
Err("".into()),
|
||||
None,
|
||||
);
|
||||
let crate3 = graph.add_crate_root(
|
||||
FileId(3u32),
|
||||
|
@ -762,8 +803,9 @@ mod tests {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
Err("".into()),
|
||||
None,
|
||||
);
|
||||
assert!(graph
|
||||
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
|
||||
|
@ -785,8 +827,9 @@ mod tests {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
Err("".into()),
|
||||
None,
|
||||
);
|
||||
let crate2 = graph.add_crate_root(
|
||||
FileId(2u32),
|
||||
|
@ -797,8 +840,9 @@ mod tests {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
false,
|
||||
CrateOrigin::CratesIo { repo: None, name: None },
|
||||
CrateOrigin::Local { repo: None, name: None },
|
||||
Err("".into()),
|
||||
None,
|
||||
);
|
||||
assert!(graph
|
||||
.add_dep(
|
||||
|
|
|
@ -16,8 +16,8 @@ pub use crate::{
|
|||
input::{
|
||||
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency,
|
||||
Edition, Env, LangCrateOrigin, ProcMacro, ProcMacroExpander, ProcMacroExpansionError,
|
||||
ProcMacroId, ProcMacroKind, ProcMacroLoadResult, ProcMacroPaths, ProcMacros, SourceRoot,
|
||||
SourceRootId, TargetLayoutLoadResult,
|
||||
ProcMacroId, ProcMacroKind, ProcMacroLoadResult, ProcMacroPaths, ProcMacros,
|
||||
ReleaseChannel, SourceRoot, SourceRootId, TargetLayoutLoadResult,
|
||||
},
|
||||
};
|
||||
pub use salsa::{self, Cancelled};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue