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

Commit e1358ff

Browse files
committed
rls-span: Use serde exclusively and serde_derive optionally
1 parent ed1caf0 commit e1358ff

File tree

4 files changed

+2712
-87
lines changed

4 files changed

+2712
-87
lines changed

rls-span/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ license = "Apache-2.0/MIT"
77
repository = "https://github.com/rust-lang/rls"
88
categories = ["development-tools"]
99

10-
[features]
11-
default = []
12-
serialize-serde = ["serde", "serde_derive"]
13-
serialize-rustc = ["rustc-serialize"]
1410

1511
[dependencies]
16-
rustc-serialize = { version = "0.3", optional = true }
17-
serde = { version = "1.0", optional = true }
12+
serde = "1.0"
1813
serde_derive = { version = "1.0", optional = true }
14+
15+
[features]
16+
default = []
17+
derive = ["serde_derive"]

rls-span/src/compiler.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
// Copyright 2016 The RLS Project Developers.
2-
//
3-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6-
// option. This file may not be copied, modified, or distributed
7-
// except according to those terms.
8-
9-
/// These are the structures emitted by the compiler as part of JSON errors.
10-
/// The original source can be found at
11-
/// https://github.com/rust-lang/rust/blob/master/src/libsyntax/json.rs
1+
///! These are the structures emitted by the compiler as part of JSON errors.
2+
///! The original source can be found at
3+
///! https://github.com/rust-lang/rust/blob/master/src/libsyntax/json.rs
124
use std::path::PathBuf;
135

146
use {Column, OneIndexed, Row, Span};
157

16-
#[cfg_attr(feature = "serialize-serde", derive(Deserialize))]
8+
#[cfg_attr(feature = "derive", derive(Deserialize))]
179
#[derive(Debug, Clone)]
1810
pub struct DiagnosticSpan {
1911
pub file_name: String,
@@ -53,7 +45,7 @@ impl DiagnosticSpan {
5345
}
5446
}
5547

56-
#[cfg_attr(feature = "serialize-serde", derive(Deserialize))]
48+
#[cfg_attr(feature = "derive", derive(Deserialize))]
5749
#[derive(Debug, Clone)]
5850
pub struct DiagnosticSpanLine {
5951
pub text: String,
@@ -64,7 +56,7 @@ pub struct DiagnosticSpanLine {
6456
pub highlight_end: usize,
6557
}
6658

67-
#[cfg_attr(feature = "serialize-serde", derive(Deserialize))]
59+
#[cfg_attr(feature = "derive", derive(Deserialize))]
6860
#[derive(Debug, Clone)]
6961
pub struct DiagnosticSpanMacroExpansion {
7062
/// span where macro was applied to generate this code; note that

rls-span/src/lib.rs

Lines changed: 12 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
1-
// Copyright 2016 The RLS Project Developers.
2-
//
3-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6-
// option. This file may not be copied, modified, or distributed
7-
// except according to those terms.
8-
9-
#![cfg_attr(rustbuild, feature(staged_api, rustc_private))]
10-
#![cfg_attr(rustbuild, unstable(feature = "rustc_private", issue = "27812"))]
11-
12-
#[cfg(feature = "serialize-serde")]
131
extern crate serde;
14-
#[cfg(feature = "serialize-serde")]
2+
#[cfg(feature = "derive")]
153
#[macro_use]
164
extern crate serde_derive;
17-
#[cfg(feature = "serialize-rustc")]
18-
extern crate rustc_serialize;
195

20-
#[cfg(feature = "serialize-rustc")]
21-
use rustc_serialize::{Decodable, Encodable};
22-
#[cfg(feature = "serialize-serde")]
236
use serde::{Deserialize, Serialize};
247

258
use std::marker::PhantomData;
269
use std::path::PathBuf;
2710

2811
pub mod compiler;
12+
mod serde_expanded;
2913

3014
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
3115
pub struct Column<I: Indexed>(pub u32, PhantomData<I>);
@@ -44,7 +28,6 @@ impl<I: Indexed> Clone for Column<I> {
4428

4529
impl<I: Indexed> Copy for Column<I> {}
4630

47-
#[cfg(feature = "serialize-serde")]
4831
impl<I: Indexed> Serialize for Column<I> {
4932
fn serialize<S: serde::Serializer>(
5033
&self,
@@ -54,26 +37,11 @@ impl<I: Indexed> Serialize for Column<I> {
5437
}
5538
}
5639

57-
#[cfg(feature = "serialize-serde")]
5840
impl<'dt, I: Indexed> Deserialize<'dt> for Column<I> {
5941
fn deserialize<D: serde::Deserializer<'dt>>(
6042
d: D,
6143
) -> std::result::Result<Self, <D as serde::Deserializer<'dt>>::Error> {
62-
<u32 as Deserialize>::deserialize(d).map(|x| Column::new(x))
63-
}
64-
}
65-
66-
#[cfg(feature = "serialize-rustc")]
67-
impl<I: Indexed> Decodable for Column<I> {
68-
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<Column<I>, D::Error> {
69-
d.read_u32().map(|x| Column::new(x))
70-
}
71-
}
72-
73-
#[cfg(feature = "serialize-rustc")]
74-
impl<I: Indexed> Encodable for Column<I> {
75-
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
76-
s.emit_u32(self.0)
44+
<u32 as Deserialize>::deserialize(d).map(Column::new)
7745
}
7846
}
7947

@@ -114,31 +82,15 @@ impl<I: Indexed> Clone for Row<I> {
11482

11583
impl<I: Indexed> Copy for Row<I> {}
11684

117-
#[cfg(feature = "serialize-serde")]
11885
impl<I: Indexed> serde::Serialize for Row<I> {
11986
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
12087
s.serialize_u32(self.0)
12188
}
12289
}
12390

124-
#[cfg(feature = "serialize-serde")]
12591
impl<'dt, I: Indexed> serde::Deserialize<'dt> for Row<I> {
12692
fn deserialize<D: serde::Deserializer<'dt>>(d: D) -> std::result::Result<Self, D::Error> {
127-
<u32 as Deserialize>::deserialize(d).map(|x| Row::new(x))
128-
}
129-
}
130-
131-
#[cfg(feature = "serialize-rustc")]
132-
impl<I: Indexed> Decodable for Row<I> {
133-
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<Row<I>, D::Error> {
134-
d.read_u32().map(|x| Row::new(x))
135-
}
136-
}
137-
138-
#[cfg(feature = "serialize-rustc")]
139-
impl<I: Indexed> Encodable for Row<I> {
140-
fn encode<S: rustc_serialize::Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
141-
s.emit_u32(self.0)
93+
<u32 as Deserialize>::deserialize(d).map(Row::new)
14294
}
14395
}
14496

@@ -162,8 +114,7 @@ impl Row<ZeroIndexed> {
162114
}
163115
}
164116

165-
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
166-
#[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
117+
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
167118
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
168119
pub struct Position<I: Indexed> {
169120
pub row: Row<I>,
@@ -196,8 +147,7 @@ impl Position<ZeroIndexed> {
196147
}
197148
}
198149

199-
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
200-
#[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
150+
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
201151
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
202152
pub struct Range<I: Indexed> {
203153
pub row_start: Row<I>,
@@ -259,8 +209,7 @@ impl Range<ZeroIndexed> {
259209
}
260210
}
261211

262-
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
263-
#[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
212+
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
264213
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
265214
pub struct Location<I: Indexed> {
266215
pub file: PathBuf,
@@ -295,8 +244,7 @@ impl Location<ZeroIndexed> {
295244
}
296245
}
297246

298-
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
299-
#[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
247+
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
300248
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
301249
pub struct Span<I: Indexed> {
302250
pub file: PathBuf,
@@ -345,17 +293,14 @@ impl Span<ZeroIndexed> {
345293
}
346294
}
347295

348-
#[cfg(feature = "serialize-serde")]
349296
pub trait Indexed {}
350-
#[cfg(not(feature = "serialize-serde"))]
351-
pub trait Indexed {}
352-
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
353-
#[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
297+
298+
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
354299
#[derive(Hash, PartialEq, Eq, Debug, PartialOrd, Ord)]
355300
pub struct ZeroIndexed;
356301
impl Indexed for ZeroIndexed {}
357-
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
358-
#[cfg_attr(feature = "serialize-serde", derive(Serialize, Deserialize))]
302+
303+
#[cfg_attr(feature = "derive", derive(Serialize, Deserialize))]
359304
#[derive(Hash, PartialEq, Eq, Debug, PartialOrd, Ord)]
360305
pub struct OneIndexed;
361306
impl Indexed for OneIndexed {}

0 commit comments

Comments
 (0)