@@ -26,7 +26,7 @@ use super::format::{self, Buffer};
26
26
use super :: render:: LinkFromSrc ;
27
27
28
28
/// This type is needed in case we want to render links on items to allow to go to their definition.
29
- pub ( crate ) struct ContextInfo < ' a , ' b , ' c > {
29
+ pub ( crate ) struct HrefContext < ' a , ' b , ' c > {
30
30
pub ( crate ) context : & ' a Context < ' b > ,
31
31
/// This span contains the current file we're going through.
32
32
pub ( crate ) file_span : Span ,
@@ -48,7 +48,7 @@ pub(crate) fn render_with_highlighting(
48
48
tooltip : Option < ( Option < Edition > , & str ) > ,
49
49
edition : Edition ,
50
50
extra_content : Option < Buffer > ,
51
- context_info : Option < ContextInfo < ' _ , ' _ , ' _ > > ,
51
+ href_context : Option < HrefContext < ' _ , ' _ , ' _ > > ,
52
52
decoration_info : Option < DecorationInfo > ,
53
53
) {
54
54
debug ! ( "highlighting: ================\n {}\n ==============" , src) ;
@@ -66,7 +66,7 @@ pub(crate) fn render_with_highlighting(
66
66
}
67
67
68
68
write_header ( out, class, extra_content) ;
69
- write_code ( out, src, edition, context_info , decoration_info) ;
69
+ write_code ( out, src, edition, href_context , decoration_info) ;
70
70
write_footer ( out, playground_button) ;
71
71
}
72
72
@@ -89,16 +89,16 @@ fn write_header(out: &mut Buffer, class: Option<&str>, extra_content: Option<Buf
89
89
///
90
90
/// Some explanations on the last arguments:
91
91
///
92
- /// In case we are rendering a code block and not a source code file, `context_info ` will be `None`.
93
- /// To put it more simply: if `context_info ` is `None`, the code won't try to generate links to an
92
+ /// In case we are rendering a code block and not a source code file, `href_context ` will be `None`.
93
+ /// To put it more simply: if `href_context ` is `None`, the code won't try to generate links to an
94
94
/// item definition.
95
95
///
96
96
/// More explanations about spans and how we use them here are provided in the
97
97
fn write_code (
98
98
out : & mut Buffer ,
99
99
src : & str ,
100
100
edition : Edition ,
101
- context_info : Option < ContextInfo < ' _ , ' _ , ' _ > > ,
101
+ href_context : Option < HrefContext < ' _ , ' _ , ' _ > > ,
102
102
decoration_info : Option < DecorationInfo > ,
103
103
) {
104
104
// This replace allows to fix how the code source with DOS backline characters is displayed.
@@ -107,13 +107,13 @@ fn write_code(
107
107
Classifier :: new (
108
108
& src,
109
109
edition,
110
- context_info . as_ref ( ) . map ( |c| c. file_span ) . unwrap_or ( DUMMY_SP ) ,
110
+ href_context . as_ref ( ) . map ( |c| c. file_span ) . unwrap_or ( DUMMY_SP ) ,
111
111
decoration_info,
112
112
)
113
113
. highlight ( & mut |highlight| {
114
114
match highlight {
115
- Highlight :: Token { text, class } => string ( out, Escape ( text) , class, & context_info ) ,
116
- Highlight :: EnterSpan { class } => closing_tag = enter_span ( out, class, & context_info ) ,
115
+ Highlight :: Token { text, class } => string ( out, Escape ( text) , class, & href_context ) ,
116
+ Highlight :: EnterSpan { class } => closing_tag = enter_span ( out, class, & href_context ) ,
117
117
Highlight :: ExitSpan => exit_span ( out, & closing_tag) ,
118
118
} ;
119
119
} ) ;
@@ -680,9 +680,9 @@ impl<'a> Classifier<'a> {
680
680
fn enter_span (
681
681
out : & mut Buffer ,
682
682
klass : Class ,
683
- context_info : & Option < ContextInfo < ' _ , ' _ , ' _ > > ,
683
+ href_context : & Option < HrefContext < ' _ , ' _ , ' _ > > ,
684
684
) -> & ' static str {
685
- string_without_closing_tag ( out, "" , Some ( klass) , context_info )
685
+ string_without_closing_tag ( out, "" , Some ( klass) , href_context )
686
686
. expect ( "no closing tag to close wrapper..." )
687
687
}
688
688
@@ -711,9 +711,9 @@ fn string<T: Display>(
711
711
out : & mut Buffer ,
712
712
text : T ,
713
713
klass : Option < Class > ,
714
- context_info : & Option < ContextInfo < ' _ , ' _ , ' _ > > ,
714
+ href_context : & Option < HrefContext < ' _ , ' _ , ' _ > > ,
715
715
) {
716
- if let Some ( closing_tag) = string_without_closing_tag ( out, text, klass, context_info ) {
716
+ if let Some ( closing_tag) = string_without_closing_tag ( out, text, klass, href_context ) {
717
717
out. write_str ( closing_tag) ;
718
718
}
719
719
}
@@ -722,7 +722,7 @@ fn string_without_closing_tag<T: Display>(
722
722
out : & mut Buffer ,
723
723
text : T ,
724
724
klass : Option < Class > ,
725
- context_info : & Option < ContextInfo < ' _ , ' _ , ' _ > > ,
725
+ href_context : & Option < HrefContext < ' _ , ' _ , ' _ > > ,
726
726
) -> Option < & ' static str > {
727
727
let Some ( klass) = klass
728
728
else {
@@ -754,10 +754,10 @@ fn string_without_closing_tag<T: Display>(
754
754
path
755
755
} ) ;
756
756
}
757
- if let Some ( context_info ) = context_info {
757
+ if let Some ( href_context ) = href_context {
758
758
if let Some ( href) =
759
- context_info . context . shared . span_correspondance_map . get ( & def_span) . and_then ( |href| {
760
- let context = context_info . context ;
759
+ href_context . context . shared . span_correspondance_map . get ( & def_span) . and_then ( |href| {
760
+ let context = href_context . context ;
761
761
// FIXME: later on, it'd be nice to provide two links (if possible) for all items:
762
762
// one to the documentation page and one to the source definition.
763
763
// FIXME: currently, external items only generate a link to their documentation,
@@ -766,15 +766,15 @@ fn string_without_closing_tag<T: Display>(
766
766
match href {
767
767
LinkFromSrc :: Local ( span) => context
768
768
. href_from_span ( * span, true )
769
- . map ( |s| format ! ( "{}{}" , context_info . root_path, s) ) ,
769
+ . map ( |s| format ! ( "{}{}" , href_context . root_path, s) ) ,
770
770
LinkFromSrc :: External ( def_id) => {
771
- format:: href_with_root_path ( * def_id, context, Some ( context_info . root_path ) )
771
+ format:: href_with_root_path ( * def_id, context, Some ( href_context . root_path ) )
772
772
. map ( |( url, _, _) | url)
773
773
. or_else ( |e| {
774
774
if e == format:: HrefError :: NotInExternalCache
775
775
&& matches ! ( klass, Class :: Macro ( _) )
776
776
{
777
- Ok ( generate_macro_def_id_path ( context_info , * def_id) )
777
+ Ok ( generate_macro_def_id_path ( href_context , * def_id) )
778
778
} else {
779
779
Err ( e)
780
780
}
@@ -784,7 +784,7 @@ fn string_without_closing_tag<T: Display>(
784
784
LinkFromSrc :: Primitive ( prim) => format:: href_with_root_path (
785
785
PrimitiveType :: primitive_locations ( context. tcx ( ) ) [ prim] ,
786
786
context,
787
- Some ( context_info . root_path ) ,
787
+ Some ( href_context . root_path ) ,
788
788
)
789
789
. ok ( )
790
790
. map ( |( url, _, _) | url) ,
@@ -801,10 +801,10 @@ fn string_without_closing_tag<T: Display>(
801
801
802
802
/// This function is to get the external macro path because they are not in the cache used n
803
803
/// `href_with_root_path`.
804
- fn generate_macro_def_id_path ( context_info : & ContextInfo < ' _ , ' _ , ' _ > , def_id : DefId ) -> String {
805
- let tcx = context_info . context . shared . tcx ;
804
+ fn generate_macro_def_id_path ( href_context : & HrefContext < ' _ , ' _ , ' _ > , def_id : DefId ) -> String {
805
+ let tcx = href_context . context . shared . tcx ;
806
806
let crate_name = tcx. crate_name ( def_id. krate ) . to_string ( ) ;
807
- let cache = & context_info . context . cache ( ) ;
807
+ let cache = & href_context . context . cache ( ) ;
808
808
809
809
let relative = tcx. def_path ( def_id) . data . into_iter ( ) . filter_map ( |elem| {
810
810
// extern blocks have an empty name
@@ -825,7 +825,7 @@ fn generate_macro_def_id_path(context_info: &ContextInfo<'_, '_, '_>, def_id: De
825
825
826
826
let url_parts = match cache. extern_locations [ & def_id. krate ] {
827
827
ExternalLocation :: Remote ( ref s) => vec ! [ s. trim_end_matches( '/' ) ] ,
828
- ExternalLocation :: Local => vec ! [ context_info . root_path. trim_end_matches( '/' ) , & crate_name] ,
828
+ ExternalLocation :: Local => vec ! [ href_context . root_path. trim_end_matches( '/' ) , & crate_name] ,
829
829
ExternalLocation :: Unknown => panic ! ( "unknown crate" ) ,
830
830
} ;
831
831
0 commit comments