diff --git a/Cargo.lock b/Cargo.lock index f135dd0170bc1..a36df24359df7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "adler32" version = "1.0.3" diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 1a46ebfcabb95..bb00f6f625130 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1383,6 +1383,7 @@ test_book!( RustdocBook, "src/doc/rustdoc", "rustdoc", default=true; RustcBook, "src/doc/rustc", "rustc", default=true; RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false; + EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false; TheBook, "src/doc/book", "book", default=false; UnstableBook, "src/doc/unstable-book", "unstable-book", default=true; ); diff --git a/src/build_helper/Cargo.toml b/src/build_helper/Cargo.toml index 01d704f816bbc..04c7820b45665 100644 --- a/src/build_helper/Cargo.toml +++ b/src/build_helper/Cargo.toml @@ -2,6 +2,7 @@ name = "build_helper" version = "0.1.0" authors = ["The Rust Project Developers"] +edition = "2018" [lib] name = "build_helper" diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index c66c5c9249087..93aa91768121c 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -1,3 +1,5 @@ +#![deny(rust_2018_idioms)] + use std::fs::File; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; diff --git a/src/liballoc/tests/arc.rs b/src/liballoc/tests/arc.rs index 2759b1b1cac27..7c5a8926126e3 100644 --- a/src/liballoc/tests/arc.rs +++ b/src/liballoc/tests/arc.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::any::Any; use std::sync::{Arc, Weak}; use std::cell::RefCell; diff --git a/src/liballoc/tests/binary_heap.rs b/src/liballoc/tests/binary_heap.rs index 94ae43237d19c..c1a1c5d88781f 100644 --- a/src/liballoc/tests/binary_heap.rs +++ b/src/liballoc/tests/binary_heap.rs @@ -282,6 +282,7 @@ fn assert_covariance() { // // Destructors must be called exactly once per element. #[test] +#[cfg(not(miri))] fn panic_safe() { static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0); diff --git a/src/liballoc/tests/btree/mod.rs b/src/liballoc/tests/btree/mod.rs index 4c704d0f8c28f..653b3f5bcb49d 100644 --- a/src/liballoc/tests/btree/mod.rs +++ b/src/liballoc/tests/btree/mod.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + mod map; mod set; diff --git a/src/liballoc/tests/heap.rs b/src/liballoc/tests/heap.rs index 24eea1d294965..809d2bc094aee 100644 --- a/src/liballoc/tests/heap.rs +++ b/src/liballoc/tests/heap.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::alloc::{Global, Alloc, Layout, System}; /// https://github.com/rust-lang/rust/issues/45955 diff --git a/src/liballoc/tests/rc.rs b/src/liballoc/tests/rc.rs index 18f82e8041008..1be01d1a7ce1a 100644 --- a/src/liballoc/tests/rc.rs +++ b/src/liballoc/tests/rc.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::any::Any; use std::rc::{Rc, Weak}; use std::cell::RefCell; diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index 334466dfb25f5..2a9fdfa9324d5 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::cell::Cell; use std::cmp::Ordering::{self, Equal, Greater, Less}; use std::mem; diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index 1bc1bd8d78c57..f4e6bc9ea31d5 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -31,6 +31,7 @@ fn test_rfind() { } #[test] +#[cfg(not(miri))] fn test_collect() { let empty = ""; let s: String = empty.chars().collect(); @@ -118,6 +119,7 @@ fn test_concat_for_different_types() { #[test] fn test_concat_for_different_lengths() { let empty: &[&str] = &[]; + #[cfg(not(miri))] test_concat!("", empty); test_concat!("a", ["a"]); test_concat!("ab", ["a", "b"]); @@ -146,6 +148,7 @@ fn test_join_for_different_types() { #[test] fn test_join_for_different_lengths() { let empty: &[&str] = &[]; + #[cfg(not(miri))] test_join!("", empty, "-"); test_join!("a", ["a"], "-"); test_join!("a-b", ["a", "b"], "-"); @@ -159,6 +162,7 @@ fn test_join_for_different_lengths_with_long_separator() { assert_eq!("~~~~~".len(), 15); let empty: &[&str] = &[]; + #[cfg(not(miri))] test_join!("", empty, "~~~~~"); test_join!("a", ["a"], "~~~~~"); test_join!("a~~~~~b", ["a", "b"], "~~~~~"); @@ -166,6 +170,7 @@ fn test_join_for_different_lengths_with_long_separator() { } #[test] +#[cfg(not(miri))] fn test_unsafe_slice() { assert_eq!("ab", unsafe {"abc".get_unchecked(0..2)}); assert_eq!("bc", unsafe {"abc".get_unchecked(1..3)}); @@ -238,6 +243,7 @@ fn test_replacen() { #[test] fn test_replace() { let a = "a"; + #[cfg(not(miri))] assert_eq!("".replace(a, "b"), ""); assert_eq!("a".replace(a, "b"), "b"); assert_eq!("ab".replace(a, "b"), "bb"); @@ -297,6 +303,7 @@ fn test_replace_pattern() { // The current implementation of SliceIndex fails to handle methods // orthogonally from range types; therefore, it is worth testing // all of the indexing operations on each input. +#[cfg(not(miri))] mod slice_index { // Test a slicing operation **that should succeed,** // testing it on all of the indexing methods. @@ -679,6 +686,7 @@ fn test_str_slice_rangetoinclusive_ok() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_str_slice_rangetoinclusive_notok() { let s = "abcαβγ"; &s[..=3]; @@ -694,6 +702,7 @@ fn test_str_slicemut_rangetoinclusive_ok() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_str_slicemut_rangetoinclusive_notok() { let mut s = "abcαβγ".to_owned(); let s: &mut str = &mut s; @@ -883,6 +892,7 @@ fn test_as_bytes() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_as_bytes_fail() { // Don't double free. (I'm not sure if this exercises the // original problem code path anymore.) @@ -972,6 +982,7 @@ fn test_split_at_mut() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_split_at_boundscheck() { let s = "ศไทย中华Việt Nam"; s.split_at(1); @@ -1066,6 +1077,7 @@ fn test_rev_iterator() { } #[test] +#[cfg(not(miri))] fn test_chars_decoding() { let mut bytes = [0; 4]; for c in (0..0x110000).filter_map(std::char::from_u32) { @@ -1077,6 +1089,7 @@ fn test_chars_decoding() { } #[test] +#[cfg(not(miri))] fn test_chars_rev_decoding() { let mut bytes = [0; 4]; for c in (0..0x110000).filter_map(std::char::from_u32) { @@ -1306,6 +1319,7 @@ fn test_splitator() { } #[test] +#[cfg(not(miri))] fn test_str_default() { use std::default::Default; @@ -1365,6 +1379,7 @@ fn test_bool_from_str() { assert_eq!("not even a boolean".parse::().ok(), None); } +#[cfg(not(miri))] fn check_contains_all_substrings(s: &str) { assert!(s.contains("")); for i in 0..s.len() { @@ -1375,6 +1390,7 @@ fn check_contains_all_substrings(s: &str) { } #[test] +#[cfg(not(miri))] fn strslice_issue_16589() { assert!("bananas".contains("nana")); @@ -1384,6 +1400,7 @@ fn strslice_issue_16589() { } #[test] +#[cfg(not(miri))] fn strslice_issue_16878() { assert!(!"1234567ah012345678901ah".contains("hah")); assert!(!"00abc01234567890123456789abc".contains("bcabc")); @@ -1391,6 +1408,7 @@ fn strslice_issue_16878() { #[test] +#[cfg(not(miri))] fn test_strslice_contains() { let x = "There are moments, Jeeves, when one asks oneself, 'Do trousers matter?'"; check_contains_all_substrings(x); @@ -1528,6 +1546,7 @@ fn trim_ws() { #[test] fn to_lowercase() { + #[cfg(not(miri))] assert_eq!("".to_lowercase(), ""); assert_eq!("AÉDžaé ".to_lowercase(), "aédžaé "); @@ -1561,6 +1580,7 @@ fn to_lowercase() { #[test] fn to_uppercase() { + #[cfg(not(miri))] assert_eq!("".to_uppercase(), ""); assert_eq!("aéDžßfiᾀ".to_uppercase(), "AÉDŽSSFIἈΙ"); } @@ -1592,6 +1612,7 @@ fn test_cow_from() { } #[test] +#[cfg(not(miri))] fn test_repeat() { assert_eq!("".repeat(3), ""); assert_eq!("abc".repeat(0), ""); diff --git a/src/liballoc/tests/string.rs b/src/liballoc/tests/string.rs index e5ce51a36ee22..e6ca54c408865 100644 --- a/src/liballoc/tests/string.rs +++ b/src/liballoc/tests/string.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::borrow::Cow; use std::collections::CollectionAllocErr::*; use std::mem::size_of; diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index 89f2e0a046d91..545332bcd6a2f 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use std::borrow::Cow; use std::mem::size_of; use std::{usize, isize}; diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index aa49bdb009086..b47e7c867e675 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -108,6 +108,7 @@ fn test_index() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_index_out_of_bounds() { let mut deq = VecDeque::new(); for i in 1..4 { @@ -906,20 +907,24 @@ fn test_append() { // normal append a.append(&mut b); assert_eq!(a.iter().cloned().collect::>(), [1, 2, 3, 4, 5, 6]); + #[cfg(not(miri))] assert_eq!(b.iter().cloned().collect::>(), []); // append nothing to something a.append(&mut b); assert_eq!(a.iter().cloned().collect::>(), [1, 2, 3, 4, 5, 6]); + #[cfg(not(miri))] assert_eq!(b.iter().cloned().collect::>(), []); // append something to nothing b.append(&mut a); assert_eq!(b.iter().cloned().collect::>(), [1, 2, 3, 4, 5, 6]); + #[cfg(not(miri))] assert_eq!(a.iter().cloned().collect::>(), []); } #[test] +#[cfg(not(miri))] fn test_append_permutations() { fn construct_vec_deque( push_back: usize, @@ -1120,6 +1125,7 @@ fn test_reserve_exact_2() { } #[test] +#[cfg(not(miri))] fn test_try_reserve() { // These are the interesting cases: @@ -1221,6 +1227,7 @@ fn test_try_reserve() { } #[test] +#[cfg(not(miri))] fn test_try_reserve_exact() { // This is exactly the same as test_try_reserve with the method changed. diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 78f1c3c0dffa5..8b728c9414d4a 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -24,7 +24,7 @@ //! often generated by LLVM. Additionally, this library can make explicit //! calls to these functions. Their signatures are the same as found in C. //! These functions are often provided by the system libc, but can also be -//! provided by the [rlibc crate](https://crates.io/crates/rlibc). +//! provided by the [compiler-builtins crate](https://crates.io/crates/compiler_builtins). //! //! * `rust_begin_panic` - This function takes four arguments, a //! `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments diff --git a/src/libcore/ops/function.rs b/src/libcore/ops/function.rs index 3a1d765f7b816..c69f5fd989696 100644 --- a/src/libcore/ops/function.rs +++ b/src/libcore/ops/function.rs @@ -62,7 +62,7 @@ label="expected an `Fn<{Args}>` closure, found `{Self}`", )] #[fundamental] // so that regex can rely that `&str: !FnMut` -#[must_use] +#[must_use = "closures are lazy and do nothing unless called"] pub trait Fn : FnMut { /// Performs the call operation. #[unstable(feature = "fn_traits", issue = "29625")] @@ -141,7 +141,7 @@ pub trait Fn : FnMut { label="expected an `FnMut<{Args}>` closure, found `{Self}`", )] #[fundamental] // so that regex can rely that `&str: !FnMut` -#[must_use] +#[must_use = "closures are lazy and do nothing unless called"] pub trait FnMut : FnOnce { /// Performs the call operation. #[unstable(feature = "fn_traits", issue = "29625")] @@ -220,7 +220,7 @@ pub trait FnMut : FnOnce { label="expected an `FnOnce<{Args}>` closure, found `{Self}`", )] #[fundamental] // so that regex can rely that `&str: !FnMut` -#[must_use] +#[must_use = "closures are lazy and do nothing unless called"] pub trait FnOnce { /// The returned type after the call operator is used. #[stable(feature = "fn_once_output", since = "1.12.0")] diff --git a/src/libcore/tests/cell.rs b/src/libcore/tests/cell.rs index 56f295dff8e43..73bdaab5861e6 100644 --- a/src/libcore/tests/cell.rs +++ b/src/libcore/tests/cell.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use core::cell::*; use core::default::Default; use std::mem::drop; diff --git a/src/libcore/tests/fmt/mod.rs b/src/libcore/tests/fmt/mod.rs index d86e21cf40b6e..b10b63fc484cb 100644 --- a/src/libcore/tests/fmt/mod.rs +++ b/src/libcore/tests/fmt/mod.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + mod builders; mod float; mod num; diff --git a/src/libcore/tests/hash/mod.rs b/src/libcore/tests/hash/mod.rs index 135f4dfcac7d5..bf3039a7e51e8 100644 --- a/src/libcore/tests/hash/mod.rs +++ b/src/libcore/tests/hash/mod.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + mod sip; use std::hash::{Hash, Hasher}; diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 0fa99745d9065..9b4c78f8d3b02 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -190,6 +190,7 @@ fn test_iterator_step_by() { } #[test] +#[cfg(not(miri))] fn test_iterator_step_by_nth() { let mut it = (0..16).step_by(5); assert_eq!(it.nth(0), Some(0)); @@ -208,6 +209,7 @@ fn test_iterator_step_by_nth() { } #[test] +#[cfg(not(miri))] fn test_iterator_step_by_nth_overflow() { #[cfg(target_pointer_width = "8")] type Bigger = u16; @@ -253,12 +255,14 @@ fn test_iterator_step_by_nth_overflow() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_iterator_step_by_zero() { let mut it = (0..).step_by(0); it.next(); } #[test] +#[cfg(not(miri))] fn test_iterator_step_by_size_hint() { struct StubSizeHint(usize, Option); impl Iterator for StubSizeHint { @@ -1413,6 +1417,7 @@ fn test_rposition() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_rposition_panic() { let v: [(Box<_>, Box<_>); 4] = [(box 0, box 0), (box 0, box 0), @@ -1652,6 +1657,7 @@ fn test_range_inclusive_nth() { } #[test] +#[cfg(not(miri))] fn test_range_step() { #![allow(deprecated)] @@ -1675,6 +1681,7 @@ fn test_range_step() { } #[test] +#[cfg(not(miri))] fn test_step_by_skip() { assert_eq!((0..640).step_by(128).skip(1).collect::>(), [128, 256, 384, 512]); assert_eq!((0..=50).step_by(10).nth(3), Some(30)); @@ -1682,6 +1689,7 @@ fn test_step_by_skip() { } #[test] +#[cfg(not(miri))] fn test_range_inclusive_step() { assert_eq!((0..=50).step_by(10).collect::>(), [0, 10, 20, 30, 40, 50]); assert_eq!((0..=5).step_by(1).collect::>(), [0, 1, 2, 3, 4, 5]); diff --git a/src/libcore/tests/num/mod.rs b/src/libcore/tests/num/mod.rs index a17c094679ea8..ab638e06cc10d 100644 --- a/src/libcore/tests/num/mod.rs +++ b/src/libcore/tests/num/mod.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use core::convert::{TryFrom, TryInto}; use core::cmp::PartialEq; use core::fmt::Debug; diff --git a/src/libcore/tests/option.rs b/src/libcore/tests/option.rs index b059b134868d9..1ba886ce037ee 100644 --- a/src/libcore/tests/option.rs +++ b/src/libcore/tests/option.rs @@ -69,6 +69,7 @@ fn test_option_dance() { } #[test] #[should_panic] +#[cfg(not(miri))] fn test_option_too_much_dance() { struct A; let mut y = Some(A); @@ -129,6 +130,7 @@ fn test_unwrap() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_unwrap_panic1() { let x: Option = None; x.unwrap(); @@ -136,6 +138,7 @@ fn test_unwrap_panic1() { #[test] #[should_panic] +#[cfg(not(miri))] fn test_unwrap_panic2() { let x: Option = None; x.unwrap(); diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index 65c1a3e0254d2..5784559082266 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use core::ptr::*; use core::cell::RefCell; diff --git a/src/libcore/tests/result.rs b/src/libcore/tests/result.rs index 1fab07526a07f..7bfd396f68d17 100644 --- a/src/libcore/tests/result.rs +++ b/src/libcore/tests/result.rs @@ -117,6 +117,7 @@ fn test_unwrap_or_else() { #[test] #[should_panic] +#[cfg(not(miri))] pub fn test_unwrap_or_else_panic() { fn handler(msg: &'static str) -> isize { if msg == "I got this." { @@ -138,6 +139,7 @@ pub fn test_expect_ok() { } #[test] #[should_panic(expected="Got expected error: \"All good\"")] +#[cfg(not(miri))] pub fn test_expect_err() { let err: Result = Err("All good"); err.expect("Got expected error"); @@ -151,6 +153,7 @@ pub fn test_expect_err_err() { } #[test] #[should_panic(expected="Got expected ok: \"All good\"")] +#[cfg(not(miri))] pub fn test_expect_err_ok() { let err: Result<&'static str, isize> = Ok("All good"); err.expect_err("Got expected ok"); diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index e210e83122c47..04d646ea01d03 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -782,6 +782,7 @@ mod slice_index { // to be used in `should_panic`) #[test] #[should_panic(expected = "out of range")] + #[cfg(not(miri))] fn assert_range_eq_can_fail_by_panic() { assert_range_eq!([0, 1, 2], 0..5, [0, 1, 2]); } @@ -791,6 +792,7 @@ mod slice_index { // to be used in `should_panic`) #[test] #[should_panic(expected = "==")] + #[cfg(not(miri))] fn assert_range_eq_can_fail_by_inequality() { assert_range_eq!([0, 1, 2], 0..2, [0, 1, 2]); } @@ -840,6 +842,7 @@ mod slice_index { #[test] #[should_panic(expected = $expect_msg)] + #[cfg(not(miri))] fn index_fail() { let v = $data; let v: &[_] = &v; @@ -848,6 +851,7 @@ mod slice_index { #[test] #[should_panic(expected = $expect_msg)] + #[cfg(not(miri))] fn index_mut_fail() { let mut v = $data; let v: &mut [_] = &mut v; @@ -1011,6 +1015,7 @@ fn test_rotate_right() { #[test] #[cfg(not(target_arch = "wasm32"))] +#[cfg(not(miri))] fn sort_unstable() { use core::cmp::Ordering::{Equal, Greater, Less}; use core::slice::heapsort; @@ -1166,6 +1171,7 @@ pub mod memchr { } #[test] +#[cfg(not(miri))] fn test_align_to_simple() { let bytes = [1u8, 2, 3, 4, 5, 6, 7]; let (prefix, aligned, suffix) = unsafe { bytes.align_to::() }; @@ -1181,6 +1187,7 @@ fn test_align_to_simple() { } #[test] +#[cfg(not(miri))] fn test_align_to_zst() { let bytes = [1, 2, 3, 4, 5, 6, 7]; let (prefix, aligned, suffix) = unsafe { bytes.align_to::<()>() }; @@ -1189,6 +1196,7 @@ fn test_align_to_zst() { } #[test] +#[cfg(not(miri))] fn test_align_to_non_trivial() { #[repr(align(8))] struct U64(u64, u64); #[repr(align(8))] struct U64U64U32(u64, u64, u32); @@ -1200,6 +1208,7 @@ fn test_align_to_non_trivial() { } #[test] +#[cfg(not(miri))] fn test_align_to_empty_mid() { use core::mem; @@ -1297,6 +1306,7 @@ fn test_copy_within() { #[test] #[should_panic(expected = "src is out of bounds")] +#[cfg(not(miri))] fn test_copy_within_panics_src_too_long() { let mut bytes = *b"Hello, World!"; // The length is only 13, so 14 is out of bounds. @@ -1305,6 +1315,7 @@ fn test_copy_within_panics_src_too_long() { #[test] #[should_panic(expected = "dest is out of bounds")] +#[cfg(not(miri))] fn test_copy_within_panics_dest_too_long() { let mut bytes = *b"Hello, World!"; // The length is only 13, so a slice of length 4 starting at index 10 is out of bounds. @@ -1312,6 +1323,7 @@ fn test_copy_within_panics_dest_too_long() { } #[test] #[should_panic(expected = "src end is before src start")] +#[cfg(not(miri))] fn test_copy_within_panics_src_inverted() { let mut bytes = *b"Hello, World!"; // 2 is greater than 1, so this range is invalid. diff --git a/src/libcore/tests/time.rs b/src/libcore/tests/time.rs index 6efd22572dc18..d39bd06930a36 100644 --- a/src/libcore/tests/time.rs +++ b/src/libcore/tests/time.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] + use core::time::Duration; #[test] diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 91fc12639baf5..c2ce932630de5 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -127,9 +127,9 @@ impl<'hir> Entry<'hir> { } } - fn is_body_owner(self, node_id: NodeId) -> bool { + fn is_body_owner(self, hir_id: HirId) -> bool { match self.associated_body() { - Some(b) => b.node_id == node_id, + Some(b) => b.hir_id == hir_id, None => false, } } @@ -436,7 +436,7 @@ impl<'hir> Map<'hir> { } pub fn body(&self, id: BodyId) -> &'hir Body { - self.read(id.node_id); + self.read_by_hir_id(id.hir_id); // N.B., intentionally bypass `self.forest.krate()` so that we // do not trigger a read of the whole krate here @@ -460,9 +460,10 @@ impl<'hir> Map<'hir> { /// Returns the `NodeId` that corresponds to the definition of /// which this is the body of, i.e., a `fn`, `const` or `static` /// item (possibly associated), a closure, or a `hir::AnonConst`. - pub fn body_owner(&self, BodyId { node_id }: BodyId) -> NodeId { + pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> NodeId { + let node_id = self.hir_to_node_id(hir_id); let parent = self.get_parent_node(node_id); - assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(node_id))); + assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(hir_id))); parent } @@ -486,6 +487,12 @@ impl<'hir> Map<'hir> { } } + // FIXME(@ljedrz): replace the NodeId variant + pub fn maybe_body_owned_by_by_hir_id(&self, id: HirId) -> Option { + let node_id = self.hir_to_node_id(id); + self.maybe_body_owned_by(node_id) + } + /// Given a body owner's id, returns the `BodyId` associated with it. pub fn body_owned_by(&self, id: NodeId) -> BodyId { self.maybe_body_owned_by(id).unwrap_or_else(|| { @@ -519,6 +526,12 @@ impl<'hir> Map<'hir> { } } + // FIXME(@ljedrz): replace the NodeId variant + pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind { + let node_id = self.hir_to_node_id(id); + self.body_owner_kind(node_id) + } + pub fn ty_param_owner(&self, id: NodeId) -> NodeId { match self.get(id) { Node::Item(&Item { node: ItemKind::Trait(..), .. }) => id, @@ -836,6 +849,12 @@ impl<'hir> Map<'hir> { self.local_def_id(self.get_module_parent_node(id)) } + // FIXME(@ljedrz): replace the NodeId variant + pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId { + let node_id = self.hir_to_node_id(id); + self.get_module_parent(node_id) + } + /// Returns the `NodeId` of `id`'s nearest module parent, or `id` itself if no /// module parent is in this map. pub fn get_module_parent_node(&self, id: NodeId) -> NodeId { @@ -931,7 +950,9 @@ impl<'hir> Map<'hir> { } } - pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData { + pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData { + let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible + match self.find(id) { Some(Node::Item(i)) => { match i.node { @@ -946,7 +967,9 @@ impl<'hir> Map<'hir> { } } - pub fn expect_variant(&self, id: NodeId) -> &'hir Variant { + pub fn expect_variant(&self, id: HirId) -> &'hir Variant { + let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible + match self.find(id) { Some(Node::Variant(variant)) => variant, _ => bug!("expected variant, found {}", self.node_to_string(id)), diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 3e7dd1432e1e3..6b8f9e60f240a 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -72,7 +72,7 @@ pub mod print; /// the local_id part of the HirId changing, which is a very useful property in /// incremental compilation where we have to persist things through changes to /// the code base. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] pub struct HirId { pub owner: DefIndex, pub local_id: ItemLocalId, @@ -1233,7 +1233,7 @@ pub enum UnsafeSource { #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct BodyId { - pub node_id: NodeId, + pub hir_id: HirId, } /// The body of a function, closure, or constant value. In the case of @@ -1267,7 +1267,7 @@ pub struct Body { impl Body { pub fn id(&self) -> BodyId { BodyId { - node_id: self.value.id + hir_id: self.value.hir_id, } } } diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 2b359428b1fa1..206df73be230d 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -989,8 +989,8 @@ impl<'a> ToStableHashKey> for hir::BodyId { fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> (DefPathHash, hir::ItemLocalId) { - let hir::BodyId { node_id } = *self; - node_id.to_stable_hash_key(hcx) + let hir::BodyId { hir_id } = *self; + hir_id.to_stable_hash_key(hcx) } } diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 8510533391287..1c23438a3b48a 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -56,7 +56,6 @@ use crate::hir::def_id::DefId; use crate::hir::Node; use crate::middle::region; use std::{cmp, fmt}; -use syntax::ast::DUMMY_NODE_ID; use syntax_pos::{Pos, Span}; use crate::traits::{ObligationCause, ObligationCauseCode}; use crate::ty::error::TypeError; @@ -182,8 +181,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let cm = self.sess.source_map(); let scope = region.free_region_binding_scope(self); - let node = self.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID); - let tag = match self.hir().find(node) { + let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); + let tag = match self.hir().find_by_hir_id(node) { Some(Node::Block(_)) | Some(Node::Expr(_)) => "body", Some(Node::Item(it)) => Self::item_scope_tag(&it), Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it), @@ -192,7 +191,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { }; let (prefix, span) = match *region { ty::ReEarlyBound(ref br) => { - let mut sp = cm.def_span(self.hir().span(node)); + let mut sp = cm.def_span(self.hir().span_by_hir_id(node)); if let Some(param) = self.hir() .get_generics(scope) .and_then(|generics| generics.get_named(&br.name)) @@ -205,7 +204,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { bound_region: ty::BoundRegion::BrNamed(_, ref name), .. }) => { - let mut sp = cm.def_span(self.hir().span(node)); + let mut sp = cm.def_span(self.hir().span_by_hir_id(node)); if let Some(param) = self.hir() .get_generics(scope) .and_then(|generics| generics.get_named(&name)) @@ -217,15 +216,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { ty::ReFree(ref fr) => match fr.bound_region { ty::BrAnon(idx) => ( format!("the anonymous lifetime #{} defined on", idx + 1), - self.hir().span(node), + self.hir().span_by_hir_id(node), ), ty::BrFresh(_) => ( "an anonymous lifetime defined on".to_owned(), - self.hir().span(node), + self.hir().span_by_hir_id(node), ), _ => ( format!("the lifetime {} as defined on", fr.bound_region), - cm.def_span(self.hir().span(node)), + cm.def_span(self.hir().span_by_hir_id(node)), ), }, _ => bug!(), @@ -1451,8 +1450,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { format!(" for lifetime parameter `{}` in coherence check", name) } infer::UpvarRegion(ref upvar_id, _) => { - let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - let var_name = self.tcx.hir().name(var_node_id); + let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); format!(" for capture of `{}` by closure", var_name) } infer::NLL(..) => bug!("NLL variable found in lexical phase"), diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index fac498bd6dd78..f0e5454fa78d0 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -105,7 +105,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { }; if let Some(body_id) = body_id { - let expr = self.tcx.hir().expect_expr(body_id.node_id); + let expr = self.tcx.hir().expect_expr_by_hir_id(body_id.hir_id); local_visitor.visit_expr(expr); } diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index efd7f3c55e900..6c481e8c0c114 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -31,8 +31,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { "...so that reference does not outlive borrowed content"); } infer::ReborrowUpvar(span, ref upvar_id) => { - let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - let var_name = self.tcx.hir().name(var_node_id); + let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); err.span_note(span, &format!("...so that closure can access `{}`", var_name)); } @@ -164,8 +163,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err } infer::ReborrowUpvar(span, ref upvar_id) => { - let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id); - let var_name = self.tcx.hir().name(var_node_id); + let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); let mut err = struct_span_err!(self.tcx.sess, span, E0313, diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 06c94d133344c..88caa27244f0c 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -9,6 +9,7 @@ pub use crate::ty::IntVarValue; use arena::SyncDroplessArena; use crate::errors::DiagnosticBuilder; +use crate::hir; use crate::hir::def_id::DefId; use crate::infer::canonical::{Canonical, CanonicalVarValues}; use crate::middle::free_region::RegionRelations; @@ -202,7 +203,7 @@ pub struct InferCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { // for each body-id in this map, which will process the // obligations within. This is expected to be done 'late enough' // that all type inference variables have been bound and so forth. - pub region_obligations: RefCell)>>, + pub region_obligations: RefCell)>>, /// What is the innermost universe we have created? Starts out as /// `UniverseIndex::root()` but grows from there as we enter @@ -1440,7 +1441,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { pub fn partially_normalize_associated_types_in( &self, span: Span, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, value: &T, ) -> InferOk<'tcx, T> diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index e28157f05f15f..4f49a78cf4fe4 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -98,7 +98,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { pub fn instantiate_opaque_types>( &self, parent_def_id: DefId, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, value: &T, ) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> { @@ -632,7 +632,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx> struct Instantiator<'a, 'gcx: 'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, parent_def_id: DefId, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, opaque_types: OpaqueTypeMap<'tcx>, obligations: Vec>, diff --git a/src/librustc/infer/outlives/env.rs b/src/librustc/infer/outlives/env.rs index 20d03f3c6edb5..0492f65e6e169 100644 --- a/src/librustc/infer/outlives/env.rs +++ b/src/librustc/infer/outlives/env.rs @@ -1,7 +1,7 @@ use crate::infer::outlives::free_region_map::FreeRegionMap; use crate::infer::{GenericKind, InferCtxt}; +use crate::hir; use rustc_data_structures::fx::FxHashMap; -use syntax::ast; use syntax_pos::Span; use crate::traits::query::outlives_bounds::{self, OutlivesBound}; use crate::ty::{self, Ty}; @@ -55,7 +55,7 @@ pub struct OutlivesEnvironment<'tcx> { // results when proving outlives obligations like `T: 'x` later // (e.g., if `T: 'x` must be proven within the body B1, then we // know it is true if either `'a: 'x` or `'b: 'x`). - region_bound_pairs_map: FxHashMap>, + region_bound_pairs_map: FxHashMap>, // Used to compute `region_bound_pairs_map`: contains the set of // in-scope region-bound pairs thus far. @@ -87,7 +87,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> { } /// Borrows current value of the `region_bound_pairs`. - pub fn region_bound_pairs_map(&self) -> &FxHashMap> { + pub fn region_bound_pairs_map(&self) -> &FxHashMap> { &self.region_bound_pairs_map } @@ -162,7 +162,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> { &mut self, infcx: &InferCtxt<'a, 'gcx, 'tcx>, fn_sig_tys: &[Ty<'tcx>], - body_id: ast::NodeId, + body_id: hir::HirId, span: Span, ) { debug!("add_implied_bounds()"); @@ -176,7 +176,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> { } /// Save the current set of region-bound pairs under the given `body_id`. - pub fn save_implied_bounds(&mut self, body_id: ast::NodeId) { + pub fn save_implied_bounds(&mut self, body_id: hir::HirId) { let old = self.region_bound_pairs_map.insert( body_id, self.region_bound_pairs_accum.clone(), diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs index 884bd58b4023b..90125e4c689d9 100644 --- a/src/librustc/infer/outlives/obligations.rs +++ b/src/librustc/infer/outlives/obligations.rs @@ -63,7 +63,7 @@ use crate::infer::outlives::env::RegionBoundPairs; use crate::infer::outlives::verify::VerifyBoundCx; use crate::infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound}; use rustc_data_structures::fx::FxHashMap; -use syntax::ast; +use crate::hir; use crate::traits::ObligationCause; use crate::ty::outlives::Component; use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable}; @@ -76,7 +76,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { /// information). pub fn register_region_obligation( &self, - body_id: ast::NodeId, + body_id: hir::HirId, obligation: RegionObligation<'tcx>, ) { debug!( @@ -110,7 +110,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { } /// Trait queries just want to pass back type obligations "as is" - pub fn take_registered_region_obligations(&self) -> Vec<(ast::NodeId, RegionObligation<'tcx>)> { + pub fn take_registered_region_obligations(&self) -> Vec<(hir::HirId, RegionObligation<'tcx>)> { ::std::mem::replace(&mut *self.region_obligations.borrow_mut(), vec![]) } @@ -149,7 +149,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { /// processed. pub fn process_registered_region_obligations( &self, - region_bound_pairs_map: &FxHashMap>, + region_bound_pairs_map: &FxHashMap>, implicit_region_bound: Option>, param_env: ty::ParamEnv<'tcx>, ) { diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 73ba47d411915..99d0c5e88d638 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -177,8 +177,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // Check the impl. If the generics on the self // type of the impl require inlining, this method // does too. - let impl_node_id = self.tcx.hir().as_local_node_id(impl_did).unwrap(); - match self.tcx.hir().expect_item(impl_node_id).node { + let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did).unwrap(); + match self.tcx.hir().expect_item_by_hir_id(impl_hir_id).node { hir::ItemKind::Impl(..) => { let generics = self.tcx.generics_of(impl_did); generics.requires_monomorphization(self.tcx) diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index f7cd241236498..f187928e0d900 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1248,12 +1248,12 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) { } => { // FIXME (#24278): non-hygienic comparison if let Some(def) = lifetimes.get(&hir::ParamName::Plain(label.modern())) { - let node_id = tcx.hir().as_local_node_id(def.id().unwrap()).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap(); signal_shadowing_problem( tcx, label.name, - original_lifetime(tcx.hir().span(node_id)), + original_lifetime(tcx.hir().span_by_hir_id(hir_id)), shadower_label(label.span), ); return; @@ -2593,12 +2593,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { ref lifetimes, s, .. } => { if let Some(&def) = lifetimes.get(¶m.name.modern()) { - let node_id = self.tcx.hir().as_local_node_id(def.id().unwrap()).unwrap(); + let hir_id = self.tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap(); signal_shadowing_problem( self.tcx, param.name.ident().name, - original_lifetime(self.tcx.hir().span(node_id)), + original_lifetime(self.tcx.hir().span_by_hir_id(hir_id)), shadower_lifetime(¶m), ); return; diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index d1db49e05f190..43ee27982b8bd 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -202,7 +202,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { full_env, ty, trait_did, - ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID), + ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID), ); fulfill.select_all_or_error(&infcx).unwrap_or_else(|e| { panic!( @@ -315,7 +315,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { user_env.caller_bounds.iter().cloned().collect(); let mut new_env = param_env.clone(); - let dummy_cause = ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID); + let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID); while let Some(pred) = predicates.pop_front() { infcx.clear_caches(); @@ -669,7 +669,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { select: &mut SelectionContext<'c, 'd, 'cx>, only_projections: bool, ) -> bool { - let dummy_cause = ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID); + let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID); for (obligation, mut predicate) in nested .map(|o| (o.clone(), o.predicate.clone())) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 79afc593a4676..c17adaf1f9f98 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1035,7 +1035,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { ).collect::>()) } Node::StructCtor(ref variant_data) => { - (self.tcx.sess.source_map().def_span(self.tcx.hir().span(variant_data.id())), + (self.tcx.sess.source_map().def_span( + self.tcx.hir().span_by_hir_id(variant_data.hir_id())), vec![ArgKind::empty(); variant_data.fields().len()]) } _ => panic!("non-FnLike node found: {:?}", node), diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index d1be8d377a84d..feaba8619c030 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -132,7 +132,7 @@ pub struct ObligationCause<'tcx> { // (in particular, closures can add new assumptions). See the // field `region_obligations` of the `FulfillmentContext` for more // information. - pub body_id: ast::NodeId, + pub body_id: hir::HirId, pub code: ObligationCauseCode<'tcx> } @@ -655,7 +655,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>( }; let obligation = Obligation { param_env, - cause: ObligationCause::misc(span, ast::DUMMY_NODE_ID), + cause: ObligationCause::misc(span, hir::DUMMY_HIR_ID), recursion_depth: 0, predicate: trait_ref.to_predicate(), }; @@ -678,7 +678,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>( // We can use a dummy node-id here because we won't pay any mind // to region obligations that arise (there shouldn't really be any // anyhow). - let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID); + let cause = ObligationCause::misc(span, hir::DUMMY_HIR_ID); fulfill_cx.register_bound(infcx, param_env, ty, def_id, cause); @@ -1058,7 +1058,7 @@ impl<'tcx,O> Obligation<'tcx,O> { } pub fn misc(span: Span, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, trait_ref: O) -> Obligation<'tcx, O> { @@ -1076,18 +1076,18 @@ impl<'tcx,O> Obligation<'tcx,O> { impl<'tcx> ObligationCause<'tcx> { #[inline] pub fn new(span: Span, - body_id: ast::NodeId, + body_id: hir::HirId, code: ObligationCauseCode<'tcx>) -> ObligationCause<'tcx> { - ObligationCause { span: span, body_id: body_id, code: code } + ObligationCause { span, body_id, code } } - pub fn misc(span: Span, body_id: ast::NodeId) -> ObligationCause<'tcx> { - ObligationCause { span: span, body_id: body_id, code: MiscObligation } + pub fn misc(span: Span, body_id: hir::HirId) -> ObligationCause<'tcx> { + ObligationCause { span, body_id, code: MiscObligation } } pub fn dummy() -> ObligationCause<'tcx> { - ObligationCause { span: DUMMY_SP, body_id: ast::CRATE_NODE_ID, code: MiscObligation } + ObligationCause { span: DUMMY_SP, body_id: hir::CRATE_HIR_ID, code: MiscObligation } } } diff --git a/src/librustc/traits/query/outlives_bounds.rs b/src/librustc/traits/query/outlives_bounds.rs index e57236b999bab..22a34d010f665 100644 --- a/src/librustc/traits/query/outlives_bounds.rs +++ b/src/librustc/traits/query/outlives_bounds.rs @@ -1,6 +1,6 @@ use crate::infer::InferCtxt; use crate::infer::canonical::OriginalQueryValues; -use syntax::ast; +use crate::hir; use syntax::source_map::Span; use crate::traits::{FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt}; use crate::traits::query::NoSolution; @@ -89,7 +89,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { pub fn implied_outlives_bounds( &self, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, ty: Ty<'tcx>, span: Span, ) -> Vec> { diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 67c919ac91610..754cc94073b10 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -525,9 +525,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn impl_is_default(self, node_item_def_id: DefId) -> bool { - match self.hir().as_local_node_id(node_item_def_id) { - Some(node_id) => { - let item = self.hir().expect_item(node_id); + match self.hir().as_local_hir_id(node_item_def_id) { + Some(hir_id) => { + let item = self.hir().expect_item_by_hir_id(hir_id); if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.node { defaultness.is_default() } else { diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index f89e50d696945..953312fddcc6b 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -461,8 +461,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // only occur very early in the compiler pipeline. let parent_def_id = self.parent_def_id(impl_def_id).unwrap(); self.push_item_path(buffer, parent_def_id, pushed_prelude_crate); - let node_id = self.hir().as_local_node_id(impl_def_id).unwrap(); - let item = self.hir().expect_item(node_id); + let hir_id = self.hir().as_local_hir_id(impl_def_id).unwrap(); + let item = self.hir().expect_item_by_hir_id(hir_id); let span_str = self.sess.source_map().span_to_string(item.span); buffer.push(&format!("", span_str)); } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 60e3ac673a0a0..66e9a33d049da 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -39,7 +39,7 @@ use std::ops::Deref; use rustc_data_structures::sync::{self, Lrc, ParallelIterator, par_iter}; use std::slice; use std::{mem, ptr}; -use syntax::ast::{self, DUMMY_NODE_ID, Name, Ident, NodeId}; +use syntax::ast::{self, Name, Ident, NodeId}; use syntax::attr; use syntax::ext::hygiene::Mark; use syntax::symbol::{keywords, Symbol, LocalInternedString, InternedString}; @@ -2794,7 +2794,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn find_field_index(self, ident: Ident, variant: &VariantDef) -> Option { variant.fields.iter().position(|field| { - self.adjust_ident(ident, variant.did, DUMMY_NODE_ID).0 == field.ident.modern() + self.adjust_ident(ident, variant.did, hir::DUMMY_HIR_ID).0 == field.ident.modern() }) } @@ -2939,8 +2939,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Get the attributes of a definition. pub fn get_attrs(self, did: DefId) -> Attributes<'gcx> { - if let Some(id) = self.hir().as_local_node_id(did) { - Attributes::Borrowed(self.hir().attrs(id)) + if let Some(id) = self.hir().as_local_hir_id(did) { + Attributes::Borrowed(self.hir().attrs_by_hir_id(id)) } else { Attributes::Owned(self.item_attrs(did)) } @@ -2991,8 +2991,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// with the name of the crate containing the impl. pub fn span_of_impl(self, impl_did: DefId) -> Result { if impl_did.is_local() { - let node_id = self.hir().as_local_node_id(impl_did).unwrap(); - Ok(self.hir().span(node_id)) + let hir_id = self.hir().as_local_hir_id(impl_did).unwrap(); + Ok(self.hir().span_by_hir_id(hir_id)) } else { Err(self.crate_name(impl_did.krate)) } @@ -3002,10 +3002,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // supposed definition name (`def_name`). The method also needs `DefId` of the supposed // definition's parent/scope to perform comparison. pub fn hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool { - self.adjust_ident(use_name, def_parent_def_id, DUMMY_NODE_ID).0 == def_name.modern() + self.adjust_ident(use_name, def_parent_def_id, hir::DUMMY_HIR_ID).0 == def_name.modern() } - pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: NodeId) -> (Ident, DefId) { + pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: hir::HirId) -> (Ident, DefId) { ident = ident.modern(); let target_expansion = match scope.krate { LOCAL_CRATE => self.hir().definitions().expansion_that_defined(scope.index), @@ -3014,8 +3014,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let scope = match ident.span.adjust(target_expansion) { Some(actual_expansion) => self.hir().definitions().parent_module_of_macro_def(actual_expansion), - None if block == DUMMY_NODE_ID => DefId::local(CRATE_DEF_INDEX), // Dummy DefId - None => self.hir().get_module_parent(block), + None if block == hir::DUMMY_HIR_ID => DefId::local(CRATE_DEF_INDEX), // Dummy DefId + None => self.hir().get_module_parent_by_hir_id(block), }; (ident, scope) } @@ -3110,8 +3110,8 @@ fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Lrc> { - let id = tcx.hir().as_local_node_id(def_id).unwrap(); - let item = tcx.hir().expect_item(id); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let item = tcx.hir().expect_item_by_hir_id(id); let vec: Vec<_> = match item.node { hir::ItemKind::Trait(.., ref trait_item_refs) => { trait_item_refs.iter() @@ -3192,8 +3192,8 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if tcx.sess.opts.debugging_opts.chalk { Some(def_id) } else { None } ); - let body_id = tcx.hir().as_local_node_id(def_id).map_or(DUMMY_NODE_ID, |id| { - tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.node_id) + let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| { + tcx.hir().maybe_body_owned_by_by_hir_id(id).map_or(id, |body| body.hir_id) }); let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id); traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause) diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 2aae953c1c40a..c020f67f789d0 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -1,10 +1,10 @@ +use crate::hir; use crate::hir::def_id::DefId; use crate::infer::InferCtxt; use crate::ty::subst::Substs; use crate::traits; use crate::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable}; use std::iter::once; -use syntax::ast; use syntax_pos::Span; use crate::middle::lang_items; @@ -16,7 +16,7 @@ use crate::middle::lang_items; /// say "$0 is WF if $0 is WF". pub fn obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, ty: Ty<'tcx>, span: Span) -> Option>> @@ -42,7 +42,7 @@ pub fn obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, /// if `Bar: Eq`. pub fn trait_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, trait_ref: &ty::TraitRef<'tcx>, span: Span) -> Vec> @@ -54,7 +54,7 @@ pub fn trait_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, pub fn predicate_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, predicate: &ty::Predicate<'tcx>, span: Span) -> Vec> @@ -103,7 +103,7 @@ pub fn predicate_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, struct WfPredicates<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, span: Span, out: Vec>, } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 2cd82d44af3aa..7a30a2870c987 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -801,7 +801,7 @@ impl fmt::Debug for ty::UpvarId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "UpvarId({:?};`{}`;{:?})", self.var_path.hir_id, - ty::tls::with(|tcx| tcx.hir().name(tcx.hir().hir_to_node_id(self.var_path.hir_id))), + ty::tls::with(|tcx| tcx.hir().name_by_hir_id(self.var_path.hir_id)), self.closure_expr_id) } } diff --git a/src/librustc_allocator/Cargo.toml b/src/librustc_allocator/Cargo.toml index 03d33f413c807..cf6c598bfb17b 100644 --- a/src/librustc_allocator/Cargo.toml +++ b/src/librustc_allocator/Cargo.toml @@ -2,6 +2,7 @@ authors = ["The Rust Project Developers"] name = "rustc_allocator" version = "0.0.0" +edition = "2018" [lib] path = "lib.rs" diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs index 1fb1794d5147d..d302e7646d168 100644 --- a/src/librustc_allocator/expand.rs +++ b/src/librustc_allocator/expand.rs @@ -1,6 +1,6 @@ +use log::debug; use rustc::middle::allocator::AllocatorKind; -use rustc_errors; -use smallvec::SmallVec; +use smallvec::{smallvec, SmallVec}; use syntax::{ ast::{ self, Arg, Attribute, Crate, Expr, FnHeader, Generics, Ident, Item, ItemKind, @@ -23,7 +23,7 @@ use syntax::{ }; use syntax_pos::Span; -use {AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS}; +use crate::{AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS}; pub fn modify( sess: &ParseSess, @@ -54,7 +54,7 @@ struct ExpandAllocatorDirectives<'a> { in_submod: isize, } -impl<'a> MutVisitor for ExpandAllocatorDirectives<'a> { +impl MutVisitor for ExpandAllocatorDirectives<'_> { fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { debug!("in submodule {}", self.in_submod); @@ -168,7 +168,7 @@ struct AllocFnFactory<'a> { cx: ExtCtxt<'a>, } -impl<'a> AllocFnFactory<'a> { +impl AllocFnFactory<'_> { fn allocator_fn(&self, method: &AllocatorMethod) -> P { let mut abi_args = Vec::new(); let mut i = 0; diff --git a/src/librustc_allocator/lib.rs b/src/librustc_allocator/lib.rs index 41c0be615956e..16b9ccfda8010 100644 --- a/src/librustc_allocator/lib.rs +++ b/src/librustc_allocator/lib.rs @@ -1,15 +1,6 @@ -#![feature(nll)] #![feature(rustc_private)] -#[macro_use] extern crate log; -extern crate rustc; -extern crate rustc_data_structures; -extern crate rustc_errors; -extern crate rustc_target; -extern crate syntax; -extern crate syntax_pos; -#[macro_use] -extern crate smallvec; +#![deny(rust_2018_idioms)] pub mod expand; diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index e40c2b4508922..ac23504264fcc 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -403,7 +403,7 @@ fn closure_to_block(closure_id: LocalDefId, match tcx.hir().get(closure_id) { Node::Expr(expr) => match expr.node { hir::ExprKind::Closure(.., body_id, _, _) => { - body_id.node_id + tcx.hir().hir_to_node_id(body_id.hir_id) } _ => { bug!("encountered non-closure id: {}", closure_id) diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 3b212f3b7472d..6963c54b50358 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -673,7 +673,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { let def_id = field.did; debug!("IsolatedEncoder::encode_field({:?})", def_id); - let variant_id = tcx.hir().as_local_node_id(variant.did).unwrap(); + let variant_id = tcx.hir().as_local_hir_id(variant.did).unwrap(); let variant_data = tcx.hir().expect_variant_data(variant_id); Entry { diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index b070031756798..248ac84237a2c 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -833,13 +833,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { format!("`{}` would have to be valid for `{}`...", name, region_name), ); - if let Some(fn_node_id) = self.infcx.tcx.hir().as_local_node_id(self.mir_def_id) { + if let Some(fn_hir_id) = self.infcx.tcx.hir().as_local_hir_id(self.mir_def_id) { err.span_label( drop_span, format!( "...but `{}` will be dropped here, when the function `{}` returns", name, - self.infcx.tcx.hir().name(fn_node_id), + self.infcx.tcx.hir().name_by_hir_id(fn_hir_id), ), ); diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 8539b5c26cee8..52003f01f9c3e 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -308,9 +308,8 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { let upvar_decl = &self.mir.upvar_decls[field.index()]; let upvar_hir_id = upvar_decl.var_hir_id.assert_crate_local(); - let upvar_node_id = - self.infcx.tcx.hir().hir_to_node_id(upvar_hir_id); - let upvar_span = self.infcx.tcx.hir().span(upvar_node_id); + let upvar_span = self.infcx.tcx.hir().span_by_hir_id( + upvar_hir_id); diag.span_label(upvar_span, "captured outer variable"); break; } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index bff8015511242..f164cfb08766b 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -10,7 +10,7 @@ use rustc::ty::subst::{Substs, UnpackedKind}; use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt}; use rustc::util::ppaux::RegionHighlightMode; use rustc_errors::DiagnosticBuilder; -use syntax::ast::{Name, DUMMY_NODE_ID}; +use syntax::ast::Name; use syntax::symbol::keywords; use syntax_pos::Span; use syntax_pos::symbol::InternedString; @@ -293,9 +293,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { name: &InternedString, ) -> Span { let scope = error_region.free_region_binding_scope(tcx); - let node = tcx.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID); + let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); - let span = tcx.sess.source_map().def_span(tcx.hir().span(node)); + let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(node)); if let Some(param) = tcx.hir() .get_generics(scope) .and_then(|generics| generics.get_named(name)) diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs index c2f2e99c0a55b..b6dfb2da77994 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs @@ -71,11 +71,10 @@ impl<'tcx> RegionInferenceContext<'tcx> { upvar_index: usize, ) -> (Symbol, Span) { let upvar_hir_id = mir.upvar_decls[upvar_index].var_hir_id.assert_crate_local(); - let upvar_node_id = tcx.hir().hir_to_node_id(upvar_hir_id); - debug!("get_upvar_name_and_span_for_region: upvar_node_id={:?}", upvar_node_id); + debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id); - let upvar_name = tcx.hir().name(upvar_node_id); - let upvar_span = tcx.hir().span(upvar_node_id); + let upvar_name = tcx.hir().name_by_hir_id(upvar_hir_id); + let upvar_span = tcx.hir().span_by_hir_id(upvar_hir_id); debug!("get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}", upvar_name, upvar_span); diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index 0a214e60bdd78..ad4444e0df24c 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -771,9 +771,8 @@ fn for_each_late_bound_region_defined_on<'tcx>( owner: fn_def_id.index, local_id: *late_bound, }; - let region_node_id = tcx.hir().hir_to_node_id(hir_id); - let name = tcx.hir().name(region_node_id).as_interned_str(); - let region_def_id = tcx.hir().local_def_id(region_node_id); + let name = tcx.hir().name_by_hir_id(hir_id).as_interned_str(); + let region_def_id = tcx.hir().local_def_id_from_hir_id(hir_id); let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion { scope: fn_def_id, bound_region: ty::BoundRegion::BrNamed(region_def_id, name), diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index f38648fda0e36..b1a745b6980fb 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -64,8 +64,8 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t ) => { (*body_id, ty.span) } - Node::AnonConst(hir::AnonConst { body, id, .. }) => { - (*body, tcx.hir().span(*id)) + Node::AnonConst(hir::AnonConst { body, hir_id, .. }) => { + (*body, tcx.hir().span_by_hir_id(*hir_id)) } _ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def_id), @@ -114,7 +114,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t let self_arg; if let Some(ref fn_decl) = tcx.hir().fn_decl(owner_id) { let ty_hir_id = fn_decl.inputs[index].hir_id; - let ty_span = tcx.hir().span(tcx.hir().hir_to_node_id(ty_hir_id)); + let ty_span = tcx.hir().span_by_hir_id(ty_hir_id); opt_ty_info = Some(ty_span); self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() { match fn_decl.implicit_self { diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 518ae978ae17a..466bdd1d25587 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -48,7 +48,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, for (index, stmt) in stmts.iter().enumerate() { let hir_id = stmt.hir_id; let opt_dxn_ext = cx.region_scope_tree.opt_destruction_scope(hir_id.local_id); - let stmt_span = StatementSpan(cx.tcx.hir().span(stmt.id)); + let stmt_span = StatementSpan(cx.tcx.hir().span_by_hir_id(hir_id)); match stmt.node { hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => { diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index e713ab17c3af5..57cbc7002acba 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -450,8 +450,8 @@ fn check_recursion_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if recursion_depth > *tcx.sess.recursion_limit.get() { let error = format!("reached the recursion limit while instantiating `{}`", instance); - if let Some(node_id) = tcx.hir().as_local_node_id(def_id) { - tcx.sess.span_fatal(tcx.hir().span(node_id), &error); + if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { + tcx.sess.span_fatal(tcx.hir().span_by_hir_id(hir_id), &error); } else { tcx.sess.fatal(&error); } @@ -482,8 +482,8 @@ fn check_type_length_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let instance_name = instance.to_string(); let msg = format!("reached the type-length limit while instantiating `{:.64}...`", instance_name); - let mut diag = if let Some(node_id) = tcx.hir().as_local_node_id(instance.def_id()) { - tcx.sess.struct_span_fatal(tcx.hir().span(node_id), &msg) + let mut diag = if let Some(hir_id) = tcx.hir().as_local_hir_id(instance.def_id()) { + tcx.sess.struct_span_fatal(tcx.hir().span_by_hir_id(hir_id), &msg) } else { tcx.sess.struct_fatal(&msg) }; diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 7d1943e21b90d..f0588eed666ea 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1172,9 +1172,9 @@ impl MirPass for QualifyAndPromoteConstants { } let def_id = src.def_id; - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let mut const_promoted_temps = None; - let mode = match tcx.hir().body_owner_kind(id) { + let mode = match tcx.hir().body_owner_kind_by_hir_id(id) { hir::BodyOwnerKind::Closure => Mode::Fn, hir::BodyOwnerKind::Fn => { if tcx.is_const_fn(def_id) { diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 739c96934e6ab..f07cceb0ce5e0 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -55,8 +55,7 @@ fn const_is_rvalue_promotable_to_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let node_id = tcx.hir().as_local_node_id(def_id) .expect("rvalue_promotable_map invoked with non-local def-id"); let body_id = tcx.hir().body_owned_by(node_id); - let body_hir_id = tcx.hir().node_to_hir_id(body_id.node_id); - tcx.rvalue_promotable_map(def_id).contains(&body_hir_id.local_id) + tcx.rvalue_promotable_map(def_id).contains(&body_id.hir_id.local_id) } fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 14a0922c47740..00d850f633848 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -804,7 +804,8 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> { def: &'tcx ty::AdtDef, // definition of the struct or enum field: &'tcx ty::FieldDef) { // definition of the field let ident = Ident::new(keywords::Invalid.name(), use_ctxt); - let def_id = self.tcx.adjust_ident(ident, def.did, self.current_item).1; + let current_hir = self.tcx.hir().node_to_hir_id(self.current_item); + let def_id = self.tcx.adjust_ident(ident, def.did, current_hir).1; if !def.is_enum() && !field.vis.is_accessible_from(def_id, self.tcx) { struct_span_err!(self.tcx.sess, span, E0451, "field `{}` of {} `{}` is private", field.ident, def.variant_descr(), self.tcx.item_path_str(def.did)) diff --git a/src/librustc_save_analysis/Cargo.toml b/src/librustc_save_analysis/Cargo.toml index e47f89c64ff07..8bb2e722b5794 100644 --- a/src/librustc_save_analysis/Cargo.toml +++ b/src/librustc_save_analysis/Cargo.toml @@ -2,6 +2,7 @@ authors = ["The Rust Project Developers"] name = "rustc_save_analysis" version = "0.0.0" +edition = "2018" [lib] name = "rustc_save_analysis" diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 995df3802aabd..4d8bc0ad5ddf0 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -16,6 +16,7 @@ use rustc::hir::def::Def as HirDef; use rustc::hir::def_id::DefId; use rustc::session::config::Input; +use rustc::span_bug; use rustc::ty::{self, TyCtxt}; use rustc_data_structures::fx::FxHashSet; @@ -32,16 +33,20 @@ use syntax::print::pprust::{ }; use syntax::ptr::P; use syntax::source_map::{Spanned, DUMMY_SP, respan}; +use syntax::walk_list; use syntax_pos::*; -use {escape, generated_code, lower_attributes, PathCollector, SaveContext}; -use json_dumper::{Access, DumpOutput, JsonDumper}; -use span_utils::SpanUtils; -use sig; +use crate::{escape, generated_code, id_from_def_id, id_from_node_id, lower_attributes, + PathCollector, SaveContext}; +use crate::json_dumper::{Access, DumpOutput, JsonDumper}; +use crate::span_utils::SpanUtils; +use crate::sig; use rls_data::{CompilationOptions, CratePreludeData, Def, DefKind, GlobalCrateId, Import, ImportKind, Ref, RefKind, Relation, RelationKind, SpanData}; +use log::{debug, error}; + macro_rules! down_cast_data { ($id:ident, $kind:ident, $sp:expr) => { let $id = if let super::Data::$kind(data) = $id { @@ -68,7 +73,7 @@ macro_rules! access_from { }; } -pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> { +pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput> { save_ctxt: SaveContext<'l, 'tcx>, tcx: TyCtxt<'l, 'tcx, 'tcx>, dumper: &'ll mut JsonDumper, @@ -245,7 +250,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { None => continue, }; if !self.span.filter_generated(ident.span) { - let id = ::id_from_node_id(id, &self.save_ctxt); + let id = id_from_node_id(id, &self.save_ctxt); let span = self.span_from_span(ident.span); self.dumper.dump_def( @@ -286,7 +291,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { debug!("process_method: {}:{}", id, ident); if let Some(mut method_data) = self.save_ctxt.get_method_data(id, ident, span) { - let sig_str = ::make_signature(&sig.decl, &generics); + let sig_str = crate::make_signature(&sig.decl, &generics); if body.is_some() { self.nest_tables( id, @@ -339,7 +344,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { // Append $id to name to make sure each one is unique. let qualname = format!("{}::{}${}", prefix, name, id); if !self.span.filter_generated(param_ss) { - let id = ::id_from_node_id(param.id, &self.save_ctxt); + let id = id_from_node_id(param.id, &self.save_ctxt); let span = self.span_from_span(param_ss); self.dumper.dump_def( @@ -433,12 +438,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { &access_from!(self.save_ctxt, vis, id), Def { kind: DefKind::Const, - id: ::id_from_node_id(id, &self.save_ctxt), + id: id_from_node_id(id, &self.save_ctxt), span, name: ident.name.to_string(), qualname, value: ty_to_string(&typ), - parent: Some(::id_from_def_id(parent_id)), + parent: Some(id_from_def_id(parent_id)), children: vec![], decl_id: None, docs: self.save_ctxt.docs_for_attrs(attrs), @@ -495,7 +500,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { value, fields .iter() - .map(|f| ::id_from_node_id(f.id, &self.save_ctxt)) + .map(|f| id_from_node_id(f.id, &self.save_ctxt)) .collect(), ) } @@ -508,7 +513,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { &access_from!(self.save_ctxt, item), Def { kind, - id: ::id_from_node_id(item.id, &self.save_ctxt), + id: id_from_node_id(item.id, &self.save_ctxt), span, name, qualname: qualname.clone(), @@ -564,8 +569,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str); if !self.span.filter_generated(name_span) { let span = self.span_from_span(name_span); - let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt); - let parent = Some(::id_from_node_id(item.id, &self.save_ctxt)); + let id = id_from_node_id(variant.node.data.id(), &self.save_ctxt); + let parent = Some(id_from_node_id(item.id, &self.save_ctxt)); self.dumper.dump_def( &access, @@ -602,8 +607,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { } if !self.span.filter_generated(name_span) { let span = self.span_from_span(name_span); - let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt); - let parent = Some(::id_from_node_id(item.id, &self.save_ctxt)); + let id = id_from_node_id(variant.node.data.id(), &self.save_ctxt); + let parent = Some(id_from_node_id(item.id, &self.save_ctxt)); self.dumper.dump_def( &access, @@ -686,11 +691,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { val.push_str(&bounds_to_string(trait_refs)); } if !self.span.filter_generated(item.ident.span) { - let id = ::id_from_node_id(item.id, &self.save_ctxt); + let id = id_from_node_id(item.id, &self.save_ctxt); let span = self.span_from_span(item.ident.span); let children = methods .iter() - .map(|i| ::id_from_node_id(i.id, &self.save_ctxt)) + .map(|i| id_from_node_id(i.id, &self.save_ctxt)) .collect(); self.dumper.dump_def( &access_from!(self.save_ctxt, item), @@ -726,14 +731,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { self.dumper.dump_ref(Ref { kind: RefKind::Type, span: span.clone(), - ref_id: ::id_from_def_id(id), + ref_id: id_from_def_id(id), }); self.dumper.dump_relation(Relation { kind: RelationKind::SuperTrait, span, - from: ::id_from_def_id(id), - to: ::id_from_node_id(item.id, &self.save_ctxt), + from: id_from_def_id(id), + to: id_from_node_id(item.id, &self.save_ctxt), }); } } @@ -873,7 +878,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { self.dumper.dump_ref(Ref { kind: RefKind::Variable, span, - ref_id: ::id_from_def_id(variant.fields[index].did), + ref_id: id_from_def_id(variant.fields[index].did), }); } } @@ -912,7 +917,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { if !self.span.filter_generated(ident.span) { let qualname = format!("{}${}", ident.to_string(), id); - let id = ::id_from_node_id(id, &self.save_ctxt); + let id = id_from_node_id(id, &self.save_ctxt); let span = self.span_from_span(ident.span); self.dumper.dump_def( @@ -988,7 +993,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { // Rust uses the id of the pattern for var lookups, so we'll use it too. if !self.span.filter_generated(ident.span) { let qualname = format!("{}${}", ident.to_string(), id); - let id = ::id_from_node_id(id, &self.save_ctxt); + let id = id_from_node_id(id, &self.save_ctxt); let span = self.span_from_span(ident.span); self.dumper.dump_def( @@ -1091,7 +1096,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { if !self.span.filter_generated(trait_item.ident.span) { let span = self.span_from_span(trait_item.ident.span); - let id = ::id_from_node_id(trait_item.id, &self.save_ctxt); + let id = id_from_node_id(trait_item.id, &self.save_ctxt); self.dumper.dump_def( &Access { @@ -1105,7 +1110,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { name, qualname, value: self.span.snippet(trait_item.span), - parent: Some(::id_from_def_id(trait_id)), + parent: Some(id_from_def_id(trait_id)), children: vec![], decl_id: None, docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs), @@ -1196,7 +1201,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { // The parent def id of a given use tree is always the enclosing item. let parent = self.save_ctxt.tcx.hir().opt_local_def_id(id) .and_then(|id| self.save_ctxt.tcx.parent_def_id(id)) - .map(::id_from_def_id); + .map(id_from_def_id); match use_tree.kind { ast::UseTreeKind::Simple(alias, ..) => { @@ -1212,7 +1217,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { let sub_span = path.segments.last().unwrap().ident.span; if !self.span.filter_generated(sub_span) { - let ref_id = self.lookup_def_id(id).map(|id| ::id_from_def_id(id)); + let ref_id = self.lookup_def_id(id).map(|id| id_from_def_id(id)); let alias_span = alias.map(|i| self.span_from_span(i.span)); let span = self.span_from_span(sub_span); self.dumper.import(&access, Import { @@ -1298,10 +1303,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc let cm = self.tcx.sess.source_map(); let filename = cm.span_to_filename(span); - let data_id = ::id_from_node_id(id, &self.save_ctxt); + let data_id = id_from_node_id(id, &self.save_ctxt); let children = m.items .iter() - .map(|i| ::id_from_node_id(i.id, &self.save_ctxt)) + .map(|i| id_from_node_id(i.id, &self.save_ctxt)) .collect(); let span = self.span_from_span(span); @@ -1345,7 +1350,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc let span = self.span_from_span(name_span); let parent = self.save_ctxt.tcx.hir().opt_local_def_id(item.id) .and_then(|id| self.save_ctxt.tcx.parent_def_id(id)) - .map(::id_from_def_id); + .map(id_from_def_id); self.dumper.import( &Access { public: false, @@ -1387,7 +1392,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc let value = ty_to_string(&ty); if !self.span.filter_generated(item.ident.span) { let span = self.span_from_span(item.ident.span); - let id = ::id_from_node_id(item.id, &self.save_ctxt); + let id = id_from_node_id(item.id, &self.save_ctxt); self.dumper.dump_def( &access_from!(self.save_ctxt, item), @@ -1417,7 +1422,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc let value = String::new(); if !self.span.filter_generated(item.ident.span) { let span = self.span_from_span(item.ident.span); - let id = ::id_from_node_id(item.id, &self.save_ctxt); + let id = id_from_node_id(item.id, &self.save_ctxt); self.dumper.dump_def( &access_from!(self.save_ctxt, item), @@ -1476,7 +1481,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc self.dumper.dump_ref(Ref { kind: RefKind::Type, span, - ref_id: ::id_from_def_id(id), + ref_id: id_from_def_id(id), }); } diff --git a/src/librustc_save_analysis/json_dumper.rs b/src/librustc_save_analysis/json_dumper.rs index 3627c5577a626..1840cf652e1d5 100644 --- a/src/librustc_save_analysis/json_dumper.rs +++ b/src/librustc_save_analysis/json_dumper.rs @@ -7,6 +7,8 @@ use rls_data::{self, Analysis, CompilationOptions, CratePreludeData, Def, DefKin MacroRef, Ref, RefKind, Relation}; use rls_span::{Column, Row}; +use log::error; + #[derive(Debug)] pub struct Access { pub reachable: bool, @@ -23,7 +25,7 @@ pub trait DumpOutput { fn dump(&mut self, result: &Analysis); } -pub struct WriteOutput<'b, W: Write + 'b> { +pub struct WriteOutput<'b, W: Write> { output: &'b mut W, } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index b9d195d571568..cbab0cc4a1701 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -1,27 +1,10 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![feature(custom_attribute)] -#![feature(nll)] +#![deny(rust_2018_idioms)] #![allow(unused_attributes)] #![recursion_limit="256"] -#[macro_use] -extern crate rustc; - -#[macro_use] -extern crate log; -extern crate rustc_data_structures; -extern crate rustc_codegen_utils; -extern crate rustc_serialize; -extern crate rustc_target; -extern crate rustc_typeck; -#[macro_use] -extern crate syntax; -extern crate syntax_pos; - -extern crate rls_data; -extern crate rls_span; - mod json_dumper; mod dump_visitor; @@ -37,6 +20,7 @@ use rustc::middle::privacy::AccessLevels; use rustc::middle::cstore::ExternCrate; use rustc::session::config::{CrateType, Input, OutputType}; use rustc::ty::{self, TyCtxt}; +use rustc::{bug, span_bug}; use rustc_typeck::hir_ty_to_ty; use rustc_codegen_utils::link::{filename_for_metadata, out_filename}; use rustc_data_structures::sync::Lrc; @@ -64,6 +48,8 @@ use rls_data::{Def, DefKind, ExternalCrateData, GlobalCrateId, MacroRef, Ref, Re RelationKind, SpanData, Impl, ImplKind}; use rls_data::config::Config; +use log::{debug, error, info}; + pub struct SaveContext<'l, 'tcx: 'l> { tcx: TyCtxt<'l, 'tcx, 'tcx>, @@ -170,7 +156,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { ast::ForeignItemKind::Static(ref ty, _) => { filter!(self.span_utils, item.ident.span); - let id = ::id_from_node_id(item.id, self); + let id = id_from_node_id(item.id, self); let span = self.span_from_span(item.ident.span); Some(Data::DefData(Def { @@ -1027,7 +1013,7 @@ impl<'a> DumpHandler<'a> { } } - fn output_file(&self, ctx: &SaveContext) -> File { + fn output_file(&self, ctx: &SaveContext<'_, '_>) -> File { let sess = &ctx.tcx.sess; let file_name = match ctx.config.output_file { Some(ref s) => PathBuf::from(s), @@ -1178,7 +1164,7 @@ fn id_from_def_id(id: DefId) -> rls_data::Id { } } -fn id_from_node_id(id: NodeId, scx: &SaveContext) -> rls_data::Id { +fn id_from_node_id(id: NodeId, scx: &SaveContext<'_, '_>) -> rls_data::Id { let def_id = scx.tcx.hir().opt_local_def_id(id); def_id.map(|id| id_from_def_id(id)).unwrap_or_else(|| { // Create a *fake* `DefId` out of a `NodeId` by subtracting the `NodeId` @@ -1198,7 +1184,7 @@ fn null_id() -> rls_data::Id { } } -fn lower_attributes(attrs: Vec, scx: &SaveContext) -> Vec { +fn lower_attributes(attrs: Vec, scx: &SaveContext<'_, '_>) -> Vec { attrs.into_iter() // Only retain real attributes. Doc comments are lowered separately. .filter(|attr| attr.path != "doc") diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 7d4c0d0f9f56f..fcd6ad07cd88f 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -25,7 +25,7 @@ // // FIXME where clauses need implementing, defs/refs in generics are mostly missing. -use {id_from_def_id, id_from_node_id, SaveContext}; +use crate::{id_from_def_id, id_from_node_id, SaveContext}; use rls_data::{SigElement, Signature}; @@ -34,14 +34,17 @@ use syntax::ast::{self, NodeId}; use syntax::print::pprust; -pub fn item_signature(item: &ast::Item, scx: &SaveContext) -> Option { +pub fn item_signature(item: &ast::Item, scx: &SaveContext<'_, '_>) -> Option { if !scx.config.signatures { return None; } item.make(0, None, scx).ok() } -pub fn foreign_item_signature(item: &ast::ForeignItem, scx: &SaveContext) -> Option { +pub fn foreign_item_signature( + item: &ast::ForeignItem, + scx: &SaveContext<'_, '_> +) -> Option { if !scx.config.signatures { return None; } @@ -50,7 +53,7 @@ pub fn foreign_item_signature(item: &ast::ForeignItem, scx: &SaveContext) -> Opt /// Signature for a struct or tuple field declaration. /// Does not include a trailing comma. -pub fn field_signature(field: &ast::StructField, scx: &SaveContext) -> Option { +pub fn field_signature(field: &ast::StructField, scx: &SaveContext<'_, '_>) -> Option { if !scx.config.signatures { return None; } @@ -58,7 +61,7 @@ pub fn field_signature(field: &ast::StructField, scx: &SaveContext) -> Option Option { +pub fn variant_signature(variant: &ast::Variant, scx: &SaveContext<'_, '_>) -> Option { if !scx.config.signatures { return None; } @@ -70,7 +73,7 @@ pub fn method_signature( ident: ast::Ident, generics: &ast::Generics, m: &ast::MethodSig, - scx: &SaveContext, + scx: &SaveContext<'_, '_>, ) -> Option { if !scx.config.signatures { return None; @@ -83,7 +86,7 @@ pub fn assoc_const_signature( ident: ast::Name, ty: &ast::Ty, default: Option<&ast::Expr>, - scx: &SaveContext, + scx: &SaveContext<'_, '_>, ) -> Option { if !scx.config.signatures { return None; @@ -96,7 +99,7 @@ pub fn assoc_type_signature( ident: ast::Ident, bounds: Option<&ast::GenericBounds>, default: Option<&ast::Ty>, - scx: &SaveContext, + scx: &SaveContext<'_, '_>, ) -> Option { if !scx.config.signatures { return None; @@ -104,10 +107,10 @@ pub fn assoc_type_signature( make_assoc_type_signature(id, ident, bounds, default, scx).ok() } -type Result = ::std::result::Result; +type Result = std::result::Result; trait Sig { - fn make(&self, offset: usize, id: Option, scx: &SaveContext) -> Result; + fn make(&self, offset: usize, id: Option, scx: &SaveContext<'_, '_>) -> Result; } fn extend_sig( @@ -155,7 +158,7 @@ fn text_sig(text: String) -> Signature { } impl Sig for ast::Ty { - fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext) -> Result { + fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext<'_, '_>) -> Result { let id = Some(self.id); match self.node { ast::TyKind::Slice(ref ty) => { @@ -227,7 +230,7 @@ impl Sig for ast::Ty { if f.unsafety == ast::Unsafety::Unsafe { text.push_str("unsafe "); } - if f.abi != ::rustc_target::spec::abi::Abi::Rust { + if f.abi != rustc_target::spec::abi::Abi::Rust { text.push_str("extern"); text.push_str(&f.abi.to_string()); text.push(' '); @@ -317,7 +320,7 @@ impl Sig for ast::Ty { } impl Sig for ast::Item { - fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext) -> Result { + fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext<'_, '_>) -> Result { let id = Some(self.id); match self.node { @@ -381,7 +384,7 @@ impl Sig for ast::Item { if header.unsafety == ast::Unsafety::Unsafe { text.push_str("unsafe "); } - if header.abi != ::rustc_target::spec::abi::Abi::Rust { + if header.abi != rustc_target::spec::abi::Abi::Rust { text.push_str("extern"); text.push_str(&header.abi.to_string()); text.push(' '); @@ -571,7 +574,7 @@ impl Sig for ast::Item { } impl Sig for ast::Path { - fn make(&self, offset: usize, id: Option, scx: &SaveContext) -> Result { + fn make(&self, offset: usize, id: Option, scx: &SaveContext<'_, '_>) -> Result { let def = scx.get_path_def(id.ok_or("Missing id for Path")?); let (name, start, end) = match def { @@ -613,7 +616,7 @@ impl Sig for ast::Path { // This does not cover the where clause, which must be processed separately. impl Sig for ast::Generics { - fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext) -> Result { + fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext<'_, '_>) -> Result { if self.params.is_empty() { return Ok(text_sig(String::new())); } @@ -662,7 +665,7 @@ impl Sig for ast::Generics { } impl Sig for ast::StructField { - fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext) -> Result { + fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext<'_, '_>) -> Result { let mut text = String::new(); let mut defs = None; if let Some(ident) = self.ident { @@ -685,7 +688,7 @@ impl Sig for ast::StructField { impl Sig for ast::Variant_ { - fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext) -> Result { + fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext<'_, '_>) -> Result { let mut text = self.ident.to_string(); match self.data { ast::VariantData::Struct(ref fields, id) => { @@ -743,7 +746,7 @@ impl Sig for ast::Variant_ { } impl Sig for ast::ForeignItem { - fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext) -> Result { + fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext<'_, '_>) -> Result { let id = Some(self.id); match self.node { ast::ForeignItemKind::Fn(ref decl, ref generics) => { @@ -827,7 +830,7 @@ fn name_and_generics( generics: &ast::Generics, id: NodeId, name: ast::Ident, - scx: &SaveContext, + scx: &SaveContext<'_, '_>, ) -> Result { let name = name.to_string(); let def = SigElement { @@ -848,7 +851,7 @@ fn make_assoc_type_signature( ident: ast::Ident, bounds: Option<&ast::GenericBounds>, default: Option<&ast::Ty>, - scx: &SaveContext, + scx: &SaveContext<'_, '_>, ) -> Result { let mut text = "type ".to_owned(); let name = ident.to_string(); @@ -882,7 +885,7 @@ fn make_assoc_const_signature( ident: ast::Name, ty: &ast::Ty, default: Option<&ast::Expr>, - scx: &SaveContext, + scx: &SaveContext<'_, '_>, ) -> Result { let mut text = "const ".to_owned(); let name = ident.to_string(); @@ -915,7 +918,7 @@ fn make_method_signature( ident: ast::Ident, generics: &ast::Generics, m: &ast::MethodSig, - scx: &SaveContext, + scx: &SaveContext<'_, '_>, ) -> Result { // FIXME code dup with function signature let mut text = String::new(); @@ -928,7 +931,7 @@ fn make_method_signature( if m.header.unsafety == ast::Unsafety::Unsafe { text.push_str("unsafe "); } - if m.header.abi != ::rustc_target::spec::abi::Abi::Rust { + if m.header.abi != rustc_target::spec::abi::Abi::Rust { text.push_str("extern"); text.push_str(&m.header.abi.to_string()); text.push(' '); diff --git a/src/librustc_save_analysis/span_utils.rs b/src/librustc_save_analysis/span_utils.rs index 88c6012f71f69..e2c93b6d33158 100644 --- a/src/librustc_save_analysis/span_utils.rs +++ b/src/librustc_save_analysis/span_utils.rs @@ -1,6 +1,6 @@ use rustc::session::Session; -use generated_code; +use crate::generated_code; use std::cell::Cell; diff --git a/src/librustc_traits/implied_outlives_bounds.rs b/src/librustc_traits/implied_outlives_bounds.rs index a3fb96990545e..a1a846c1e537c 100644 --- a/src/librustc_traits/implied_outlives_bounds.rs +++ b/src/librustc_traits/implied_outlives_bounds.rs @@ -1,6 +1,7 @@ //! Provider for the `implied_outlives_bounds` query. //! Do not call this query directory. See [`rustc::traits::query::implied_outlives_bounds`]. +use rustc::hir; use rustc::infer::InferCtxt; use rustc::infer::canonical::{self, Canonical}; use rustc::traits::{TraitEngine, TraitEngineExt}; @@ -11,7 +12,6 @@ use rustc::ty::outlives::Component; use rustc::ty::query::Providers; use rustc::ty::wf; use smallvec::{SmallVec, smallvec}; -use syntax::ast::DUMMY_NODE_ID; use syntax::source_map::DUMMY_SP; use rustc::traits::FulfillmentContext; @@ -65,7 +65,7 @@ fn compute_implied_outlives_bounds<'tcx>( // unresolved inference variables here anyway, but there might be // during typeck under some circumstances.) let obligations = - wf::obligations(infcx, param_env, DUMMY_NODE_ID, ty, DUMMY_SP).unwrap_or(vec![]); + wf::obligations(infcx, param_env, hir::DUMMY_HIR_ID, ty, DUMMY_SP).unwrap_or(vec![]); // N.B., all of these predicates *ought* to be easily proven // true. In fact, their correctness is (mostly) implied by diff --git a/src/librustc_traits/normalize_projection_ty.rs b/src/librustc_traits/normalize_projection_ty.rs index b31e9c15d0367..c90d5a2c85000 100644 --- a/src/librustc_traits/normalize_projection_ty.rs +++ b/src/librustc_traits/normalize_projection_ty.rs @@ -1,3 +1,4 @@ +use rustc::hir; use rustc::infer::canonical::{Canonical, QueryResponse}; use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution}; use rustc::traits::{self, ObligationCause, SelectionContext, TraitEngineExt}; @@ -5,7 +6,6 @@ use rustc::ty::query::Providers; use rustc::ty::{ParamEnvAnd, TyCtxt}; use rustc_data_structures::sync::Lrc; use std::sync::atomic::Ordering; -use syntax::ast::DUMMY_NODE_ID; use syntax_pos::DUMMY_SP; crate fn provide(p: &mut Providers) { @@ -34,7 +34,7 @@ fn normalize_projection_ty<'tcx>( value: goal, }| { let selcx = &mut SelectionContext::new(infcx); - let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID); + let cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID); let mut obligations = vec![]; let answer = traits::normalize_projection_type( selcx, diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index 526637e108d40..fbb89f54ad886 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -1,6 +1,7 @@ use rustc::infer::at::ToTrace; use rustc::infer::canonical::{Canonical, QueryResponse}; use rustc::infer::InferCtxt; +use rustc::hir; use rustc::hir::def_id::DefId; use rustc::traits::query::type_op::ascribe_user_type::AscribeUserType; use rustc::traits::query::type_op::eq::Eq; @@ -18,7 +19,6 @@ use rustc::ty::{ }; use rustc_data_structures::sync::Lrc; use std::fmt; -use syntax::ast; use syntax_pos::DUMMY_SP; crate fn provide(p: &mut Providers) { @@ -71,7 +71,7 @@ impl AscribeUserTypeCx<'me, 'gcx, 'tcx> { self.infcx .partially_normalize_associated_types_in( DUMMY_SP, - ast::CRATE_NODE_ID, + hir::CRATE_HIR_ID, self.param_env, &value, ) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 8da0b6dcbeac3..ae7ec7f0120aa 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -111,7 +111,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { { let tcx = self.tcx(); let lifetime_name = |def_id| { - tcx.hir().name(tcx.hir().as_local_node_id(def_id).unwrap()).as_interned_str() + tcx.hir().name_by_hir_id(tcx.hir().as_local_hir_id(def_id).unwrap()).as_interned_str() }; let r = match tcx.named_region(lifetime.hir_id) { @@ -878,8 +878,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { binding.item_name, binding.span) }?; + let hir_ref_id = self.tcx().hir().node_to_hir_id(ref_id); let (assoc_ident, def_scope) = - tcx.adjust_ident(binding.item_name, candidate.def_id(), ref_id); + tcx.adjust_ident(binding.item_name, candidate.def_id(), hir_ref_id); let assoc_ty = tcx.associated_items(candidate.def_id()).find(|i| { i.kind == ty::AssociatedKind::Type && i.ident.modern() == assoc_ident }).expect("missing associated type"); @@ -1373,7 +1374,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { }; let trait_did = bound.def_id(); - let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_ident, trait_did, ref_id); + let hir_ref_id = self.tcx().hir().node_to_hir_id(ref_id); + let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_ident, trait_did, hir_ref_id); let item = tcx.associated_items(trait_did).find(|i| { Namespace::from(i.kind) == Namespace::Type && i.ident.modern() == assoc_ident @@ -1682,12 +1684,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { assert_eq!(opt_self_ty, None); self.prohibit_generics(&path.segments); - let node_id = tcx.hir().as_local_node_id(did).unwrap(); - let item_id = tcx.hir().get_parent_node(node_id); - let item_def_id = tcx.hir().local_def_id(item_id); + let hir_id = tcx.hir().as_local_hir_id(did).unwrap(); + let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id); + let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id); let generics = tcx.generics_of(item_def_id); - let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(node_id)]; - tcx.mk_ty_param(index, tcx.hir().name(node_id).as_interned_str()) + let index = generics.param_def_id_to_index[ + &tcx.hir().local_def_id_from_hir_id(hir_id)]; + tcx.mk_ty_param(index, tcx.hir().name_by_hir_id(hir_id).as_interned_str()) } Def::SelfTy(_, Some(def_id)) => { // `Self` in impl (we know the concrete type). diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index 35ac4f3957eb4..f863cfe1887db 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -1,6 +1,7 @@ use super::{FnCtxt, PlaceOp, Needs}; use super::method::MethodCallee; +use rustc::hir; use rustc::infer::{InferCtxt, InferOk}; use rustc::session::DiagnosticMessageId; use rustc::traits::{self, TraitEngine}; @@ -9,7 +10,7 @@ use rustc::ty::{ToPredicate, TypeFoldable}; use rustc::ty::adjustment::{Adjustment, Adjust, OverloadedDeref}; use syntax_pos::Span; -use syntax::ast::{self, Ident}; +use syntax::ast::Ident; use std::iter; @@ -21,7 +22,7 @@ enum AutoderefKind { pub struct Autoderef<'a, 'gcx: 'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, steps: Vec<(Ty<'tcx>, AutoderefKind)>, cur_ty: Ty<'tcx>, @@ -87,7 +88,7 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> { pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId, + body_id: hir::HirId, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'gcx, 'tcx> diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index df83c92fde5b4..1f52a9f3ee857 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -641,7 +641,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .liberate_late_bound_regions(expr_def_id, &bound_sig); let liberated_sig = self.inh.normalize_associated_types_in( body.value.span, - body.value.id, + body.value.hir_id, self.param_env, &liberated_sig, ); diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 0eb8d7d06b1f6..5f16e6e8e9e93 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -84,10 +84,11 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // `ObligationCause` (and the `FnCtxt`). This is what // `regionck_item` expects. let impl_m_node_id = tcx.hir().as_local_node_id(impl_m.def_id).unwrap(); + let impl_m_hir_id = tcx.hir().node_to_hir_id(impl_m_node_id); let cause = ObligationCause { span: impl_m_span, - body_id: impl_m_node_id, + body_id: impl_m_hir_id, code: ObligationCauseCode::CompareImplMethodObligation { item_name: impl_m.ident.name, impl_item_def_id: impl_m.def_id, @@ -205,7 +206,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Construct trait parameter environment and then shift it into the placeholder viewpoint. // The key step here is to update the caller_bounds's predicates to be // the new hybrid bounds we computed. - let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_node_id); + let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_hir_id); let param_env = ty::ParamEnv::new( tcx.intern_predicates(&hybrid_preds.predicates), Reveal::UserFacing, @@ -262,7 +263,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ); let impl_sig = inh.normalize_associated_types_in(impl_m_span, - impl_m_node_id, + impl_m_hir_id, param_env, &impl_sig); let impl_fty = tcx.mk_fn_ptr(ty::Binder::bind(impl_sig)); @@ -275,7 +276,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_sig.subst(tcx, trait_to_skol_substs); let trait_sig = inh.normalize_associated_types_in(impl_m_span, - impl_m_node_id, + impl_m_hir_id, param_env, &trait_sig); let trait_fty = tcx.mk_fn_ptr(ty::Binder::bind(trait_sig)); @@ -347,8 +348,8 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Finally, resolve all regions. This catches wily misuses of // lifetime parameters. - let fcx = FnCtxt::new(&inh, param_env, impl_m_node_id); - fcx.regionck_item(impl_m_node_id, impl_m_span, &[]); + let fcx = FnCtxt::new(&inh, param_env, impl_m_hir_id); + fcx.regionck_item(impl_m_hir_id, impl_m_span, &[]); Ok(()) }) @@ -736,8 +737,8 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, in impl_m_type_params.zip(trait_m_type_params) { if impl_synthetic != trait_synthetic { - let impl_node_id = tcx.hir().as_local_node_id(impl_def_id).unwrap(); - let impl_span = tcx.hir().span(impl_node_id); + let impl_hir_id = tcx.hir().as_local_hir_id(impl_def_id).unwrap(); + let impl_span = tcx.hir().span_by_hir_id(impl_hir_id); let trait_span = tcx.def_span(trait_def_id); let mut err = struct_span_err!(tcx.sess, impl_span, @@ -840,7 +841,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, match param.kind { GenericParamKind::Lifetime { .. } => None, GenericParamKind::Type { .. } => { - if param.id == impl_node_id { + if param.hir_id == impl_hir_id { Some(¶m.bounds) } else { None @@ -903,22 +904,23 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Create a parameter environment that represents the implementation's // method. let impl_c_node_id = tcx.hir().as_local_node_id(impl_c.def_id).unwrap(); + let impl_c_hir_id = tcx.hir().node_to_hir_id(impl_c_node_id); // Compute placeholder form of impl and trait const tys. let impl_ty = tcx.type_of(impl_c.def_id); let trait_ty = tcx.type_of(trait_c.def_id).subst(tcx, trait_to_impl_substs); - let mut cause = ObligationCause::misc(impl_c_span, impl_c_node_id); + let mut cause = ObligationCause::misc(impl_c_span, impl_c_hir_id); // There is no "body" here, so just pass dummy id. let impl_ty = inh.normalize_associated_types_in(impl_c_span, - impl_c_node_id, + impl_c_hir_id, param_env, &impl_ty); debug!("compare_const_impl: impl_ty={:?}", impl_ty); let trait_ty = inh.normalize_associated_types_in(impl_c_span, - impl_c_node_id, + impl_c_hir_id, param_env, &trait_ty); @@ -973,7 +975,7 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return; } - let fcx = FnCtxt::new(&inh, param_env, impl_c_node_id); - fcx.regionck_item(impl_c_node_id, impl_c_span, &[]); + let fcx = FnCtxt::new(&inh, param_env, impl_c_hir_id); + fcx.regionck_item(impl_c_hir_id, impl_c_span, &[]); }); } diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 60b5db0d12cc4..bb045f093d5f7 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -1,5 +1,6 @@ use check::regionck::RegionCtxt; +use hir; use hir::def_id::DefId; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::{self, InferOk, SuppressRegionErrors}; @@ -9,7 +10,6 @@ use rustc::ty::subst::{Subst, Substs, UnpackedKind}; use rustc::ty::{self, Ty, TyCtxt}; use util::common::ErrorReported; -use syntax::ast; use syntax_pos::Span; /// check_drop_impl confirms that the Drop implementation identified by @@ -70,7 +70,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>( drop_impl_ty: Ty<'tcx>, self_type_did: DefId, ) -> Result<(), ErrorReported> { - let drop_impl_node_id = tcx.hir().as_local_node_id(drop_impl_did).unwrap(); + let drop_impl_hir_id = tcx.hir().as_local_hir_id(drop_impl_did).unwrap(); // check that the impl type can be made to match the trait type. @@ -85,7 +85,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>( let fresh_impl_substs = infcx.fresh_substs_for_item(drop_impl_span, drop_impl_did); let fresh_impl_self_ty = drop_impl_ty.subst(tcx, fresh_impl_substs); - let cause = &ObligationCause::misc(drop_impl_span, drop_impl_node_id); + let cause = &ObligationCause::misc(drop_impl_span, drop_impl_hir_id); match infcx .at(cause, impl_param_env) .eq(named_type, fresh_impl_self_ty) @@ -184,7 +184,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>( // absent. So we report an error that the Drop impl injected a // predicate that is not present on the struct definition. - let self_type_node_id = tcx.hir().as_local_node_id(self_type_did).unwrap(); + let self_type_hir_id = tcx.hir().as_local_hir_id(self_type_did).unwrap(); let drop_impl_span = tcx.def_span(drop_impl_did); @@ -216,7 +216,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>( // repeated `contains` calls. if !assumptions_in_impl_context.contains(&predicate) { - let item_span = tcx.hir().span(self_type_node_id); + let item_span = tcx.hir().span_by_hir_id(self_type_hir_id); struct_span_err!( tcx.sess, drop_impl_span, @@ -292,7 +292,7 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'gcx, 'tcx>( rcx: &mut RegionCtxt<'a, 'gcx, 'tcx>, ty: Ty<'tcx>, span: Span, - body_id: ast::NodeId, + body_id: hir::HirId, scope: region::Scope, ) -> Result<(), ErrorReported> { debug!("check_safety_of_destructor_if_necessary typ: {:?} scope: {:?}", diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 82d4300d99687..3ddf20a823c39 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -58,7 +58,7 @@ fn equate_intrinsic_type<'a, 'tcx>( safety, abi ))); - let cause = ObligationCause::new(it.span, it.id, ObligationCauseCode::IntrinsicType); + let cause = ObligationCause::new(it.span, it.hir_id, ObligationCauseCode::IntrinsicType); require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(def_id)), fty); } diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 623677482db34..a9c4d0676a68e 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -370,7 +370,7 @@ fn method_autoderef_steps<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, tcx.infer_ctxt().enter_with_canonical(DUMMY_SP, &goal, |ref infcx, goal, inference_vars| { let ParamEnvAnd { param_env, value: self_ty } = goal; - let mut autoderef = Autoderef::new(infcx, param_env, ast::DUMMY_NODE_ID, DUMMY_SP, self_ty) + let mut autoderef = Autoderef::new(infcx, param_env, hir::DUMMY_HIR_ID, DUMMY_SP, self_ty) .include_raw_pointers() .silence_errors(); let mut reached_raw_pointer = false; @@ -1137,7 +1137,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { stable_pick: &Pick, unstable_candidates: &[(&Candidate<'tcx>, Symbol)], ) { - let mut diag = self.tcx.struct_span_lint_node( + let mut diag = self.tcx.struct_span_lint_hir( lint::builtin::UNSTABLE_NAME_COLLISIONS, self.fcx.body_id, self.span, diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 55b6e8f099ea9..055412b411767 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -346,7 +346,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }; let field_ty = field.ty(tcx, substs); - let scope = self.tcx.hir().get_module_parent(self.body_id); + let scope = self.tcx.hir().get_module_parent_by_hir_id( + self.body_id); if field.vis.is_accessible_from(scope, self.tcx) { if self.is_fn_ty(&field_ty, span) { err.help(&format!("use `({0}.{1})(...)` if you \ @@ -499,7 +500,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { err: &mut DiagnosticBuilder, mut msg: String, candidates: Vec) { - let module_did = self.tcx.hir().get_module_parent(self.body_id); + let module_did = self.tcx.hir().get_module_parent_by_hir_id(self.body_id); let module_id = self.tcx.hir().as_local_node_id(module_did).unwrap(); let krate = self.tcx.hir().krate(); let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 3e2a9d720f1c1..c21415a9e3a07 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -510,7 +510,7 @@ impl<'gcx, 'tcx> EnclosingBreakables<'gcx, 'tcx> { } pub struct FnCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { - body_id: ast::NodeId, + body_id: hir::HirId, /// The parameter environment used for proving trait obligations /// in this function. This can change when we descend into @@ -672,7 +672,7 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> { fn normalize_associated_types_in(&self, span: Span, - body_id: ast::NodeId, + body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, value: &T) -> T where T : TypeFoldable<'tcx> @@ -861,14 +861,14 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx.liberate_late_bound_regions(def_id, &fn_sig); let fn_sig = inh.normalize_associated_types_in(body.value.span, - body_id.node_id, + body_id.hir_id, param_env, &fn_sig); let fcx = check_fn(&inh, param_env, fn_sig, decl, id, body, None).0; fcx } else { - let fcx = FnCtxt::new(&inh, param_env, body.value.id); + let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id); let expected_type = tcx.type_of(def_id); let expected_type = fcx.normalize_associated_types_in(body.value.span, &expected_type); fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized); @@ -1062,7 +1062,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // Create the function context. This is either derived from scratch or, // in the case of closures, based on the outer context. - let mut fcx = FnCtxt::new(inherited, param_env, body.value.id); + let mut fcx = FnCtxt::new(inherited, param_env, body.value.hir_id); *fcx.ps.borrow_mut() = UnsafetyState::function(fn_sig.unsafety, fn_id); let declared_ret_ty = fn_sig.output(); @@ -1169,8 +1169,9 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, let substs = fcx.tcx.mk_substs_trait(declared_ret_ty, &[]); let trait_ref = ty::TraitRef::new(term_id, substs); let return_ty_span = decl.output.span(); + let fn_hir_id = fcx.tcx.hir().node_to_hir_id(fn_id); let cause = traits::ObligationCause::new( - return_ty_span, fn_id, ObligationCauseCode::MainFunctionType); + return_ty_span, fn_hir_id, ObligationCauseCode::MainFunctionType); inherited.register_predicate( traits::Obligation::new( @@ -1883,14 +1884,14 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Check for duplicate discriminant values if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) { let variant_did = def.variants[VariantIdx::new(i)].did; - let variant_i_node_id = tcx.hir().as_local_node_id(variant_did).unwrap(); - let variant_i = tcx.hir().expect_variant(variant_i_node_id); + let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did).unwrap(); + let variant_i = tcx.hir().expect_variant(variant_i_hir_id); let i_span = match variant_i.node.disr_expr { - Some(ref expr) => tcx.hir().span(expr.id), - None => tcx.hir().span(variant_i_node_id) + Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id), + None => tcx.hir().span_by_hir_id(variant_i_hir_id) }; let span = match v.node.disr_expr { - Some(ref expr) => tcx.hir().span(expr.id), + Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id), None => v.span }; struct_span_err!(tcx.sess, span, E0081, @@ -2022,7 +2023,7 @@ enum TupleArgumentsFlag { impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn new(inh: &'a Inherited<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - body_id: ast::NodeId) + body_id: hir::HirId) -> FnCtxt<'a, 'gcx, 'tcx> { FnCtxt { body_id, @@ -5703,8 +5704,8 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }); for (&used, param) in types_used.iter().zip(types) { if !used { - let id = tcx.hir().as_local_node_id(param.def_id).unwrap(); - let span = tcx.hir().span(id); + let id = tcx.hir().as_local_hir_id(param.def_id).unwrap(); + let span = tcx.hir().span_by_hir_id(id); struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param.name) .span_label(span, "unused type parameter") .emit(); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index b90c18eb41cb5..1c946208b2403 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -112,7 +112,7 @@ macro_rules! ignore_err { impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn regionck_expr(&self, body: &'gcx hir::Body) { let subject = self.tcx.hir().body_owner_def_id(body.id()); - let id = body.value.id; + let id = body.value.hir_id; let mut rcx = RegionCtxt::new( self, RepeatingScope(id), @@ -138,9 +138,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// Region checking during the WF phase for items. `wf_tys` are the /// types from which we should derive implied bounds, if any. - pub fn regionck_item(&self, item_id: ast::NodeId, span: Span, wf_tys: &[Ty<'tcx>]) { + pub fn regionck_item(&self, item_id: hir::HirId, span: Span, wf_tys: &[Ty<'tcx>]) { debug!("regionck_item(item.id={:?}, wf_tys={:?})", item_id, wf_tys); - let subject = self.tcx.hir().local_def_id(item_id); + let subject = self.tcx.hir().local_def_id_from_hir_id(item_id); let mut rcx = RegionCtxt::new( self, RepeatingScope(item_id), @@ -166,18 +166,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn regionck_fn(&self, fn_id: ast::NodeId, body: &'gcx hir::Body) { debug!("regionck_fn(id={})", fn_id); let subject = self.tcx.hir().body_owner_def_id(body.id()); - let node_id = body.value.id; + let hir_id = body.value.hir_id; let mut rcx = RegionCtxt::new( self, - RepeatingScope(node_id), - node_id, + RepeatingScope(hir_id), + hir_id, Subject(subject), self.param_env, ); if self.err_count_since_creation() == 0 { + let fn_hir_id = self.tcx.hir().node_to_hir_id(fn_id); // regionck assumes typeck succeeded - rcx.visit_fn_body(fn_id, body, self.tcx.hir().span(fn_id)); + rcx.visit_fn_body(fn_hir_id, body, self.tcx.hir().span_by_hir_id(fn_hir_id)); } rcx.resolve_regions_and_report_errors(SuppressRegionErrors::when_nll_is_enabled(self.tcx)); @@ -201,13 +202,13 @@ pub struct RegionCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { outlives_environment: OutlivesEnvironment<'tcx>, // id of innermost fn body id - body_id: ast::NodeId, + body_id: hir::HirId, // call_site scope of innermost fn call_site_scope: Option, // id of innermost fn or loop - repeating_scope: ast::NodeId, + repeating_scope: hir::HirId, // id of AST node being analyzed (the subject of the analysis). subject_def_id: DefId, @@ -220,14 +221,14 @@ impl<'a, 'gcx, 'tcx> Deref for RegionCtxt<'a, 'gcx, 'tcx> { } } -pub struct RepeatingScope(ast::NodeId); +pub struct RepeatingScope(hir::HirId); pub struct Subject(DefId); impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { pub fn new( fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, RepeatingScope(initial_repeating_scope): RepeatingScope, - initial_body_id: ast::NodeId, + initial_body_id: hir::HirId, Subject(subject): Subject, param_env: ty::ParamEnv<'tcx>, ) -> RegionCtxt<'a, 'gcx, 'tcx> { @@ -244,7 +245,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { } } - fn set_repeating_scope(&mut self, scope: ast::NodeId) -> ast::NodeId { + fn set_repeating_scope(&mut self, scope: hir::HirId) -> hir::HirId { mem::replace(&mut self.repeating_scope, scope) } @@ -301,15 +302,15 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { /// `intravisit::Visitor` impl below.) fn visit_fn_body( &mut self, - id: ast::NodeId, // the id of the fn itself + id: hir::HirId, // the id of the fn itself body: &'gcx hir::Body, span: Span, ) { // When we enter a function, we can derive - debug!("visit_fn_body(id={})", id); + debug!("visit_fn_body(id={:?})", id); let body_id = body.id(); - self.body_id = body_id.node_id; + self.body_id = body_id.hir_id; let call_site = region::Scope { id: body.value.hir_id.local_id, @@ -318,11 +319,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { self.call_site_scope = Some(call_site); let fn_sig = { - let fn_hir_id = self.tcx.hir().node_to_hir_id(id); - match self.tables.borrow().liberated_fn_sigs().get(fn_hir_id) { + match self.tables.borrow().liberated_fn_sigs().get(id) { Some(f) => f.clone(), None => { - bug!("No fn-sig entry for id={}", id); + bug!("No fn-sig entry for id={:?}", id); } } }; @@ -342,11 +342,11 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { self.outlives_environment.add_implied_bounds( self.fcx, &fn_sig_tys[..], - body_id.node_id, + body_id.hir_id, span, ); self.outlives_environment - .save_implied_bounds(body_id.node_id); + .save_implied_bounds(body_id.hir_id); self.link_fn_args( region::Scope { id: body.value.hir_id.local_id, @@ -355,7 +355,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { &body.arguments, ); self.visit_body(body); - self.visit_region_obligations(body_id.node_id); + self.visit_region_obligations(body_id.hir_id); let call_site_scope = self.call_site_scope.unwrap(); debug!( @@ -365,8 +365,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { ); let call_site_region = self.tcx.mk_region(ty::ReScope(call_site_scope)); - let body_hir_id = self.tcx.hir().node_to_hir_id(body_id.node_id); - self.type_of_node_must_outlive(infer::CallReturn(span), body_hir_id, call_site_region); + self.type_of_node_must_outlive(infer::CallReturn(span), body_id.hir_id, call_site_region); self.constrain_opaque_types( &self.fcx.opaque_types.borrow(), @@ -374,8 +373,8 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { ); } - fn visit_region_obligations(&mut self, node_id: ast::NodeId) { - debug!("visit_region_obligations: node_id={}", node_id); + fn visit_region_obligations(&mut self, hir_id: hir::HirId) { + debug!("visit_region_obligations: hir_id={:?}", hir_id); // region checking can introduce new pending obligations // which, when processed, might generate new region @@ -474,7 +473,8 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { let env_snapshot = self.outlives_environment.push_snapshot_pre_closure(); let body = self.tcx.hir().body(body_id); - self.visit_fn_body(id, body, span); + let hir_id = self.tcx.hir().node_to_hir_id(id); + self.visit_fn_body(hir_id, body, span); // Restore state from previous function. self.outlives_environment @@ -502,7 +502,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { fn visit_expr(&mut self, expr: &'gcx hir::Expr) { debug!( - "regionck::visit_expr(e={:?}, repeating_scope={})", + "regionck::visit_expr(e={:?}, repeating_scope={:?})", expr, self.repeating_scope ); @@ -555,7 +555,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { } debug!( - "regionck::visit_expr(e={:?}, repeating_scope={}) - visiting subexprs", + "regionck::visit_expr(e={:?}, repeating_scope={:?}) - visiting subexprs", expr, self.repeating_scope ); match expr.node { @@ -679,16 +679,16 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { } hir::ExprKind::Loop(ref body, _, _) => { - let repeating_scope = self.set_repeating_scope(body.id); + let repeating_scope = self.set_repeating_scope(body.hir_id); intravisit::walk_expr(self, expr); self.set_repeating_scope(repeating_scope); } hir::ExprKind::While(ref cond, ref body, _) => { - let repeating_scope = self.set_repeating_scope(cond.id); + let repeating_scope = self.set_repeating_scope(cond.hir_id); self.visit_expr(&cond); - self.set_repeating_scope(body.id); + self.set_repeating_scope(body.hir_id); self.visit_block(&body); self.set_repeating_scope(repeating_scope); @@ -758,7 +758,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { } fn check_expr_fn_block(&mut self, expr: &'gcx hir::Expr, body_id: hir::BodyId) { - let repeating_scope = self.set_repeating_scope(body_id.node_id); + let repeating_scope = self.set_repeating_scope(body_id.hir_id); intravisit::walk_expr(self, expr); self.set_repeating_scope(repeating_scope); } diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index ffd7c2114e5ab..15ae0166b93cb 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -650,6 +650,5 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> { } fn var_name(tcx: TyCtxt, var_hir_id: hir::HirId) -> ast::Name { - let var_node_id = tcx.hir().hir_to_node_id(var_hir_id); - tcx.hir().name(var_node_id) + tcx.hir().name_by_hir_id(var_hir_id) } diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 97881708b0a07..78bfac16e2971 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -22,7 +22,7 @@ use rustc::hir; /// `F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(FnCtxt<'b, 'gcx, 'tcx>)`. struct CheckWfFcxBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { inherited: super::InheritedBuilder<'a, 'gcx, 'tcx>, - id: ast::NodeId, + id: hir::HirId, span: Span, param_env: ty::ParamEnv<'tcx>, } @@ -62,11 +62,11 @@ impl<'a, 'gcx, 'tcx> CheckWfFcxBuilder<'a, 'gcx, 'tcx> { /// not included it frequently leads to confusing errors in fn bodies. So it's better to check /// the types first. pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let item = tcx.hir().expect_item(node_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let item = tcx.hir().expect_item_by_hir_id(hir_id); - debug!("check_item_well_formed(it.id={}, it.name={})", - item.id, + debug!("check_item_well_formed(it.hir_id={:?}, it.name={})", + item.hir_id, tcx.item_path_str(def_id)); match item.node { @@ -88,7 +88,7 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def // won't be allowed unless there's an *explicit* implementation of `Send` // for `T` hir::ItemKind::Impl(_, polarity, defaultness, _, ref trait_ref, ref self_ty, _) => { - let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id(item.id)) + let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id_from_hir_id(item.hir_id)) .map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id)); if let (hir::Defaultness::Default { .. }, true) = (defaultness, is_auto) { tcx.sess.span_err(item.span, "impls of auto traits cannot be default"); @@ -226,9 +226,10 @@ fn for_item<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, item: &hir::Item) fn for_id<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, id: ast::NodeId, span: Span) -> CheckWfFcxBuilder<'a, 'gcx, 'tcx> { let def_id = tcx.hir().local_def_id(id); + let hir_id = tcx.hir().node_to_hir_id(id); CheckWfFcxBuilder { inherited: Inherited::build(tcx, def_id), - id, + id: hir_id, span, param_env: tcx.param_env(def_id), } @@ -968,13 +969,13 @@ fn reject_shadowing_parameters(tcx: TyCtxt, def_id: DefId) { fn check_false_global_bounds<'a, 'gcx, 'tcx>( fcx: &FnCtxt<'a, 'gcx, 'tcx>, span: Span, - id: ast::NodeId) + id: hir::HirId) { use rustc::ty::TypeFoldable; let empty_env = ty::ParamEnv::empty(); - let def_id = fcx.tcx.hir().local_def_id(id); + let def_id = fcx.tcx.hir().local_def_id_from_hir_id(id); let predicates = fcx.tcx.predicates_of(def_id).predicates .iter() .map(|(p, _)| *p) diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 238b087fe32f8..fc1229eaf6ac9 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -100,7 +100,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { body: &'gcx hir::Body, rustc_dump_user_substs: bool, ) -> WritebackCx<'cx, 'gcx, 'tcx> { - let owner = fcx.tcx.hir().definitions().node_to_hir_id(body.id().node_id); + let owner = body.id().hir_id; WritebackCx { fcx, @@ -407,8 +407,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { if let ty::UserType::TypeOf(_, user_substs) = c_ty.value { if self.rustc_dump_user_substs { // This is a unit-testing mechanism. - let node_id = self.tcx().hir().hir_to_node_id(hir_id); - let span = self.tcx().hir().span(node_id); + let span = self.tcx().hir().span_by_hir_id(hir_id); // We need to buffer the errors in order to guarantee a consistent // order when emitting them. let err = self.tcx().sess.struct_span_err( @@ -739,15 +738,14 @@ impl Locatable for ast::NodeId { impl Locatable for DefIndex { fn to_span(&self, tcx: &TyCtxt) -> Span { - let node_id = tcx.hir().def_index_to_node_id(*self); - tcx.hir().span(node_id) + let hir_id = tcx.hir().def_index_to_hir_id(*self); + tcx.hir().span_by_hir_id(hir_id) } } impl Locatable for hir::HirId { fn to_span(&self, tcx: &TyCtxt) -> Span { - let node_id = tcx.hir().hir_to_node_id(*self); - tcx.hir().span(node_id) + tcx.hir().span_by_hir_id(*self) } } diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index bd2373d1659c9..0996d1ff3b998 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -76,7 +76,7 @@ fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: DefId) { debug!("visit_implementation_of_copy: impl_did={:?}", impl_did); - let impl_node_id = if let Some(n) = tcx.hir().as_local_node_id(impl_did) { + let impl_hir_id = if let Some(n) = tcx.hir().as_local_hir_id(impl_did) { n } else { debug!("visit_implementation_of_copy(): impl not in this crate"); @@ -87,7 +87,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type); - let span = tcx.hir().span(impl_node_id); + let span = tcx.hir().span_by_hir_id(impl_hir_id); let param_env = tcx.param_env(impl_did); assert!(!self_type.has_escaping_bound_vars()); @@ -97,7 +97,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: match param_env.can_type_implement_copy(tcx, self_type) { Ok(()) => {} Err(CopyImplementationError::InfrigingFields(fields)) => { - let item = tcx.hir().expect_item(impl_node_id); + let item = tcx.hir().expect_item_by_hir_id(impl_hir_id); let span = if let ItemKind::Impl(.., Some(ref tr), _, _) = item.node { tr.path.span } else { @@ -114,7 +114,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: err.emit() } Err(CopyImplementationError::NotAnAdt) => { - let item = tcx.hir().expect_item(impl_node_id); + let item = tcx.hir().expect_item_by_hir_id(impl_hir_id); let span = if let ItemKind::Impl(.., ref ty, _) = item.node { ty.span } else { @@ -162,8 +162,8 @@ fn visit_implementation_of_dispatch_from_dyn<'a, 'tcx>( if impl_did.is_local() { let dispatch_from_dyn_trait = tcx.lang_items().dispatch_from_dyn_trait().unwrap(); - let impl_node_id = tcx.hir().as_local_node_id(impl_did).unwrap(); - let span = tcx.hir().span(impl_node_id); + let impl_hir_id = tcx.hir().as_local_hir_id(impl_did).unwrap(); + let span = tcx.hir().span_by_hir_id(impl_hir_id); let source = tcx.type_of(impl_did); assert!(!source.has_escaping_bound_vars()); @@ -185,7 +185,7 @@ fn visit_implementation_of_dispatch_from_dyn<'a, 'tcx>( }; tcx.infer_ctxt().enter(|infcx| { - let cause = ObligationCause::misc(span, impl_node_id); + let cause = ObligationCause::misc(span, impl_hir_id); use ty::TyKind::*; match (&source.sty, &target.sty) { @@ -332,7 +332,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, }); // this provider should only get invoked for local def-ids - let impl_node_id = gcx.hir().as_local_node_id(impl_did).unwrap_or_else(|| { + let impl_hir_id = gcx.hir().as_local_hir_id(impl_did).unwrap_or_else(|| { bug!("coerce_unsized_info: invoked for non-local def-id {:?}", impl_did) }); @@ -344,7 +344,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, source, target); - let span = gcx.hir().span(impl_node_id); + let span = gcx.hir().span_by_hir_id(impl_hir_id); let param_env = gcx.param_env(impl_did); assert!(!source.has_escaping_bound_vars()); @@ -355,7 +355,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, target); gcx.infer_ctxt().enter(|infcx| { - let cause = ObligationCause::misc(span, impl_node_id); + let cause = ObligationCause::misc(span, impl_hir_id); let check_mutbl = |mt_a: ty::TypeAndMut<'gcx>, mt_b: ty::TypeAndMut<'gcx>, mk_ptr: &dyn Fn(Ty<'gcx>) -> Ty<'gcx>| { @@ -481,11 +481,11 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, being coerced, none found"); return err_info; } else if diff_fields.len() > 1 { - let item = gcx.hir().expect_item(impl_node_id); + let item = gcx.hir().expect_item_by_hir_id(impl_hir_id); let span = if let ItemKind::Impl(.., Some(ref t), _, _) = item.node { t.path.span } else { - gcx.hir().span(impl_node_id) + gcx.hir().span_by_hir_id(impl_hir_id) }; let mut err = struct_span_err!(gcx.sess, @@ -527,7 +527,7 @@ pub fn coerce_unsized_info<'a, 'gcx>(gcx: TyCtxt<'a, 'gcx, 'gcx>, let mut fulfill_cx = TraitEngine::new(infcx.tcx); // Register an obligation for `A: Trait`. - let cause = traits::ObligationCause::misc(span, impl_node_id); + let cause = traits::ObligationCause::misc(span, impl_hir_id); let predicate = gcx.predicate_for_trait_def(param_env, cause, trait_def_id, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 9dc74c5d63a4e..f5e50678040f6 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -737,8 +737,8 @@ fn super_predicates_of<'a, 'tcx>( } fn trait_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::TraitDef { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let item = tcx.hir().expect_item(node_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let item = tcx.hir().expect_item_by_hir_id(hir_id); let (is_auto, unsafety) = match item.node { hir::ItemKind::Trait(is_auto, unsafety, ..) => (is_auto == hir::IsAuto::Yes, unsafety), @@ -1509,8 +1509,8 @@ fn impl_trait_ref<'a, 'tcx>( ) -> Option> { let icx = ItemCtxt::new(tcx, def_id); - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - match tcx.hir().expect_item(node_id).node { + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + match tcx.hir().expect_item_by_hir_id(hir_id).node { hir::ItemKind::Impl(.., ref opt_trait_ref, _, _) => { opt_trait_ref.as_ref().map(|ast_trait_ref| { let selfty = tcx.type_of(def_id); @@ -1522,8 +1522,8 @@ fn impl_trait_ref<'a, 'tcx>( } fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> hir::ImplPolarity { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - match tcx.hir().expect_item(node_id).node { + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + match tcx.hir().expect_item_by_hir_id(hir_id).node { hir::ItemKind::Impl(_, polarity, ..) => polarity, ref item => bug!("impl_polarity: {:?} not an impl", item), } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 8d77310f3d427..9f290d0d295de 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -181,12 +181,12 @@ fn require_same_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, main_def_id: DefId) { - let main_id = tcx.hir().as_local_node_id(main_def_id).unwrap(); + let main_id = tcx.hir().as_local_hir_id(main_def_id).unwrap(); let main_span = tcx.def_span(main_def_id); let main_t = tcx.type_of(main_def_id); match main_t.sty { ty::FnDef(..) => { - if let Some(Node::Item(it)) = tcx.hir().find(main_id) { + if let Some(Node::Item(it)) = tcx.hir().find_by_hir_id(main_id) { if let hir::ItemKind::Fn(.., ref generics, _) = it.node { let mut error = false; if !generics.params.is_empty() { @@ -246,12 +246,12 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, main_def_id: DefId) { } fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, start_def_id: DefId) { - let start_id = tcx.hir().as_local_node_id(start_def_id).unwrap(); + let start_id = tcx.hir().as_local_hir_id(start_def_id).unwrap(); let start_span = tcx.def_span(start_def_id); let start_t = tcx.type_of(start_def_id); match start_t.sty { ty::FnDef(..) => { - if let Some(Node::Item(it)) = tcx.hir().find(start_id) { + if let Some(Node::Item(it)) = tcx.hir().find_by_hir_id(start_id) { if let hir::ItemKind::Fn(.., ref generics, _) = it.node { let mut error = false; if !generics.params.is_empty() { diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index afb6a68482013..347422780d516 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -46,12 +46,12 @@ fn crate_variances<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) fn variances_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId) -> Lrc> { - let id = tcx.hir().as_local_node_id(item_def_id).expect("expected local def-id"); + let id = tcx.hir().as_local_hir_id(item_def_id).expect("expected local def-id"); let unsupported = || { // Variance not relevant. - span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item") + span_bug!(tcx.hir().span_by_hir_id(id), "asked to compute variance for wrong kind of item") }; - match tcx.hir().get(id) { + match tcx.hir().get_by_hir_id(id) { Node::Item(item) => match item.node { hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) | diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index bd0525583f2cd..8e0a535305a8e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1724,6 +1724,30 @@ impl FnDecl { pub fn self_type(&self) -> Option { self.inputs.values.get(0).and_then(|v| v.to_self()) } + + /// Returns the sugared return type for an async function. + /// + /// For example, if the return type is `impl std::future::Future`, this function + /// will return `i32`. + /// + /// # Panics + /// + /// This function will panic if the return type does not match the expected sugaring for async + /// functions. + pub fn sugared_async_return_type(&self) -> FunctionRetTy { + match &self.output { + FunctionRetTy::Return(Type::ImplTrait(bounds)) => { + match &bounds[0] { + GenericBound::TraitBound(PolyTrait { trait_, .. }, ..) => { + let bindings = trait_.bindings().unwrap(); + FunctionRetTy::Return(bindings[0].ty.clone()) + } + _ => panic!("unexpected desugaring of async function"), + } + } + _ => panic!("unexpected desugaring of async function"), + } + } } #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] @@ -2282,6 +2306,21 @@ impl Type { _ => None, } } + + pub fn bindings(&self) -> Option<&[TypeBinding]> { + match *self { + ResolvedPath { ref path, .. } => { + path.segments.last().and_then(|seg| { + if let GenericArgs::AngleBracketed { ref bindings, .. } = seg.args { + Some(&**bindings) + } else { + None + } + }) + } + _ => None + } + } } impl GetDefId for Type { @@ -3762,7 +3801,7 @@ fn print_const(cx: &DocContext, n: ty::LazyConst) -> String { } fn print_const_expr(cx: &DocContext, body: hir::BodyId) -> String { - cx.tcx.hir().node_to_pretty_string(body.node_id) + cx.tcx.hir().hir_to_pretty_string(body.hir_id) } /// Given a type Path, resolve it to a Type using the TyCtxt diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 5a3e6984859a2..c03e679bc5194 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -5,6 +5,7 @@ //! assume that HTML output is desired, although it may be possible to redesign //! them in the future to instead emit any format desired. +use std::borrow::Cow; use std::fmt; use rustc::hir::def_id::DefId; @@ -44,14 +45,16 @@ pub struct GenericBounds<'a>(pub &'a [clean::GenericBound]); pub struct CommaSep<'a, T: 'a>(pub &'a [T]); pub struct AbiSpace(pub Abi); -/// Wrapper struct for properly emitting a method declaration. -pub struct Method<'a> { +/// Wrapper struct for properly emitting a function or method declaration. +pub struct Function<'a> { /// The declaration to emit. pub decl: &'a clean::FnDecl, /// The length of the function's "name", used to determine line-wrapping. pub name_len: usize, /// The number of spaces to indent each successive line with, if line-wrapping is necessary. pub indent: usize, + /// Whether the function is async or not. + pub asyncness: hir::IsAsync, } /// Wrapper struct for emitting a where clause from Generics. @@ -829,9 +832,9 @@ impl fmt::Display for clean::FnDecl { } } -impl<'a> fmt::Display for Method<'a> { +impl<'a> fmt::Display for Function<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let &Method { decl, name_len, indent } = self; + let &Function { decl, name_len, indent, asyncness } = self; let amp = if f.alternate() { "&" } else { "&" }; let mut args = String::new(); let mut args_plain = String::new(); @@ -891,11 +894,17 @@ impl<'a> fmt::Display for Method<'a> { args_plain.push_str(", ..."); } - let arrow_plain = format!("{:#}", decl.output); + let output = if let hir::IsAsync::Async = asyncness { + Cow::Owned(decl.sugared_async_return_type()) + } else { + Cow::Borrowed(&decl.output) + }; + + let arrow_plain = format!("{:#}", &output); let arrow = if f.alternate() { - format!("{:#}", decl.output) + format!("{:#}", &output) } else { - decl.output.to_string() + output.to_string() }; let pad = " ".repeat(name_len); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index a85ac19286af5..8e4d6b26c7225 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -62,7 +62,7 @@ use fold::DocFolder; use html::escape::Escape; use html::format::{AsyncSpace, ConstnessSpace}; use html::format::{GenericBounds, WhereClause, href, AbiSpace}; -use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace}; +use html::format::{VisSpace, Function, UnsafetySpace, MutableSpace}; use html::format::fmt_impl_for_trait_page; use html::item_type::ItemType; use html::markdown::{self, Markdown, MarkdownHtml, MarkdownSummaryLine, ErrorCodes, IdMap}; @@ -2977,10 +2977,11 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, name = it.name.as_ref().unwrap(), generics = f.generics, where_clause = WhereClause { gens: &f.generics, indent: 0, end_newline: true }, - decl = Method { + decl = Function { decl: &f.decl, name_len, indent: 0, + asyncness: f.header.asyncness, })?; document(w, cx, it) } @@ -3424,10 +3425,11 @@ fn render_assoc_item(w: &mut fmt::Formatter, href = href, name = name, generics = *g, - decl = Method { + decl = Function { decl: d, name_len: head_len, indent, + asyncness: header.asyncness, }, where_clause = WhereClause { gens: g, diff --git a/src/test/rustdoc/async-fn.rs b/src/test/rustdoc/async-fn.rs index a0b6c29126092..ba4997a7f9b5b 100644 --- a/src/test/rustdoc/async-fn.rs +++ b/src/test/rustdoc/async-fn.rs @@ -1,14 +1,35 @@ // edition:2018 -// compile-flags:-Z unstable-options - -// FIXME: once `--edition` is stable in rustdoc, remove that `compile-flags` directive #![feature(async_await, futures_api)] -// @has async_fn/struct.S.html -// @has - '//code' 'pub async fn f()' -pub struct S; +// @has async_fn/fn.foo.html '//pre[@class="rust fn"]' 'pub async fn foo() -> Option' +pub async fn foo() -> Option { + None +} + +// @has async_fn/fn.bar.html '//pre[@class="rust fn"]' 'pub async fn bar(a: i32, b: i32) -> i32' +pub async fn bar(a: i32, b: i32) -> i32 { + 0 +} + +// @has async_fn/fn.baz.html '//pre[@class="rust fn"]' 'pub async fn baz(a: T) -> T' +pub async fn baz(a: T) -> T { + a +} + +trait Bar {} + +impl Bar for () {} + +// @has async_fn/fn.quux.html '//pre[@class="rust fn"]' 'pub async fn quux() -> impl Bar' +pub async fn quux() -> impl Bar { + () +} + +// @has async_fn/struct.Foo.html +// @matches - '//code' 'pub async fn f\(\)$' +pub struct Foo; -impl S { +impl Foo { pub async fn f() {} } diff --git a/src/tools/compiletest/Cargo.toml b/src/tools/compiletest/Cargo.toml index edf4aeab1c70f..00e1a53473cda 100644 --- a/src/tools/compiletest/Cargo.toml +++ b/src/tools/compiletest/Cargo.toml @@ -2,6 +2,7 @@ authors = ["The Rust Project Developers"] name = "compiletest" version = "0.0.0" +edition = "2018" [dependencies] diff = "0.1.10" diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index f6f8ef1dff485..42afb72c91f39 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use test::ColorConfig; -use util::PathBufExt; +use crate::util::PathBufExt; #[derive(Clone, Copy, PartialEq, Debug)] pub enum Mode { @@ -66,7 +66,7 @@ impl FromStr for Mode { } impl fmt::Display for Mode { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let s = match *self { CompileFail => "compile-fail", RunFail => "run-fail", diff --git a/src/tools/compiletest/src/errors.rs b/src/tools/compiletest/src/errors.rs index fd3f002fb6682..0329fb0db1422 100644 --- a/src/tools/compiletest/src/errors.rs +++ b/src/tools/compiletest/src/errors.rs @@ -33,7 +33,7 @@ impl FromStr for ErrorKind { } impl fmt::Display for ErrorKind { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { ErrorKind::Help => write!(f, "help message"), ErrorKind::Error => write!(f, "error"), diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 591d92f0cfa14..80a015d7aea56 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -4,10 +4,10 @@ use std::io::prelude::*; use std::io::BufReader; use std::path::{Path, PathBuf}; -use common::{self, CompareMode, Config, Mode}; -use util; +use crate::common::{self, CompareMode, Config, Mode}; +use crate::util; -use extract_gdb_version; +use crate::extract_gdb_version; /// Whether to ignore the test. #[derive(Clone, Copy, PartialEq, Debug)] diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index 106aa67157a42..12aae303f29aa 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -1,5 +1,5 @@ -use errors::{Error, ErrorKind}; -use runtest::ProcRes; +use crate::errors::{Error, ErrorKind}; +use crate::runtest::ProcRes; use serde_json; use std::path::Path; use std::str::FromStr; diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 15d53f1e3755c..1f9b4b2ad4363 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -1,29 +1,21 @@ #![crate_name = "compiletest"] #![feature(test)] -#![deny(warnings)] +#![deny(warnings, rust_2018_idioms)] -extern crate diff; -extern crate env_logger; -extern crate filetime; -extern crate getopts; #[cfg(unix)] extern crate libc; #[macro_use] extern crate log; -extern crate regex; #[macro_use] extern crate lazy_static; #[macro_use] extern crate serde_derive; -extern crate serde_json; extern crate test; -extern crate rustfix; -extern crate walkdir; -use common::CompareMode; -use common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS}; -use common::{Config, TestPaths}; -use common::{DebugInfoBoth, DebugInfoGdb, DebugInfoLldb, Mode, Pretty}; +use crate::common::CompareMode; +use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS}; +use crate::common::{Config, TestPaths}; +use crate::common::{DebugInfoBoth, DebugInfoGdb, DebugInfoLldb, Mode, Pretty}; use filetime::FileTime; use getopts::Options; use std::env; @@ -33,8 +25,10 @@ use std::io::{self, ErrorKind}; use std::path::{Path, PathBuf}; use std::process::Command; use test::ColorConfig; -use util::logv; +use crate::util::logv; use walkdir::WalkDir; +use env_logger; +use getopts; use self::header::{EarlyProps, Ignore}; diff --git a/src/tools/compiletest/src/read2.rs b/src/tools/compiletest/src/read2.rs index 5a4caddcdd319..6dfd8e97c636d 100644 --- a/src/tools/compiletest/src/read2.rs +++ b/src/tools/compiletest/src/read2.rs @@ -100,18 +100,15 @@ mod imp { #[cfg(windows)] mod imp { - extern crate miow; - extern crate winapi; - use std::io; use std::os::windows::prelude::*; use std::process::{ChildStderr, ChildStdout}; use std::slice; - use self::miow::iocp::{CompletionPort, CompletionStatus}; - use self::miow::pipe::NamedPipe; - use self::miow::Overlapped; - use self::winapi::shared::winerror::ERROR_BROKEN_PIPE; + use miow::iocp::{CompletionPort, CompletionStatus}; + use miow::pipe::NamedPipe; + use miow::Overlapped; + use winapi::shared::winerror::ERROR_BROKEN_PIPE; struct Pipe<'a> { dst: &'a mut Vec, diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index ff201b03a0bdc..31529810a04db 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1,18 +1,18 @@ -use common::CompareMode; -use common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT}; -use common::{output_base_dir, output_base_name, output_testname_unique}; -use common::{Codegen, CodegenUnits, DebugInfoBoth, DebugInfoGdb, DebugInfoLldb, Rustdoc}; -use common::{CompileFail, Pretty, RunFail, RunPass, RunPassValgrind}; -use common::{Config, TestPaths}; -use common::{Incremental, MirOpt, RunMake, Ui}; +use crate::common::CompareMode; +use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT}; +use crate::common::{output_base_dir, output_base_name, output_testname_unique}; +use crate::common::{Codegen, CodegenUnits, DebugInfoBoth, DebugInfoGdb, DebugInfoLldb, Rustdoc}; +use crate::common::{CompileFail, Pretty, RunFail, RunPass, RunPassValgrind}; +use crate::common::{Config, TestPaths}; +use crate::common::{Incremental, MirOpt, RunMake, Ui}; use diff; -use errors::{self, Error, ErrorKind}; +use crate::errors::{self, Error, ErrorKind}; use filetime::FileTime; -use header::TestProps; -use json; +use crate::header::TestProps; +use crate::json; use regex::Regex; use rustfix::{apply_suggestions, get_suggestions_from_json, Filter}; -use util::{logv, PathBufExt}; +use crate::util::{logv, PathBufExt}; use std::collections::hash_map::DefaultHasher; use std::collections::{HashMap, HashSet, VecDeque}; @@ -27,8 +27,8 @@ use std::path::{Path, PathBuf}; use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::str; -use extract_gdb_version; -use is_android_gdb_target; +use crate::extract_gdb_version; +use crate::is_android_gdb_target; #[cfg(windows)] fn disable_error_reporting R, R>(f: F) -> R { @@ -1937,7 +1937,7 @@ impl<'test> TestCx<'test> { } fn make_cmdline(&self, command: &Command, libpath: &str) -> String { - use util; + use crate::util; // Linux and mac don't require adjusting the library search path if cfg!(unix) { @@ -3255,7 +3255,7 @@ impl<'test> TestCx<'test> { } fn create_stamp(&self) { - let stamp = ::stamp(&self.config, self.testpaths, self.revision); + let stamp = crate::stamp(&self.config, self.testpaths, self.revision); fs::write(&stamp, compute_stamp_hash(&self.config)).unwrap(); } } @@ -3311,7 +3311,7 @@ impl fmt::Debug for ExpectedLine where T: AsRef + fmt::Debug, { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { if let &ExpectedLine::Text(ref t) = self { write!(formatter, "{:?}", t) } else { @@ -3334,7 +3334,7 @@ fn nocomment_mir_line(line: &str) -> &str { } fn read2_abbreviated(mut child: Child) -> io::Result { - use read2::read2; + use crate::read2::read2; use std::mem::replace; const HEAD_LEN: usize = 160 * 1024; diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index 90dfadeee4612..85be2fed07567 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -1,7 +1,7 @@ use std::ffi::OsStr; use std::env; use std::path::PathBuf; -use common::Config; +use crate::common::Config; /// Conversion table from triple OS name to Rust SYSNAME const OS_TABLE: &'static [(&'static str, &'static str)] = &[ diff --git a/src/tools/rustdoc/Cargo.toml b/src/tools/rustdoc/Cargo.toml index d38815004418c..36aa5916da733 100644 --- a/src/tools/rustdoc/Cargo.toml +++ b/src/tools/rustdoc/Cargo.toml @@ -2,6 +2,7 @@ name = "rustdoc-tool" version = "0.0.0" authors = ["The Rust Project Developers"] +edition = "2018" # Cargo adds a number of paths to the dylib search path on windows, which results in # the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool" diff --git a/src/tools/rustdoc/main.rs b/src/tools/rustdoc/main.rs index df9d2c6ba96db..8bdc365c4ca68 100644 --- a/src/tools/rustdoc/main.rs +++ b/src/tools/rustdoc/main.rs @@ -1,3 +1,5 @@ +#![deny(rust_2018_idioms)] + #![feature(link_args)] #[allow(unused_attributes)] @@ -10,6 +12,4 @@ // See src/rustc/rustc.rs for the corresponding rustc settings. extern {} -extern crate rustdoc; - fn main() { rustdoc::main() }