|
1 | 1 | use rustc_errors::{Applicability, ErrorReported, StashKey};
|
2 | 2 | use rustc_hir as hir;
|
3 |
| -use rustc_hir::def::CtorOf; |
4 |
| -use rustc_hir::def::{DefKind, Res}; |
| 3 | +use rustc_hir::def::Res; |
5 | 4 | use rustc_hir::def_id::{DefId, LocalDefId};
|
6 | 5 | use rustc_hir::intravisit;
|
7 | 6 | use rustc_hir::intravisit::Visitor;
|
8 | 7 | use rustc_hir::{HirId, Node};
|
9 | 8 | use rustc_middle::hir::nested_filter;
|
10 | 9 | use rustc_middle::ty::subst::InternalSubsts;
|
11 | 10 | use rustc_middle::ty::util::IntTypeExt;
|
12 |
| -use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt, TypeFoldable, TypeFolder}; |
| 11 | +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder}; |
13 | 12 | use rustc_span::symbol::Ident;
|
14 | 13 | use rustc_span::{Span, DUMMY_SP};
|
15 | 14 |
|
@@ -198,38 +197,9 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
198 | 197 | // Try to use the segment resolution if it is valid, otherwise we
|
199 | 198 | // default to the path resolution.
|
200 | 199 | let res = segment.res.filter(|&r| r != Res::Err).unwrap_or(path.res);
|
201 |
| - let generics = match res { |
202 |
| - Res::Def(DefKind::Ctor(CtorOf::Variant, _), def_id) => tcx |
203 |
| - .generics_of(tcx.parent(def_id).and_then(|def_id| tcx.parent(def_id)).unwrap()), |
204 |
| - Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Struct, _), def_id) => { |
205 |
| - tcx.generics_of(tcx.parent(def_id).unwrap()) |
206 |
| - } |
207 |
| - // Other `DefKind`s don't have generics and would ICE when calling |
208 |
| - // `generics_of`. |
209 |
| - Res::Def( |
210 |
| - DefKind::Struct |
211 |
| - | DefKind::Union |
212 |
| - | DefKind::Enum |
213 |
| - | DefKind::Trait |
214 |
| - | DefKind::OpaqueTy |
215 |
| - | DefKind::TyAlias |
216 |
| - | DefKind::ForeignTy |
217 |
| - | DefKind::TraitAlias |
218 |
| - | DefKind::AssocTy |
219 |
| - | DefKind::Fn |
220 |
| - | DefKind::AssocFn |
221 |
| - | DefKind::AssocConst |
222 |
| - | DefKind::Impl, |
223 |
| - def_id, |
224 |
| - ) => tcx.generics_of(def_id), |
225 |
| - Res::Err => { |
226 |
| - tcx.sess.delay_span_bug(tcx.def_span(def_id), "anon const with Res::Err"); |
227 |
| - return None; |
228 |
| - } |
229 |
| - _ => { |
230 |
| - // If the user tries to specify generics on a type that does not take them, |
231 |
| - // e.g. `usize<T>`, we may hit this branch, in which case we treat it as if |
232 |
| - // no arguments have been passed. An error should already have been emitted. |
| 200 | + let generics = match tcx.res_generics_def_id(res) { |
| 201 | + Some(def_id) => tcx.generics_of(def_id), |
| 202 | + None => { |
233 | 203 | tcx.sess.delay_span_bug(
|
234 | 204 | tcx.def_span(def_id),
|
235 | 205 | &format!("unexpected anon const res {:?} in path: {:?}", res, path),
|
|
0 commit comments