Skip to content

long literal expressions should be truncated #125581

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

Closed
lolbinarycat opened this issue May 26, 2024 · 22 comments · Fixed by #137757
Closed

long literal expressions should be truncated #125581

lolbinarycat opened this issue May 26, 2024 · 22 comments · Fixed by #137757
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lolbinarycat
Copy link
Contributor

lolbinarycat commented May 26, 2024

Code

const FOO: &[&str] = ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"];
  |                      +

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error

Desired output

error[E0308]: mismatched types
 --> src/lib.rs:1:22
  |
1 | const FOO: &[&str] = [ ... ];
  |                      ^^^^^^^ expected `&[&str]`, found `[&str; 4]`
help: consider borrowing here
  |
1 | const FOO: &[&str] = &[ ... ];
  |                      +


For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error

Rationale and extra context

because of the terminal line wrapping several times above and below the error message, it can be very difficult to find the actual details of the error (in this case, the expected and actual types)

this gets much worse if you are trying to include a generated constant expression into your code, as the include! will actually be expanded in the error message, meaning rustc might bury the important details of the error between hundreds or thousands of lines of irrelevant autogenerated code.

Other cases

No response

Rust Version

rustc 1.80.0-nightly (9cdfe285c 2024-05-22)
binary: rustc
commit-hash: 9cdfe285ca724c801dc9f78d22b24ea69b787f26
commit-date: 2024-05-22
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Anything else?

No response

@lolbinarycat lolbinarycat added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 26, 2024
@workingjubilee
Copy link
Member

this gets much worse if you are trying to include a generated constant expression into your code, as the include! will actually be expanded in the error message, meaning rustc might bury the important details of the error between hundreds or thousands of lines of irrelevant autogenerated code.

Yeah that's unacceptable, shoving a string behind an include_str! or something is precisely what people should be doing for huge text they want to shove into their program.

@workingjubilee workingjubilee added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label May 26, 2024
@workingjubilee
Copy link
Member

@lolbinarycat wait, apparently this doesn't happen with include_str!?

can you produce an example that produces the bad diagnostics you describe with include! or include_str!?

@lolbinarycat
Copy link
Contribut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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]

then do rustc --crate-type=lib longconst1.rs

@lolbinarycat
Copy link
Contributor Author

here's the terminal output.

surprisingly alacritty actually doesn't turn the line wraps into hard newlines when you copy the selection.

error[E0308]: mismatched types
 --> longconst.rs:1:1
  |
1 | ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]
  | +

error: aborting due to 1 previous error

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

@lolbinarycat
Copy link
Contributor Author

it looks like the syntax error actually shows as being inside the included file, which makes sense. i couldn't tell before because it was cut off.

@workingjubilee
Copy link
Member

...okay there's... still some kinda diagnostic bug here but I don't know what lol.

@workingjubilee
Copy link
Member

like I would expect this suggestion:

help: consider borrowing here
  |
1 | const FOO: &[&str] = &include!("longconst2.rs");
  |                      +

@lolbinarycat
Copy link
Contributor Author

it's grabbing the source position of the [ token, presumably. i don't know how else you would possibly implement that diagnostic. also consider that the type mismatch might not be solvable by adding a token to the start of the file, and thus the diagnostic might suggest adding & somewhere else, consider the case of _: &[&[u8]] = &[[1]];.

it's impossible for the suggestions to be 100% accurate, what i think is more important is making sure the programmer can see the details of the error.

@lolbinarycat
Copy link
Contributor Author

lolbinarycat commented May 27, 2024

in case it wasn't obvious why the current behavior is a problem, here's a more accurate representation of what you would see in your terminal.

and remember, this is a mild example. it can get so much worse.

very long error message
error[E0308]: mismatched types
 --> longconst.rs:1:1
  |
1 | ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
a", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa"]
  | +

error: aborting due to 1 previous error

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

@workingjubilee
Copy link
Member

workingjubilee commented May 27, 2024

I did take a look at the error in my actual terminal and honestly it didn't look that bad (i.e. that was not really an "accurate representation of what you would see in your terminal", for all terminals anyways, and "more" feels debatable?).

Force-wrapping your terminal to the width of a punch card and then including 420-character strings in your source is an... interesting combination of decisions.

@workingjubilee
Copy link
Member

workingjubilee commented May 27, 2024

I was curious how this is handled for multiple line errors and it does indeed partially elide these cases:

error[E0308]: mismatched types
   --> longconst2.rs:424:49
    |
424 |         unsafe { core::str::from_utf8_unchecked(s) }
    |                  ------------------------------ ^ expected `&[u8]`, found `[u8; 420]`
    |                  |
    |                  arguments to this function are incorrect
    |
