Panic: if `get_resource` is called (provides None if missing), then `init_resource`, get a panic
まだ誰も着手していません。
評価
調査の方向性
Start by reading the shown get and init_resource implementations, then inspect contains and the resource map behavior to confirm how an empty entry is represented. Update the check so init_resource initializes when the resource has no value, and add or run a regression test for calling get_resource before init_resource to verify it no longer panics.
索引モデルが issue の本文から書いたものです。
説明
world.get_resource does this:
#[track_caller]
pub fn get<T: HasSchema>(&self) -> Option<Ref<T>> {
let b = self.untyped.get(T::schema()).borrow();
if b.is_some() {
Some(Ref::map(b, |b| unsafe {
b.as_ref().unwrap().as_ref().cast_into_unchecked()
}))
} else {
None
}
}
self.untyped.get() This inserts the the schema id into OnceMap, with contents being empty.
init_resource does:
pub fn init_resource<R: HasSchema + FromWorld>(&mut self) -> RefMut<R> {
if unlikely(!self.resources.contains::<R>()) {
let value = R::from_world(self);
self.resources.insert(value);
}
self.resource_mut()
}
and contains only checks if ID is contained - not if resource has a value. This skips the init branch, and only calls self.resource_mut which panics on missing resource value.
This is the only place in bones that contains is used, I think we should update this to check if the resource has a value, and not just ID entry in map. This is what I would expect when using the function as well.
- 主要言語
- Rust
- スター
- 314
- フォーク
- 26
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fishfolk/bones のほかの issue
-
code:todo
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
-
code:todo
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
code:todo
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
code:todo
難易度 3/5 半日 初心者へのやさしさ 48/100
-
code:todo
難易度 3/5 1〜2日 初心者へのやさしさ 67/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
farion1231/cc-switch#8829 ·
メンテナーはふだん 1 日以内に返信
-
Validate CI command vectors before indexing Cargo subcommands対応中かも @amandeavor が今日担当しました。 オープンbug ci good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
longbridge/gpui-kit#3677 ·
メンテナーはふだん 1 日以内に返信
-
E-pr-welcome
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
seanmonstar/reqwest#3121 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
ilya-zlobintsev/LACT#1235 ·
メンテナーはふだん 1 日以内に返信