Skip to content

Commit 15b58fe

Browse files
committed
Fallout in libsyntax/librustc: use newtype'd options for linked lists,
since `Option` is not fundamental and hence the old impls run afoul of the orphan rules.
1 parent 30b2d9e commit 15b58fe

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/librustc/metadata/encoder.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ use std::io::prelude::*;
3434
use std::io::{Cursor, SeekFrom};
3535
use syntax::abi;
3636
use syntax::ast::{self, DefId, NodeId};
37-
use syntax::ast_map::{PathElem, PathElems};
38-
use syntax::ast_map;
37+
use syntax::ast_map::{self, LinkedPath, PathElem, PathElems};
3938
use syntax::ast_util::*;
4039
use syntax::ast_util;
4140
use syntax::attr;
@@ -1513,7 +1512,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
15131512
&krate.module,
15141513
&[],
15151514
ast::CRATE_NODE_ID,
1516-
[].iter().cloned().chain(None),
1515+
[].iter().cloned().chain(LinkedPath::empty()),
15171516
syntax::parse::token::special_idents::invalid,
15181517
ast::Public);
15191518

@@ -1874,7 +1873,7 @@ fn encode_misc_info(ecx: &EncodeContext,
18741873
}
18751874

18761875
// Encode reexports for the root module.
1877-
encode_reexports(ecx, rbml_w, 0, [].iter().cloned().chain(None));
1876+
encode_reexports(ecx, rbml_w, 0, [].iter().cloned().chain(LinkedPath::empty()));
18781877

18791878
rbml_w.end_tag();
18801879
rbml_w.end_tag();

src/libsyntax/ast_map/mod.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,29 @@ impl fmt::Display for PathElem {
5353
}
5454

5555
#[derive(Clone)]
56-
struct LinkedPathNode<'a> {
56+
pub struct LinkedPathNode<'a> {
5757
node: PathElem,
5858
next: LinkedPath<'a>,
5959
}
6060

61-
type LinkedPath<'a> = Option<&'a LinkedPathNode<'a>>;
61+
#[derive(Copy, Clone)]
62+
pub struct LinkedPath<'a>(Option<&'a LinkedPathNode<'a>>);
63+
64+
impl<'a> LinkedPath<'a> {
65+
pub fn empty() -> LinkedPath<'a> {
66+
LinkedPath(None)
67+
}
68+
69+
pub fn from(node: &'a LinkedPathNode) -> LinkedPath<'a> {
70+
LinkedPath(Some(node))
71+
}
72+
}
6273

6374
impl<'a> Iterator for LinkedPath<'a> {
6475
type Item = PathElem;
6576

6677
fn next(&mut self) -> Option<PathElem> {
67-
match *self {
78+
match self.0 {
6879
Some(node) => {
6980
*self = node.next;
7081
Some(node.node)
@@ -384,7 +395,7 @@ impl<'ast> Map<'ast> {
384395
pub fn with_path<T, F>(&self, id: NodeId, f: F) -> T where
385396
F: FnOnce(PathElems) -> T,
386397
{
387-
self.with_path_next(id, None, f)
398+
self.with_path_next(id, LinkedPath::empty(), f)
388399
}
389400

390401
pub fn path_to_string(&self, id: NodeId) -> String {
@@ -422,7 +433,7 @@ impl<'ast> Map<'ast> {
422433
_ => f([].iter().cloned().chain(next))
423434
}
424435
} else {
425-
self.with_path_next(parent, Some(&LinkedPathNode {
436+
self.with_path_next(parent, LinkedPath::from(&LinkedPathNode {
426437
node: self.get_path_elem(id),
427438
next: next
428439
}), f)

0 commit comments

Comments
 (0)