From 9f4daf4474c0066c2c1dd3fa962f3ffc47ca8d4d Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 25 Sep 2017 19:31:46 -0700 Subject: [PATCH] Update codegen for 2017-09-25 nightly. --- codegen/build.rs | 4 ++-- codegen/src/lib.rs | 2 -- codegen/src/parser/param.rs | 10 ++++------ codegen/src/utils/span_ext.rs | 27 +++++++++++---------------- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/codegen/build.rs b/codegen/build.rs index cd097465..de393f85 100644 --- a/codegen/build.rs +++ b/codegen/build.rs @@ -8,8 +8,8 @@ use yansi::Color::{Red, Yellow, Blue, White}; use version_check::{supports_features, is_min_version, is_min_date}; // Specifies the minimum nightly version needed to compile Rocket's codegen. -const MIN_DATE: &'static str = "2017-08-10"; -const MIN_VERSION: &'static str = "1.21.0-nightly"; +const MIN_DATE: &'static str = "2017-09-25"; +const MIN_VERSION: &'static str = "1.22.0-nightly"; fn main() { let ok_channel = supports_features(); diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index d4d0a247..a638dbd3 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -144,10 +144,8 @@ #![allow(deprecated)] #[macro_use] extern crate log; -extern crate rustc; extern crate syntax; extern crate syntax_ext; -extern crate syntax_pos; extern crate rustc_plugin; extern crate rocket; diff --git a/codegen/src/parser/param.rs b/codegen/src/parser/param.rs index 4d0d3449..059d8128 100644 --- a/codegen/src/parser/param.rs +++ b/codegen/src/parser/param.rs @@ -1,8 +1,8 @@ use syntax::ast::Ident; use syntax::ext::base::ExtCtxt; -use syntax::codemap::{Span, Spanned, BytePos}; +use syntax::codemap::{Span, Spanned}; -use utils::span; +use utils::{span, SpanExt}; #[derive(Debug)] pub enum Param { @@ -67,13 +67,11 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> { (false, full_param) }; - let mut param_span = self.span; - param_span.lo = self.span.lo + BytePos(start as u32); - param_span.hi = self.span.lo + BytePos((end + 1) as u32); + let param_span = self.span.trim_left(start).shorten_to(end + 1); // Advance the string and span. self.string = &self.string[(end + 1)..]; - self.span.lo = self.span.lo + BytePos((end + 1) as u32); + self.span = self.span.trim_left(end + 1); let spanned_ident = span(Ident::from_str(param), param_span); if is_many { diff --git a/codegen/src/utils/span_ext.rs b/codegen/src/utils/span_ext.rs index 932e69ba..41f17ce4 100644 --- a/codegen/src/utils/span_ext.rs +++ b/codegen/src/utils/span_ext.rs @@ -18,29 +18,24 @@ pub trait SpanExt { } impl SpanExt for Span { - fn trim_left(mut self, length: usize) -> Span { - self.lo = self.lo + BytePos(length as u32); - self + fn trim_left(self, length: usize) -> Span { + self.with_lo(self.lo() + BytePos(length as u32)) } - fn trim_right(mut self, length: usize) -> Span { - self.hi = self.hi - BytePos(length as u32); - self + fn trim_right(self, length: usize) -> Span { + self.with_hi(self.hi() - BytePos(length as u32)) } - fn shorten_to(mut self, to_length: usize) -> Span { - self.hi = self.lo + BytePos(to_length as u32); - self + fn shorten_to(self, to_length: usize) -> Span { + self.with_hi(self.lo() + BytePos(to_length as u32)) } - fn shorten_upto(mut self, length: usize) -> Span { - self.lo = self.hi - BytePos(length as u32); - self + fn shorten_upto(self, length: usize) -> Span { + self.with_lo(self.hi() - BytePos(length as u32)) } - fn trim(mut self, length: u32) -> Span { - self.lo = self.lo + BytePos(length); - self.hi = self.hi - BytePos(length); - self + fn trim(self, length: u32) -> Span { + self.with_lo(self.lo() + BytePos(length)) + .with_hi(self.hi() - BytePos(length)) } }