use rustc::hir::map::Map;
use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc::mir::mono::Linkage;
+use rustc::session::parse::feature_err;
use rustc::traits;
use rustc::ty::query::Providers;
use rustc::ty::subst::GenericArgKind;
use syntax::ast;
use syntax::ast::{Ident, MetaItemKind};
use syntax::attr::{list_contains_name, mark_used, InlineAttr, OptimizeAttr};
-use syntax::feature_gate;
-
-use rustc_error_codes::*;
struct OnlySelfBounds(bool);
| hir::ItemKind::Enum(_, generics)
| hir::ItemKind::TraitAlias(generics, _)
| hir::ItemKind::Trait(_, _, generics, ..)
- | hir::ItemKind::Impl(_, _, _, generics, ..)
+ | hir::ItemKind::Impl { generics, .. }
| hir::ItemKind::Struct(_, generics) => (generics, true),
hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. })
| hir::ItemKind::TyAlias(_, generics) => (generics, false),
Node::Item(item) => {
match item.kind {
ItemKind::Fn(.., ref generics, _)
- | ItemKind::Impl(_, _, _, ref generics, ..)
+ | ItemKind::Impl { ref generics, .. }
| ItemKind::TyAlias(_, ref generics)
| ItemKind::OpaqueTy(OpaqueTy { ref generics, impl_trait_fn: None, .. })
| ItemKind::Enum(_, ref generics)
tcx.predicates_of(def_id);
convert_enum_variant_types(tcx, def_id, &enum_definition.variants);
}
- hir::ItemKind::Impl(..) => {
+ hir::ItemKind::Impl { .. } => {
tcx.generics_of(def_id);
tcx.type_of(def_id);
tcx.impl_trait_ref(def_id);
Node::Item(item) => {
match item.kind {
- ItemKind::Fn(.., ref generics, _) | ItemKind::Impl(_, _, _, ref generics, ..) => {
- generics
- }
+ ItemKind::Fn(.., ref generics, _) | ItemKind::Impl { ref generics, .. } => generics,
ItemKind::TyAlias(_, ref generics)
| ItemKind::Enum(_, ref generics)
icx.to_ty(ty)
}
}
- ItemKind::TyAlias(ref ty, _) | ItemKind::Impl(.., ref ty, _) => icx.to_ty(ty),
+ ItemKind::TyAlias(ref self_ty, _) | ItemKind::Impl { ref self_ty, .. } => {
+ icx.to_ty(self_ty)
+ }
ItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id, substs)
_ => None,
};
if let Some(unsupported_type) = err {
- feature_gate::feature_err(
+ feature_err(
&tcx.sess.parse_sess,
sym::const_compare_raw_pointers,
hir_ty.span,
}
}
+fn are_suggestable_generic_args(generic_args: &[hir::GenericArg<'_>]) -> bool {
+ generic_args
+ .iter()
+ .filter_map(|arg| match arg {
+ hir::GenericArg::Type(ty) => Some(ty),
+ _ => None,
+ })
+ .any(is_suggestable_infer_ty)
+}
+
/// Whether `ty` is a type with `_` placeholders that can be infered. Used in diagnostics only to
/// use inference to provide suggestions for the appropriate type if possible.
fn is_suggestable_infer_ty(ty: &hir::Ty<'_>) -> bool {
Slice(ty) | Array(ty, _) => is_suggestable_infer_ty(ty),
Tup(tys) => tys.iter().any(is_suggestable_infer_ty),
Ptr(mut_ty) | Rptr(_, mut_ty) => is_suggestable_infer_ty(mut_ty.ty),
- Def(_, generic_args) => generic_args
- .iter()
- .filter_map(|arg| match arg {
- hir::GenericArg::Type(ty) => Some(ty),
- _ => None,
- })
- .any(is_suggestable_infer_ty),
+ Def(_, generic_args) => are_suggestable_generic_args(generic_args),
+ Path(hir::QPath::TypeRelative(ty, segment)) => {
+ is_suggestable_infer_ty(ty) || are_suggestable_generic_args(segment.generic_args().args)
+ }
+ Path(hir::QPath::Resolved(ty_opt, hir::Path { segments, .. })) => {
+ ty_opt.map_or(false, is_suggestable_infer_ty)
+ || segments
+ .iter()
+ .any(|segment| are_suggestable_generic_args(segment.generic_args().args))
+ }
_ => false,
}
}
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
match tcx.hir().expect_item(hir_id).kind {
- hir::ItemKind::Impl(.., ref opt_trait_ref, _, _) => {
- opt_trait_ref.as_ref().map(|ast_trait_ref| {
- let selfty = tcx.type_of(def_id);
- AstConv::instantiate_mono_trait_ref(&icx, ast_trait_ref, selfty)
- })
- }
+ hir::ItemKind::Impl { ref of_trait, .. } => of_trait.as_ref().map(|ast_trait_ref| {
+ let selfty = tcx.type_of(def_id);
+ AstConv::instantiate_mono_trait_ref(&icx, ast_trait_ref, selfty)
+ }),
_ => bug!(),
}
}
let is_rustc_reservation = tcx.has_attr(def_id, sym::rustc_reservation_impl);
let item = tcx.hir().expect_item(hir_id);
match &item.kind {
- hir::ItemKind::Impl(_, hir::ImplPolarity::Negative, ..) => {
+ hir::ItemKind::Impl { polarity: hir::ImplPolarity::Negative, .. } => {
if is_rustc_reservation {
tcx.sess.span_err(item.span, "reservation impls can't be negative");
}
ty::ImplPolarity::Negative
}
- hir::ItemKind::Impl(_, hir::ImplPolarity::Positive, _, _, None, _, _) => {
+ hir::ItemKind::Impl { polarity: hir::ImplPolarity::Positive, of_trait: None, .. } => {
if is_rustc_reservation {
tcx.sess.span_err(item.span, "reservation impls can't be inherent");
}
ty::ImplPolarity::Positive
}
- hir::ItemKind::Impl(_, hir::ImplPolarity::Positive, _, _, Some(_tr), _, _) => {
+ hir::ItemKind::Impl {
+ polarity: hir::ImplPolarity::Positive, of_trait: Some(_), ..
+ } => {
if is_rustc_reservation {
ty::ImplPolarity::Reservation
} else {
Node::Item(item) => {
match item.kind {
- ItemKind::Impl(_, _, defaultness, ref generics, ..) => {
+ ItemKind::Impl { defaultness, ref generics, .. } => {
if defaultness.is_default() {
is_default_impl_trait = tcx.impl_trait_ref(def_id);
}
// before uses of `U`. This avoids false ambiguity errors
// in trait checking. See `setup_constraining_predicates`
// for details.
- if let Node::Item(&Item { kind: ItemKind::Impl(..), .. }) = node {
+ if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node {
let self_ty = tcx.type_of(def_id);
let trait_ref = tcx.impl_trait_ref(def_id);
cgp::setup_constraining_predicates(
None => true,
};
if !allowed && id.is_local() {
- feature_gate::feature_err(
+ feature_err(
&tcx.sess.parse_sess,
feature_gate.unwrap(),
item.span(),