note: function defined here
   --> /home/jubilee/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/str/converts.rs:173:21
    |
173 | pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
    |                     ^^^^^^^^^^^^^^^^^^^
help: consider borrowing here
    |
424 |         unsafe { core::str::from_utf8_unchecked(&s) }
    |                                                 +

error[E0308]: mismatched types
   --> longconst2.rs:1:1
    |
1   | / [
2   | |     {
3   | |         let mut s = [0; 420];
4   | | s[0] = b'a';
...   |
429 | |
430 | | ]
    | |_^ expected `&[&str]`, found `[&str; 4]`
    |
help: consider borrowing here
    |
1   | &[
    | +

error: aborting due to 2 previous errors

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

Even when source describes a single literal:

error[E0308]: mismatched types
   --> longconst2.rs:1:1
    |
1   | / ["\
2   | |     aaaaaaaaaaaaa\
3   | |     aaaaaaaaaaaaa\
4   | |     aaaaaaaaaaaaa\
...   |
426 | |     "a"
427 | | ]
    | |_^ expected `&[&str]`, found `[&str; 4]`
    |
help: consider borrowing here
    |
1   | &["\
    | +

error: aborting due to 1 previous error

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

But there the linebreaks provide the natural, well, breaking points, so the heuristic of when to start "horizontal" elision seems like it will be more complicated (due to the aforementioned variable terminal width).

@workingjubilee
Copy link
Member

Ah, right, --diagnostic-width! Which apparently defaults to 140 columns?

const DEFAULT_COLUMN_WIDTH: usize = 140;

There's... still quite a few heuristics indeed.

Hmm, we do seem to have partial support for horizontal elision, but only on the start of a line, if I'm reading this correctly...?

@lolbinarycat
Copy link
Contributor Author

hmm, i just realized the diagnostics code doesn't recive an AST..

that does make things quite a bit trickier.

@workingjubilee
Copy link
Member

workingjubilee commented May 27, 2024

Well, it looks at spans.

This has benefits, in that it prevents losing track of where in the actual code (and not the abstractifications of it) the error occurs. rustc's errors are often surfaced from deep inside borrow-checking or const-eval, so remembering spans all the way through helps prevent looking at fake code that doesn't exist, or pointing at the wrong thing.

You're right that sometimes looking at the abstractification is kinda what we want. I don't think it makes resolving this issue impossible, though. It just might make the implementation... funny.

More likely to induce grief are the includes, I think:

/// include! : parse the given file as an expr
/// This is generally a bad idea because it's going to behave
/// unhygienically.
pub(crate) fn expand_include<'cx>(
cx: &'cx mut ExtCtxt<'_>,
sp: Span,
tts: TokenStream,
) -> MacroExpanderResult<'cx> {
let sp = cx.with_def_site_ctxt(sp);
let ExpandResult::Ready(mac) = get_single_str_from_tts(cx, sp, tts, "include!") else {
return ExpandResult::Retry(());
};
let file = match mac {
Ok(file) => file,
Err(guar) => return ExpandResult::Ready(DummyResult::any(sp, guar)),
};
// The file will be added to the code map by the parser
let file = match resolve_path(&cx.sess, file.as_str(), sp) {
Ok(f) => f,
Err(err) => {
let guar = err.emit();
return ExpandResult::Ready(DummyResult::any(sp, guar));
}
};
let p = new_parser_from_file(cx.psess(), &file, Some(sp));
// If in the included file we have e.g., `mod bar;`,
// then the path of `bar.rs` should be relative to the directory of `file`.
// See https://github.com/rust-lang/rust/pull/69838/files#r395217057 for a discussion.
// `MacroExpander::fully_expand_fragment` later restores, so "stack discipline" is maintained.
let dir_path = file.parent().unwrap_or(&file).to_owned();
cx.current_expansion.module = Rc::new(cx.current_expansion.module.with_dir_path(dir_path));
cx.current_expansion.dir_ownership = DirOwnership::Owned { relative: None };
struct ExpandInclude<'a> {
p: Parser<'a>,
node_id: ast::NodeId,
}
impl<'a> MacResult for ExpandInclude<'a> {
fn make_expr(mut self: Box<ExpandInclude<'a>>) -> Option<P<ast::Expr>> {
let expr = parse_expr(&mut self.p).ok()?;
if self.p.token != token::Eof {
self.p.psess.buffer_lint(
INCOMPLETE_INCLUDE,
self.p.token.span,
self.node_id,
BuiltinLintDiag::IncompleteInclude,
);
}
Some(expr)
}
fn make_items(mut self: Box<ExpandInclude<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
let mut ret = SmallVec::new();
loop {
match self.p.parse_item(ForceCollect::No) {
Err(err) => {
err.emit();
break;
}
Ok(Some(item)) => ret.push(item),
Ok(None) => {
if self.p.token != token::Eof {
let token = pprust::token_to_string(&self.p.token);
let msg = format!("expected item, found `{token}`");
self.p.dcx().span_err(self.p.token.span, msg);
}
break;
}
}
}
Some(ret)
}
}
ExpandResult::Ready(Box::new(ExpandInclude { p, node_id: cx.current_expansion.lint_node_id }))
}

