These are chat archives for rust-lang/rust

30th
Jun 2017
David Harvey-Macaulay
@alteous
Jun 30 2017 11:04
Hi, I'm having problems using an internal crate macro. It's not importing correctly for some reason. The macro is called try_validate and the compiler can't find it in this module. For sanity I tested the same setup which works as intended This demonstrates the problem - the compiler complains the hello_world macro is not in scope. What am I doing wrong?
Denis Lisov
@tanriol
Jun 30 2017 11:12
@alteous The current macro system is implemented on a lower level than item lookup. Like the C defines, they need to be (in a module declared) above the place or module they're used in.
David Harvey-Macaulay
@alteous
Jun 30 2017 11:34
@tanriol I don't fully understand. #include in C would import macros so why wouldn't #[macro_use] mod macros; do the same?
So, can macros only be used in the same place as they're defined?
Denis Lisov
@tanriol
Jun 30 2017 11:36
It does, but #[macro_use] mod macros; needs to be above (= read before) the module that uses the macros.
Zakarum
@omni-viral
Jun 30 2017 11:38

@alteous You just need to put

/// Contains the `try_validate` macro.
#[macro_use]
pub mod macros;

above all other mod <something>;

David Harvey-Macaulay
@alteous
Jun 30 2017 11:41
@SCareAngel Thanks, that worked. That's really bizarre!
Zakarum
@omni-viral
Jun 30 2017 11:43
@alteous for me using things declared below looked bizarre for some time )
Zakarum
@omni-viral
Jun 30 2017 11:48
@alteous no. I mean that I am used to C world where you need everything to be declared above usage
stevensonmt
@stevensonmt
Jun 30 2017 13:56

Getting an error loop that doesn't make sense to me.

fn foo(s: String) -> String {
  println!("{}", s)
}

yields the error expected struct 'std::string::String', found () whereas

fn foo(s: String) -> String {
  println!("{}", s);
}

yields the inverse mismatched type error expected (), found struct 'std::string::String'.

Denis Lisov
@tanriol
Jun 30 2017 14:02
@stevensonmt These two are about the same, but in different ways: the first tells you "this expression needs to return String, but returns ()", the second tells you "this function should be returning () (because the final statement is terminated with ;), but the return value is said to be String"
The underlying problem is the same: there's nothing in the function that could return a String.
stevensonmt
@stevensonmt
Jun 30 2017 14:11
Thanks. I just realized that println! macro does not return a string.
Is there a reason the concat() method inserts \n between the concatenated strings?
join("") does the same.
Denis Lisov
@tanriol
Jun 30 2017 14:17
Hmm... does it?
It does not... check why there's a \n in your strings.
stevensonmt
@stevensonmt
Jun 30 2017 14:19
Ah, the \n is getting input with io::stdin().read_line(). Thanks.
Tobias Schottdorf
@tschottdorf
Jun 30 2017 18:34

on current master:

14:33 $ git grep E0619
src/librustc_typeck/check/intrinsic.rs:            struct_span_err!(tcx.sess, it.span, E0619,
src/librustc_typeck/check/mod.rs:                    type_error_struct!(self.tcx.sess, sp, ty, E0619,

Some merge skew here?

catches a warning during build, too
ah, nvm, rust-lang/rust#42957