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

Macro indentation issue with rust-mode #13937

Closed
gsingh93 opened this issue May 4, 2014 · 6 comments
Closed

Macro indentation issue with rust-mode #13937

gsingh93 opened this issue May 4, 2014 · 6 comments

Comments

@gsingh93
Copy link
Contributor

gsingh93 commented May 4, 2014

I'm using rust-mode in emacs 24.3.

Here is a macro from the Macros guide:

macro_rules! early_return(
    ($inp:expr $sp:ident) => ( // invoke it like `(input_5 SpecialE)`
        match $inp {
            $sp(x) => { return x; }
            _ => {}
        }
    );
)

If I select all and hit tab, this is how it indents it:

macro_rules! try_option_or_fail(
    ($e:expr) => (
        match $e {
            Some(x) => x,
            None => fail!("Expected Some, got None", $e)
        }
        );
    )
@huonw
Copy link
Member

huonw commented May 8, 2014

cc #8793 and @pnkfelix

@gsingh93
Copy link
Contributor Author

I was just looking at the code for rust-mode. Can we just use the same rule we use } (unindent one level) when the first non-whitespace character of the line is a )? Or would that cause issues?

@gsingh93
Copy link
Contributor Author

I just tried this out by changing the code starting at line 113.

((or (looking-at "}") (save-excursion
                        (move-beginning-of-line nil)
                        (looking-at "[ \t]*)")))
 (- baseline rust-indent-offset))

It properly handles the case in the example.

@tomjakubowski
Copy link
Contributor

FWIW you can work around this in the meantime by using {} instead of () for the macro body and transcribers:

macro_rules! early_return {
    ($inp:expr $sp:ident) => { // invoke it like `(input_5 SpecialE)`
        match $inp {
            $sp(x) => { return x; }
            _ => {}
        }
    };
}

Emacs should indent that properly.

@shepmaster
Copy link
Member

This may now be fixed indirectly by #18635 via ddb2466. It is now required to have a semicolon at the end of that macro definition.

@steveklabnik
Copy link
Member

@gsingh93 , please let me know if @shepmaster is wrong, but yes, this would seem to be fixed.

bors added a commit to rust-lang-ci/rust that referenced this issue Feb 13, 2023
remove recursive 'Display' implementations

closes rust-lang#13920

`@lnicola` is this the solution you were looking for?

having explicitly unimplemented methods seems preferable to apparently implemented methods that can't be called
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

No branches or pull requests

5 participants