Skip to content

Commit d0a45cf

Browse files
Fix Result and Option not getting a jump to def link generated
1 parent 717f5df commit d0a45cf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/librustdoc/html/highlight.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ impl<'a, 'tcx, F: Write> TokenHandler<'a, 'tcx, F> {
181181
// current parent tag is not the same as our pending content.
182182
let close_tag = if self.pending_elems.len() > 1
183183
&& let Some(current_class) = current_class
184+
// `PreludeTy` can never include more than an ident so it should not generate
185+
// a wrapping `span`.
186+
&& !matches!(current_class, Class::PreludeTy(_))
184187
{
185188
Some(enter_span(self.out, current_class, &self.href_context))
186189
} else {
@@ -333,7 +336,7 @@ enum Class {
333336
/// `Ident` isn't rendered in the HTML but we still need it for the `Span` it contains.
334337
Ident(Span),
335338
Lifetime,
336-
PreludeTy,
339+
PreludeTy(Span),
337340
PreludeVal,
338341
QuestionMark,
339342
Decoration(&'static str),
@@ -381,7 +384,7 @@ impl Class {
381384
Class::Bool => "bool-val",
382385
Class::Ident(_) => "",
383386
Class::Lifetime => "lifetime",
384-
Class::PreludeTy => "prelude-ty",
387+
Class::PreludeTy(_) => "prelude-ty",
385388
Class::PreludeVal => "prelude-val",
386389
Class::QuestionMark => "question-mark",
387390
Class::Decoration(kind) => kind,
@@ -392,7 +395,7 @@ impl Class {
392395
/// a "span" (a tuple representing `(lo, hi)` equivalent of `Span`).
393396
fn get_span(self) -> Option<Span> {
394397
match self {
395-
Self::Ident(sp) | Self::Self_(sp) | Self::Macro(sp) => Some(sp),
398+
Self::Ident(sp) | Self::Self_(sp) | Self::Macro(sp) | Self::PreludeTy(sp) => Some(sp),
396399
Self::Comment
397400
| Self::DocComment
398401
| Self::Attribute
@@ -403,14 +406,14 @@ impl Class {
403406
| Self::Number
404407
| Self::Bool
405408
| Self::Lifetime
406-
| Self::PreludeTy
407409
| Self::PreludeVal
408410
| Self::QuestionMark
409411
| Self::Decoration(_) => None,
410412
}
411413
}
412414
}
413415

416+
#[derive(Debug)]
414417
enum Highlight<'a> {
415418
Token { text: &'a str, class: Option<Class> },
416419
EnterSpan { class: Class },
@@ -847,7 +850,7 @@ impl<'src> Classifier<'src> {
847850
}
848851
TokenKind::Ident => match get_real_ident_class(text, false) {
849852
None => match text {
850-
"Option" | "Result" => Class::PreludeTy,
853+
"Option" | "Result" => Class::PreludeTy(self.new_span(before, text)),
851854
"Some" | "None" | "Ok" | "Err" => Class::PreludeVal,
852855
// "union" is a weak keyword and is only considered as a keyword when declaring
853856
// a union type.

0 commit comments

Comments
 (0)