From 969926fcfe68787595d384f53d19cf6b8c9df3e3 Mon Sep 17 00:00:00 2001 From: Christoph Schmidler Date: Wed, 20 Nov 2019 23:17:30 +0100 Subject: [PATCH 1/2] Draw vertical lines in compiler error messages with multiline annotations correctly when non-1space unicode characters are to the left For this we use the correct calculation of the 'left' identation --- src/librustc_errors/emitter.rs | 6 +++--- .../non-1-width-unicode-multiline-label.rs | 7 +++++++ .../non-1-width-unicode-multiline-label.stderr | 17 +++++++++++++++++ .../non-whitespace-trimming-unicode.stderr | 2 +- 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/terminal-width/non-1-width-unicode-multiline-label.rs create mode 100644 src/test/ui/terminal-width/non-1-width-unicode-multiline-label.stderr diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index ea779982ba961..451913757482a 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -835,7 +835,7 @@ impl EmitterWriter { return vec![]; } - // Write the colunmn separator. + // Write the column separator. // // After this we will have: // @@ -906,7 +906,7 @@ impl EmitterWriter { // | __________ // | | | // | | - // 3 | + // 3 | | // 4 | | } // | |_ for &(pos, annotation) in &annotations_position { @@ -920,7 +920,7 @@ impl EmitterWriter { if pos > 1 && (annotation.has_label() || annotation.takes_space()) { for p in line_offset + 1..=line_offset + pos { buffer.putc(p, - code_offset + annotation.start_col - margin.computed_left, + (code_offset + annotation.start_col).saturating_sub(left), '|', style); } diff --git a/src/test/ui/terminal-width/non-1-width-unicode-multiline-label.rs b/src/test/ui/terminal-width/non-1-width-unicode-multiline-label.rs new file mode 100644 index 0000000000000..cc94680530cf2 --- /dev/null +++ b/src/test/ui/terminal-width/non-1-width-unicode-multiline-label.rs @@ -0,0 +1,7 @@ +// ignore-tidy-linelength + +fn main() { + let unicode_is_fun = "؁‱ஹ௸௵꧄.ဪ꧅⸻𒈙𒐫﷽𒌄𒈟𒍼𒁎𒀱𒌧𒅃 𒈓𒍙𒊎𒄡𒅌𒁏𒀰𒐪𒐩𒈙𒐫𪚥"; + let _ = "ༀ༁༂༃༄༅༆༇༈༉༊་༌།༎༏༐༑༒༓༔༕༖༗༘༙༚༛༜༝༞༟༠༡༢༣༤༥༦༧༨༩༪༫༬༭༮༯༰༱༲༳༴༵༶༷༸༹༺༻༼༽༾༿ཀཁགགྷངཅཆཇ཈ཉཊཋཌཌྷཎཏཐདདྷནཔཕབབྷམཙཚཛཛྷཝཞཟའཡརལཤཥསཧཨཀྵཪཫཬ཭཮཯཰ཱཱཱིིུུྲྀཷླྀཹེཻོཽཾཿ྄ཱྀྀྂྃ྅྆྇ྈྉྊྋྌྍྎྏྐྑྒྒྷྔྕྖྗ྘ྙྚྛྜྜྷྞྟྠྡྡྷྣྤྥྦྦྷྨྩྪྫྫྷྭྮྯྰྱྲླྴྵྶྷྸྐྵྺྻྼ྽྾྿࿀࿁࿂࿃࿄࿅࿆࿇࿈࿉࿊࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!"; + //~^ ERROR binary operation `+` cannot be applied to type `&str` +} diff --git a/src/test/ui/terminal-width/non-1-width-unicode-multiline-label.stderr b/src/test/ui/terminal-width/non-1-width-unicode-multiline-label.stderr new file mode 100644 index 0000000000000..9f0f990670f2d --- /dev/null +++ b/src/test/ui/terminal-width/non-1-width-unicode-multiline-label.stderr @@ -0,0 +1,17 @@ +error[E0369]: binary operation `+` cannot be applied to type `&str` + --> $DIR/non-1-width-unicode-multiline-label.rs:5:260 + | +LL | ...ཽཾཿ྄ཱྀྀྂྃ྅྆྇ྈྉྊྋྌྍྎྏྐྑྒྒྷྔྕྖྗ྘ྙྚྛྜྜྷྞྟྠྡྡྷྣྤྥྦྦྷྨྩྪྫྫྷྭྮྯྰྱྲླྴྵྶྷྸྐྵྺྻྼ྽྾྿࿀࿁࿂࿃࿄࿅࿆࿇...࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!"; + | -------------- ^ -------------- &str + | | | + | | `+` cannot be used to concatenate two `&str` strings + | &str + | +help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left + | +LL | let _ = "ༀ༁༂༃༄༅༆༇༈༉༊་༌།༎༏༐༑༒༓༔༕༖༗༘༙༚༛༜༝༞༟༠༡༢༣༤༥༦༧༨༩༪༫༬༭༮༯༰༱༲༳༴༵༶༷༸༹༺༻༼༽༾༿ཀཁགགྷངཅཆཇ཈ཉཊཋཌཌྷཎཏཐདདྷནཔཕབབྷམཙཚཛཛྷཝཞཟའཡརལཤཥསཧཨཀྵཪཫཬ཭཮཯཰ཱཱཱིིུུྲྀཷླྀཹེཻོཽཾཿ྄ཱྀྀྂྃ྅྆྇ྈྉྊྋྌྍྎྏྐྑྒྒྷྔྕྖྗ྘ྙྚྛྜྜྷྞྟྠྡྡྷྣྤྥྦྦྷྨྩྪྫྫྷྭྮྯྰྱྲླྴྵྶྷྸྐྵྺྻྼ྽྾྿࿀࿁࿂࿃࿄࿅࿆࿇࿈࿉࿊࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun.to_owned() + " really fun!"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/terminal-width/non-whitespace-trimming-unicode.stderr b/src/test/ui/terminal-width/non-whitespace-trimming-unicode.stderr index d4993fad15c97..1e5ff9398321f 100644 --- a/src/test/ui/terminal-width/non-whitespace-trimming-unicode.stderr +++ b/src/test/ui/terminal-width/non-whitespace-trimming-unicode.stderr @@ -3,7 +3,7 @@ error[E0308]: mismatched types | LL | ...♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚈⚉4"; let _: () = 42; let _: &str = "🦀☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓ ☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼☽☾☿♀♁♂♃♄... | -- ^^ expected `()`, found integer - | | + | | | expected due to this error: aborting due to previous error From a678628e58d06f46413e91ed699cdbc938b96cac Mon Sep 17 00:00:00 2001 From: Christoph Schmidler Date: Mon, 9 Dec 2019 20:13:42 +0100 Subject: [PATCH 2/2] Update HashMap documentation hint of the used 'quadratic probing' and 'SIMD lookup' algorithms --- src/libstd/collections/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 522b8b25144f4..e8b9e9cb1f29c 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -433,7 +433,7 @@ mod hash; #[stable(feature = "rust1", since = "1.0.0")] pub mod hash_map { - //! A hash map implemented with linear probing and Robin Hood bucket stealing. + //! A hash map implemented with quadratic probing and SIMD lookup. #[stable(feature = "rust1", since = "1.0.0")] pub use super::hash::map::*; }