Trouble with several scan! macros (extern crate text_io)


#1

hello, I dont understand why I get an error:

#[macro_use] extern crate text_io;

let i: i32;
let a: i32;

scan!("{}", i);
scan!("{}", a);

but works separated with curved brackets:
scan!("{}", i);
{
scan!("{}", a);
}

??


#2

Hello @p53. Can you please elaborate:

  • What is the desired behavior?
  • What is the error you get? Is it an error message, or does something just not work right?
  • Can you please post the complete code that does not work and the code (the one with the curly braces), that does work?

#3

thanks for response; that is the complete code (inside a main function) :slight_smile:
All I care about is the principle why you can not do several simple scan without this weird error message.

let a: i32;
let b: i32;

scan!("{}", a);
scan!("{}", b);

/*
25 | scan!("{}", a);
   | --------------- previous import of the trait `Read` here
26 | scan!("{}", b);
   | ^^^^^^^^^^^^^^^ `Read` reimported here
   = note: `Read` must be defined only once in the type namespace of this block
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
help: You can use `as` to change the binding name of the import
2  | use :: std :: io :: Read as OtherRead ; scan ! (
*/

#4

Looks like a bug in that macro definition. File an issue in that crate’s github repo.