}
/// Syntax used to declare a trait object.
-#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]
+#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
pub enum TraitObjectSyntax {
Dyn,
None,
if kind != TraitObjectSyntax::Dyn {
self.maybe_lint_bare_trait(t.span, t.id, false);
}
- hir::TyKind::TraitObject(bounds, lifetime_bound)
+ hir::TyKind::TraitObject(bounds, lifetime_bound, kind)
}
TyKind::ImplTrait(def_node_id, ref bounds) => {
let span = t.span;
hir::TyKind::TraitObject(
arena_vec![self; principal],
self.elided_dyn_bound(span),
+ TraitObjectSyntax::None,
)
}
_ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
use rustc_ast::util::parser::ExprPrecedence;
use rustc_ast::{self as ast, CrateSugar, LlvmAsmDialect};
-use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
+use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, TraitObjectSyntax, UintTy};
pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
pub use rustc_ast::{CaptureBy, Movability, Mutability};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
OpaqueDef(ItemId, &'hir [GenericArg<'hir>]),
/// A trait object type `Bound1 + Bound2 + Bound3`
/// where `Bound` is a trait or a lifetime.
- TraitObject(&'hir [PolyTraitRef<'hir>], Lifetime),
+ TraitObject(&'hir [PolyTraitRef<'hir>], Lifetime, TraitObjectSyntax),
/// Unused for now.
Typeof(AnonConst),
/// `TyKind::Infer` means the type should be inferred instead of it having been
visitor.visit_ty(ty);
visitor.visit_anon_const(length)
}
- TyKind::TraitObject(bounds, ref lifetime) => {
+ TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
for bound in bounds {
visitor.visit_poly_trait_ref(bound, TraitBoundModifier::None);
}
}
hir::TyKind::OpaqueDef(..) => self.s.word("/*impl Trait*/"),
hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false),
- hir::TyKind::TraitObject(bounds, ref lifetime) => {
+ hir::TyKind::TraitObject(bounds, ref lifetime, syntax) => {
+ if syntax == ast::TraitObjectSyntax::Dyn {
+ self.word_space("dyn");
+ }
let mut first = true;
for bound in bounds {
if first {
return;
}
- hir::TyKind::TraitObject(bounds, _) => {
+ hir::TyKind::TraitObject(bounds, ..) => {
for bound in bounds {
self.current_index.shift_in(1);
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
);
}
}
- TyKind::TraitObject(_, lt) => match lt.name {
+ TyKind::TraitObject(_, lt, _) => match lt.name {
LifetimeName::ImplicitObjectLifetimeDefault => {
err.span_suggestion_verbose(
fn_return.span.shrink_to_hi(),
if let TyKind::TraitObject(
poly_trait_refs,
Lifetime { name: LifetimeName::ImplicitObjectLifetimeDefault, .. },
+ _,
) = t.kind
{
for ptr in poly_trait_refs {
hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Static,
..
},
+ _,
) => {
self.0.push(ty);
}
self.missing_named_lifetime_spots.pop();
self.is_in_fn_syntax = was_in_fn_syntax;
}
- hir::TyKind::TraitObject(bounds, ref lifetime) => {
+ hir::TyKind::TraitObject(bounds, ref lifetime, _) => {
debug!("visit_ty: TraitObject(bounds={:?}, lifetime={:?})", bounds, lifetime);
for bound in bounds {
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
self.outer_index.shift_in(1);
}
match ty.kind {
- hir::TyKind::TraitObject(bounds, ref lifetime) => {
+ hir::TyKind::TraitObject(bounds, ref lifetime, _) => {
for bound in bounds {
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
}
Some(ast_ty),
))
}
- hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
+ hir::TyKind::TraitObject(ref bounds, ref lifetime, _) => {
self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime, borrowed)
}
hir::TyKind::Path(hir::QPath::Resolved(ref maybe_qself, ref path)) => {
}
}
TyKind::Path(_) => clean_qpath(&self, cx),
- TyKind::TraitObject(ref bounds, ref lifetime) => {
+ TyKind::TraitObject(ref bounds, ref lifetime, _) => {
match bounds[0].clean(cx).trait_ {
ResolvedPath { path, param_names: None, did, is_generic } => {
let mut bounds: Vec<self::GenericBound> = bounds[1..]
self.nested_elision_site_lts.append(&mut sub_visitor.all_lts());
return;
},
- TyKind::TraitObject(bounds, ref lt) => {
+ TyKind::TraitObject(bounds, ref lt, _) => {
if !lt.is_elided() {
self.unelided_trait_object_lifetime = true;
}
// Originally reported as the issue #3128.
let inner_snippet = snippet(cx, inner.span, "..");
let suggestion = match &inner.kind {
- TyKind::TraitObject(bounds, lt_bound) if bounds.len() > 1 || !lt_bound.is_elided() => {
+ TyKind::TraitObject(bounds, lt_bound, _) if bounds.len() > 1 || !lt_bound.is_elided() => {
format!("&{}({})", ltopt, &inner_snippet)
},
TyKind::Path(qpath)
// Returns true if given type is `Any` trait.
fn is_any_trait(t: &hir::Ty<'_>) -> bool {
if_chain! {
- if let TyKind::TraitObject(ref traits, _) = t.kind;
+ if let TyKind::TraitObject(ref traits, ..) = t.kind;
if !traits.is_empty();
// Only Send/Sync can be used as additional traits, so it is enough to
// check only the first trait.
// function types bring a lot of overhead
TyKind::BareFn(ref bare) if bare.abi == Abi::Rust => (50 * self.nest, 1),
- TyKind::TraitObject(ref param_bounds, _) => {
+ TyKind::TraitObject(ref param_bounds, ..) => {
let has_lifetime_parameters = param_bounds.iter().any(|bound| {
bound
.bound_generic_params
TyKind::OpaqueDef(_, arg_list) => {
self.hash_generic_args(arg_list);
},
- TyKind::TraitObject(_, lifetime) => {
+ TyKind::TraitObject(_, lifetime, _) => {
self.hash_lifetime(lifetime);
},
TyKind::Typeof(anon_const) => {