|
1 | 1 | use std::cmp::Ordering;
|
2 | 2 | use std::collections::hash_map;
|
3 | 3 | use std::collections::{BTreeMap, HashMap, HashSet};
|
| 4 | +use std::fmt; |
4 | 5 | use std::mem;
|
5 | 6 | use std::path::{Path, PathBuf};
|
6 | 7 |
|
@@ -1895,8 +1896,7 @@ package {name} is defined in two different locations:\n\
|
1895 | 1896 | // more refactoring, so it's left to a future date in the
|
1896 | 1897 | // hopes that most folks won't actually run into this for
|
1897 | 1898 | // the time being.
|
1898 |
| - "interface `{name}` transitively depends on an interface in \ |
1899 |
| - incompatible ways", |
| 1899 | + InvalidTransitiveDependency(name), |
1900 | 1900 | );
|
1901 | 1901 | }
|
1902 | 1902 | }
|
@@ -3439,6 +3439,34 @@ fn update_stability(from: &Stability, into: &mut Stability) -> Result<()> {
|
3439 | 3439 | bail!("mismatch in stability attributes")
|
3440 | 3440 | }
|
3441 | 3441 |
|
| 3442 | +/// An error that can be returned during "world elaboration" during various |
| 3443 | +/// [`Resolve`] operations. |
| 3444 | +/// |
| 3445 | +/// Methods on [`Resolve`] which mutate its internals, such as |
| 3446 | +/// [`Resolve::push_dir`] or [`Resolve::importize`] can fail if `world` imports |
| 3447 | +/// in WIT packages are invalid. This error indicates one of these situations |
| 3448 | +/// where an invalid dependency graph between imports and exports are detected. |
| 3449 | +/// |
| 3450 | +/// Note that at this time this error is subtle and not easy to understand, and |
| 3451 | +/// work needs to be done to explain this better and additionally provide a |
| 3452 | +/// better error message. For now though this type enables callers to test for |
| 3453 | +/// the exact kind of error emitted. |
| 3454 | +#[derive(Debug, Clone)] |
| 3455 | +pub struct InvalidTransitiveDependency(String); |
| 3456 | + |
| 3457 | +impl fmt::Display for InvalidTransitiveDependency { |
| 3458 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 3459 | + write!( |
| 3460 | + f, |
| 3461 | + "interface `{}` transitively depends on an interface in \ |
| 3462 | + incompatible ways", |
| 3463 | + self.0 |
| 3464 | + ) |
| 3465 | + } |
| 3466 | +} |
| 3467 | + |
| 3468 | +impl std::error::Error for InvalidTransitiveDependency {} |
| 3469 | + |
3442 | 3470 | #[cfg(test)]
|
3443 | 3471 | mod tests {
|
3444 | 3472 | use crate::Resolve;
|
|
0 commit comments