Rust
E0255 Import Name Conflict Fix
A use declaration binds a name in your module, and a local item with the same name in the same namespace cannot take that name too - that collision is E0255. This guide works the collision against a struct, a function, a constant, a static, an alias, a trait, an enum, and a union, matches each one to its repair, and separates the neighboring duplicate-name errors E0252, E0428, and E0659.
Written November 29, 2026 · Tested with Rust 1.99.1 · 23 min read
- The rule underneath: one name per namespace per module
- How to read the diagnostic
- The first failure: an import against a local struct
- The second failure: an import against a local function
Written November 29, 2026
Tested with Rust 1.99.1
What this guide is
Error E0255 is a name claimed twice in one module where one of the claims is an import. The error codes index states it in one line - "You can't import a value whose name is the same as another value defined in the module" - and its erroneous example imports bar::foo into a module that also defines its own fn foo, repaired in its working examples by aliasing the import, use bar::foo as bar_foo;, or by deleting the import and referring to the item through its parent, bar::foo().
A use declaration does not merely abbreviate a path at its use sites; it creates a binding - it puts the imported name itself into the module, in every namespace the imported item occupies. A local item that then tries to take the same name in one of those namespaces has nowhere to go: within a namespace, a module's name points at exactly one thing. The defect is never that either item is wrong on its own. Both items in every program in this guide are ordinary, working items; the collision between their names is the whole error.
The forms in this guide each reproduce E0255 with a small, complete program: an imported name against a local struct, a function, a constant, a static, a type alias, a trait, an enum, and a union, each followed by its repair. In each failing program the imported item is a tuple struct from a helper module, so the import carries a type and a constructor at once, and main uses the imported side - that is what keeps each transcript to the single E0255 diagnostic. The traps then cover the shapes that sit next to this error: two imports of one name, two local definitions of one name, two glob imports used ambiguously, and the glob import that raises no error at all.
Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.
The rule underneath: one name per namespace per module
The Rust Reference explains why some same-name pairs collide and others do not: a namespace is "a logical grouping of declared names", names "are segregated into separate namespaces based on the kind of entity the name refers to", and namespaces "allow the occurrence of a name in one namespace to not conflict with the same name in another namespace". Its type namespace holds module, struct, union, enum, trait, and type alias declarations; its value namespace holds function, constant, and static declarations, together with struct and enum variant constructors; a third, macro namespace holds macro_rules declarations and macros.
The use declarations chapter supplies the import half of the rule: a use declaration "creates one or more local name bindings synonymous with some other path", and "use will create bindings for all namespaces from the imported entities". That last clause is why the imported item in this guide is a tuple struct: importing it binds its name in the type namespace (the struct type) and in the value namespace (its constructor) at the same time, so a local item of either kind can collide with it. The same chapter gives the escape the compiler itself suggests: "The as keyword can be used to change the name of an imported entity" - use p::q::r as x; binds the item under x instead, and the original name stays free for the local item.
The Rust Book frames the same mechanism from the writer's side: a use brings a path into scope so the item can be named without its full path, and bringing a function's parent module into scope - rather than the function itself - is the idiomatic form for functions, precisely because it keeps clear which names are locally defined. E0255 is the compiler enforcing the boundary that advice points at: an imported binding and a local definition are different kinds of claim on a module's names, and one name in one namespace can only be claimed once.
Two consequences follow. First, the collision is per namespace, not per spelling: the note under every diagnostic in this guide names the namespace that overflowed - "must be defined only once in the type namespace of this module" or "in the value namespace" - and a pair that shares a spelling but lives in different namespaces is legal. Second, every repair works by separating the two claims: rename one of them (the import with as, or the local item), or withdraw the import's claim entirely and reach the imported item through its parent module's path instead.
How to read the diagnostic
The header is "the name Widget is defined multiple times", with the code E0255, naming whichever name collided. The diagnostic carries two labels. The first underlines the imported name inside the use line and reads "previous import of the type Widget here" - the wording after "import of the" names what was imported: the value, the type, the trait, or the module. The second underlines the local item's name and reads "Widget redefined here". Below the labels, a note states the rule for the namespace in question - "Widget must be defined only once in the type namespace of this module" - and a help block offers the as repair, spelled with a placeholder rename: use bar::Widget as OtherWidget; for a type, use bar::foo as other_foo; for a value. The placeholder is mechanical - it prefixes or renames to a generic variant of the same name - so treat it as a pointer to the mechanism, not as the name to actually choose; a rename that says where the item came from, such as the ImportedWidget form the repairs in this guide use, reads better in real code.
One diagnostic detail is worth knowing before the traps: this help block is part of what separates E0255 from its nearest neighbor. When both claims on a name are local definitions, the error is E0428, the header and note are identical in form, and there is no help block - there is no import to rename. The traps section works that pair side by side.
The first failure: an import against a local struct
This is the shape behind most real sightings of this error - a module grows its own type with the same name as a type it imports, the way a crate defines its own error type under a name it also imports from the standard library. The local item here is a struct with a named field, and the imported item is a tuple struct of the same name in a helper module:
use bar::Widget;
struct Widget { x: i32 }
mod bar { pub struct Widget(pub i32); }
fn main() { let w = Widget(4); println!("{}", w.0); }
error[E0255]: the name `Widget` is defined multiple times
--> a1.rs:2:1
|
1 | use bar::Widget;
| ----------- previous import of the type `Widget` here
2 | struct Widget { x: i32 }
| ^^^^^^^^^^^^^ `Widget` redefined here
|
= note: `Widget` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
1 | use bar::Widget as OtherWidget;
| ++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0255`.
The first label calls the import "previous import of the type Widget", because a struct lives in the type namespace, and the note names that namespace. main constructs Widget(4) - the imported tuple struct's constructor - and prints its field; none of that is reached, because the module's names fail to resolve first. The repair renames the import with as, keeping both types, and main now constructs each one under its own name:
use bar::Widget as ImportedWidget;
struct Widget { x: i32 }
mod bar { pub struct Widget(pub i32); }
fn main() { let w = Widget { x: 4 }; let iw = ImportedWidget(9); println!("{} {}", w.x, iw.0); }
4 9
The output is 4 9: the local struct's field, then the imported struct's field. Nothing else changed - the two items were never the problem, only the shared name was.
The second failure: an import against a local function
A function lives in the value namespace, so the imported item collides with it through its constructor - a tuple struct's constructor is a value with the struct's name. This program defines a local function Pair and imports a tuple struct Pair; a helper function's parameter is annotated with the imported type, which is the imported side in use:
use bar::Pair;
fn Pair(x: i32) -> i32 { x }
mod bar { pub struct Pair(pub i32); }
fn show(p: Pair) -> i32 { p.0 }
fn main() { println!("{}", show(bar::Pair(4))); }
error[E0255]: the name `Pair` is defined multiple times
--> a2.rs:2:1
|
1 | use bar::Pair;
| --------- previous import of the value `Pair` here
2 | fn Pair(x: i32) -> i32 { x }
| ^^^^^^^^^^^^^^^^^^^^^^ `Pair` redefined here
|
= note: `Pair` must be defined only once in the value namespace of this module
help: you can use `as` to change the binding name of the import
|
1 | use bar::Pair as OtherPair;
| ++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0255`.
The first label now reads "previous import of the value Pair here" and the note names the value namespace: the claim that overflowed is the constructor's, not the type's. The repair here renames the local item instead - the function takes the conventional snake-case name pair, the import keeps Pair, and both stay callable:
use bar::Pair;
fn pair(x: i32) -> i32 { x }
mod bar { pub struct Pair(pub i32); }
fn show(p: Pair) -> i32 { p.0 }
fn main() { println!("{} {}", pair(4), show(Pair(9))); }
4 9
The output is 4 9: the local function's return, then the imported struct's field read through the helper. Renaming either side is a complete repair; which side to rename is a naming decision, not a compiler requirement - rename the one whose name matters less at its use sites.
The same error on a constant and a static
Constants and statics are value-namespace items, like functions, so each collides with an imported tuple struct through its constructor in exactly the function's form. A constant:
use bar::Value;
const Value: i32 = 4;
mod bar { pub struct Value(pub i32); }
fn show(v: Value) -> i32 { v.0 }
fn main() { println!("{}", show(bar::Value(9))); }
error[E0255]: the name `Value` is defined multiple times
--> a3.rs:2:1
|
1 | use bar::Value;
| ---------- previous import of the value `Value` here
2 | const Value: i32 = 4;
| ^^^^^^^^^^^^^^^^^^^^^ `Value` redefined here
|
= note: `Value` must be defined only once in the value namespace of this module
help: you can use `as` to change the binding name of the import
|
1 | use bar::Value as OtherValue;
| +++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0255`.
The repair renames the local constant to the conventional upper-case form, which also frees the name:
use bar::Value;
const VALUE: i32 = 4;
mod bar { pub struct Value(pub i32); }
fn show(v: Value) -> i32 { v.0 }
fn main() { println!("{} {}", VALUE, show(Value(9))); }
4 9
The output is 4 9: the constant, then the imported struct's field. A static draws the identical diagnostic - the labels, note, and help are the same shape, with the static's line underlined as the redefinition:
use bar::Value;
static Value: i32 = 4;
mod bar { pub struct Value(pub i32); }
fn show(v: Value) -> i32 { v.0 }
fn main() { println!("{}", show(bar::Value(9))); }
error[E0255]: the name `Value` is defined multiple times
--> a4.rs:2:1
|
1 | use bar::Value;
| ---------- previous import of the value `Value` here
2 | static Value: i32 = 4;
| ^^^^^^^^^^^^^^^^^^^^^^ `Value` redefined here
|
= note: `Value` must be defined only once in the value namespace of this module
help: you can use `as` to change the binding name of the import
|
1 | use bar::Value as OtherValue;
| +++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0255`.
use bar::Value;
static VALUE: i32 = 4;
mod bar { pub struct Value(pub i32); }
fn show(v: Value) -> i32 { v.0 }
fn main() { println!("{} {}", VALUE, show(Value(9))); }
4 9
The output is 4 9, the static's value and the imported field. In both programs the imported type is in use as the helper's parameter type, and main reaches the imported side through bar::Value(9) - the collision itself is in the value namespace, between the imported constructor and the local constant or static.
The same error on a type alias, a trait, an enum, and a union
The remaining type-namespace items all draw the identical diagnostic in the struct's form, with "previous import of the type" in the first label - the label names the imported item's kind, and the imported item in each of these programs is the tuple struct, so all four read "the type". For each of them the repair is the struct's repair, renaming the import with as. A type alias names a type but defines no constructor, so it collides in the type namespace only:
use bar::Pair;
type Pair = i32;
mod bar { pub struct Pair(pub i32); }
fn main() { let p = Pair(4); println!("{}", p.0); }
error[E0255]: the name `Pair` is defined multiple times
--> a5.rs:2:1
|
1 | use bar::Pair;
| --------- previous import of the type `Pair` here
2 | type Pair = i32;
| ^^^^^^^^^^^^^^^^ `Pair` redefined here
|
= note: `Pair` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
1 | use bar::Pair as OtherPair;
| ++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0255`.
use bar::Pair as ImportedPair;
type Pair = i32;
mod bar { pub struct Pair(pub i32); }
fn main() { let n: Pair = 4; let p = ImportedPair(9); println!("{} {}", n, p.0); }
4 9
The output is 4 9: a value held under the alias, then the imported struct's field. A trait:
use bar::Greeter;
trait Greeter { fn value(&self) -> i32; }
mod bar { pub struct Greeter(pub i32); }
fn main() { let g = Greeter(4); println!("{}", g.0); }
error[E0255]: the name `Greeter` is defined multiple times
--> a6.rs:2:1
|
1 | use bar::Greeter;
| ------------ previous import of the type `Greeter` here
2 | trait Greeter { fn value(&self) -> i32; }
| ^^^^^^^^^^^^^ `Greeter` redefined here
|
= note: `Greeter` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
1 | use bar::Greeter as OtherGreeter;
| +++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0255`.
use bar::Greeter as ImportedGreeter;
trait Greeter { fn value(&self) -> i32; }
mod bar { pub struct Greeter(pub i32); }
struct Unit;
impl Greeter for Unit { fn value(&self) -> i32 { 4 } }
fn main() { let g = ImportedGreeter(9); println!("{} {}", Unit.value(), g.0); }
4 9
The output is 4 9: the local trait's method value from its implementation, then the imported struct's field. An enum:
use bar::Shape;
enum Shape { Square, Circle }
mod bar { pub struct Shape(pub i32); }
fn main() { let s = Shape(4); println!("{}", s.0); }
error[E0255]: the name `Shape` is defined multiple times
--> a7.rs:2:1
|
1 | use bar::Shape;
| ---------- previous import of the type `Shape` here
2 | enum Shape { Square, Circle }
| ^^^^^^^^^^ `Shape` redefined here
|
= note: `Shape` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
1 | use bar::Shape as OtherShape;
| +++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0255`.
use bar::Shape as ImportedShape;
enum Shape { Square, Circle }
mod bar { pub struct Shape(pub i32); }
fn pick(s: Shape) -> i32 { match s { Shape::Square => 4, Shape::Circle => 9 } }
fn main() { let s = ImportedShape(9); println!("{} {} {}", pick(Shape::Square), pick(Shape::Circle), s.0); }
4 9 9
The output is 4 9 9: the two local variants' values through the matching helper, then the imported struct's field. And a union, the last of the type-namespace definition kinds:
use bar::Helper;
union Helper { x: i32 }
mod bar { pub struct Helper(pub i32); }
fn main() { let h = Helper(4); println!("{}", h.0); }
error[E0255]: the name `Helper` is defined multiple times
--> a8.rs:2:1
|
1 | use bar::Helper;
| ----------- previous import of the type `Helper` here
2 | union Helper { x: i32 }
| ^^^^^^^^^^^^ `Helper` redefined here
|
= note: `Helper` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
1 | use bar::Helper as OtherHelper;
| ++++++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0255`.
use bar::Helper as ImportedHelper;
union Helper { x: i32 }
mod bar { pub struct Helper(pub i32); }
fn main() { let h = Helper { x: 4 }; let ih = ImportedHelper(9); println!("{} {}", unsafe { h.x }, ih.0); }
4 9
The output is 4 9: the local union's field read back, then the imported struct's field. Across all four, the pattern from the struct case holds unchanged - the namespace in the note is the type namespace, the help offers the as rename, and renaming the import separates the claims without touching either item's definition.
The traps
Two imports of the same name are E0252, not E0255. Neither claim here is a local item - both are use lines:
use bar::Pair;
use baz::Pair;
fn show(p: Pair) -> i32 { p.0 }
mod bar { pub struct Pair(pub i32); }
mod baz { pub struct Pair(pub i32); }
fn main() { println!("{}", show(bar::Pair(4))); }
error[E0252]: the name `Pair` is defined multiple times
--> n1.rs:2:5
|
1 | use bar::Pair;
| --------- previous import of the type `Pair` here
2 | use baz::Pair;
| ^^^^^^^^^ `Pair` reimported here
|
= note: `Pair` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
2 | use baz::Pair as OtherPair;
| ++++++++++++
warning: unused import: `baz::Pair`
--> n1.rs:2:5
|
2 | use baz::Pair;
| ^^^^^^^^^
|
= note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0252`.
The second label reads "Pair reimported here" instead of "redefined here", the code is E0252, and the transcript also carries an unused-import warning for the second import, because the bare name in the annotation never resolves to it. The repair is the same as mechanism - the alias-repaired version of this pair is the struct repair's move applied to one import - but the code tells you where to look: E0252 means import against import, E0255 means import against local item.
Two local definitions of the same name are E0428, not E0255. No import is involved at all:
fn foo() -> i32 { 4 }
fn foo() -> i32 { 9 }
fn main() { println!("{}", foo()); }
error[E0428]: the name `foo` is defined multiple times
--> n2.rs:2:1
|
1 | fn foo() -> i32 { 4 }
| --------------- previous definition of the value `foo` here
2 | fn foo() -> i32 { 9 }
| ^^^^^^^^^^^^^^^ `foo` redefined here
|
= note: `foo` must be defined only once in the value namespace of this module
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0428`.
The header and the note are the same in form - "the name foo is defined multiple times", "must be defined only once in the value namespace of this module" - but the first label reads "previous definition of the value foo here", and there is no help block, because there is no import for as to rename. The repair is to rename or delete one of the two definitions; aliasing has nothing to attach to.
Two glob imports that both bring in a name raise no error at the imports - the error arrives at the use site, as E0659. This program imports everything from two modules that each define a foo, plus one distinct function each, and calls all three:
use bar::*;
use baz::*;
fn main() { println!("{} {} {}", foo(), apple(), banana()); }
mod bar { pub fn foo() -> i32 { 9 } pub fn apple() -> i32 { 1 } }
mod baz { pub fn foo() -> i32 { 10 } pub fn banana() -> i32 { 2 } }
error[E0659]: `foo` is ambiguous
--> n3.rs:3:34
|
3 | fn main() { println!("{} {} {}", foo(), apple(), banana()); }
| ^^^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `foo` could refer to the function imported here
--> n3.rs:1:5
|
1 | use bar::*;
| ^^^^^^
= help: consider adding an explicit import of `foo` to disambiguate
note: `foo` could also refer to the function imported here
--> n3.rs:2:5
|
2 | use baz::*;
| ^^^^^^
= help: consider adding an explicit import of `foo` to disambiguate
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0659`.
The diagnostic is "foo is ambiguous", pointed at the call, with a note for each glob import the name could have come from and a suggestion to add an explicit import to disambiguate. The other two calls are not the problem - apple and banana each arrive through exactly one glob. Adding an explicit use for foo from one of the two modules, or calling it qualified as bar::foo(), resolves the ambiguity; renaming with as is not the tool here, because neither glob bound the name on its own.
A glob import against a local item is not an error at all. A local definition shadows a glob import in the same namespace - the use declarations chapter states it directly: "Items and named imports are allowed to shadow names from glob imports in the same namespace." So this program, the glob cousin of the first failure's family, compiles:
use bar::*;
fn foo() -> i32 { 4 }
mod bar { pub fn foo() -> i32 { 9 } pub fn nine() -> i32 { 9 } }
fn main() { println!("{} {} {}", foo(), nine(), bar::foo()); }
4 9 9
The output is 4 9 9: the local foo() wins the bare name and returns 4, the glob still supplies nine(), and the imported foo remains reachable through its parent as bar::foo(). If a collision you expected does not appear, check whether one side arrived through a glob - explicit imports collide with E0255, glob imports defer.
That qualified reach is also the error index's second repair, and it works as a repair for E0255 itself: delete the import entirely and refer to the imported item through its parent module everywhere it is used. Applied to the struct case:
struct Widget { x: i32 }
mod bar { pub struct Widget(pub i32); }
fn show(w: bar::Widget) -> i32 { w.0 }
fn main() { let w = Widget { x: 4 }; println!("{} {}", w.x, show(bar::Widget(9))); }
4 9
The output is 4 9: the local struct's field, then the imported struct's field read through a helper whose parameter is annotated bar::Widget. No name is bound, so no name can collide - the cost is the longer path at every use site, which is why this repair suits items used in one or two places, while as suits items used throughout the module.
Fixes in reach order
When E0255 appears, work the collision in this order. First, read the two labels: the first names the import and the kind imported, the second names the local item, and the note names the namespace - that tells you exactly which two claims collided. Second, if both items are genuinely needed in this module, rename the import with as, choosing a name that says where it came from rather than the compiler's placeholder - this is the repair that changes the least code. Third, if the local item's name is the negotiable one - an internal helper function, a constant not yet in its conventional form - rename the local item instead and keep the import. Fourth, if the imported item is used in only one or two places, delete the import and refer to it through its parent module's path. Last, if the code is not E0255 at all, switch playbooks: E0252 is import against import (rename one import), E0428 is local against local (rename or delete one definition), E0659 is glob against glob at the use site (add an explicit import or qualify the call), and a glob against a local item needs no fix because the local item shadows it.
Decision summary
E0255, "the name is defined multiple times", is one name claimed twice in one namespace of one module where one claim is a use import and the other is a local item - a struct, a function, a constant, a static, a type alias, a trait, an enum, or a union. The diagnostic labels the previous import and the redefinition, notes the namespace that overflowed - type namespace for structs, aliases, traits, enums, unions, and modules; value namespace for functions, constants, statics, and constructors - and offers an as rename in its help. The repair separates the claims: rename the import with as, rename the local item, or delete the import and reach the item through its parent module. Three neighbors are not this error: two imports of one name are E0252 ("reimported here"), two local definitions are E0428 (same header, no help block), and two glob imports collide only at the use site as E0659 - while a glob import against a local item is no error, because the local item shadows the glob.
Checklist
- Every name in a module is claimed once per namespace - an explicit import and a local item never share a name in the type or the value namespace.
- A renamed import uses a name that says where the item came from, not the compiler's
Other-prefixed placeholder. - A tuple struct import is remembered as two claims - its type and its constructor - so it can collide with a local function, constant, or static as well as with a local type.
- An imported item used in only a few places is reached through its parent module's path instead of being imported under a colliding name.
- E0252, E0428, and E0659 are told apart from E0255 by the labels: "reimported here", "previous definition" with no help block, and an ambiguous use site.
- A name arriving through a glob import is not expected to collide - a local item or a named import shadows it.
Related guides on this site
- Fix Rust E0599 "no method named" — Import the Trait, Fix the Receiver, or Use the Current Name
- Name Already Used for Generic E0403 Fix
- E0415 Duplicate Parameter Name Fix
- E0659 Ambiguous Name Fix
Sources
- Rust error codes index, E0255 - you can't import a value whose name is the same as another value defined in the module, its erroneous
use bar::foo;against a localfn foo, and its two working repairs: aliasing the import withasand referring to the item through its parent. - The Rust Reference, Use declarations - a use declaration creates local name bindings synonymous with another path, creates bindings for all namespaces of the imported entities, can change an imported entity's name with
as, and items and named imports shadow names from glob imports in the same namespace. - The Rust Reference, Namespaces - a namespace is a logical grouping of declared names, names in different namespaces do not conflict, and the type, value, and macro namespaces' member kinds.
- The Rust Programming Language, Bringing Paths into Scope with the use Keyword -
usebrings a path into scope to shorten item references, and bringing a function's parent module into scope is the idiomatic form because it keeps clear which names are locally defined.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.