Skip to content

Commit 3e656d1

Browse files
bors[bot]Marwes
andauthored
Merge #879
879: fix: Give tuple fields a span r=Marwes a=Marwes Fixes gluon-lang/gluon_language-server#40 Co-authored-by: Markus Westerlind <[email protected]>
2 parents 8b02957 + 2a1c2c7 commit 3e656d1

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

base/src/pos.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ pub struct Spanned<T, Pos> {
319319
pub value: T,
320320
}
321321

322+
impl<T, Pos> From<(T, Span<Pos>)> for Spanned<T, Pos> {
323+
fn from((value, span): (T, Span<Pos>)) -> Self {
324+
Spanned { span, value }
325+
}
326+
}
327+
322328
impl<T, Pos> From<T> for Spanned<T, Pos>
323329
where
324330
Pos: Default,

base/src/symbol.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use std::{
99
sync::Arc,
1010
};
1111

12-
use crate::ast::{DisplayEnv, IdentEnv};
12+
use crate::{
13+
ast::{DisplayEnv, IdentEnv},
14+
pos::{BytePos, Span},
15+
};
1316

1417
// FIXME Don't have a double indirection (Arc + String)
1518
/// A symbol uniquely identifies something regardless of its name and which module it originated
@@ -161,6 +164,12 @@ impl From<String> for Symbol {
161164
}
162165
}
163166

167+
impl From<(Symbol, Span<BytePos>)> for Symbol {
168+
fn from((name, _): (Symbol, Span<BytePos>)) -> Symbol {
169+
name
170+
}
171+
}
172+
164173
impl<N> From<SymbolData<N>> for Symbol
165174
where
166175
N: Into<NameBuf>,

base/src/types/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,19 +1117,19 @@ where
11171117
pub fn tuple<S, I>(symbols: &mut S, elems: I) -> T
11181118
where
11191119
S: ?Sized + IdentEnv<Ident = Id>,
1120-
T::SpannedId: From<Id>,
1120+
T::SpannedId: From<(Id, Span<BytePos>)>,
11211121
I: IntoIterator<Item = T>,
1122-
T: From<(Type<Id, T>, Flags)>,
1122+
T: From<(Type<Id, T>, Flags)> + HasSpan,
11231123
{
11241124
T::from(Type::tuple_(symbols, elems))
11251125
}
11261126

11271127
pub fn tuple_<S, I>(symbols: &mut S, elems: I) -> Type<Id, T>
11281128
where
11291129
S: ?Sized + IdentEnv<Ident = Id>,
1130-
T::SpannedId: From<Id>,
1130+
T::SpannedId: From<(Id, Span<BytePos>)>,
11311131
I: IntoIterator<Item = T>,
1132-
T: From<(Type<Id, T>, Flags)>,
1132+
T: From<(Type<Id, T>, Flags)> + HasSpan,
11331133
{
11341134
NullInterner.tuple_(symbols, elems)
11351135
}
@@ -3583,8 +3583,9 @@ where
35833583
fn tuple<S, I>(&mut self, symbols: &mut S, elems: I) -> T
35843584
where
35853585
S: ?Sized + IdentEnv<Ident = Id>,
3586-
T::SpannedId: From<Id>,
3586+
T::SpannedId: From<(Id, Span<BytePos>)>,
35873587
I: IntoIterator<Item = T>,
3588+
T: HasSpan,
35883589
{
35893590
let t = self.tuple_(symbols, elems);
35903591
self.intern(t)
@@ -3593,12 +3594,13 @@ where
35933594
fn tuple_<S, I>(&mut self, symbols: &mut S, elems: I) -> Type<Id, T>
35943595
where
35953596
S: ?Sized + IdentEnv<Ident = Id>,
3596-
T::SpannedId: From<Id>,
3597+
T::SpannedId: From<(Id, Span<BytePos>)>,
3598+
T: HasSpan,
35973599
I: IntoIterator<Item = T>,
35983600
{
35993601
let empty_row = self.empty_row();
36003602
let elems = self.intern_fields(elems.into_iter().enumerate().map(|(i, typ)| Field {
3601-
name: symbols.from_str(&format!("_{}", i)).into(),
3603+
name: (symbols.from_str(&format!("_{}", i)), typ.span()).into(),
36023604
typ,
36033605
}));
36043606
Type::Record(self.extend_row(elems, empty_row))

0 commit comments

Comments
 (0)