@@ -46,7 +46,7 @@ use hir::HirVec;
4646use hir:: map:: { Definitions , DefKey , DefPathData } ;
4747use hir:: def_id:: { DefIndex , DefId , CRATE_DEF_INDEX , DefIndexAddressSpace } ;
4848use hir:: def:: { Def , PathResolution } ;
49- use lint:: builtin:: PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES ;
49+ use lint:: builtin:: { self , PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES } ;
5050use middle:: cstore:: CrateStore ;
5151use rustc_data_structures:: indexed_vec:: IndexVec ;
5252use session:: Session ;
@@ -912,7 +912,11 @@ impl<'a> LoweringContext<'a> {
912912 TyKind :: Path ( ref qself, ref path) => {
913913 let id = self . lower_node_id ( t. id ) ;
914914 let qpath = self . lower_qpath ( t. id , qself, path, ParamMode :: Explicit , itctx) ;
915- return self . ty_path ( id, t. span , qpath) ;
915+ let ty = self . ty_path ( id, t. span , qpath) ;
916+ if let hir:: TyTraitObject ( ..) = ty. node {
917+ self . maybe_lint_bare_trait ( t. span , t. id , qself. is_none ( ) && path. is_global ( ) ) ;
918+ }
919+ return ty;
916920 }
917921 TyKind :: ImplicitSelf => {
918922 hir:: TyPath ( hir:: QPath :: Resolved ( None , P ( hir:: Path {
@@ -931,7 +935,7 @@ impl<'a> LoweringContext<'a> {
931935 let expr = self . lower_body ( None , |this| this. lower_expr ( expr) ) ;
932936 hir:: TyTypeof ( expr)
933937 }
934- TyKind :: TraitObject ( ref bounds, .. ) => {
938+ TyKind :: TraitObject ( ref bounds, kind ) => {
935939 let mut lifetime_bound = None ;
936940 let bounds = bounds. iter ( ) . filter_map ( |bound| {
937941 match * bound {
@@ -950,6 +954,9 @@ impl<'a> LoweringContext<'a> {
950954 let lifetime_bound = lifetime_bound. unwrap_or_else ( || {
951955 self . elided_lifetime ( t. span )
952956 } ) ;
957+ if kind != TraitObjectSyntax :: Dyn {
958+ self . maybe_lint_bare_trait ( t. span , t. id , false ) ;
959+ }
953960 hir:: TyTraitObject ( bounds, lifetime_bound)
954961 }
955962 TyKind :: ImplTrait ( ref bounds) => {
@@ -3685,7 +3692,6 @@ impl<'a> LoweringContext<'a> {
36853692 // The original ID is taken by the `PolyTraitRef`,
36863693 // so the `Ty` itself needs a different one.
36873694 id = self . next_id ( ) ;
3688-
36893695 hir:: TyTraitObject ( hir_vec ! [ principal] , self . elided_lifetime ( span) )
36903696 } else {
36913697 hir:: TyPath ( hir:: QPath :: Resolved ( None , path) )
@@ -3703,6 +3709,16 @@ impl<'a> LoweringContext<'a> {
37033709 name : hir:: LifetimeName :: Implicit ,
37043710 }
37053711 }
3712+
3713+ fn maybe_lint_bare_trait ( & self , span : Span , id : NodeId , is_global : bool ) {
3714+ if self . sess . features . borrow ( ) . dyn_trait {
3715+ self . sess . buffer_lint_with_diagnostic (
3716+ builtin:: BARE_TRAIT_OBJECT , id, span,
3717+ "trait objects without an explicit `dyn` are deprecated" ,
3718+ builtin:: BuiltinLintDiagnostics :: BareTraitObject ( span, is_global)
3719+ )
3720+ }
3721+ }
37063722}
37073723
37083724fn body_ids ( bodies : & BTreeMap < hir:: BodyId , hir:: Body > ) -> Vec < hir:: BodyId > {
0 commit comments