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

Label struct/enum constructor instead of fn item, mention that it should be called on type mismatch #106524

Merged
merged 2 commits into from
Jan 12, 2023

Conversation

compiler-errors
Copy link
Member

Fixes #106516

@rustbot
Copy link
Collaborator

rustbot commented Jan 6, 2023

r? @cjgillot

(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 Jan 6, 2023
Comment on lines +322 to +326
ty::FnDef(def_id, ..) => match tcx.def_kind(def_id) {
DefKind::Ctor(CtorOf::Struct, _) => "struct constructor".into(),
DefKind::Ctor(CtorOf::Variant, _) => "enum constructor".into(),
_ => "fn item".into(),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use the existing descr method? The output is a bit different, but also more uniform with other diags.

Suggested change
ty::FnDef(def_id, ..) => match tcx.def_kind(def_id) {
DefKind::Ctor(CtorOf::Struct, _) => "struct constructor".into(),
DefKind::Ctor(CtorOf::Variant, _) => "enum constructor".into(),
_ => "fn item".into(),
},
ty::FnDef(def_id, ..) => tcx.def_kind(def_id).descr(def_id).into(),

Copy link
Member Author

Choose a reason for hiding this comment

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

Mostly because descr is pretty verbose here.. I didn't like how it sounded for these ctor DefKinds, but I don't have a particularly strong opinion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, also, I'm not really a fan of renaming functions from "fn item" to their descr "function".

@@ -366,7 +370,11 @@ impl<'tcx> Ty<'tcx> {
_ => "reference",
}
.into(),
ty::FnDef(..) => "fn item".into(),
ty::FnDef(def_id, ..) => match tcx.def_kind(def_id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise.

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs Outdated Show resolved Hide resolved
@cjgillot
Copy link
Contributor

cjgillot commented Jan 8, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Jan 8, 2023

📌 Commit 43d69cdba0d60e673465de27038a61dfade96d24 has been approved by cjgillot

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 8, 2023
@compiler-errors
Copy link
Member Author

rebased

@bors r=cjgillot

@bors
Copy link
Contributor

bors commented Jan 11, 2023

📌 Commit d375440 has been approved by cjgillot

It is now in the queue for this repository.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 12, 2023
…r=cjgillot

Label `struct/enum constructor` instead of `fn item`, mention that it should be called on type mismatch

Fixes rust-lang#106516
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 12, 2023
…mpiler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#103236 (doc: rewrite doc for signed int::{carrying_add,borrowing_sub})
 - rust-lang#103800 (Stabilize `::{core,std}::pin::pin!`)
 - rust-lang#106097 (Migrate mir_build diagnostics 2 of 3)
 - rust-lang#106170 (Move autoderef to `rustc_hir_analysis`)
 - rust-lang#106323 (Stabilize f16c_target_feature)
 - rust-lang#106360 (Tweak E0277 `&`-removal suggestions)
 - rust-lang#106524 (Label `struct/enum constructor` instead of `fn item`, mention that it should be called on type mismatch)
 - rust-lang#106739 (Remove `<dyn AstConv<'tcx>>::fun(c, ...)` calls in favour of `c.astconv().fun(...)`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d711394 into rust-lang:master Jan 12, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 12, 2023
@compiler-errors compiler-errors deleted the constructor-note branch August 11, 2023 19:57
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.

Clarify that function items defined by struct and such are constructors for these types
4 participants