Skip to content

Commit

Permalink
Unrolled build for rust-lang#137631
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#137631 - TaKO8Ki:issue-137508, r=compiler-errors

Avoid collecting associated types for undefined trait

Fixes rust-lang#137508
Fixes rust-lang#137554
  • Loading branch information
rust-timer authored Feb 26, 2025
2 parents ac91805 + b7a5497 commit a9ca133
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {

Some(args.constraints.iter().filter_map(|constraint| {
let ident = constraint.ident;
let trait_def = path.res.def_id();

let Res::Def(DefKind::Trait, trait_def) = path.res else {
return None;
};

let assoc_item = tcx.associated_items(trait_def).find_by_name_and_kind(
tcx,
ident,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Regression test for <https://github.com/rust-lang/rust/issues/137554>.

fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
//~^ ERROR `?Trait` is not permitted in trait object types
//~| ERROR expected trait, found associated function `Iterator::advance_by`
//~| ERROR the value of the associated type `Item` in `Iterator` must be specified
todo!()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0658]: `?Trait` is not permitted in trait object types
--> $DIR/missing-associated_item_or_field_def_ids.rs:3:29
|
LL | fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0404]: expected trait, found associated function `Iterator::advance_by`
--> $DIR/missing-associated_item_or_field_def_ids.rs:3:30
|
LL | fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a trait

error[E0191]: the value of the associated type `Item` in `Iterator` must be specified
--> $DIR/missing-associated_item_or_field_def_ids.rs:3:18
|
LL | fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
| ^^^^^^^^ help: specify the associated type: `Iterator<Item = Type>`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0191, E0404, E0658.
For more information about an error, try `rustc --explain E0191`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Fix for <https://github.com/rust-lang/rust/issues/137508>.

trait Tr {
type Item;
}

fn main() {
let _: dyn Tr + ?Foo<Assoc = ()>;
//~^ ERROR: `?Trait` is not permitted in trait object types
//~| ERROR: cannot find trait `Foo` in this scope
//~| ERROR: the value of the associated type `Item` in `Tr` must be specified
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error[E0658]: `?Trait` is not permitted in trait object types
--> $DIR/avoid-getting-associated-items-of-undefined-trait.rs:8:21
|
LL | let _: dyn Tr + ?Foo<Assoc = ()>;
| ^^^^^^^^^^^^^^^^
|
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0405]: cannot find trait `Foo` in this scope
--> $DIR/avoid-getting-associated-items-of-undefined-trait.rs:8:22
|
LL | let _: dyn Tr + ?Foo<Assoc = ()>;
| ^^^ not found in this scope

error[E0191]: the value of the associated type `Item` in `Tr` must be specified
--> $DIR/avoid-getting-associated-items-of-undefined-trait.rs:8:16
|
LL | type Item;
| --------- `Item` defined here
...
LL | let _: dyn Tr + ?Foo<Assoc = ()>;
| ^^ help: specify the associated type: `Tr<Item = Type>`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0191, E0405, E0658.
For more information about an error, try `rustc --explain E0191`.

0 comments on commit a9ca133

Please sign in to comment.