These are chat archives for rust-lang/rust

9th
May 2018
A K Fischer
@autokorrelationsfunktion
May 09 2018 09:15
Hi all, I am writing a derive macro that I need to debug. I am trying to expand, but get an error[E0464]: multiple matching crates for lazy_static. It looks like my toolchain has two lazy_static rlibs. How do I fix this?
trsh
@trsh
May 09 2018 10:38
Hi. I fallowed this tut https://blog.jfo.click/calling-a-c-function-from-rust/, and in end result Im still getting "note: /usr/bin/ld: cannot find -ldoubler.o". What could be the catch?
P.S. the doubler.o is definitely there
Andrey Lesnikov
@ozkriff
May 09 2018 10:43
@autokorrelationsfunktion update your Cargo.lock or check it to find which dependency you need to downgrade
A K Fischer
@autokorrelationsfunktion
May 09 2018 10:44
@ozkriff downgrade? I did have two dependencies that used two different versions, but I updated them and the Cargo.lock only requires the current version now
Andrey Lesnikov
@ozkriff
May 09 2018 10:45
Hmm, that's strange. Can you share your Cargo.lock (using some pastebin)?
trsh
@trsh
May 09 2018 10:46
Pls help :)
A K Fischer
@autokorrelationsfunktion
May 09 2018 10:48
Andrey Lesnikov
@ozkriff
May 09 2018 10:51
Yep, looks fine. Can you show the exact command and error message?
@trsh I'm not sure what's the problem, but it's usually done with build.rs and cc crate in practice, like here - https://github.com/alexcrichton/rust-ffi-examples/tree/master/rust-to-c
A K Fischer
@autokorrelationsfunktion
May 09 2018 10:55
Andrey Lesnikov
@ozkriff
May 09 2018 10:57
A K Fischer
@autokorrelationsfunktion
May 09 2018 10:58
I read that too. Unfortunately, it sounds to me as if nobody knows what's going on...
trsh
@trsh
May 09 2018 10:59
Actually im trying to run c in rust
ahh those names ar confusing
Ok, good example, will go form there, tnx
Denis Lisov
@tanriol
May 09 2018 11:07
@autokorrelationsfunktion Have you tried building it with Cargo?
A K Fischer
@autokorrelationsfunktion
May 09 2018 11:12
@tanriol Yes. Currently, it does not compile when I use my derive macro and I do not understand why -- hence my want to expand the generated code
Denis Lisov
@tanriol
May 09 2018 11:14
@autokorrelationsfunktion Try going via cargo rustc -- -Z unstable-options --pretty expanded
A K Fischer
@autokorrelationsfunktion
May 09 2018 11:15
I actually couldn't figure out how to properly specify which file I want to have expanded with that
so I just built a small project in which I have just one src/main.rs to test the macro
so I can solve the expansion for debugging the macro
but I still don't understand either how to use cargo rustc to expand single files nor why rustc has that problem with lazy_static
Denis Lisov
@tanriol
May 09 2018 11:19
Your test requires the lazy_static crate. IIUC, normally cargo provides special arguments to rustc to tell it where should the crates come from. You don't pass it, so rustc tries a fallback and fails due to multiple candidates it cannot choose between.
A K Fischer
@autokorrelationsfunktion
May 09 2018 11:19
How do I tell rustc which lib to use?
Denis Lisov
@tanriol
May 09 2018 11:22
Run cargo build --verbose to see the full command line cargo uses
A K Fischer
@autokorrelationsfunktion
May 09 2018 11:25
Ah, very nice. This helps, thank you!
VJ
@00imvj00
May 09 2018 11:32
when 1.26 is releasing ?
Release Dates
Rust 1.25 stable was released on Fri Mar 30 2018.
Rust 1.26 stable will be released on Fri May 11 2018.
Rust 1.27 stable will be released on Fri Jun 22 2018.
VJ
@00imvj00
May 09 2018 11:35
@ozkriff thnks.
A K Fischer
@autokorrelationsfunktion
May 09 2018 11:50
I have another question. I am deriving a trait "HasX" for a type T. In my derive macro, I need to use lazy_static to generate a pub static ref. I would like this ref's name to be essentially T_X. How can I do that? I think I'd either need to define a new Ident (which I don't think is possible) or write something like "#T_X" in the quote, but that's not correct syntax.
Denis Lisov
@tanriol
May 09 2018 11:56
IIUC, the #var in quote! refers to a variable called var, so you probably need to introduce a variable for it.
A K Fischer
@autokorrelationsfunktion
May 09 2018 11:57
Oh, nevermind, I just found https://github.com/dtolnay/quote and it has the answer...
but thanks a lot!
for some reason I didn't think to check quote's documentation
Dylan DPC
@Dylan-DPC
May 09 2018 12:21
@ozkriff they should release a special version during rustfest.. will be fun :D
Dimitri Sabadie
@phaazon
May 09 2018 13:39
hey, I think I’ve found a rule I didn’t know it existed
is there some kind of rule forbidding “lifting up” of trait’s impl through safe coercion or auto-deref?
Denis Lisov
@tanriol
May 09 2018 15:42
@phaazon What do you mean? Going from &Trait to &Req when trait Trait: Req?
Dimitri Sabadie
@phaazon
May 09 2018 16:01
no
I mean something like, if you have a trait implemented on &T, you cannot directly call that impl if you have a &mut T, while it safely coerce to &T
tandrysyawaludin
@tandrysyawaludin
May 09 2018 17:51
Hi, everybody know what kind of error is this? error[E0583]: file not found for module
i wanna use mod in schema.rs not main.rs

i try to call module like this

mod module_name

in main.rs, it works, but not in schema.rs

Denis Lisov
@tanriol
May 09 2018 17:58
The stable way is to have
main.rs
schema/mod.rs
schema/module_name.rs
tandrysyawaludin
@tandrysyawaludin
May 09 2018 18:04
but how i call a mod in another file? @tanriol
Denis Lisov
@tanriol
May 09 2018 18:08
// main.rs
mod schema; // refers to schema/mod.rs
// schema/mod.rs
mod submodule; // refers to schema/submodule.rs
use schema::submodule::S as So; // note absolute path in `use`
const MY_S: submodule::S = So;
// schema/submodule.rs
pub(crate) struct S;
tandrysyawaludin
@tandrysyawaludin
May 09 2018 18:10
thanks for your help @tanriol