@@ -18,7 +18,7 @@ use crate::translation::{to_fluent_args, Translate};
1818use crate :: {
1919 diagnostic:: DiagnosticLocation , CodeSuggestion , Diagnostic , DiagnosticId , DiagnosticMessage ,
2020 FluentBundle , Handler , LazyFallbackBundle , Level , MultiSpan , SubDiagnostic ,
21- SubstitutionHighlight , SuggestionStyle ,
21+ SubstitutionHighlight , SuggestionStyle , TerminalUrl ,
2222} ;
2323use rustc_lint_defs:: pluralize;
2424
@@ -66,6 +66,7 @@ impl HumanReadableErrorType {
6666 diagnostic_width : Option < usize > ,
6767 macro_backtrace : bool ,
6868 track_diagnostics : bool ,
69+ terminal_url : TerminalUrl ,
6970 ) -> EmitterWriter {
7071 let ( short, color_config) = self . unzip ( ) ;
7172 let color = color_config. suggests_using_colors ( ) ;
@@ -80,6 +81,7 @@ impl HumanReadableErrorType {
8081 diagnostic_width,
8182 macro_backtrace,
8283 track_diagnostics,
84+ terminal_url,
8385 )
8486 }
8587}
@@ -652,6 +654,7 @@ pub struct EmitterWriter {
652654
653655 macro_backtrace : bool ,
654656 track_diagnostics : bool ,
657+ terminal_url : TerminalUrl ,
655658}
656659
657660#[ derive( Debug ) ]
@@ -672,6 +675,7 @@ impl EmitterWriter {
672675 diagnostic_width : Option < usize > ,
673676 macro_backtrace : bool ,
674677 track_diagnostics : bool ,
678+ terminal_url : TerminalUrl ,
675679 ) -> EmitterWriter {
676680 let dst = Destination :: from_stderr ( color_config) ;
677681 EmitterWriter {
@@ -685,6 +689,7 @@ impl EmitterWriter {
685689 diagnostic_width,
686690 macro_backtrace,
687691 track_diagnostics,
692+ terminal_url,
688693 }
689694 }
690695
@@ -699,6 +704,7 @@ impl EmitterWriter {
699704 diagnostic_width : Option < usize > ,
700705 macro_backtrace : bool ,
701706 track_diagnostics : bool ,
707+ terminal_url : TerminalUrl ,
702708 ) -> EmitterWriter {
703709 EmitterWriter {
704710 dst : Raw ( dst, colored) ,
@@ -711,6 +717,7 @@ impl EmitterWriter {
711717 diagnostic_width,
712718 macro_backtrace,
713719 track_diagnostics,
720+ terminal_url,
714721 }
715722 }
716723
@@ -1378,7 +1385,13 @@ impl EmitterWriter {
13781385 // only render error codes, not lint codes
13791386 if let Some ( DiagnosticId :: Error ( ref code) ) = * code {
13801387 buffer. append ( 0 , "[" , Style :: Level ( * level) ) ;
1381- buffer. append ( 0 , code, Style :: Level ( * level) ) ;
1388+ let code = if let TerminalUrl :: Yes = self . terminal_url {
1389+ let path = "https://doc.rust-lang.org/error_codes" ;
1390+ format ! ( "\x1b ]8;;{path}/{code}.html\x07 {code}\x1b ]8;;\x07 " )
1391+ } else {
1392+ code. clone ( )
1393+ } ;
1394+ buffer. append ( 0 , & code, Style :: Level ( * level) ) ;
13821395 buffer. append ( 0 , "]" , Style :: Level ( * level) ) ;
13831396 label_width += 2 + code. len ( ) ;
13841397 }
0 commit comments