use rustc_ast::util::comments::strip_doc_comment_decoration;
use rustc_ast_pretty::pprust::attribute_to_string;
use rustc_hir as hir;
-use rustc_hir::def::{CtorOf, DefKind as HirDefKind, Res};
+use rustc_hir::def::{DefKind as HirDefKind, Res};
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::Node;
}
pub fn get_expr_data(&self, expr: &hir::Expr<'_>) -> Option<Data> {
- let hir_node = self.tcx.hir().expect_expr(expr.hir_id);
- let ty = self.tables.expr_ty_adjusted_opt(&hir_node);
- if ty.is_none() || ty.unwrap().kind == ty::Error {
+ let ty = self.tables.expr_ty_adjusted_opt(expr)?;
+ if matches!(ty.kind, ty::Error(_)) {
return None;
}
match expr.kind {
hir::ExprKind::Field(ref sub_ex, ident) => {
- let hir_node = match self.tcx.hir().find(sub_ex.hir_id) {
- Some(Node::Expr(expr)) => expr,
- _ => {
- debug!(
- "Missing or weird node for sub-expression {} in {:?}",
- sub_ex.hir_id, expr
- );
- return None;
- }
- };
- match self.tables.expr_ty_adjusted(&hir_node).kind {
+ match self.tables.expr_ty_adjusted(&sub_ex).kind {
ty::Adt(def, _) if !def.is_enum() => {
let variant = &def.non_enum_variant();
filter!(self.span_utils, ident.span);
hir::QPath::Resolved(_, path) => path.segments.last().unwrap(),
hir::QPath::TypeRelative(_, segment) => segment,
};
- match self.tables.expr_ty_adjusted(&hir_node).kind {
- ty::Adt(def, _) if !def.is_enum() => {
+ match ty.kind {
+ ty::Adt(def, _) => {
let sub_span = segment.ident.span;
filter!(self.span_utils, sub_span);
let span = self.span_from_span(sub_span);
}))
}
_ => {
- // FIXME ty could legitimately be an enum, but then we will fail
- // later if we try to look up the fields.
- debug!("expected struct or union, found {:?}", ty);
+ debug!("expected adt, found {:?}", ty);
None
}
}
| HirDefKind::TyAlias
| HirDefKind::ForeignTy
| HirDefKind::TraitAlias
- | HirDefKind::AssocOpaqueTy
| HirDefKind::AssocTy
| HirDefKind::Trait
| HirDefKind::OpaqueTy
Res::Def(HirDefKind::ConstParam, def_id) => {
Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(def_id) })
}
- Res::Def(HirDefKind::Ctor(CtorOf::Struct, ..), def_id) => {
- // This is a reference to a tuple struct where the def_id points
+ Res::Def(HirDefKind::Ctor(_, ..), def_id) => {
+ // This is a reference to a tuple struct or an enum variant where the def_id points
// to an invisible constructor function. That is not a very useful
- // def, so adjust to point to the tuple struct itself.
+ // def, so adjust to point to the tuple struct or enum variant itself.
let parent_def_id = self.tcx.parent(def_id).unwrap();
Some(Ref { kind: RefKind::Type, span, ref_id: id_from_def_id(parent_def_id) })
}
- Res::Def(
- HirDefKind::Static
- | HirDefKind::Const
- | HirDefKind::AssocConst
- | HirDefKind::Ctor(..),
- _,
- ) => Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(res.def_id()) }),
+ Res::Def(HirDefKind::Static | HirDefKind::Const | HirDefKind::AssocConst, _) => {
+ Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(res.def_id()) })
+ }
Res::Def(HirDefKind::AssocFn, decl_id) => {
let def_id = if decl_id.is_local() {
let ti = self.tcx.associated_item(decl_id);
}
fn null_id() -> rls_data::Id {
- rls_data::Id { krate: u32::max_value(), index: u32::max_value() }
+ rls_data::Id { krate: u32::MAX, index: u32::MAX }
}
fn lower_attributes(