-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Rustdoc displays private internals of associated constants (regression) #97933
Comments
#95316 is indeed the cause. More specifically the following line: rust/src/librustdoc/html/render/mod.rs Line 715 in 3dea003
If we “fail” to evaluate (“failure” also includes “the constant is a struct”) the const value of a provided associated const with I assume in the non-associated const version (shown below) the call to pub struct Struct { private: () }
pub const CONST: Struct = Struct { private: () };
I am not sure how to proceed @GuillaumeGomez. This is another instance of constant-printing for provided assoc consts being problematic. Previous incident: Performance (#95316 (comment)). |
Maybe we could update the |
The ideal solution (non-hotfix) would be to generally improve the printing of (unevaluated) constants (as returned by |
Seems like we want something similar. I don't think it's very difficult but might involve a lot of code. Want to give it a try? |
I might as well try. If successful, my PR needs backporting. @rustbot claim |
Error: Parsing assign command in comment failed: ...'bot assign' | error: specify user to assign to at >| ''... Please let |
I'm not convinced that displaying the value of (provided associated) constants in rustdoc is ever worthwhile and indeed it could be harmful. Users should not need to know what value a constant holds, only what it represents; indeed they should only ever be using the constant itself to represent that value when it's required—that is to say, the value assigned is an implementation detail and nobody should be relying upon it. |
I strongly disagree. Associated constants are meant to be used by externals users, otherwise they'd not be created. They are definitely not an implementation detail and they are part of the public API so everyone should rely on them. There are a lot of examples so I'll just take one: all |
I'm not sure I follow. Why do I need to know that |
I agree with @GuillaumeGomez. They are not an implementation detail, at least not those that are of a type that exposes structural equality (deriving ( I even vaguely remember seeing a Zulip discussion about how public constants always leak their implementation / concrete value, not just those of a |
Isn't that just relying on an implementation detail in order to work-around current limitations in the language? If/when |
What I am saying is that changing the value of a public constant is a breaking change since it is part of the public API. As a simplified example, consider the case where a crate called Crate pub struct Container<const B: bool>;
const _: Container<{constants::Y}> = Container::<{!constants::X}>; Crate const _: () = match true { constants::X | constants::Y => {} }; In version A of |
Ah, understood! Sorry for being slow on the uptake :). That all makes sense now. |
@fmease I understand your argument to some extent, but changing a function's body can also be a SemVer breaking change. Why should constants — which also hide a complex expression and present a simple API, like functions — be treated differently? |
My point is that we never show function bodies (even with We do show the bodies of free (non-associated) constants already, but I think I'd rather stop doing that instead of also displaying associated constants' values. |
I see your point. I disagree though. If you update a constant value, it's the same as changing a function's header: it's a breaking change. And it's also super useful to be able to see the value of a constant (associated or not) and I think it's definitely a big plus. |
Well, I at least think we shouldn't show the raw expression from the constant's body; we should only show the fully-computed value. |
@camelid Yes, we should prefer printing the evaluated const. I am working on this. It's not as trivial and I am going to do it incrementally. The biggest issue is the missing support for const substitutions as you might remember. Yesterday I almost had a working PR done, in some sense a hotfix for this issue, that “censors” complex unevaluated expressions like struct literals and match expressions by replacing them with I have further plans for improving const support but the current representation of constant expressions and the lack of const substitutions in rustdoc is giving me headaches. I have already prepared a more sophisticated PR that adds hyperlinks to const exprs and understands the concept of private and |
Yeah, the current state of the code is quite unfortunate :( I've tried to improve it, but as you've seen it's very hard to understand and change. |
PR coming up within the next hour. I just need to write some more tests. |
Correct:
Incorrect:
I used the following script to bisect:
cargo-bisect-rustc --script ./bisect.sh
It bisects to nightly-2022-04-14 and specifically #95990, of which #95316 seems the most relevant because it involves associated constants in rustdoc. @fmease @notriddle @GuillaumeGomez
The text was updated successfully, but these errors were encountered: