From e13eb37eeb3ccb447f33496fe86d77498558d2d5 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Sun, 14 Jul 2024 17:46:25 +0530 Subject: [PATCH 1/9] Fix malformed suggestion for repeated maybe unsized bounds --- compiler/rustc_hir/src/hir.rs | 24 ++- compiler/rustc_middle/src/ty/diagnostics.rs | 69 +++++-- ...tionf-for-repeated-unsized-bound-127441.rs | 39 ++++ ...f-for-repeated-unsized-bound-127441.stderr | 192 ++++++++++++++++++ 4 files changed, 295 insertions(+), 29 deletions(-) create mode 100644 tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs create mode 100644 tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index d57fad6ba4c2d..0f1b2bec6c648 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -723,7 +723,7 @@ impl<'hir> Generics<'hir> { ) } - fn span_for_predicate_removal(&self, pos: usize) -> Span { + pub fn span_for_predicate_removal(&self, pos: usize) -> Span { let predicate = &self.predicates[pos]; let span = predicate.span(); @@ -766,15 +766,21 @@ impl<'hir> Generics<'hir> { return self.span_for_predicate_removal(predicate_pos); } - let span = bounds[bound_pos].span(); - if bound_pos == 0 { - // where T: ?Sized + Bar, Foo: Bar, - // ^^^^^^^^^ - span.to(bounds[1].span().shrink_to_lo()) + let bound_span = bounds[bound_pos].span(); + if bound_pos < bounds.len() - 1 { + // If there's another bound after the current bound + // include the following '+' e.g.: + // + // `T: Foo + CurrentBound + Bar` + // ^^^^^^^^^^^^^^^ + bound_span.to(bounds[bound_pos + 1].span().shrink_to_lo()) } else { - // where T: Bar + ?Sized, Foo: Bar, - // ^^^^^^^^^ - bounds[bound_pos - 1].span().shrink_to_hi().to(span) + // If the current bound is the last bound + // include the preceding '+' E.g.: + // + // `T: Foo + Bar + CurrentBound` + // ^^^^^^^^^^^^^^^ + bound_span.with_lo(bounds[bound_pos - 1].span().hi()) } } } diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 4bf2233799130..3a5cb22be388f 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -188,31 +188,60 @@ fn suggest_changing_unsized_bound( continue; }; - for (pos, bound) in predicate.bounds.iter().enumerate() { - let hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) = bound else { - continue; - }; - if poly.trait_ref.trait_def_id() != def_id { - continue; - } - if predicate.origin == PredicateOrigin::ImplTrait && predicate.bounds.len() == 1 { - // For `impl ?Sized` with no other bounds, suggest `impl Sized` instead. - let bound_span = bound.span(); - if bound_span.can_be_used_for_suggestions() { - let question_span = bound_span.with_hi(bound_span.lo() + BytePos(1)); - suggestions.push(( + let unsized_bounds = predicate + .bounds + .iter() + .enumerate() + .filter(|(_, bound)| { + if let hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) = bound + && poly.trait_ref.trait_def_id() == def_id + { + true + } else { + false + } + }) + .collect::>(); + + if unsized_bounds.is_empty() { + continue; + } + + let mut push_suggestion = |sp, msg| suggestions.push((sp, String::new(), msg)); + + if predicate.bounds.len() == unsized_bounds.len() { + // All the bounds are unsized bounds, e.g. + // `T: ?Sized + ?Sized` or `_: impl ?Sized + ?Sized`, + // so in this case: + // - if it's an impl trait predicate suggest changing the + // the first bound to sized and removing the rest + // - Otherwise simply suggest removing the entire predicate + if predicate.origin == PredicateOrigin::ImplTrait { + let first_bound = unsized_bounds[0].1; + let first_bound_span = first_bound.span(); + if first_bound_span.can_be_used_for_suggestions() { + let question_span = + first_bound_span.with_hi(first_bound_span.lo() + BytePos(1)); + push_suggestion( question_span, - String::new(), SuggestChangingConstraintsMessage::ReplaceMaybeUnsizedWithSized, - )); + ); + + for (pos, _) in unsized_bounds.iter().skip(1) { + let sp = generics.span_for_bound_removal(where_pos, *pos); + push_suggestion(sp, SuggestChangingConstraintsMessage::RemoveMaybeUnsized); + } } } else { + let sp = generics.span_for_predicate_removal(where_pos); + push_suggestion(sp, SuggestChangingConstraintsMessage::RemoveMaybeUnsized); + } + } else { + // Some of the bounds are other than unsized. + // So push separate removal suggestion for each unsized bound + for (pos, _) in unsized_bounds { let sp = generics.span_for_bound_removal(where_pos, pos); - suggestions.push(( - sp, - String::new(), - SuggestChangingConstraintsMessage::RemoveMaybeUnsized, - )); + push_suggestion(sp, SuggestChangingConstraintsMessage::RemoveMaybeUnsized); } } } diff --git a/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs b/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs new file mode 100644 index 0000000000000..e6d7f74880fb2 --- /dev/null +++ b/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs @@ -0,0 +1,39 @@ +// Regression test for #127441 + +// Tests that we make the correct suggestion +// in case there are more than one `?Sized` +// bounds on a function parameter + +use std::fmt::Debug; + +fn foo1(a: T) {} +//~^ ERROR he size for values of type `T` cannot be known at compilation time + +fn foo2(a: T) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR the size for values of type `T` cannot be known at compilation time + +fn foo3(a: T) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR he size for values of type `T` cannot be known at compilation time + +fn foo4(a: T) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR the size for values of type `T` cannot be known at compilation time + +fn foo5(_: impl ?Sized) {} +//~^ ERROR the size for values of type `impl ?Sized` cannot be known at compilation time + +fn foo6(_: impl ?Sized + ?Sized) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR the size for values of type `impl ?Sized + ?Sized` cannot be known at compilation tim + +fn foo7(_: impl ?Sized + ?Sized + Debug) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR the size for values of type `impl ?Sized + ?Sized + Debug` cannot be known at compilation time + +fn foo8(_: impl ?Sized + Debug + ?Sized ) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR the size for values of type `impl ?Sized + Debug + ?Sized` cannot be known at compilation time + +fn main() {} diff --git a/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr b/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr new file mode 100644 index 0000000000000..3e8f45ee9fc26 --- /dev/null +++ b/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr @@ -0,0 +1,192 @@ +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:12:12 + | +LL | fn foo2(a: T) {} + | ^^^^^^ ^^^^^^ + +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:16:12 + | +LL | fn foo3(a: T) {} + | ^^^^^^ ^^^^^^ + +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:20:12 + | +LL | fn foo4(a: T) {} + | ^^^^^^ ^^^^^^ + +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:27:17 + | +LL | fn foo6(_: impl ?Sized + ?Sized) {} + | ^^^^^^ ^^^^^^ + +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:31:17 + | +LL | fn foo7(_: impl ?Sized + ?Sized + Debug) {} + | ^^^^^^ ^^^^^^ + +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:35:17 + | +LL | fn foo8(_: impl ?Sized + Debug + ?Sized ) {} + | ^^^^^^ ^^^^^^ + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:9:20 + | +LL | fn foo1(a: T) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `Sized` + | + = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL - fn foo1(a: T) {} +LL + fn foo1(a: T) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo1(a: &T) {} + | + + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:12:29 + | +LL | fn foo2(a: T) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `Sized` + | + = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL - fn foo2(a: T) {} +LL + fn foo2(a: T) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo2(a: &T) {} + | + + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:16:37 + | +LL | fn foo3(a: T) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `Sized` + | + = help: unsized fn params are gated as an unstable feature +help: consider restricting type parameters + | +LL - fn foo3(a: T) {} +LL + fn foo3(a: T) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo3(a: &T) {} + | + + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:20:38 + | +LL | fn foo4(a: T) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `Sized` + | + = help: unsized fn params are gated as an unstable feature +help: consider restricting type parameters + | +LL - fn foo4(a: T) {} +LL + fn foo4(a: T) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo4(a: &T) {} + | + + +error[E0277]: the size for values of type `impl ?Sized` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:24:9 + | +LL | fn foo5(_: impl ?Sized) {} + | ^ ----------- this type parameter needs to be `Sized` + | | + | doesn't have a size known at compile-time + | + = help: unsized fn params are gated as an unstable feature +help: consider replacing `?Sized` with `Sized` + | +LL - fn foo5(_: impl ?Sized) {} +LL + fn foo5(_: impl Sized) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo5(_: &impl ?Sized) {} + | + + +error[E0277]: the size for values of type `impl ?Sized + ?Sized` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:27:9 + | +LL | fn foo6(_: impl ?Sized + ?Sized) {} + | ^ -------------------- this type parameter needs to be `Sized` + | | + | doesn't have a size known at compile-time + | + = help: unsized fn params are gated as an unstable feature +help: consider restricting type parameters + | +LL - fn foo6(_: impl ?Sized + ?Sized) {} +LL + fn foo6(_: impl Sized) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo6(_: &impl ?Sized + ?Sized) {} + | + + +error[E0277]: the size for values of type `impl ?Sized + ?Sized + Debug` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:31:9 + | +LL | fn foo7(_: impl ?Sized + ?Sized + Debug) {} + | ^ ---------------------------- this type parameter needs to be `Sized` + | | + | doesn't have a size known at compile-time + | + = help: unsized fn params are gated as an unstable feature +help: consider restricting type parameters + | +LL - fn foo7(_: impl ?Sized + ?Sized + Debug) {} +LL + fn foo7(_: impl Debug) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo7(_: &impl ?Sized + ?Sized + Debug) {} + | + + +error[E0277]: the size for values of type `impl ?Sized + Debug + ?Sized` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:35:9 + | +LL | fn foo8(_: impl ?Sized + Debug + ?Sized ) {} + | ^ ---------------------------- this type parameter needs to be `Sized` + | | + | doesn't have a size known at compile-time + | + = help: unsized fn params are gated as an unstable feature +help: consider restricting type parameters + | +LL - fn foo8(_: impl ?Sized + Debug + ?Sized ) {} +LL + fn foo8(_: impl Debug ) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo8(_: &impl ?Sized + Debug + ?Sized ) {} + | + + +error: aborting due to 14 previous errors + +Some errors have detailed explanations: E0203, E0277. +For more information about an error, try `rustc --explain E0203`. From 89f273f40dafb693139496ed6f914872b6533fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 9 Jul 2024 16:46:09 +0000 Subject: [PATCH 2/9] Replace ASCII control chars with Unicode Control Pictures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` error: bare CR not allowed in doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32 | LL | /// doc comment with bare CR: '␍' | ^ ``` --- compiler/rustc_errors/src/emitter.rs | 69 ++++++++++++++---- ...-bare-cr-string-literal-doc-comment.stderr | 14 ++-- tests/ui/parser/bad-char-literals.rs | Bin 496 -> 608 bytes tests/ui/parser/bad-char-literals.stderr | 17 ++++- tests/ui/parser/issues/issue-66473.stderr | Bin 1061 -> 1209 bytes tests/ui/parser/issues/issue-68629.stderr | Bin 944 -> 976 bytes tests/ui/parser/issues/issue-68730.stderr | Bin 1266 -> 1294 bytes .../raw/raw-byte-string-literals.stderr | 2 +- ...ral-carriage-returns-in-doc-comment.stderr | 6 +- .../trailing-carriage-return-in-string.stderr | 2 +- tests/ui/parser/utf16-be-without-bom.stderr | Bin 3641 -> 4029 bytes tests/ui/parser/utf16-le-without-bom.stderr | Bin 3603 -> 3939 bytes .../rfc-3348-c-string-literals/no-nuls.stderr | Bin 2028 -> 2040 bytes tests/ui/str/str-escape.stderr | 2 +- 14 files changed, 81 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index aa47ca166764b..95e1b5348b733 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -677,10 +677,7 @@ impl HumanEmitter { .skip(left) .take_while(|ch| { // Make sure that the trimming on the right will fall within the terminal width. - // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` - // is. For now, just accept that sometimes the code line will be longer than - // desired. - let next = unicode_width::UnicodeWidthChar::width(*ch).unwrap_or(1); + let next = char_width(*ch); if taken + next > right - left { return false; } @@ -742,11 +739,7 @@ impl HumanEmitter { let left = margin.left(source_string.len()); // Account for unicode characters of width !=0 that were removed. - let left = source_string - .chars() - .take(left) - .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) - .sum(); + let left = source_string.chars().take(left).map(|ch| char_width(ch)).sum(); self.draw_line( buffer, @@ -2039,7 +2032,7 @@ impl HumanEmitter { let sub_len: usize = if is_whitespace_addition { &part.snippet } else { part.snippet.trim() } .chars() - .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) + .map(|ch| char_width(ch)) .sum(); let offset: isize = offsets @@ -2076,11 +2069,8 @@ impl HumanEmitter { } // length of the code after substitution - let full_sub_len = part - .snippet - .chars() - .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) - .sum::() as isize; + let full_sub_len = + part.snippet.chars().map(|ch| char_width(ch)).sum::() as isize; // length of the code to be substituted let snippet_len = span_end_pos as isize - span_start_pos as isize; @@ -2580,6 +2570,40 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[ ('\u{2068}', ""), ('\u{202C}', ""), ('\u{2069}', ""), + // In terminals without Unicode support the following will be garbled, but in *all* terminals + // the underlying codepoint will be as well. We could gate this replacement behind a "unicode + // support" gate. + ('\u{0000}', "␀"), + ('\u{0001}', "␁"), + ('\u{0002}', "␂"), + ('\u{0003}', "␃"), + ('\u{0004}', "␄"), + ('\u{0005}', "␅"), + ('\u{0006}', "␆"), + ('\u{0007}', "␇"), + ('\u{0008}', "␈"), + ('\u{000B}', "␋"), + ('\u{000C}', "␌"), + ('\u{000D}', "␍"), + ('\u{000E}', "␎"), + ('\u{000F}', "␏"), + ('\u{0010}', "␐"), + ('\u{0011}', "␑"), + ('\u{0012}', "␒"), + ('\u{0013}', "␓"), + ('\u{0014}', "␔"), + ('\u{0015}', "␕"), + ('\u{0016}', "␖"), + ('\u{0017}', "␗"), + ('\u{0018}', "␘"), + ('\u{0019}', "␙"), + ('\u{001A}', "␚"), + ('\u{001B}', "␛"), + ('\u{001C}', "␜"), + ('\u{001D}', "␝"), + ('\u{001E}', "␞"), + ('\u{001F}', "␟"), + ('\u{007F}', "␡"), ]; fn normalize_whitespace(str: &str) -> String { @@ -2590,6 +2614,21 @@ fn normalize_whitespace(str: &str) -> String { s } +fn char_width(ch: char) -> usize { + // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is. For now, + // just accept that sometimes the code line will be longer than desired. + match ch { + '\t' => 4, + '\u{0000}' | '\u{0001}' | '\u{0002}' | '\u{0003}' | '\u{0004}' | '\u{0005}' + | '\u{0006}' | '\u{0007}' | '\u{0008}' | '\u{000B}' | '\u{000C}' | '\u{000D}' + | '\u{000E}' | '\u{000F}' | '\u{0010}' | '\u{0011}' | '\u{0012}' | '\u{0013}' + | '\u{0014}' | '\u{0015}' | '\u{0016}' | '\u{0017}' | '\u{0018}' | '\u{0019}' + | '\u{001A}' | '\u{001B}' | '\u{001C}' | '\u{001D}' | '\u{001E}' | '\u{001F}' + | '\u{007F}' => 1, + _ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1), + } +} + fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) { buffer.puts(line, col, "| ", Style::LineNumber); } diff --git a/tests/ui/lexer/lex-bare-cr-string-literal-doc-comment.stderr b/tests/ui/lexer/lex-bare-cr-string-literal-doc-comment.stderr index da80991c727f7..841d5236edefa 100644 --- a/tests/ui/lexer/lex-bare-cr-string-literal-doc-comment.stderr +++ b/tests/ui/lexer/lex-bare-cr-string-literal-doc-comment.stderr @@ -1,31 +1,31 @@ error: bare CR not allowed in doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32 | -LL | /// doc comment with bare CR: ' ' +LL | /// doc comment with bare CR: '␍' | ^ error: bare CR not allowed in block doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:7:38 | -LL | /** block doc comment with bare CR: ' ' */ +LL | /** block doc comment with bare CR: '␍' */ | ^ error: bare CR not allowed in doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:12:36 | -LL | //! doc comment with bare CR: ' ' +LL | //! doc comment with bare CR: '␍' | ^ error: bare CR not allowed in block doc-comment --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:15:42 | -LL | /*! block doc comment with bare CR: ' ' */ +LL | /*! block doc comment with bare CR: '␍' */ | ^ error: bare CR not allowed in string, use `\r` instead --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:19:18 | -LL | let _s = "foo bar"; +LL | let _s = "foo␍bar"; | ^ | help: escape the character @@ -36,13 +36,13 @@ LL | let _s = "foo\rbar"; error: bare CR not allowed in raw string --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:22:19 | -LL | let _s = r"bar foo"; +LL | let _s = r"bar␍foo"; | ^ error: unknown character escape: `\r` --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:25:19 | -LL | let _s = "foo\ bar"; +LL | let _s = "foo\␍bar"; | ^ unknown character escape | = help: this is an isolated carriage return; consider checking your editor and version control settings diff --git a/tests/ui/parser/bad-char-literals.rs b/tests/ui/parser/bad-char-literals.rs index 748b4a22253f52301df92a22cf2b848ac6e4726f..c3d55d3f7e3bfbb53c98f8ce78ebfe4bff3fe477 100644 GIT binary patch delta 72 zcmeys{D5V{Oh#V6P#+&I1t3t@Wzd~$$0(telUb5ll$fKCn^>ukpO;gqker`al9-tX Yhy)h^ diff --git a/tests/ui/parser/bad-char-literals.stderr b/tests/ui/parser/bad-char-literals.stderr index 89253d7d4aacd..38889da5da12c 100644 --- a/tests/ui/parser/bad-char-literals.stderr +++ b/tests/ui/parser/bad-char-literals.stderr @@ -25,7 +25,7 @@ LL | '\n'; error: character constant must be escaped: `\r` --> $DIR/bad-char-literals.rs:15:6 | -LL | ' '; +LL | '␍'; | ^ | help: escape the character @@ -33,8 +33,19 @@ help: escape the character LL | '\r'; | ++ +error: character literal may only contain one codepoint + --> $DIR/bad-char-literals.rs:18:5 + | +LL | '-␀-'; + | ^^^^ + | +help: if you meant to write a string literal, use double quotes + | +LL | "-␀-"; + | ~ ~ + error: character constant must be escaped: `\t` - --> $DIR/bad-char-literals.rs:18:6 + --> $DIR/bad-char-literals.rs:21:6 | LL | ' '; | ^^^^ @@ -44,5 +55,5 @@ help: escape the character LL | '\t'; | ++ -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors diff --git a/tests/ui/parser/issues/issue-66473.stderr b/tests/ui/parser/issues/issue-66473.stderr index 0e8b0a5da220569b607fe3512ae59ee94e3fcf1b..4be992d58460ebac5cf5fa9ee562da839f670d59 100644 GIT binary patch delta 316 zcmZ3=v6FK`kjLc%1G?IY7gkKRWlpvu&rJ}U6m%#1F-wbKw_x%^W)}eZ C*Q@9N delta 126 zcmdnVxs+oi_@% diff --git a/tests/ui/parser/issues/issue-68629.stderr b/tests/ui/parser/issues/issue-68629.stderr index 2562baa1c49c3034012d9721c128aecc4303dc02..ccb0624208b2e20aee028a8efb2fd0fc25d61c94 100644 GIT binary patch delta 125 zcmdnMet~_0pV*@ba~@5YUsC*NLW5#-btadBfzJYy$AFGUfNioC3{rVF-bYSc#2xGDe<2@z@hRF@gqMK!zSQ(+By3D>1(EtFB CauJFE diff --git a/tests/ui/parser/issues/issue-68730.stderr b/tests/ui/parser/issues/issue-68730.stderr index 5bca5bbebeacb44984c8679e4d2c4757be4ee742..6025ea8c1ae7fbdec8c78ea332e3560ee2796981 100644 GIT binary patch delta 96 zcmeyw*~c{@kmJ#WhSXdjF){QBoITl=@dbjT$+Qc>dCruE-~=*HMsQv*_aZozER_HO CpD&UC delta 67 zcmeC<`ouXQkcA;NmtkV$6EHp5mGK3HVal`%!uZaV24SQ!PX;q4vGhU&rm|E50I|*! AssI20 diff --git a/tests/ui/parser/raw/raw-byte-string-literals.stderr b/tests/ui/parser/raw/raw-byte-string-literals.stderr index a2f27d1ed70ae..a20ce845c3268 100644 --- a/tests/ui/parser/raw/raw-byte-string-literals.stderr +++ b/tests/ui/parser/raw/raw-byte-string-literals.stderr @@ -1,7 +1,7 @@ error: bare CR not allowed in raw string --> $DIR/raw-byte-string-literals.rs:4:9 | -LL | br"a "; +LL | br"a␍"; | ^ error: non-ASCII character in raw byte string literal diff --git a/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr b/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr index 07066fc22e6cd..3150570e1c908 100644 --- a/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr +++ b/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr @@ -1,19 +1,19 @@ error: bare CR not allowed in doc-comment --> $DIR/several-carriage-returns-in-doc-comment.rs:6:12 | -LL | /// This do c comment contains three isolated `\r` symbols +LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols | ^ error: bare CR not allowed in doc-comment --> $DIR/several-carriage-returns-in-doc-comment.rs:6:32 | -LL | /// This do c comment contains three isolated `\r` symbols +LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols | ^ error: bare CR not allowed in doc-comment --> $DIR/several-carriage-returns-in-doc-comment.rs:6:52 | -LL | /// This do c comment contains three isolated `\r` symbols +LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols | ^ error: aborting due to 3 previous errors diff --git a/tests/ui/parser/trailing-carriage-return-in-string.stderr b/tests/ui/parser/trailing-carriage-return-in-string.stderr index fa2677921b32d..c5949432af893 100644 --- a/tests/ui/parser/trailing-carriage-return-in-string.stderr +++ b/tests/ui/parser/trailing-carriage-return-in-string.stderr @@ -1,7 +1,7 @@ error: unknown character escape: `\r` --> $DIR/trailing-carriage-return-in-string.rs:10:25 | -LL | let bad = "This is \ a test"; +LL | let bad = "This is \␍ a test"; | ^ unknown character escape | = help: this is an isolated carriage return; consider checking your editor and version control settings diff --git a/tests/ui/parser/utf16-be-without-bom.stderr b/tests/ui/parser/utf16-be-without-bom.stderr index c041f3ecf53b22d8bfd994f7a8c24d583594e027..28cf6d97e96c2a8d08d193f97d4289da04c2aa38 100644 GIT binary patch literal 4029 zcmds)%}T>S6ovPBiX*sCFlx2_1#~5X;7W8SC24YFhNg4N{8&p>d<37-C-J6%;z|@| zA+tCzOfvV*{T7EgWDJ`OUQaa7HLNR)1J`goA)VpDFZW*)AWbi@d3k-i=UqKGPREqa zm223$bj;ITW3yp4kl*l<+}z*=pC9kFNQ=7lR8)wRsN35TZHu~ZOVO)nbsD3-h*Ua9 zL+vbsWp7GCty;2}dh1ZKc7@Wozq?9LLAvCMDmZ#}J2D47&!}{=p?%w8yl~wy_1MT% zW$6v(4QUjpR9%xH?fL>rKSEh}OI4CkFeZl~n8XILR5=|iMjgn0$1CA0-FdL4M&OtaYjuKBmLynS9NLT)MfYy18HFd!<-^jrR zd6wlnsM+fZxz6R4_lt-*4DuKp;fFi*9s1}gLDQ;=3=B>Asf&oNA=p_VdDO8iND}6R r7IQW-M7^5gdjkG@{C#^{r_W-{#&ta_zv?y^VrJ+`vA0+SRGTDUM5ECC literal 3641 zcmds)OG^VW6os>%UvUH%3LUjtUjw=lLFh_!CuOEHcRHbMZpot$+WOl~Td2FzfD6ek z2{$+QoW&s@Y0Wx=Q$xiw1!D_s!8I%oNoDwQ%d2$)r0FwGU*6s?ovqti?KU02lyz~ z7o`JX@fW29fgu>92iKuV7^MlpaTuiw;hFgFY}j)JE81XCev*SV@+`|+sM)Csxyt?D z=LjI`1bmTtIPmhW&kmG478zNQhNdx3H$Y<>f|(Sao-F$Xc^(?lV#eB!T5o6lrLsd% e_WiwQqN2~*ZhBX4+qK=nMAKBVGuUF2Ns=Enq*san diff --git a/tests/ui/parser/utf16-le-without-bom.stderr b/tests/ui/parser/utf16-le-without-bom.stderr index cc2220441ac1073c755b178c4da74085faedd2a1..53004ac942d988ea867e0ea7573b4ffd6cfbd026 100644 GIT binary patch literal 3939 zcmds)%SyvQ6o&VCieGS{V6@R%B%mu11XrRvk)+9q8Jf;1bFqpSd<37-C-J0((v^6b zh0NlIkYr|ZzQs>IGKNhKuP2)48rGG@fg3oUkj`=Ap9U`pkftZtJUzeM^RCH8X-DZ? zxt6_4$2{FNHXr8u@*19#iwiuX`FMZR5=f?!QlcdNy)DVMq<{7#d66uZ0=LU8WS?WS z)Xj2O_NF2sp-L*1P zRe6JXOBy9=)ih*CyX6K--$7Y;OLdY^Fe1ah6NwGUC;*b!m>h**5*w6k5QIu}SOT=H z)N6EAn}z7wD8U42+$hO}>D?I7><22}DA|N+;3(k)tKsJ1a#U x9m@rY3{L2A&PFC^79*@w_2-`Y`ns~ja?Hl{2iAUZR5rxS(7j@Bu@Fg{B%hBqn&$uj literal 3603 zcmds)PfNo<5XE!Or+9(~g+`6mA^|;#Ab1kJi6l)XW@)+;_K#_4^|QNerSzm-@F08J zER)%J@9>x(Da9&-l@rOmgf@jT;2MS}Bs09&#o0#;B*_g9Z|@&Zt*O&d(o)h3)37zk zn5QR7XT$8=m0=k_JYb1Bk`bb5R7Ap^j-q4twTM2VbqVmgDRuSNXsGQnXtt^()S@Mg zsnrH0OH&Am=cl{m3M5OesDh!H8MtX_)=_EPg|uyp@!YI_6K{>1y)3Ol-;hLsO4Kze zl4jFD$TtWLtEq}(`ZMLj{gsC%edHlMH0@VD+Cvkco_VPcPQFLlxtI$s@=~A73(^3u zG$4h0846SqZ*Z{r|M-Z<&E5tq> Date: Tue, 9 Jul 2024 17:00:19 +0000 Subject: [PATCH 3/9] Be more accurate about calculating `display_col` from a `BytePos` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No longer track "zero-width" chars in `SourceMap`, read directly from the line when calculating the `display_col` of a `BytePos`. Move `char_width` to `rustc_span` and use it from the emitter. This change allows the following to properly align in terminals (depending on the font, the replaced control codepoints are rendered as 1 or 2 width, on my terminal they are rendered as 1, on VSCode text they are rendered as 2): ``` error: this file contains an unclosed delimiter --> $DIR/issue-68629.rs:5:17 | LL | ␜␟ts␀![{i | -- unclosed delimiter | | | unclosed delimiter LL | ␀␀ fn rݻoa>rݻm | ^ ``` --- Cargo.lock | 1 - compiler/rustc_errors/Cargo.toml | 1 - compiler/rustc_errors/src/emitter.rs | 17 +-- compiler/rustc_metadata/src/rmeta/decoder.rs | 2 - .../src/ich/impls_syntax.rs | 6 - .../rustc_span/src/analyze_source_file.rs | 40 +----- .../src/analyze_source_file/tests.rs | 24 +--- compiler/rustc_span/src/lib.rs | 133 +++++------------- compiler/rustc_span/src/source_map.rs | 2 - compiler/rustc_span/src/source_map/tests.rs | 2 - .../doctest/test-compile-fail3.stderr | 2 +- tests/ui/codemap_tests/tab_2.stderr | 2 +- tests/ui/error-codes/E0601.stderr | 2 +- tests/ui/issues/issue-44078.stderr | 2 +- tests/ui/lexer/unterminated-comment.stderr | 2 +- .../lexer/unterminated-nested-comment.stderr | 2 +- tests/ui/lint/issue-104897.stderr | 2 +- ...07423-unused-delim-only-one-no-pair.stderr | 2 +- tests/ui/parser/bad-char-literals.stderr | 4 +- tests/ui/parser/brace-in-let-chain.stderr | 2 +- tests/ui/parser/byte-string-literals.stderr | 2 +- tests/ui/parser/deli-ident-issue-1.stderr | 2 +- tests/ui/parser/issues/issue-103451.stderr | 2 +- tests/ui/parser/issues/issue-104367.stderr | 2 +- tests/ui/parser/issues/issue-105209.stderr | 2 +- tests/ui/parser/issues/issue-107705.stderr | 2 +- tests/ui/parser/issues/issue-2354.stderr | 2 +- tests/ui/parser/issues/issue-62546.stderr | 2 +- tests/ui/parser/issues/issue-62554.stderr | 2 +- tests/ui/parser/issues/issue-62881.stderr | 2 +- tests/ui/parser/issues/issue-62894.stderr | 2 +- tests/ui/parser/issues/issue-62973.stderr | 2 +- tests/ui/parser/issues/issue-63116.stderr | 2 +- tests/ui/parser/issues/issue-63135.stderr | 2 +- tests/ui/parser/issues/issue-66473.stderr | 10 +- ...invalid-syntax-in-enum-discriminant.stderr | 2 +- tests/ui/parser/issues/issue-68629.stderr | 14 +- tests/ui/parser/issues/issue-68730.stderr | 12 +- tests/ui/parser/issues/issue-81804.stderr | 2 +- tests/ui/parser/issues/issue-81827.stderr | 2 +- tests/ui/parser/issues/issue-84104.stderr | 2 +- tests/ui/parser/issues/issue-84148-2.stderr | 2 +- tests/ui/parser/issues/issue-88770.stderr | 2 +- .../missing-close-brace-in-impl-trait.stderr | 2 +- .../missing-close-brace-in-struct.stderr | 2 +- .../missing-close-brace-in-trait.stderr | 2 +- .../parser-ice-ed2021-await-105210.stderr | 2 +- tests/ui/parser/parser-recovery-1.stderr | 2 +- ...ral-carriage-returns-in-doc-comment.stderr | 4 +- tests/ui/parser/unbalanced-doublequote.stderr | 2 +- tests/ui/parser/unclosed-braces.stderr | 2 +- .../unmatched-delimiter-at-end-of-file.stderr | 2 +- tests/ui/parser/use-unclosed-brace.stderr | 2 +- tests/ui/parser/utf16-be-without-bom.stderr | 28 ++-- tests/ui/parser/utf16-le-without-bom.stderr | 24 ++-- .../rustdoc/unterminated-doc-comment.stderr | 2 +- ...incompatible-closure-captures-93117.stderr | 2 +- tests/ui/str/str-escape.stderr | 4 +- tests/ui/suggestions/issue-94171.stderr | 2 +- tests/ui/typeck/issue-91334.stderr | 2 +- 60 files changed, 134 insertions(+), 278 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c1607e4c1ac4..d6060992ef21d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4008,7 +4008,6 @@ dependencies = [ "termcolor", "termize", "tracing", - "unicode-width", "windows", ] diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index cc114fdcd8c35..2fff9f2de50fb 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -26,7 +26,6 @@ serde_json = "1.0.59" termcolor = "1.2.0" termize = "0.1.1" tracing = "0.1" -unicode-width = "0.1.4" # tidy-alphabetical-end [target.'cfg(windows)'.dependencies.windows] diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 95e1b5348b733..16fa0ff7a2d6c 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -8,7 +8,7 @@ //! The output types are defined in `rustc_session::config::ErrorOutputType`. use rustc_span::source_map::SourceMap; -use rustc_span::{FileLines, FileName, SourceFile, Span}; +use rustc_span::{char_width, FileLines, FileName, SourceFile, Span}; use crate::snippet::{ Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString, @@ -2614,21 +2614,6 @@ fn normalize_whitespace(str: &str) -> String { s } -fn char_width(ch: char) -> usize { - // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is. For now, - // just accept that sometimes the code line will be longer than desired. - match ch { - '\t' => 4, - '\u{0000}' | '\u{0001}' | '\u{0002}' | '\u{0003}' | '\u{0004}' | '\u{0005}' - | '\u{0006}' | '\u{0007}' | '\u{0008}' | '\u{000B}' | '\u{000C}' | '\u{000D}' - | '\u{000E}' | '\u{000F}' | '\u{0010}' | '\u{0011}' | '\u{0012}' | '\u{0013}' - | '\u{0014}' | '\u{0015}' | '\u{0016}' | '\u{0017}' | '\u{0018}' | '\u{0019}' - | '\u{001A}' | '\u{001B}' | '\u{001C}' | '\u{001D}' | '\u{001E}' | '\u{001F}' - | '\u{007F}' => 1, - _ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1), - } -} - fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) { buffer.puts(line, col, "| ", Style::LineNumber); } diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 0ba9b940eed10..9f2fe2547538a 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1727,7 +1727,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { source_len, lines, multibyte_chars, - non_narrow_chars, normalized_pos, stable_id, .. @@ -1779,7 +1778,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { self.cnum, lines, multibyte_chars, - non_narrow_chars, normalized_pos, source_file_index, ); diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs index 5bd4fe04848fb..39da5e395c42d 100644 --- a/compiler/rustc_query_system/src/ich/impls_syntax.rs +++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs @@ -73,7 +73,6 @@ impl<'a> HashStable> for SourceFile { source_len: _, lines: _, ref multibyte_chars, - ref non_narrow_chars, ref normalized_pos, } = *self; @@ -98,11 +97,6 @@ impl<'a> HashStable> for SourceFile { char_pos.hash_stable(hcx, hasher); } - non_narrow_chars.len().hash_stable(hcx, hasher); - for &char_pos in non_narrow_chars.iter() { - char_pos.hash_stable(hcx, hasher); - } - normalized_pos.len().hash_stable(hcx, hasher); for &char_pos in normalized_pos.iter() { char_pos.hash_stable(hcx, hasher); diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs index d9e1ebaf0bce0..ba7e0cec5bd80 100644 --- a/compiler/rustc_span/src/analyze_source_file.rs +++ b/compiler/rustc_span/src/analyze_source_file.rs @@ -1,5 +1,4 @@ use super::*; -use unicode_width::UnicodeWidthChar; #[cfg(test)] mod tests; @@ -9,15 +8,12 @@ mod tests; /// /// This function will use an SSE2 enhanced implementation if hardware support /// is detected at runtime. -pub fn analyze_source_file( - src: &str, -) -> (Vec, Vec, Vec) { +pub fn analyze_source_file(src: &str) -> (Vec, Vec) { let mut lines = vec![RelativeBytePos::from_u32(0)]; let mut multi_byte_chars = vec![]; - let mut non_narrow_chars = vec![]; // Calls the right implementation, depending on hardware support available. - analyze_source_file_dispatch(src, &mut lines, &mut multi_byte_chars, &mut non_narrow_chars); + analyze_source_file_dispatch(src, &mut lines, &mut multi_byte_chars); // The code above optimistically registers a new line *after* each \n // it encounters. If that point is already outside the source_file, remove @@ -30,7 +26,7 @@ pub fn analyze_source_file( } } - (lines, multi_byte_chars, non_narrow_chars) + (lines, multi_byte_chars) } cfg_match! { @@ -39,11 +35,10 @@ cfg_match! { src: &str, lines: &mut Vec, multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec, ) { if is_x86_feature_detected!("sse2") { unsafe { - analyze_source_file_sse2(src, lines, multi_byte_chars, non_narrow_chars); + analyze_source_file_sse2(src, lines, multi_byte_chars); } } else { analyze_source_file_generic( @@ -52,7 +47,6 @@ cfg_match! { RelativeBytePos::from_u32(0), lines, multi_byte_chars, - non_narrow_chars, ); } } @@ -66,7 +60,6 @@ cfg_match! { src: &str, lines: &mut Vec, multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec, ) { #[cfg(target_arch = "x86")] use std::arch::x86::*; @@ -159,7 +152,6 @@ cfg_match! { RelativeBytePos::from_usize(scan_start), lines, multi_byte_chars, - non_narrow_chars, ); } @@ -172,7 +164,6 @@ cfg_match! { RelativeBytePos::from_usize(tail_start), lines, multi_byte_chars, - non_narrow_chars, ); } } @@ -183,7 +174,6 @@ cfg_match! { src: &str, lines: &mut Vec, multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec, ) { analyze_source_file_generic( src, @@ -191,7 +181,6 @@ cfg_match! { RelativeBytePos::from_u32(0), lines, multi_byte_chars, - non_narrow_chars, ); } } @@ -205,7 +194,6 @@ fn analyze_source_file_generic( output_offset: RelativeBytePos, lines: &mut Vec, multi_byte_chars: &mut Vec, - non_narrow_chars: &mut Vec, ) -> usize { assert!(src.len() >= scan_len); let mut i = 0; @@ -227,16 +215,8 @@ fn analyze_source_file_generic( let pos = RelativeBytePos::from_usize(i) + output_offset; - match byte { - b'\n' => { - lines.push(pos + RelativeBytePos(1)); - } - b'\t' => { - non_narrow_chars.push(NonNarrowChar::Tab(pos)); - } - _ => { - non_narrow_chars.push(NonNarrowChar::ZeroWidth(pos)); - } + if let b'\n' = byte { + lines.push(pos + RelativeBytePos(1)); } } else if byte >= 127 { // The slow path: @@ -252,14 +232,6 @@ fn analyze_source_file_generic( let mbc = MultiByteChar { pos, bytes: char_len as u8 }; multi_byte_chars.push(mbc); } - - // Assume control characters are zero width. - // FIXME: How can we decide between `width` and `width_cjk`? - let char_width = UnicodeWidthChar::width(c).unwrap_or(0); - - if char_width != 1 { - non_narrow_chars.push(NonNarrowChar::new(pos, char_width)); - } } i += char_len; diff --git a/compiler/rustc_span/src/analyze_source_file/tests.rs b/compiler/rustc_span/src/analyze_source_file/tests.rs index 0c77d080c17a0..e4a24239d8ea1 100644 --- a/compiler/rustc_span/src/analyze_source_file/tests.rs +++ b/compiler/rustc_span/src/analyze_source_file/tests.rs @@ -4,11 +4,10 @@ macro_rules! test { (case: $test_name:ident, text: $text:expr, lines: $lines:expr, - multi_byte_chars: $multi_byte_chars:expr, - non_narrow_chars: $non_narrow_chars:expr,) => { + multi_byte_chars: $multi_byte_chars:expr,) => { #[test] fn $test_name() { - let (lines, multi_byte_chars, non_narrow_chars) = analyze_source_file($text); + let (lines, multi_byte_chars) = analyze_source_file($text); let expected_lines: Vec = $lines.into_iter().map(RelativeBytePos).collect(); @@ -21,13 +20,6 @@ macro_rules! test { .collect(); assert_eq!(multi_byte_chars, expected_mbcs); - - let expected_nncs: Vec = $non_narrow_chars - .into_iter() - .map(|(pos, width)| NonNarrowChar::new(RelativeBytePos(pos), width)) - .collect(); - - assert_eq!(non_narrow_chars, expected_nncs); } }; } @@ -37,7 +29,6 @@ test!( text: "", lines: vec![], multi_byte_chars: vec![], - non_narrow_chars: vec![], ); test!( @@ -45,7 +36,6 @@ test!( text: "a\nc", lines: vec![0, 2], multi_byte_chars: vec![], - non_narrow_chars: vec![], ); test!( @@ -53,7 +43,6 @@ test!( text: "012345678\nabcdef012345678\na", lines: vec![0, 10, 26], multi_byte_chars: vec![], - non_narrow_chars: vec![], ); test!( @@ -61,7 +50,6 @@ test!( text: "01234β789\nbcdef0123456789abcdef", lines: vec![0, 11], multi_byte_chars: vec![(5, 2)], - non_narrow_chars: vec![], ); test!( @@ -69,7 +57,6 @@ test!( text: "01234\u{07}6789\nbcdef0123456789abcdef", lines: vec![0, 11], multi_byte_chars: vec![], - non_narrow_chars: vec![(5, 0)], ); test!( @@ -77,7 +64,6 @@ test!( text: "aβc", lines: vec![0], multi_byte_chars: vec![(1, 2)], - non_narrow_chars: vec![], ); test!( @@ -85,7 +71,6 @@ test!( text: "0123456789abcΔf012345β", lines: vec![0], multi_byte_chars: vec![(13, 2), (22, 2)], - non_narrow_chars: vec![], ); test!( @@ -93,7 +78,6 @@ test!( text: "0123456789abcdeΔ123456789abcdef01234", lines: vec![0], multi_byte_chars: vec![(15, 2)], - non_narrow_chars: vec![], ); test!( @@ -101,7 +85,6 @@ test!( text: "0123456789abcdeΔ....", lines: vec![0], multi_byte_chars: vec![(15, 2)], - non_narrow_chars: vec![], ); test!( @@ -109,7 +92,6 @@ test!( text: "0\t2", lines: vec![0], multi_byte_chars: vec![], - non_narrow_chars: vec![(1, 4)], ); test!( @@ -117,7 +99,6 @@ test!( text: "01\t3456789abcdef01234567\u{07}9", lines: vec![0], multi_byte_chars: vec![], - non_narrow_chars: vec![(2, 4), (24, 0)], ); test!( @@ -125,5 +106,4 @@ test!( text: "01\t345\n789abcΔf01234567\u{07}9\nbcΔf", lines: vec![0, 7, 27], multi_byte_chars: vec![(13, 2), (29, 2)], - non_narrow_chars: vec![(2, 4), (24, 0)], ); diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 266956d63d710..ea57c1ce8185b 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1345,68 +1345,6 @@ pub struct MultiByteChar { pub bytes: u8, } -/// Identifies an offset of a non-narrow character in a `SourceFile`. -#[derive(Copy, Clone, Encodable, Decodable, Eq, PartialEq, Debug, HashStable_Generic)] -pub enum NonNarrowChar { - /// Represents a zero-width character. - ZeroWidth(RelativeBytePos), - /// Represents a wide (full-width) character. - Wide(RelativeBytePos), - /// Represents a tab character, represented visually with a width of 4 characters. - Tab(RelativeBytePos), -} - -impl NonNarrowChar { - fn new(pos: RelativeBytePos, width: usize) -> Self { - match width { - 0 => NonNarrowChar::ZeroWidth(pos), - 2 => NonNarrowChar::Wide(pos), - 4 => NonNarrowChar::Tab(pos), - _ => panic!("width {width} given for non-narrow character"), - } - } - - /// Returns the relative offset of the character in the `SourceFile`. - pub fn pos(&self) -> RelativeBytePos { - match *self { - NonNarrowChar::ZeroWidth(p) | NonNarrowChar::Wide(p) | NonNarrowChar::Tab(p) => p, - } - } - - /// Returns the width of the character, 0 (zero-width) or 2 (wide). - pub fn width(&self) -> usize { - match *self { - NonNarrowChar::ZeroWidth(_) => 0, - NonNarrowChar::Wide(_) => 2, - NonNarrowChar::Tab(_) => 4, - } - } -} - -impl Add for NonNarrowChar { - type Output = Self; - - fn add(self, rhs: RelativeBytePos) -> Self { - match self { - NonNarrowChar::ZeroWidth(pos) => NonNarrowChar::ZeroWidth(pos + rhs), - NonNarrowChar::Wide(pos) => NonNarrowChar::Wide(pos + rhs), - NonNarrowChar::Tab(pos) => NonNarrowChar::Tab(pos + rhs), - } - } -} - -impl Sub for NonNarrowChar { - type Output = Self; - - fn sub(self, rhs: RelativeBytePos) -> Self { - match self { - NonNarrowChar::ZeroWidth(pos) => NonNarrowChar::ZeroWidth(pos - rhs), - NonNarrowChar::Wide(pos) => NonNarrowChar::Wide(pos - rhs), - NonNarrowChar::Tab(pos) => NonNarrowChar::Tab(pos - rhs), - } - } -} - /// Identifies an offset of a character that was normalized away from `SourceFile`. #[derive(Copy, Clone, Encodable, Decodable, Eq, PartialEq, Debug, HashStable_Generic)] pub struct NormalizedPos { @@ -1581,8 +1519,6 @@ pub struct SourceFile { pub lines: FreezeLock, /// Locations of multi-byte characters in the source code. pub multibyte_chars: Vec, - /// Width of characters that are not narrow in the source code. - pub non_narrow_chars: Vec, /// Locations of characters removed during normalization. pub normalized_pos: Vec, /// A hash of the filename & crate-id, used for uniquely identifying source @@ -1604,7 +1540,6 @@ impl Clone for SourceFile { source_len: self.source_len, lines: self.lines.clone(), multibyte_chars: self.multibyte_chars.clone(), - non_narrow_chars: self.non_narrow_chars.clone(), normalized_pos: self.normalized_pos.clone(), stable_id: self.stable_id, cnum: self.cnum, @@ -1679,7 +1614,6 @@ impl Encodable for SourceFile { } self.multibyte_chars.encode(s); - self.non_narrow_chars.encode(s); self.stable_id.encode(s); self.normalized_pos.encode(s); self.cnum.encode(s); @@ -1706,7 +1640,6 @@ impl Decodable for SourceFile { } }; let multibyte_chars: Vec = Decodable::decode(d); - let non_narrow_chars: Vec = Decodable::decode(d); let stable_id = Decodable::decode(d); let normalized_pos: Vec = Decodable::decode(d); let cnum: CrateNum = Decodable::decode(d); @@ -1721,7 +1654,6 @@ impl Decodable for SourceFile { external_src: FreezeLock::frozen(ExternalSource::Unneeded), lines: FreezeLock::new(lines), multibyte_chars, - non_narrow_chars, normalized_pos, stable_id, cnum, @@ -1809,8 +1741,7 @@ impl SourceFile { let source_len = src.len(); let source_len = u32::try_from(source_len).map_err(|_| OffsetOverflowError)?; - let (lines, multibyte_chars, non_narrow_chars) = - analyze_source_file::analyze_source_file(&src); + let (lines, multibyte_chars) = analyze_source_file::analyze_source_file(&src); Ok(SourceFile { name, @@ -1821,7 +1752,6 @@ impl SourceFile { source_len: RelativeBytePos::from_u32(source_len), lines: FreezeLock::frozen(SourceFileLines::Lines(lines)), multibyte_chars, - non_narrow_chars, normalized_pos, stable_id, cnum: LOCAL_CRATE, @@ -2130,41 +2060,44 @@ impl SourceFile { let pos = self.relative_position(pos); let (line, col_or_chpos) = self.lookup_file_pos(pos); if line > 0 { - let col = col_or_chpos; - let linebpos = self.lines()[line - 1]; - let col_display = { - let start_width_idx = self - .non_narrow_chars - .binary_search_by_key(&linebpos, |x| x.pos()) - .unwrap_or_else(|x| x); - let end_width_idx = self - .non_narrow_chars - .binary_search_by_key(&pos, |x| x.pos()) - .unwrap_or_else(|x| x); - let special_chars = end_width_idx - start_width_idx; - let non_narrow: usize = self.non_narrow_chars[start_width_idx..end_width_idx] - .iter() - .map(|x| x.width()) - .sum(); - col.0 - special_chars + non_narrow + let Some(code) = self.get_line(line - 1) else { + // If we don't have the code available, it is ok as a fallback to return the bytepos + // instead of the "display" column, which is only used to properly show underlines + // in the terminal. + // FIXME: we'll want better handling of this in the future for the sake of tools + // that want to use the display col instead of byte offsets to modify Rust code, but + // that is a problem for another day, the previous code was already incorrect for + // both displaying *and* third party tools using the json output naïvely. + tracing::info!("couldn't find line {line} {:?}", self.name); + return (line, col_or_chpos, col_or_chpos.0); }; - (line, col, col_display) + let display_col = code.chars().take(col_or_chpos.0).map(|ch| char_width(ch)).sum(); + (line, col_or_chpos, display_col) } else { - let chpos = col_or_chpos; - let col_display = { - let end_width_idx = self - .non_narrow_chars - .binary_search_by_key(&pos, |x| x.pos()) - .unwrap_or_else(|x| x); - let non_narrow: usize = - self.non_narrow_chars[0..end_width_idx].iter().map(|x| x.width()).sum(); - chpos.0 - end_width_idx + non_narrow - }; - (0, chpos, col_display) + // This is never meant to happen? + (0, col_or_chpos, col_or_chpos.0) } } } +pub fn char_width(ch: char) -> usize { + // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is. For now, + // just accept that sometimes the code line will be longer than desired. + match ch { + '\t' => 4, + // Keep the following list in sync with `rustc_errors::emitter::OUTPUT_REPLACEMENTS`. These + // are control points that we replace before printing with a visible codepoint for the sake + // of being able to point at them with underlines. + '\u{0000}' | '\u{0001}' | '\u{0002}' | '\u{0003}' | '\u{0004}' | '\u{0005}' + | '\u{0006}' | '\u{0007}' | '\u{0008}' | '\u{000B}' | '\u{000C}' | '\u{000D}' + | '\u{000E}' | '\u{000F}' | '\u{0010}' | '\u{0011}' | '\u{0012}' | '\u{0013}' + | '\u{0014}' | '\u{0015}' | '\u{0016}' | '\u{0017}' | '\u{0018}' | '\u{0019}' + | '\u{001A}' | '\u{001B}' | '\u{001C}' | '\u{001D}' | '\u{001E}' | '\u{001F}' + | '\u{007F}' => 1, + _ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1), + } +} + /// Normalizes the source code and records the normalizations. fn normalize_src(src: &mut String) -> Vec { let mut normalized_pos = vec![]; diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index fb212d67997a7..14c157a0111ce 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -330,7 +330,6 @@ impl SourceMap { cnum: CrateNum, file_local_lines: FreezeLock, multibyte_chars: Vec, - non_narrow_chars: Vec, normalized_pos: Vec, metadata_index: u32, ) -> Lrc { @@ -348,7 +347,6 @@ impl SourceMap { source_len, lines: file_local_lines, multibyte_chars, - non_narrow_chars, normalized_pos, stable_id, cnum, diff --git a/compiler/rustc_span/src/source_map/tests.rs b/compiler/rustc_span/src/source_map/tests.rs index dcb02da371921..0c818b94b85a3 100644 --- a/compiler/rustc_span/src/source_map/tests.rs +++ b/compiler/rustc_span/src/source_map/tests.rs @@ -232,7 +232,6 @@ fn t10() { source_len, lines, multibyte_chars, - non_narrow_chars, normalized_pos, stable_id, .. @@ -246,7 +245,6 @@ fn t10() { CrateNum::ZERO, FreezeLock::new(lines.read().clone()), multibyte_chars, - non_narrow_chars, normalized_pos, 0, ); diff --git a/tests/rustdoc-ui/doctest/test-compile-fail3.stderr b/tests/rustdoc-ui/doctest/test-compile-fail3.stderr index 1ed4554225116..09d78b2f34673 100644 --- a/tests/rustdoc-ui/doctest/test-compile-fail3.stderr +++ b/tests/rustdoc-ui/doctest/test-compile-fail3.stderr @@ -2,7 +2,7 @@ error[E0765]: unterminated double quote string --> $DIR/test-compile-fail3.rs:3:1 | 3 | "fail - | ^^^^^^ + | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/codemap_tests/tab_2.stderr b/tests/ui/codemap_tests/tab_2.stderr index 4f9a937155dde..b22c7b4266517 100644 --- a/tests/ui/codemap_tests/tab_2.stderr +++ b/tests/ui/codemap_tests/tab_2.stderr @@ -4,7 +4,7 @@ error[E0765]: unterminated double quote string LL | """; | ___________________^ LL | | } - | |__^ + | |_^ error: aborting due to 1 previous error diff --git a/tests/ui/error-codes/E0601.stderr b/tests/ui/error-codes/E0601.stderr index 41a4a8f7dbbaa..c051bc0b31a0f 100644 --- a/tests/ui/error-codes/E0601.stderr +++ b/tests/ui/error-codes/E0601.stderr @@ -2,7 +2,7 @@ error[E0601]: `main` function not found in crate `E0601` --> $DIR/E0601.rs:1:37 | LL | - | ^ consider adding a `main` function to `$DIR/E0601.rs` + | ^ consider adding a `main` function to `$DIR/E0601.rs` error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-44078.stderr b/tests/ui/issues/issue-44078.stderr index 3e12de34e11ee..41106b29aad78 100644 --- a/tests/ui/issues/issue-44078.stderr +++ b/tests/ui/issues/issue-44078.stderr @@ -4,7 +4,7 @@ error[E0765]: unterminated double quote string LL | "😊""; | _________^ LL | | } - | |__^ + | |_^ error: aborting due to 1 previous error diff --git a/tests/ui/lexer/unterminated-comment.stderr b/tests/ui/lexer/unterminated-comment.stderr index ea65bffd10368..6ab5441ee05ce 100644 --- a/tests/ui/lexer/unterminated-comment.stderr +++ b/tests/ui/lexer/unterminated-comment.stderr @@ -2,7 +2,7 @@ error[E0758]: unterminated block comment --> $DIR/unterminated-comment.rs:1:1 | LL | /* - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/lexer/unterminated-nested-comment.stderr b/tests/ui/lexer/unterminated-nested-comment.stderr index 9117b689c94e3..78b72ce1fe4a0 100644 --- a/tests/ui/lexer/unterminated-nested-comment.stderr +++ b/tests/ui/lexer/unterminated-nested-comment.stderr @@ -12,7 +12,7 @@ LL | | /* | | | | | ...as last nested comment starts here, maybe you want to close this instead? LL | | */ - | |_--^ + | |_-^ | | | ...and last nested comment terminates here. diff --git a/tests/ui/lint/issue-104897.stderr b/tests/ui/lint/issue-104897.stderr index 1f3d40605f673..584902ee4c03c 100644 --- a/tests/ui/lint/issue-104897.stderr +++ b/tests/ui/lint/issue-104897.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-104897.rs:5:18 | LL | fn f(){(print!(á - | -- - ^ + | -- - ^ | || | | || unclosed delimiter | |unclosed delimiter diff --git a/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr b/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr index ad90aeda1d13b..d9748843fd7a8 100644 --- a/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr +++ b/tests/ui/malformed/issue-107423-unused-delim-only-one-no-pair.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-107423-unused-delim-only-one-no-pair.rs:7:11 | LL | fn a(){{{ - | --- ^ + | ---^ | ||| | ||unclosed delimiter | |unclosed delimiter diff --git a/tests/ui/parser/bad-char-literals.stderr b/tests/ui/parser/bad-char-literals.stderr index 38889da5da12c..1fb324a1b7e84 100644 --- a/tests/ui/parser/bad-char-literals.stderr +++ b/tests/ui/parser/bad-char-literals.stderr @@ -37,12 +37,12 @@ error: character literal may only contain one codepoint --> $DIR/bad-char-literals.rs:18:5 | LL | '-␀-'; - | ^^^^ + | ^^^^^ | help: if you meant to write a string literal, use double quotes | LL | "-␀-"; - | ~ ~ + | ~ ~ error: character constant must be escaped: `\t` --> $DIR/bad-char-literals.rs:21:6 diff --git a/tests/ui/parser/brace-in-let-chain.stderr b/tests/ui/parser/brace-in-let-chain.stderr index 7182d86d001d0..d76cb25ad8b84 100644 --- a/tests/ui/parser/brace-in-let-chain.stderr +++ b/tests/ui/parser/brace-in-let-chain.stderr @@ -31,7 +31,7 @@ LL | && let () = () LL | } | - ...as it matches this but it has different indentation LL | } - | ^ + | ^ error: found a `{` in the middle of a let-chain --> $DIR/brace-in-let-chain.rs:14:24 diff --git a/tests/ui/parser/byte-string-literals.stderr b/tests/ui/parser/byte-string-literals.stderr index 655b6998e85ff..24e0eaac8fa91 100644 --- a/tests/ui/parser/byte-string-literals.stderr +++ b/tests/ui/parser/byte-string-literals.stderr @@ -43,7 +43,7 @@ error[E0766]: unterminated double quote byte string LL | b"a | ______^ LL | | } - | |__^ + | |_^ error: aborting due to 6 previous errors diff --git a/tests/ui/parser/deli-ident-issue-1.stderr b/tests/ui/parser/deli-ident-issue-1.stderr index 78f5d7b63b954..d17913eb7ea40 100644 --- a/tests/ui/parser/deli-ident-issue-1.stderr +++ b/tests/ui/parser/deli-ident-issue-1.stderr @@ -11,7 +11,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | fn main() { } - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-103451.stderr b/tests/ui/parser/issues/issue-103451.stderr index 7ad816e451eab..f078e556e2b16 100644 --- a/tests/ui/parser/issues/issue-103451.stderr +++ b/tests/ui/parser/issues/issue-103451.stderr @@ -4,7 +4,7 @@ error: this file contains an unclosed delimiter LL | struct S { | - unclosed delimiter LL | x: [u8; R - | - ^ + | - ^ | | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-104367.stderr b/tests/ui/parser/issues/issue-104367.stderr index e6e76535761fb..c067d12e2d96c 100644 --- a/tests/ui/parser/issues/issue-104367.stderr +++ b/tests/ui/parser/issues/issue-104367.stderr @@ -20,7 +20,7 @@ LL | #![cfg] { LL | #![w,) | - missing open `(` for this delimiter LL | - | ^ + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/parser/issues/issue-105209.stderr b/tests/ui/parser/issues/issue-105209.stderr index c75eafa18335e..72017e4327de4 100644 --- a/tests/ui/parser/issues/issue-105209.stderr +++ b/tests/ui/parser/issues/issue-105209.stderr @@ -16,7 +16,7 @@ LL | #![c={#![c[)x | | unclosed delimiter | unclosed delimiter LL | - | ^ + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/parser/issues/issue-107705.stderr b/tests/ui/parser/issues/issue-107705.stderr index 2d0c3e0e675c7..10a47b799318c 100644 --- a/tests/ui/parser/issues/issue-107705.stderr +++ b/tests/ui/parser/issues/issue-107705.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-107705.rs:3:67 | LL | fn f() {a(b:&, - | - - unclosed delimiter ^ + | - - unclosed delimiter ^ | | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-2354.stderr b/tests/ui/parser/issues/issue-2354.stderr index fd649a575c6c6..3e63473b6f45c 100644 --- a/tests/ui/parser/issues/issue-2354.stderr +++ b/tests/ui/parser/issues/issue-2354.stderr @@ -10,7 +10,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-62546.stderr b/tests/ui/parser/issues/issue-62546.stderr index 6889cb3b8e9d2..6435cb2b719f4 100644 --- a/tests/ui/parser/issues/issue-62546.stderr +++ b/tests/ui/parser/issues/issue-62546.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-62546.rs:1:60 | LL | pub t(# - | - unclosed delimiter ^ + | - unclosed delimiter ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-62554.stderr b/tests/ui/parser/issues/issue-62554.stderr index 37314dd39c7fd..d4aaef1618139 100644 --- a/tests/ui/parser/issues/issue-62554.stderr +++ b/tests/ui/parser/issues/issue-62554.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-62554.rs:5:89 | LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 { - | - - - - - ^ + | - - - - -^ | | | | | | | | | | | unclosed delimiter | | | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-62881.stderr b/tests/ui/parser/issues/issue-62881.stderr index 2165a81a0482d..d8ae2cf090530 100644 --- a/tests/ui/parser/issues/issue-62881.stderr +++ b/tests/ui/parser/issues/issue-62881.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-62881.rs:3:96 | LL | fn f() -> isize { fn f() -> isize {} pub f< - | - unclosed delimiter ^ + | - unclosed delimiter ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-62894.stderr b/tests/ui/parser/issues/issue-62894.stderr index 870633fc96f85..230319fc31e7e 100644 --- a/tests/ui/parser/issues/issue-62894.stderr +++ b/tests/ui/parser/issues/issue-62894.stderr @@ -8,7 +8,7 @@ LL | fn f() { assert_eq!(f(), (), assert_eq!(assert_eq! | unclosed delimiter LL | LL | fn main() {} - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-62973.stderr b/tests/ui/parser/issues/issue-62973.stderr index 14411a8cb7849..493183988e18b 100644 --- a/tests/ui/parser/issues/issue-62973.stderr +++ b/tests/ui/parser/issues/issue-62973.stderr @@ -25,7 +25,7 @@ LL | fn p() { match s { v, E { [) {) } | unclosed delimiter LL | LL | - | ^ + | ^ error: aborting due to 3 previous errors diff --git a/tests/ui/parser/issues/issue-63116.stderr b/tests/ui/parser/issues/issue-63116.stderr index 27c94f337bdb8..e0f7dd176ceb3 100644 --- a/tests/ui/parser/issues/issue-63116.stderr +++ b/tests/ui/parser/issues/issue-63116.stderr @@ -10,7 +10,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-63116.rs:3:18 | LL | impl W $DIR/issue-63135.rs:3:16 | LL | fn i(n{...,f # - | - - ^ + | - - ^ | | | | | unclosed delimiter | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-66473.stderr b/tests/ui/parser/issues/issue-66473.stderr index 4be992d58460e..ba38c4fa1b7ad 100644 --- a/tests/ui/parser/issues/issue-66473.stderr +++ b/tests/ui/parser/issues/issue-66473.stderr @@ -8,7 +8,7 @@ error: unknown start of token: \u{0} --> $DIR/issue-66473.rs:4:3 | LL | #͈␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀ - | ^ + | ^^^^^^^^^^^^^^^^^^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used = note: character appears 17 more times @@ -17,19 +17,19 @@ error: unknown start of token: \u{1d} --> $DIR/issue-66473.rs:5:2 | LL | ␋␝6␝␀␀ - | ^ + | ^ error: unknown start of token: \u{1d} --> $DIR/issue-66473.rs:5:4 | LL | ␋␝6␝␀␀ - | ^ + | ^ error: unknown start of token: \u{0} --> $DIR/issue-66473.rs:5:5 | LL | ␋␝6␝␀␀ - | ^ + | ^^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used = note: character appears once more @@ -40,7 +40,7 @@ error: expected one of `!` or `[`, found `6` LL | #͈␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀ | - expected one of `!` or `[` LL | ␋␝6␝␀␀ - | ^ unexpected token + | ^ unexpected token error: aborting due to 6 previous errors diff --git a/tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr b/tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr index 9f631edf680c8..b82b0f3255b55 100644 --- a/tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr +++ b/tests/ui/parser/issues/issue-67377-invalid-syntax-in-enum-discriminant.stderr @@ -41,7 +41,7 @@ LL | V = [Vec::new; { [0].len() ].len() as isize, | - missing open `[` for this delimiter ... LL | fn main() {} - | ^ + | ^ error: aborting due to 4 previous errors diff --git a/tests/ui/parser/issues/issue-68629.stderr b/tests/ui/parser/issues/issue-68629.stderr index ccb0624208b2e..f003f37817951 100644 --- a/tests/ui/parser/issues/issue-68629.stderr +++ b/tests/ui/parser/issues/issue-68629.stderr @@ -8,13 +8,13 @@ error: unknown start of token: \u{1f} --> $DIR/issue-68629.rs:4:2 | LL | ␜␟ts␀![{i - | ^ + | ^ error: unknown start of token: \u{0} --> $DIR/issue-68629.rs:4:5 | LL | ␜␟ts␀![{i - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -22,7 +22,7 @@ error: unknown start of token: \u{0} --> $DIR/issue-68629.rs:5:1 | LL | ␀␀ fn rݻoa>rݻm - | ^ + | ^^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used = note: character appears once more @@ -31,11 +31,11 @@ error: this file contains an unclosed delimiter --> $DIR/issue-68629.rs:5:17 | LL | ␜␟ts␀![{i - | -- unclosed delimiter - | | - | unclosed delimiter + | -- unclosed delimiter + | | + | unclosed delimiter LL | ␀␀ fn rݻoa>rݻm - | ^ + | ^ error: aborting due to 5 previous errors diff --git a/tests/ui/parser/issues/issue-68730.stderr b/tests/ui/parser/issues/issue-68730.stderr index 6025ea8c1ae7f..9bd98287db34a 100644 --- a/tests/ui/parser/issues/issue-68730.stderr +++ b/tests/ui/parser/issues/issue-68730.stderr @@ -10,7 +10,7 @@ error: unknown start of token: \u{0} --> $DIR/issue-68730.rs:5:8 | LL | enum␀em␀˂˂ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -18,30 +18,30 @@ error: unknown start of token: \u{2c2} --> $DIR/issue-68730.rs:5:9 | LL | enum␀em␀˂˂ - | ^^ + | ^^ | = note: character appears once more help: Unicode character '˂' (Modifier Letter Left Arrowhead) looks like '<' (Less-Than Sign), but it is not | LL | enum␀em␀<< - | ~~ + | ~~ error: unknown start of token: \u{2c2} --> $DIR/issue-68730.rs:5:10 | LL | enum␀em␀˂˂ - | ^ + | ^ | help: Unicode character '˂' (Modifier Letter Left Arrowhead) looks like '<' (Less-Than Sign), but it is not | LL | enum␀em␀˂< - | ~ + | ~ error: expected one of `#`, `>`, `const`, identifier, or lifetime, found `<` --> $DIR/issue-68730.rs:5:10 | LL | enum␀em␀˂˂ - | ^ expected one of `#`, `>`, `const`, identifier, or lifetime + | ^ expected one of `#`, `>`, `const`, identifier, or lifetime error: aborting due to 5 previous errors diff --git a/tests/ui/parser/issues/issue-81804.stderr b/tests/ui/parser/issues/issue-81804.stderr index de3b33ecd95c6..6caaaa792b196 100644 --- a/tests/ui/parser/issues/issue-81804.stderr +++ b/tests/ui/parser/issues/issue-81804.stderr @@ -10,7 +10,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-81804.rs:6:11 | LL | fn p([=(} - | -- ^ + | -- ^ | || | |unclosed delimiter | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-81827.stderr b/tests/ui/parser/issues/issue-81827.stderr index 63d135f73e69f..d12c74b4a3420 100644 --- a/tests/ui/parser/issues/issue-81827.stderr +++ b/tests/ui/parser/issues/issue-81827.stderr @@ -11,7 +11,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-81827.rs:10:27 | LL | fn r()->i{0|{#[cfg(r(0{]0 - | - - - ^ + | - - - ^ | | | | | | | missing open `[` for this delimiter | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-84104.stderr b/tests/ui/parser/issues/issue-84104.stderr index e866d39226751..b9b14c081a985 100644 --- a/tests/ui/parser/issues/issue-84104.stderr +++ b/tests/ui/parser/issues/issue-84104.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-84104.rs:2:13 | LL | #[i=i::<ښܖ< - | - ^ + | - ^ | | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-84148-2.stderr b/tests/ui/parser/issues/issue-84148-2.stderr index d9b6b336a2ce8..b30f3d9114c1d 100644 --- a/tests/ui/parser/issues/issue-84148-2.stderr +++ b/tests/ui/parser/issues/issue-84148-2.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-84148-2.rs:2:16 | LL | fn f(t:for<>t? - | - ^ + | - ^ | | | unclosed delimiter diff --git a/tests/ui/parser/issues/issue-88770.stderr b/tests/ui/parser/issues/issue-88770.stderr index 60ef025fa8bfd..5b54072d009fb 100644 --- a/tests/ui/parser/issues/issue-88770.stderr +++ b/tests/ui/parser/issues/issue-88770.stderr @@ -8,7 +8,7 @@ LL | fn m(){print!("",(c for&g | unclosed delimiter ... LL | e - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr b/tests/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr index 97aac661d4658..39144246be24a 100644 --- a/tests/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr +++ b/tests/ui/parser/mismatched-braces/missing-close-brace-in-impl-trait.stderr @@ -5,7 +5,7 @@ LL | impl T for () { | - unclosed delimiter ... LL | - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr b/tests/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr index f70dac443e55f..603aee02ad6b0 100644 --- a/tests/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr +++ b/tests/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr @@ -5,7 +5,7 @@ LL | pub(crate) struct Bar { | - unclosed delimiter ... LL | fn main() {} - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr b/tests/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr index a565ad49b221c..a2fb698c80f65 100644 --- a/tests/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr +++ b/tests/ui/parser/mismatched-braces/missing-close-brace-in-trait.stderr @@ -5,7 +5,7 @@ LL | trait T { | - unclosed delimiter ... LL | fn main() {} - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/parser-ice-ed2021-await-105210.stderr b/tests/ui/parser/parser-ice-ed2021-await-105210.stderr index fc54476c22048..29abab2608e94 100644 --- a/tests/ui/parser/parser-ice-ed2021-await-105210.stderr +++ b/tests/ui/parser/parser-ice-ed2021-await-105210.stderr @@ -28,7 +28,7 @@ LL | (( h (const {( default ( await ( await ( (move {await((((}} | unclosed delimiter ... LL | - | ^ + | ^ error: aborting due to 3 previous errors diff --git a/tests/ui/parser/parser-recovery-1.stderr b/tests/ui/parser/parser-recovery-1.stderr index 8162db3d8e5d6..4ed40d7532612 100644 --- a/tests/ui/parser/parser-recovery-1.stderr +++ b/tests/ui/parser/parser-recovery-1.stderr @@ -10,7 +10,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | } - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr b/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr index 3150570e1c908..e235a15838493 100644 --- a/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr +++ b/tests/ui/parser/several-carriage-returns-in-doc-comment.stderr @@ -8,13 +8,13 @@ error: bare CR not allowed in doc-comment --> $DIR/several-carriage-returns-in-doc-comment.rs:6:32 | LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols - | ^ + | ^ error: bare CR not allowed in doc-comment --> $DIR/several-carriage-returns-in-doc-comment.rs:6:52 | LL | /// This do␍c comment contains ␍three isolated `\r`␍ symbols - | ^ + | ^ error: aborting due to 3 previous errors diff --git a/tests/ui/parser/unbalanced-doublequote.stderr b/tests/ui/parser/unbalanced-doublequote.stderr index d40b982da7c39..9fdad87a86cf1 100644 --- a/tests/ui/parser/unbalanced-doublequote.stderr +++ b/tests/ui/parser/unbalanced-doublequote.stderr @@ -3,7 +3,7 @@ error[E0765]: unterminated double quote string | LL | / " LL | | } - | |__^ + | |_^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/unclosed-braces.stderr b/tests/ui/parser/unclosed-braces.stderr index acd92ac792597..74ac66af528db 100644 --- a/tests/ui/parser/unclosed-braces.stderr +++ b/tests/ui/parser/unclosed-braces.stderr @@ -11,7 +11,7 @@ LL | } | - ...as it matches this but it has different indentation ... LL | - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/unmatched-delimiter-at-end-of-file.stderr b/tests/ui/parser/unmatched-delimiter-at-end-of-file.stderr index c6960892b2bc8..192f5324935f6 100644 --- a/tests/ui/parser/unmatched-delimiter-at-end-of-file.stderr +++ b/tests/ui/parser/unmatched-delimiter-at-end-of-file.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/unmatched-delimiter-at-end-of-file.rs:11:63 | LL | fn foo() { - | - unclosed delimiter ^ + | - unclosed delimiter ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/use-unclosed-brace.stderr b/tests/ui/parser/use-unclosed-brace.stderr index 6e624cb913163..1e62a0a06a36b 100644 --- a/tests/ui/parser/use-unclosed-brace.stderr +++ b/tests/ui/parser/use-unclosed-brace.stderr @@ -5,7 +5,7 @@ LL | use foo::{bar, baz; | - unclosed delimiter ... LL | fn main() {} - | ^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/parser/utf16-be-without-bom.stderr b/tests/ui/parser/utf16-be-without-bom.stderr index 28cf6d97e96c2..55ebf7aacd237 100644 --- a/tests/ui/parser/utf16-be-without-bom.stderr +++ b/tests/ui/parser/utf16-be-without-bom.stderr @@ -10,7 +10,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:3 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -18,7 +18,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:5 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -26,7 +26,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:7 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -34,7 +34,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:9 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -42,7 +42,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:11 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -50,7 +50,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:13 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -58,7 +58,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:15 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -66,7 +66,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:17 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -74,7 +74,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:19 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -82,7 +82,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:21 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -90,7 +90,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:23 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -98,7 +98,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-be-without-bom.rs:4:25 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -106,12 +106,12 @@ error: expected one of `!` or `::`, found `n` --> $DIR/utf16-be-without-bom.rs:4:4 | LL | ␀f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ expected one of `!` or `::` + | ^ expected one of `!` or `::` | help: consider removing the space to spell keyword `fn` | LL | ␀fn␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ~~ + | ~~ error: aborting due to 14 previous errors diff --git a/tests/ui/parser/utf16-le-without-bom.stderr b/tests/ui/parser/utf16-le-without-bom.stderr index 53004ac942d98..ad272a70f0627 100644 --- a/tests/ui/parser/utf16-le-without-bom.stderr +++ b/tests/ui/parser/utf16-le-without-bom.stderr @@ -10,7 +10,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:4 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -18,7 +18,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:6 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -26,7 +26,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:8 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -34,7 +34,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:10 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -42,7 +42,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:12 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -50,7 +50,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:14 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -58,7 +58,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:16 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -66,7 +66,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:18 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -74,7 +74,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:20 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -82,7 +82,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:22 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -90,7 +90,7 @@ error: unknown start of token: \u{0} --> $DIR/utf16-le-without-bom.rs:4:24 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ + | ^ | = help: source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used @@ -106,7 +106,7 @@ error: expected one of `!` or `::`, found `n` --> $DIR/utf16-le-without-bom.rs:4:3 | LL | f␀n␀ ␀m␀a␀i␀n␀(␀)␀ ␀{␀}␀ - | ^ expected one of `!` or `::` + | ^ expected one of `!` or `::` | help: consider removing the space to spell keyword `fn` | diff --git a/tests/ui/rustdoc/unterminated-doc-comment.stderr b/tests/ui/rustdoc/unterminated-doc-comment.stderr index 2d96c606b1636..f0b691333dc93 100644 --- a/tests/ui/rustdoc/unterminated-doc-comment.stderr +++ b/tests/ui/rustdoc/unterminated-doc-comment.stderr @@ -2,7 +2,7 @@ error[E0758]: unterminated block doc-comment --> $DIR/unterminated-doc-comment.rs:1:1 | LL | /*! - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr index 004a057bbcdaf..c8cce16241617 100644 --- a/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr +++ b/tests/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr @@ -2,7 +2,7 @@ error: this file contains an unclosed delimiter --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:12:85 | LL | trait C{async fn new(val: T) {} - | - unclosed delimiter ^ + | - unclosed delimiter ^ error: aborting due to 1 previous error diff --git a/tests/ui/str/str-escape.stderr b/tests/ui/str/str-escape.stderr index 599c8de97578f..4c8ee6bc013ef 100644 --- a/tests/ui/str/str-escape.stderr +++ b/tests/ui/str/str-escape.stderr @@ -23,8 +23,8 @@ warning: whitespace symbol '\u{c}' is not skipped LL | let s = b"a\ | ________________^ LL | | ␌b"; - | | ^- whitespace symbol '\u{c}' is not skipped - | |____| + | | ^ whitespace symbol '\u{c}' is not skipped + | |_____| | warning: 3 warnings emitted diff --git a/tests/ui/suggestions/issue-94171.stderr b/tests/ui/suggestions/issue-94171.stderr index b3440e46e8acd..3d73ee1d27a06 100644 --- a/tests/ui/suggestions/issue-94171.stderr +++ b/tests/ui/suggestions/issue-94171.stderr @@ -30,7 +30,7 @@ LL | (; {` | unclosed delimiter ... LL | - | ^ + | ^ error: aborting due to 3 previous errors diff --git a/tests/ui/typeck/issue-91334.stderr b/tests/ui/typeck/issue-91334.stderr index 7cb30eea530c6..01e34919ce67d 100644 --- a/tests/ui/typeck/issue-91334.stderr +++ b/tests/ui/typeck/issue-91334.stderr @@ -11,7 +11,7 @@ error: this file contains an unclosed delimiter --> $DIR/issue-91334.rs:7:23 | LL | fn f(){||yield(((){), - | - - - ^ + | - - - ^ | | | | | | | missing open `(` for this delimiter | | unclosed delimiter From 9dffe9573be86ac7302fb2f27219ef8f9c78dea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 18 Jul 2024 20:02:08 +0000 Subject: [PATCH 4/9] =?UTF-8?q?Make=20unicode=20text=20flow=20control=20ch?= =?UTF-8?q?ars=20visible=20as=20=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We already point these out quite aggressively, telling people not to use them, but would normally be rendered as nothing. Having them visible will make it easier for people to actually deal with them. ``` error: unicode codepoint changing visible direction of text present in literal --> $DIR/unicode-control-codepoints.rs:26:22 | LL | println!("{:?}", '�'); | ^-^ | || | |'\u{202e}' | this literal contains an invisible unicode text flow control codepoint | = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen = help: if their presence wasn't intentional, you can remove them help: if you want to keep them but make them visible in your source code, you can escape them | LL | println!("{:?}", '\u{202e}'); | ~~~~~~~~ ``` vs the previous ``` error: unicode codepoint changing visible direction of text present in literal --> $DIR/unicode-control-codepoints.rs:26:22 | LL | println!("{:?}", ''); | ^- | || | |'\u{202e}' | this literal contains an invisible unicode text flow control codepoint | = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen = help: if their presence wasn't intentional, you can remove them help: if you want to keep them but make them visible in your source code, you can escape them | LL | println!("{:?}", '\u{202e}'); | ~~~~~~~~ ``` --- compiler/rustc_errors/src/emitter.rs | 21 ++-- compiler/rustc_span/src/lib.rs | 3 +- .../parser/unicode-control-codepoints.stderr | 98 +++++++++---------- 3 files changed, 62 insertions(+), 60 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 16fa0ff7a2d6c..58220c6549005 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2558,18 +2558,19 @@ fn num_decimal_digits(num: usize) -> usize { } // We replace some characters so the CLI output is always consistent and underlines aligned. +// Keep the following list in sync with `rustc_span::char_width`. const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[ - ('\t', " "), // We do our own tab replacement + ('\t', " "), // We do our own tab replacement ('\u{200D}', ""), // Replace ZWJ with nothing for consistent terminal output of grapheme clusters. - ('\u{202A}', ""), // The following unicode text flow control characters are inconsistently - ('\u{202B}', ""), // supported across CLIs and can cause confusion due to the bytes on disk - ('\u{202D}', ""), // not corresponding to the visible source code, so we replace them always. - ('\u{202E}', ""), - ('\u{2066}', ""), - ('\u{2067}', ""), - ('\u{2068}', ""), - ('\u{202C}', ""), - ('\u{2069}', ""), + ('\u{202A}', "�"), // The following unicode text flow control characters are inconsistently + ('\u{202B}', "�"), // supported across CLIs and can cause confusion due to the bytes on disk + ('\u{202D}', "�"), // not corresponding to the visible source code, so we replace them always. + ('\u{202E}', "�"), + ('\u{2066}', "�"), + ('\u{2067}', "�"), + ('\u{2068}', "�"), + ('\u{202C}', "�"), + ('\u{2069}', "�"), // In terminals without Unicode support the following will be garbled, but in *all* terminals // the underlying codepoint will be as well. We could gate this replacement behind a "unicode // support" gate. diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index ea57c1ce8185b..7c8ac3be4beca 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -2093,7 +2093,8 @@ pub fn char_width(ch: char) -> usize { | '\u{000E}' | '\u{000F}' | '\u{0010}' | '\u{0011}' | '\u{0012}' | '\u{0013}' | '\u{0014}' | '\u{0015}' | '\u{0016}' | '\u{0017}' | '\u{0018}' | '\u{0019}' | '\u{001A}' | '\u{001B}' | '\u{001C}' | '\u{001D}' | '\u{001E}' | '\u{001F}' - | '\u{007F}' => 1, + | '\u{007F}' | '\u{202A}' | '\u{202B}' | '\u{202D}' | '\u{202E}' | '\u{2066}' + | '\u{2067}' | '\u{2068}' | '\u{202C}' | '\u{2069}' => 1, _ => unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1), } } diff --git a/tests/ui/parser/unicode-control-codepoints.stderr b/tests/ui/parser/unicode-control-codepoints.stderr index fc071a9419142..28de4ae72abbd 100644 --- a/tests/ui/parser/unicode-control-codepoints.stderr +++ b/tests/ui/parser/unicode-control-codepoints.stderr @@ -17,78 +17,78 @@ LL | println!("{:?}", b"us\u{202B}e\u{202A}r"); error: non-ASCII character in byte string literal --> $DIR/unicode-control-codepoints.rs:16:26 | -LL | println!("{:?}", b"/* } if isAdmin begin admins only "); +LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); | ^ must be ASCII but is '\u{202e}' | help: if you meant to use the UTF-8 encoding of '\u{202e}', use \xHH escapes | -LL | println!("{:?}", b"/*\xE2\x80\xAE } if isAdmin begin admins only "); +LL | println!("{:?}", b"/*\xE2\x80\xAE } �if isAdmin� � begin admins only "); | ~~~~~~~~~~~~ error: non-ASCII character in byte string literal --> $DIR/unicode-control-codepoints.rs:16:30 | -LL | println!("{:?}", b"/* } if isAdmin begin admins only "); - | ^ must be ASCII but is '\u{2066}' +LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); + | ^ must be ASCII but is '\u{2066}' | help: if you meant to use the UTF-8 encoding of '\u{2066}', use \xHH escapes | -LL | println!("{:?}", b"/* } \xE2\x81\xA6if isAdmin begin admins only "); - | ~~~~~~~~~~~~ +LL | println!("{:?}", b"/*� } \xE2\x81\xA6if isAdmin� � begin admins only "); + | ~~~~~~~~~~~~ error: non-ASCII character in byte string literal --> $DIR/unicode-control-codepoints.rs:16:41 | -LL | println!("{:?}", b"/* } if isAdmin begin admins only "); - | ^ must be ASCII but is '\u{2069}' +LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); + | ^ must be ASCII but is '\u{2069}' | help: if you meant to use the UTF-8 encoding of '\u{2069}', use \xHH escapes | -LL | println!("{:?}", b"/* } if isAdmin\xE2\x81\xA9 begin admins only "); - | ~~~~~~~~~~~~ +LL | println!("{:?}", b"/*� } �if isAdmin\xE2\x81\xA9 � begin admins only "); + | ~~~~~~~~~~~~ error: non-ASCII character in byte string literal --> $DIR/unicode-control-codepoints.rs:16:43 | -LL | println!("{:?}", b"/* } if isAdmin begin admins only "); - | ^ must be ASCII but is '\u{2066}' +LL | println!("{:?}", b"/*� } �if isAdmin� � begin admins only "); + | ^ must be ASCII but is '\u{2066}' | help: if you meant to use the UTF-8 encoding of '\u{2066}', use \xHH escapes | -LL | println!("{:?}", b"/* } if isAdmin \xE2\x81\xA6 begin admins only "); - | ~~~~~~~~~~~~ +LL | println!("{:?}", b"/*� } �if isAdmin� \xE2\x81\xA6 begin admins only "); + | ~~~~~~~~~~~~ error: non-ASCII character in raw byte string literal --> $DIR/unicode-control-codepoints.rs:21:29 | -LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); +LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); | ^ must be ASCII but is '\u{202e}' error: non-ASCII character in raw byte string literal --> $DIR/unicode-control-codepoints.rs:21:33 | -LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); - | ^ must be ASCII but is '\u{2066}' +LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); + | ^ must be ASCII but is '\u{2066}' error: non-ASCII character in raw byte string literal --> $DIR/unicode-control-codepoints.rs:21:44 | -LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); - | ^ must be ASCII but is '\u{2069}' +LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); + | ^ must be ASCII but is '\u{2069}' error: non-ASCII character in raw byte string literal --> $DIR/unicode-control-codepoints.rs:21:46 | -LL | println!("{:?}", br##"/* } if isAdmin begin admins only "##); - | ^ must be ASCII but is '\u{2066}' +LL | println!("{:?}", br##"/*� } �if isAdmin� � begin admins only "##); + | ^ must be ASCII but is '\u{2066}' error: unicode codepoint changing visible direction of text present in comment --> $DIR/unicode-control-codepoints.rs:2:5 | -LL | // if access_level != "user" { // Check if admin - | ^^^^^^^^^^^^^^^^^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^ - | | || - | | |'\u{202a}' +LL | // if access_level != "us�e�r" { // Check if admin + | ^^^^^^^^^^^^^^^^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^ + | | | | + | | | '\u{202a}' | | '\u{202b}' | this comment contains invisible unicode text flow control codepoints | @@ -99,12 +99,12 @@ LL | // if access_level != "user" { // Check if admin error: unicode codepoint changing visible direction of text present in comment --> $DIR/unicode-control-codepoints.rs:30:1 | -LL | //"/* } if isAdmin begin admins only */" - | ^^^^^-^^-^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^ - | | | | || - | | | | |'\u{2066}' - | | | | '\u{2069}' - | | | '\u{2066}' +LL | //"/*� } �if isAdmin� � begin admins only */" + | ^^^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^ + | | | | | | + | | | | | '\u{2066}' + | | | | '\u{2069}' + | | | '\u{2066}' | | '\u{202e}' | this comment contains invisible unicode text flow control codepoints | @@ -114,12 +114,12 @@ LL | //"/* } if isAdmin begin admins only */" error: unicode codepoint changing visible direction of text present in literal --> $DIR/unicode-control-codepoints.rs:11:22 | -LL | println!("{:?}", "/* } if isAdmin begin admins only "); - | ^^^-^^-^^^^^^^^^--^^^^^^^^^^^^^^^^^^^ - | | | | || - | | | | |'\u{2066}' - | | | | '\u{2069}' - | | | '\u{2066}' +LL | println!("{:?}", "/*� } �if isAdmin� � begin admins only "); + | ^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^ + | | | | | | + | | | | | '\u{2066}' + | | | | '\u{2069}' + | | | '\u{2066}' | | '\u{202e}' | this literal contains invisible unicode text flow control codepoints | @@ -134,12 +134,12 @@ LL | println!("{:?}", "/*\u{202e} } \u{2066}if isAdmin\u{2069} \u{2066} begi error: unicode codepoint changing visible direction of text present in literal --> $DIR/unicode-control-codepoints.rs:14:22 | -LL | println!("{:?}", r##"/* } if isAdmin begin admins only "##); - | ^^^^^^-^^-^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^ - | | | | || - | | | | |'\u{2066}' - | | | | '\u{2069}' - | | | '\u{2066}' +LL | println!("{:?}", r##"/*� } �if isAdmin� � begin admins only "##); + | ^^^^^^-^^^-^^^^^^^^^^-^-^^^^^^^^^^^^^^^^^^^^^^ + | | | | | | + | | | | | '\u{2066}' + | | | | '\u{2069}' + | | | '\u{2066}' | | '\u{202e}' | this literal contains invisible unicode text flow control codepoints | @@ -153,8 +153,8 @@ LL | println!("{:?}", r##"/*\u{202e} } \u{2066}if isAdmin\u{2069} \u{2066} b error: unicode codepoint changing visible direction of text present in literal --> $DIR/unicode-control-codepoints.rs:26:22 | -LL | println!("{:?}", ''); - | ^- +LL | println!("{:?}", '�'); + | ^-^ | || | |'\u{202e}' | this literal contains an invisible unicode text flow control codepoint @@ -169,8 +169,8 @@ LL | println!("{:?}", '\u{202e}'); error: unicode codepoint changing visible direction of text present in doc comment --> $DIR/unicode-control-codepoints.rs:33:1 | -LL | /** ''); */fn foo() {} - | ^^^^^^^^^^^^ this doc comment contains an invisible unicode text flow control codepoint +LL | /** '�'); */fn foo() {} + | ^^^^^^^^^^^^^ this doc comment contains an invisible unicode text flow control codepoint | = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen = note: if their presence wasn't intentional, you can remove them @@ -181,8 +181,8 @@ error: unicode codepoint changing visible direction of text present in doc comme | LL | / /** LL | | * -LL | | * ''); */fn bar() {} - | |___________^ this doc comment contains an invisible unicode text flow control codepoint +LL | | * '�'); */fn bar() {} + | |____________^ this doc comment contains an invisible unicode text flow control codepoint | = note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen = note: if their presence wasn't intentional, you can remove them From b74f426e074bbaafdd9d15d60c3f57ff4e3f91b9 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Mon, 22 Jul 2024 00:59:58 +0300 Subject: [PATCH 5/9] Fix some `#[cfg_attr(not(doc), repr(..))]` Now that #90435 seems to have been resolved. --- library/core/src/error.rs | 2 +- library/core/src/ffi/c_str.rs | 2 +- library/core/src/ffi/mod.rs | 2 +- library/core/src/ffi/va_list.rs | 4 ++-- library/core/src/task/wake.rs | 4 ++-- library/std/src/ffi/os_str.rs | 6 ++---- library/std/src/path.rs | 6 ++---- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/library/core/src/error.rs b/library/core/src/error.rs index ca8983d4cbcfe..19b7bb44f855a 100644 --- a/library/core/src/error.rs +++ b/library/core/src/error.rs @@ -506,7 +506,7 @@ where /// ``` /// #[unstable(feature = "error_generic_member_access", issue = "99301")] -#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435 +#[repr(transparent)] pub struct Request<'a>(Tagged + 'a>); impl<'a> Request<'a> { diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 563f0a324e3f1..c9111254082da 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -103,7 +103,7 @@ use crate::str; // However, `CStr` layout is considered an implementation detail and must not be relied upon. We // want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under // `cfg(doc)`. This is an ad-hoc implementation of attribute privacy. -#[cfg_attr(not(doc), repr(transparent))] +#[repr(transparent)] #[allow(clippy::derived_hash_with_manual_eq)] pub struct CStr { // FIXME: this should not be represented with a DST slice but rather with diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index 88adc378477fd..93426b90c706a 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -191,7 +191,7 @@ mod c_long_definition { // be UB. #[doc = include_str!("c_void.md")] #[lang = "c_void"] -#[cfg_attr(not(doc), repr(u8))] // work around https://github.com/rust-lang/rust/issues/90435 +#[cfg_attr(not(doc), repr(u8))] // An implementation detail we don't want to show up in rustdoc #[stable(feature = "core_c_void", since = "1.30.0")] pub enum c_void { #[unstable( diff --git a/library/core/src/ffi/va_list.rs b/library/core/src/ffi/va_list.rs index 6a2e8b67d0c2a..f4c746225dc03 100644 --- a/library/core/src/ffi/va_list.rs +++ b/library/core/src/ffi/va_list.rs @@ -23,7 +23,7 @@ use crate::ops::{Deref, DerefMut}; target_os = "uefi", windows, ))] -#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435 +#[repr(transparent)] #[lang = "va_list"] pub struct VaListImpl<'f> { ptr: *mut c_void, @@ -115,7 +115,7 @@ pub struct VaListImpl<'f> { } /// A wrapper for a `va_list` -#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435 +#[repr(transparent)] #[derive(Debug)] pub struct VaList<'a, 'f: 'a> { #[cfg(any( diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index 86a965f68e085..9d74e64ed6372 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -429,7 +429,7 @@ impl<'a> ContextBuilder<'a> { /// [`Future::poll()`]: core::future::Future::poll /// [`Poll::Pending`]: core::task::Poll::Pending /// [`Wake`]: ../../alloc/task/trait.Wake.html -#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/66401 +#[repr(transparent)] #[stable(feature = "futures_api", since = "1.36.0")] pub struct Waker { waker: RawWaker, @@ -695,7 +695,7 @@ impl fmt::Debug for Waker { /// [`Poll::Pending`]: core::task::Poll::Pending /// [`local_waker`]: core::task::Context::local_waker #[unstable(feature = "local_waker", issue = "118959")] -#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/66401 +#[repr(transparent)] pub struct LocalWaker { waker: RawWaker, } diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index f9dba08da4c3c..0fb3964c9a9b4 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -115,10 +115,8 @@ impl crate::sealed::Sealed for OsString {} #[stable(feature = "rust1", since = "1.0.0")] // `OsStr::from_inner` current implementation relies // on `OsStr` being layout-compatible with `Slice`. -// However, `OsStr` layout is considered an implementation detail and must not be relied upon. We -// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under -// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy. -#[cfg_attr(not(doc), repr(transparent))] +// However, `OsStr` layout is considered an implementation detail and must not be relied upon. +#[repr(transparent)] pub struct OsStr { inner: Slice, } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index d5121a554bf6c..0cef862549c8a 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2079,10 +2079,8 @@ impl AsRef for PathBuf { #[stable(feature = "rust1", since = "1.0.0")] // `Path::new` current implementation relies // on `Path` being layout-compatible with `OsStr`. -// However, `Path` layout is considered an implementation detail and must not be relied upon. We -// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under -// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy. -#[cfg_attr(not(doc), repr(transparent))] +// However, `Path` layout is considered an implementation detail and must not be relied upon. +#[repr(transparent)] pub struct Path { inner: OsStr, } From a4dd0d6899983fde238305bd6fb4befa61e6e9a6 Mon Sep 17 00:00:00 2001 From: joboet Date: Wed, 24 Jul 2024 14:13:57 +0200 Subject: [PATCH 6/9] std: use duplicate thread local state in tests With rust-lang/miri#3739 merged, the deduplication hack is no longer necessary. --- library/std/src/thread/mod.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index e9731bc85d61c..c4e60d53216df 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -192,22 +192,14 @@ pub use scoped::{scope, Scope, ScopedJoinHandle}; #[macro_use] mod local; -cfg_if::cfg_if! { - if #[cfg(test)] { - // Avoid duplicating the global state associated with thread-locals between this crate and - // realstd. Miri relies on this. - pub use realstd::thread::{local_impl, AccessError, LocalKey}; - } else { - #[stable(feature = "rust1", since = "1.0.0")] - pub use self::local::{AccessError, LocalKey}; - - // Implementation details used by the thread_local!{} macro. - #[doc(hidden)] - #[unstable(feature = "thread_local_internals", issue = "none")] - pub mod local_impl { - pub use crate::sys::thread_local::*; - } - } +#[stable(feature = "rust1", since = "1.0.0")] +pub use self::local::{AccessError, LocalKey}; + +// Implementation details used by the thread_local!{} macro. +#[doc(hidden)] +#[unstable(feature = "thread_local_internals", issue = "none")] +pub mod local_impl { + pub use crate::sys::thread_local::*; } //////////////////////////////////////////////////////////////////////////////// From dfb3fb32cec8613cb2c3317493bc1b449de9246c Mon Sep 17 00:00:00 2001 From: rik86189 <75071538+rik86189@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:23:29 +0200 Subject: [PATCH 7/9] Improved clarity of documentation for std::fs::create_dir_all --- library/std/src/fs.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 6413b3515ecec..536d0d1b356a9 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -2400,13 +2400,8 @@ pub fn create_dir>(path: P) -> io::Result<()> { /// /// # Errors /// -/// This function will return an error in the following situations, but is not -/// limited to just these cases: -/// -/// * If any directory in the path specified by `path` -/// does not already exist and it could not be created otherwise. The specific -/// error conditions for when a directory is being created (after it is -/// determined to not exist) are outlined by [`fs::create_dir`]. +/// The function will return an error if any directory specified in path does not exist and +/// could not be created. There may be other error conditions; see [`fs::create_dir`] for specifics. /// /// Notable exception is made for situations where any of the directories /// specified in the `path` could not be created as it was being created concurrently. From 4d5ac84285e13a05c0ade4b83aeb309a1f351610 Mon Sep 17 00:00:00 2001 From: Veera Date: Wed, 24 Jul 2024 11:06:23 -0400 Subject: [PATCH 8/9] Remove Unnecessary `.as_str()` Conversions --- compiler/rustc_hir_typeck/src/method/probe.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 9cb6124ab2176..ae34ddeaa87d4 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1846,7 +1846,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { /// Determine if the associated item with the given DefId matches /// the desired name via a doc alias. fn matches_by_doc_alias(&self, def_id: DefId) -> bool { - let Some(name) = self.method_name else { + let Some(method) = self.method_name else { return false; }; let Some(local_def_id) = def_id.as_local() else { @@ -1863,7 +1863,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // #[rustc_confusables("foo", "bar"))] for n in confusables { if let Some(lit) = n.lit() - && name.as_str() == lit.symbol.as_str() + && method.name == lit.symbol { return true; } @@ -1883,14 +1883,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // #[doc(alias("foo", "bar"))] for n in nested { if let Some(lit) = n.lit() - && name.as_str() == lit.symbol.as_str() + && method.name == lit.symbol { return true; } } } else if let Some(meta) = v.meta_item() && let Some(lit) = meta.name_value_literal() - && name.as_str() == lit.symbol.as_str() + && method.name == lit.symbol { // #[doc(alias = "foo")] return true; From c9886a1ddf6b19e35b0361062825666d34f8dfee Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 23 Jul 2024 18:56:29 -0500 Subject: [PATCH 9/9] Mark `missing_fragment_specifier` as `FutureReleaseErrorReportInDeps` We are moving toward forbidding `missing_fragment_specifier` either in edition 2024 or unconditionally. Make a first step toward this by ensuring crates that rely on the old behavior are reported when used as dependencies. Tracking issue: --- compiler/rustc_lint_defs/src/builtin.rs | 2 +- tests/ui/lint/expansion-time.stderr | 15 +++++++ tests/ui/macros/issue-39404.stderr | 11 +++++ .../ui/macros/macro-match-nonterminal.stderr | 22 +++++++++ ...acro-missing-fragment-deduplication.stderr | 11 +++++ tests/ui/macros/macro-missing-fragment.stderr | 45 +++++++++++++++++++ tests/ui/parser/macro/issue-33569.stderr | 11 +++++ 7 files changed, 116 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 2f4e6a3230831..5d4cc7561a63d 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1424,7 +1424,7 @@ declare_lint! { Deny, "detects missing fragment specifiers in unused `macro_rules!` patterns", @future_incompatible = FutureIncompatibleInfo { - reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps, + reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps, reference: "issue #40107 ", }; } diff --git a/tests/ui/lint/expansion-time.stderr b/tests/ui/lint/expansion-time.stderr index 626e51dd00c2f..e490ae91a4888 100644 --- a/tests/ui/lint/expansion-time.stderr +++ b/tests/ui/lint/expansion-time.stderr @@ -55,6 +55,21 @@ LL | #[warn(incomplete_include)] warning: 4 warnings emitted Future incompatibility report: Future breakage diagnostic: +warning: missing fragment specifier + --> $DIR/expansion-time.rs:9:19 + | +LL | macro_rules! m { ($i) => {} } + | ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #40107 +note: the lint level is defined here + --> $DIR/expansion-time.rs:8:8 + | +LL | #[warn(missing_fragment_specifier)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: warning: use of unstable library feature 'test': `bench` is a part of custom test frameworks which are unstable --> $DIR/expansion-time.rs:14:7 | diff --git a/tests/ui/macros/issue-39404.stderr b/tests/ui/macros/issue-39404.stderr index 33cafd93a4042..176c8e9f073c8 100644 --- a/tests/ui/macros/issue-39404.stderr +++ b/tests/ui/macros/issue-39404.stderr @@ -10,3 +10,14 @@ LL | macro_rules! m { ($i) => {} } error: aborting due to 1 previous error +Future incompatibility report: Future breakage diagnostic: +error: missing fragment specifier + --> $DIR/issue-39404.rs:3:19 + | +LL | macro_rules! m { ($i) => {} } + | ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #40107 + = note: `#[deny(missing_fragment_specifier)]` on by default + diff --git a/tests/ui/macros/macro-match-nonterminal.stderr b/tests/ui/macros/macro-match-nonterminal.stderr index ef7261c02394a..831579c4fefd5 100644 --- a/tests/ui/macros/macro-match-nonterminal.stderr +++ b/tests/ui/macros/macro-match-nonterminal.stderr @@ -25,3 +25,25 @@ LL | ($a, $b) => { error: aborting due to 3 previous errors +Future incompatibility report: Future breakage diagnostic: +error: missing fragment specifier + --> $DIR/macro-match-nonterminal.rs:2:8 + | +LL | ($a, $b) => { + | ^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #40107 + = note: `#[deny(missing_fragment_specifier)]` on by default + +Future breakage diagnostic: +error: missing fragment specifier + --> $DIR/macro-match-nonterminal.rs:2:10 + | +LL | ($a, $b) => { + | ^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #40107 + = note: `#[deny(missing_fragment_specifier)]` on by default + diff --git a/tests/ui/macros/macro-missing-fragment-deduplication.stderr b/tests/ui/macros/macro-missing-fragment-deduplication.stderr index 3b9e716e194d5..c46712f70fd53 100644 --- a/tests/ui/macros/macro-missing-fragment-deduplication.stderr +++ b/tests/ui/macros/macro-missing-fragment-deduplication.stderr @@ -16,3 +16,14 @@ LL | ($name) => {} error: aborting due to 2 previous errors +Future incompatibility report: Future breakage diagnostic: +error: missing fragment specifier + --> $DIR/macro-missing-fragment-deduplication.rs:4:6 + | +LL | ($name) => {} + | ^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #40107 + = note: `#[deny(missing_fragment_specifier)]` on by default + diff --git a/tests/ui/macros/macro-missing-fragment.stderr b/tests/ui/macros/macro-missing-fragment.stderr index 1089f67f4336d..abe4d4cd68a2b 100644 --- a/tests/ui/macros/macro-missing-fragment.stderr +++ b/tests/ui/macros/macro-missing-fragment.stderr @@ -38,3 +38,48 @@ LL | ( $name ) => {}; error: aborting due to 1 previous error; 3 warnings emitted +Future incompatibility report: Future breakage diagnostic: +warning: missing fragment specifier + --> $DIR/macro-missing-fragment.rs:4:20 + | +LL | ( $( any_token $field_rust_type )* ) => {}; + | ^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #40107 +note: the lint level is defined here + --> $DIR/macro-missing-fragment.rs:1:9 + | +LL | #![warn(missing_fragment_specifier)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: missing fragment specifier + --> $DIR/macro-missing-fragment.rs:12:7 + | +LL | ( $name ) => {}; + | ^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #40107 +note: the lint level is defined here + --> $DIR/macro-missing-fragment.rs:1:9 + | +LL | #![warn(missing_fragment_specifier)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: missing fragment specifier + --> $DIR/macro-missing-fragment.rs:18:7 + | +LL | ( $name ) => {}; + | ^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #40107 +note: the lint level is defined here + --> $DIR/macro-missing-fragment.rs:1:9 + | +LL | #![warn(missing_fragment_specifier)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/ui/parser/macro/issue-33569.stderr b/tests/ui/parser/macro/issue-33569.stderr index 0dca090fb87c2..d1b6abfeeebfd 100644 --- a/tests/ui/parser/macro/issue-33569.stderr +++ b/tests/ui/parser/macro/issue-33569.stderr @@ -28,3 +28,14 @@ LL | { $+ } => { error: aborting due to 4 previous errors +Future incompatibility report: Future breakage diagnostic: +error: missing fragment specifier + --> $DIR/issue-33569.rs:2:8 + | +LL | { $+ } => { + | ^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #40107 + = note: `#[deny(missing_fragment_specifier)]` on by default +