You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Fix panic processing invalid WIT
When an error was being generated part of the error message generation
was producing a panic by accessing some data within `Resolve` before it
was updated. The fix here is to move the data-updating before the error
message generation to resolve the panic.
* Reformat some long lines
Let `rustfmt` be able to wrap the lines
* Fix `cargo test -p wit-parser` in isolation
* Thread `Span` information for stability errors instead
/// Returns whether the `stability` annotation contained within `pkg_id`
1782
+
/// should be included or not.
1783
+
///
1784
+
/// The `span` provided here is an optional span pointing to the item that
1785
+
/// is annotated with `stability`.
1786
+
///
1787
+
/// Returns `Ok(true)` if the item is included, or `Ok(false)` if the item
1788
+
/// is not.
1789
+
///
1790
+
/// # Errors
1791
+
///
1792
+
/// Returns an error if the `pkg_id` isn't annotated with sufficient version
1793
+
/// information to have a `stability` annotation. For example if `pkg_id`
1794
+
/// has no version listed then an error will be returned if `stability`
1795
+
/// mentions a version.
1796
+
fninclude_stability(
1797
+
&self,
1798
+
stability:&Stability,
1799
+
pkg_id:&PackageId,
1800
+
span:Option<Span>,
1801
+
) -> Result<bool>{
1802
+
let err = |msg:String| match span {
1803
+
Some(span) => Error::new(span, msg).into(),
1804
+
None => anyhow::Error::msg(msg),
1805
+
};
1782
1806
Ok(match stability {
1783
1807
Stability::Unknown => true,
1784
-
// NOTE: deprecations are intentionally omitted -- an existing `@since` takes precedence over `@deprecated`
1808
+
// NOTE: deprecations are intentionally omitted -- an existing
1809
+
// `@since` takes precedence over `@deprecated`
1785
1810
Stability::Stable{ since, .. } => {
1786
1811
letSome(p) = self.packages.get(*pkg_id)else{
1787
-
// We can't check much without a package (possibly dealing with an item in an `UnresolvedPackage`),
1788
-
// @since version & deprecations can't be checked because there's no package version to compare to.
1812
+
// We can't check much without a package (possibly dealing
1813
+
// with an item in an `UnresolvedPackage`), @since version &
1814
+
// deprecations can't be checked because there's no package
1815
+
// version to compare to.
1789
1816
//
1790
-
// Feature requirements on stabilized features are ignored in resolved packages, so we do the same here.
1817
+
// Feature requirements on stabilized features are ignored
1818
+
// in resolved packages, so we do the same here.
1791
1819
returnOk(true);
1792
1820
};
1793
1821
1794
-
// Use of feature gating with version specifiers inside a package that is not versioned is not allowed
1795
-
let package_version = p.name.version.as_ref().with_context(|| format!("package [{}] contains a feature gate with a version specifier, so it must have a version", p.name))?;
1822
+
// Use of feature gating with version specifiers inside a
1823
+
// package that is not versioned is not allowed
1824
+
let package_version = p.name.version.as_ref().ok_or_else(|| {
1825
+
err(format!(
1826
+
"package [{}] contains a feature gate with a version \
1827
+
specifier, so it must have a version",
1828
+
p.name
1829
+
))
1830
+
})?;
1796
1831
1797
1832
// If the version on the feature gate is:
1798
1833
// - released, then we can include it
1799
1834
// - unreleased, then we must check the feature (if present)
1800
-
ensure!(
1801
-
since <= package_version,
1802
-
"feature gate cannot reference unreleased version {since} of package [{}] (current version {package_version})",
1803
-
p.name
1804
-
);
1835
+
if since > package_version {
1836
+
returnErr(err(format!(
1837
+
"feature gate cannot reference unreleased version \
1838
+
{since} of package [{}] (current version {package_version})",
0 commit comments