@lolbinarycat
Copy link
Contributor Author

there's also a midground solution to consider: if a line is extremely long (say, line.len() > termwidth*termheight/2), just omit the line entirely, and just print file:line:column diagnostics.

a lot of older compilers only print souce code locations, so i don't think it would be so bad, and it would definitely be an improvement over the current situation, since you could actually see the errors. only tricky part might be getting the "help" diagnostics to print a source code location where you could change something.

@workingjubilee
Copy link
Member

Hmm, my experience with learning Rust is I had no idea what the file:line:column things meant.

@estebank
Copy link
Contributor

estebank commented May 27, 2024

Hmm, we do seem to have partial support for horizontal elision, but only on the start of a line, if I'm reading this correctly...?

That is correct, we trim the beginning and end of long lines, but we don't even attempt to cut the middle of long lines. I didn't implement that originally because 1) it would have been too much logic to land at once, 2) I wasn't sure what the heuristic should have been (note that this logic could also trigger with multiple long expressions on the same line), 3) was concerned about mucking around too much with the code as written by end users.

The machinery for keeping track of this is already all there: you need to account for multibyte chars (to avoid splitting one of them when cutting the code string up), to keep track of the trimmings so the underline keeps working, to write a very clear ... in the middle so that people can know what's happening, to account for multiple long literals in the same line (will you trim to something like let x = ["aaaaaaaa...aaaaaaaa", "bbbbbbbbbbb...bbbbbbbbbb"]?), how to make the underline bridge the gap (^^^^^^^...^^^^^^? Just make the underline ^ pointing at the ...?), whether this will only go for literals, or for any long span on the same line, whether you show the start and end of the span or just the start. One thing that would be my preference, is that this should only trigger if the span is longer than double the width of the screen for a single span, and maybe special case when there's a single long span in a line or if there are more than one. (But at some point, these are all mitigations, if people decide to format their entire crate in a single line, there's only so much we can do to make the output look ok.)

Edit: One more thing, I think that whatever is done for this should be done on the emitter itself, not anywhere else. This has to be a change to the presentation, not the underlying data.

omit the line entirely, and just print file:line:column diagnostics.

It's not a bad idea, but I don't think it is the best course of action. We already mangle users' code a bit for long lines, we should either lean into that, or remove what we have already and use that new solution for those cases too. I lean towards leaning in.

Also note that we currently don't apply this logic for suggestions, because I deemed likely to confuse people, but maybe I was wrong and we should also trim suggestions as well. That might require additional impl work.

@estebank estebank added the D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. label May 27, 2024
@workingjubilee
Copy link
Member

The machinery for keeping track of this is already all there: you need to account for multibyte chars (to avoid splitting one of them when cutting the code string up), to keep track of the trimmings so the underline keeps working, to write a very clear ... in the middle so that people can know what's happening, to account for multiple long literals in the same line (will you trim to something like let x = ["aaaaaaaa...aaaaaaaa", "bbbbbbbbbbb...bbbbbbbbbb"]?), how to make the underline bridge the gap (^^^^^^^...^^^^^^? Just make the underline ^ pointing at the ...?)

Hmmm.

While the emitter reasons about things in terms of chars, as it should, I think we should prefer to elide entire tokens at a time. That's also justified by only doing this if the code runs wildly "off the page"... if someone overhangs by a few dozen bytes, that would still render "normally", but if we determine the token is effectively useless to the output then we should discard it.

@lolbinarycat
Copy link
Contributor Author

there's always the option of discarding the line entirely, which might be good enough considering not many people will have lines 1000s of chars long.

or, alternatively, we could discard the ends of very long lines, as well as their beginning. this way you can still have the alignment-based help messages, while not flooding the screen, and also without significant increases to code complexity.

@estebank
Copy link
Contributor

While the emitter reasons about things in terms of chars, as it should, I think we should prefer to elide entire tokens at a time.

I'm not sure I agree for two reasons. One is stylistic: providing partial context is useful to help identify what we might be pointing at. If you have let text = "It was the best of times. It was the wor... it is easier to skim the code to find the issue than if we show let text = "...";, as people might look for the later in their code. The other reason is practical: the emitter right now doesn't know about tokens, and I think it'd be for the best to keep it that way.

if someone overhangs by a few dozen bytes, that would still render "normally"

Agree.

if we determine the token is effectively useless to the output then we should discard it.

It might be that the span covers more than a single token. It could be quite a complex expression that might be hard to find a natural cutting place for without AST analysis. I think that the "show a bit of the start and a bit of the end" has worked well enough as a heuristic in the past, and we should use it here too.

or, alternatively, we could discard the ends of very long lines, as well as their beginning.

We do, the problem is for long spans, not long lines in general:

error[E0308]: mismatched types
--> $DIR/non-whitespace-trimming-2.rs:4:311
|
LL | ...13; let _: usize = 14; let _: usize = 15; let _: () = 42; let _: usize = 0; let _: usize = 1; let _: usize = 2; let _: usize = 3; let ...
| -- ^^ expected `()`, found integer
| |
| expected due to this

@lolbinarycat
Copy link
Contributor Author

We do, the problem is for long spans, not long lines in general

in that case i think it would make sense to keep to the behavior of only omitting at the start and the end. otherwise diagnostics could end up with an ellipsis in 3 places (such as if it consists of a short span, a very long span, then another short span), and that seems needlessly confusing.

i propose a simple change: if, after omitting all leading and trailing spans, the line is still extremely long, the end of the target span should also be omitted (only enough to make the line a reasonable length).

estebank added a commit to estebank/rust that referenced this issue Feb 27, 2025
…al width

When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

```
error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`
```

Address part of rust-lang#137680 (missing handling of the long suggestion). Fix rust-lang#125581.
estebank added a commit to estebank/rust that referenced this issue Feb 27, 2025
…al width

When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

```
error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`
```

Address part of rust-lang#137680 (missing handling of the long suggestion). Fix rust-lang#125581.
@estebank
Copy link
Contributor

I think that #137757 will address everything but the suggestions.

Image

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 7, 2025
On long spans, trim the middle of them to make them fit in the terminal width

When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

```
error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`
```

Address part of rust-lang#137680 (missing handling of the long suggestion). Fix rust-lang#125581.

---

Change the way that underline positions are calculated by delaying using the "visual" column position until the last possible moment, instead using the "file"/byte position in the file, and then calculating visual positioning as late as possible. This should make the underlines more resilient to non-1-width unicode chars.

Unfortunately, as part of this change (which fixes some visual bugs) comes with the loss of some eager tab codepoint handling, but the output remains legible despite some minor regression on the "margin trimming" logic.

---

`-Zteach` is perma-unstable, barely used, the highlighting logic buggy and the flag being passed around is tech-debt. We should likely remove `-Zteach` in its entirely.
jhpratt added a commit to jhpratt/rust that referenced this issue Mar 8, 2025
On long spans, trim the middle of them to make them fit in the terminal width

When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

```
error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`
```

Address part of rust-lang#137680 (missing handling of the long suggestion). Fix rust-lang#125581.

---

Change the way that underline positions are calculated by delaying using the "visual" column position until the last possible moment, instead using the "file"/byte position in the file, and then calculating visual positioning as late as possible. This should make the underlines more resilient to non-1-width unicode chars.

Unfortunately, as part of this change (which fixes some visual bugs) comes with the loss of some eager tab codepoint handling, but the output remains legible despite some minor regression on the "margin trimming" logic.

---

`-Zteach` is perma-unstable, barely used, the highlighting logic buggy and the flag being passed around is tech-debt. We should likely remove `-Zteach` in its entirely.
@bors bors closed this as completed in 72326bf Mar 8, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 8, 2025
Rollup merge of rust-lang#137757 - estebank:trim-spans, r=davidtwco

On long spans, trim the middle of them to make them fit in the terminal width

When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

```
error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`
```

Address part of rust-lang#137680 (missing handling of the long suggestion). Fix rust-lang#125581.

---

Change the way that underline positions are calculated by delaying using the "visual" column position until the last possible moment, instead using the "file"/byte position in the file, and then calculating visual positioning as late as possible. This should make the underlines more resilient to non-1-width unicode chars.

Unfortunately, as part of this change (which fixes some visual bugs) comes with the loss of some eager tab codepoint handling, but the output remains legible despite some minor regression on the "margin trimming" logic.

---

`-Zteach` is perma-unstable, barely used, the highlighting logic buggy and the flag being passed around is tech-debt. We should likely remove `-Zteach` in its entirely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants