Explicit positive integer literals

#[rustfmt::nowrap]?

I would love to see common usages of #[rustfmt::skip] get turned into special attributes. My shortlist would include:

  • grid, which for me does mean columnar alignment (often for 2+ dimensional arrays). These are even often truly constant so "nice" diffs does not matter, just nice viewing.
  • blob, for giant blobs pasted in (this can probably continue to be spelled "skip").
  • i_dunno, for short-line clauses that I still want to see on multiple lines. Like in some matches or in certain large if conditions, or certain a | (b << 2) | (c << 8) | (d << 12) expressions (which get reflowed imo suboptimally now).

I'm not sure exactly how fruitful an audit would be here, as I often just sigh and let the formatter go nuts. Definitely preserve-newlines mode at least would be put to use.

We may only need the ability to specify number of columns e.g.

#[rustfmt::align(3)]
let x = [
    1,   2,   3,
    10,  20,  30,
    100, 200, 300,
];
#[rustfmt::align(2)]
let x = [
    1,   2, 
    3,   10, 
    20,  30,
    100, 200, 
    300,
];

Then preserving 100 character line width will be responsibility of user. It doesn't matter that much in tables anyway, so there it would be fine to break this rule

This is part of some actual code of mine:

    #[rustfmt::skip]
    return match (
         found_in_globals,
                found_in_pins,
                       xpins,
                              is_pin,
                                     prefer_local) {
        (true,  _,     _,     _,     false) => ast::TypedNet::Global(net),
        (true,  true,  false, _,     true ) => ast::TypedNet::Pin(net),
        (true,  true,  true,  true,  true ) => ast::TypedNet::Pin(net),
        (true,  true,  true,  false, true ) => ast::TypedNet::Global(net),
        (true,  false, _,     _,     true ) => ast::TypedNet::Global(net),
        (false, true,  false, _,     _    ) => ast::TypedNet::Pin(net),
        (false, true,  true,  true,  _    ) => ast::TypedNet::Pin(net),
        (false, true,  true,  false, _    ) => ast::TypedNet::Net(net),
        (false, false, _,     _,     _    ) => ast::TypedNet::Net(net),
    };

... and I find it's not so bad.

4 Likes

I personally find it not so difficult to type in generally well formatted (albeit not strictly uniform) code in the first place. But that's not why we use formatters.

Yes you're right. But I think I can wait a few years before rustfmt learns that trick :slight_smile:

Honestly, what I’d like to see is "soft formatting" support built into code editors; like soft wrapping or custom tab width/stops, it would be purely presentational and distinct from the bytes-on-disk representation which could be in a standard format to facilitate collaboration.

In general I’d like to see code editors moving towards actually treating code as a tree, its "native" representation, rather than rows and columns of characters which is only an incidental representation. This would include tree-oriented navigation and eding commands similar to Emacs’s ParEdit mode and its spiritual successor, Parinfer.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.