Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libsyntax_pos => 2018 #58124

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/libsyntax_pos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "syntax_pos"
version = "0.0.0"
edition = "2018"

[lib]
name = "syntax_pos"
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_pos/analyze_source_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn analyze_source_file(
(lines, multi_byte_chars, non_narrow_chars)
}

cfg_if! {
cfg_if::cfg_if! {
if #[cfg(all(any(target_arch = "x86", target_arch = "x86_64")))] {
fn analyze_source_file_dispatch(src: &str,
source_file_start_pos: BytePos,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_pos/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub const EDITION_NAME_LIST: &str = "2015|2018";
pub const DEFAULT_EDITION: Edition = Edition::Edition2015;

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 {
Edition::Edition2015 => "2015",
Edition::Edition2018 => "2018",
Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax_pos/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
//! DOI=10.1017/S0956796812000093 <https://doi.org/10.1017/S0956796812000093>
use GLOBALS;
use Span;
use edition::{Edition, DEFAULT_EDITION};
use symbol::{keywords, Symbol};
use crate::GLOBALS;
use crate::Span;
use crate::edition::{Edition, DEFAULT_EDITION};
use crate::symbol::{keywords, Symbol};

use serialize::{Encodable, Decodable, Encoder, Decoder};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
Expand Down Expand Up @@ -525,7 +525,7 @@ impl 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)
}
}
Expand Down
41 changes: 15 additions & 26 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,23 @@
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")]

#![deny(rust_2018_idioms)]

#![feature(const_fn)]
#![feature(crate_visibility_modifier)]
#![feature(custom_attribute)]
#![feature(nll)]
#![feature(non_exhaustive)]
#![feature(optin_builtin_traits)]
#![feature(rustc_attrs)]
#![feature(specialization)]
#![feature(step_trait)]
#![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};

extern crate serialize;
#[allow(unused_extern_crates)]
extern crate serialize as rustc_serialize; // used by deriving

#[macro_use]
extern crate cfg_if;

extern crate unicode_width;

pub mod edition;
pub mod hygiene;
pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, CompilerDesugaringKind};
Expand Down Expand Up @@ -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.
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)]
Expand All @@ -100,8 +89,8 @@ pub enum FileName {
}

impl std::fmt::Display for FileName {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
use self::FileName::*;
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use FileName::*;
match *self {
Real(ref path) => write!(fmt, "{}", path.display()),
Macros(ref name) => write!(fmt, "<{} macros>", name),
Expand All @@ -127,7 +116,7 @@ impl From<PathBuf> for FileName {

impl FileName {
pub fn is_real(&self) -> bool {
use self::FileName::*;
use FileName::*;
match *self {
Real(_) => true,
Macros(_) |
Expand All @@ -143,7 +132,7 @@ impl FileName {
}

pub fn is_macros(&self) -> bool {
use self::FileName::*;
use FileName::*;
match *self {
Real(_) |
Anon(_) |
Expand Down Expand Up @@ -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")
.field("lo", &span.lo())
.field("hi", &span.hi())
Expand All @@ -620,13 +609,13 @@ pub fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result {
}

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))
}
}

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))
}
}
Expand Down Expand Up @@ -1009,7 +998,7 @@ impl Decodable for SourceFile {
// `crate_of_origin` has to be set by the importer.
// This value matches up with rustc::hir::def_id::INVALID_CRATE.
// That constant is not available here unfortunately :(
crate_of_origin: ::std::u32::MAX - 1,
crate_of_origin: std::u32::MAX - 1,
start_pos,
end_pos,
src: None,
Expand All @@ -1025,7 +1014,7 @@ impl Decodable 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)
}
}
Expand Down Expand Up @@ -1111,7 +1100,7 @@ impl SourceFile {

/// Get a line from the list of pre-computed line-beginnings.
/// 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 {
// We can't use `lines.get(line_number+1)` because we might
// be parsing when we call this function and thus the current
Expand Down Expand Up @@ -1353,7 +1342,7 @@ pub struct FileLines {
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));

#[derive(Debug)]
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax_pos/span_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// 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

use GLOBALS;
use {BytePos, SpanData};
use hygiene::SyntaxContext;
use crate::GLOBALS;
use crate::{BytePos, SpanData};
use crate::hygiene::SyntaxContext;

use rustc_data_structures::fx::FxHashMap;
use std::hash::{Hash, Hasher};
Expand Down
49 changes: 25 additions & 24 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
use arena::DroplessArena;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::newtype_index;
use serialize::{Decodable, Decoder, Encodable, Encoder};

use std::fmt;
use std::str;
use std::cmp::{PartialEq, Ordering, PartialOrd, Ord};
use std::hash::{Hash, Hasher};

use hygiene::SyntaxContext;
use {Span, DUMMY_SP, GLOBALS};
use crate::hygiene::SyntaxContext;
use crate::{Span, DUMMY_SP, GLOBALS};

#[derive(Copy, Clone, Eq)]
pub struct Ident {
Expand Down Expand Up @@ -100,13 +101,13 @@ impl Hash 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())
}
}

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)
}
}
Expand Down Expand Up @@ -181,7 +182,7 @@ impl Symbol {
pub fn as_str(self) -> LocalInternedString {
with_interner(|interner| unsafe {
LocalInternedString {
string: ::std::mem::transmute::<&str, &str>(interner.get(self))
string: std::mem::transmute::<&str, &str>(interner.get(self))
}
})
}
Expand All @@ -198,7 +199,7 @@ impl 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));
if is_gensymed {
write!(f, "{}({:?})", self, self.0)
Expand All @@ -209,7 +210,7 @@ impl fmt::Debug 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)
}
}
Expand All @@ -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 {
self.as_str() == other.deref()
}
Expand Down Expand Up @@ -335,7 +336,7 @@ macro_rules! declare_keywords {(
};
)*

impl ::std::str::FromStr for Keyword {
impl std::str::FromStr for Keyword {
type Err = ();

fn from_str(s: &str) -> Result<Self, ()> {
Expand Down Expand Up @@ -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
str: ::std::convert::AsRef<U>
str: std::convert::AsRef<U>
{
fn as_ref(&self) -> &U {
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 {
self.string == other.deref()
}
}

impl ::std::cmp::PartialEq<LocalInternedString> for str {
impl std::cmp::PartialEq<LocalInternedString> for str {
fn eq(&self, other: &LocalInternedString) -> bool {
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 {
*self == other.string
}
}

impl ::std::cmp::PartialEq<LocalInternedString> for String {
impl std::cmp::PartialEq<LocalInternedString> for String {
fn eq(&self, other: &LocalInternedString) -> bool {
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 {
*self == other.string
}
Expand All @@ -561,19 +562,19 @@ impl<'a> ::std::cmp::PartialEq<LocalInternedString> for &'a String {
impl !Send for LocalInternedString {}
impl !Sync for LocalInternedString {}

impl ::std::ops::Deref for LocalInternedString {
impl std::ops::Deref for LocalInternedString {
type Target = str;
fn deref(&self) -> &str { self.string }
}

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)
}
}

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)
}
}
Expand Down Expand Up @@ -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 {
self.with(|string| string == other.deref())
}
Expand Down Expand Up @@ -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 {
val.as_symbol().to_string()
}
}

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))
}
}

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))
}
}
Expand All @@ -709,7 +710,7 @@ impl Encodable for InternedString {
#[cfg(test)]
mod tests {
use super::*;
use Globals;
use crate::Globals;

#[test]
fn interner_tests() {
Expand Down