3
3
use rustc_errors:: ErrorGuaranteed ;
4
4
use rustc_hir as hir;
5
5
use rustc_hir:: def:: { Namespace , Res } ;
6
- use rustc_hir:: def_id:: DefId ;
6
+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
7
7
use rustc_hir:: intravisit:: Visitor ;
8
8
use rustc_middle:: hir:: nested_filter;
9
9
use rustc_middle:: traits:: ObligationCauseCode ;
10
10
use rustc_middle:: ty:: error:: ExpectedFound ;
11
11
use rustc_middle:: ty:: print:: RegionHighlightMode ;
12
12
use rustc_middle:: ty:: { self , TyCtxt , TypeVisitable } ;
13
- use rustc_span:: Span ;
13
+ use rustc_span:: { Span , sym } ;
14
14
use tracing:: debug;
15
15
16
16
use crate :: error_reporting:: infer:: nice_region_error:: NiceRegionError ;
@@ -33,14 +33,21 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
33
33
_,
34
34
) = error. clone ( )
35
35
&& let ( Subtype ( sup_trace) , Subtype ( sub_trace) ) = ( & sup_origin, & sub_origin)
36
- && let & ObligationCauseCode :: CompareImplItem { trait_item_def_id, .. } =
37
- sub_trace. cause . code ( )
36
+ && let & ObligationCauseCode :: CompareImplItem {
37
+ trait_item_def_id, impl_item_def_id, ..
38
+ } = sub_trace. cause . code ( )
38
39
&& sub_trace. values == sup_trace. values
39
40
&& let ValuePairs :: PolySigs ( ExpectedFound { expected, found } ) = sub_trace. values
40
41
{
41
42
// FIXME(compiler-errors): Don't like that this needs `Ty`s, but
42
43
// all of the region highlighting machinery only deals with those.
43
- let guar = self . emit_err ( var_origin. span ( ) , expected, found, trait_item_def_id) ;
44
+ let guar = self . emit_err (
45
+ var_origin. span ( ) ,
46
+ expected,
47
+ found,
48
+ trait_item_def_id,
49
+ impl_item_def_id,
50
+ ) ;
44
51
return Some ( guar) ;
45
52
}
46
53
None
@@ -52,6 +59,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
52
59
expected : ty:: PolyFnSig < ' tcx > ,
53
60
found : ty:: PolyFnSig < ' tcx > ,
54
61
trait_item_def_id : DefId ,
62
+ impl_item_def_id : LocalDefId ,
55
63
) -> ErrorGuaranteed {
56
64
let trait_sp = self . tcx ( ) . def_span ( trait_item_def_id) ;
57
65
@@ -82,18 +90,31 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
82
90
83
91
let expected_highlight = HighlightBuilder :: build ( expected) ;
84
92
let tcx = self . cx . tcx ;
85
- let expected = Highlighted {
93
+ let mut expected = Highlighted {
86
94
highlight : expected_highlight,
87
95
ns : Namespace :: TypeNS ,
88
96
tcx,
89
97
value : expected,
90
98
}
91
99
. to_string ( ) ;
100
+ // Cannot look at parsed codegen attributes, as those don't get emitted while we don't
101
+ // allow target_features on trait methods.
102
+ if let Some ( trait_item_def_id) = trait_item_def_id. as_local ( ) {
103
+ if tcx. has_attr ( trait_item_def_id, sym:: target_feature) {
104
+ expected = format ! ( "#[target_features] {expected}" ) ;
105
+ }
106
+ }
92
107
let found_highlight = HighlightBuilder :: build ( found) ;
93
- let found =
108
+ let mut found =
94
109
Highlighted { highlight : found_highlight, ns : Namespace :: TypeNS , tcx, value : found }
95
110
. to_string ( ) ;
96
111
112
+ // Cannot look at parsed codegen attributes, as those don't get emitted while we don't
113
+ // allow target_features on trait impl methods.
114
+ if tcx. has_attr ( impl_item_def_id, sym:: target_feature) {
115
+ found = format ! ( "#[target_features] {found}" ) ;
116
+ }
117
+
97
118
// Get the span of all the used type parameters in the method.
98
119
let assoc_item = self . tcx ( ) . associated_item ( trait_item_def_id) ;
99
120
let mut visitor = TypeParamSpanVisitor { tcx : self . tcx ( ) , types : vec ! [ ] } ;
0 commit comments