# Displaying types in errors: absolute path or same as I wrote them?

**URL:** <https://internals.rust-lang.org/t/displaying-types-in-errors-absolute-path-or-same-as-i-wrote-them/5745>\
**Category:** Uncategorized\
**Created:** [August 10, 2017, 3:10pm UTC](https://internals.rust-lang.org/t/displaying-types-in-errors-absolute-path-or-same-as-i-wrote-them/5745 "2017-08-10T15:10:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [August 10, 2017, 3:10pm UTC](https://internals.rust-lang.org/t/displaying-types-in-errors-absolute-path-or-same-as-i-wrote-them/5745/1 "2017-08-10T15:10:06Z")

</div>

If I use a type such as `Vec<Option<_>>` the error message about it will print it as `std::vec::Vec<std::option::Option<_>>`.

Is that a bug or a feature?

Personally, I don’t like how long and syntactically noisy the messages are. I never write `Option` as `std::option::Option`, so in this case the message adds a detail that I don’t actually care about.

I suppose there’s a trade-off between being very, very clear about types and using names as written in the code/familar to users.

Would it be desirable to write types in errors in the context of the file they’re in? Taking into account prelude, `use`/`type`, etc?

---

<div class="post-metadata">

**Author:** ![oli-obk](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/oli-obk/32/3168_2.png) [@oli-obk](https://internals.rust-lang.org/u/oli-obk)\
**Post date:** [August 10, 2017, 3:12pm UTC](https://internals.rust-lang.org/t/displaying-types-in-errors-absolute-path-or-same-as-i-wrote-them/5745/2 "2017-08-10T15:12:42Z")

</div>

I think that’s just a case of “noone got around to implementing it”. This would certainly help make error messages more readable imo.

---

<div class="post-metadata">

**Author:** ![ahmedcharles](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ahmedcharles/32/4041_2.png) [@ahmedcharles](https://internals.rust-lang.org/u/ahmedcharles)\
**Post date:** [August 10, 2017, 7:34pm UTC](https://internals.rust-lang.org/t/displaying-types-in-errors-absolute-path-or-same-as-i-wrote-them/5745/3 "2017-08-10T19:34:49Z")

</div>

The issue is that while this works for `Option`, it hardly works for `Result`. If you get an error that says: Expected `Result`, but found `Result`, rather than: Expected `std::io::Result`, but found `std::result::Result`, that would be more confusing.

Anyways, it’s a non-trivial problem.

---

<div class="post-metadata">

**Author:** ![zackw](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/zackw/32/2071_2.png) [@zackw](https://internals.rust-lang.org/u/zackw)\
**Post date:** [August 10, 2017, 7:46pm UTC](https://internals.rust-lang.org/t/displaying-types-in-errors-absolute-path-or-same-as-i-wrote-them/5745/4 "2017-08-10T19:46:41Z")

</div>

Heuristic: prepend module names until the two strings are not the same? That would give you Expected `io::Result`, but found `result::Result`, which is perfect (IMO). It doesn’t help when you have `foo` and `bar` crates that both provide `x::y::z::Type`, but that is hopefully rare, and it doesn’t do _worse_ then.

---

<div class="post-metadata">

**Author:** ![ekuber](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ekuber/32/1646_2.png) [@ekuber](https://internals.rust-lang.org/u/ekuber)\
**Post date:** [August 10, 2017, 8:10pm UTC](https://internals.rust-lang.org/t/displaying-types-in-errors-absolute-path-or-same-as-i-wrote-them/5745/5 "2017-08-10T20:10:51Z")

</div>

> [@kornel](#):
>
> Is that a bug or a feature?

> [@ker](#):
>
> I think that’s just a case of “noone got around to implementing it”. This would certainly help make error messages more readable imo.

Good old [#21934](https://github.com/rust-lang/rust/issues/21934). I've been wondering if adding a `HashMap` of local bindings to `FnCtxt` would be an appropriate solution to this.

> [@ahmedcharles](#):
>
> The issue is that while this works for Option, it hardly works for Result. If you get an error that says: Expected Result, but found Result, rather than: Expected std::io::Result, but found std::result::Result, that would be more confusing.

The solution to that problem is to keep track of local bindings in every context. You will never have both `std::io::Result` and `std::result::Result` available as `Result` in the same scope. If neither are in scope, the compiler would use the fully qualified path.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:28am UTC](https://internals.rust-lang.org/t/displaying-types-in-errors-absolute-path-or-same-as-i-wrote-them/5745/6 "2019-03-25T08:28:54Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
