11use crate :: core:: { Edition , Feature , Features , Manifest , Package } ;
22use crate :: { CargoResult , GlobalContext } ;
3- use annotate_snippets:: { Level , Snippet } ;
3+ use annotate_snippets:: { AnnotationKind , Group , Level , Snippet } ;
44use cargo_util_schemas:: manifest:: { TomlLintLevel , TomlToolLints } ;
55use pathdiff:: diff_paths;
66use std:: fmt:: Display ;
@@ -133,18 +133,16 @@ fn verify_feature_enabled(
133133 dash_feature_name
134134 ) ;
135135
136- let message = if let Some ( span) =
137- get_span ( manifest. document ( ) , & [ "lints" , "cargo" , lint_name] , false )
138- {
139- Level :: Error
140- . title ( & title)
141- . snippet (
142- Snippet :: source ( manifest. contents ( ) )
143- . origin ( & manifest_path)
144- . annotation ( Level :: Error . span ( span) . label ( & label) )
145- . fold ( true ) ,
146- )
147- . footer ( Level :: Help . title ( & help) )
136+ let mut groups = Vec :: new ( ) ;
137+ let mut group = Group :: with_title ( Level :: ERROR . primary_title ( title) ) ;
138+
139+ if let Some ( span) = get_span ( manifest. document ( ) , & [ "lints" , "cargo" , lint_name] , false ) {
140+ group = group. element (
141+ Snippet :: source ( manifest. contents ( ) )
142+ . path ( manifest_path)
143+ . annotation ( AnnotationKind :: Primary . span ( span) . label ( label) ) ,
144+ ) ;
145+ group = group. element ( Level :: HELP . message ( help) ) ;
148146 } else {
149147 let lint_span = get_span (
150148 ws_document,
@@ -154,37 +152,37 @@ fn verify_feature_enabled(
154152 . unwrap_or_else ( || {
155153 panic ! ( "could not find `cargo::{lint_name}` in `[lints]`, or `[workspace.lints]` " )
156154 } ) ;
155+ group = group. element (
156+ Snippet :: source ( ws_contents)
157+ . path ( ws_path)
158+ . annotation ( AnnotationKind :: Primary . span ( lint_span) . label ( & label) ) ,
159+ ) ;
157160
158- let inherited_note = if let ( Some ( inherit_span_key) , Some ( inherit_span_value) ) = (
161+ if let ( Some ( inherit_span_key) , Some ( inherit_span_value) ) = (
159162 get_span ( manifest. document ( ) , & [ "lints" , "workspace" ] , false ) ,
160163 get_span ( manifest. document ( ) , & [ "lints" , "workspace" ] , true ) ,
161164 ) {
162- Level :: Note . title ( & second_title) . snippet (
165+ let mut temp_group = Group :: with_title ( Level :: NOTE . secondary_title ( second_title) ) ;
166+ std:: mem:: swap ( & mut group, & mut temp_group) ;
167+ groups. push ( temp_group) ;
168+
169+ group = group. element (
163170 Snippet :: source ( manifest. contents ( ) )
164- . origin ( & manifest_path)
171+ . path ( manifest_path)
165172 . annotation (
166- Level :: Note . span ( inherit_span_key . start ..inherit_span_value . end ) ,
167- )
168- . fold ( true ) ,
169- )
173+ AnnotationKind :: Context
174+ . span ( inherit_span_key . start ..inherit_span_value . end ) ,
175+ ) ,
176+ ) ;
170177 } else {
171- Level :: Note . title ( & second_title)
178+ group = group . element ( Level :: NOTE . message ( second_title) ) ;
172179 } ;
173180
174- Level :: Error
175- . title ( & title)
176- . snippet (
177- Snippet :: source ( ws_contents)
178- . origin ( & ws_path)
179- . annotation ( Level :: Error . span ( lint_span) . label ( & label) )
180- . fold ( true ) ,
181- )
182- . footer ( inherited_note)
183- . footer ( Level :: Help . title ( & help) )
181+ group = group. element ( Level :: HELP . message ( help) ) ;
184182 } ;
185-
183+ groups . push ( group ) ;
186184 * error_count += 1 ;
187- gctx. shell ( ) . print_message ( message ) ?;
185+ gctx. shell ( ) . print_report ( & groups ) ?;
188186 }
189187 Ok ( ( ) )
190188}
@@ -337,12 +335,12 @@ impl LintLevel {
337335 self == & LintLevel :: Forbid || self == & LintLevel :: Deny
338336 }
339337
340- pub fn to_diagnostic_level ( self ) -> Level {
338+ pub fn to_diagnostic_level ( self ) -> Level < ' static > {
341339 match self {
342340 LintLevel :: Allow => unreachable ! ( "allow does not map to a diagnostic level" ) ,
343- LintLevel :: Warn => Level :: Warning ,
344- LintLevel :: Deny => Level :: Error ,
345- LintLevel :: Forbid => Level :: Error ,
341+ LintLevel :: Warn => Level :: WARNING ,
342+ LintLevel :: Deny => Level :: ERROR ,
343+ LintLevel :: Forbid => Level :: ERROR ,
346344 }
347345 }
348346}
@@ -457,17 +455,15 @@ pub fn check_im_a_teapot(
457455
458456 let key_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , false ) . unwrap ( ) ;
459457 let value_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , true ) . unwrap ( ) ;
460- let message = level
461- . title ( IM_A_TEAPOT . desc )
462- . snippet (
458+ let message = & [ Group :: with_title ( level. primary_title ( IM_A_TEAPOT . desc ) )
459+ . element (
463460 Snippet :: source ( manifest. contents ( ) )
464- . origin ( & manifest_path)
465- . annotation ( level. span ( key_span. start ..value_span. end ) )
466- . fold ( true ) ,
461+ . path ( & manifest_path)
462+ . annotation ( AnnotationKind :: Primary . span ( key_span. start ..value_span. end ) ) ,
467463 )
468- . footer ( Level :: Note . title ( & emitted_reason) ) ;
464+ . element ( Level :: NOTE . message ( & emitted_reason) ) ] ;
469465
470- gctx. shell ( ) . print_message ( message) ?;
466+ gctx. shell ( ) . print_report ( message) ?;
471467 }
472468 Ok ( ( ) )
473469}
@@ -535,21 +531,23 @@ fn output_unknown_lints(
535531 let help =
536532 matching. map ( |( name, kind) | format ! ( "there is a {kind} with a similar name: `{name}`" ) ) ;
537533
538- let mut footers = Vec :: new ( ) ;
539- if emitted_source. is_none ( ) {
540- emitted_source = Some ( UNKNOWN_LINTS . emitted_source ( lint_level, reason) ) ;
541- footers. push ( Level :: Note . title ( emitted_source. as_ref ( ) . unwrap ( ) ) ) ;
542- }
534+ let mut groups = Vec :: new ( ) ;
535+ let mut group = Group :: with_title ( level. clone ( ) . primary_title ( title) ) ;
543536
544- let mut message = if let Some ( span) =
545- get_span ( manifest. document ( ) , & [ "lints" , "cargo" , lint_name] , false )
546- {
547- level. title ( & title) . snippet (
537+ if let Some ( span) = get_span ( manifest. document ( ) , & [ "lints" , "cargo" , lint_name] , false ) {
538+ group = group. element (
548539 Snippet :: source ( manifest. contents ( ) )
549- . origin ( & manifest_path)
550- . annotation ( Level :: Error . span ( span) )
551- . fold ( true ) ,
552- )
540+ . path ( manifest_path)
541+ . annotation ( AnnotationKind :: Primary . span ( span) ) ,
542+ ) ;
543+ if emitted_source. is_none ( ) {
544+ emitted_source = Some ( UNKNOWN_LINTS . emitted_source ( lint_level, reason) ) ;
545+ group = group. element ( Level :: NOTE . message ( emitted_source. as_ref ( ) . unwrap ( ) ) ) ;
546+ }
547+
548+ if let Some ( help) = help. as_ref ( ) {
549+ group = group. element ( Level :: HELP . message ( help) ) ;
550+ }
553551 } else {
554552 let lint_span = get_span (
555553 ws_document,
@@ -560,39 +558,43 @@ fn output_unknown_lints(
560558 panic ! ( "could not find `cargo::{lint_name}` in `[lints]`, or `[workspace.lints]` " )
561559 } ) ;
562560
563- let inherited_note = if let ( Some ( inherit_span_key) , Some ( inherit_span_value) ) = (
561+ group = group. element (
562+ Snippet :: source ( ws_contents)
563+ . path ( ws_path)
564+ . annotation ( AnnotationKind :: Primary . span ( lint_span) ) ,
565+ ) ;
566+ if emitted_source. is_none ( ) {
567+ emitted_source = Some ( UNKNOWN_LINTS . emitted_source ( lint_level, reason) ) ;
568+ group = group. element ( Level :: NOTE . message ( emitted_source. as_ref ( ) . unwrap ( ) ) ) ;
569+ }
570+
571+ if let Some ( help) = help. as_ref ( ) {
572+ group = group. element ( Level :: HELP . message ( help) ) ;
573+ }
574+
575+ if let ( Some ( inherit_span_key) , Some ( inherit_span_value) ) = (
564576 get_span ( manifest. document ( ) , & [ "lints" , "workspace" ] , false ) ,
565577 get_span ( manifest. document ( ) , & [ "lints" , "workspace" ] , true ) ,
566578 ) {
567- Level :: Note . title ( & second_title) . snippet (
579+ let mut temp_group = Group :: with_title ( Level :: NOTE . secondary_title ( second_title) ) ;
580+ std:: mem:: swap ( & mut group, & mut temp_group) ;
581+ groups. push ( temp_group) ;
582+
583+ group = group. element (
568584 Snippet :: source ( manifest. contents ( ) )
569- . origin ( & manifest_path)
585+ . path ( manifest_path)
570586 . annotation (
571- Level :: Note . span ( inherit_span_key . start ..inherit_span_value . end ) ,
572- )
573- . fold ( true ) ,
574- )
587+ AnnotationKind :: Context
588+ . span ( inherit_span_key . start ..inherit_span_value . end ) ,
589+ ) ,
590+ ) ;
575591 } else {
576- Level :: Note . title ( & second_title)
592+ group = group . element ( Level :: NOTE . message ( second_title) ) ;
577593 } ;
578- footers. push ( inherited_note) ;
579-
580- level. title ( & title) . snippet (
581- Snippet :: source ( ws_contents)
582- . origin ( & ws_path)
583- . annotation ( Level :: Error . span ( lint_span) )
584- . fold ( true ) ,
585- )
586594 } ;
587595
588- if let Some ( help) = help. as_ref ( ) {
589- footers. push ( Level :: Help . title ( help) ) ;
590- }
591- for footer in footers {
592- message = message. footer ( footer) ;
593- }
594-
595- gctx. shell ( ) . print_message ( message) ?;
596+ groups. push ( group) ;
597+ gctx. shell ( ) . print_report ( & groups) ?;
596598 }
597599
598600 Ok ( ( ) )
0 commit comments