File tree Expand file tree Collapse file tree 5 files changed +52
-0
lines changed
compiler/rustc_hir_analysis
tests/ui/associated-types Expand file tree Collapse file tree 5 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -620,6 +620,8 @@ hir_analysis_variances_of = {$variances}
620620hir_analysis_where_clause_on_main = `main` function is not allowed to have a `where` clause
621621 .label = `main` cannot have a `where` clause
622622
623+ hir_analysis_within_macro = due to this macro variable
624+
623625hir_analysis_wrong_number_of_generic_arguments_to_intrinsic =
624626 intrinsic has wrong number of { $descr } parameters: found { $found } , expected { $expected }
625627 .label = expected { $expected } { $descr } { $expected ->
Original file line number Diff line number Diff line change @@ -84,6 +84,8 @@ pub(crate) struct AssocItemNotFound<'a> {
8484 pub label : Option < AssocItemNotFoundLabel < ' a > > ,
8585 #[ subdiagnostic]
8686 pub sugg : Option < AssocItemNotFoundSugg < ' a > > ,
87+ #[ label( hir_analysis_within_macro) ]
88+ pub within_macro_span : Option < Span > ,
8789}
8890
8991#[ derive( Subdiagnostic ) ]
Original file line number Diff line number Diff line change @@ -151,6 +151,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
151151 qself : & qself_str,
152152 label : None ,
153153 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) ,
154157 } ;
155158
156159 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+ | --- due to this macro variable
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+ | --- due to this macro variable
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