X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_hir_analysis%2Fsrc%2Fastconv%2Fmod.rs;h=9dd9bf05540fbfe6d8c4c716a4fd0bb2def7141c;hb=36d813498c50b9014463f5b7162066113fdb57f1;hp=6baf98449775da892321c3a68134e0038a11709b;hpb=6dd64d38a3621d9702cbffeaf491ce17903d16b5;p=rust.git diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 6baf9844977..9dd9bf05540 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -23,7 +23,6 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{walk_generics, Visitor as _}; -use rustc_hir::lang_items::LangItem; use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin}; use rustc_middle::middle::stability::AllowUnstable; use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef}; @@ -55,7 +54,7 @@ pub trait AstConv<'tcx> { fn tcx<'a>(&'a self) -> TyCtxt<'tcx>; - fn item_def_id(&self) -> Option; + fn item_def_id(&self) -> DefId; /// Returns predicates in scope of the form `X: Foo`, where `X` /// is a type parameter `X` with the given id `def_id` and T @@ -501,6 +500,9 @@ fn inferred_kind( } GenericParamDefKind::Const { has_default } => { let ty = tcx.at(self.span).type_of(param.def_id); + if ty.references_error() { + return tcx.const_error(ty).into(); + } if !infer_args && has_default { tcx.bound_const_param_default(param.def_id) .subst(tcx, substs.unwrap()) @@ -884,9 +886,9 @@ pub(crate) fn add_implicitly_sized<'hir>( } } - let sized_def_id = tcx.lang_items().require(LangItem::Sized); + let sized_def_id = tcx.lang_items().sized_trait(); match (&sized_def_id, unbound) { - (Ok(sized_def_id), Some(tpb)) + (Some(sized_def_id), Some(tpb)) if tpb.path.res == Res::Def(DefKind::Trait, *sized_def_id) => { // There was in fact a `?Sized` bound, return without doing anything @@ -906,7 +908,7 @@ pub(crate) fn add_implicitly_sized<'hir>( // There was no `?Sized` bound; add implicitly sized if `Sized` is available. } } - if sized_def_id.is_err() { + if sized_def_id.is_none() { // No lang item for `Sized`, so we can't add it as a bound. return; } @@ -2080,17 +2082,14 @@ fn qpath_to_ty( debug!("qpath_to_ty: self.item_def_id()={:?}", def_id); - let parent_def_id = def_id - .and_then(|def_id| { - def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) - }) + let parent_def_id = def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) .map(|hir_id| tcx.hir().get_parent_item(hir_id).to_def_id()); debug!("qpath_to_ty: parent_def_id={:?}", parent_def_id); // If the trait in segment is the same as the trait defining the item, // use the `` syntax in the error. - let is_part_of_self_trait_constraints = def_id == Some(trait_def_id); + let is_part_of_self_trait_constraints = def_id == trait_def_id; let is_part_of_fn_in_self_trait = parent_def_id == Some(trait_def_id); let type_name = if is_part_of_self_trait_constraints || is_part_of_fn_in_self_trait { @@ -2661,7 +2660,7 @@ fn ast_ty_to_ty_inner(&self, ast_ty: &hir::Ty<'_>, borrowed: bool, in_path: bool } hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => { let opaque_ty = tcx.hir().item(item_id); - let def_id = item_id.def_id.to_def_id(); + let def_id = item_id.owner_id.to_def_id(); match opaque_ty.kind { hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {