mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
refactor(manifest): Switch from toml_edit to toml
Technically this will cause a small regression in performance from `toml_edit@0.23` but not `toml_edit@0.22`
This commit is contained in:
parent
6e04449c27
commit
ad8fb2f0c9
@ -63,7 +63,7 @@ impl EitherManifest {
|
|||||||
pub struct Manifest {
|
pub struct Manifest {
|
||||||
// alternate forms of manifests:
|
// alternate forms of manifests:
|
||||||
contents: Rc<String>,
|
contents: Rc<String>,
|
||||||
document: Rc<toml_edit::Document<String>>,
|
document: Rc<toml::Spanned<toml::de::DeTable<'static>>>,
|
||||||
original_toml: Rc<TomlManifest>,
|
original_toml: Rc<TomlManifest>,
|
||||||
normalized_toml: Rc<TomlManifest>,
|
normalized_toml: Rc<TomlManifest>,
|
||||||
summary: Summary,
|
summary: Summary,
|
||||||
@ -109,7 +109,7 @@ pub struct Warnings(Vec<DelayedWarning>);
|
|||||||
pub struct VirtualManifest {
|
pub struct VirtualManifest {
|
||||||
// alternate forms of manifests:
|
// alternate forms of manifests:
|
||||||
contents: Rc<String>,
|
contents: Rc<String>,
|
||||||
document: Rc<toml_edit::Document<String>>,
|
document: Rc<toml::Spanned<toml::de::DeTable<'static>>>,
|
||||||
original_toml: Rc<TomlManifest>,
|
original_toml: Rc<TomlManifest>,
|
||||||
normalized_toml: Rc<TomlManifest>,
|
normalized_toml: Rc<TomlManifest>,
|
||||||
|
|
||||||
@ -496,7 +496,7 @@ compact_debug! {
|
|||||||
impl Manifest {
|
impl Manifest {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
contents: Rc<String>,
|
contents: Rc<String>,
|
||||||
document: Rc<toml_edit::Document<String>>,
|
document: Rc<toml::Spanned<toml::de::DeTable<'static>>>,
|
||||||
original_toml: Rc<TomlManifest>,
|
original_toml: Rc<TomlManifest>,
|
||||||
normalized_toml: Rc<TomlManifest>,
|
normalized_toml: Rc<TomlManifest>,
|
||||||
summary: Summary,
|
summary: Summary,
|
||||||
@ -565,7 +565,7 @@ impl Manifest {
|
|||||||
Ok(format!("{}\n{}", MANIFEST_PREAMBLE, toml))
|
Ok(format!("{}\n{}", MANIFEST_PREAMBLE, toml))
|
||||||
}
|
}
|
||||||
/// Collection of spans for the original TOML
|
/// Collection of spans for the original TOML
|
||||||
pub fn document(&self) -> &toml_edit::Document<String> {
|
pub fn document(&self) -> &toml::Spanned<toml::de::DeTable<'static>> {
|
||||||
&self.document
|
&self.document
|
||||||
}
|
}
|
||||||
/// The [`TomlManifest`] as parsed from [`Manifest::document`]
|
/// The [`TomlManifest`] as parsed from [`Manifest::document`]
|
||||||
@ -738,7 +738,7 @@ impl Manifest {
|
|||||||
impl VirtualManifest {
|
impl VirtualManifest {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
contents: Rc<String>,
|
contents: Rc<String>,
|
||||||
document: Rc<toml_edit::Document<String>>,
|
document: Rc<toml::Spanned<toml::de::DeTable<'static>>>,
|
||||||
original_toml: Rc<TomlManifest>,
|
original_toml: Rc<TomlManifest>,
|
||||||
normalized_toml: Rc<TomlManifest>,
|
normalized_toml: Rc<TomlManifest>,
|
||||||
replace: Vec<(PackageIdSpec, Dependency)>,
|
replace: Vec<(PackageIdSpec, Dependency)>,
|
||||||
@ -766,7 +766,7 @@ impl VirtualManifest {
|
|||||||
self.contents.as_str()
|
self.contents.as_str()
|
||||||
}
|
}
|
||||||
/// Collection of spans for the original TOML
|
/// Collection of spans for the original TOML
|
||||||
pub fn document(&self) -> &toml_edit::Document<String> {
|
pub fn document(&self) -> &toml::Spanned<toml::de::DeTable<'static>> {
|
||||||
&self.document
|
&self.document
|
||||||
}
|
}
|
||||||
/// The [`TomlManifest`] as parsed from [`VirtualManifest::document`]
|
/// The [`TomlManifest`] as parsed from [`VirtualManifest::document`]
|
||||||
|
@ -6,7 +6,6 @@ use pathdiff::diff_paths;
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use toml_edit::Document;
|
|
||||||
|
|
||||||
const LINT_GROUPS: &[LintGroup] = &[TEST_DUMMY_UNSTABLE];
|
const LINT_GROUPS: &[LintGroup] = &[TEST_DUMMY_UNSTABLE];
|
||||||
pub const LINTS: &[Lint] = &[IM_A_TEAPOT, UNKNOWN_LINTS];
|
pub const LINTS: &[Lint] = &[IM_A_TEAPOT, UNKNOWN_LINTS];
|
||||||
@ -16,7 +15,7 @@ pub fn analyze_cargo_lints_table(
|
|||||||
path: &Path,
|
path: &Path,
|
||||||
pkg_lints: &TomlToolLints,
|
pkg_lints: &TomlToolLints,
|
||||||
ws_contents: &str,
|
ws_contents: &str,
|
||||||
ws_document: &Document<String>,
|
ws_document: &toml::Spanned<toml::de::DeTable<'static>>,
|
||||||
ws_path: &Path,
|
ws_path: &Path,
|
||||||
gctx: &GlobalContext,
|
gctx: &GlobalContext,
|
||||||
) -> CargoResult<()> {
|
) -> CargoResult<()> {
|
||||||
@ -116,7 +115,7 @@ fn verify_feature_enabled(
|
|||||||
manifest: &Manifest,
|
manifest: &Manifest,
|
||||||
manifest_path: &str,
|
manifest_path: &str,
|
||||||
ws_contents: &str,
|
ws_contents: &str,
|
||||||
ws_document: &Document<String>,
|
ws_document: &toml::Spanned<toml::de::DeTable<'static>>,
|
||||||
ws_path: &str,
|
ws_path: &str,
|
||||||
error_count: &mut usize,
|
error_count: &mut usize,
|
||||||
gctx: &GlobalContext,
|
gctx: &GlobalContext,
|
||||||
@ -191,43 +190,33 @@ fn verify_feature_enabled(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_span(
|
pub fn get_span(
|
||||||
document: &Document<String>,
|
document: &toml::Spanned<toml::de::DeTable<'static>>,
|
||||||
path: &[&str],
|
path: &[&str],
|
||||||
get_value: bool,
|
get_value: bool,
|
||||||
) -> Option<Range<usize>> {
|
) -> Option<Range<usize>> {
|
||||||
let mut table = document.as_item().as_table_like()?;
|
let mut table = document.get_ref();
|
||||||
let mut iter = path.into_iter().peekable();
|
let mut iter = path.into_iter().peekable();
|
||||||
while let Some(key) = iter.next() {
|
while let Some(key) = iter.next() {
|
||||||
let (key, item) = table.get_key_value(key)?;
|
let key_s: &str = key.as_ref();
|
||||||
|
let (key, item) = table.get_key_value(key_s)?;
|
||||||
if iter.peek().is_none() {
|
if iter.peek().is_none() {
|
||||||
return if get_value {
|
return if get_value {
|
||||||
item.span()
|
Some(item.span())
|
||||||
} else {
|
} else {
|
||||||
let leaf_decor = key.dotted_decor();
|
Some(key.span())
|
||||||
let leaf_prefix_span = leaf_decor.prefix().and_then(|p| p.span());
|
|
||||||
let leaf_suffix_span = leaf_decor.suffix().and_then(|s| s.span());
|
|
||||||
if let (Some(leaf_prefix_span), Some(leaf_suffix_span)) =
|
|
||||||
(leaf_prefix_span, leaf_suffix_span)
|
|
||||||
{
|
|
||||||
Some(leaf_prefix_span.start..leaf_suffix_span.end)
|
|
||||||
} else {
|
|
||||||
key.span()
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if item.is_table_like() {
|
if let Some(next_table) = item.get_ref().as_table() {
|
||||||
table = item.as_table_like().unwrap();
|
table = next_table;
|
||||||
}
|
}
|
||||||
if item.is_array() && iter.peek().is_some() {
|
if iter.peek().is_some() {
|
||||||
let array = item.as_array().unwrap();
|
if let Some(array) = item.get_ref().as_array() {
|
||||||
let next = iter.next().unwrap();
|
let next = iter.next().unwrap();
|
||||||
return array.iter().find_map(|item| {
|
return array.iter().find_map(|item| match item.get_ref() {
|
||||||
if next == &item.to_string() {
|
toml::de::DeValue::String(s) if s == next => Some(item.span()),
|
||||||
item.span()
|
_ => None,
|
||||||
} else {
|
});
|
||||||
None
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
@ -511,7 +500,7 @@ fn output_unknown_lints(
|
|||||||
manifest_path: &str,
|
manifest_path: &str,
|
||||||
pkg_lints: &TomlToolLints,
|
pkg_lints: &TomlToolLints,
|
||||||
ws_contents: &str,
|
ws_contents: &str,
|
||||||
ws_document: &Document<String>,
|
ws_document: &toml::Spanned<toml::de::DeTable<'static>>,
|
||||||
ws_path: &str,
|
ws_path: &str,
|
||||||
error_count: &mut usize,
|
error_count: &mut usize,
|
||||||
gctx: &GlobalContext,
|
gctx: &GlobalContext,
|
||||||
|
@ -19,7 +19,6 @@ use cargo_util_schemas::manifest::{RustVersion, StringOrBool};
|
|||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lazycell::LazyCell;
|
use lazycell::LazyCell;
|
||||||
use pathdiff::diff_paths;
|
use pathdiff::diff_paths;
|
||||||
use toml_edit::Document;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::core::compiler::{CompileKind, CompileTarget};
|
use crate::core::compiler::{CompileKind, CompileTarget};
|
||||||
@ -166,16 +165,28 @@ fn read_toml_string(path: &Path, is_embedded: bool, gctx: &GlobalContext) -> Car
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
fn parse_document(contents: &str) -> Result<toml_edit::Document<String>, toml_edit::de::Error> {
|
fn parse_document(
|
||||||
toml_edit::Document::parse(contents.to_owned()).map_err(Into::into)
|
contents: &str,
|
||||||
|
) -> Result<toml::Spanned<toml::de::DeTable<'static>>, toml::de::Error> {
|
||||||
|
let mut table = toml::de::DeTable::parse(contents)?;
|
||||||
|
table.get_mut().make_owned();
|
||||||
|
// SAFETY: `DeTable::make_owned` ensures no borrows remain and the lifetime does not affect
|
||||||
|
// layout
|
||||||
|
let table = unsafe {
|
||||||
|
std::mem::transmute::<
|
||||||
|
toml::Spanned<toml::de::DeTable<'_>>,
|
||||||
|
toml::Spanned<toml::de::DeTable<'static>>,
|
||||||
|
>(table)
|
||||||
|
};
|
||||||
|
Ok(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
fn deserialize_toml(
|
fn deserialize_toml(
|
||||||
document: &toml_edit::Document<String>,
|
document: &toml::Spanned<toml::de::DeTable<'static>>,
|
||||||
) -> Result<manifest::TomlManifest, toml_edit::de::Error> {
|
) -> Result<manifest::TomlManifest, toml::de::Error> {
|
||||||
let mut unused = BTreeSet::new();
|
let mut unused = BTreeSet::new();
|
||||||
let deserializer = toml_edit::de::Deserializer::from(document.clone());
|
let deserializer = toml::de::Deserializer::from(document.clone());
|
||||||
let mut document: manifest::TomlManifest = serde_ignored::deserialize(deserializer, |path| {
|
let mut document: manifest::TomlManifest = serde_ignored::deserialize(deserializer, |path| {
|
||||||
let mut key = String::new();
|
let mut key = String::new();
|
||||||
stringify(&mut key, &path);
|
stringify(&mut key, &path);
|
||||||
@ -1256,7 +1267,7 @@ fn deprecated_ws_default_features(
|
|||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub fn to_real_manifest(
|
pub fn to_real_manifest(
|
||||||
contents: String,
|
contents: String,
|
||||||
document: toml_edit::Document<String>,
|
document: toml::Spanned<toml::de::DeTable<'static>>,
|
||||||
original_toml: manifest::TomlManifest,
|
original_toml: manifest::TomlManifest,
|
||||||
normalized_toml: manifest::TomlManifest,
|
normalized_toml: manifest::TomlManifest,
|
||||||
features: Features,
|
features: Features,
|
||||||
@ -1843,7 +1854,7 @@ pub fn to_real_manifest(
|
|||||||
fn missing_dep_diagnostic(
|
fn missing_dep_diagnostic(
|
||||||
missing_dep: &MissingDependencyError,
|
missing_dep: &MissingDependencyError,
|
||||||
orig_toml: &TomlManifest,
|
orig_toml: &TomlManifest,
|
||||||
document: &Document<String>,
|
document: &toml::Spanned<toml::de::DeTable<'static>>,
|
||||||
contents: &str,
|
contents: &str,
|
||||||
manifest_file: &Path,
|
manifest_file: &Path,
|
||||||
gctx: &GlobalContext,
|
gctx: &GlobalContext,
|
||||||
@ -1921,7 +1932,7 @@ fn missing_dep_diagnostic(
|
|||||||
|
|
||||||
fn to_virtual_manifest(
|
fn to_virtual_manifest(
|
||||||
contents: String,
|
contents: String,
|
||||||
document: toml_edit::Document<String>,
|
document: toml::Spanned<toml::de::DeTable<'static>>,
|
||||||
original_toml: manifest::TomlManifest,
|
original_toml: manifest::TomlManifest,
|
||||||
normalized_toml: manifest::TomlManifest,
|
normalized_toml: manifest::TomlManifest,
|
||||||
features: Features,
|
features: Features,
|
||||||
@ -2761,7 +2772,7 @@ fn lints_to_rustflags(lints: &manifest::TomlLints) -> CargoResult<Vec<String>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn emit_diagnostic(
|
fn emit_diagnostic(
|
||||||
e: toml_edit::de::Error,
|
e: toml::de::Error,
|
||||||
contents: &str,
|
contents: &str,
|
||||||
manifest_file: &Path,
|
manifest_file: &Path,
|
||||||
gctx: &GlobalContext,
|
gctx: &GlobalContext,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user