Skip to content

Fixing bad suggestion for _ in const type when a function #81885#81914

Merged
bors merged 5 commits into
rust-lang:masterfrom
kper:fixing-81885
Feb 15, 2021
Merged

Fixing bad suggestion for _ in const type when a function #81885#81914
bors merged 5 commits into
rust-lang:masterfrom
kper:fixing-81885

Conversation

@kper

@kper kper commented Feb 9, 2021

Copy link
Copy Markdown
Contributor

Closes #81885

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
  --> $DIR/typeck_type_placeholder_item_help.rs:13:22
   |
LL | const TEST4: fn() -> _ = 42;
   |                      ^
   |                      |
   |                      not allowed in type signatures
   |                      help: use type parameters instead: `T`

Do not show the suggestion help: use type parameters instead: T when fn

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @estebank

(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 Feb 9, 2021
@rust-log-analyzer

This comment has been minimized.

@estebank estebank left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I originally thought that a simple filter as you're doing here would be enough, but looking at the result I feel like we might have to do something a bit more involved to be accurate and remain helpful. Would you be interested in exploring alternatives we could have here?

Comment thread compiler/rustc_typeck/src/collect.rs Outdated
Comment thread src/test/ui/did_you_mean/bad-assoc-ty.stderr
Comment thread src/test/ui/typeck/typeck_type_placeholder_item.stderr
@kper

kper commented Feb 9, 2021

Copy link
Copy Markdown
Contributor Author

Thank you for your comments. I will look into it.

@kper

kper commented Feb 10, 2021

Copy link
Copy Markdown
Contributor Author

I am currently thinking of ways to implement this filter. But, how can a function know that it is in a context of type?
Do I have to change something in typing context? https://github.com/rust-lang/rust/blob/master/compiler/rustc_typeck/src/collect.rs#L756

@kper

kper commented Feb 12, 2021

Copy link
Copy Markdown
Contributor Author

I am currently thinking of ways to implement this filter. But, how can a function know that it is in a context of type?
Do I have to change something in typing context? https://github.com/rust-lang/rust/blob/master/compiler/rustc_typeck/src/collect.rs#L756

Nevermind that, I passed the hir::Ty which has a reference to the parent_node. This node can I check if it is const or static.

However, this is not working for impl yet

fn main() {}
struct MyStruct;

trait Test {
}

impl Test for MyStruct {
    const TEST: fn() -> _ = 42; 
}
error[E0438]: const `TEST` is not a member of trait `Test`
  --> main_test.rs:10:5
   |
10 |     const TEST: fn() -> _ = 42; 
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Test`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
  --> main_test.rs:10:25
   |
10 |     const TEST: fn() -> _ = 42; 
   |                         ^
   |                         |
   |                         not allowed in type signatures
   |                         help: use type parameters instead: `T`

@estebank

Copy link
Copy Markdown
Contributor

@kper that is ok about associated consts. The other improvements in the output are more than great.

@bors r+

@bors

bors commented Feb 12, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 1adc6be has been approved by estebank

@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 Feb 12, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#80523 (#[doc(inline)] sym_generated)
 - rust-lang#80920 (Visit more targets when validating attributes)
 - rust-lang#81720 (Updated smallvec version due to RUSTSEC-2021-0003)
 - rust-lang#81891 ([rustdoc-json] Make `header` a vec of modifiers, and FunctionPointer consistent)
 - rust-lang#81912 (Implement the precise analysis pass for lint `disjoint_capture_drop_reorder`)
 - rust-lang#81914 (Fixing bad suggestion for `_` in `const` type when a function rust-lang#81885)
 - rust-lang#81919 (BTreeMap: fix internal comments)
 - rust-lang#81927 (Add a regression test for rust-lang#32498)
 - rust-lang#81965 (Fix MIR pretty printer for non-local DefIds)
 - rust-lang#82029 (Use debug log level for developer oriented logs)
 - rust-lang#82056 (fix ice (rust-lang#82032))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a6809d0 into rust-lang:master Feb 15, 2021
@rustbot rustbot added this to the 1.52.0 milestone Feb 15, 2021
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad suggestion for _ in const type

6 participants