Skip to main content

ResolveError

Enum ResolveError 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

§module: ModuleId

The module the duplicate was added to.

§name: Symbol

The name that was already declared there.

§

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

§module: ModuleId

The module the name was looked up in.

§name: Symbol

The name that could not be found.

§

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

§module: ModuleId

The module that declares the name privately.

§name: Symbol

The private name an import tried to reach.

§

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.

Fields

§module: ModuleId

The module the walk looped back to.

§name: Symbol

The name whose import chain forms the cycle.

Trait Implementations§

Source§

impl Clone for ResolveError

Source§

fn clone(&self) -> ResolveError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResolveError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ResolveError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ResolveError

Source§

impl Error for ResolveError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for ResolveError

Source§

fn eq(&self, other: &ResolveError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ResolveError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.