module-linker icon indicating copy to clipboard operation
module-linker copied to clipboard

Fails on some rust imports

Open Boscop opened this issue 8 years ago • 12 comments

E.g.: use database_url::extract_database_url;

Boscop avatar Nov 08 '17 13:11 Boscop

Chrome or Firefox?

fiatjaf avatar Nov 08 '17 16:11 fiatjaf

Chrome at least.

Boscop avatar Nov 08 '17 18:11 Boscop

I believe this has been fixed on the newest versions, which are not published on Chrome yet.

I had to change the permissions for Firefox, however, because Chrome automatically grants some permissions which we weren't asking and Firefox doesn't -- which made the extension don't work unless we've changed that. Now if I publish the latest releases to Chrome it will prompt all users to accept the new permissions, which is very annoying.

Since I'm working on a rewrite of some parts which will change the permissions anyway, I thought I would delay publishing the new Chrome versions until then, but it is taking more time than I had planned. So, what should I do?

fiatjaf avatar Nov 08 '17 18:11 fiatjaf

It's not that important, I can wait :) (#27 is my main issue atm.)

Boscop avatar Nov 09 '17 14:11 Boscop

The rewrite I mentioned earlier was completed today, but it was so much easier than i was imagining that I'm afraid I may have commited stupid mistakes, please let me know if I did.

(And please reopen this issue if it is not solved.)

fiatjaf avatar Dec 06 '17 18:12 fiatjaf

Is this fixed in the latest version for Chrome? I'm still seeing it in 2.0.2.

Here's where I first saw the issue in the exa source:

use std::io::{stderr, Write, Result as IOResult};

Made a few permutations of different ways it fails here, including if the name is in the comments.

Antelope13 avatar Dec 22 '17 18:12 Antelope13

Not the same bug. But I think I know how to fix this.

fiatjaf avatar Dec 22 '17 19:12 fiatjaf

Nice, thanks for taking a look. I really love this extension!

Antelope13 avatar Dec 23 '17 17:12 Antelope13

Btw, Rust is getting nested group imports: https://github.com/rust-lang/rfcs/pull/2128

Boscop avatar Dec 23 '17 19:12 Boscop

Such complexity. Much problem.

Is that only for local/relative modules, @Boscop, or for external crates also? use is just for local modules, right? And std is a module local to everywhere?

What is exactly a crate, a module, whatever?

fiatjaf avatar Dec 23 '17 20:12 fiatjaf

Basically, crates are compilation units (either lib or bin) and when you do extern crate foo; it also imports foo into the current scope, so you can use symbols from foo like foo::bar() but if you are in another scope that's not a sub-scope (e.g. in another rust file), you have to import foo first with use foo; before you can use foo::bar(). Every file creates a module, but you can also create new modules within a module by writing mod asd { .. }. But this module doesn't inherit imports from the parent module! std is implicitly imported in every module. If you write use foo; in a rust file it will look for foo in the crate root (main.rs for bins or lib.rs for libs), also for use {foo, bar};. This foo could have been imported by extern crate foo; or it could be a module (mod foo; or mod foo {...}) or any symbol defined in main.rs/lib.rs. So basically extern crate foo; is similar to mod foo;, in that it makes 'foo' available in the crate root. I hope it makes sense :)

The new nested syntax is just syntactic sugar, so you can write many imports from different submodules of a module/crate in fewer lines.

use syntax::ast::{self, *}; means use syntax::ast; use syntax::ast::*;

Boscop avatar Dec 26 '17 06:12 Boscop

Someone wrote a guide:

https://dev.to/hertz4/rust-module-essentials-12oi

Boscop avatar Jan 05 '18 01:01 Boscop