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

Do not suggest to add type annotations for unnameable types #86215

Merged
merged 2 commits into from
Jun 12, 2021

Conversation

FabianWolff
Copy link
Contributor

Consider this example:

const A = || 42;

struct S<T> { t: T }
const B: _ = S { t: || 42 };

This currently produces the following output:

error: missing type for `const` item
 --> src/lib.rs:1:7
  |
1 | const A = || 42;
  |       ^ help: provide a type for the item: `A: [closure@src/lib.rs:1:11: 1:16]`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --> src/lib.rs:4:10
  |
4 | const B: _ = S { t: || 42 };
  |          ^
  |          |
  |          not allowed in type signatures
  |          help: replace `_` with the correct type: `S<[closure@src/lib.rs:4:21: 4:26]>`

error: aborting due to 2 previous errors

However, these suggestions are obviously useless, because the suggested types cannot be written down. With my changes, the suggestion is replaced with a note, because there is no simple fix:

error: missing type for `const` item
 --> test.rs:1:7
  |
1 | const A = || 42;
  |       ^
  |
note: however, the inferred type `[[email protected]:1:11: 1:16]` cannot be named
 --> test.rs:1:11
  |
1 | const A = || 42;
  |           ^^^^^

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --> test.rs:4:10
  |
4 | const B: _ = S { t: || 42 };
  |          ^ not allowed in type signatures
  |
note: however, the inferred type `S<[[email protected]:4:21: 4:26]>` cannot be named
 --> test.rs:4:14
  |
4 | const B: _ = S { t: || 42 };
  |              ^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

@rust-highfive
Copy link
Collaborator

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 11, 2021
compiler/rustc_typeck/src/collect/type_of.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/collect/type_of.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/collect/type_of.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/collect/type_of.rs Outdated Show resolved Hide resolved
@jackh726
Copy link
Member

@bors delegate+

r=me with or without @fee1-dead's suggestion on suggesting a fn ptr instead of a fn def (I'd like to see it here, but also okay with that as a followup)

@bors
Copy link
Contributor

bors commented Jun 11, 2021

✌️ @FabianWolff can now approve this pull request

@jackh726
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 12, 2021

📌 Commit 79dc9a7 has been approved by jackh726

@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 Jun 12, 2021
@bors
Copy link
Contributor

bors commented Jun 12, 2021

⌛ Testing commit 79dc9a7 with merge 60f1a2f...

@bors
Copy link
Contributor

bors commented Jun 12, 2021

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 60f1a2f to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 12, 2021
@bors bors merged commit 60f1a2f into rust-lang:master Jun 12, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants