Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit e4ac381

Browse files
committed
Add more helpful compiler messages when the features are improperly specified
1 parent 39a375f commit e4ac381

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

rls-analysis/src/raw.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub use data::{
1212
CratePreludeData, Def, DefKind, GlobalCrateId as CrateId, Import, Ref, Relation, RelationKind,
1313
SigElement, Signature, SpanData,
1414
};
15-
use json;
1615
use listings::{DirectoryListing, ListingKind};
1716
use {AnalysisLoader, Blacklist};
1817

@@ -157,16 +156,28 @@ fn read_crate_data(path: &Path) -> Option<Analysis> {
157156
s
158157
}
159158

160-
#[cfg(feature = "serialize-rustc")]
159+
#[cfg(all(feature = "serialize-rustc", not(feature = "serialize-serde")))]
161160
fn decode_buf(buf: &str) -> Result<Option<Analysis>, rustc_serialize::json::DecoderError> {
162161
::rustc_serialize::json::decode(buf)
163162
}
164163

165-
#[cfg(feature = "serialize-serde")]
164+
#[cfg(all(feature = "serialize-serde", not(feature = "serialize-rustc")))]
166165
fn decode_buf(buf: &str) -> Result<Option<Analysis>, serde_json::Error> {
167166
::serde_json::from_str(buf)
168167
}
169168

169+
#[cfg(all(feature = "serialize-rustc", feature = "serialize-serde"))]
170+
fn decode_buf(buf: &str) -> Result<Option<Analysis>, Box<dyn std::error::Error>> {
171+
compile_error!("Features \"serialize-serde\" and \"serialize-rustc\" cannot both be enabled for this crate.")
172+
}
173+
174+
#[cfg(not(any(feature = "serialize-serde", feature = "serialize-rustc")))]
175+
fn decode_buf(buf: &str) -> Result<Option<Analysis>, Box<dyn std::error::Error>> {
176+
compile_error!(
177+
"Either feature \"serialize-serde\" or \"serialize-rustc\" must be enabled for this crate."
178+
)
179+
}
180+
170181
pub fn name_space_for_def_kind(dk: DefKind) -> char {
171182
match dk {
172183
DefKind::Enum

0 commit comments

Comments
 (0)