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

Make sure to ignore elided lifetimes when pointing at args for fulfillment errors #132935

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

compiler-errors
Copy link
Member

See the comment I left in the code.


If we have something like:

fn foo<'a, T: 'a + BoundThatIsNotSatisfied>() {}

And the user turbofishes just the type args:

foo::<()>();

Then if we try pointing at () (i.e. the type argument for T), we don't actually consider the possibility that the lifetimes may have been left out of the turbofish. We try indexing incorrectly into the HIR args, and bail on the suggestion.

@rustbot
Copy link
Collaborator

rustbot commented Nov 12, 2024

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 12, 2024
@@ -17,6 +17,22 @@ LL | <(i32,) as X<i32>>::f("abc");
|
= help: the trait `X<'_, T>` is implemented for `(S,)`

error[E0277]: the trait bound `for<'b> i32: X<'b, i32>` is not satisfied
Copy link
Member Author

@compiler-errors compiler-errors Nov 12, 2024

Choose a reason for hiding this comment

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

We have a duplicated error here b/c we can only refine one of two copies of this fulfillment error: one that comes from well-formedness, and one that comes from the predicates_of query.

I think it's fine to ignore this regression, since it's a net improvement for other errors.

@@ -15,10 +15,10 @@ LL | for<'b> <T as X<'b, T>>::U: Clone,
| ^^^^^ required by this bound in `X`

error[E0277]: the trait bound `str: Clone` is not satisfied
--> $DIR/hr-associated-type-bound-param-3.rs:18:5
--> $DIR/hr-associated-type-bound-param-3.rs:18:18
|
LL | <(i32,) as X<(i32,)>>::f("abc");
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a great example of the bug. We have X<'a, T> above, but have only specified the type parameter. Since we were basically trying to index at 1 into a list of 1, we would fail. Now we properly adjust the index to account for the lifetime not being there :D

|
LL | <(i32,) as X<i32>>::f("abc");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str`
| ^^^ the trait `Clone` is not implemented for `str`
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like a worse error? The carets point to i32 but the text talks about str, feels very confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a preexisting consequence of the algorithm. I'm just fixing an off-by-N bug.

|
LL | <i32 as X<Box<i32>>>::f("abc");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str`
| ^^^^^^^^ the trait `Clone` is not implemented for `str`
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

|
LL | impl_hr::<T>();
| ^^^^^^^^^^^^^^ the trait `for<'a> Trait<'a, '_>` is not implemented for `T`
| ^ the trait `for<'a> Trait<'a, '_>` is not implemented for `T`
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is better, the carets point to T which matches the error text.

@nnethercote
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 12, 2024

📌 Commit d128c80 has been approved by nnethercote

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 12, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 12, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#132651 (Remove attributes from generics in built-in derive macros)
 - rust-lang#132668 (Feature gate yield expressions not in 2024)
 - rust-lang#132771 (test(configure): cover `parse_args` in `src/bootstrap/configure.py`)
 - rust-lang#132895 (Generalize `NonNull::from_raw_parts` per ACP362)
 - rust-lang#132914 (Update grammar in std::cell docs.)
 - rust-lang#132927 (Consolidate type system const evaluation under `traits::evaluate_const`)
 - rust-lang#132935 (Make sure to ignore elided lifetimes when pointing at args for fulfillment errors)
 - rust-lang#132941 (Subtree update of `rust-analyzer`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9a4a954 into rust-lang:master Nov 12, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 12, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 12, 2024
Rollup merge of rust-lang#132935 - compiler-errors:arg-math, r=nnethercote

Make sure to ignore elided lifetimes when pointing at args for fulfillment errors

See the comment I left in the code.

---

If we have something like:

```
fn foo<'a, T: 'a + BoundThatIsNotSatisfied>() {}
```

And the user turbofishes just the type args:

```
foo::<()>();
```

Then if we try pointing at `()` (i.e. the type argument for `T`), we don't actually consider the possibility that the lifetimes may have been left out of the turbofish. We try indexing incorrectly into the HIR args, and bail on the suggestion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants