@@ -46,7 +46,7 @@ use hir::HirVec;
46
46
use hir:: map:: { Definitions , DefKey , DefPathData } ;
47
47
use hir:: def_id:: { DefIndex , DefId , CRATE_DEF_INDEX , DefIndexAddressSpace } ;
48
48
use 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 } ;
50
50
use middle:: cstore:: CrateStore ;
51
51
use rustc_data_structures:: indexed_vec:: IndexVec ;
52
52
use session:: Session ;
@@ -912,7 +912,11 @@ impl<'a> LoweringContext<'a> {
912
912
TyKind :: Path ( ref qself, ref path) => {
913
913
let id = self . lower_node_id ( t. id ) ;
914
914
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 ) ;
918
+ }
919
+ return ty;
916
920
}
917
921
TyKind :: ImplicitSelf => {
918
922
hir:: TyPath ( hir:: QPath :: Resolved ( None , P ( hir:: Path {
@@ -931,7 +935,7 @@ impl<'a> LoweringContext<'a> {
931
935
let expr = self . lower_body ( None , |this| this. lower_expr ( expr) ) ;
932
936
hir:: TyTypeof ( expr)
933
937
}
934
- TyKind :: TraitObject ( ref bounds, .. ) => {
938
+ TyKind :: TraitObject ( ref bounds, kind ) => {
935
939
let mut lifetime_bound = None ;
936
940
let bounds = bounds. iter ( ) . filter_map ( |bound| {
937
941
match * bound {
@@ -950,6 +954,9 @@ impl<'a> LoweringContext<'a> {
950
954
let lifetime_bound = lifetime_bound. unwrap_or_else ( || {
951
955
self . elided_lifetime ( t. span )
952
956
} ) ;
957
+ if kind != TraitObjectSyntax :: Dyn {
958
+ self . maybe_lint_bare_trait ( t. span , t. id ) ;
959
+ }
953
960
hir:: TyTraitObject ( bounds, lifetime_bound)
954
961
}
955
962
TyKind :: ImplTrait ( ref bounds) => {
@@ -3685,7 +3692,6 @@ impl<'a> LoweringContext<'a> {
3685
3692
// The original ID is taken by the `PolyTraitRef`,
3686
3693
// so the `Ty` itself needs a different one.
3687
3694
id = self . next_id ( ) ;
3688
-
3689
3695
hir:: TyTraitObject ( hir_vec ! [ principal] , self . elided_lifetime ( span) )
3690
3696
} else {
3691
3697
hir:: TyPath ( hir:: QPath :: Resolved ( None , path) )
@@ -3703,6 +3709,16 @@ impl<'a> LoweringContext<'a> {
3703
3709
name : hir:: LifetimeName :: Implicit ,
3704
3710
}
3705
3711
}
3712
+
3713
+ fn maybe_lint_bare_trait ( & self , span : Span , id : NodeId ) {
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)
3719
+ )
3720
+ }
3721
+ }
3706
3722
}
3707
3723
3708
3724
fn body_ids ( bodies : & BTreeMap < hir:: BodyId , hir:: Body > ) -> Vec < hir:: BodyId > {
0 commit comments