Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler suggested <unnamed> in a use #43189

Closed
moonheart08 opened this issue Jul 12, 2017 · 2 comments
Closed

Compiler suggested <unnamed> in a use #43189

moonheart08 opened this issue Jul 12, 2017 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@moonheart08
Copy link
Contributor

moonheart08 commented Jul 12, 2017

error[E0599]: no method named `size` found for type `glutin_window::GlutinWindow` in the current sco
pe
  --> src/grenderer/game.rs:28:39
   |
28 |             let tilespace_y = (window.size().height / 4) * 3;
   |                                       ^^^^
   |
   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
           candidate #1: `use piston::<unnamed>::Window;`

Attempting to use that suggustion causes a compiler error itself, and the correct use statement is use piston::window::Window;

I dont know how to reproduce this behavior, but it can likely be found by looking in the piston_window crate's source code.

@kennytm
Copy link
Member

kennytm commented Jul 12, 2017

Looks like it's because piston::window is an extern crate. Simplified:

#!/bin/sh
set -ex
rm -rf a b c
cargo new --lib a
cargo new --lib b
cargo new --bin c
echo 'pub trait A { fn a(&self) {} } impl A for () {}' > a/src/lib.rs
echo 'a = { path = "../a" }' >> b/Cargo.toml
echo 'pub extern crate a;' > b/src/lib.rs
echo 'b = { path = "../b" }' >> c/Cargo.toml
echo 'extern crate b; fn main() { ().a(); }' > c/src/main.rs
cargo build --manifest-path c/Cargo.toml

Running this gives the error:

+ rm -rf a b c
+ cargo new --lib a
     Created library `a` project
+ cargo new --lib b
     Created library `b` project
+ cargo new --bin c
     Created binary (application) `c` project
+ echo 'pub trait A { fn a(&self) {} } impl A for () {}'
+ echo 'a = { path = "../a" }'
+ echo 'pub extern crate a;'
+ echo 'b = { path = "../b" }'
+ echo 'extern crate b; fn main() { ().a(); }'
+ cargo build --manifest-path c/Cargo.toml
   Compiling a v0.1.0 (file:///Users/kennytm/Downloads/a/a)
   Compiling b v0.1.0 (file:///Users/kennytm/Downloads/a/b)
   Compiling c v0.1.0 (file:///Users/kennytm/Downloads/a/c)
error[E0599]: no method named `a` found for type `()` in the current scope
 --> c/src/main.rs:1:32
  |
1 | extern crate b; fn main() { ().a(); }
  |                                ^
  |
  = help: items from traits can only be used if the trait is in scope
  = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
          candidate #1: `use b::<unnamed>::A;`

error: aborting due to previous error

error: Could not compile `c`.

To learn more, run the command again with --verbose.

(Here crate a is pistoncore-window, crate b is piston, and crate c is the user's crate.)

@sanxiyn sanxiyn added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 13, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
bors added a commit that referenced this issue May 30, 2018
Use crate name for reexported `extern crate` paths

Fix #43189.
@moonheart08
Copy link
Contributor Author

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants