-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
I tried this code:
use std::{cell::RefCell};
pub struct MessageListeners<'a> {
listeners: RefCell<Vec<Box<dyn FnMut(()) + 'a>>>
}
impl<'a> MessageListeners<'a> {
pub fn new()->Self {
MessageListeners { listeners: RefCell::new(Vec::new()) }
}
pub fn listen(&self, f: impl FnMut(())+'a) {
self.listeners.borrow_mut().push(Box::new(f));
}
pub fn send(&self, message: ()) {
for listener in self.listeners.borrow_mut().iter_mut() {
(*listener)(message.clone());
}
}
pub fn map(&self, f: impl Fn(())->())->MessageListeners<'a> {
let r = MessageListeners::new();
self.listeners().listen(|m| r.send(f(m)));
r
}
}
pub trait MessageListenersInterface {
fn listeners(&self)->&MessageListeners;
}
impl<'a> MessageListenersInterface for MessageListeners<'a> {
fn listeners<'b>(&'b self)->&'a MessageListeners<'b> {
self
}
}
#[test]
fn test_message_listeners_map0() {
let ml = MessageListeners::new();
let f = |m: ()| {};
let g = |m: ()| m;
ml.map(g).listen(f);
ml.send(());
}
#[test]
fn test_message_listeners_map2() {
let ml = MessageListeners::new();
let f = |m: ()| {};
let g = |m: ()| m;
let temp_variable=ml.map(g);
temp_variable.listen(f);
ml.send(());
}
I expected to see this happen: the two tests do the same thing
Instead, this happened: the first unit test SEG faults, the second succeeds
Meta
rustc --version --verbose
:
rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: aarch64-apple-darwin
release: 1.65.0
LLVM version: 15.0.0```
<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>
Caused by:
process didn't exit successfully: /Users/adamritter/Documents/GitHub/synced_collection/target/debug/deps/synccollection-9d89a83a383169be
(signal: 11, SIGSEGV: invalid memory reference)```
wwylele
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Type
Projects
Status
Completed
Milestone
Relationships
Development
Select code repository
Activity
frxstrem commentedon Dec 5, 2022
MIRI claims undefined behavior here:
Given that this code only consists of safe code, that smells like a compiler bug.
jruderman commentedon Dec 5, 2022
First crashes in nightly-2020-10-07.
Bisection details
I used:
With unsound.sh containing:
Earlier versions report a lifetime error:
Lifetime error reported with nightly-2020-10-06
Was that lifetime error correct?
apiraino commentedon Dec 5, 2022
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-critical
RustyYato commentedon Dec 5, 2022
Yes, the lifetime error is correct
fn(&self) -> &'a _
is incompatible with the definition in the trait:fn(&self) -> &_
.compiler-errors commentedon Dec 8, 2022
Looks like it may be a bug in
compare_predicate_entailment
(trait<=>impl method compatibility checking). I'll take a look at this today, and if I can't find a root cause + fix in a few hours, I'll give it back.@rustbot claim
26 remaining items