Skip to content

Commit 0611e2c

Browse files
authored
Fix compilation without default features (#1548)
This also fixes the `utils` feature without `model`. `cargo check --no-default-features --features utils` Additionally, it introduces a new `no default features` CI job to prevent miscompilations when default features are disabled in the future. Closes #763
1 parent 921ff6f commit 0611e2c

File tree

15 files changed

+33
-7
lines changed

15 files changed

+33
-7
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
- nightly
2020
- macOS
2121
- Windows
22+
- no default features
2223
- no cache
2324
- no gateway
2425
- unstable Discord API features
@@ -34,6 +35,8 @@ jobs:
3435
os: macOS-latest
3536
- name: Windows
3637
os: windows-latest
38+
- name: no default features
39+
features: " "
3740
- name: no cache
3841
features: builder client framework gateway model http standard_framework utils rustls_backend
3942
- name: no gateway

src/model/channel/channel_id.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::Arc;
55

66
#[cfg(feature = "model")]
77
use bytes::buf::Buf;
8+
#[cfg(feature = "model")]
89
use futures::stream::Stream;
910
#[cfg(feature = "model")]
1011
use reqwest::Url;
@@ -17,13 +18,14 @@ use tokio::{fs::File, io::AsyncReadExt};
1718
use crate::builder::{
1819
CreateInvite,
1920
CreateMessage,
21+
CreateStageInstance,
2022
CreateThread,
2123
EditChannel,
2224
EditMessage,
25+
EditStageInstance,
2326
EditThread,
2427
GetMessages,
2528
};
26-
use crate::builder::{CreateStageInstance, EditStageInstance};
2729
#[cfg(all(feature = "cache", feature = "model"))]
2830
use crate::cache::Cache;
2931
#[cfg(feature = "collector")]
@@ -1213,13 +1215,15 @@ impl ChannelId {
12131215
}
12141216
}
12151217

1218+
#[cfg(feature = "model")]
12161219
impl From<Channel> for ChannelId {
12171220
/// Gets the Id of a [`Channel`].
12181221
fn from(channel: Channel) -> ChannelId {
12191222
channel.id()
12201223
}
12211224
}
12221225

1226+
#[cfg(feature = "model")]
12231227
impl<'a> From<&'a Channel> for ChannelId {
12241228
/// Gets the Id of a [`Channel`].
12251229
fn from(channel: &Channel) -> ChannelId {

src/model/channel/guild_channel.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ use crate::builder::EditChannel;
1313
use crate::builder::{
1414
CreateInvite,
1515
CreateMessage,
16+
CreateStageInstance,
1617
CreateThread,
1718
EditMessage,
19+
EditStageInstance,
1820
EditThread,
1921
EditVoiceState,
2022
GetMessages,
2123
};
22-
use crate::builder::{CreateStageInstance, EditStageInstance};
2324
#[cfg(feature = "cache")]
2425
use crate::cache::Cache;
2526
#[cfg(feature = "collector")]

src/model/channel/message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Models relating to Discord channels.
22
3+
#[cfg(feature = "model")]
34
use std::fmt::Display;
45
#[cfg(all(feature = "cache", feature = "model"))]
56
use std::fmt::Write;

src/model/channel/reaction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
#[cfg(feature = "model")]
2+
use std::cmp::Ordering;
13
use std::convert::TryFrom;
24
use std::str::FromStr;
35
use std::{
4-
cmp::Ordering,
56
error::Error as StdError,
67
fmt::{self, Display, Formatter, Result as FmtResult, Write as FmtWrite},
78
};

src/model/event.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,7 @@ pub enum Event {
19101910
Unknown(UnknownEvent),
19111911
}
19121912

1913+
#[cfg(feature = "model")]
19131914
fn gid_from_channel(c: &Channel) -> RelatedId<GuildId> {
19141915
use RelatedId::*;
19151916
match c {
@@ -2272,6 +2273,7 @@ macro_rules! with_related_ids_for_event_types {
22722273
};
22732274
}
22742275

2276+
#[cfg(feature = "model")]
22752277
macro_rules! define_event_related_id_methods {
22762278
($(
22772279
$(#[$attr:meta])?
@@ -2404,6 +2406,7 @@ impl Event {
24042406
}
24052407
}
24062408

2409+
#[cfg(feature = "model")]
24072410
with_related_ids_for_event_types!(define_event_related_id_methods);
24082411
}
24092412

src/model/guild/emoji.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use serde_json::json;
55

66
#[cfg(all(feature = "cache", feature = "model"))]
77
use crate::cache::Cache;
8+
#[cfg(all(feature = "cache", feature = "model"))]
89
use crate::http::Http;
910
#[cfg(all(feature = "cache", feature = "model"))]
1011
use crate::internal::prelude::*;

src/model/guild/guild_id.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(feature = "model")]
12
use futures::stream::Stream;
23
#[cfg(feature = "model")]
34
use serde_json::json;

src/model/guild/member.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#[cfg(feature = "model")]
22
use std::borrow::Cow;
3+
#[cfg(all(feature = "cache", feature = "model"))]
34
use std::cmp::Reverse;
45
use std::fmt::{Display, Formatter, Result as FmtResult};
56

6-
#[cfg(feature = "model")]
77
use bitflags::__impl_bitflags;
88
use chrono::{DateTime, Utc};
99
use serde::{Serialize, Serializer};

src/model/guild/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mod role;
1515
mod system_channel;
1616

1717
use chrono::{DateTime, Utc};
18+
#[cfg(feature = "model")]
1819
use futures::stream::StreamExt;
1920
use serde::de::Error as DeError;
2021
use serde::{Serialize, Serializer};

0 commit comments

Comments
 (0)