libsyntax_pos => 2018

This commit is contained in:
Taiki Endo 2019-02-04 03:42:27 +09:00
parent fc6e9a2845
commit 6413480adf
7 changed files with 51 additions and 60 deletions

View file

@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"] authors = ["The Rust Project Developers"]
name = "syntax_pos" name = "syntax_pos"
version = "0.0.0" version = "0.0.0"
edition = "2018"
[lib] [lib]
name = "syntax_pos" name = "syntax_pos"

View file

@ -36,7 +36,7 @@ pub fn analyze_source_file(
(lines, multi_byte_chars, non_narrow_chars) (lines, multi_byte_chars, non_narrow_chars)
} }
cfg_if! { cfg_if::cfg_if! {
if #[cfg(all(any(target_arch = "x86", target_arch = "x86_64")))] { if #[cfg(all(any(target_arch = "x86", target_arch = "x86_64")))] {
fn analyze_source_file_dispatch(src: &str, fn analyze_source_file_dispatch(src: &str,
source_file_start_pos: BytePos, source_file_start_pos: BytePos,

View file

@ -27,7 +27,7 @@ pub const EDITION_NAME_LIST: &str = "2015|2018";
pub const DEFAULT_EDITION: Edition = Edition::Edition2015; pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
impl fmt::Display for Edition { impl fmt::Display for Edition {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match *self { let s = match *self {
Edition::Edition2015 => "2015", Edition::Edition2015 => "2015",
Edition::Edition2018 => "2018", Edition::Edition2018 => "2018",

View file

@ -5,10 +5,10 @@
//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216. //! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
//! DOI=10.1017/S0956796812000093 <https://doi.org/10.1017/S0956796812000093> //! DOI=10.1017/S0956796812000093 <https://doi.org/10.1017/S0956796812000093>
use GLOBALS; use crate::GLOBALS;
use Span; use crate::Span;
use edition::{Edition, DEFAULT_EDITION}; use crate::edition::{Edition, DEFAULT_EDITION};
use symbol::{keywords, Symbol}; use crate::symbol::{keywords, Symbol};
use serialize::{Encodable, Decodable, Encoder, Decoder}; use serialize::{Encodable, Decodable, Encoder, Decoder};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@ -525,7 +525,7 @@ impl SyntaxContext {
} }
impl fmt::Debug for SyntaxContext { impl fmt::Debug for SyntaxContext {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "#{}", self.0) write!(f, "#{}", self.0)
} }
} }

View file

@ -8,10 +8,11 @@
html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")] html_root_url = "https://doc.rust-lang.org/nightly/")]
#![deny(rust_2018_idioms)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(custom_attribute)] #![feature(custom_attribute)]
#![feature(nll)]
#![feature(non_exhaustive)] #![feature(non_exhaustive)]
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
@ -19,23 +20,11 @@
#![feature(step_trait)] #![feature(step_trait)]
#![cfg_attr(not(stage0), feature(stdsimd))] #![cfg_attr(not(stage0), feature(stdsimd))]
extern crate arena;
#[macro_use]
extern crate rustc_data_structures;
#[macro_use]
extern crate scoped_tls;
use serialize::{Encodable, Decodable, Encoder, Decoder}; use serialize::{Encodable, Decodable, Encoder, Decoder};
extern crate serialize; #[allow(unused_extern_crates)]
extern crate serialize as rustc_serialize; // used by deriving extern crate serialize as rustc_serialize; // used by deriving
#[macro_use]
extern crate cfg_if;
extern crate unicode_width;
pub mod edition; pub mod edition;
pub mod hygiene; pub mod hygiene;
pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, CompilerDesugaringKind}; pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, CompilerDesugaringKind};
@ -74,7 +63,7 @@ impl Globals {
} }
} }
scoped_thread_local!(pub static GLOBALS: Globals); scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
/// Differentiates between real files and common virtual files. /// Differentiates between real files and common virtual files.
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)] #[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)]
@ -100,8 +89,8 @@ pub enum FileName {
} }
impl std::fmt::Display for FileName { impl std::fmt::Display for FileName {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use self::FileName::*; use FileName::*;
match *self { match *self {
Real(ref path) => write!(fmt, "{}", path.display()), Real(ref path) => write!(fmt, "{}", path.display()),
Macros(ref name) => write!(fmt, "<{} macros>", name), Macros(ref name) => write!(fmt, "<{} macros>", name),
@ -127,7 +116,7 @@ impl From<PathBuf> for FileName {
impl FileName { impl FileName {
pub fn is_real(&self) -> bool { pub fn is_real(&self) -> bool {
use self::FileName::*; use FileName::*;
match *self { match *self {
Real(_) => true, Real(_) => true,
Macros(_) | Macros(_) |
@ -143,7 +132,7 @@ impl FileName {
} }
pub fn is_macros(&self) -> bool { pub fn is_macros(&self) -> bool {
use self::FileName::*; use FileName::*;
match *self { match *self {
Real(_) | Real(_) |
Anon(_) | Anon(_) |
@ -611,7 +600,7 @@ impl serialize::UseSpecializedDecodable for Span {
} }
} }
pub fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result { pub fn default_span_debug(span: Span, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Span") f.debug_struct("Span")
.field("lo", &span.lo()) .field("lo", &span.lo())
.field("hi", &span.hi()) .field("hi", &span.hi())
@ -620,13 +609,13 @@ pub fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result {
} }
impl fmt::Debug for Span { impl fmt::Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
SPAN_DEBUG.with(|span_debug| span_debug.get()(*self, f)) SPAN_DEBUG.with(|span_debug| span_debug.get()(*self, f))
} }
} }
impl fmt::Debug for SpanData { impl fmt::Debug for SpanData {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
SPAN_DEBUG.with(|span_debug| span_debug.get()(Span::new(self.lo, self.hi, self.ctxt), f)) SPAN_DEBUG.with(|span_debug| span_debug.get()(Span::new(self.lo, self.hi, self.ctxt), f))
} }
} }
@ -1009,7 +998,7 @@ impl Decodable for SourceFile {
// `crate_of_origin` has to be set by the importer. // `crate_of_origin` has to be set by the importer.
// This value matches up with rustc::hir::def_id::INVALID_CRATE. // This value matches up with rustc::hir::def_id::INVALID_CRATE.
// That constant is not available here unfortunately :( // That constant is not available here unfortunately :(
crate_of_origin: ::std::u32::MAX - 1, crate_of_origin: std::u32::MAX - 1,
start_pos, start_pos,
end_pos, end_pos,
src: None, src: None,
@ -1025,7 +1014,7 @@ impl Decodable for SourceFile {
} }
impl fmt::Debug for SourceFile { impl fmt::Debug for SourceFile {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "SourceFile({})", self.name) write!(fmt, "SourceFile({})", self.name)
} }
} }
@ -1111,7 +1100,7 @@ impl SourceFile {
/// Get a line from the list of pre-computed line-beginnings. /// Get a line from the list of pre-computed line-beginnings.
/// The line number here is 0-based. /// The line number here is 0-based.
pub fn get_line(&self, line_number: usize) -> Option<Cow<str>> { pub fn get_line(&self, line_number: usize) -> Option<Cow<'_, str>> {
fn get_until_newline(src: &str, begin: usize) -> &str { fn get_until_newline(src: &str, begin: usize) -> &str {
// We can't use `lines.get(line_number+1)` because we might // We can't use `lines.get(line_number+1)` because we might
// be parsing when we call this function and thus the current // be parsing when we call this function and thus the current
@ -1353,7 +1342,7 @@ pub struct FileLines {
pub lines: Vec<LineInfo> pub lines: Vec<LineInfo>
} }
thread_local!(pub static SPAN_DEBUG: Cell<fn(Span, &mut fmt::Formatter) -> fmt::Result> = thread_local!(pub static SPAN_DEBUG: Cell<fn(Span, &mut fmt::Formatter<'_>) -> fmt::Result> =
Cell::new(default_span_debug)); Cell::new(default_span_debug));
#[derive(Debug)] #[derive(Debug)]

View file

@ -4,9 +4,9 @@
// The encoding format for inline spans were obtained by optimizing over crates in rustc/libstd. // The encoding format for inline spans were obtained by optimizing over crates in rustc/libstd.
// See https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/28 // See https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/28
use GLOBALS; use crate::GLOBALS;
use {BytePos, SpanData}; use crate::{BytePos, SpanData};
use hygiene::SyntaxContext; use crate::hygiene::SyntaxContext;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};

View file

@ -5,6 +5,7 @@
use arena::DroplessArena; use arena::DroplessArena;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::newtype_index;
use serialize::{Decodable, Decoder, Encodable, Encoder}; use serialize::{Decodable, Decoder, Encodable, Encoder};
use std::fmt; use std::fmt;
@ -12,8 +13,8 @@ use std::str;
use std::cmp::{PartialEq, Ordering, PartialOrd, Ord}; use std::cmp::{PartialEq, Ordering, PartialOrd, Ord};
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use hygiene::SyntaxContext; use crate::hygiene::SyntaxContext;
use {Span, DUMMY_SP, GLOBALS}; use crate::{Span, DUMMY_SP, GLOBALS};
#[derive(Copy, Clone, Eq)] #[derive(Copy, Clone, Eq)]
pub struct Ident { pub struct Ident {
@ -100,13 +101,13 @@ impl Hash for Ident {
} }
impl fmt::Debug for Ident { impl fmt::Debug for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}{:?}", self.name, self.span.ctxt()) write!(f, "{}{:?}", self.name, self.span.ctxt())
} }
} }
impl fmt::Display for Ident { impl fmt::Display for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.name, f) fmt::Display::fmt(&self.name, f)
} }
} }
@ -181,7 +182,7 @@ impl Symbol {
pub fn as_str(self) -> LocalInternedString { pub fn as_str(self) -> LocalInternedString {
with_interner(|interner| unsafe { with_interner(|interner| unsafe {
LocalInternedString { LocalInternedString {
string: ::std::mem::transmute::<&str, &str>(interner.get(self)) string: std::mem::transmute::<&str, &str>(interner.get(self))
} }
}) })
} }
@ -198,7 +199,7 @@ impl Symbol {
} }
impl fmt::Debug for Symbol { impl fmt::Debug for Symbol {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let is_gensymed = with_interner(|interner| interner.is_gensymed(*self)); let is_gensymed = with_interner(|interner| interner.is_gensymed(*self));
if is_gensymed { if is_gensymed {
write!(f, "{}({:?})", self, self.0) write!(f, "{}({:?})", self, self.0)
@ -209,7 +210,7 @@ impl fmt::Debug for Symbol {
} }
impl fmt::Display for Symbol { impl fmt::Display for Symbol {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.as_str(), f) fmt::Display::fmt(&self.as_str(), f)
} }
} }
@ -226,7 +227,7 @@ impl Decodable for Symbol {
} }
} }
impl<T: ::std::ops::Deref<Target=str>> PartialEq<T> for Symbol { impl<T: std::ops::Deref<Target=str>> PartialEq<T> for Symbol {
fn eq(&self, other: &T) -> bool { fn eq(&self, other: &T) -> bool {
self.as_str() == other.deref() self.as_str() == other.deref()
} }
@ -335,7 +336,7 @@ macro_rules! declare_keywords {(
}; };
)* )*
impl ::std::str::FromStr for Keyword { impl std::str::FromStr for Keyword {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, ()> { fn from_str(s: &str) -> Result<Self, ()> {
@ -519,40 +520,40 @@ impl LocalInternedString {
} }
} }
impl<U: ?Sized> ::std::convert::AsRef<U> for LocalInternedString impl<U: ?Sized> std::convert::AsRef<U> for LocalInternedString
where where
str: ::std::convert::AsRef<U> str: std::convert::AsRef<U>
{ {
fn as_ref(&self) -> &U { fn as_ref(&self) -> &U {
self.string.as_ref() self.string.as_ref()
} }
} }
impl<T: ::std::ops::Deref<Target = str>> ::std::cmp::PartialEq<T> for LocalInternedString { impl<T: std::ops::Deref<Target = str>> std::cmp::PartialEq<T> for LocalInternedString {
fn eq(&self, other: &T) -> bool { fn eq(&self, other: &T) -> bool {
self.string == other.deref() self.string == other.deref()
} }
} }
impl ::std::cmp::PartialEq<LocalInternedString> for str { impl std::cmp::PartialEq<LocalInternedString> for str {
fn eq(&self, other: &LocalInternedString) -> bool { fn eq(&self, other: &LocalInternedString) -> bool {
self == other.string self == other.string
} }
} }
impl<'a> ::std::cmp::PartialEq<LocalInternedString> for &'a str { impl<'a> std::cmp::PartialEq<LocalInternedString> for &'a str {
fn eq(&self, other: &LocalInternedString) -> bool { fn eq(&self, other: &LocalInternedString) -> bool {
*self == other.string *self == other.string
} }
} }
impl ::std::cmp::PartialEq<LocalInternedString> for String { impl std::cmp::PartialEq<LocalInternedString> for String {
fn eq(&self, other: &LocalInternedString) -> bool { fn eq(&self, other: &LocalInternedString) -> bool {
self == other.string self == other.string
} }
} }
impl<'a> ::std::cmp::PartialEq<LocalInternedString> for &'a String { impl<'a> std::cmp::PartialEq<LocalInternedString> for &'a String {
fn eq(&self, other: &LocalInternedString) -> bool { fn eq(&self, other: &LocalInternedString) -> bool {
*self == other.string *self == other.string
} }
@ -561,19 +562,19 @@ impl<'a> ::std::cmp::PartialEq<LocalInternedString> for &'a String {
impl !Send for LocalInternedString {} impl !Send for LocalInternedString {}
impl !Sync for LocalInternedString {} impl !Sync for LocalInternedString {}
impl ::std::ops::Deref for LocalInternedString { impl std::ops::Deref for LocalInternedString {
type Target = str; type Target = str;
fn deref(&self) -> &str { self.string } fn deref(&self) -> &str { self.string }
} }
impl fmt::Debug for LocalInternedString { impl fmt::Debug for LocalInternedString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(self.string, f) fmt::Debug::fmt(self.string, f)
} }
} }
impl fmt::Display for LocalInternedString { impl fmt::Display for LocalInternedString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self.string, f) fmt::Display::fmt(self.string, f)
} }
} }
@ -640,7 +641,7 @@ impl Ord for InternedString {
} }
} }
impl<T: ::std::ops::Deref<Target = str>> PartialEq<T> for InternedString { impl<T: std::ops::Deref<Target = str>> PartialEq<T> for InternedString {
fn eq(&self, other: &T) -> bool { fn eq(&self, other: &T) -> bool {
self.with(|string| string == other.deref()) self.with(|string| string == other.deref())
} }
@ -676,20 +677,20 @@ impl<'a> PartialEq<InternedString> for &'a String {
} }
} }
impl ::std::convert::From<InternedString> for String { impl std::convert::From<InternedString> for String {
fn from(val: InternedString) -> String { fn from(val: InternedString) -> String {
val.as_symbol().to_string() val.as_symbol().to_string()
} }
} }
impl fmt::Debug for InternedString { impl fmt::Debug for InternedString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.with(|str| fmt::Debug::fmt(&str, f)) self.with(|str| fmt::Debug::fmt(&str, f))
} }
} }
impl fmt::Display for InternedString { impl fmt::Display for InternedString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.with(|str| fmt::Display::fmt(&str, f)) self.with(|str| fmt::Display::fmt(&str, f))
} }
} }
@ -709,7 +710,7 @@ impl Encodable for InternedString {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use Globals; use crate::Globals;
#[test] #[test]
fn interner_tests() { fn interner_tests() {