Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bcd4e2e

Browse files
Add support for trait associated items
1 parent 0a62c9e commit bcd4e2e

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

‎src/librustdoc/html/render/span_map.rs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
44
use rustc_hir::def::{DefKind, Res};
55
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
66
use rustc_hir::intravisit::{self, Visitor};
7-
use rustc_hir::{ExprKind, HirId, Item, ItemKind, Mod, Node, Pat,PatKind,QPath};
7+
use rustc_hir::{ExprKind, HirId, Item, ItemKind, Mod, Node, QPath};
88
use rustc_middle::hir::nested_filter;
99
use rustc_middle::ty::TyCtxt;
1010
use rustc_span::hygiene::MacroKind;
@@ -189,27 +189,6 @@ impl SpanMapVisitor<'_> {
189189
self.matches.insert(span, link);
190190
}
191191
}
192-
193-
fn handle_pat(&mut self, p: &Pat<'_>) {
194-
match p.kind {
195-
PatKind::Binding(_, _, _, Some(p)) => self.handle_pat(p),
196-
PatKind::Struct(qpath, _, _)
197-
| PatKind::TupleStruct(qpath, _, _)
198-
| PatKind::Path(qpath) => match qpath {
199-
QPath::TypeRelative(_, path) if matches!(path.res, Res::Err) => {
200-
self.infer_id(path.hir_id, Some(p.hir_id), qpath.span());
201-
}
202-
QPath::Resolved(_, path) => self.handle_path(path),
203-
_ => {}
204-
},
205-
PatKind::Or(pats) => {
206-
for pat in pats {
207-
self.handle_pat(pat);
208-
}
209-
}
210-
_ => {}
211-
}
212-
}
213192
}
214193

215194
impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
@@ -227,8 +206,36 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
227206
intravisit::walk_path(self, path);
228207
}
229208

230-
fn visit_pat(&mut self, p: &Pat<'tcx>) {
231-
self.handle_pat(p);
209+
fn visit_qpath(&mut self, qpath: &QPath<'tcx>, id: HirId, span: Span) {
210+
match *qpath {
211+
QPath::TypeRelative(qself, path) => {
212+
if matches!(path.res, Res::Err) {
213+
let tcx = self.tcx;
214+
let hir = tcx.hir();
215+
let body_id = hir.enclosing_body_owner(id);
216+
let typeck_results = tcx.typeck_body(hir.body_owned_by(body_id).id());
217+
let path = rustc_hir::Path {
218+
// We change the span to not include parens.
219+
span: span.with_hi(path.ident.span.hi()),
220+
res: typeck_results.qpath_res(qpath, id),
221+
segments: &[],
222+
};
223+
self.handle_path(&path);
224+
} else {
225+
self.infer_id(path.hir_id, Some(id), span);
226+
}
227+
228+
rustc_ast::visit::try_visit!(self.visit_ty(qself));
229+
self.visit_path_segment(path);
230+
}
231+
QPath::Resolved(maybe_qself, path) => {
232+
self.handle_path(path);
233+
234+
rustc_ast::visit::visit_opt!(self, visit_ty, maybe_qself);
235+
self.visit_path(path, id)
236+
}
237+
_ => {}
238+
}
232239
}
233240

234241
fn visit_mod(&mut self, m: &'tcx Mod<'tcx>, span: Span, id: HirId) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ compile-flags: -Zunstable-options --generate-link-to-definition
2+
3+
#![crate_name = "foo"]
4+
5+
pub enum Ty {
6+
Var,
7+
}
8+
9+
//@ has 'src/foo/jump-to-def-assoc-items.rs.html'
10+
//@ has - '//a[@href="#6"]' 'Self::Var'
11+
impl Ty {
12+
fn f() {
13+
let _ = Self::Var;
14+
}
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /