Comments (21)
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.
from rust.
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.
from rust.
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.
from rust.
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:
from rust.
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.
from rust.
@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!
?
from rust.
longconst1.rs:
const FOO: &[&str] = include!("longconst2.rs");
longconst2.rs
["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]
then do rustc --crate-type=lib longconst1.rs
from rust.
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 | ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]
| +
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.
from rust.
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.
from rust.
...okay there's... still some kinda diagnostic bug here but I don't know what lol.
from rust.
like I would expect this suggestion:
help: consider borrowing here
|
1 | const FOO: &[&str] = &include!("longconst2.rs");
| +
from rust.
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.
from rust.
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
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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa"]
| +
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.
from rust.
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).
from rust.
Ah, right, --diagnostic-width
! Which apparently defaults to 140 columns?
rust/compiler/rustc_errors/src/emitter.rs
Line 41 in cdc509f
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...?
from rust.
hmm, i just realized the diagnostics code doesn't recive an AST..
that does make things quite a bit trickier.
from rust.
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:
rust/compiler/rustc_builtin_macros/src/source_util.rs
Lines 105 to 182 in cdc509f
from rust.
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.
from rust.
Hmm, my experience with learning Rust is I had no idea what the file:line:column things meant.
from rust.
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.
from rust.
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).
from rust.
Related Issues (20)
- Should tokens passed through `macro_rules` be able to join? HOT 1
- rustc ignores first exposed private type / span incorrect
- spurious ci failure: `The process cannot access the file because it is being used by another process` HOT 1
- A problem has to do with tuple and println!()
- Unresolved symbol linker error when running `cargo test` with an `#[used]` static variable on Windows HOT 2
- Assertion failure: Unexpected captures in ABI-compatible shim for Fn/FnMut implementation of coroutine-closure HOT 1
- ICE: assertion failed `Alias(Projection, ..` != `FreshTy(0)` HOT 3
- ICE: `associated_type_for_effects: Defid .. should be Trait or Impl but is TraitAlias` HOT 1
- ICE: `expected type for .. but found Const(false) when instantiating` HOT 1
- ICE: `parent item: DefId(0:5 ~ a[9a36]::{impl#1}) not marked as default` HOT 4
- `-Znext-solver` errors with `impl` for projected `Self` type
- Tracking Issue for anonymous pipe API HOT 2
- tests: double check if tests contain incorrect follow-up error annotation syntax `//|` instead of `//~|` HOT 1
- error: internal compiler error: compiler/rustc_infer/src/infer/at.rs:400:21: relating different kinds. HOT 3
- rustdoc json output on stdout ? HOT 1
- cannot run cargo because windows CMD error : "[0x7FFBC7A07FA4] ANOMALY: use of REX.w is meaningless (default operand size is 64)"
- ICE because of a bad file on disk? HOT 5
- confusing error when trying to call a not-in-scope method that shares a name with a field HOT 1
- rustc SIGSEGV compiling rug 1.24.1 crate on RISC-V Armbian 24.5.0 HOT 1
- Clang linker script support - incorrect argument HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust.