Skip to content

Commit 177666b

Browse files
committed
chore!: Remove Origin::primary
1 parent ab439c5 commit 177666b

File tree

4 files changed

+66
-84
lines changed

4 files changed

+66
-84
lines changed

src/renderer/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,6 @@ impl Renderer {
346346
max_line_num_len + 1,
347347
);
348348
}
349-
Some(Element::Origin(origin)) if origin.primary => self
350-
.draw_col_separator_end(
351-
&mut buffer,
352-
current_line,
353-
max_line_num_len + 1,
354-
),
355349
None if group_len > 1 => self.draw_col_separator_end(
356350
&mut buffer,
357351
current_line,
@@ -386,6 +380,7 @@ impl Renderer {
386380
&mut buffer,
387381
max_line_num_len,
388382
origin,
383+
is_primary,
389384
buffer_msg_line_offset,
390385
);
391386
last_was_suggestion = false;
@@ -472,7 +467,6 @@ impl Renderer {
472467

473468
if let Some(path) = &cause.path {
474469
let mut origin = Origin::path(path.as_ref());
475-
origin.primary = true;
476470

477471
let source_map = SourceMap::new(&cause.source, cause.line_start);
478472
let (_depth, annotated_lines) =
@@ -493,7 +487,7 @@ impl Renderer {
493487
}
494488
}
495489

496-
self.render_origin(&mut buffer, 0, &origin, 0);
490+
self.render_origin(&mut buffer, 0, &origin, true, 0);
497491
buffer.append(0, ": ", ElementStyle::LineAndColumn);
498492
}
499493
}
@@ -641,9 +635,10 @@ impl Renderer {
641635
buffer: &mut StyledBuffer,
642636
max_line_num_len: usize,
643637
origin: &Origin<'_>,
638+
is_primary: bool,
644639
buffer_msg_line_offset: usize,
645640
) {
646-
if origin.primary && !self.short_message {
641+
if is_primary && !self.short_message {
647642
buffer.prepend(
648643
buffer_msg_line_offset,
649644
self.file_start(),
@@ -712,7 +707,6 @@ impl Renderer {
712707
//let is_primary = primary_path == Some(&origin.path);
713708

714709
if is_primary {
715-
origin.primary = true;
716710
if let Some(primary_line) = annotated_lines
717711
.iter()
718712
.find(|l| l.annotations.iter().any(LineAnnotation::is_primary))
@@ -752,7 +746,13 @@ impl Renderer {
752746
}
753747
}
754748
let buffer_msg_line_offset = buffer.num_lines();
755-
self.render_origin(buffer, max_line_num_len, &origin, buffer_msg_line_offset);
749+
self.render_origin(
750+
buffer,
751+
max_line_num_len,
752+
&origin,
753+
is_primary,
754+
buffer_msg_line_offset,
755+
);
756756
// Put in the spacer between the location and annotated source
757757
self.draw_col_separator_no_space(
758758
buffer,

src/snippet.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ pub struct Origin<'a> {
437437
pub(crate) path: Cow<'a, str>,
438438
pub(crate) line: Option<usize>,
439439
pub(crate) char_column: Option<usize>,
440-
pub(crate) primary: bool,
441440
}
442441

443442
impl<'a> Origin<'a> {
@@ -453,7 +452,6 @@ impl<'a> Origin<'a> {
453452
path: path.into(),
454453
line: None,
455454
char_column: None,
456-
primary: false,
457455
}
458456
}
459457

@@ -474,12 +472,6 @@ impl<'a> Origin<'a> {
474472
self.char_column = Some(char_column);
475473
self
476474
}
477-
478-
/// Mark this as the source that the [Group's Title][Group::with_title] references
479-
pub fn primary(mut self, primary: bool) -> Self {
480-
self.primary = primary;
481-
self
482-
}
483475
}
484476

485477
impl<'a> From<Cow<'a, str>> for Origin<'a> {

tests/color/multiline_removal_suggestion.term.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/rustc_tests.rs

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,6 @@ fn main() {
17461746
Origin::path("$SRC_DIR/core/src/cmp.rs")
17471747
.line(334)
17481748
.char_column(14)
1749-
.primary(true)
17501749
)
17511750
.element(Padding)
17521751
.element(Level::NOTE.message("...because it uses `Self` as a type parameter"))
@@ -2901,8 +2900,7 @@ fn main() {
29012900
.element(
29022901
Origin::path("$SRC_DIR/alloc/src/boxed.rs")
29032902
.line(231)
2904-
.char_column(0)
2905-
.primary(true),
2903+
.char_column(0),
29062904
)
29072905
.element(
29082906
Origin::path("$SRC_DIR/alloc/src/boxed.rs")
@@ -3013,21 +3011,20 @@ fn main() {
30133011
let title_1 = "trait `Future` which provides `poll` is implemented but not in scope; perhaps you want to import it";
30143012

30153013
let input = &[
3016-
Group::with_title(Level::ERROR.title(title_0).id("E0599"))
3017-
.element(
3018-
Snippet::source(source)
3019-
.path("$DIR/dont-project-to-specializable-projection.rs")
3020-
.annotation(
3021-
AnnotationKind::Primary
3022-
.span(1071..1075)
3023-
.label("method not found in `Pin<&mut impl Future<Output = ()>>`"),
3024-
),
3025-
)
3014+
Group::with_title(Level::ERROR.title(title_0).id("E0599")).element(
3015+
Snippet::source(source)
3016+
.path("$DIR/dont-project-to-specializable-projection.rs")
3017+
.annotation(
3018+
AnnotationKind::Primary
3019+
.span(1071..1075)
3020+
.label("method not found in `Pin<&mut impl Future<Output = ()>>`"),
3021+
),
3022+
),
3023+
Group::with_level(Level::ERROR)
30263024
.element(
30273025
Origin::path("$SRC_DIR/core/src/future/future.rs")
30283026
.line(104)
3029-
.char_column(7)
3030-
.primary(true),
3027+
.char_column(7),
30313028
)
30323029
.element(Padding)
30333030
.element(
@@ -3136,16 +3133,15 @@ fn main() {
31363133
.element(
31373134
Origin::path("$SRC_DIR/std/src/io/error.rs")
31383135
.line(65)
3139-
.char_column(0)
3140-
.primary(true),
3136+
.char_column(0),
31413137
)
31423138
.element(Padding)
3143-
.element(Level::NOTE.message("not implement `PartialEq`"))
3139+
.element(Level::NOTE.message("not implement `PartialEq`")),
3140+
Group::with_level(Level::NOTE)
31443141
.element(
31453142
Origin::path("$SRC_DIR/std/src/thread/mod.rs")
31463143
.line(1415)
3147-
.char_column(0)
3148-
.primary(true),
3144+
.char_column(0),
31493145
)
31503146
.element(Padding)
31513147
.element(Level::NOTE.message("not implement `PartialEq`")),
@@ -3204,31 +3200,31 @@ struct Foo;
32043200
pub fn main() {}
32053201
"#;
32063202

3207-
let input =
3208-
&[
3209-
Group::with_title(Level::ERROR.title("cannot find derive macro `Eqr` in this scope"))
3210-
.element(
3211-
Snippet::source(source)
3212-
.path("$DIR/deriving-meta-unknown-trait.rs")
3213-
.annotation(
3214-
AnnotationKind::Primary
3215-
.span(9..12)
3216-
.label("help: a derive macro with a similar name exists: `Eq`"),
3217-
),
3218-
)
3219-
.element(
3220-
Origin::path("$SRC_DIR/core/src/cmp.rs")
3221-
.line(356)
3222-
.char_column(0)
3223-
.primary(true),
3224-
)
3225-
.element(Padding)
3226-
.element(Level::NOTE.message("similarly named derive macro `Eq` defined here"))
3227-
.element(Padding)
3228-
.element(Level::NOTE.message(
3229-
"duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`",
3230-
)),
3231-
];
3203+
let input = &[
3204+
Group::with_title(Level::ERROR.title("cannot find derive macro `Eqr` in this scope"))
3205+
.element(
3206+
Snippet::source(source)
3207+
.path("$DIR/deriving-meta-unknown-trait.rs")
3208+
.annotation(
3209+
AnnotationKind::Primary
3210+
.span(9..12)
3211+
.label("help: a derive macro with a similar name exists: `Eq`"),
3212+
),
3213+
),
3214+
Group::with_level(Level::ERROR)
3215+
.element(
3216+
Origin::path("$SRC_DIR/core/src/cmp.rs")
3217+
.line(356)
3218+
.char_column(0),
3219+
)
3220+
.element(Padding)
3221+
.element(Level::NOTE.message("similarly named derive macro `Eq` defined here"))
3222+
.element(Padding)
3223+
.element(
3224+
Level::NOTE
3225+
.message("duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`"),
3226+
),
3227+
];
32323228

32333229
let expected_ascii = str![[r#"
32343230
error: cannot find derive macro `Eqr` in this scope
@@ -3309,17 +3305,15 @@ which is required by `&mut Ipv4Addr: proc_macro::ext::RepIteratorExt`"#;
33093305
.element(
33103306
Origin::path("$SRC_DIR/proc_macro/src/to_tokens.rs")
33113307
.line(11)
3312-
.char_column(0)
3313-
.primary(true),
3314-
)
3315-
.element(
3308+
.char_column(0),
3309+
),
3310+
Group::with_level(Level::NOTE).element(
33163311
Origin::path("$SRC_DIR/core/src/iter/traits/iterator.rs")
33173312
.line(39)
3318-
.char_column(0)
3319-
.primary(true),
3313+
.char_column(0),
33203314
),
33213315
];
3322-
let expected_ascii = str![[r##"
3316+
let expected_ascii = str![[r#"
33233317
error[E0599]: the method `quote_into_iter` exists for struct `Ipv4Addr`, but its trait bounds were not satisfied
33243318
--> $DIR/not-repeatable.rs:11:13
33253319
|
@@ -3341,7 +3335,7 @@ LL | let _ = quote! { $($ip)* }; //~ ERROR the method `quote_into_iter` exis
33413335
note: the traits `Iterator` and `ToTokens` must be implemented
33423336
--> $SRC_DIR/proc_macro/src/to_tokens.rs:11:0
33433337
--> $SRC_DIR/core/src/iter/traits/iterator.rs:39:0
3344-
"##]];
3338+
"#]];
33453339
let renderer = Renderer::plain().anonymized_line_numbers(true);
33463340
assert_data_eq!(renderer.render(input), expected_ascii);
33473341

@@ -3575,8 +3569,7 @@ fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }
35753569
.element(
35763570
Origin::path("$SRC_DIR/core/src/alloc/layout.rs")
35773571
.line(40)
3578-
.char_column(0)
3579-
.primary(true),
3572+
.char_column(0),
35803573
),
35813574
Group::with_title(Level::NOTE.title("`Layout` is defined in the current crate")).element(
35823575
Snippet::source(source)
@@ -3733,8 +3726,7 @@ fn main() {
37333726
.element(
37343727
Origin::path("$SRC_DIR/core/src/option.rs")
37353728
.line(593)
3736-
.char_column(0)
3737-
.primary(true),
3729+
.char_column(0),
37383730
)
37393731
.element(
37403732
Origin::path("$SRC_DIR/core/src/option.rs")
@@ -3822,8 +3814,7 @@ for more information, visit <https://doc.rust-lang.org/reference/items/traits.ht
38223814
.element(
38233815
Origin::path("$SRC_DIR/core/src/cmp.rs")
38243816
.line(961)
3825-
.char_column(20)
3826-
.primary(true),
3817+
.char_column(20),
38273818
)
38283819
.element(Padding)
38293820
.element(Level::NOTE.message(
@@ -3920,16 +3911,15 @@ fn main() {
39203911
.element(
39213912
Origin::path("$SRC_DIR/std/src/io/error.rs")
39223913
.line(65)
3923-
.char_column(0)
3924-
.primary(true),
3914+
.char_column(0),
39253915
)
39263916
.element(Padding)
3927-
.element(Level::NOTE.message("not implement `PartialEq`"))
3917+
.element(Level::NOTE.message("not implement `PartialEq`")),
3918+
Group::with_level(Level::NOTE)
39283919
.element(
39293920
Origin::path("$SRC_DIR/std/src/thread/mod.rs")
39303921
.line(1439)
3931-
.char_column(0)
3932-
.primary(true),
3922+
.char_column(0),
39333923
)
39343924
.element(Padding)
39353925
.element(Level::NOTE.message("not implement `PartialEq`")),

0 commit comments

Comments
 (0)