@@ -10,14 +10,15 @@ use core::mem;
1010use rustc_ast:: util:: parser:: { PREC_PREFIX , PREC_UNAMBIGUOUS } ;
1111use rustc_data_structures:: fx:: FxIndexMap ;
1212use rustc_errors:: Applicability ;
13+ use rustc_hir:: def_id:: DefId ;
1314use rustc_hir:: intravisit:: { Visitor , walk_ty} ;
1415use rustc_hir:: {
1516 self as hir, BindingMode , Body , BodyId , BorrowKind , Expr , ExprKind , HirId , MatchSource , Mutability , Node , Pat ,
1617 PatKind , Path , QPath , TyKind , UnOp ,
1718} ;
1819use rustc_lint:: { LateContext , LateLintPass } ;
1920use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , AutoBorrow , AutoBorrowMutability } ;
20- use rustc_middle:: ty:: { self , ParamEnv , Ty , TyCtxt , TypeVisitableExt , TypeckResults } ;
21+ use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitableExt , TypeckResults } ;
2122use rustc_session:: impl_lint_pass;
2223use rustc_span:: symbol:: sym;
2324use rustc_span:: { Span , Symbol } ;
@@ -753,10 +754,10 @@ impl TyCoercionStability {
753754 fn for_defined_ty < ' tcx > ( cx : & LateContext < ' tcx > , ty : DefinedTy < ' tcx > , for_return : bool ) -> Self {
754755 match ty {
755756 DefinedTy :: Hir ( ty) => Self :: for_hir_ty ( ty) ,
756- DefinedTy :: Mir ( ty ) => Self :: for_mir_ty (
757+ DefinedTy :: Mir { def_site_def_id , ty } => Self :: for_mir_ty (
757758 cx. tcx ,
758- ty . param_env ,
759- cx. tcx . instantiate_bound_regions_with_erased ( ty. value ) ,
759+ def_site_def_id ,
760+ cx. tcx . instantiate_bound_regions_with_erased ( ty) ,
760761 for_return,
761762 ) ,
762763 }
@@ -823,12 +824,15 @@ impl TyCoercionStability {
823824 }
824825 }
825826
826- fn for_mir_ty < ' tcx > ( tcx : TyCtxt < ' tcx > , param_env : ParamEnv < ' tcx > , ty : Ty < ' tcx > , for_return : bool ) -> Self {
827+ fn for_mir_ty < ' tcx > ( tcx : TyCtxt < ' tcx > , def_site_def_id : Option < DefId > , ty : Ty < ' tcx > , for_return : bool ) -> Self {
827828 let ty:: Ref ( _, mut ty, _) = * ty. kind ( ) else {
828829 return Self :: None ;
829830 } ;
830831
831- ty = tcx. try_normalize_erasing_regions ( param_env, ty) . unwrap_or ( ty) ;
832+ if let Some ( def_id) = def_site_def_id {
833+ let typing_env = ty:: TypingEnv :: non_body_analysis ( tcx, def_id) ;
834+ ty = tcx. try_normalize_erasing_regions ( typing_env, ty) . unwrap_or ( ty) ;
835+ }
832836 loop {
833837 break match * ty. kind ( ) {
834838 ty:: Ref ( _, ref_ty, _) => {
@@ -959,7 +963,7 @@ fn report<'tcx>(
959963 // expr_str (the suggestion) is never shown if is_final_ufcs is true, since it's
960964 // `expr.kind == ExprKind::Call`. Therefore, this is, afaik, always unnecessary.
961965 /*
962- expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence().order() < PREC_PREFIX {
966+ expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence() < PREC_PREFIX {
963967 Cow::Owned(format!("({expr_str})"))
964968 } else {
965969 expr_str
@@ -999,7 +1003,7 @@ fn report<'tcx>(
9991003 Node :: Expr ( e) => match e. kind {
10001004 ExprKind :: Call ( callee, _) if callee. hir_id != data. first_expr . hir_id => ( 0 , false ) ,
10011005 ExprKind :: Call ( ..) => ( PREC_UNAMBIGUOUS , matches ! ( expr. kind, ExprKind :: Field ( ..) ) ) ,
1002- _ => ( e. precedence ( ) . order ( ) , false ) ,
1006+ _ => ( e. precedence ( ) , false ) ,
10031007 } ,
10041008 _ => ( 0 , false ) ,
10051009 } ;
@@ -1012,7 +1016,7 @@ fn report<'tcx>(
10121016 ) ;
10131017
10141018 let sugg = if !snip_is_macro
1015- && ( calls_field || expr. precedence ( ) . order ( ) < precedence)
1019+ && ( calls_field || expr. precedence ( ) < precedence)
10161020 && !has_enclosing_paren ( & snip)
10171021 && !is_in_tuple
10181022 {
@@ -1027,7 +1031,7 @@ fn report<'tcx>(
10271031 State :: ExplicitDeref { mutability } => {
10281032 if is_block_like ( expr)
10291033 && let ty:: Ref ( _, ty, _) = data. adjusted_ty . kind ( )
1030- && ty. is_sized ( cx. tcx , cx. param_env )
1034+ && ty. is_sized ( cx. tcx , cx. typing_env ( ) )
10311035 {
10321036 // Rustc bug: auto deref doesn't work on block expression when targeting sized types.
10331037 return ;
@@ -1066,12 +1070,11 @@ fn report<'tcx>(
10661070 let mut app = Applicability :: MachineApplicable ;
10671071 let ( snip, snip_is_macro) =
10681072 snippet_with_context ( cx, expr. span , data. first_expr . span . ctxt ( ) , ".." , & mut app) ;
1069- let sugg =
1070- if !snip_is_macro && expr. precedence ( ) . order ( ) < precedence && !has_enclosing_paren ( & snip) {
1071- format ! ( "{prefix}({snip})" )
1072- } else {
1073- format ! ( "{prefix}{snip}" )
1074- } ;
1073+ let sugg = if !snip_is_macro && expr. precedence ( ) < precedence && !has_enclosing_paren ( & snip) {
1074+ format ! ( "{prefix}({snip})" )
1075+ } else {
1076+ format ! ( "{prefix}{snip}" )
1077+ } ;
10751078 diag. span_suggestion ( data. first_expr . span , "try" , sugg, app) ;
10761079 } ,
10771080 ) ;
@@ -1154,7 +1157,7 @@ impl<'tcx> Dereferencing<'tcx> {
11541157 } ,
11551158 Some ( parent) if !parent. span . from_expansion ( ) => {
11561159 // Double reference might be needed at this point.
1157- if parent. precedence ( ) . order ( ) == PREC_UNAMBIGUOUS {
1160+ if parent. precedence ( ) == PREC_UNAMBIGUOUS {
11581161 // Parentheses would be needed here, don't lint.
11591162 * outer_pat = None ;
11601163 } else {
0 commit comments