File tree 5 files changed +52
-0
lines changed
compiler/rustc_hir_analysis
tests/ui/associated-types
5 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -618,6 +618,8 @@ hir_analysis_variances_of = {$variances}
618
618
hir_analysis_where_clause_on_main = `main` function is not allowed to have a `where` clause
619
619
.label = `main` cannot have a `where` clause
620
620
621
+ hir_analysis_within_macro = within this macro
622
+
621
623
hir_analysis_wrong_number_of_generic_arguments_to_intrinsic =
622
624
intrinsic has wrong number of { $descr } parameters: found { $found } , expected { $expected }
623
625
.label = expected { $expected } { $descr } { $expected ->
Original file line number Diff line number Diff line change @@ -84,6 +84,8 @@ pub(crate) struct AssocItemNotFound<'a> {
84
84
pub label : Option < AssocItemNotFoundLabel < ' a > > ,
85
85
#[ subdiagnostic]
86
86
pub sugg : Option < AssocItemNotFoundSugg < ' a > > ,
87
+ #[ label( hir_analysis_within_macro) ]
88
+ pub within_macro_span : Option < Span > ,
87
89
}
88
90
89
91
#[ derive( Subdiagnostic ) ]
Original file line number Diff line number Diff line change @@ -151,6 +151,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
151
151
qself : & qself_str,
152
152
label : None ,
153
153
sugg : None ,
154
+ // Try to get the span of the identifier within the path's syntax context
155
+ // (if that's different).
156
+ within_macro_span : assoc_name. span . within_macro ( span) ,
154
157
} ;
155
158
156
159
if is_dummy {
Original file line number Diff line number Diff line change
1
+ trait Trait { }
2
+ impl Trait for ( ) { }
3
+
4
+ macro_rules! fully_qualified {
5
+ ( $id: ident) => {
6
+ <( ) as Trait >:: $id
7
+ }
8
+ }
9
+
10
+ macro_rules! type_dependent {
11
+ ( $t: ident, $id: ident) => {
12
+ T :: $id
13
+ }
14
+ }
15
+
16
+ fn t < T : Trait > ( ) {
17
+ let x: fully_qualified ! ( Assoc ) ;
18
+ //~^ ERROR cannot find associated type `Assoc` in trait `Trait`
19
+ let x: type_dependent ! ( T , Assoc ) ;
20
+ //~^ ERROR associated type `Assoc` not found for `T`
21
+ }
22
+
23
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0576]: cannot find associated type `Assoc` in trait `Trait`
2
+ --> $DIR/ident-from-macro-expansion.rs:17:29
3
+ |
4
+ LL | <() as Trait>::$id
5
+ | --- within this macro
6
+ ...
7
+ LL | let x: fully_qualified!(Assoc);
8
+ | ^^^^^ not found in `Trait`
9
+
10
+ error[E0220]: associated type `Assoc` not found for `T`
11
+ --> $DIR/ident-from-macro-expansion.rs:19:31
12
+ |
13
+ LL | T::$id
14
+ | --- within this macro
15
+ ...
16
+ LL | let x: type_dependent!(T, Assoc);
17
+ | ^^^^^ associated type `Assoc` not found
18
+
19
+ error: aborting due to 2 previous errors
20
+
21
+ Some errors have detailed explanations: E0220, E0576.
22
+ For more information about an error, try `rustc --explain E0220`.
You can’t perform that action at this time.
0 commit comments