Skip to content

Tracking Issue for -Z terminal-width #84673

@ehuss

Description

@ehuss
Contributor

Status: The rustc side has been stabilized in 1.64 as the --diagnostic-width option. This tracking issue is still open for the cargo side of changes. See #84673 (comment).

This is a tracking issue for the -Z terminal-width flag. This flag tells rustc the width of the terminal so that it can truncate long lines in diagnostic output to the correct length. A corresponding flag of the same name is available in Cargo, which detects the terminal width and sends in the appropriate value to rustc.

Unresolved Questions

Unknown.

Implementation history

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
on Apr 28, 2021
ehuss

ehuss commented on Apr 28, 2021

@ehuss
ContributorAuthor

cc @rust-lang/wg-diagnostics Hope you don't mind I open this. If anyone knows of any unresolved questions or blockers for this, I would appreciate if you could update the issue (or perhaps there is no desire to carry this forward?).

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Jul 30, 2021
shepmaster

shepmaster commented on Mar 27, 2022

@shepmaster
Member

I wanted this feature to be able to automatically format errors to a width suitable for inclusion on slides. However, it does not:

% rustc +nightly src/main.rs -Z terminal-width=80
error[E0425]: cannot find value `and_then_an_argument` in this scope
 --> src/main.rs:2:43
  |
2 |     a_very_long_function_name_that_pushes(and_then_an_argument);
  |                                           ^^^^^^^^^^^^^^^^^^^^ not found in this scope

this scope exceeds the specified width of 80 columns. I'd prefer it be

% rustc +nightly src/main.rs -Z terminal-width=80
error[E0425]: cannot find value `and_then_an_argument` in this scope
 --> src/main.rs:2:43
  |
2 |     a_very_long_function_name_that_pushes(and_then_an_argument);
  |                                           ^^^^^^^^^^^^^^^^^^^^ not found in
  |                                                                this scope

Should I register this as a separate issue?

estebank

estebank commented on Mar 27, 2022

@estebank
Contributor

That should indeed be a separate issue, I think. It is related, but independent. I also know it will be very difficult to come up with a good layout algorithm :-/

For things like slides, I think a better option would be html output.

davidtwco

davidtwco commented on Apr 4, 2022

@davidtwco
Member

I think that we should go ahead with stabilizing this, it's a small compiler feature that hasn't seen any major changes since it was implemented, and is useful for people invoking rustc through build systems other than Cargo.

Stabilization PR: #95635

@rfcbot fcp merge

Brief summary

rustc currently detects the width of the terminal and will truncate diagnostic output when it includes source code lines which are longer than the terminal width.

error[E0308]: mismatched types
  --> $DIR/flag-human.rs:7:17
   |
LL | ..._: () = 42;
   |       --   ^^ expected `()`, found integer
   |       |
   |       expected due to this

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.

However, rustc is unable to detect the terminal width when it is being invoked indirectly (i.e. through a build tool like Cargo). --terminal-width (currently -Zterminal-width) enables build tools to provide the terminal width to rustc so that it can continue to perform this truncation.

Implementation History

Test Coverage

FAQ

1. Is a flag necessary to turn this behaviour off?
--terminal-width doesn't do anything if it hasn't been explicitly provided to the compiler. When emitting an error and deciding whether to truncate output, rustc uses (in priority order):

  1. --terminal-width (if provided)
  2. If the compiler is being invoked for UI testing, then the terminal width is fixed at 140 columns.
  3. Using term_size to determine the current terminal width, and if that fails, defaulting to 140 columns.

Having this flag on stable won't change any behaviour, just allow tools to tell rustc the terminal width.

2. Can the terminal width be determined through environment variables?
Shells don't provide the terminal size to processes as an environment variable. There are "fake" environment variables available in the shell - namely COLUMNS and LINES - from some shells, but the shell wouldn't be able to keep these variables up to date if they were provided to a process, so it doesn't give them to the process at all. Processes can determine the terminal width by sending ioctl commands, asking stty size, or by listening for SIGWINCH signals. rustc uses the term_size crate to determine the terminal width when possible.

Outstanding bugs

Notes

  • If this is stabilized, then Cargo will need to be updated to use the stable flag, cc @ehuss
rfcbot

rfcbot commented on Apr 4, 2022

@rfcbot
Collaborator

Team member @davidtwco has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

added
proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.
on Apr 4, 2022
nikomatsakis

nikomatsakis commented on May 19, 2022

@nikomatsakis
Contributor

@rfcbot reviewed

added
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
on May 19, 2022

19 remaining items

Loading
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

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnosticsdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @ehuss@nikomatsakis@shepmaster@davidtwco@estebank

      Issue actions

        Tracking Issue for `-Z terminal-width` · Issue #84673 · rust-lang/rust