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

Improve error when missing macro argument #322

Merged
merged 1 commit into from
Mar 10, 2019
Merged

Improve error when missing macro argument #322

merged 1 commit into from
Mar 10, 2019

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Mar 9, 2019

The log! macro matches part of its arguments as $($arg:tt)+, but the other macros match it as $($arg:tt)*. That means if a user calls error!() or any of the other macros with an empty argument, it successfully matches the macro rules of the first macro they called but then turns into an invalid call to log!, leading to a confusing error message.

This PR uses $($arg:tt)+ consistently to match arguments.

Example:

use log::error;

fn main() {
    error!();
}

Before:

error: expected identifier, found `,`
 --> src/main.rs:4:5
  |
4 |     error!();
  |     ^^^^^^^^^
  |     |
  |     expected identifier
  |     help: remove this comma
  |
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

After:

error: unexpected end of macro invocation
 --> src/main.rs:4:5
  |
4 |     error!();
  |     ^^^^^^^^^ missing tokens in macro arguments

Closes #271 (comment).

The log! macro matches part of its arguments as $($arg:tt)+, but the other
macros match it as $($arg:tt)*. That means if a user calls error!() or any of
the other macros with an empty argument, it successfully matches the macro rules
of the first macro they called but then turns into an invalid call to log!,
leading to a confusing error message.

This PR uses $($arg:tt)+ consistently to match arguments.

Example:

    use log::error;

    fn main() {
        error!();
    }

Before:

    error: expected identifier, found `,`
     --> src/main.rs:4:5
      |
    4 |     error!();
      |     ^^^^^^^^^
      |     |
      |     expected identifier
      |     help: remove this comma
      |
      = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

After:

    error: unexpected end of macro invocation
     --> src/main.rs:4:5
      |
    4 |     error!();
      |     ^^^^^^^^^ missing tokens in macro arguments
@dtolnay dtolnay merged commit f8522db into rust-lang:master Mar 10, 2019
@dtolnay dtolnay deleted the missing branch March 10, 2019 00:14
EFanZh pushed a commit to EFanZh/log that referenced this pull request Jul 23, 2023
* Test default `pkt-url` for GitLab and BitBucket
* Fail if `cargo-build` is called when testing GitLab/BitBucket
* Fix use of `remote_exists` in `GhCrateMeta::launch_baseline_find_tasks`
   
   If `Method::HEAD` fails, try `Method::GET` since some servers reject
   `Method::HEAD`, e.g. bbuseruploads.s3.amazonaws.com

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants