From 9aa89b25232b79b93dc122e86b8071fb14fc4e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 8 Mar 2019 19:08:28 -0800 Subject: [PATCH 01/22] When encountetring `||{}()`, suggest the likely intended `(||{})()` --- src/librustc_typeck/check/callee.rs | 35 ++++++++++++++++++- .../suggest-on-bare-closure-call.rs | 4 +++ .../suggest-on-bare-closure-call.stderr | 15 ++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/suggestions/suggest-on-bare-closure-call.rs create mode 100644 src/test/ui/suggestions/suggest-on-bare-closure-call.stderr diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 0a4c0eb3aff72..15ae39600f6b4 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -2,7 +2,7 @@ use super::autoderef::Autoderef; use super::method::MethodCallee; use super::{Expectation, FnCtxt, Needs, TupleArgumentsFlag}; -use errors::Applicability; +use errors::{Applicability, DiagnosticBuilder}; use hir::def::Def; use hir::def_id::{DefId, LOCAL_CRATE}; use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; @@ -232,6 +232,32 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { None } + /// Give appropriate suggestion when encountering `||{/* not callable */}()`, where the + /// likely intention is to call the closure, suggest `(||{})()`. (#55851) + fn identify_bad_closure_def_and_call( + &self, + err: &mut DiagnosticBuilder<'a>, + hir_id: hir::HirId, + callee_node: &hir::ExprKind, + callee_span: Span, + ) { + let hir_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id); + let parent_node = self.tcx.hir().get_by_hir_id(hir_id); + if let ( + hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, _, _, sp, ..), .. }), + hir::ExprKind::Block(..), + ) = (parent_node, callee_node) { + let start = sp.shrink_to_lo(); + let end = self.tcx.sess.source_map().next_point(callee_span); + err.multipart_suggestion( + "if you meant to create this closure and immediately call it, surround the \ + closure with parenthesis", + vec![(start, "(".to_string()), (end, ")".to_string())], + Applicability::MaybeIncorrect, + ); + } + } + fn confirm_builtin_call( &self, call_expr: &hir::Expr, @@ -268,6 +294,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } ); + self.identify_bad_closure_def_and_call( + &mut err, + call_expr.hir_id, + &callee.node, + callee.span, + ); + if let Some(ref path) = unit_variant { err.span_suggestion( call_expr.span, diff --git a/src/test/ui/suggestions/suggest-on-bare-closure-call.rs b/src/test/ui/suggestions/suggest-on-bare-closure-call.rs new file mode 100644 index 0000000000000..355708c08ec2f --- /dev/null +++ b/src/test/ui/suggestions/suggest-on-bare-closure-call.rs @@ -0,0 +1,4 @@ +fn main() { + let _ = ||{}(); + //~^ ERROR expected function, found `()` +} diff --git a/src/test/ui/suggestions/suggest-on-bare-closure-call.stderr b/src/test/ui/suggestions/suggest-on-bare-closure-call.stderr new file mode 100644 index 0000000000000..17001e3974c6d --- /dev/null +++ b/src/test/ui/suggestions/suggest-on-bare-closure-call.stderr @@ -0,0 +1,15 @@ +error[E0618]: expected function, found `()` + --> $DIR/suggest-on-bare-closure-call.rs:2:15 + | +LL | let _ = ||{}(); + | ^^-- + | | + | call expression requires function +help: if you meant to create this closure and immediately call it, surround the closure with parenthesis + | +LL | let _ = (||{})(); + | ^ ^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0618`. From 94a6936a692ed5e6f6c6a64d622d21ea4083e051 Mon Sep 17 00:00:00 2001 From: kennytm Date: Sat, 9 Mar 2019 14:28:25 +0800 Subject: [PATCH 02/22] Track embedded-book in the toolstate --- src/ci/docker/x86_64-gnu-tools/checktools.sh | 1 + src/tools/publish_toolstate.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ci/docker/x86_64-gnu-tools/checktools.sh b/src/ci/docker/x86_64-gnu-tools/checktools.sh index 3343716419ff4..97e6ee25ec7a0 100755 --- a/src/ci/docker/x86_64-gnu-tools/checktools.sh +++ b/src/ci/docker/x86_64-gnu-tools/checktools.sh @@ -78,6 +78,7 @@ status_check() { check_dispatch $1 beta clippy-driver src/tools/clippy # these tools are not required for beta to successfully branch check_dispatch $1 nightly miri src/tools/miri + check_dispatch $1 nightly embedded-book src/doc/embedded-book } # If this PR is intended to update one of these tools, do not let the build pass diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py index fb6132a5358ef..430db48954826 100755 --- a/src/tools/publish_toolstate.py +++ b/src/tools/publish_toolstate.py @@ -12,7 +12,7 @@ except ImportError: import urllib.request as urllib2 -# List of people to ping when the status of a tool changed. +# List of people to ping when the status of a tool or a book changed. MAINTAINERS = { 'miri': '@oli-obk @RalfJung @eddyb', 'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk @phansch', @@ -22,6 +22,7 @@ 'nomicon': '@frewsxcv @Gankro', 'reference': '@steveklabnik @Havvy @matthewjasper @alercah', 'rust-by-example': '@steveklabnik @marioidival @projektir', + 'embedded-book': '', } REPOS = { @@ -33,6 +34,7 @@ 'nomicon': 'https://github.com/rust-lang-nursery/nomicon', 'reference': 'https://github.com/rust-lang-nursery/reference', 'rust-by-example': 'https://github.com/rust-lang/rust-by-example', + 'embedded-book': 'https://github.com/rust-embedded/book', } @@ -70,7 +72,7 @@ def issue( cc @{}, the PR reviewer, and @rust-lang/compiler -- nominating for prioritization. - ''').format(relevant_pr_number, tool, REPOS[tool], relevant_pr_user, pr_reviewer), + ''').format(relevant_pr_number, tool, REPOS.get(tool), relevant_pr_user, pr_reviewer), 'title': '`{}` no longer builds after {}'.format(tool, relevant_pr_number), 'assignees': assignees, 'labels': ['T-compiler', 'I-nominated'], @@ -137,7 +139,7 @@ def update_latest( if build_failed: try: issue( - tool, MAINTAINERS.get(tool), + tool, MAINTAINERS.get(tool, ''), relevant_pr_number, relevant_pr_user, pr_reviewer, ) except IOError as e: From 135b686db41f67c4241144e25277a90092b014f4 Mon Sep 17 00:00:00 2001 From: James Munns Date: Sun, 10 Mar 2019 17:38:16 +0800 Subject: [PATCH 03/22] Update src/tools/publish_toolstate.py Co-Authored-By: kennytm --- src/tools/publish_toolstate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py index 430db48954826..6e06034db599a 100755 --- a/src/tools/publish_toolstate.py +++ b/src/tools/publish_toolstate.py @@ -22,7 +22,7 @@ 'nomicon': '@frewsxcv @Gankro', 'reference': '@steveklabnik @Havvy @matthewjasper @alercah', 'rust-by-example': '@steveklabnik @marioidival @projektir', - 'embedded-book': '', + 'embedded-book': '@adamgreig @andre-richter @jamesmunns @korken89 @ryankurte @thejpster @therealprof', } REPOS = { From d6f51006cd47ca3f1ccacc4e0faa345877653b81 Mon Sep 17 00:00:00 2001 From: kennytm Date: Sun, 10 Mar 2019 18:02:40 +0800 Subject: [PATCH 04/22] Fix tidy --- src/tools/publish_toolstate.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py index 6e06034db599a..f2a585e627307 100755 --- a/src/tools/publish_toolstate.py +++ b/src/tools/publish_toolstate.py @@ -22,7 +22,10 @@ 'nomicon': '@frewsxcv @Gankro', 'reference': '@steveklabnik @Havvy @matthewjasper @alercah', 'rust-by-example': '@steveklabnik @marioidival @projektir', - 'embedded-book': '@adamgreig @andre-richter @jamesmunns @korken89 @ryankurte @thejpster @therealprof', + 'embedded-book': ( + '@adamgreig @andre-richter @jamesmunns @korken89 ' + '@ryankurte @thejpster @therealprof' + ), } REPOS = { From 83534874444f8981c540685eba1ddb8fb42999bc Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 7 Mar 2019 17:57:18 +0100 Subject: [PATCH 05/22] refactor build-mainfest. --- src/tools/build-manifest/src/main.rs | 401 +++++++++++++-------------- 1 file changed, 197 insertions(+), 204 deletions(-) diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index d44a51a9635e9..ae297e23061f1 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -10,7 +10,7 @@ use std::io::{self, Read, Write}; use std::path::{PathBuf, Path}; use std::process::{Command, Stdio}; -static HOSTS: &'static [&'static str] = &[ +static HOSTS: &[&str] = &[ "aarch64-unknown-linux-gnu", "arm-unknown-linux-gnueabi", "arm-unknown-linux-gnueabihf", @@ -35,7 +35,7 @@ static HOSTS: &'static [&'static str] = &[ "x86_64-unknown-netbsd", ]; -static TARGETS: &'static [&'static str] = &[ +static TARGETS: &[&str] = &[ "aarch64-apple-ios", "aarch64-fuchsia", "aarch64-linux-android", @@ -115,7 +115,7 @@ static TARGETS: &'static [&'static str] = &[ "x86_64-unknown-redox", ]; -static DOCS_TARGETS: &'static [&'static str] = &[ +static DOCS_TARGETS: &[&str] = &[ "i686-apple-darwin", "i686-pc-windows-gnu", "i686-pc-windows-msvc", @@ -126,7 +126,7 @@ static DOCS_TARGETS: &'static [&'static str] = &[ "x86_64-unknown-linux-gnu", ]; -static MINGW: &'static [&'static str] = &[ +static MINGW: &[&str] = &[ "i686-pc-windows-gnu", "x86_64-pc-windows-gnu", ]; @@ -153,7 +153,7 @@ struct Rename { to: String, } -#[derive(Serialize)] +#[derive(Serialize, Default)] struct Target { available: bool, url: Option, @@ -165,17 +165,7 @@ struct Target { } impl Target { - fn unavailable() -> Target { - Target { - available: false, - url: None, - hash: None, - xz_url: None, - xz_hash: None, - components: None, - extensions: None, - } - } + fn unavailable() -> Self { Self::default() } } #[derive(Serialize)] @@ -184,6 +174,12 @@ struct Component { target: String, } +impl Component { + fn from_str(pkg: &str, target: &str) -> Self { + Self { pkg: pkg.to_string(), target: target.to_string() } + } +} + macro_rules! t { ($e:expr) => (match $e { Ok(e) => e, @@ -301,6 +297,25 @@ fn main() { }.build(); } +enum PkgType { RustSrc, Cargo, Rls, Clippy, Rustfmt, LlvmTools, Lldb, Miri, Other } + +impl PkgType { + fn from_component(component: &str) -> Self { + use PkgType::*; + match component { + "rust-src" => RustSrc, + "cargo" => Cargo, + "rls" | "rls-preview" => Rls, + "clippy" | "clippy-preview" => Clippy, + "rustfmt" | "rustfmt-preview" => Rustfmt, + "llvm-tools" | "llvm-tools-preview" => LlvmTools, + "lldb" | "lldb-preview" => Lldb, + "miri" | "miri-preview" => Miri, + _ => Other, + } + } +} + impl Builder { fn build(&mut self) { self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu"); @@ -349,39 +364,56 @@ impl Builder { renames: BTreeMap::new(), profiles: BTreeMap::new(), }; + self.add_packages_to(&mut manifest); + self.add_profiles_to(&mut manifest); + self.add_renames_to(&mut manifest); + manifest.pkg.insert("rust".to_string(), self.rust_package(&manifest)); + manifest + } - self.package("rustc", &mut manifest.pkg, HOSTS); - self.package("cargo", &mut manifest.pkg, HOSTS); - self.package("rust-mingw", &mut manifest.pkg, MINGW); - self.package("rust-std", &mut manifest.pkg, TARGETS); - self.package("rust-docs", &mut manifest.pkg, DOCS_TARGETS); - self.package("rust-src", &mut manifest.pkg, &["*"]); - self.package("rls-preview", &mut manifest.pkg, HOSTS); - self.package("clippy-preview", &mut manifest.pkg, HOSTS); - self.package("miri", &mut manifest.pkg, HOSTS); - self.package("rustfmt-preview", &mut manifest.pkg, HOSTS); - self.package("rust-analysis", &mut manifest.pkg, TARGETS); - self.package("llvm-tools-preview", &mut manifest.pkg, TARGETS); - self.package("lldb-preview", &mut manifest.pkg, TARGETS); - - self.profile("minimal", - &mut manifest.profiles, - &["rustc", "cargo", "rust-std", "rust-mingw"]); - self.profile("default", - &mut manifest.profiles, - &["rustc", "cargo", "rust-std", "rust-mingw", - "rust-docs", "rustfmt-preview", "clippy-preview"]); - self.profile("complete", - &mut manifest.profiles, - &["rustc", "cargo", "rust-std", "rust-mingw", - "rust-docs", "rustfmt-preview", "clippy-preview", - "rls-preview", "rust-src", "llvm-tools-preview", - "lldb-preview", "rust-analysis", "miri"]); - - manifest.renames.insert("rls".to_owned(), Rename { to: "rls-preview".to_owned() }); - manifest.renames.insert("rustfmt".to_owned(), Rename { to: "rustfmt-preview".to_owned() }); - manifest.renames.insert("clippy".to_owned(), Rename { to: "clippy-preview".to_owned() }); + fn add_packages_to(&mut self, manifest: &mut Manifest) { + let mut package = |name, targets| self.package(name, &mut manifest.pkg, targets); + package("rustc", HOSTS); + package("cargo", HOSTS); + package("rust-mingw", MINGW); + package("rust-std", TARGETS); + package("rust-docs", DOCS_TARGETS); + package("rust-src", &["*"]); + package("rls-preview", HOSTS); + package("clippy-preview", HOSTS); + package("miri", HOSTS); + package("rustfmt-preview", HOSTS); + package("rust-analysis", TARGETS); + package("llvm-tools-preview", TARGETS); + package("lldb-preview", TARGETS); + } + fn add_profiles_to(&mut self, manifest: &mut Manifest) { + let mut profile = |name, pkgs| self.profile(name, &mut manifest.profiles, pkgs); + profile("minimal", &["rustc", "cargo", "rust-std", "rust-mingw"]); + profile("default", &[ + "rustc", "cargo", "rust-std", "rust-mingw", + "rust-docs", "rustfmt-preview", "clippy-preview" + ]); + profile("complete", &[ + "rustc", "cargo", "rust-std", "rust-mingw", + "rust-docs", "rustfmt-preview", "clippy-preview", + "rls-preview", "rust-src", "llvm-tools-preview", + "lldb-preview", "rust-analysis", "miri" + ]); + } + + fn add_renames_to(&self, manifest: &mut Manifest) { + let mut rename = |from: &str, to: &str| manifest.renames.insert( + from.to_owned(), + Rename { to: to.to_owned() } + ); + rename("rls", "rls-preview"); + rename("rustfmt", "rustfmt-preview"); + rename("clippy", "clippy-preview"); + } + + fn rust_package(&mut self, manifest: &Manifest) -> Package { let mut pkg = Package { version: self.cached_version("rust") .as_ref() @@ -391,90 +423,82 @@ impl Builder { target: BTreeMap::new(), }; for host in HOSTS { - let filename = self.filename("rust", host); - let digest = match self.digests.remove(&filename) { - Some(digest) => digest, - None => { - pkg.target.insert(host.to_string(), Target::unavailable()); - continue - } - }; - let xz_filename = filename.replace(".tar.gz", ".tar.xz"); - let xz_digest = self.digests.remove(&xz_filename); - let mut components = Vec::new(); - let mut extensions = Vec::new(); - - // rustc/rust-std/cargo/docs are all required, and so is rust-mingw - // if it's available for the target. - components.extend(vec![ - Component { pkg: "rustc".to_string(), target: host.to_string() }, - Component { pkg: "rust-std".to_string(), target: host.to_string() }, - Component { pkg: "cargo".to_string(), target: host.to_string() }, - Component { pkg: "rust-docs".to_string(), target: host.to_string() }, - ]); - if host.contains("pc-windows-gnu") { - components.push(Component { - pkg: "rust-mingw".to_string(), - target: host.to_string(), - }); - } - - // Tools are always present in the manifest, but might be marked as unavailable if they - // weren't built - extensions.extend(vec![ - Component { pkg: "clippy-preview".to_string(), target: host.to_string() }, - Component { pkg: "miri".to_string(), target: host.to_string() }, - Component { pkg: "rls-preview".to_string(), target: host.to_string() }, - Component { pkg: "rustfmt-preview".to_string(), target: host.to_string() }, - Component { pkg: "llvm-tools-preview".to_string(), target: host.to_string() }, - Component { pkg: "lldb-preview".to_string(), target: host.to_string() }, - Component { pkg: "rust-analysis".to_string(), target: host.to_string() }, - ]); - - for target in TARGETS { - if target != host { - extensions.push(Component { - pkg: "rust-std".to_string(), - target: target.to_string(), - }); - } - } - extensions.push(Component { - pkg: "rust-src".to_string(), - target: "*".to_string(), - }); - - // If the components/extensions don't actually exist for this - // particular host/target combination then nix it entirely from our - // lists. - { - let has_component = |c: &Component| { - if c.target == "*" { - return true - } - let pkg = match manifest.pkg.get(&c.pkg) { - Some(p) => p, - None => return false, - }; - pkg.target.get(&c.target).is_some() - }; - extensions.retain(&has_component); - components.retain(&has_component); + if let Some(target) = self.target_host_combination(host, &manifest) { + pkg.target.insert(host.to_string(), target); + } else { + pkg.target.insert(host.to_string(), Target::unavailable()); + continue } + } + pkg + } - pkg.target.insert(host.to_string(), Target { - available: true, - url: Some(self.url(&filename)), - hash: Some(digest), - xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)), - xz_hash: xz_digest, - components: Some(components), - extensions: Some(extensions), - }); + fn target_host_combination(&mut self, host: &str, manifest: &Manifest) -> Option { + let filename = self.filename("rust", host); + let digest = self.digests.remove(&filename)?; + let xz_filename = filename.replace(".tar.gz", ".tar.xz"); + let xz_digest = self.digests.remove(&xz_filename); + let mut components = Vec::new(); + let mut extensions = Vec::new(); + + let host_component = |pkg| Component::from_str(pkg, host); + + // rustc/rust-std/cargo/docs are all required, + // and so is rust-mingw if it's available for the target. + components.extend(vec![ + host_component("rustc"), + host_component("rust-std"), + host_component("cargo"), + host_component("rust-docs"), + ]); + if host.contains("pc-windows-gnu") { + components.push(host_component("rust-mingw")); } - manifest.pkg.insert("rust".to_string(), pkg); - manifest + // Tools are always present in the manifest, + // but might be marked as unavailable if they weren't built. + extensions.extend(vec![ + host_component("clippy-preview"), + host_component("miri"), + host_component("rls-preview"), + host_component("rustfmt-preview"), + host_component("llvm-tools-preview"), + host_component("lldb-preview"), + host_component("rust-analysis"), + ]); + + extensions.extend( + TARGETS.iter() + .filter(|&&target| target != host) + .map(|target| Component::from_str("rust-std", target)) + ); + extensions.push(Component::from_str("rust-src", "*")); + + // If the components/extensions don't actually exist for this + // particular host/target combination then nix it entirely from our + // lists. + let has_component = |c: &Component| { + if c.target == "*" { + return true + } + let pkg = match manifest.pkg.get(&c.pkg) { + Some(p) => p, + None => return false, + }; + pkg.target.get(&c.target).is_some() + }; + extensions.retain(&has_component); + components.retain(&has_component); + + Some(Target { + available: true, + url: Some(self.url(&filename)), + hash: Some(digest), + xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)), + xz_hash: xz_digest, + components: Some(components), + extensions: Some(extensions), + }) } fn profile(&mut self, @@ -488,10 +512,11 @@ impl Builder { pkgname: &str, dst: &mut BTreeMap, targets: &[&str]) { - let (version, is_present) = match *self.cached_version(pkgname) { - Some(ref version) => (version.clone(), true), - None => (String::new(), false), - }; + let (version, is_present) = self.cached_version(pkgname) + .as_ref() + .cloned() + .map(|version| (version, true)) + .unwrap_or_default(); let targets = targets.iter().map(|name| { if is_present { @@ -515,15 +540,7 @@ impl Builder { } else { // If the component is not present for this build add it anyway but mark it as // unavailable -- this way rustup won't allow upgrades without --force - (name.to_string(), Target { - available: false, - url: None, - hash: None, - xz_url: None, - xz_hash: None, - components: None, - extensions: None, - }) + (name.to_string(), Target::unavailable()) } }).collect(); @@ -542,89 +559,65 @@ impl Builder { } fn filename(&self, component: &str, target: &str) -> String { - if component == "rust-src" { - format!("rust-src-{}.tar.gz", self.rust_release) - } else if component == "cargo" { - format!("cargo-{}-{}.tar.gz", self.cargo_release, target) - } else if component == "rls" || component == "rls-preview" { - format!("rls-{}-{}.tar.gz", self.rls_release, target) - } else if component == "clippy" || component == "clippy-preview" { - format!("clippy-{}-{}.tar.gz", self.clippy_release, target) - } else if component == "rustfmt" || component == "rustfmt-preview" { - format!("rustfmt-{}-{}.tar.gz", self.rustfmt_release, target) - } else if component == "llvm-tools" || component == "llvm-tools-preview" { - format!("llvm-tools-{}-{}.tar.gz", self.llvm_tools_release, target) - } else if component == "lldb" || component == "lldb-preview" { - format!("lldb-{}-{}.tar.gz", self.lldb_release, target) - } else if component == "miri" || component == "miri-preview" { - format!("miri-{}-{}.tar.gz", self.miri_release, target) - } else { - format!("{}-{}-{}.tar.gz", component, self.rust_release, target) + use PkgType::*; + match PkgType::from_component(component) { + RustSrc => format!("rust-src-{}.tar.gz", self.rust_release), + Cargo => format!("cargo-{}-{}.tar.gz", self.cargo_release, target), + Rls => format!("rls-{}-{}.tar.gz", self.rls_release, target), + Clippy => format!("clippy-{}-{}.tar.gz", self.clippy_release, target), + Rustfmt => format!("rustfmt-{}-{}.tar.gz", self.rustfmt_release, target), + LlvmTools => format!("llvm-tools-{}-{}.tar.gz", self.llvm_tools_release, target), + Lldb => format!("lldb-{}-{}.tar.gz", self.lldb_release, target), + Miri => format!("miri-{}-{}.tar.gz", self.miri_release, target), + Other => format!("{}-{}-{}.tar.gz", component, self.rust_release, target), } } fn cached_version(&self, component: &str) -> &Option { - if component == "cargo" { - &self.cargo_version - } else if component == "rls" || component == "rls-preview" { - &self.rls_version - } else if component == "clippy" || component == "clippy-preview" { - &self.clippy_version - } else if component == "rustfmt" || component == "rustfmt-preview" { - &self.rustfmt_version - } else if component == "llvm-tools" || component == "llvm-tools-preview" { - &self.llvm_tools_version - } else if component == "lldb" || component == "lldb-preview" { - &self.lldb_version - } else if component == "miri" || component == "miri-preview" { - &self.miri_version - } else { - &self.rust_version + use PkgType::*; + match PkgType::from_component(component) { + Cargo => &self.cargo_version, + Rls => &self.rls_version, + Clippy => &self.clippy_version, + Rustfmt => &self.rustfmt_version, + LlvmTools => &self.llvm_tools_version, + Lldb => &self.lldb_version, + Miri => &self.miri_version, + _ => &self.rust_version, } } fn cached_git_commit_hash(&self, component: &str) -> &Option { - if component == "cargo" { - &self.cargo_git_commit_hash - } else if component == "rls" || component == "rls-preview" { - &self.rls_git_commit_hash - } else if component == "clippy" || component == "clippy-preview" { - &self.clippy_git_commit_hash - } else if component == "rustfmt" || component == "rustfmt-preview" { - &self.rustfmt_git_commit_hash - } else if component == "llvm-tools" || component == "llvm-tools-preview" { - &self.llvm_tools_git_commit_hash - } else if component == "lldb" || component == "lldb-preview" { - &self.lldb_git_commit_hash - } else if component == "miri" || component == "miri-preview" { - &self.miri_git_commit_hash - } else { - &self.rust_git_commit_hash + use PkgType::*; + match PkgType::from_component(component) { + Cargo => &self.cargo_git_commit_hash, + Rls => &self.rls_git_commit_hash, + Clippy => &self.clippy_git_commit_hash, + Rustfmt => &self.rustfmt_git_commit_hash, + LlvmTools => &self.llvm_tools_git_commit_hash, + Lldb => &self.lldb_git_commit_hash, + Miri => &self.miri_git_commit_hash, + _ => &self.rust_git_commit_hash, } } fn version(&self, component: &str, target: &str) -> Option { - let mut cmd = Command::new("tar"); - let filename = self.filename(component, target); - cmd.arg("xf") - .arg(self.input.join(&filename)) - .arg(format!("{}/version", filename.replace(".tar.gz", ""))) - .arg("-O"); - let output = t!(cmd.output()); - if output.status.success() { - Some(String::from_utf8_lossy(&output.stdout).trim().to_string()) - } else { - // Perhaps we didn't build this package. - None - } + self.untar(component, target, |filename| format!("{}/version", filename)) } fn git_commit_hash(&self, component: &str, target: &str) -> Option { + self.untar(component, target, |filename| format!("{}/git-commit-hash", filename)) + } + + fn untar(&self, component: &str, target: &str, dir: F) -> Option + where + F: FnOnce(String) -> String + { let mut cmd = Command::new("tar"); let filename = self.filename(component, target); cmd.arg("xf") .arg(self.input.join(&filename)) - .arg(format!("{}/git-commit-hash", filename.replace(".tar.gz", ""))) + .arg(dir(filename.replace(".tar.gz", ""))) .arg("-O"); let output = t!(cmd.output()); if output.status.success() { From 7e1914f75b94d9454a63e8aa2797ab16b8997f80 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 10 Mar 2019 13:07:16 +0100 Subject: [PATCH 06/22] hir: replace NodeId with HirId in trait_impls --- src/librustc/hir/lowering.rs | 6 ++++-- src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/mod.rs | 2 +- src/librustc/ty/trait_def.rs | 4 ++-- src/librustc_typeck/coherence/builtin.rs | 2 +- src/librustc_typeck/coherence/mod.rs | 11 +++++------ src/librustdoc/passes/collect_trait_impls.rs | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 949fdd2682b96..d3fa7ce283d12 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -89,7 +89,7 @@ pub struct LoweringContext<'a> { bodies: BTreeMap, exported_macros: Vec, - trait_impls: BTreeMap>, + trait_impls: BTreeMap>, trait_auto_impl: BTreeMap, modules: BTreeMap, @@ -2967,6 +2967,7 @@ impl<'a> LoweringContext<'a> { // method, it will not be considered an in-band // lifetime to be added, but rather a reference to a // parent lifetime. + let lowered_trait_impl_id = self.lower_node_id(id).hir_id; let (generics, (trait_ref, lowered_ty)) = self.add_in_band_defs( ast_generics, def_id, @@ -2978,7 +2979,8 @@ impl<'a> LoweringContext<'a> { if let Some(ref trait_ref) = trait_ref { if let Def::Trait(def_id) = trait_ref.path.def { - this.trait_impls.entry(def_id).or_default().push(id); + this.trait_impls.entry(def_id).or_default().push( + lowered_trait_impl_id); } } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 86b6805cc9b4c..44091eb4395be 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -555,7 +555,7 @@ impl<'hir> Map<'hir> { } } - pub fn trait_impls(&self, trait_did: DefId) -> &'hir [NodeId] { + pub fn trait_impls(&self, trait_did: DefId) -> &'hir [HirId] { self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls)); // N.B., intentionally bypass `self.forest.krate()` so that we diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index e47bc3d1c2533..ef72d0187b6b6 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -723,7 +723,7 @@ pub struct Crate { pub trait_items: BTreeMap, pub impl_items: BTreeMap, pub bodies: BTreeMap, - pub trait_impls: BTreeMap>, + pub trait_impls: BTreeMap>, pub trait_auto_impl: BTreeMap, /// A list of the body ids written out in the order in which they diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index 9ce8bf2e60a31..a45b5b5b8470a 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -179,8 +179,8 @@ pub(super) fn trait_impls_of_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } - for &node_id in tcx.hir().trait_impls(trait_id) { - add_impl(tcx.hir().local_def_id(node_id)); + for &hir_id in tcx.hir().trait_impls(trait_id) { + add_impl(tcx.hir().local_def_id_from_hir_id(hir_id)); } } diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 5d86bc5409532..2cb2dd50d7505 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -37,7 +37,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { { if Some(self.trait_def_id) == trait_def_id { for &impl_id in self.tcx.hir().trait_impls(self.trait_def_id) { - let impl_def_id = self.tcx.hir().local_def_id(impl_id); + let impl_def_id = self.tcx.hir().local_def_id_from_hir_id(impl_id); f(self.tcx, impl_def_id); } } diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 39a2f5d37bd7a..bf7284d8445ff 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -5,22 +5,21 @@ // done by the orphan and overlap modules. Then we build up various // mappings. That mapping code resides here. +use crate::hir::HirId; use crate::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::traits; use rustc::ty::{self, TyCtxt, TypeFoldable}; use rustc::ty::query::Providers; use rustc::util::common::time; -use syntax::ast; - mod builtin; mod inherent_impls; mod inherent_impls_overlap; mod orphan; mod unsafety; -fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, node_id: ast::NodeId) { - let impl_def_id = tcx.hir().local_def_id(node_id); +fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_id: HirId) { + let impl_def_id = tcx.hir().local_def_id_from_hir_id(hir_id); // If there are no traits, then this implementation must have a // base type. @@ -160,8 +159,8 @@ pub fn check_coherence<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { /// Overlap: no two impls for the same trait are implemented for the /// same type. Likewise, no two inherent impls for a given type /// constructor provide a method with the same name. -fn check_impl_overlap<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, node_id: ast::NodeId) { - let impl_def_id = tcx.hir().local_def_id(node_id); +fn check_impl_overlap<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_id: HirId) { + let impl_def_id = tcx.hir().local_def_id_from_hir_id(hir_id); let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); let trait_def_id = trait_ref.def_id; diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index de043277c8359..611291c2688f5 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -119,7 +119,7 @@ pub fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate { // doesn't work with it anyway, so pull them from the HIR map instead for &trait_did in cx.all_traits.iter() { for &impl_node in cx.tcx.hir().trait_impls(trait_did) { - let impl_did = cx.tcx.hir().local_def_id(impl_node); + let impl_did = cx.tcx.hir().local_def_id_from_hir_id(impl_node); inline::build_impl(cx, impl_did, &mut new_items); } } From 401329e829cd4c6ced5a2bd9a0891f59672bf241 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 10 Mar 2019 13:08:02 +0100 Subject: [PATCH 07/22] HirIdification: remove all NodeIds from borrowck --- src/librustc_borrowck/borrowck/gather_loans/lifetime.rs | 4 ++-- src/librustc_borrowck/borrowck/gather_loans/mod.rs | 9 +++------ src/librustc_borrowck/borrowck/mod.rs | 8 +++----- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs index 0e08b62668ac8..9680dd4ce2faf 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs @@ -2,13 +2,13 @@ //! does not exceed the lifetime of the value being borrowed. use crate::borrowck::*; +use rustc::hir::HirId; use rustc::middle::expr_use_visitor as euv; use rustc::middle::mem_categorization as mc; use rustc::middle::mem_categorization::Categorization; use rustc::middle::region; use rustc::ty; -use syntax::ast; use syntax_pos::Span; use log::debug; @@ -51,7 +51,7 @@ struct GuaranteeLifetimeContext<'a, 'tcx: 'a> { } impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> { - fn check(&self, cmt: &mc::cmt_<'tcx>, discr_scope: Option) -> R { + fn check(&self, cmt: &mc::cmt_<'tcx>, discr_scope: Option) -> R { //! Main routine. Walks down `cmt` until we find the //! "guarantor". Reports an error if `self.loan_region` is //! larger than scope of `cmt`. diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index bf730ba41f428..ed631f2cdaa0d 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -14,7 +14,6 @@ use rustc::middle::mem_categorization::Categorization; use rustc::middle::region; use rustc::ty::{self, TyCtxt}; -use syntax::ast; use syntax_pos::Span; use rustc::hir; use log::debug; @@ -141,8 +140,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { assignee_cmt: &mc::cmt_<'tcx>, _: euv::MutateMode) { - let node_id = self.bccx.tcx.hir().hir_to_node_id(assignment_id); - self.guarantee_assignment_valid(node_id, + self.guarantee_assignment_valid(assignment_id, assignment_span, assignee_cmt); } @@ -238,7 +236,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { /// Guarantees that `cmt` is assignable, or reports an error. fn guarantee_assignment_valid(&mut self, - assignment_id: ast::NodeId, + assignment_id: hir::HirId, assignment_span: Span, cmt: &mc::cmt_<'tcx>) { @@ -272,8 +270,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { self.mark_loan_path_as_mutated(&lp); } gather_moves::gather_assignment(self.bccx, &self.move_data, - self.bccx.tcx.hir().node_to_hir_id(assignment_id) - .local_id, + assignment_id.local_id, assignment_span, lp); } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index da065f9e05d9e..3a6e53a92482c 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -34,7 +34,6 @@ use std::fmt; use std::rc::Rc; use rustc_data_structures::sync::Lrc; use std::hash::{Hash, Hasher}; -use syntax::ast; use syntax_pos::{MultiSpan, Span}; use errors::{Applicability, DiagnosticBuilder, DiagnosticId}; use log::debug; @@ -399,12 +398,12 @@ pub enum LoanPathElem<'tcx> { } fn closure_to_block(closure_id: LocalDefId, - tcx: TyCtxt<'_, '_, '_>) -> ast::NodeId { + tcx: TyCtxt<'_, '_, '_>) -> HirId { let closure_id = tcx.hir().local_def_id_to_node_id(closure_id); match tcx.hir().get(closure_id) { Node::Expr(expr) => match expr.node { hir::ExprKind::Closure(.., body_id, _, _) => { - tcx.hir().hir_to_node_id(body_id.hir_id) + body_id.hir_id } _ => { bug!("encountered non-closure id: {}", closure_id) @@ -422,8 +421,7 @@ impl<'a, 'tcx> LoanPath<'tcx> { } LpUpvar(upvar_id) => { let block_id = closure_to_block(upvar_id.closure_expr_id, bccx.tcx); - let hir_id = bccx.tcx.hir().node_to_hir_id(block_id); - region::Scope { id: hir_id.local_id, data: region::ScopeData::Node } + region::Scope { id: block_id.local_id, data: region::ScopeData::Node } } LpDowncast(ref base, _) | LpExtend(ref base, ..) => base.kill_scope(bccx), From aa5374192704861bd64dc031b363a88ec7edc0ad Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 10 Mar 2019 13:08:18 +0100 Subject: [PATCH 08/22] HirIdification: remove all NodeIds from typeck --- src/librustc_typeck/check/method/mod.rs | 4 ++-- src/librustc_typeck/check/method/probe.rs | 9 +++++---- src/librustc_typeck/check/mod.rs | 15 +++++++-------- src/librustc_typeck/check/writeback.rs | 11 ++--------- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 8f27b5b7dc81f..5e3ebcb3446c6 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -196,7 +196,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { )?; if let Some(import_id) = pick.import_id { - let import_def_id = self.tcx.hir().local_def_id(import_id); + let import_def_id = self.tcx.hir().local_def_id_from_hir_id(import_id); debug!("used_trait_import: {:?}", import_def_id); Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports) .unwrap().insert(import_def_id); @@ -428,7 +428,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self_ty, expr_id, ProbeScope::TraitsInScope)?; debug!("resolve_ufcs: pick={:?}", pick); if let Some(import_id) = pick.import_id { - let import_def_id = tcx.hir().local_def_id(import_id); + let import_def_id = tcx.hir().local_def_id_from_hir_id(import_id); debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id); Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports) .unwrap().insert(import_def_id); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index efae870c3c3a9..217be19e72a0c 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -120,7 +120,7 @@ struct Candidate<'tcx> { xform_ret_ty: Option>, item: ty::AssociatedItem, kind: CandidateKind<'tcx>, - import_id: Option, + import_id: Option, } #[derive(Debug)] @@ -145,7 +145,7 @@ enum ProbeResult { pub struct Pick<'tcx> { pub item: ty::AssociatedItem, pub kind: PickKind<'tcx>, - pub import_id: Option, + pub import_id: Option, // Indicates that the source expression should be autoderef'd N times // @@ -836,7 +836,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { for trait_candidate in applicable_traits.iter() { let trait_did = trait_candidate.def_id; if duplicates.insert(trait_did) { - let import_id = trait_candidate.import_id; + let import_id = trait_candidate.import_id.map(|node_id| + self.fcx.tcx.hir().node_to_hir_id(node_id)); let result = self.assemble_extension_candidates_for_trait(import_id, trait_did); result?; } @@ -887,7 +888,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { } fn assemble_extension_candidates_for_trait(&mut self, - import_id: Option, + import_id: Option, trait_def_id: DefId) -> Result<(), MethodError<'tcx>> { debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 28c79ce0c74e8..13f17d2f44fb1 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4966,10 +4966,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // that highlight errors inline. let mut sp = blk.span; let mut fn_span = None; - let blk_node_id = self.tcx.hir().hir_to_node_id(blk.hir_id); - if let Some((decl, ident)) = self.get_parent_fn_decl(blk_node_id) { + if let Some((decl, ident)) = self.get_parent_fn_decl(blk.hir_id) { let ret_sp = decl.output.span(); - if let Some(block_sp) = self.parent_item_span(blk_node_id) { + if let Some(block_sp) = self.parent_item_span(blk.hir_id) { // HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the // output would otherwise be incorrect and even misleading. Make sure // the span we're aiming at correspond to a `fn` body. @@ -5009,8 +5008,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ty } - fn parent_item_span(&self, id: ast::NodeId) -> Option { - let node = self.tcx.hir().get(self.tcx.hir().get_parent(id)); + fn parent_item_span(&self, id: hir::HirId) -> Option { + let node = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_item(id)); match node { Node::Item(&hir::Item { node: hir::ItemKind::Fn(_, _, _, body_id), .. @@ -5028,9 +5027,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { None } - /// Given a function block's `NodeId`, returns its `FnDecl` if it exists, or `None` otherwise. - fn get_parent_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, ast::Ident)> { - let parent = self.tcx.hir().get(self.tcx.hir().get_parent(blk_id)); + /// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise. + fn get_parent_fn_decl(&self, blk_id: hir::HirId) -> Option<(hir::FnDecl, ast::Ident)> { + let parent = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_item(blk_id)); self.get_node_fn_decl(parent).map(|(fn_decl, ident, _)| (fn_decl, ident)) } diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index d001545d1d915..01a77e85caede 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -15,7 +15,6 @@ use rustc::ty::{self, Ty, TyCtxt}; use rustc::util::nodemap::DefIdSet; use rustc_data_structures::sync::Lrc; use std::mem; -use syntax::ast; use syntax_pos::Span; /////////////////////////////////////////////////////////////////////////// @@ -444,8 +443,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { fn visit_opaque_types(&mut self, span: Span) { for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() { - let node_id = self.tcx().hir().as_local_node_id(def_id).unwrap(); - let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &node_id); + let hir_id = self.tcx().hir().as_local_hir_id(def_id).unwrap(); + let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id); let generics = self.tcx().generics_of(def_id); @@ -731,12 +730,6 @@ impl Locatable for Span { } } -impl Locatable for ast::NodeId { - fn to_span(&self, tcx: &TyCtxt<'_, '_, '_>) -> Span { - tcx.hir().span(*self) - } -} - impl Locatable for DefIndex { fn to_span(&self, tcx: &TyCtxt<'_, '_, '_>) -> Span { let hir_id = tcx.hir().def_index_to_hir_id(*self); From 9151eabf97512efe3d66fa931fcb1e14b7f02e5f Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 10 Mar 2019 13:22:00 +0100 Subject: [PATCH 09/22] HirIdification: remove all NodeIds from rustc_mir --- src/librustc_mir/borrow_check/nll/universal_regions.rs | 8 ++------ src/librustc_mir/build/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index 4d9a3775b3123..ae8dfa8144fd9 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -23,7 +23,6 @@ use rustc::util::nodemap::FxHashMap; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; use rustc_errors::DiagnosticBuilder; use std::iter; -use syntax::ast; use super::ToRegionVid; @@ -200,12 +199,10 @@ impl<'tcx> UniversalRegions<'tcx> { param_env: ty::ParamEnv<'tcx>, ) -> Self { let tcx = infcx.tcx; - let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).unwrap(); - let mir_hir_id = tcx.hir().node_to_hir_id(mir_node_id); + let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).unwrap(); UniversalRegionsBuilder { infcx, mir_def_id, - mir_node_id, mir_hir_id, param_env, }.build() @@ -370,7 +367,6 @@ struct UniversalRegionsBuilder<'cx, 'gcx: 'tcx, 'tcx: 'cx> { infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>, mir_def_id: DefId, mir_hir_id: HirId, - mir_node_id: ast::NodeId, param_env: ty::ParamEnv<'tcx>, } @@ -475,7 +471,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> { let tcx = self.infcx.tcx; let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); - match tcx.hir().body_owner_kind(self.mir_node_id) { + match tcx.hir().body_owner_kind_by_hir_id(self.mir_hir_id) { BodyOwnerKind::Closure | BodyOwnerKind::Fn => { let defining_ty = if self.mir_def_id == closure_base_def_id { diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index c8e48dea1f34c..3aac79c1d16ad 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -373,7 +373,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { /// finish building it. guard_context: Vec, - /// Maps `NodeId`s of variable bindings to the `Local`s created for them. + /// Maps `HirId`s of variable bindings to the `Local`s created for them. /// (A match binding can have two locals; the 2nd is for the arm's guard.) var_indices: HirIdMap, local_decls: IndexVec>, @@ -451,7 +451,7 @@ impl BlockContext { #[derive(Debug)] enum LocalsForNode { - /// In the usual case, a `NodeId` for an identifier maps to at most + /// In the usual case, a `HirId` for an identifier maps to at most /// one `Local` declaration. One(Local), From 584d61a2bee9af2af572103899fc3e485e0a1fa8 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 10 Mar 2019 13:56:58 +0100 Subject: [PATCH 10/22] hir: remove trait_auto_impl --- src/librustc/hir/lowering.rs | 3 --- src/librustc/hir/map/collector.rs | 1 - src/librustc/hir/map/mod.rs | 12 ------------ src/librustc/hir/mod.rs | 1 - 4 files changed, 17 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d3fa7ce283d12..7715e926aa1f5 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -90,7 +90,6 @@ pub struct LoweringContext<'a> { exported_macros: Vec, trait_impls: BTreeMap>, - trait_auto_impl: BTreeMap, modules: BTreeMap, @@ -233,7 +232,6 @@ pub fn lower_crate( impl_items: BTreeMap::new(), bodies: BTreeMap::new(), trait_impls: BTreeMap::new(), - trait_auto_impl: BTreeMap::new(), modules: BTreeMap::new(), exported_macros: Vec::new(), catch_scopes: Vec::new(), @@ -514,7 +512,6 @@ impl<'a> LoweringContext<'a> { bodies: self.bodies, body_ids, trait_impls: self.trait_impls, - trait_auto_impl: self.trait_auto_impl, modules: self.modules, } } diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 9f39d648df1bf..e88f9e60702f7 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -121,7 +121,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { impl_items: _, bodies: _, trait_impls: _, - trait_auto_impl: _, body_ids: _, modules: _, } = *krate; diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 44091eb4395be..19b9c78be4c38 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -563,18 +563,6 @@ impl<'hir> Map<'hir> { self.forest.krate.trait_impls.get(&trait_did).map_or(&[], |xs| &xs[..]) } - pub fn trait_auto_impl(&self, trait_did: DefId) -> Option { - self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls)); - - // N.B., intentionally bypass `self.forest.krate()` so that we - // do not trigger a read of the whole krate here - self.forest.krate.trait_auto_impl.get(&trait_did).cloned() - } - - pub fn trait_is_auto(&self, trait_did: DefId) -> bool { - self.trait_auto_impl(trait_did).is_some() - } - /// Gets the attributes on the crate. This is preferable to /// invoking `krate.attrs` because it registers a tighter /// dep-graph access. diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index ef72d0187b6b6..a099811b748b1 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -724,7 +724,6 @@ pub struct Crate { pub impl_items: BTreeMap, pub bodies: BTreeMap, pub trait_impls: BTreeMap>, - pub trait_auto_impl: BTreeMap, /// A list of the body ids written out in the order in which they /// appear in the crate. If you're going to process all the bodies From b9d12edd6ce7b364fb1a4de53f7541d536df0940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 11 Mar 2019 15:07:07 -0700 Subject: [PATCH 11/22] Be more discerning on when to attempt suggesting a comma in a macro invocation --- src/libsyntax/tokenstream.rs | 8 +++++--- src/test/ui/macros/missing-comma.rs | 7 +++++++ src/test/ui/macros/missing-comma.stderr | 21 +++++++++++++++------ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 4ce308d015c00..5caa59a53f92b 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -178,9 +178,11 @@ impl TokenStream { while let Some((pos, ts)) = iter.next() { if let Some((_, next)) = iter.peek() { let sp = match (&ts, &next) { - ((TokenTree::Token(_, token::Token::Comma), NonJoint), _) | - (_, (TokenTree::Token(_, token::Token::Comma), NonJoint)) => continue, - ((TokenTree::Token(sp, _), NonJoint), _) => *sp, + (_, (TokenTree::Token(_, token::Token::Comma), _)) => continue, + ((TokenTree::Token(sp, token_left), NonJoint), + (TokenTree::Token(_, token_right), _)) + if token_left.is_ident() || token_left.is_lit() && + token_right.is_ident() || token_right.is_lit() => *sp, ((TokenTree::Delimited(sp, ..), NonJoint), _) => sp.entire(), _ => continue, }; diff --git a/src/test/ui/macros/missing-comma.rs b/src/test/ui/macros/missing-comma.rs index 1e146875bcc76..2b411aba8a2ee 100644 --- a/src/test/ui/macros/missing-comma.rs +++ b/src/test/ui/macros/missing-comma.rs @@ -6,6 +6,11 @@ macro_rules! foo { ($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => (); } +macro_rules! bar { + ($lvl:expr, $($arg:tt)+) => {} +} + + fn main() { println!("{}" a); //~^ ERROR expected token: `,` @@ -17,4 +22,6 @@ fn main() { //~^ ERROR no rules expected the token `d` foo!(a, b, c d e); //~^ ERROR no rules expected the token `d` + bar!(Level::Error, ); + //~^ ERROR unexpected end of macro invocation } diff --git a/src/test/ui/macros/missing-comma.stderr b/src/test/ui/macros/missing-comma.stderr index 5881e0b7b68c6..424fefd00f873 100644 --- a/src/test/ui/macros/missing-comma.stderr +++ b/src/test/ui/macros/missing-comma.stderr @@ -1,11 +1,11 @@ error: expected token: `,` - --> $DIR/missing-comma.rs:10:19 + --> $DIR/missing-comma.rs:15:19 | LL | println!("{}" a); | ^ error: no rules expected the token `b` - --> $DIR/missing-comma.rs:12:12 + --> $DIR/missing-comma.rs:17:12 | LL | macro_rules! foo { | ---------------- when calling this macro @@ -16,7 +16,7 @@ LL | foo!(a b); | help: missing comma here error: no rules expected the token `e` - --> $DIR/missing-comma.rs:14:21 + --> $DIR/missing-comma.rs:19:21 | LL | macro_rules! foo { | ---------------- when calling this macro @@ -27,7 +27,7 @@ LL | foo!(a, b, c, d e); | help: missing comma here error: no rules expected the token `d` - --> $DIR/missing-comma.rs:16:18 + --> $DIR/missing-comma.rs:21:18 | LL | macro_rules! foo { | ---------------- when calling this macro @@ -38,7 +38,7 @@ LL | foo!(a, b, c d, e); | help: missing comma here error: no rules expected the token `d` - --> $DIR/missing-comma.rs:18:18 + --> $DIR/missing-comma.rs:23:18 | LL | macro_rules! foo { | ---------------- when calling this macro @@ -46,5 +46,14 @@ LL | macro_rules! foo { LL | foo!(a, b, c d e); | ^ no rules expected this token in macro call -error: aborting due to 5 previous errors +error: unexpected end of macro invocation + --> $DIR/missing-comma.rs:25:23 + | +LL | macro_rules! bar { + | ---------------- when calling this macro +... +LL | bar!(Level::Error, ); + | ^ missing tokens in macro arguments + +error: aborting due to 6 previous errors From 27abd52170b2d2769f5fbed665795bdb9a3facef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 13 Mar 2019 00:10:16 -0700 Subject: [PATCH 12/22] Fix operator precedence --- src/libsyntax/tokenstream.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 5caa59a53f92b..80a7bde606afa 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -181,8 +181,8 @@ impl TokenStream { (_, (TokenTree::Token(_, token::Token::Comma), _)) => continue, ((TokenTree::Token(sp, token_left), NonJoint), (TokenTree::Token(_, token_right), _)) - if token_left.is_ident() || token_left.is_lit() && - token_right.is_ident() || token_right.is_lit() => *sp, + if (token_left.is_ident() || token_left.is_lit()) && + (token_right.is_ident() || token_right.is_lit()) => *sp, ((TokenTree::Delimited(sp, ..), NonJoint), _) => sp.entire(), _ => continue, }; From 856b081eb2ae3264da07434debd55d734fba7eb4 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 11 Mar 2019 11:03:19 +0100 Subject: [PATCH 13/22] middle: replace NodeId with HirId in AccessLevels --- src/librustc/middle/dead.rs | 2 +- src/librustc/middle/privacy.rs | 4 +- src/librustc/middle/reachable.rs | 5 +-- src/librustc/middle/stability.rs | 2 +- src/librustc_lint/builtin.rs | 12 ++--- src/librustc_privacy/lib.rs | 25 ++++------- src/librustc_save_analysis/dump_visitor.rs | 51 ++++++++++++++-------- src/librustdoc/core.rs | 6 +-- 8 files changed, 55 insertions(+), 52 deletions(-) diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 94de999c25da8..0de169e652371 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -414,7 +414,7 @@ fn create_and_seed_worklist<'a, 'tcx>( ) -> (Vec, FxHashMap) { let worklist = access_levels.map.iter().filter_map(|(&id, level)| { if level >= &privacy::AccessLevel::Reachable { - Some(tcx.hir().node_to_hir_id(id)) + Some(id) } else { None } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 6ba55f882f8fd..787ff8d48c119 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -2,11 +2,11 @@ //! outside their scopes. This pass will also generate a set of exported items //! which are available for use externally when compiled as a library. +use crate::hir::HirId; use crate::util::nodemap::{DefIdSet, FxHashMap}; use std::hash::Hash; use std::fmt; -use syntax::ast::NodeId; use rustc_macros::HashStable; // Accessibility levels, sorted in ascending order @@ -27,7 +27,7 @@ pub enum AccessLevel { // Accessibility levels for reachable HIR nodes #[derive(Clone)] -pub struct AccessLevels { +pub struct AccessLevels { pub map: FxHashMap } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 72f6d22b696f7..a7294dbf07c00 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -354,8 +354,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, // We need only trait impls here, not inherent impls, and only non-exported ones if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node { - let node_id = self.tcx.hir().hir_to_node_id(item.hir_id); - if !self.access_levels.is_reachable(node_id) { + if !self.access_levels.is_reachable(item.hir_id) { self.worklist.extend(impl_item_refs.iter().map(|ii_ref| ii_ref.id.hir_id)); let trait_def_id = match trait_ref.path.def { @@ -415,7 +414,7 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> // use the lang items, so we need to be sure to mark them as // exported. reachable_context.worklist.extend( - access_levels.map.iter().map(|(id, _)| tcx.hir().node_to_hir_id(*id))); + access_levels.map.iter().map(|(id, _)| *id)); for item in tcx.lang_items().items().iter() { if let Some(did) = *item { if let Some(hir_id) = tcx.hir().as_local_hir_id(did) { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 1677384059e09..b0abe215867b5 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -319,7 +319,7 @@ impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> { let stab = self.tcx.stability().local_stability(hir_id); let is_error = !self.tcx.sess.opts.test && stab.is_none() && - self.access_levels.is_reachable(self.tcx.hir().hir_to_node_id(hir_id)); + self.access_levels.is_reachable(hir_id); if is_error { self.tcx.sess.span_err( span, diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 7a7c49e460428..ad69493bf79c5 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -380,8 +380,7 @@ impl MissingDoc { // It's an option so the crate root can also use this function (it doesn't // have a NodeId). if let Some(id) = id { - let node_id = cx.tcx.hir().hir_to_node_id(id); - if !cx.access_levels.is_exported(node_id) { + if !cx.access_levels.is_exported(id) { return; } } @@ -557,8 +556,7 @@ impl LintPass for MissingCopyImplementations { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) { - let node_id = cx.tcx.hir().hir_to_node_id(item.hir_id); - if !cx.access_levels.is_reachable(node_id) { + if !cx.access_levels.is_reachable(item.hir_id) { return; } let (def, ty) = match item.node { @@ -629,8 +627,7 @@ impl LintPass for MissingDebugImplementations { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) { - let node_id = cx.tcx.hir().hir_to_node_id(item.hir_id); - if !cx.access_levels.is_reachable(node_id) { + if !cx.access_levels.is_reachable(item.hir_id) { return; } @@ -1169,9 +1166,8 @@ impl UnreachablePub { fn perform_lint(&self, cx: &LateContext<'_, '_>, what: &str, id: hir::HirId, vis: &hir::Visibility, span: Span, exportable: bool) { let mut applicability = Applicability::MachineApplicable; - let node_id = cx.tcx.hir().hir_to_node_id(id); match vis.node { - hir::VisibilityKind::Public if !cx.access_levels.is_reachable(node_id) => { + hir::VisibilityKind::Public if !cx.access_levels.is_reachable(id) => { if span.ctxt().outer().expn_info().is_some() { applicability = Applicability::MaybeIncorrect; } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 52514a3ca97d6..386a121d5acac 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -379,8 +379,8 @@ impl VisibilityLike for Option { // (which require reaching the `DefId`s in them). const SHALLOW: bool = true; fn new_min<'a, 'tcx>(find: &FindMin<'a, 'tcx, Self>, def_id: DefId) -> Self { - cmp::min(if let Some(node_id) = find.tcx.hir().as_local_node_id(def_id) { - find.access_levels.map.get(&node_id).cloned() + cmp::min(if let Some(hir_id) = find.tcx.hir().as_local_hir_id(def_id) { + find.access_levels.map.get(&hir_id).cloned() } else { Self::MAX }, find.min) @@ -410,8 +410,7 @@ struct ReachEverythingInTheInterfaceVisitor<'b, 'a: 'b, 'tcx: 'a> { impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> { fn get(&self, id: hir::HirId) -> Option { - let node_id = self.tcx.hir().hir_to_node_id(id); - self.access_levels.map.get(&node_id).cloned() + self.access_levels.map.get(&id).cloned() } // Updates node level and returns the updated level. @@ -419,8 +418,7 @@ impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> { let old_level = self.get(id); // Accessibility levels can only grow. if level > old_level { - let node_id = self.tcx.hir().hir_to_node_id(id); - self.access_levels.map.insert(node_id, level.unwrap()); + self.access_levels.map.insert(id, level.unwrap()); self.changed = true; level } else { @@ -1197,8 +1195,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { fn trait_is_public(&self, trait_id: hir::HirId) -> bool { // FIXME: this would preferably be using `exported_items`, but all // traits are exported currently (see `EmbargoVisitor.exported_trait`). - let node_id = self.tcx.hir().hir_to_node_id(trait_id); - self.access_levels.is_public(node_id) + self.access_levels.is_public(trait_id) } fn check_generic_bound(&mut self, bound: &hir::GenericBound) { @@ -1210,8 +1207,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } fn item_is_public(&self, id: &hir::HirId, vis: &hir::Visibility) -> bool { - let node_id = self.tcx.hir().hir_to_node_id(*id); - self.access_levels.is_reachable(node_id) || vis.node.is_pub() + self.access_levels.is_reachable(*id) || vis.node.is_pub() } } @@ -1325,8 +1321,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { hir::ImplItemKind::Const(..) | hir::ImplItemKind::Method(..) => { self.access_levels.is_reachable( - self.tcx.hir().hir_to_node_id( - impl_item_ref.id.hir_id)) + impl_item_ref.id.hir_id) } hir::ImplItemKind::Existential(..) | hir::ImplItemKind::Type(_) => false, @@ -1455,8 +1450,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem) { - let node_id = self.tcx.hir().hir_to_node_id(item.hir_id); - if self.access_levels.is_reachable(node_id) { + if self.access_levels.is_reachable(item.hir_id) { intravisit::walk_foreign_item(self, item) } } @@ -1474,8 +1468,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { v: &'tcx hir::Variant, g: &'tcx hir::Generics, item_id: hir::HirId) { - let node_id = self.tcx.hir().hir_to_node_id(v.node.data.hir_id()); - if self.access_levels.is_reachable(node_id) { + if self.access_levels.is_reachable(v.node.data.hir_id()) { self.in_variant = true; intravisit::walk_variant(self, v, g, item_id); self.in_variant = false; diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index b82aee7c96ad2..8eb2702447dbc 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -58,17 +58,19 @@ macro_rules! down_cast_data { } macro_rules! access_from { - ($save_ctxt:expr, $vis:expr, $id:expr) => { + ($save_ctxt:expr, $item:expr, $id:expr) => { Access { - public: $vis.node.is_pub(), + public: $item.vis.node.is_pub(), reachable: $save_ctxt.access_levels.is_reachable($id), } }; +} - ($save_ctxt:expr, $item:expr) => { +macro_rules! access_from_vis { + ($save_ctxt:expr, $vis:expr, $id:expr) => { Access { - public: $item.vis.node.is_pub(), - reachable: $save_ctxt.access_levels.is_reachable($item.id), + public: $vis.node.is_pub(), + reachable: $save_ctxt.access_levels.is_reachable($id), } }; } @@ -303,7 +305,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { method_data.value = sig_str; method_data.sig = sig::method_signature(id, ident, generics, sig, &self.save_ctxt); - self.dumper.dump_def(&access_from!(self.save_ctxt, vis, id), method_data); + let hir_id = self.tcx.hir().node_to_hir_id(id); + self.dumper.dump_def(&access_from_vis!(self.save_ctxt, vis, hir_id), method_data); } // walk arg and return types @@ -324,7 +327,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { fn process_struct_field_def(&mut self, field: &ast::StructField, parent_id: NodeId) { let field_data = self.save_ctxt.get_field_data(field, parent_id); if let Some(field_data) = field_data { - self.dumper.dump_def(&access_from!(self.save_ctxt, field), field_data); + let hir_id = self.tcx.hir().node_to_hir_id(field.id); + self.dumper.dump_def(&access_from!(self.save_ctxt, field, hir_id), field_data); } } @@ -389,7 +393,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { |v| v.process_formals(&decl.inputs, &fn_data.qualname), ); self.process_generic_params(ty_params, &fn_data.qualname, item.id); - self.dumper.dump_def(&access_from!(self.save_ctxt, item), fn_data); + let hir_id = self.tcx.hir().node_to_hir_id(item.id); + self.dumper.dump_def(&access_from!(self.save_ctxt, item, hir_id), fn_data); } for arg in &decl.inputs { @@ -409,10 +414,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { typ: &'l ast::Ty, expr: &'l ast::Expr, ) { + let hir_id = self.tcx.hir().node_to_hir_id(item.id); self.nest_tables(item.id, |v| { if let Some(var_data) = v.save_ctxt.get_item_data(item) { down_cast_data!(var_data, DefData, item.span); - v.dumper.dump_def(&access_from!(v.save_ctxt, item), var_data); + v.dumper.dump_def(&access_from!(v.save_ctxt, item, hir_id), var_data); } v.visit_ty(&typ); v.visit_expr(expr); @@ -434,9 +440,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { if !self.span.filter_generated(ident.span) { let sig = sig::assoc_const_signature(id, ident.name, typ, expr, &self.save_ctxt); let span = self.span_from_span(ident.span); + let hir_id = self.tcx.hir().node_to_hir_id(id); self.dumper.dump_def( - &access_from!(self.save_ctxt, vis, id), + &access_from_vis!(self.save_ctxt, vis, hir_id), Def { kind: DefKind::Const, id: id_from_node_id(id, &self.save_ctxt), @@ -510,8 +517,9 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { if !self.span.filter_generated(item.ident.span) { let span = self.span_from_span(item.ident.span); + let hir_id = self.tcx.hir().node_to_hir_id(item.id); self.dumper.dump_def( - &access_from!(self.save_ctxt, item), + &access_from!(self.save_ctxt, item, hir_id), Def { kind, id: id_from_node_id(item.id, &self.save_ctxt), @@ -550,7 +558,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { }; down_cast_data!(enum_data, DefData, item.span); - let access = access_from!(self.save_ctxt, item); + let hir_id = self.tcx.hir().node_to_hir_id(item.id); + let access = access_from!(self.save_ctxt, item, hir_id); for variant in &enum_definition.variants { let name = variant.node.ident.name.to_string(); @@ -698,8 +707,9 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { .iter() .map(|i| id_from_node_id(i.id, &self.save_ctxt)) .collect(); + let hir_id = self.tcx.hir().node_to_hir_id(item.id); self.dumper.dump_def( - &access_from!(self.save_ctxt, item), + &access_from!(self.save_ctxt, item, hir_id), Def { kind: DefKind::Trait, id, @@ -757,7 +767,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { fn process_mod(&mut self, item: &ast::Item) { if let Some(mod_data) = self.save_ctxt.get_item_data(item) { down_cast_data!(mod_data, DefData, item.span); - self.dumper.dump_def(&access_from!(self.save_ctxt, item), mod_data); + let hir_id = self.tcx.hir().node_to_hir_id(item.id); + self.dumper.dump_def(&access_from!(self.save_ctxt, item, hir_id), mod_data); } } @@ -1197,7 +1208,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { // The access is calculated using the current tree ID, but with the root tree's visibility // (since nested trees don't have their own visibility). - let access = access_from!(self.save_ctxt, root_item.vis, id); + let hir_id = self.tcx.hir().node_to_hir_id(id); + let access = access_from!(self.save_ctxt, root_item, hir_id); // 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) @@ -1394,9 +1406,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc 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 hir_id = self.tcx.hir().node_to_hir_id(item.id); self.dumper.dump_def( - &access_from!(self.save_ctxt, item), + &access_from!(self.save_ctxt, item, hir_id), Def { kind: DefKind::Type, id, @@ -1424,9 +1437,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc 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 hir_id = self.tcx.hir().node_to_hir_id(item.id); self.dumper.dump_def( - &access_from!(self.save_ctxt, item), + &access_from!(self.save_ctxt, item, hir_id), Def { kind: DefKind::Type, id, @@ -1624,7 +1638,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc } fn visit_foreign_item(&mut self, item: &'l ast::ForeignItem) { - let access = access_from!(self.save_ctxt, item); + let hir_id = self.tcx.hir().node_to_hir_id(item.id); + let access = access_from!(self.save_ctxt, item, hir_id); match item.node { ast::ForeignItemKind::Fn(ref decl, ref generics) => { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 47dbbc20980ba..fe6133dc0830e 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -461,11 +461,11 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt sess.abort_if_errors(); let access_levels = tcx.privacy_access_levels(LOCAL_CRATE); - // Convert from a NodeId set to a DefId set since we don't always have easy access - // to the map from defid -> nodeid + // Convert from a HirId set to a DefId set since we don't always have easy access + // to the map from defid -> hirid let access_levels = AccessLevels { map: access_levels.map.iter() - .map(|(&k, &v)| (tcx.hir().local_def_id(k), v)) + .map(|(&k, &v)| (tcx.hir().local_def_id_from_hir_id(k), v)) .collect() }; From 4e5692d9858d298f27757579688c71ba494cb5c3 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 18 Jan 2019 12:18:57 +0100 Subject: [PATCH 14/22] test that wildcard type `_` is not duplicated by `type Foo = (X, X);` and potentially instantiated at different types. (Updated to reflect changes in diagnostic output and compiletest infrastructure.) --- ...ssue-55748-pat-types-constrain-bindings.rs | 70 +++++++++++++++++++ ...-55748-pat-types-constrain-bindings.stderr | 29 ++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs create mode 100644 src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr diff --git a/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs new file mode 100644 index 0000000000000..3d042d442d531 --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs @@ -0,0 +1,70 @@ +// This test is ensuring that type ascriptions on let bindings +// constrain both: +// +// 1. the input expression on the right-hand side (after any potential +// coercion, and allowing for covariance), *and* +// +// 2. the bindings (if any) nested within the pattern on the left-hand +// side (and here, the type-constraint is *invariant*). + +#![feature(nll)] + +#![allow(dead_code, unused_mut)] +type PairUncoupled<'a, 'b, T> = (&'a T, &'b T); +type PairCoupledRegions<'a, T> = (&'a T, &'a T); +type PairCoupledTypes = (T, T); + +fn uncoupled_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((mut y, mut _z),): (PairUncoupled,) = ((s, &_x),); // ok + // Above compiling does *not* imply below would compile. + // ::std::mem::swap(&mut y, &mut _z); + y +} + +fn swap_regions((mut y, mut _z): PairCoupledRegions) { + ::std::mem::swap(&mut y, &mut _z); +} + +fn coupled_regions_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),): (PairCoupledRegions,) = ((s, &_x),); + // If above line compiled, so should line below ... + + // swap_regions((y, _z)); + + // ... but the ascribed type also invalidates this use of `y` + y //~ ERROR lifetime may not live long enough +} + +fn swap_types((mut y, mut _z): PairCoupledTypes<&u32>) { + ::std::mem::swap(&mut y, &mut _z); +} + +fn coupled_types_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),): (PairCoupledTypes<&u32>,) = ((s, &_x),); + // If above line compiled, so should line below ... + + // swap_types((y, _z)); + + // ... but the ascribed type also invalidates this use of `y` + y //~ ERROR lifetime may not live long enough +} + +fn swap_wilds((mut y, mut _z): PairCoupledTypes<&u32>) { + ::std::mem::swap(&mut y, &mut _z); +} + +fn coupled_wilds_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),): (PairCoupledTypes<_>,) = ((s, &_x),); + // If above line compiled, so should line below + // swap_wilds((y, _z)); + + // ... but the ascribed type also invalidates this use of `y` + y //~ ERROR lifetime may not live long enough +} + +fn main() { + uncoupled_lhs(&3, &4); + coupled_regions_lhs(&3, &4); + coupled_types_lhs(&3, &4); + coupled_wilds_lhs(&3, &4); +} diff --git a/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr new file mode 100644 index 0000000000000..5929707e41e10 --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr @@ -0,0 +1,29 @@ +error: lifetime may not live long enough + --> $DIR/issue-55748-pat-types-constrain-bindings.rs:35:5 + | +LL | fn coupled_regions_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/issue-55748-pat-types-constrain-bindings.rs:49:5 + | +LL | fn coupled_types_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/issue-55748-pat-types-constrain-bindings.rs:62:5 + | +LL | fn coupled_wilds_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: aborting due to 3 previous errors + From a7bd36c9e8cdfac6a6edd4124e0d1d99a41b99a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Mon, 11 Mar 2019 16:07:31 +0000 Subject: [PATCH 15/22] Add peer_addr function to UdpSocket --- src/libstd/net/udp.rs | 17 +++++++++++++++++ src/libstd/sys/cloudabi/shims/net.rs | 4 ++++ src/libstd/sys/redox/net/udp.rs | 5 +++++ src/libstd/sys/sgx/net.rs | 4 ++++ src/libstd/sys_common/net.rs | 6 ++++++ 5 files changed, 36 insertions(+) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index edc9d665444a0..c7ccf45b953e7 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -180,6 +180,23 @@ impl UdpSocket { } } + /// Returns the socket address of the remote peer this socket was connected to. + /// + /// # Examples + /// + /// ```no_run + /// use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, UdpSocket}; + /// + /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address"); + /// socket.connect("192.168.0.1:41203").expect("couldn't connect to address"); + /// assert_eq!(socket.peer_addr().unwrap(), + /// SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 0, 1), 41203))); + /// ``` + #[stable(feature = "rust1", since = "1.0.0")] + pub fn peer_addr(&self) -> io::Result { + self.0.peer_addr() + } + /// Returns the socket address that this socket was created from. /// /// # Examples diff --git a/src/libstd/sys/cloudabi/shims/net.rs b/src/libstd/sys/cloudabi/shims/net.rs index 6d2a4962ab444..4364a1365443a 100644 --- a/src/libstd/sys/cloudabi/shims/net.rs +++ b/src/libstd/sys/cloudabi/shims/net.rs @@ -159,6 +159,10 @@ impl UdpSocket { unsupported() } + pub fn peer_addr(&self) -> io::Result { + match self.0 {} + } + pub fn socket_addr(&self) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/redox/net/udp.rs b/src/libstd/sys/redox/net/udp.rs index b1a60b1457083..274123dce4b58 100644 --- a/src/libstd/sys/redox/net/udp.rs +++ b/src/libstd/sys/redox/net/udp.rs @@ -72,6 +72,11 @@ impl UdpSocket { Ok(None) } + pub fn peer_addr(&self) -> Result { + let path = self.0.path()?; + Ok(path_to_peer_addr(path.to_str().unwrap_or(""))) + } + pub fn socket_addr(&self) -> Result { let path = self.0.path()?; Ok(path_to_local_addr(path.to_str().unwrap_or(""))) diff --git a/src/libstd/sys/sgx/net.rs b/src/libstd/sys/sgx/net.rs index e5e42e3d0b048..e851bdfe6a831 100644 --- a/src/libstd/sys/sgx/net.rs +++ b/src/libstd/sys/sgx/net.rs @@ -257,6 +257,10 @@ impl UdpSocket { unsupported() } + pub fn peer_addr(&self) -> io::Result { + match self.0 {} + } + pub fn socket_addr(&self) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index b9505aaa69ba5..b77bcee4b9d04 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -472,6 +472,12 @@ impl UdpSocket { pub fn into_socket(self) -> Socket { self.inner } + pub fn peer_addr(&self) -> io::Result { + sockname(|buf, len| unsafe { + c::getpeername(*self.inner.as_inner(), buf, len) + }) + } + pub fn socket_addr(&self) -> io::Result { sockname(|buf, len| unsafe { c::getsockname(*self.inner.as_inner(), buf, len) From bf473e3c153dfa84056249864a9f696d72f4e9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Tue, 12 Mar 2019 10:32:23 +0000 Subject: [PATCH 16/22] Mark UdpSocket peer_addr unstable w/ tracking issue --- src/libstd/net/udp.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index c7ccf45b953e7..164039b303230 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -185,6 +185,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run + /// #![feature(udp_peer_addr)] /// use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, UdpSocket}; /// /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address"); @@ -192,7 +193,7 @@ impl UdpSocket { /// assert_eq!(socket.peer_addr().unwrap(), /// SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 0, 1), 41203))); /// ``` - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "udp_peer_addr", issue = "59127")] pub fn peer_addr(&self) -> io::Result { self.0.peer_addr() } From 24e3fa079c150675e1911f1a9f958b690ecaa1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Tue, 12 Mar 2019 11:19:33 +0000 Subject: [PATCH 17/22] Document UdpSocket peer_addr NotConnected error --- src/libstd/net/udp.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index 164039b303230..79e5ae79e4c01 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -193,6 +193,19 @@ impl UdpSocket { /// assert_eq!(socket.peer_addr().unwrap(), /// SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 0, 1), 41203))); /// ``` + /// + /// If the socket isn't connected, it will return a [`NotConnected`] error. + /// + /// [`NotConnected`]: ../../std/io/enum.ErrorKind.html#variant.NotConnected + /// + /// ```no_run + /// #![feature(udp_peer_addr)] + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address"); + /// assert_eq!(socket.peer_addr().unwrap_err().kind(), + /// ::std::io::ErrorKind::NotConnected); + /// ``` #[unstable(feature = "udp_peer_addr", issue = "59127")] pub fn peer_addr(&self) -> io::Result { self.0.peer_addr() From 7f7cfaee6aafbaa2477cb00b273299ec4e7d18d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Tue, 12 Mar 2019 16:50:00 +0000 Subject: [PATCH 18/22] Add test for UdpSocket peer_addr --- src/libstd/net/udp.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index 79e5ae79e4c01..f3f65034f4256 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -903,6 +903,16 @@ mod tests { }) } + #[test] + fn socket_peer_ip4() { + each_ip(&mut |addr1, addr2| { + let server = t!(UdpSocket::bind(&addr1)); + assert_eq!(server.peer_addr().unwrap_err().kind(), ErrorKind::NotConnected); + t!(server.connect(&addr2)); + assert_eq!(addr2, t!(server.peer_addr())); + }) + } + #[test] fn udp_clone_smoke() { each_ip(&mut |addr1, addr2| { From 7e73cd48c4d531d8c3048941b4436833ec8651e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Tue, 12 Mar 2019 17:18:07 +0000 Subject: [PATCH 19/22] Fix test names regarding ip version --- src/libstd/net/udp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index f3f65034f4256..b42a812304269 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -896,7 +896,7 @@ mod tests { } #[test] - fn socket_name_ip4() { + fn socket_name() { each_ip(&mut |addr, _| { let server = t!(UdpSocket::bind(&addr)); assert_eq!(addr, t!(server.local_addr())); @@ -904,7 +904,7 @@ mod tests { } #[test] - fn socket_peer_ip4() { + fn socket_peer() { each_ip(&mut |addr1, addr2| { let server = t!(UdpSocket::bind(&addr1)); assert_eq!(server.peer_addr().unwrap_err().kind(), ErrorKind::NotConnected); From 214110bb4c7902e4787612efc265e4b2bdf0c1df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Sat, 16 Mar 2019 11:19:01 +0000 Subject: [PATCH 20/22] Add UdpSocket peer_addr implementation for L4Re --- src/libstd/sys/unix/l4re.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/l4re.rs b/src/libstd/sys/unix/l4re.rs index b9e725371a36e..b3dd1cf6aaac7 100644 --- a/src/libstd/sys/unix/l4re.rs +++ b/src/libstd/sys/unix/l4re.rs @@ -292,6 +292,10 @@ pub mod net { pub fn into_socket(self) -> Socket { self.inner } + pub fn peer_addr(&self) -> io::Result { + unimpl!(); + } + pub fn socket_addr(&self) -> io::Result { unimpl!(); } @@ -463,4 +467,3 @@ pub mod net { } } } - From 81d5fb5c6fc65e947ff97c02997bfff9a1f6ce16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Sat, 16 Mar 2019 11:20:02 +0000 Subject: [PATCH 21/22] Add UdpSocket peer_addr implementation for Wasm --- src/libstd/sys/wasm/net.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libstd/sys/wasm/net.rs b/src/libstd/sys/wasm/net.rs index a2ea2dfbbc032..c85dd000afe6f 100644 --- a/src/libstd/sys/wasm/net.rs +++ b/src/libstd/sys/wasm/net.rs @@ -156,6 +156,10 @@ impl UdpSocket { unsupported() } + pub fn peer_addr(&self) -> io::Result { + match self.0 {} + } + pub fn socket_addr(&self) -> io::Result { match self.0 {} } From 47ee538a285944e4e2fe824a733b0e40bbe5aa67 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 9 Mar 2019 16:15:40 +0300 Subject: [PATCH 22/22] resolve: Account for new importable entities --- src/librustc_resolve/build_reduced_graph.rs | 18 +++++-------- .../uniform-paths/auxiliary/cross-crate.rs | 5 ++++ .../ui/rust-2018/uniform-paths/cross-crate.rs | 11 ++++++++ .../uniform-paths/cross-crate.stderr | 26 +++++++++++++++++++ 4 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 src/test/ui/rust-2018/uniform-paths/auxiliary/cross-crate.rs create mode 100644 src/test/ui/rust-2018/uniform-paths/cross-crate.rs create mode 100644 src/test/ui/rust-2018/uniform-paths/cross-crate.stderr diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 5c9927011a707..895e92a97f3da 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -636,10 +636,9 @@ impl<'a> Resolver<'a> { // but metadata cannot encode gensyms currently, so we create it here. // This is only a guess, two equivalent idents may incorrectly get different gensyms here. let ident = ident.gensym_if_underscore(); - let def_id = def.def_id(); let expansion = Mark::root(); // FIXME(jseyfried) intercrate hygiene match def { - Def::Mod(..) | Def::Enum(..) => { + Def::Mod(def_id) | Def::Enum(def_id) => { let module = self.new_module(parent, ModuleKind::Def(def, ident.name), def_id, @@ -647,13 +646,14 @@ impl<'a> Resolver<'a> { span); self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion)); } - Def::Variant(..) | Def::TyAlias(..) | Def::ForeignTy(..) => { + Def::Variant(..) | Def::TyAlias(..) | Def::ForeignTy(..) | Def::Existential(..) | + Def::TraitAlias(..) | Def::PrimTy(..) | Def::ToolMod => { self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion)); } Def::Fn(..) | Def::Static(..) | Def::Const(..) | Def::VariantCtor(..) => { self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion)); } - Def::StructCtor(..) => { + Def::StructCtor(def_id, ..) => { self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion)); if let Some(struct_def_id) = @@ -662,7 +662,7 @@ impl<'a> Resolver<'a> { self.struct_constructors.insert(struct_def_id, (def, vis)); } } - Def::Trait(..) => { + Def::Trait(def_id) => { let module_kind = ModuleKind::Def(def, ident.name); let module = self.new_module(parent, module_kind, @@ -683,18 +683,14 @@ impl<'a> Resolver<'a> { } module.populated.set(true); } - Def::Existential(..) | - Def::TraitAlias(..) => { - self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion)); - } - Def::Struct(..) | Def::Union(..) => { + Def::Struct(def_id) | Def::Union(def_id) => { self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion)); // Record field names for error reporting. let field_names = self.cstore.struct_field_names_untracked(def_id); self.insert_field_names(def_id, field_names); } - Def::Macro(..) => { + Def::Macro(..) | Def::NonMacroAttr(..) => { self.define(parent, ident, MacroNS, (def, vis, DUMMY_SP, expansion)); } _ => bug!("unexpected definition: {:?}", def) diff --git a/src/test/ui/rust-2018/uniform-paths/auxiliary/cross-crate.rs b/src/test/ui/rust-2018/uniform-paths/auxiliary/cross-crate.rs new file mode 100644 index 0000000000000..4aa5d1870000d --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/auxiliary/cross-crate.rs @@ -0,0 +1,5 @@ +// edition:2018 + +pub use ignore as built_in_attr; +pub use u8 as built_in_type; +pub use rustfmt as tool_mod; diff --git a/src/test/ui/rust-2018/uniform-paths/cross-crate.rs b/src/test/ui/rust-2018/uniform-paths/cross-crate.rs new file mode 100644 index 0000000000000..27d6dbf4683e3 --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/cross-crate.rs @@ -0,0 +1,11 @@ +// edition:2018 +// aux-build:cross-crate.rs + +extern crate cross_crate; +use cross_crate::*; + +#[built_in_attr] //~ ERROR cannot use a built-in attribute through an import +#[tool_mod::skip] //~ ERROR cannot use a tool module through an import +fn main() { + let _: built_in_type; // OK +} diff --git a/src/test/ui/rust-2018/uniform-paths/cross-crate.stderr b/src/test/ui/rust-2018/uniform-paths/cross-crate.stderr new file mode 100644 index 0000000000000..fdde75faf5f04 --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/cross-crate.stderr @@ -0,0 +1,26 @@ +error: cannot use a built-in attribute through an import + --> $DIR/cross-crate.rs:7:3 + | +LL | #[built_in_attr] + | ^^^^^^^^^^^^^ + | +note: the built-in attribute imported here + --> $DIR/cross-crate.rs:5:5 + | +LL | use cross_crate::*; + | ^^^^^^^^^^^^^^ + +error: cannot use a tool module through an import + --> $DIR/cross-crate.rs:8:3 + | +LL | #[tool_mod::skip] + | ^^^^^^^^ + | +note: the tool module imported here + --> $DIR/cross-crate.rs:5:5 + | +LL | use cross_crate::*; + | ^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors +