question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect reference resolution when crate contains a module with the same name as function being imported

See original GitHub issue

In the below example, the polygon function and the rectangle function are resolved incorrectly as the polygon.rs module and the rectangle.rs module respectively.

Cargo.toml:

[package]
name = "rust_test"
version = "0.1.0"
authors = ["johnthagen <johnthagen@gmail.com>"]

[dependencies]
piston_window = "0.52.0"

main.rs:

extern crate piston_window;

use piston_window::{
    clear,  // Correctly resolved as function.
    PistonWindow,
    polygon, // INCORRECTLY resolved as module polygon.rs (should be function polygon)
    rectangle, // INCORRECTLY resolved as module rectangle.rs (should be function rectangle)
    WindowSettings
};

const POLYGON: &'static [[f64; 2]] = &[
    [0.0, -1.0 * 16.0 / 2.0],
    [20.0, 0.0],
    [0.0, 16.0 / 2.0]
];

fn main() {
    let title = "Hello Piston! (press any key to enter inner loop)";
    let mut window: PistonWindow = WindowSettings::new(title, [640, 480])
        .exit_on_esc(true)
        .build()
        .unwrap_or_else(|error| { panic!("Failed to build PistonWindow: {}", error) });

    while let Some(event) = window.next() {
        const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 1.0];
        const DARK_GREEN: [f32; 4] = [0.0, 0.5, 0.0, 1.0];

        window.draw_2d(&event,
                       |context, graphics| {
                           clear(WHITE, graphics);
                           rectangle(DARK_GREEN,
                                     [50.0, 50.0, 100.0, 100.0],
                                     context.transform,
                                     graphics);
                           polygon(DARK_GREEN,
                                   POLYGON,
                                   context.transform,
                                   graphics);
                       });
    }
}

Tested in PyCharm 2016.2.3, Windows 10 x64, plugin v0.1.0.981.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
matkladcommented, Oct 3, 2016

Simplified example:

mod m {
    pub mod foo { pub fn bar() {} }
    pub fn foo() {}
}

fn main() {
    use self::m::foo; // <- this should resolve to both a fn and a mod.

    foo(); // <- this should resolve to fn
    foo::bar(); // <- this should resolve to mod. 
}
1reaction
matkladcommented, Oct 28, 2016

Should be fixed now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Name resolution question in macros - help - The Rust Programming ...
I'm trying to use the unicode-segmentation crate in some macros I'm writing. I've added "unicode-segmentation" = "version = "^0.1.2" to my Cargo.toml file....
Read more >
How do I import from a sibling module? - rust - Stack Overflow
To import a module on the same level, do the following: ... directly both give // the same result, because they refer to...
Read more >
1560-name-resolution - The Rust RFC Book
Internally, name resolution will be split into two parts - import resolution and name lookup. Import resolution is moved forward in time to...
Read more >
Crates and Modules - The Rust Programming Language - MIT
Rust has two distinct terms that relate to the module system: 'crate' and 'module'. A crate is synonymous with a 'library' or 'package'...
Read more >
Unable to resolve reference of Custom Dataweave Function ...
This error can occur while using the custom function in the main DW if the custom module/ Dataweave script is not properly imported....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found