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

Fix invalid syntax and incomplete suggestion in impl Trait parameter type suggestions for E0311 #106167

Merged
merged 1 commit into from
Jan 12, 2023

Conversation

yanchen4791
Copy link
Contributor

@yanchen4791 yanchen4791 commented Dec 27, 2022

Fixes #105544

The problems: The suggestion given for E0311 has invalid syntax when the synthetic type parameter is used for Trait type in function declaration:

fn foo(d: impl Sized) -> impl Sized

instead of explicitly specified like the following:

fn foo<T: Sized>(d: T) -> impl Sized

In addition to the syntax error, the suggestions given for E0311 are not complete when multiple elided lifetimes are involved in lifetime bounds, not all involved parameters are given the named lifetime in the suggestions. For the following test case:

fn foo(d: impl Sized, p: &mut ()) -> impl Sized + '_ {
    (d, p)
}

a good suggestion should add the lifetime 'a to both d and p, instead of d only:

fn foo<'a>(d: impl Sized + 'a, p: &'a mut ()) -> impl Sized + '_ {
    (d, p)
}

The Solution: Fix the syntax problem in the suggestions when synthetic type parameter is used, and also add lifetimes for all involved parameters.

@rustbot
Copy link
Collaborator

rustbot commented Dec 27, 2022

r? @nagisa

(rustbot has picked a reviewer for you, use r? to override)

@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 Dec 27, 2022
@nagisa
Copy link
Member

nagisa commented Jan 9, 2023

r? rust-lang/compiler

@rustbot rustbot assigned lcnr and unassigned nagisa Jan 9, 2023
@lcnr
Copy link
Contributor

lcnr commented Jan 9, 2023

r? compiler

@rustbot rustbot assigned oli-obk and unassigned lcnr Jan 9, 2023
@yanchen4791 yanchen4791 force-pushed the issue-105544-fix branch 2 times, most recently from ff8050b to 1463b22 Compare January 10, 2023 07:55
@oli-obk
Copy link
Contributor

oli-obk commented Jan 11, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 11, 2023

📌 Commit 1f106cc86941acaa28165ad1ddd7b794935bebd6 has been approved by oli-obk

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 Jan 11, 2023
@dtolnay
Copy link
Member

dtolnay commented Jan 11, 2023

Rebased to fix conflict with #106458, since this was showing not mergeable in bors.
https://bors.rust-lang.org/queue/rust
@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Jan 11, 2023

📌 Commit 621d412 has been approved by oli-obk

It is now in the queue for this repository.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jan 12, 2023
…i-obk

Fix invalid syntax and incomplete suggestion in impl Trait parameter type suggestions for E0311

Fixes rust-lang#105544

The problems: The suggestion given for E0311 has invalid syntax when the synthetic type parameter is used for Trait type in function declaration:
```rust
fn foo(d: impl Sized) -> impl Sized
```
instead of explicitly specified like the following:
```rust
fn foo<T: Sized>(d: T) -> impl Sized
```
In addition to the syntax error, the suggestions given for E0311 are not complete when multiple elided lifetimes are involved in lifetime bounds, not all involved parameters are given the named lifetime in the suggestions. For the following test case:
```
fn foo(d: impl Sized, p: &mut ()) -> impl Sized + '_ {
    (d, p)
}
```
a good suggestion should add the lifetime 'a to both d and p, instead of d only:
```
fn foo<'a>(d: impl Sized + 'a, p: &'a mut ()) -> impl Sized + '_ {
    (d, p)
}
```

The Solution: Fix the syntax problem in the suggestions when synthetic type parameter is used, and also add lifetimes for all involved parameters.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 12, 2023
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#106167 (Fix invalid syntax and incomplete suggestion in impl Trait parameter type suggestions for E0311)
 - rust-lang#106309 (Prefer non-`[type error]` candidates during selection)
 - rust-lang#106532 (Allow codegen to unsize `dyn*` to `dyn`)
 - rust-lang#106596 (Hide more of long types in E0271)
 - rust-lang#106638 (std tests: use __OsLocalKeyInner from realstd)
 - rust-lang#106676 (Test that we cannot use trait impl methods arguments as defining uses)
 - rust-lang#106702 (Conserve cause of `ImplDerivedObligation` in E0599)
 - rust-lang#106732 (rustc_llvm: replace llvm::makeArrayRef with ArrayRef constructors.)
 - rust-lang#106733 (Revert "warn newer available version of the x tool")
 - rust-lang#106748 (Clean up `OnUnimplementedFormatString::verify`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a8bd0c0 into rust-lang:master Jan 12, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 12, 2023
@yanchen4791 yanchen4791 deleted the issue-105544-fix branch January 13, 2023 21:13
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.

E0311 for impl Trait parameter type suggests invalid syntax
7 participants