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

Add shorter and more direct error for dyn AsyncFn #133267

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cramertj
Copy link
Member

Fix #132713
cc #62290

@rustbot
Copy link
Collaborator

rustbot commented Nov 20, 2024

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Nov 20, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 20, 2024

HIR ty lowering was modified

cc @fmease

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

@cramertj cramertj added the F-async_closure `#![feature(async_closure)]` label Nov 20, 2024
@@ -779,14 +795,18 @@ impl DynCompatibilityViolation {
DynCompatibilityViolation::GAT(name, _) => {
format!("it contains the generic associated type `{name}`").into()
}
DynCompatibilityViolation::AsyncFnTrait { .. } => {
"`async` function traits are not yet `dyn`-compatible".into()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"`async` function traits are not yet `dyn`-compatible".into()
"`async` function traits are not yet dyn-compatible".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.

What is the reason for preferring backticks for async and other keywords, but not for dyn? Should I also remove the backticks for async?

Copy link
Member

@fmease fmease Nov 20, 2024

Choose a reason for hiding this comment

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

There isn't a clear-cut general answer I'd say. As for dyn-compatible specifically, I'd like to think of it as a well-established term — including its spelling — as per rust-lang/lang-team#286 and all PRs under #130852. It would only break consistency to use dyn-compatible now.

Copy link
Member

@fmease fmease Nov 20, 2024

Choose a reason for hiding this comment

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

Hot-ish take, feel free to ignore

(Personally speaking, I think I'm leaning towards fully avoiding the use of backticks in running text / prose for the sake of legibility unless it surrounds literal source code. Mixing "code" and "prose" to express certain concepts feels rather ad hoc and awkward to me — like, I do that, too, when writing quick GH comments for example but for "official text" I think that's a different story. Note that I've probably broken that "rule" many times myself and I'm not suggesting you should follow it barring dyn-compatibility ^^ as it's quite unrealistic since several terms used in diagnostics are ad hoc & have never been seen before and it's quite convenient to intermix code and text)

Copy link
Member Author

Choose a reason for hiding this comment

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

rust-lang/lang-team#286 also does not hyphenate. That proposal uses "dyn compatibility" instead of "dyn-compatibility", so to be consistent I suppose I'll use "dyn compatible" rather than "dyn-compatible".

Copy link
Member

Choose a reason for hiding this comment

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

I'll use "dyn compatible" rather than "dyn-compatible".

Ye, that's fine. CC #126554 (comment)

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 geeze-- yeah, there are lots of uses of "dyn-compatible" throughout the codebase. It would be nice to have a standard here. "dyn compatible" + "dyn-compatibility"? I've added a commit that does a broad search+replace, but we can drop that if you don't think it's justified here.

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be done elsewhere

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, by elsewhere I mean on a different PR. And then probably assign that to @fmease if they want it. This PR now touches 150 files 😅

Copy link
Member Author

@cramertj cramertj Nov 21, 2024

Choose a reason for hiding this comment

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

I'm happy to leave it for another PR. In that case, I'd prefer to keep this PR using the existing terminology that is present throughout the codebase ("dyn-compatible") and a different PR can sort out whether that choice should be revised. I prefer this approach because it keeps the terminology more uniform in the meantime.

@rust-log-analyzer

This comment has been minimized.

compiler/rustc_type_ir/src/interner.rs Outdated Show resolved Hide resolved
// errors about the details of why these traits aren't object-safe.
for supertrait in tcx.supertrait_def_ids(trait_def_id) {
if tcx.trait_is_async_fn(supertrait) {
let fn_trait = tcx.item_name(supertrait);
Copy link
Member

Choose a reason for hiding this comment

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

defer this call to item_name to the error reporting.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, lol, you can't. If you want, you could probably remove the PartialOrd implementation from DynCompatibilityViolation, and change the one(?) sort call in error reporting to stop doing that.

while let hir::Node::Ty(ty) = tcx.parent_hir_node(hir_id) {
hir_id = ty.hir_id;
}
if tcx.parent_hir_node(hir_id).fn_sig().is_none() {
Copy link
Member

Choose a reason for hiding this comment

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

What does this actually suppress?

Copy link
Member

Choose a reason for hiding this comment

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

Also, I just re-read the whole diff. I see that you just moved this code to generalize the suggestion, right?

If so, then if you don't want to deal w/ the nits in this specific area, I guess that's fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm happy to make drive-by cleanups-- thanks for the suggestions and for helping me learn!

compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Nov 21, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 21, 2024

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @rust-lang/wg-const-eval

@rust-log-analyzer

This comment has been minimized.

@compiler-errors compiler-errors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 21, 2024
@@ -614,7 +614,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// codegen'd / interpreted as virtual calls through the vtable.
ty::InstanceKind::Virtual(def_id, idx) => {
let mut args = args.to_vec();
// We have to implement all "dyn-compatible receivers". So we have to go search for a
// We have to implement all "dyn compatible receivers". So we have to go search for a
Copy link
Member

@RalfJung RalfJung Nov 21, 2024

Choose a reason for hiding this comment

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

Doesn't English grammar say we need a - since this is a compound term used as an adjective? It's like "self-referential data", for instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

That was my intuition as well-- the initial version of this PR used the hyphenated compound adjective. @fmease linked to #126554 (comment) which seems to indicate a different preference.

My personal preference is for uniform use of "dyn-compatible" and "dyn-compatibility". This seems like something we should have a formal decision (T-lang approval?) around so that different decisions aren't being made at the level of individual contributions.

Copy link
Member

@RalfJung RalfJung Nov 21, 2024

Choose a reason for hiding this comment

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

Travis wrote there:

one would probably say that "a trait is dyn compatible" (but one might "have a dyn-compatible trait")

This is what makes most sense to me. A compound term in English is used with hyphen in adjective form but without hyphen elsewhere. That's how English works, it would be non-grammatical and confusing to insist on the same spelling everywhere.

It seems odd to me that t-lang would decide on a grammar question (the grammar of English, not of Rust ;), but 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-async_closure `#![feature(async_closure)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dyn AsyncFn generates many independent errors
8 participants