Skip to content

Assert panic is difficult to read for long expressions #61449

@jyn514

Description

@jyn514

Given the following test, the traceback is very ugly and difficult to read. I think the assert! macro is trying to limit the width to 80 or 100 characters, but it also indents by a ridiculous amount. It should either use block indentation instead of visual indentation, put everything one line, or possibly just format it the same as the original code.

This happened even when the terminal width was more than 100 characters.

    #[test]
    fn test_complex_types() {
        assert!(match_type(
            parse("char * const (*(* const bar)[10])(int )"),
            Pointer(
                Box::new(Array(
                    Box::new(Pointer(
                        Box::new(Function(FunctionType {
                            return_type: Box::new(Pointer(Box::new(Char(true)), Qualifiers::CONST)),
                            params: vec![Symbol {
                                ctype: Int(true),
                                storage_class: Default::default(),
                                id: String::new(),
                                qualifiers: Qualifiers::NONE,
                            }],
                            varargs: false,
                        })),
                        Qualifiers::NONE
                    )),
                    ArrayType::Fixed(Box::new(Expr::Int(Token::Int(10))))
                )),
                Qualifiers::CONST
            )
        ));
    }
failures:

---- parse::tests::test_complex_types stdout ----
thread 'parse::tests::test_complex_types' panicked at 'assertion failed: match_type(parse("char * const (*(* const bar)[10])(int )"),
           Pointer(Box::new(Array(Box::new(Pointer(Box::new(Function(FunctionType{return_type:
                                                                                      Box::new(Pointer(Box::new(Char(true)),
                                                                                                       Qualifiers::CONST)),
                                                                                  params:
                                                                                      vec![Symbol
                                                                                           {
                                                                                           ctype
                                                                                           :
                                                                                           Int
                                                                                           (
                                                                                           true
                                                                                           )
                                                                                           ,
                                                                                           storage_class
                                                                                           :
                                                                                           Default
                                                                                           ::
                                                                                           default
                                                                                           (

                                                                                           )
                                                                                           ,
                                                                                           id
                                                                                           :
                                                                                           String
                                                                                           ::
                                                                                           new
                                                                                           (

                                                                                           )
                                                                                           ,
                                                                                           qualifiers
                                                                                           :
                                                                                           Qualifiers
                                                                                           ::
                                                                                           NONE
                                                                                           ,
                                                                                           }],
                                                                                  varargs:
                                                                                      false,})),
                                                   Qualifiers::NONE)),
                                  ArrayType::Fixed(Box::new(Expr::Int(Token::Int(10)))))),
                   Qualifiers::CONST))', src/parse.rs:965:9

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-prettyArea: Pretty printing (including `-Z unpretty`)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions