#[non_exhaustive]pub enum ResolveError {
UnknownModule(ModuleId),
DuplicateName {
module: ModuleId,
name: Symbol,
},
Unresolved {
module: ModuleId,
name: Symbol,
},
Private {
module: ModuleId,
name: Symbol,
},
ImportCycle {
module: ModuleId,
name: Symbol,
},
}Expand description
The reason a graph operation or a name resolution did not succeed.
Building the graph and resolving through it can fail five ways, each a distinct, defined outcome rather than a panic or a silently wrong answer:
- the id passed in was not minted by this graph
(
UnknownModule), - a name was declared twice in one module
(
DuplicateName), - a name is not declared in the module it was looked up in
(
Unresolved), - an import targets a name that is private to the module that declares it
(
Private), or - an import chain loops back on itself (
ImportCycle).
Each variant carries the ModuleId and Symbol it concerns, so a caller
can recover the human-readable spelling from its own interner and build a
richer diagnostic. The fmt::Display form is a terse fallback that names the
raw ids — module-lang does not own the interner, so it cannot print the name.
The enum is #[non_exhaustive]: a downstream match must include a wildcard
arm, so later additions never force a breaking change on callers.
§Examples
use intern_lang::Interner;
use module_lang::{ModuleGraph, ResolveError, Visibility};
use source_lang::SourceMap;
let mut sources = SourceMap::new();
let mut names = Interner::new();
let mut graph: ModuleGraph<()> = ModuleGraph::new();
let m = graph.add_module(names.intern("m"), sources.add("m", "").expect("fits"));
let x = names.intern("x");
graph.define(m, x, Visibility::Public, ()).expect("first definition is unique");
// Declaring the same name again in the same module is a defined error.
assert!(matches!(
graph.define(m, x, Visibility::Public, ()),
Err(ResolveError::DuplicateName { .. }),
));
// Looking up a name that was never declared is a defined error, not a panic.
let y = names.intern("y");
assert!(matches!(
graph.resolve(m, y),
Err(ResolveError::Unresolved { .. }),
));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
UnknownModule(ModuleId)
A ModuleId was passed that this graph never minted.
Every id comes from
ModuleGraph::add_module on the graph it
is used with; an id from a different graph, or one fabricated by other
means, lands here instead of indexing out of bounds.
DuplicateName
A name was declared twice in the same module.
Both define and
import reject a name already present in the
target module — a module’s namespace is flat, so a definition and an import
cannot share a spelling. The conflict is reported where the second
declaration is added, not silently resolved last-write-wins.
Fields
Unresolved
A name is not declared in the module it was looked up in.
Returned by resolve when neither a
definition nor an import in the module (or, following an import chain, in a
source module) declares the name.
Fields
Private
An import resolved to a name that is private to the module declaring it.
A Visibility::Private definition is visible
only from within its own module; reaching it through an import from another
module is rejected here rather than silently allowed.
Fields
ImportCycle
An import chain loops back on itself.
Resolving an import follows it to its source module, and so on; if that walk
returns to a (module, name) pair it has already visited, the chain forms a
cycle. It is reported here in bounded time rather than recursing without
limit.
Trait Implementations§
Source§impl Clone for ResolveError
impl Clone for ResolveError
Source§fn clone(&self) -> ResolveError
fn clone(&self) -> ResolveError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ResolveError
impl Debug for ResolveError
Source§impl Display for ResolveError
impl Display for ResolveError
impl Eq for ResolveError
Source§impl Error for ResolveError
impl Error for ResolveError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl PartialEq for ResolveError
impl PartialEq for ResolveError
Source§fn eq(&self, other: &ResolveError) -> bool
fn eq(&self, other: &ResolveError) -> bool
self and other values to be equal, and is used by ==.