-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Conversation
r? @nnethercote rustbot has assigned @nnethercote. Use |
@@ -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 |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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.
@bors r+ rollup |
…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
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.
See the comment I left in the code.
If we have something like:
And the user turbofishes just the type args:
Then if we try pointing at
()
(i.e. the type argument forT
), 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.