mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Rollup merge of #58124 - taiki-e:libsyntax_pos-2018, r=Centril
libsyntax_pos => 2018 Transitions `libsyntax_pos` to Rust 2018; cc #58099 r? @Centril
This commit is contained in:
commit
281a26bb33
@ -2,6 +2,7 @@
|
||||
authors = ["The Rust Project Developers"]
|
||||
name = "syntax_pos"
|
||||
version = "0.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "syntax_pos"
|
||||
|
@ -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,
|
||||
|
@ -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",
|
||||
|
@ -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};
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,11 @@
|
||||
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)]
|
||||
@ -19,23 +20,11 @@
|
||||
#![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};
|
||||
@ -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)]
|
||||
@ -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),
|
||||
@ -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(_) |
|
||||
@ -143,7 +132,7 @@ impl FileName {
|
||||
}
|
||||
|
||||
pub fn is_macros(&self) -> bool {
|
||||
use self::FileName::*;
|
||||
use FileName::*;
|
||||
match *self {
|
||||
Real(_) |
|
||||
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")
|
||||
.field("lo", &span.lo())
|
||||
.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 {
|
||||
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))
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
@ -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)]
|
||||
|
@ -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};
|
||||
|
@ -5,6 +5,7 @@
|
||||
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;
|
||||
@ -12,8 +13,8 @@ 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 {
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -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)
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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()
|
||||
}
|
||||
@ -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, ()> {
|
||||
@ -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
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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())
|
||||
}
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
@ -709,7 +710,7 @@ impl Encodable for InternedString {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use Globals;
|
||||
use crate::Globals;
|
||||
|
||||
#[test]
|
||||
fn interner_tests() {
|
||||
|
Loading…
Reference in New Issue
Block a user