File tree 3 files changed +21
-17
lines changed
compiler/rustc_hir_analysis/src/hir_ty_lowering
tests/ui/associated-types
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> + '_ {
789
789
790
790
Some ( args. constraints . iter ( ) . filter_map ( |constraint| {
791
791
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
+ ) ;
801
803
802
804
Some ( ( ident. name , assoc_item?) )
803
805
} ) )
Original file line number Diff line number Diff line change
1
+ // Fix for https://github.com/rust-lang/rust/issues/137508>.
2
+
1
3
trait Tr {
2
4
type Item ;
3
5
}
4
6
5
7
fn main ( ) {
6
- let _: dyn Tr + ?Foo ( ) ;
8
+ let _: dyn Tr + ?Foo < Assoc = ( ) > ;
7
9
//~^ ERROR: `?Trait` is not permitted in trait object types
8
10
//~| ERROR: cannot find trait `Foo` in this scope
9
11
//~| ERROR: the value of the associated type `Item` in `Tr` must be specifi
Original file line number Diff line number Diff line change 1
1
error[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
3
3
|
4
- LL | let _: dyn Tr + ?Foo() ;
5
- | ^^^^^^
4
+ LL | let _: dyn Tr + ?Foo<Assoc = ()> ;
5
+ | ^^^^^^^^^^^^^^^^
6
6
|
7
7
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
8
8
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
9
9
10
10
error[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
12
12
|
13
- LL | let _: dyn Tr + ?Foo() ;
13
+ LL | let _: dyn Tr + ?Foo<Assoc = ()> ;
14
14
| ^^^ not found in this scope
15
15
16
16
error[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
18
18
|
19
19
LL | type Item;
20
20
| --------- `Item` defined here
21
21
...
22
- LL | let _: dyn Tr + ?Foo() ;
22
+ LL | let _: dyn Tr + ?Foo<Assoc = ()> ;
23
23
| ^^ help: specify the associated type: `Tr<Item = Type>`
24
24
25
25
error: aborting due to 3 previous errors
You can’t perform that action at this time.
0 commit comments