Skip to content

Commit 76dcb39

Browse files
committed
Adjust error messages
1 parent f65250b commit 76dcb39

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ symbols! {
309309
PathBuf,
310310
Pending,
311311
PinCoerceUnsized,
312+
PinDerefMutHelper,
312313
Pointer,
313314
Poll,
314315
ProcMacro,

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,6 +3476,24 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
34763476
// can do about it. As far as they are concerned, `?` is compiler magic.
34773477
return;
34783478
}
3479+
if tcx.is_diagnostic_item(sym::PinDerefMutHelper, parent_def_id) {
3480+
let parent_predicate =
3481+
self.resolve_vars_if_possible(data.derived.parent_trait_pred);
3482+
3483+
// Skip PinDerefMutHelper in suggestions, but still show downstream suggestions.
3484+
ensure_sufficient_stack(|| {
3485+
self.note_obligation_cause_code(
3486+
body_id,
3487+
err,
3488+
parent_predicate,
3489+
param_env,
3490+
&data.derived.parent_code,
3491+
obligated_types,
3492+
seen_requirements,
3493+
)
3494+
});
3495+
return;
3496+
}
34793497
let self_ty_str =
34803498
tcx.short_string(parent_trait_pred.skip_binder().self_ty(), err.long_ty_path());
34813499
let trait_name = tcx.short_string(

library/core/src/pin.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,20 +1711,21 @@ mod helper {
17111711
#[repr(transparent)]
17121712
#[unstable(feature = "pin_derefmut_internals", issue = "none")]
17131713
#[allow(missing_debug_implementations)]
1714-
pub struct Pin<Ptr> {
1714+
pub struct PinHelper<Ptr> {
17151715
pointer: Ptr,
17161716
}
17171717

17181718
#[unstable(feature = "pin_derefmut_internals", issue = "none")]
17191719
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
1720-
pub const trait DerefMut {
1720+
#[rustc_diagnostic_item = "PinDerefMutHelper"]
1721+
pub const trait PinDerefMutHelper {
17211722
type Target: ?Sized;
17221723
fn deref_mut(&mut self) -> &mut Self::Target;
17231724
}
17241725

17251726
#[unstable(feature = "pin_derefmut_internals", issue = "none")]
17261727
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
1727-
impl<Ptr: [const] super::DerefMut> const DerefMut for Pin<Ptr>
1728+
impl<Ptr: [const] super::DerefMut> const PinDerefMutHelper for PinHelper<Ptr>
17281729
where
17291730
Ptr::Target: crate::marker::Unpin,
17301731
{
@@ -1743,14 +1744,14 @@ mod helper {
17431744
impl<Ptr> const DerefMut for Pin<Ptr>
17441745
where
17451746
Ptr: [const] Deref,
1746-
helper::Pin<Ptr>: [const] helper::DerefMut<Target = Self::Target>,
1747+
helper::PinHelper<Ptr>: [const] helper::PinDerefMutHelper<Target = Self::Target>,
17471748
{
17481749
#[inline]
17491750
fn deref_mut(&mut self) -> &mut Ptr::Target {
1750-
// SAFETY: Pin and helper::Pin have the same layout, so this is equivalent to
1751+
// SAFETY: Pin and PinHelper have the same layout, so this is equivalent to
17511752
// `&mut self.pointer` which is safe because `Target: Unpin`.
1752-
helper::DerefMut::deref_mut(unsafe {
1753-
&mut *(self as *mut Pin<Ptr> as *mut helper::Pin<Ptr>)
1753+
helper::PinDerefMutHelper::deref_mut(unsafe {
1754+
&mut *(self as *mut Pin<Ptr> as *mut helper::PinHelper<Ptr>)
17541755
})
17551756
}
17561757
}

tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
+ let mut _44: &mut std::future::Ready<()>;
6464
+ let mut _45: &mut std::pin::Pin<&mut std::future::Ready<()>>;
6565
+ scope 14 (inlined <Pin<&mut std::future::Ready<()>> as DerefMut>::deref_mut) {
66-
+ let mut _46: *mut std::pin::helper::Pin<&mut std::future::Ready<()>>;
66+
+ let mut _46: *mut std::pin::helper::PinHelper<&mut std::future::Ready<()>>;
6767
+ let mut _47: *mut std::pin::Pin<&mut std::future::Ready<()>>;
68-
+ scope 15 (inlined <pin::helper::Pin<&mut std::future::Ready<()>> as pin::helper::DerefMut>::deref_mut) {
68+
+ scope 15 (inlined <pin::helper::PinHelper<&mut std::future::Ready<()>> as pin::helper::PinDerefMutHelper>::deref_mut) {
6969
+ let mut _48: &mut &mut std::future::Ready<()>;
7070
+ scope 16 (inlined <&mut std::future::Ready<()> as DerefMut>::deref_mut) {
7171
+ }
@@ -221,7 +221,7 @@
221221
+ StorageLive(_42);
222222
+ StorageLive(_47);
223223
+ _47 = &raw mut _19;
224-
+ _46 = copy _47 as *mut std::pin::helper::Pin<&mut std::future::Ready<()>> (PtrToPtr);
224+
+ _46 = copy _47 as *mut std::pin::helper::PinHelper<&mut std::future::Ready<()>> (PtrToPtr);
225225
+ StorageDead(_47);
226226
+ _44 = copy ((*_46).0: &mut std::future::Ready<()>);
227227
+ StorageLive(_49);

tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-unwind.diff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
+ let mut _46: &mut std::future::Ready<()>;
6666
+ let mut _47: &mut std::pin::Pin<&mut std::future::Ready<()>>;
6767
+ scope 14 (inlined <Pin<&mut std::future::Ready<()>> as DerefMut>::deref_mut) {
68-
+ let mut _48: *mut std::pin::helper::Pin<&mut std::future::Ready<()>>;
68+
+ let mut _48: *mut std::pin::helper::PinHelper<&mut std::future::Ready<()>>;
6969
+ let mut _49: *mut std::pin::Pin<&mut std::future::Ready<()>>;
70-
+ scope 15 (inlined <pin::helper::Pin<&mut std::future::Ready<()>> as pin::helper::DerefMut>::deref_mut) {
70+
+ scope 15 (inlined <pin::helper::PinHelper<&mut std::future::Ready<()>> as pin::helper::PinDerefMutHelper>::deref_mut) {
7171
+ let mut _50: &mut &mut std::future::Ready<()>;
7272
+ scope 16 (inlined <&mut std::future::Ready<()> as DerefMut>::deref_mut) {
7373
+ }
@@ -238,7 +238,7 @@
238238
+ StorageLive(_44);
239239
+ StorageLive(_49);
240240
+ _49 = &raw mut _19;
241-
+ _48 = copy _49 as *mut std::pin::helper::Pin<&mut std::future::Ready<()>> (PtrToPtr);
241+
+ _48 = copy _49 as *mut std::pin::helper::PinHelper<&mut std::future::Ready<()>> (PtrToPtr);
242242
+ StorageDead(_49);
243243
+ _46 = copy ((*_48).0: &mut std::future::Ready<()>);
244244
+ StorageLive(_51);

tests/ui/deref/pin-impl-deref.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | impl_deref_mut(r_unpin)
77
| required by a bound introduced by this call
88
|
99
= note: `DerefMut` is implemented for `&mut MyUnpinType`, but not for `&MyUnpinType`
10-
= note: required for `pin::helper::Pin<&MyUnpinType>` to implement `pin::helper::DerefMut`
1110
= note: required for `Pin<&MyUnpinType>` to implement `DerefMut`
1211
note: required by a bound in `impl_deref_mut`
1312
--> $DIR/pin-impl-deref.rs:22:27
@@ -24,7 +23,6 @@ LL | impl_deref_mut(r_pin)
2423
| required by a bound introduced by this call
2524
|
2625
= note: `DerefMut` is implemented for `&mut MyPinType`, but not for `&MyPinType`
27-
= note: required for `pin::helper::Pin<&MyPinType>` to implement `pin::helper::DerefMut`
2826
= note: required for `Pin<&MyPinType>` to implement `DerefMut`
2927
note: required by a bound in `impl_deref_mut`
3028
--> $DIR/pin-impl-deref.rs:22:27
@@ -47,7 +45,6 @@ note: required because it appears within the type `MyPinType`
4745
|
4846
LL | struct MyPinType(core::marker::PhantomPinned);
4947
| ^^^^^^^^^
50-
= note: required for `pin::helper::Pin<&MyPinType>` to implement `pin::helper::DerefMut`
5148
= note: required for `Pin<&MyPinType>` to implement `DerefMut`
5249
note: required by a bound in `impl_deref_mut`
5350
--> $DIR/pin-impl-deref.rs:22:27
@@ -70,7 +67,6 @@ note: required because it appears within the type `MyPinType`
7067
|
7168
LL | struct MyPinType(core::marker::PhantomPinned);
7269
| ^^^^^^^^^
73-
= note: required for `pin::helper::Pin<&mut MyPinType>` to implement `pin::helper::DerefMut`
7470
= note: required for `Pin<&mut MyPinType>` to implement `DerefMut`
7571
note: required by a bound in `impl_deref_mut`
7672
--> $DIR/pin-impl-deref.rs:22:27

tests/ui/typeck/pin-unsound-issue-85099-derefmut.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | impl<'b, 'a, Fut> DerefMut for Pin<&'b dyn SomeTrait<'a, Fut>> {
66
|
77
= note: conflicting implementation in crate `core`:
88
- impl<Ptr> DerefMut for Pin<Ptr>
9-
where <pin::helper::Pin<Ptr> as pin::helper::DerefMut>::Target == <Pin<Ptr> as Deref>::Target, Ptr: Deref, pin::helper::Pin<Ptr>: pin::helper::DerefMut, pin::helper::Pin<Ptr>: ?Sized;
10-
= note: upstream crates may add a new impl of trait `std::pin::helper::DerefMut` for type `std::pin::helper::Pin<&dyn SomeTrait<'_, _>>` in future versions
9+
where <pin::helper::PinHelper<Ptr> as pin::helper::PinDerefMutHelper>::Target == <Pin<Ptr> as Deref>::Target, Ptr: Deref, pin::helper::PinHelper<Ptr>: pin::helper::PinDerefMutHelper, pin::helper::PinHelper<Ptr>: ?Sized;
10+
= note: upstream crates may add a new impl of trait `std::pin::helper::PinDerefMutHelper` for type `std::pin::helper::PinHelper<&dyn SomeTrait<'_, _>>` in future versions
1111

1212
error: aborting due to 1 previous error
1313

0 commit comments

Comments
 (0)