| 
1 | 1 | use std::assert_matches::assert_matches;  | 
2 | 2 | use std::ops::ControlFlow;  | 
3 | 3 | 
 
  | 
4 |  | -use hir::intravisit::{self, Visitor};  | 
5 |  | -use hir::{GenericParamKind, HirId, Node};  | 
6 | 4 | use rustc_hir::def::DefKind;  | 
7 | 5 | 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;  | 
10 | 9 | use rustc_middle::ty::{self, TyCtxt};  | 
11 | 10 | use rustc_session::lint;  | 
12 | 11 | use rustc_span::{Span, Symbol, kw};  | 
@@ -212,7 +211,19 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {  | 
212 | 211 |             // inherit the generics of the item.  | 
213 | 212 |             Some(parent.to_def_id())  | 
214 | 213 |         }  | 
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 insantiating 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:?}"),  | 
216 | 227 |     };  | 
217 | 228 | 
 
  | 
218 | 229 |     enum Defaults {  | 
 | 
0 commit comments