Merge pull request #527 from taiki-e/in_band_lifetimes

Remove usage of in_band_lifetimes feature
This commit is contained in:
Jonathan Turner 2019-08-30 05:10:23 +12:00 committed by GitHub
commit ebce7231a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 49 additions and 50 deletions

View File

@ -30,7 +30,7 @@ pub enum MaybeOwned<'a, T> {
Borrowed(&'a T), Borrowed(&'a T),
} }
impl<T> MaybeOwned<'a, T> { impl<T> MaybeOwned<'_, T> {
pub fn borrow(&self) -> &T { pub fn borrow(&self) -> &T {
match self { match self {
MaybeOwned::Owned(v) => v, MaybeOwned::Owned(v) => v,

View File

@ -9,7 +9,7 @@ pub struct GenericView<'value> {
value: &'value Value, value: &'value Value,
} }
impl RenderView for GenericView<'value> { impl RenderView for GenericView<'_> {
fn render_view(&self, host: &mut dyn Host) -> Result<(), ShellError> { fn render_view(&self, host: &mut dyn Host) -> Result<(), ShellError> {
match self.value { match self.value {
Value::Primitive(p) => Ok(host.stdout(&p.format(None))), Value::Primitive(p) => Ok(host.stdout(&p.format(None))),

View File

@ -1,5 +1,4 @@
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(in_band_lifetimes)]
#![feature(generators)] #![feature(generators)]
#![feature(specialization)] #![feature(specialization)]
#![feature(proc_macro_hygiene)] #![feature(proc_macro_hygiene)]

View File

@ -176,7 +176,7 @@ pub enum Value {
Block(Block), Block(Block),
} }
pub fn debug_list(values: &'a Vec<Tagged<Value>>) -> ValuesDebug<'a> { pub fn debug_list(values: &Vec<Tagged<Value>>) -> ValuesDebug<'_> {
ValuesDebug { values } ValuesDebug { values }
} }
@ -184,7 +184,7 @@ pub struct ValuesDebug<'a> {
values: &'a Vec<Tagged<Value>>, values: &'a Vec<Tagged<Value>>,
} }
impl fmt::Debug for ValuesDebug<'a> { impl fmt::Debug for ValuesDebug<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list() f.debug_list()
.entries(self.values.iter().map(|i| i.debug())) .entries(self.values.iter().map(|i| i.debug()))
@ -196,7 +196,7 @@ pub struct ValueDebug<'a> {
value: &'a Tagged<Value>, value: &'a Tagged<Value>,
} }
impl fmt::Debug for ValueDebug<'a> { impl fmt::Debug for ValueDebug<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.value.item() { match self.value.item() {
Value::Primitive(p) => p.debug(f), Value::Primitive(p) => p.debug(f),
@ -215,10 +215,10 @@ impl Tagged<Value> {
} }
} }
impl std::convert::TryFrom<&'a Tagged<Value>> for Block { impl std::convert::TryFrom<&Tagged<Value>> for Block {
type Error = ShellError; type Error = ShellError;
fn try_from(value: &'a Tagged<Value>) -> Result<Block, ShellError> { fn try_from(value: &Tagged<Value>) -> Result<Block, ShellError> {
match value.item() { match value.item() {
Value::Block(block) => Ok(block.clone()), Value::Block(block) => Ok(block.clone()),
v => Err(ShellError::type_error( v => Err(ShellError::type_error(
@ -229,10 +229,10 @@ impl std::convert::TryFrom<&'a Tagged<Value>> for Block {
} }
} }
impl std::convert::TryFrom<&'a Tagged<Value>> for i64 { impl std::convert::TryFrom<&Tagged<Value>> for i64 {
type Error = ShellError; type Error = ShellError;
fn try_from(value: &'a Tagged<Value>) -> Result<i64, ShellError> { fn try_from(value: &Tagged<Value>) -> Result<i64, ShellError> {
match value.item() { match value.item() {
Value::Primitive(Primitive::Int(int)) => Ok(*int), Value::Primitive(Primitive::Int(int)) => Ok(*int),
v => Err(ShellError::type_error( v => Err(ShellError::type_error(
@ -243,10 +243,10 @@ impl std::convert::TryFrom<&'a Tagged<Value>> for i64 {
} }
} }
impl std::convert::TryFrom<&'a Tagged<Value>> for String { impl std::convert::TryFrom<&Tagged<Value>> for String {
type Error = ShellError; type Error = ShellError;
fn try_from(value: &'a Tagged<Value>) -> Result<String, ShellError> { fn try_from(value: &Tagged<Value>) -> Result<String, ShellError> {
match value.item() { match value.item() {
Value::Primitive(Primitive::String(s)) => Ok(s.clone()), Value::Primitive(Primitive::String(s)) => Ok(s.clone()),
v => Err(ShellError::type_error( v => Err(ShellError::type_error(
@ -257,10 +257,10 @@ impl std::convert::TryFrom<&'a Tagged<Value>> for String {
} }
} }
impl std::convert::TryFrom<&'a Tagged<Value>> for Vec<u8> { impl std::convert::TryFrom<&Tagged<Value>> for Vec<u8> {
type Error = ShellError; type Error = ShellError;
fn try_from(value: &'a Tagged<Value>) -> Result<Vec<u8>, ShellError> { fn try_from(value: &Tagged<Value>) -> Result<Vec<u8>, ShellError> {
match value.item() { match value.item() {
Value::Binary(b) => Ok(b.clone()), Value::Binary(b) => Ok(b.clone()),
v => Err(ShellError::type_error( v => Err(ShellError::type_error(
@ -271,7 +271,7 @@ impl std::convert::TryFrom<&'a Tagged<Value>> for Vec<u8> {
} }
} }
impl std::convert::TryFrom<&'a Tagged<Value>> for &'a crate::object::Dictionary { impl<'a> std::convert::TryFrom<&'a Tagged<Value>> for &'a crate::object::Dictionary {
type Error = ShellError; type Error = ShellError;
fn try_from(value: &'a Tagged<Value>) -> Result<&'a crate::object::Dictionary, ShellError> { fn try_from(value: &'a Tagged<Value>) -> Result<&'a crate::object::Dictionary, ShellError> {
@ -301,10 +301,10 @@ impl Switch {
} }
} }
impl std::convert::TryFrom<Option<&'a Tagged<Value>>> for Switch { impl std::convert::TryFrom<Option<&Tagged<Value>>> for Switch {
type Error = ShellError; type Error = ShellError;
fn try_from(value: Option<&'a Tagged<Value>>) -> Result<Switch, ShellError> { fn try_from(value: Option<&Tagged<Value>>) -> Result<Switch, ShellError> {
match value { match value {
None => Ok(Switch::Absent), None => Ok(Switch::Absent),
Some(value) => match value.item() { Some(value) => match value.item() {
@ -319,7 +319,7 @@ impl std::convert::TryFrom<Option<&'a Tagged<Value>>> for Switch {
} }
impl Tagged<Value> { impl Tagged<Value> {
pub(crate) fn debug(&'a self) -> ValueDebug<'a> { pub(crate) fn debug(&self) -> ValueDebug<'_> {
ValueDebug { value: self } ValueDebug { value: self }
} }
} }
@ -351,7 +351,7 @@ impl Value {
} }
} }
pub(crate) fn get_data_by_key(&'a self, name: &str) -> Option<&Tagged<Value>> { pub(crate) fn get_data_by_key(&self, name: &str) -> Option<&Tagged<Value>> {
match self { match self {
Value::Object(o) => o.get_data_by_key(name), Value::Object(o) => o.get_data_by_key(name),
Value::List(l) => { Value::List(l) => {
@ -374,14 +374,14 @@ impl Value {
} }
#[allow(unused)] #[allow(unused)]
pub(crate) fn get_data_by_index(&'a self, idx: usize) -> Option<&Tagged<Value>> { pub(crate) fn get_data_by_index(&self, idx: usize) -> Option<&Tagged<Value>> {
match self { match self {
Value::List(l) => l.iter().nth(idx), Value::List(l) => l.iter().nth(idx),
_ => None, _ => None,
} }
} }
pub fn get_data_by_path(&'a self, tag: Tag, path: &str) -> Option<Tagged<&Value>> { pub fn get_data_by_path(&self, tag: Tag, path: &str) -> Option<Tagged<&Value>> {
let mut current = self; let mut current = self;
for p in path.split(".") { for p in path.split(".") {
match current.get_data_by_key(p) { match current.get_data_by_key(p) {
@ -394,7 +394,7 @@ impl Value {
} }
pub fn insert_data_at_path( pub fn insert_data_at_path(
&'a self, &self,
tag: Tag, tag: Tag,
path: &str, path: &str,
new_value: Value, new_value: Value,
@ -447,7 +447,7 @@ impl Value {
} }
pub fn replace_data_at_path( pub fn replace_data_at_path(
&'a self, &self,
tag: Tag, tag: Tag,
path: &str, path: &str,
replaced_value: Value, replaced_value: Value,
@ -481,7 +481,7 @@ impl Value {
None None
} }
pub fn get_data(&'a self, desc: &String) -> MaybeOwned<'a, Value> { pub fn get_data(&self, desc: &String) -> MaybeOwned<'_, Value> {
match self { match self {
p @ Value::Primitive(_) => MaybeOwned::Borrowed(p), p @ Value::Primitive(_) => MaybeOwned::Borrowed(p),
Value::Object(o) => o.get_data(desc), Value::Object(o) => o.get_data(desc),

View File

@ -72,7 +72,7 @@ impl PartialEq<Value> for Dictionary {
} }
impl Dictionary { impl Dictionary {
pub fn get_data(&'a self, desc: &String) -> MaybeOwned<'a, Value> { pub fn get_data(&self, desc: &String) -> MaybeOwned<'_, Value> {
match self.entries.get(desc) { match self.entries.get(desc) {
Some(v) => MaybeOwned::Borrowed(v), Some(v) => MaybeOwned::Borrowed(v),
None => MaybeOwned::Owned(Value::Primitive(Primitive::Nothing)), None => MaybeOwned::Owned(Value::Primitive(Primitive::Nothing)),

View File

@ -256,7 +256,7 @@ impl Span {
self.start == 0 && self.end == 0 self.start == 0 && self.end == 0
} }
pub fn slice(&self, source: &'a str) -> &'a str { pub fn slice<'a>(&self, source: &'a str) -> &'a str {
&source[self.start..self.end] &source[self.start..self.end]
} }
} }

View File

@ -100,7 +100,7 @@ impl ExtractType for Value {
} }
impl ExtractType for bool { impl ExtractType for bool {
fn extract(value: &'a Tagged<Value>) -> Result<bool, ShellError> { fn extract(value: &Tagged<Value>) -> Result<bool, ShellError> {
trace!("Extracting {:?} for bool", value); trace!("Extracting {:?} for bool", value);
match &value { match &value {
@ -118,7 +118,7 @@ impl ExtractType for bool {
} }
impl ExtractType for std::path::PathBuf { impl ExtractType for std::path::PathBuf {
fn extract(value: &'a Tagged<Value>) -> Result<std::path::PathBuf, ShellError> { fn extract(value: &Tagged<Value>) -> Result<std::path::PathBuf, ShellError> {
trace!("Extracting {:?} for PathBuf", value); trace!("Extracting {:?} for PathBuf", value);
match &value { match &value {

View File

@ -16,7 +16,7 @@ pub struct ConfigDeserializer<'de> {
position: usize, position: usize,
} }
impl ConfigDeserializer<'de> { impl<'de> ConfigDeserializer<'de> {
pub fn from_call_info(call: CallInfo) -> ConfigDeserializer<'de> { pub fn from_call_info(call: CallInfo) -> ConfigDeserializer<'de> {
ConfigDeserializer { ConfigDeserializer {
call, call,

View File

@ -331,7 +331,7 @@ pub struct TokensIterator<'a> {
seen: indexmap::IndexSet<usize>, seen: indexmap::IndexSet<usize>,
} }
impl TokensIterator<'a> { impl TokensIterator<'_> {
pub fn remove(&mut self, position: usize) { pub fn remove(&mut self, position: usize) {
self.seen.insert(position); self.seen.insert(position);
} }
@ -404,7 +404,7 @@ impl TokensIterator<'a> {
} }
} }
impl Iterator for TokensIterator<'a> { impl<'a> Iterator for TokensIterator<'a> {
type Item = &'a TokenNode; type Item = &'a TokenNode;
fn next(&mut self) -> Option<&'a TokenNode> { fn next(&mut self) -> Option<&'a TokenNode> {

View File

@ -23,7 +23,7 @@ use std::str::FromStr;
pub type NomSpan<'a> = LocatedSpan<&'a str>; pub type NomSpan<'a> = LocatedSpan<&'a str>;
pub fn nom_input(s: &'a str) -> NomSpan<'a> { pub fn nom_input(s: &str) -> NomSpan<'_> {
LocatedSpan::new(s) LocatedSpan::new(s)
} }

View File

@ -213,7 +213,7 @@ impl Serialize for Text {
} }
} }
impl Deserialize<'de> for Text { impl<'de> Deserialize<'de> for Text {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,

View File

@ -27,7 +27,7 @@ pub struct DebugTokenNode<'a> {
source: &'a Text, source: &'a Text,
} }
impl fmt::Debug for DebugTokenNode<'a> { impl fmt::Debug for DebugTokenNode<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.node { match self.node {
TokenNode::Token(t) => write!(f, "{:?}", t.debug(self.source)), TokenNode::Token(t) => write!(f, "{:?}", t.debug(self.source)),
@ -115,7 +115,7 @@ impl TokenNode {
.to_string() .to_string()
} }
pub fn debug(&'a self, source: &'a Text) -> DebugTokenNode<'a> { pub fn debug<'a>(&'a self, source: &'a Text) -> DebugTokenNode<'a> {
DebugTokenNode { node: self, source } DebugTokenNode { node: self, source }
} }
@ -123,7 +123,7 @@ impl TokenNode {
self.span().slice(source).to_string() self.span().slice(source).to_string()
} }
pub fn source(&self, source: &'a Text) -> &'a str { pub fn source<'a>(&self, source: &'a Text) -> &'a str {
self.span().slice(source) self.span().slice(source)
} }

View File

@ -28,7 +28,7 @@ impl RawToken {
pub type Token = Tagged<RawToken>; pub type Token = Tagged<RawToken>;
impl Token { impl Token {
pub fn debug(&self, source: &'a Text) -> DebugToken<'a> { pub fn debug<'a>(&self, source: &'a Text) -> DebugToken<'a> {
DebugToken { DebugToken {
node: *self, node: *self,
source, source,
@ -41,7 +41,7 @@ pub struct DebugToken<'a> {
source: &'a Text, source: &'a Text,
} }
impl fmt::Debug for DebugToken<'a> { impl fmt::Debug for DebugToken<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.node.span().slice(self.source)) write!(f, "{}", self.node.span().slice(self.source))
} }

View File

@ -205,7 +205,7 @@ fn extract_switch(name: &str, tokens: &mut hir::TokensIterator<'_>, source: &Tex
fn extract_mandatory( fn extract_mandatory(
config: &Signature, config: &Signature,
name: &str, name: &str,
tokens: &mut hir::TokensIterator<'a>, tokens: &mut hir::TokensIterator<'_>,
source: &Text, source: &Text,
span: Span, span: Span,
) -> Result<(usize, Tagged<Flag>), ShellError> { ) -> Result<(usize, Tagged<Flag>), ShellError> {
@ -227,7 +227,7 @@ fn extract_mandatory(
fn extract_optional( fn extract_optional(
name: &str, name: &str,
tokens: &mut hir::TokensIterator<'a>, tokens: &mut hir::TokensIterator<'_>,
source: &Text, source: &Text,
) -> Result<(Option<(usize, Tagged<Flag>)>), ShellError> { ) -> Result<(Option<(usize, Tagged<Flag>)>), ShellError> {
let flag = tokens.extract(|t| t.as_flag(name, source)); let flag = tokens.extract(|t| t.as_flag(name, source));
@ -241,7 +241,7 @@ fn extract_optional(
} }
} }
pub fn trace_remaining(desc: &'static str, tail: hir::TokensIterator<'a>, source: &Text) { pub fn trace_remaining(desc: &'static str, tail: hir::TokensIterator<'_>, source: &Text) {
trace!( trace!(
"{} = {:?}", "{} = {:?}",
desc, desc,

View File

@ -158,7 +158,7 @@ pub struct DebugEvaluatedPositional<'a> {
positional: &'a Option<Vec<Tagged<Value>>>, positional: &'a Option<Vec<Tagged<Value>>>,
} }
impl fmt::Debug for DebugEvaluatedPositional<'a> { impl fmt::Debug for DebugEvaluatedPositional<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.positional { match &self.positional {
None => write!(f, "None"), None => write!(f, "None"),
@ -175,7 +175,7 @@ pub struct DebugEvaluatedNamed<'a> {
named: &'a Option<IndexMap<String, Tagged<Value>>>, named: &'a Option<IndexMap<String, Tagged<Value>>>,
} }
impl fmt::Debug for DebugEvaluatedNamed<'a> { impl fmt::Debug for DebugEvaluatedNamed<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.named { match &self.named {
None => write!(f, "None"), None => write!(f, "None"),
@ -191,7 +191,7 @@ pub struct DebugEvaluatedArgs<'a> {
args: &'a EvaluatedArgs, args: &'a EvaluatedArgs,
} }
impl fmt::Debug for DebugEvaluatedArgs<'a> { impl fmt::Debug for DebugEvaluatedArgs<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut s = f.debug_struct("Args"); let mut s = f.debug_struct("Args");
@ -206,7 +206,7 @@ impl fmt::Debug for DebugEvaluatedArgs<'a> {
} }
impl EvaluatedArgs { impl EvaluatedArgs {
pub fn debug(&'a self) -> DebugEvaluatedArgs<'a> { pub fn debug(&self) -> DebugEvaluatedArgs<'_> {
DebugEvaluatedArgs { args: self } DebugEvaluatedArgs { args: self }
} }
@ -248,7 +248,7 @@ impl EvaluatedArgs {
} }
} }
pub fn positional_iter(&'a self) -> PositionalIter<'a> { pub fn positional_iter(&self) -> PositionalIter<'_> {
match &self.positional { match &self.positional {
None => PositionalIter::Empty, None => PositionalIter::Empty,
Some(v) => { Some(v) => {
@ -264,7 +264,7 @@ pub enum PositionalIter<'a> {
Array(std::slice::Iter<'a, Tagged<Value>>), Array(std::slice::Iter<'a, Tagged<Value>>),
} }
impl Iterator for PositionalIter<'a> { impl<'a> Iterator for PositionalIter<'a> {
type Item = &'a Tagged<Value>; type Item = &'a Tagged<Value>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {

View File

@ -6,7 +6,7 @@ pub struct Debuggable<'a, T: ToDebug> {
source: &'a str, source: &'a str,
} }
impl<T: ToDebug> fmt::Display for Debuggable<'a, T> { impl<T: ToDebug> fmt::Display for Debuggable<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.inner.fmt_debug(f, self.source) self.inner.fmt_debug(f, self.source)
} }
@ -17,7 +17,7 @@ pub trait HasSpan {
} }
pub trait ToDebug: Sized { pub trait ToDebug: Sized {
fn debug(&'a self, source: &'a str) -> Debuggable<'a, Self> { fn debug<'a>(&'a self, source: &'a str) -> Debuggable<'a, Self> {
Debuggable { Debuggable {
inner: self, inner: self,
source, source,

View File

@ -185,7 +185,7 @@ impl FileStructure {
Ok(()) Ok(())
} }
fn build(&mut self, src: &'a Path, lvl: usize) -> Result<(), ShellError> { fn build(&mut self, src: &Path, lvl: usize) -> Result<(), ShellError> {
let source = dunce::canonicalize(src)?; let source = dunce::canonicalize(src)?;
if source.is_dir() { if source.is_dir() {