Skip to content

Labels and Messages don't account for terminal width #419

Description

@Muscraft

When rendering subdiagnostics with long labels or messages that would render beyond the terminal width, split the label or message on a best effort basis so that the text is rendered with newlines, keeping the text left-aligned and within the terminal width.

error: `Iterator::map` call that discard the iterator's values
  --> $DIR/lint_map_unit_fn.rs:11:18
   |
11 |         x.iter_mut().map(|items| {
   |                      ^   -------
   |                      |   |
   |  ____________________|___this function returns `()`, which is likely not what you wanted
   | |  __________________|
   | | |
12 | | |     //~^ ERROR `Iterator::map` call that discard the iterator's values
13 | | |         items.sort();
14 | | |     });
   | | |     -^ after this call to map, the resulting iterator is `impl Iterator<Item = ()>`, which means the only information carried by the iterator is the number of items
   | | |_____||
   | |_______|
   |         called `Iterator::map` with callable that returns `()`
   |
   = note: `Iterator::map`, like many of the methods on `Iterator`, gets executed lazily, meaning that its effects won't be visible until it is iterated
help: you might have meant to use `Iterator::for_each`
   |
11 -     x.iter_mut().map(|items| {
11 +     x.iter_mut().for_each(|items| {
   |

After:

error: `Iterator::map` call that discard the iterator's values
  --> $DIR/lint_map_unit_fn.rs:11:18
   |
11 |         x.iter_mut().map(|items| {
   |                      ^   -------
   |                      |   |
   |  ____________________|___this function returns `()`, which is likely not
   | |                    |   what you wanted
   | |  __________________|
   | | |
12 | | |     //~^ ERROR `Iterator::map` call that discard the iterator's values
13 | | |         items.sort();
14 | | |     });
   | | |     -^
   | | |_____||
   | | |_____||
   | |       |after this call to map, the resulting iterator is `impl
   | |       |Iterator<Item = ()>`, which means the only information carried by
   | |_______|the iterator is the number of items
   |         called `Iterator::map` with callable that returns `()`
   |
   = note: `Iterator::map`, like many of the methods on `Iterator`, gets executed
   |       lazily, meaning that its effects won't be visible until it is iterated
help: you might have meant to use `Iterator::for_each`
   |
11 -     x.iter_mut().map(|items| {
11 +     x.iter_mut().for_each(|items| {
   |

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions