Skip to content

Path in error message is neither public name nor internal name of type #56943

Closed
@dtolnay

Description

@dtolnay

dep/src/lib.rs

pub struct S;
mod m { pub struct S; }
pub use crate::m::S as S2;

repro/src/lib.rs

extern crate dep;
fn f() {
    let _: dep::S = dep::S2;
}

The error message refers to both types as dep::S even though one is dep::S2. I am reporting this as distinct from #21934 because dep::S isn't even the internal name of the other struct. That would be dep::m::S. Printing dep::S2 would be ideal (as tracked in #21934) but printing dep::m::S would still be a big improvement.

error[E0308]: mismatched types
 --> src/lib.rs:4:21
  |
4 |     let _: dep::S = dep::S2;
  |                     ^^^^^^^ expected struct `dep::S`, found a different struct `dep::S`
  |
  = note: expected type `dep::S` (struct `dep::S`)
             found type `dep::S` (struct `dep::S`)

Same thing in script form:

#!/bin/bash

cargo new --lib dep
cargo new --lib repro

echo >dep/src/lib.rs '
pub struct S;
mod m { pub struct S; }
pub use crate::m::S as S2;
'

echo >repro/src/lib.rs '
extern crate dep;
fn f() {
    let _: dep::S = dep::S2;
}
'

echo >>repro/Cargo.toml 'dep = { path = "../dep" }'

# rustc 1.33.0-nightly (adbfec229 2018-12-17)
cargo +nightly check --manifest-path repro/Cargo.toml

Mentioning @dgreid who hit this today. The real case involves multiple Error types across different modules, each re-exported from lib.rs under a unique name.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions