1
Fork 0

Account for multiple multiline spans with empty padding

Instead of

```
LL |    fn oom(
   |  __^
   | | _|
   | ||
LL | || ) {
   | ||_-
LL | |  }
   | |__^
```

emit

```
LL | // fn oom(
LL | || ) {
   | ||_-
LL | |  }
   | |__^
   ```
This commit is contained in:
Esteban Küber 2022-12-27 11:03:59 -08:00
parent caa64e5b5e
commit af74ca0666
9 changed files with 30 additions and 47 deletions

View file

@ -845,7 +845,10 @@ impl EmitterWriter {
// 3 | | // 3 | |
// 4 | | } // 4 | | }
// | |_^ test // | |_^ test
if let [ann] = &line.annotations[..] { let mut buffer_ops = vec![];
let mut annotations = vec![];
let mut short_start = true;
for ann in &line.annotations {
if let AnnotationType::MultilineStart(depth) = ann.annotation_type { if let AnnotationType::MultilineStart(depth) = ann.annotation_type {
if source_string.chars().take(ann.start_col).all(|c| c.is_whitespace()) { if source_string.chars().take(ann.start_col).all(|c| c.is_whitespace()) {
let style = if ann.is_primary { let style = if ann.is_primary {
@ -853,10 +856,23 @@ impl EmitterWriter {
} else { } else {
Style::UnderlineSecondary Style::UnderlineSecondary
}; };
buffer.putc(line_offset, width_offset + depth - 1, '/', style); annotations.push((depth, style));
return vec![(depth, style)]; buffer_ops.push((line_offset, width_offset + depth - 1, '/', style));
} else {
short_start = false;
break;
}
} else if let AnnotationType::MultilineLine(_) = ann.annotation_type {
} else {
short_start = false;
break;
} }
} }
if short_start {
for (y, x, c, s) in buffer_ops {
buffer.putc(y, x, c, s);
}
return annotations;
} }
// We want to display like this: // We want to display like this:

View file

@ -3,10 +3,7 @@ error[E0308]: mismatched types
| |
LL | #[alloc_error_handler] LL | #[alloc_error_handler]
| ---------------------- in this procedural macro expansion | ---------------------- in this procedural macro expansion
LL | fn oom( LL | // fn oom(
| __^
| | _|
| ||
LL | || info: &Layout, LL | || info: &Layout,
LL | || ) -> () LL | || ) -> ()
| ||_______- arguments to this function are incorrect | ||_______- arguments to this function are incorrect
@ -29,10 +26,7 @@ error[E0308]: mismatched types
| |
LL | #[alloc_error_handler] LL | #[alloc_error_handler]
| ---------------------- in this procedural macro expansion | ---------------------- in this procedural macro expansion
LL | fn oom( LL | // fn oom(
| __^
| | _|
| ||
LL | || info: &Layout, LL | || info: &Layout,
LL | || ) -> () LL | || ) -> ()
| ||_______^ expected `!`, found `()` | ||_______^ expected `!`, found `()`

View file

