@@ -10,14 +10,15 @@ use core::mem;
10
10
use rustc_ast:: util:: parser:: { PREC_PREFIX , PREC_UNAMBIGUOUS } ;
11
11
use rustc_data_structures:: fx:: FxIndexMap ;
12
12
use rustc_errors:: Applicability ;
13
+ use rustc_hir:: def_id:: DefId ;
13
14
use rustc_hir:: intravisit:: { Visitor , walk_ty} ;
14
15
use rustc_hir:: {
15
16
self as hir, BindingMode , Body , BodyId , BorrowKind , Expr , ExprKind , HirId , MatchSource , Mutability , Node , Pat ,
16
17
PatKind , Path , QPath , TyKind , UnOp ,
17
18
} ;
18
19
use rustc_lint:: { LateContext , LateLintPass } ;
19
20
use 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 } ;
21
22
use rustc_session:: impl_lint_pass;
22
23
use rustc_span:: symbol:: sym;
23
24
use rustc_span:: { Span , Symbol } ;
@@ -753,10 +754,10 @@ impl TyCoercionStability {
753
754
fn for_defined_ty < ' tcx > ( cx : & LateContext < ' tcx > , ty : DefinedTy < ' tcx > , for_return : bool ) -> Self {
754
755
match ty {
755
756
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 (
757
758
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) ,
760
761
for_return,
761
762
) ,
762
763
}
@@ -823,12 +824,15 @@ impl TyCoercionStability {
823
824
}
824
825
}
825
826
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 {
827
828
let ty:: Ref ( _, mut ty, _) = * ty. kind ( ) else {
828
829
return Self :: None ;
829
830
} ;
830
831
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
+ }
832
836
loop {
833
837
break match * ty. kind ( ) {
834
838
ty:: Ref ( _, ref_ty, _) => {
@@ -959,7 +963,7 @@ fn report<'tcx>(
959
963
// expr_str (the suggestion) is never shown if is_final_ufcs is true, since it's
960
964
// `expr.kind == ExprKind::Call`. Therefore, this is, afaik, always unnecessary.
961
965
/*
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 {
963
967
Cow::Owned(format!("({expr_str})"))
964
968
} else {
965
969
expr_str
@@ -999,7 +1003,7 @@ fn report<'tcx>(
999
1003
Node :: Expr ( e) => match e. kind {
1000
1004
ExprKind :: Call ( callee, _) if callee. hir_id != data. first_expr . hir_id => ( 0 , false ) ,
1001
1005
ExprKind :: Call ( ..) => ( PREC_UNAMBIGUOUS , matches ! ( expr. kind, ExprKind :: Field ( ..) ) ) ,
1002
- _ => ( e. precedence ( ) . order ( ) , false ) ,
1006
+ _ => ( e. precedence ( ) , false ) ,
1003
1007
} ,
1004
1008
_ => ( 0 , false ) ,
1005
1009
} ;
@@ -1012,7 +1016,7 @@ fn report<'tcx>(
1012
1016
) ;
1013
1017
1014
1018
let sugg = if !snip_is_macro
1015
- && ( calls_field || expr. precedence ( ) . order ( ) < precedence)
1019
+ && ( calls_field || expr. precedence ( ) < precedence)
1016
1020
&& !has_enclosing_paren ( & snip)
1017
1021
&& !is_in_tuple
1018
1022
{
@@ -1027,7 +1031,7 @@ fn report<'tcx>(
1027
1031
State :: ExplicitDeref { mutability } => {
1028
1032
if is_block_like ( expr)
1029
1033
&& 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 ( ) )
1031
1035
{
1032
1036
// Rustc bug: auto deref doesn't work on block expression when targeting sized types.
1033
1037
return ;
@@ -1066,12 +1070,11 @@ fn report<'tcx>(
1066
1070
let mut app = Applicability :: MachineApplicable ;
1067
1071
let ( snip, snip_is_macro) =
1068
1072
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
+ } ;
1075
1078
diag. span_suggestion ( data. first_expr . span , "try" , sugg, app) ;
1076
1079
} ,
1077
1080
) ;
@@ -1154,7 +1157,7 @@ impl<'tcx> Dereferencing<'tcx> {
1154
1157
} ,
1155
1158
Some ( parent) if !parent. span . from_expansion ( ) => {
1156
1159
// Double reference might be needed at this point.
1157
- if parent. precedence ( ) . order ( ) == PREC_UNAMBIGUOUS {
1160
+ if parent. precedence ( ) == PREC_UNAMBIGUOUS {
1158
1161
// Parentheses would be needed here, don't lint.
1159
1162
* outer_pat = None ;
1160
1163
} else {
0 commit comments