]> git.lizzy.rs Git - rust.git/commitdiff
hir: Preserve used syntax in `TyKind::TraitObject`
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 13 Mar 2021 12:44:29 +0000 (15:44 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Thu, 18 Mar 2021 00:02:32 +0000 (03:02 +0300)
15 files changed:
compiler/rustc_ast/src/ast.rs
compiler/rustc_ast_lowering/src/lib.rs
compiler/rustc_hir/src/hir.rs
compiler/rustc_hir/src/intravisit.rs
compiler/rustc_hir_pretty/src/lib.rs
compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs
compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs
compiler/rustc_middle/src/ty/diagnostics.rs
compiler/rustc_resolve/src/late/lifetimes.rs
compiler/rustc_typeck/src/astconv/mod.rs
src/librustdoc/clean/mod.rs
src/tools/clippy/clippy_lints/src/lifetimes.rs
src/tools/clippy/clippy_lints/src/types/borrowed_box.rs
src/tools/clippy/clippy_lints/src/types/mod.rs
src/tools/clippy/clippy_utils/src/hir_utils.rs

index ee7367d408d5f4b5b5e3ceef61237abbd29c7215..7e82d7ff77d9617c115b610ecbe9807001444d89 100644 (file)
@@ -1964,7 +1964,7 @@ pub fn is_unit(&self) -> bool {
 }
 
 /// 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,
index 44f05cbf4360a6f4e73c4d0bfaa49954019ec639..f9872f84e125e27d693745b9e03d5f80bc564ecb 100644 (file)
@@ -1396,7 +1396,7 @@ fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_, 'hir>) ->
                 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;
@@ -2648,6 +2648,7 @@ fn ty_path(
                         hir::TyKind::TraitObject(
                             arena_vec![self; principal],
                             self.elided_dyn_bound(span),
+                            TraitObjectSyntax::None,
                         )
                     }
                     _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
index 2b84d4658f90f37ef01bb455d7bcaf19fb208b05..d03584d49a5bcc595a2e3a94839a142cc6cb0a55 100644 (file)
@@ -6,7 +6,7 @@
 
 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};
@@ -2327,7 +2327,7 @@ pub enum TyKind<'hir> {
     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
index 1ed8ab044fe53749faa8da980ec611f10b6500d9..701e4a632939473180b28cab0009da66dcf8d049 100644 (file)
@@ -709,7 +709,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
             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);
             }
index 9eab6cab64d411947e961dd9d55b4eb01bc0def6..b37a3e19b84081093e2d0d8b3c0050a95c4e07f1 100644 (file)
@@ -410,7 +410,10 @@ pub fn print_type(&mut self, ty: &hir::Ty<'_>) {
             }
             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 {
index d9ab83190455130b4a6bbee4fb9dfe329fb60af6..35b9bc96f133999bc3496dba3029f2f0004387d2 100644 (file)
@@ -99,7 +99,7 @@ fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
                 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);
index fa0d5b8301349a6fa752519454b3778dc356f754..1e926989263c9cb66ea81f0eb7a356a6f6cbd3c4 100644 (file)
@@ -292,7 +292,7 @@ pub(super) fn try_report_static_impl_trait(&self) -> Option<ErrorReported> {
                         );
                     }
                 }
-                TyKind::TraitObject(_, lt) => match lt.name {
+                TyKind::TraitObject(_, lt, _) => match lt.name {
                     LifetimeName::ImplicitObjectLifetimeDefault => {
                         err.span_suggestion_verbose(
                             fn_return.span.shrink_to_hi(),
@@ -498,6 +498,7 @@ fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
         if let TyKind::TraitObject(
             poly_trait_refs,
             Lifetime { name: LifetimeName::ImplicitObjectLifetimeDefault, .. },
+            _,
         ) = t.kind
         {
             for ptr in poly_trait_refs {
index f41bb7e6d6350945d172f565e6851340cb90c457..982c8a354b4ab20a91933e8613398ab32dd543c7 100644 (file)
@@ -314,6 +314,7 @@ fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) {
                         hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Static,
                     ..
                 },
+                _,
             ) => {
                 self.0.push(ty);
             }
index 4f92532e3a698e5424ecef765d6e3657113eb257..2c61c0963ae2844b9dc65d9dd17b68e88dc6f03a 100644 (file)
@@ -540,7 +540,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
                 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);
@@ -2299,7 +2299,7 @@ fn visit_ty(&mut self, ty: &hir::Ty<'_>) {
                     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);
                         }
index a973b56f7d62c9ccea11b82928dd791dd324314a..d0a03008c95222ad572dbd8f805f55bc05281a9d 100644 (file)
@@ -2201,7 +2201,7 @@ fn ast_ty_to_ty_inner(&self, ast_ty: &hir::Ty<'_>, borrowed: bool) -> Ty<'tcx> {
                     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)) => {
index ead9d7d66463539d74379ede4056d96b277bffb3..17a961a5f6655efcfee3dee5a6cb84b79eeb4492 100644 (file)
@@ -1477,7 +1477,7 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Type {
                 }
             }
             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..]
index 33ff01a30e8813c7e85a0963f5c094d6c47b9d31..3ac6e6cbbefcf49f1b924cbb8b7278f7ebea0204 100644 (file)
@@ -387,7 +387,7 @@ fn visit_ty(&mut self, ty: &'tcx Ty<'_>) {
                 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;
                 }
index a7a511b21cf59020af650c10296ce43f9eecc7d8..81090040d92e0af42b1f8a9a700305119d6bc3d8 100644 (file)
@@ -50,7 +50,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
                     // 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)
@@ -86,7 +86,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
 // 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.
index f7a6399a7f048499b1fff6bdb166d3ddf3612d78..4a1a608e8ae62ea308ffa0f7dcb43e6f3b2129b0 100644 (file)
@@ -911,7 +911,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
             // 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
index af82f992d56f6475a599177b0a4b034a3685b44a..7f7d9c5f56a1e0463071f9a9784083beb9c46241 100644 (file)
@@ -892,7 +892,7 @@ pub fn hash_tykind(&mut self, ty: &TyKind<'_>) {
             TyKind::OpaqueDef(_, arg_list) => {
                 self.hash_generic_args(arg_list);
             },
-            TyKind::TraitObject(_, lifetime) => {
+            TyKind::TraitObject(_, lifetime, _) => {
                 self.hash_lifetime(lifetime);
             },
             TyKind::Typeof(anon_const) => {