@ -3,10 +3,7 @@ error[E0308]: mismatched types
| |
LL | #[alloc_error_handler] LL | #[alloc_error_handler]
| ---------------------- in this procedural macro expansion | ---------------------- in this procedural macro expansion
LL | fn oom( LL | // fn oom(
| __^
| | _|
| ||
LL | || info: Layout, LL | || info: Layout,
LL | || ) { LL | || ) {
| ||_- arguments to this function are incorrect | ||_- arguments to this function are incorrect
@ -36,10 +33,7 @@ error[E0308]: mismatched types
| |
LL | #[alloc_error_handler] LL | #[alloc_error_handler]
| ---------------------- in this procedural macro expansion | ---------------------- in this procedural macro expansion
LL | fn oom( LL | // fn oom(
| __^
| | _|
| ||
LL | || info: Layout, LL | || info: Layout,
LL | || ) { LL | || ) {
| ||_^ expected `!`, found `()` | ||_^ expected `!`, found `()`

View file

@ -30,12 +30,7 @@ error: asm outputs are not allowed with the `noreturn` option
LL | asm!("", $in(x) x, $out(x) x, $lateout(x) x, $inout(x) x, $inlateout(x) x, LL | asm!("", $in(x) x, $out(x) x, $lateout(x) x, $inout(x) x, $inlateout(x) x,
| ^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^ | ^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^
... ...
LL | m!(in out lateout inout inlateout const sym LL | / m!(in out lateout inout inlateout const sym
| _____-
| |_____|
| |_____|
| |_____|
| |
LL | | pure nomem readonly preserves_flags LL | | pure nomem readonly preserves_flags
LL | | noreturn nostack options); LL | | noreturn nostack options);
| | - | | -

View file

@ -30,12 +30,7 @@ error: asm outputs are not allowed with the `noreturn` option
LL | asm!("", $in(x) x, $out(x) x, $lateout(x) x, $inout(x) x, $inlateout(x) x, LL | asm!("", $in(x) x, $out(x) x, $lateout(x) x, $inout(x) x, $inlateout(x) x,
| ^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^ | ^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^
... ...
LL | m!(in out lateout inout inlateout const sym LL | / m!(in out lateout inout inlateout const sym
| _____-
| |_____|
| |_____|
| |_____|
| |
LL | | pure nomem readonly preserves_flags LL | | pure nomem readonly preserves_flags
LL | | noreturn nostack att_syntax options); LL | | noreturn nostack att_syntax options);
| | - | | -

View file

@ -1,10 +1,7 @@
error[E0515]: cannot return value referencing local variable `rawLines` error[E0515]: cannot return value referencing local variable `rawLines`
--> $DIR/issue-13497-2.rs:3:5 --> $DIR/issue-13497-2.rs:3:5
| |
LL | rawLines LL | // rawLines
| ______^
| | _____|
| ||
LL | || .iter().map(|l| l.trim()).collect() LL | || .iter().map(|l| l.trim()).collect()
| ||_______________-___________________________^ returns a value referencing data owned by the current function | ||_______________-___________________________^ returns a value referencing data owned by the current function
| |_______________| | |_______________|

View file

@ -4,10 +4,7 @@ error[E0618]: expected function, found enum variant `Alias::Unit`
LL | Unit, LL | Unit,
| ---- enum variant `Alias::Unit` defined here | ---- enum variant `Alias::Unit` defined here
... ...
LL | Alias:: LL | // Alias::
| ______^
| | _____|
| ||
LL | || Unit(); LL | || Unit();
| ||________^_- call expression requires function | ||________^_- call expression requires function
| |________| | |________|

View file

@ -3,8 +3,7 @@ error: an async construct yields a type which is itself awaitable
| |
LL | let _h = async { LL | let _h = async {
| _____________________- | _____________________-
LL | | async { LL | |/ async {
| | _________^
LL | || 3 LL | || 3
LL | || } LL | || }
| ||_________^ awaitable value not awaited | ||_________^ awaitable value not awaited
@ -37,8 +36,7 @@ error: an async construct yields a type which is itself awaitable
| |
LL | let _j = async || { LL | let _j = async || {
| ________________________- | ________________________-
LL | | async { LL | |/ async {
| | _________^
LL | || 3 LL | || 3
LL | || } LL | || }
| ||_________^ awaitable value not awaited | ||_________^ awaitable value not awaited

View file

@ -19,10 +19,7 @@ LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value)
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_unfixable.rs:29:5 --> $DIR/result_map_unit_fn_unfixable.rs:29:5
| |
LL | x.field.map(|value| { LL | // x.field.map(|value| {
| ______^
| | _____|
| ||
LL | || do_nothing(value); LL | || do_nothing(value);
LL | || do_nothing(value) LL | || do_nothing(value)
LL | || }); LL | || });