Make hir::PathSegment::res
non-optional.
This commit is contained in:
parent
ee244bf196
commit
6d850d936b
20 changed files with 65 additions and 76 deletions
|
@ -1114,7 +1114,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let item_segment = hir::PathSegment {
|
||||
ident,
|
||||
hir_id: Some(binding.hir_id),
|
||||
res: None,
|
||||
res: Res::Err,
|
||||
args: Some(binding.gen_args),
|
||||
infer_args: false,
|
||||
};
|
||||
|
@ -1845,7 +1845,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
[.., hir::PathSegment {
|
||||
ident,
|
||||
args,
|
||||
res: Some(Res::Def(DefKind::Enum, _)),
|
||||
res: Res::Def(DefKind::Enum, _),
|
||||
..
|
||||
}, _] => (
|
||||
// We need to include the `::` in `Type::Variant::<Args>`
|
||||
|
@ -2127,24 +2127,22 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let types_and_spans: Vec<_> = segments
|
||||
.clone()
|
||||
.flat_map(|segment| {
|
||||
segment.res.and_then(|res| {
|
||||
if segment.args().args.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some((
|
||||
match res {
|
||||
Res::PrimTy(ty) => format!("{} `{}`", res.descr(), ty.name()),
|
||||
if segment.args().args.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some((
|
||||
match segment.res {
|
||||
Res::PrimTy(ty) => format!("{} `{}`", segment.res.descr(), ty.name()),
|
||||
Res::Def(_, def_id)
|
||||
if let Some(name) = self.tcx().opt_item_name(def_id) => {
|
||||
format!("{} `{name}`", res.descr())
|
||||
format!("{} `{name}`", segment.res.descr())
|
||||
}
|
||||
Res::Err => "this type".to_string(),
|
||||
_ => res.descr().to_string(),
|
||||
_ => segment.res.descr().to_string(),
|
||||
},
|
||||
segment.ident.span,
|
||||
))
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let this_type = match &types_and_spans[..] {
|
||||
|
|
|
@ -610,12 +610,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes<'tcx>(
|
|||
fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
|
||||
match arg.kind {
|
||||
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => match &path.segments {
|
||||
[
|
||||
PathSegment {
|
||||
res: Some(Res::SelfTy { trait_: _, alias_to: impl_ref }),
|
||||
..
|
||||
},
|
||||
] => {
|
||||
[PathSegment { res: Res::SelfTy { trait_: _, alias_to: impl_ref }, .. }] => {
|
||||
let impl_ty_name =
|
||||
impl_ref.map(|(def_id, _)| self.tcx.def_path_str(def_id));
|
||||
self.selftys.push((path.span, impl_ty_name));
|
||||
|
|
|
@ -768,7 +768,7 @@ impl<'tcx> TypeVisitor<'tcx> for GATSubstCollector<'tcx> {
|
|||
fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
|
||||
match ty.kind {
|
||||
hir::TyKind::TraitObject([trait_ref], ..) => match trait_ref.trait_ref.path.segments {
|
||||
[s] => s.res.and_then(|r| r.opt_def_id()) == Some(trait_def_id.to_def_id()),
|
||||
[s] => s.res.opt_def_id() == Some(trait_def_id.to_def_id()),
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use rustc_errors::{Applicability, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::intravisit;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
|
@ -179,15 +178,12 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
|||
return None;
|
||||
};
|
||||
|
||||
// Try to use the segment resolution if it is valid, otherwise we
|
||||
// default to the path resolution.
|
||||
let res = segment.res.filter(|&r| r != Res::Err).unwrap_or(path.res);
|
||||
let generics = match tcx.res_generics_def_id(res) {
|
||||
let generics = match tcx.res_generics_def_id(segment.res) {
|
||||
Some(def_id) => tcx.generics_of(def_id),
|
||||
None => {
|
||||
tcx.sess.delay_span_bug(
|
||||
tcx.def_span(def_id),
|
||||
&format!("unexpected anon const res {:?} in path: {:?}", res, path),
|
||||
&format!("unexpected anon const res {:?} in path: {:?}", segment.res, path),
|
||||
);
|
||||
return None;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue