-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Redact CoercePointee target type #136796
base: master
Are you sure you want to change the base?
Redact CoercePointee target type #136796
Conversation
This comment has been minimized.
This comment has been minimized.
22bab31
to
a26a420
Compare
This comment has been minimized.
This comment has been minimized.
a26a420
to
eb47b38
Compare
@rustbot label +F-derive_coerce_pointee |
I will mark as ready when the base PR is is ready to go as well |
eb47b38
to
8e48d60
Compare
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred in compiler/rustc_codegen_gcc |
This comment has been minimized.
This comment has been minimized.
8e48d60
to
8f7c0e5
Compare
| | ||
LL | struct TryToWipeRepr<'a, #[pointee] T: ?Sized> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 17 previous errors | ||
error[E0277]: the trait bound `Box<T>: Unsize<Box<T {unsized}>>` is not satisfied |
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.
This PR changes introduces quite a lot of machinery just to rename __S
to T {unsized}
. I don't actually think that's very different, and not worth the changes.
If we're going to do anything here, then it needs to be about changing the wording of the error message to explain what this Unsize
obligation is about.
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 would like to quote #134846 that this PR attempts to fix:
Desired output
Something that does not mention internal things likeUnsize
or__S
So I am thinking, should we instead redact all errors from unfulfilled Unsize
obligation entirely and replace them with messages to say unsizing <some type> is not permitted
, or something along this line?
Concretely, if we encounter a fulfillment error for Ty1: Unsize<Ty2>
, we write out a message saying unsizing Ty1 is not permitted
and forget about Ty2
, since Ty2
may contain internal stuffs like __S
in most cases and redacting those internal type names individually is now considered harmful. Is this what we are going after 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.
Sure. I think all this PR needs to do is intercept the errors in:
rust/compiler/rustc_hir_analysis/src/coherence/builtin.rs
Lines 560 to 562 in 06a24e9
if !errors.is_empty() { | |
infcx.err_ctxt().report_fulfillment_errors(errors); | |
} |
And:
rust/compiler/rustc_hir_analysis/src/coherence/builtin.rs
Lines 348 to 350 in 06a24e9
if !errors.is_empty() { | |
res = Err(infcx.err_ctxt().report_fulfillment_errors(errors)); | |
} |
And just say something like: "In order for ADT
to have a valid implementation of CoerceUnsized
, you need to be able to unsize &W<T>
."
Most importantly, it needs to explain why the unsize isn't valid. I know you're interested in fixing what was requested in #134846, but please think about the bigger picture, and also please think about minimizing the changes to the compiler while trying to fix the issue.
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.
See comment. If we're going to touch these error messages at all, then they should be heavily reworked to explain why the Unsize
goal exists at all.
target_pointee_ty: Ty<'tcx>, | ||
new_pointee_ty: Ty<'tcx>, | ||
) -> FulfillmentError<'tcx> { | ||
use traits::FulfillmentErrorCode::*; |
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.
no function-local glob imports please
When you get this error: "the trait bound I think the real error you need to emit is something like:
this lets you hide the If you instead get this error: "the trait bound
|
8f7c0e5
to
41ef5b5
Compare
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.
This implementation still needs a lot of clean up and simplification, but I don't want to leave review comments until it's clear that it's ready for review. S
pecifically, please check that the code has no changes that are unrelated to fixing this issue; all changes should either be reverted or exercised by tests.
Please mark it as S-waiting-on-review when it's ready.
51fc2ea
to
81a0c29
Compare
@rustbot ready
|
81a0c29
to
5044be4
Compare
@@ -372,9 +414,11 @@ pub(crate) fn coerce_unsized_info<'tcx>( | |||
let unsize_trait = tcx.require_lang_item(LangItem::Unsize, Some(span)); | |||
|
|||
let source = tcx.type_of(impl_did).instantiate_identity(); | |||
let self_ty = source; |
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.
Please revert this. It's not useful.
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.
source
binding is shadowed later. However, the diagnostics depends on this Self
type.
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.
Why not just rename the variable? The reassignment feels a bit awkward.
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().instantiate_identity(); | ||
assert_eq!(trait_ref.def_id, coerce_unsized_trait); | ||
let target = trait_ref.args.type_at(1); | ||
let coerced_ty = target; |
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.
Same here.
trait_name: "DispatchFromDyn", | ||
note: true, | ||
})); | ||
if extract_coerce_pointee_data(tcx, def_a.did()).is_some() { |
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.
Is this exercised by a test?
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.
Unless there is a good reason to have this, please revert it.
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.
.collect::<Vec<_>>() | ||
.join(", "), | ||
})); | ||
if extract_coerce_pointee_data(tcx, def_a.did()).is_some() { |
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.
Is this exercised by a test?
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.
@@ -509,12 +553,28 @@ pub(crate) fn coerce_unsized_info<'tcx>( | |||
.collect::<Vec<_>>(); | |||
|
|||
if diff_fields.is_empty() { | |||
if extract_coerce_pointee_data(tcx, def_a.did()).is_some() { |
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.
Is this exercised by a test?
if self.found { | ||
return; | ||
} | ||
if t == self.pointee { |
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.
Why is this implementation "micro-optimized"? It shouldn't matter to override all these functions, and it makes the visitor much larger than it needs to be.
if tcx.is_lang_item(pred.def_id(), LangItem::Unsize) { | ||
if mentions_pointee() { |
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.
Why is this two nested if
statements when the next one is &&
? Can you choose one?
.note = `derive(CoercePointee)` demands that `{$ty}` can be coerced to an unsized type | ||
.help = the standard pointers such as `Arc`, `Rc`, `Box`, and other types with `derive(CoercePointee)` can be coerced to their corresponding unsized types | ||
|
||
hir_analysis_coerce_pointee_cannot_unsize = `{$ty}` cannot be coerced to any unsized value |
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.
hir_analysis_coerce_pointee_cannot_unsize = `{$ty}` cannot be coerced to any unsized value | |
hir_analysis_coerce_pointee_cannot_unsize = `{$ty}` cannot be coerced to an unsized value |
@@ -85,6 +85,19 @@ hir_analysis_cmse_output_stack_spill = | |||
.note1 = functions with the `{$abi}` ABI must pass their result via the available return registers | |||
.note2 = the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size | |||
|
|||
hir_analysis_coerce_pointee_cannot_coerce_unsize = `{$ty}` cannot be coerced to an unsized type | |||
.note = `derive(CoercePointee)` demands that `{$ty}` can be coerced to an unsized type |
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.
This note is not exercised by any test, I think?
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 just realised that the note cannot be exercised because the span falls within the macro expansion.
Instead it is overwritten by this message.
note: this error originates in the derive macro `CoercePointee` (in Nightly builds, run with -Z macro-backtrace for more info)
This happens still after adding the missing #[note]
and #[help]
attributes to the diagnostics.
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.
Maybe I need to switch to the span of the ADT definition.
.help = the standard pointers such as `Arc`, `Rc`, `Box`, and other types with `derive(CoercePointee)` can be coerced to their corresponding unsized types | ||
|
||
hir_analysis_coerce_pointee_cannot_unsize = `{$ty}` cannot be coerced to any unsized value | ||
.note = `derive(CoercePointee)` demands that `{$ty}` can be coerced to an unsized type |
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.
Similar, this note is not exercised by any test?
OK -- so I think I understand my problem with this PR in its current state. Specifically, it's trying to do two things:
I'm somewhat hesitant that they need to be fixed at the same time, and I dislike the fact that the improvements relies on For example, for (1.) we could simply just detect if the impl is coming from an expansion (by looking at the span of the impl) and change the error message (like For the trait error reporting, we could simply emit a more tailored fulfillment error if there is only one fulfillment error and it ends up failing an TL;DR is that I think this PR is trying to change a lot all at once, and I'm somewhat overwhelmed with the state of it right now. |
@compiler-errors I sense that it is preferable to break this PR into two and improve the diagnostics in 1. and 2. separately. Shall we start from there?
I couldn't t follow unfortunately. It could be the naming at fault here and I owe the explanation, nevertheless I found the purpose of
It is where I can see intricacy. I am afraid that span information is brittle and unreliable because
This gets me thinking. What shall be the treatment when there are more than just one, and among those fulfilment errors are some involves |
I opened an alternative PR in #137289 that is a bit less complicated. I think it can be improved and refined in the future, but it seems to me easier to land than this one. |
Fix #134846
The issue here is that
__S
is actually an implementation detail ofderive(CoercePointee)
. This should not appear in our diagnostics. A better way to present this message is to designate it as<pointee generic type> {unsized}
as opposed to the undecipherable__S
here.r? @compiler-errors