Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
nikomatsakis committed Apr 1, 2015
commit 15b58fedcacba7d10a9f7d460a83da645a09ad3e
7 changes: 3 additions & 4 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ use std::io::prelude::*;
use std::io::{Cursor, SeekFrom};
use syntax::abi;
use syntax::ast::{self, DefId, NodeId};
use syntax::ast_map::{PathElem, PathElems};
use syntax::ast_map;
use syntax::ast_map::{self, LinkedPath, PathElem, PathElems};
use syntax::ast_util::*;
use syntax::ast_util;
use syntax::attr;
Expand Down Expand Up @@ -1513,7 +1512,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
&krate.module,
&[],
ast::CRATE_NODE_ID,
[].iter().cloned().chain(None),
[].iter().cloned().chain(LinkedPath::empty()),
syntax::parse::token::special_idents::invalid,
ast::Public);

Expand Down Expand Up @@ -1874,7 +1873,7 @@ fn encode_misc_info(ecx: &EncodeContext,
}

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

rbml_w.end_tag();
rbml_w.end_tag();
Expand Down
21 changes: 16 additions & 5 deletions src/libsyntax/ast_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,29 @@ impl fmt::Display for PathElem {
}

#[derive(Clone)]
struct LinkedPathNode<'a> {
pub struct LinkedPathNode<'a> {
node: PathElem,
next: LinkedPath<'a>,
}

type LinkedPath<'a> = Option<&'a LinkedPathNode<'a>>;
#[derive(Copy, Clone)]
pub struct LinkedPath<'a>(Option<&'a LinkedPathNode<'a>>);

impl<'a> LinkedPath<'a> {
pub fn empty() -> LinkedPath<'a> {
LinkedPath(None)
}

pub fn from(node: &'a LinkedPathNode) -> LinkedPath<'a> {
LinkedPath(Some(node))
}
}

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

fn next(&mut self) -> Option<PathElem> {
match *self {
match self.0 {
Some(node) => {
*self = node.next;
Some(node.node)
Expand Down Expand Up @@ -384,7 +395,7 @@ impl<'ast> Map<'ast> {
pub fn with_path<T, F>(&self, id: NodeId, f: F) -> T where
F: FnOnce(PathElems) -> T,
{
self.with_path_next(id, None, f)
self.with_path_next(id, LinkedPath::empty(), f)
}

pub fn path_to_string(&self, id: NodeId) -> String {
Expand Down Expand Up @@ -422,7 +433,7 @@ impl<'ast> Map<'ast> {
_ => f([].iter().cloned().chain(next))
}
} else {
self.with_path_next(parent, Some(&LinkedPathNode {
self.with_path_next(parent, LinkedPath::from(&LinkedPathNode {
node: self.get_path_elem(id),
next: next
}), f)
Expand Down