-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
base: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
HIR ty lowering was modified cc @fmease Some changes occurred in diagnostic error codes |
@@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"`async` function traits are not yet `dyn`-compatible".into() | |
"`async` function traits are not yet dyn-compatible".into() |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😅
There was a problem hiding this comment.
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.
1e17c14
to
55d16b9
Compare
This comment has been minimized.
This comment has been minimized.
// 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs
Outdated
Show resolved
Hide resolved
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
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 |
This comment has been minimized.
This comment has been minimized.
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🤷
0fc289a
to
0718a49
Compare
0718a49
to
b73794d
Compare
Fix #132713
cc #62290