Skip to content

Commit 579b2c3

Browse files
authored
Merge pull request #318 from dtolnay/headingnote
Normalize indentation of consteval notes
2 parents e1d19ae + 9485845 commit 579b2c3

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

src/normalize.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ normalizations! {
6262
AndOthersVerbose,
6363
UnindentMultilineNote,
6464
DependencyVersion,
65+
HeadingNote,
6566
// New normalization steps are to be inserted here at the end so that any
6667
// snapshots saved before your normalization change remain passing.
6768
}
@@ -562,7 +563,7 @@ fn unindent(diag: String, normalization: Normalization) -> String {
562563
normalized.push_str(line);
563564
normalized.push('\n');
564565

565-
if indented_line_kind(line, &mut false, normalization) != IndentedLineKind::Heading {
566+
if indented_line_kind(line, true, &mut false, normalization) != IndentedLineKind::Heading {
566567
continue;
567568
}
568569

@@ -572,14 +573,15 @@ fn unindent(diag: String, normalization: Normalization) -> String {
572573
};
573574

574575
if let IndentedLineKind::Code(indent) =
575-
indented_line_kind(next_line, &mut false, normalization)
576+
indented_line_kind(next_line, false, &mut false, normalization)
576577
{
577578
if next_line[indent + 1..].starts_with("--> ") {
578579
let mut lines_in_block = 1;
579580
let mut least_indent = indent;
580581
let mut previous_line_is_note = false;
581582
while let Some(line) = ahead.next() {
582-
match indented_line_kind(line, &mut previous_line_is_note, normalization) {
583+
match indented_line_kind(line, false, &mut previous_line_is_note, normalization)
584+
{
583585
IndentedLineKind::Heading => break,
584586
IndentedLineKind::Code(indent) => {
585587
lines_in_block += 1;
@@ -599,7 +601,7 @@ fn unindent(diag: String, normalization: Normalization) -> String {
599601
for _ in 0..lines_in_block {
600602
let line = lines.next().unwrap();
601603
if let IndentedLineKind::Code(_) | IndentedLineKind::Other(_) =
602-
indented_line_kind(line, &mut previous_line_is_note, normalization)
604+
indented_line_kind(line, false, &mut previous_line_is_note, normalization)
603605
{
604606
let space = line.find(' ').unwrap();
605607
normalized.push_str(&line[..space]);
@@ -618,6 +620,7 @@ fn unindent(diag: String, normalization: Normalization) -> String {
618620

619621
fn indented_line_kind(
620622
line: &str,
623+
first_line_in_block: bool,
621624
previous_line_is_note: &mut bool,
622625
normalization: Normalization,
623626
) -> IndentedLineKind {
@@ -635,6 +638,10 @@ fn indented_line_kind(
635638
}
636639
}
637640

641+
if first_line_in_block && normalization >= HeadingNote && line.starts_with("note: ") {
642+
return IndentedLineKind::Heading;
643+
}
644+
638645
if line.starts_with("note:")
639646
|| line == "..."
640647
|| normalization >= UnindentAfterHelp && line.starts_with("help:")

src/tests/consteval.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
test_normalize! {
2+
WORKSPACE="/git/monostate"
3+
"
4+
error[E0080]: evaluation panicked: assertion failed: N == mem::size_of::<T::Type>()
5+
--> /git/monostate/src/string.rs:46:13
6+
|
7+
46 | assert!(N == mem::size_of::<T::Type>());
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `<(monostate::alphabet::len<8>, (monostate::alphabet::char<'a'>, monostate::alphabet::char<'s'>, monostate::alphabet::char<'d'>, monostate::alphabet::char<'f'>)) as monostate::string::Sealed>::__private::{constant#0}` failed here
9+
10+
note: erroneous constant encountered
11+
--> /git/monostate/src/string.rs:45:9
12+
|
13+
45 | / const {
14+
46 | | assert!(N == mem::size_of::<T::Type>());
15+
47 | | }
16+
| |_________^
17+
18+
note: erroneous constant encountered
19+
--> /git/monostate/src/string.rs:29:33
20+
|
21+
29 | const VALUE: &'static str = T::__private.0;
22+
| ^^^^^^^^^^^^
23+
24+
note: erroneous constant encountered
25+
--> /git/monostate/src/value.rs:132:37
26+
|
27+
132 | pub const VALUE: &'static str = V::VALUE;
28+
| ^^^^^^^^
29+
" "
30+
error[E0080]: evaluation panicked: assertion failed: N == mem::size_of::<T::Type>()
31+
--> $WORKSPACE/src/string.rs
32+
|
33+
| assert!(N == mem::size_of::<T::Type>());
34+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `<(monostate::alphabet::len<8>, (monostate::alphabet::char<'a'>, monostate::alphabet::char<'s'>, monostate::alphabet::char<'d'>, monostate::alphabet::char<'f'>)) as monostate::string::Sealed>::__private::{constant#0}` failed here
35+
36+
note: erroneous constant encountered
37+
--> $WORKSPACE/src/string.rs
38+
|
39+
| / const {
40+
| | assert!(N == mem::size_of::<T::Type>());
41+
| | }
42+
| |_________^
43+
44+
note: erroneous constant encountered
45+
--> $WORKSPACE/src/string.rs
46+
|
47+
| const VALUE: &'static str = T::__private.0;
48+
| ^^^^^^^^^^^^
49+
50+
note: erroneous constant encountered
51+
--> $WORKSPACE/src/value.rs
52+
|
53+
| pub const VALUE: &'static str = V::VALUE;
54+
| ^^^^^^^^
55+
"}

0 commit comments

Comments
 (0)