Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added regression test for generics index out of bounds #132523

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/ui/traits/ice-index-out-of-bounds-issue-117446.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//@ check-fail
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, no need to mark tests as //@ check-fail. It's redundant.

//
// Regression for https://github.com/rust-lang/rust/issues/117446

pub struct Repeated<T>(Vec<T>);

trait Foo<'a> {
fn outer<D>() -> Option<()>;
}

impl<'a, T> Foo<'a> for Repeated<T> {
fn outer() -> Option<()> {
//~^ ERROR associated function `outer` has 0 type parameters but its trait declaration has 1 type parameter [E0049]
//~^^ ERROR mismatched types [E0308]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer //~| for continuing lines.

fn inner<Q>(value: Option<()>) -> Repeated<Q> {
match value {
_ => Self(unimplemented!()),
//~^ ERROR can't reference `Self` constructor from outer item [E0401]
}
}
}
}

fn main() {}
33 changes: 33 additions & 0 deletions tests/ui/traits/ice-index-out-of-bounds-issue-117446.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
error[E0049]: associated function `outer` has 0 type parameters but its trait declaration has 1 type parameter
--> $DIR/ice-index-out-of-bounds-issue-117446.rs:12:13
|
LL | fn outer<D>() -> Option<()>;
| - expected 1 type parameter
...
LL | fn outer() -> Option<()> {
| ^ found 0 type parameters

error[E0308]: mismatched types
--> $DIR/ice-index-out-of-bounds-issue-117446.rs:12:19
|
LL | fn outer() -> Option<()> {
| ----- ^^^^^^^^^^ expected `Option<()>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected enum `Option<()>`
found unit type `()`

error[E0401]: can't reference `Self` constructor from outer item
--> $DIR/ice-index-out-of-bounds-issue-117446.rs:17:22
|
LL | impl<'a, T> Foo<'a> for Repeated<T> {
| ----------------------------------- the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference
...
LL | _ => Self(unimplemented!()),
| ^^^^ help: replace `Self` with the actual type: `Repeated`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0049, E0308, E0401.
For more information about an error, try `rustc --explain E0049`.
Loading