File tree Expand file tree Collapse file tree 3 files changed +21
-17
lines changed
compiler/rustc_hir_analysis/src/hir_ty_lowering
tests/ui/associated-types Expand file tree Collapse file tree 3 files changed +21
-17
lines changed Original file line number Diff line number Diff line change @@ -789,15 +789,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
789789
790790 Some ( args. constraints . iter ( ) . filter_map ( |constraint| {
791791 let ident = constraint. ident ;
792- let trait_def = path. res . opt_def_id ( ) ;
793- let assoc_item = trait_def. and_then ( |trait_def_id| {
794- tcx. associated_items ( trait_def_id) . find_by_name_and_kind (
795- tcx,
796- ident,
797- ty:: AssocKind :: Type ,
798- trait_def_id,
799- )
800- } ) ;
792+
793+ let Res :: Def ( DefKind :: Trait , trait_def) = path. res else {
794+ return None ;
795+ } ;
796+
797+ let assoc_item = tcx. associated_items ( trait_def) . find_by_name_and_kind (
798+ tcx,
799+ ident,
800+ ty:: AssocKind :: Type ,
801+ trait_def,
802+ ) ;
801803
802804 Some ( ( ident. name , assoc_item?) )
803805 } ) )
Original file line number Diff line number Diff line change 1+ // Fix for https://github.com/rust-lang/rust/issues/137508>.
2+
13trait Tr {
24 type Item ;
35}
46
57fn main ( ) {
6- let _: dyn Tr + ?Foo ( ) ;
8+ let _: dyn Tr + ?Foo < Assoc = ( ) > ;
79 //~^ ERROR: `?Trait` is not permitted in trait object types
810 //~| ERROR: cannot find trait `Foo` in this scope
911 //~| ERROR: the value of the associated type `Item` in `Tr` must be specifi
Original file line number Diff line number Diff line change 11error[E0658]: `?Trait` is not permitted in trait object types
2- --> $DIR/issue-137508 .rs:6 :21
2+ --> $DIR/avoid-getting-associated-items-of-undefined-trait .rs:8 :21
33 |
4- LL | let _: dyn Tr + ?Foo() ;
5- | ^^^^^^
4+ LL | let _: dyn Tr + ?Foo<Assoc = ()> ;
5+ | ^^^^^^^^^^^^^^^^
66 |
77 = help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
88 = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
99
1010error[E0405]: cannot find trait `Foo` in this scope
11- --> $DIR/issue-137508 .rs:6 :22
11+ --> $DIR/avoid-getting-associated-items-of-undefined-trait .rs:8 :22
1212 |
13- LL | let _: dyn Tr + ?Foo() ;
13+ LL | let _: dyn Tr + ?Foo<Assoc = ()> ;
1414 | ^^^ not found in this scope
1515
1616error[E0191]: the value of the associated type `Item` in `Tr` must be specified
17- --> $DIR/issue-137508 .rs:6 :16
17+ --> $DIR/avoid-getting-associated-items-of-undefined-trait .rs:8 :16
1818 |
1919LL | type Item;
2020 | --------- `Item` defined here
2121...
22- LL | let _: dyn Tr + ?Foo() ;
22+ LL | let _: dyn Tr + ?Foo<Assoc = ()> ;
2323 | ^^ help: specify the associated type: `Tr<Item = Type>`
2424
2525error: aborting due to 3 previous errors
You can’t perform that action at this time.
0 commit comments