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 0330525

Browse files
Explicitly handle all nodes in generics_of when computing parent
1 parent b94bd12 commit 0330525

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

‎compiler/rustc_hir_analysis/src/collect/generics_of.rs‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::assert_matches::assert_matches;
22
use std::ops::ControlFlow;
33

4-
use hir::intravisit::{self, Visitor};
5-
use hir::{GenericParamKind, HirId, Node};
64
use rustc_hir::def::DefKind;
75
use rustc_hir::def_id::LocalDefId;
8-
use rustc_hir::intravisit::VisitorExt;
9-
use rustc_hir::{self as hir, AmbigArg};
6+
use rustc_hir::intravisit::{self, Visitor, VisitorExt};
7+
use rustc_hir::{self as hir, AmbigArg, GenericParamKind, HirId, Node};
8+
use rustc_middle::span_bug;
109
use rustc_middle::ty::{self, TyCtxt};
1110
use rustc_session::lint;
1211
use rustc_span::{Span, Symbol, kw};
@@ -212,7 +211,19 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
212211
// inherit the generics of the item.
213212
Some(parent.to_def_id())
214213
}
215-
_ => None,
214+
215+
// All of these nodes have no parent from which to inherit generics.
216+
Node::Item(_) | Node::ForeignItem(_) => None,
217+
218+
// Params don't really have generics, but we use it when instantiating their value paths.
219+
Node::GenericParam(_) => None,
220+
221+
Node::Synthetic => span_bug!(
222+
tcx.def_span(def_id),
223+
"synthetic HIR should have its `generics_of` explicitly fed"
224+
),
225+
226+
_ => span_bug!(tcx.def_span(def_id), "unhandled node {node:?}"),
216227
};
217228

218229
enum Defaults {

0 commit comments

Comments
(0)

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