Skip to content

Commit 73bc9c5

Browse files
Fix missing cache variable when temp_cache feature is enabled (#3384)
This fixes an issue introduced in [commit][cmt] when trying to rewrite with new 1.88 let-chains. [cmt]: ffaf185
1 parent 357010d commit 73bc9c5

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

src/model/channel/channel_id.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,24 @@ impl ChannelId {
5555
guild_id: Option<GuildId>,
5656
) -> Result<GuildChannel> {
5757
#[cfg(feature = "cache")]
58-
if let Some(cache) = cache_http.cache()
59-
&& let Some(guild_id) = guild_id
60-
&& let Some(guild) = cache.guild(guild_id)
61-
&& let Some(channel) = guild.channels.get(&self)
62-
{
63-
return Ok(channel.clone());
64-
}
65-
66-
#[cfg(feature = "temp_cache")]
67-
if let Some(temp_channel) = cache.temp_channels.get(&self) {
68-
if guild_id.is_some_and(|id| temp_channel.base.guild_id != id) {
69-
return Err(Error::Model(ModelError::ChannelNotFound));
58+
// Ignore clippy, the two `if let`s must be separated
59+
#[allow(clippy::collapsible_if)]
60+
if let Some(cache) = cache_http.cache() {
61+
if let Some(guild_id) = guild_id
62+
&& let Some(guild) = cache.guild(guild_id)
63+
&& let Some(channel) = guild.channels.get(&self)
64+
{
65+
return Ok(channel.clone());
7066
}
7167

72-
return Ok(GuildChannel::clone(&temp_channel));
68+
#[cfg(feature = "temp_cache")]
69+
if let Some(temp_channel) = cache.temp_channels.get(&self) {
70+
if guild_id.is_some_and(|id| temp_channel.base.guild_id != id) {
71+
return Err(Error::Model(ModelError::ChannelNotFound));
72+
}
73+
74+
return Ok(GuildChannel::clone(&temp_channel));
75+
}
7376
}
7477

7578
let channel = cache_http.http().get_channel(self.widen()).await?;

src/model/channel/thread.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,24 @@ impl ThreadId {
3333
guild_id: Option<GuildId>,
3434
) -> Result<GuildThread> {
3535
#[cfg(feature = "cache")]
36-
if let Some(cache) = cache_http.cache()
37-
&& let Some(guild_id) = guild_id
38-
&& let Some(guild) = cache.guild(guild_id)
39-
&& let Some(thread) = guild.threads.get(&self)
40-
{
41-
return Ok(thread.clone());
42-
}
43-
44-
#[cfg(feature = "temp_cache")]
45-
if let Some(temp_thread) = cache.temp_threads.get(&self) {
46-
if guild_id.is_some_and(|id| temp_thread.base.guild_id != id) {
47-
return Err(Error::Model(ModelError::ChannelNotFound));
36+
// Ignore clippy, the two `if let`s must be separated
37+
#[allow(clippy::collapsible_if)]
38+
if let Some(cache) = cache_http.cache() {
39+
if let Some(guild_id) = guild_id
40+
&& let Some(guild) = cache.guild(guild_id)
41+
&& let Some(thread) = guild.threads.get(&self)
42+
{
43+
return Ok(thread.clone());
4844
}
4945

50-
return Ok(GuildThread::clone(&temp_thread));
46+
#[cfg(feature = "temp_cache")]
47+
if let Some(temp_thread) = cache.temp_threads.get(&self) {
48+
if guild_id.is_some_and(|id| temp_thread.base.guild_id != id) {
49+
return Err(Error::Model(ModelError::ChannelNotFound));
50+
}
51+
52+
return Ok(GuildThread::clone(&temp_thread));
53+
}
5154
}
5255

5356
let channel = cache_http.http().get_channel(self.widen()).await?;

0 commit comments

Comments
 (0)