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

Rollup of 8 pull requests #110772

Closed
wants to merge 33 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d9256f9
Add Lazy{Cell,Lock}::into_inner
SUPERCILEX Dec 26, 2022
41e3cc4
Add some tests around (lack of) object safety of associated types and…
oli-obk Apr 20, 2023
704a9da
Ignore src/bootstrap formatting commit in .git-blame-ignore-revs
jyn514 Apr 20, 2023
06ff310
Migrate `rustc_hir_analysis` to session diagnostic
obeis Apr 14, 2023
adb5ded
add known-bug test for unsound issue 25860
whtahy Apr 18, 2023
2fb2098
add known-bug test for unsound issue 49206
whtahy Apr 18, 2023
232d685
add known-bug test for unsound issue 57893
whtahy Apr 19, 2023
fbfb620
add known-bug test for unsound issue 84366
whtahy Apr 19, 2023
cac62ab
add known-bug test for unsound issue 84533
whtahy Apr 19, 2023
be68c69
add known-bug test for unsound issue 84591
whtahy Apr 19, 2023
3c5de9a
add known-bug test for unsound issue 85099
whtahy Apr 20, 2023
0e68cbd
Remove useless special case.
cjgillot Apr 15, 2023
629cdb4
Move eval_discriminant.
cjgillot Apr 15, 2023
dd452ae
Simplify logic.
cjgillot Apr 15, 2023
dd78b99
Reduce rightward drift.
cjgillot Apr 15, 2023
3141262
add known-bug test for unsound issue 98117
whtahy Apr 22, 2023
cff6c0e
add known-bug test for unsound issue 100041
whtahy Apr 22, 2023
6f6550f
add known-bug test for unsound issue 100051
whtahy Apr 22, 2023
ebe61ce
add known-bug test for unsound issue 104005
whtahy Apr 22, 2023
f5e535c
bootstrap: update paths cargo-credential crate
weihanglo Apr 23, 2023
e496fbe
Split `{Idx, IndexVec, IndexSlice}` into their own modules
WaffleLapkin Apr 19, 2023
99ebfe2
move index code around
WaffleLapkin Apr 19, 2023
7d23b52
`const`-ify some `{IndexVec, IndexSlice}` methods
WaffleLapkin Apr 19, 2023
5d809b1
Decorative changes to `IndexVec`
WaffleLapkin Apr 19, 2023
c0daff0
Fix `rustc_index` imports outside the compiler
WaffleLapkin Apr 19, 2023
d03ebe4
Rollup merge of #106152 - SUPERCILEX:lazycell, r=Amanieu
matthiaskrgr Apr 24, 2023
66e0836
Rollup merge of #110325 - obeis:hir-analysis-migrate-diagnostics-4, r…
matthiaskrgr Apr 24, 2023
9b0db55
Rollup merge of #110480 - whtahy:105107/known-bug-tests-for-unsound-i…
matthiaskrgr Apr 24, 2023
07d4ee4
Rollup merge of #110539 - WaffleLapkin:split_index_vec&slice, r=cjgillot
matthiaskrgr Apr 24, 2023
a0cc452
Rollup merge of #110590 - oli-obk:object_safe_assoc_types, r=jackh726
matthiaskrgr Apr 24, 2023
1b540f7
Rollup merge of #110602 - jyn514:ignore-fmt, r=Mark-Simulacrum
matthiaskrgr Apr 24, 2023
704e78c
Rollup merge of #110685 - cjgillot:clean-dcp, r=oli-obk
matthiaskrgr Apr 24, 2023
79efb26
Rollup merge of #110744 - weihanglo:cargo-credential-install, r=ehuss
matthiaskrgr Apr 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add known-bug test for unsound issue 85099
whtahy committed Apr 22, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tvdeyen Thomas von Deyen
commit 3c5de9a2e85e4490fad8c30a8078ac7117a01836
68 changes: 68 additions & 0 deletions tests/ui/typeck/pin-unsound-issue-85099-derefmut.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// check-pass
// known-bug: #85099

// Should fail. Can coerce `Pin<T>` into `Pin<U>` where
// `T: Deref<Target: Unpin>` and `U: Deref<Target: !Unpin>`, using the
// `CoerceUnsized` impl on `Pin` and an unorthodox `DerefMut` impl for
// `Pin<&_>`.

// This should not be allowed, since one can unpin `T::Target` (since it is
// `Unpin`) to gain unpinned access to the previously pinned `U::Target` (which
// is `!Unpin`) and then move it.

use std::{
cell::{RefCell, RefMut},
future::Future,
ops::DerefMut,
pin::Pin,
};

struct SomeLocalStruct<'a, Fut>(&'a RefCell<Fut>);

trait SomeTrait<'a, Fut> {
#[allow(clippy::mut_from_ref)]
fn deref_helper(&self) -> &mut (dyn SomeTrait<'a, Fut> + 'a) {
unimplemented!()
}
fn downcast(self: Pin<&mut Self>) -> Pin<&mut Fut> {
unimplemented!()
}
}

impl<'a, Fut: Future<Output = ()>> SomeTrait<'a, Fut> for SomeLocalStruct<'a, Fut> {
fn deref_helper(&self) -> &mut (dyn SomeTrait<'a, Fut> + 'a) {
let x = Box::new(self.0.borrow_mut());
let x: &'a mut RefMut<'a, Fut> = Box::leak(x);
&mut **x
}
}
impl<'a, Fut: Future<Output = ()>> SomeTrait<'a, Fut> for Fut {
fn downcast(self: Pin<&mut Self>) -> Pin<&mut Fut> {
self
}
}

impl<'b, 'a, Fut> DerefMut for Pin<&'b dyn SomeTrait<'a, Fut>> {
fn deref_mut<'c>(
self: &'c mut Pin<&'b dyn SomeTrait<'a, Fut>>,
) -> &'c mut (dyn SomeTrait<'a, Fut> + 'b) {
self.deref_helper()
}
}

// obviously a "working" function with this signature is problematic
pub fn unsound_pin<Fut: Future<Output = ()>>(
fut: Fut,
callback: impl FnOnce(Pin<&mut Fut>),
) -> Fut {
let cell = RefCell::new(fut);
let s: &SomeLocalStruct<'_, Fut> = &SomeLocalStruct(&cell);
let p: Pin<Pin<&SomeLocalStruct<'_, Fut>>> = Pin::new(Pin::new(s));
let mut p: Pin<Pin<&dyn SomeTrait<'_, Fut>>> = p;
let r: Pin<&mut dyn SomeTrait<'_, Fut>> = p.as_mut();
let f: Pin<&mut Fut> = r.downcast();
callback(f);
cell.into_inner()
}

fn main() {}