diff --git a/README.md b/README.md index f387b4be6008f..dbb5bf9ce38d6 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Read ["Installing Rust"] from [The Book]. 3. Build and install: ```sh - $ ./x.py build && sudo ./x.py dist --install + $ ./x.py build && sudo ./x.py install ``` > ***Note:*** Install locations can be adjusted by copying the config file @@ -43,7 +43,7 @@ Read ["Installing Rust"] from [The Book]. > adjusting the `prefix` option under `[install]`. Various other options are > also supported, and are documented in the config file. - When complete, `sudo ./x.py dist --install` will place several programs into + When complete, `sudo ./x.py install` will place several programs into `/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the API-documentation tool. This install does not include [Cargo], Rust's package manager, which you may also want to build. @@ -96,7 +96,7 @@ build. 4. Navigate to Rust's source code (or clone it), then build it: ```sh - $ ./x.py build && ./x.py dist --install + $ ./x.py build && ./x.py install ``` #### MSVC diff --git a/src/Cargo.lock b/src/Cargo.lock index e23bdbd9fd87f..6fadf148e70e4 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -165,7 +165,7 @@ dependencies = [ "hamcrest 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -472,7 +472,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.12 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -600,7 +600,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libgit2-sys" -version = "0.6.10" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cmake 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2056,7 +2056,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum languageserver-types 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97c2985bfcbbcb0189cfa25e1c10c1ac7111df2b6214b652c690127aefdf4e5b" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" "checksum libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "babb8281da88cba992fa1f4ddec7d63ed96280a1a53ec9b919fd37b53d71e502" -"checksum libgit2-sys 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "dd89dd7196d5fa35b659c3eaf3c1b14b9bd961bfd1a07dfca49adeb8a6aa3763" +"checksum libgit2-sys 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d9dc31ee90fb179b706d35fb672e91d0b74e950d7fb4ea7eae3c0f5ecbf2d3d3" "checksum libssh2-sys 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0db4ec23611747ef772db1c4d650f8bd762f07b461727ec998f953c614024b75" "checksum libz-sys 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e5ee912a45d686d393d5ac87fac15ba0ba18daae14e8e7543c63ebf7fb7e970c" "checksum log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5141eca02775a762cc6cd564d8d2c50f67c0ea3a372cbf1c51592b3e029e10ad" diff --git a/src/bootstrap/config.toml.example b/src/bootstrap/config.toml.example index 95cca96f7fcc0..0eb6c4c82c4dd 100644 --- a/src/bootstrap/config.toml.example +++ b/src/bootstrap/config.toml.example @@ -314,3 +314,9 @@ # Note that this address should not contain a trailing slash as file names will # be appended to it. #upload-addr = "https://example.com/folder" + +# Whether to build a plain source tarball to upload +# We disable that on Windows not to override the one already uploaded on S3 +# as the one built on Windows will contain backslashes in paths causing problems +# on linux +#src-tarball = true diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 14ddcc7cb3232..c50165c5e3904 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -30,11 +30,11 @@ use {Build, Compiler, Mode}; use channel; use util::{cp_r, libdir, is_dylib, cp_filtered, copy, exe}; -fn pkgname(build: &Build, component: &str) -> String { +pub fn pkgname(build: &Build, component: &str) -> String { if component == "cargo" { format!("{}-{}", component, build.cargo_package_vers()) } else if component == "rls" { - format!("{}-{}", component, build.package_vers(&build.release_num("rls"))) + format!("{}-{}", component, build.rls_package_vers()) } else { assert!(component.starts_with("rust")); format!("{}-{}", component, build.rust_package_vers()) @@ -489,38 +489,7 @@ pub fn analysis(build: &Build, compiler: &Compiler, target: &str) { t!(fs::remove_dir_all(&image)); } -const CARGO_VENDOR_VERSION: &'static str = "0.1.4"; - -/// Creates the `rust-src` installer component and the plain source tarball -pub fn rust_src(build: &Build) { - if !build.config.rust_dist_src { - return - } - - println!("Dist src"); - - // Make sure that the root folder of tarball has the correct name - let plain_name = format!("rustc-{}-src", build.rust_package_vers()); - let plain_dst_src = tmpdir(build).join(&plain_name); - let _ = fs::remove_dir_all(&plain_dst_src); - t!(fs::create_dir_all(&plain_dst_src)); - - // This is the set of root paths which will become part of the source package - let src_files = [ - "COPYRIGHT", - "LICENSE-APACHE", - "LICENSE-MIT", - "CONTRIBUTING.md", - "README.md", - "RELEASES.md", - "configure", - "x.py", - ]; - let src_dirs = [ - "man", - "src", - ]; - +fn copy_src_dirs(build: &Build, src_dirs: &[&str], dst_dir: &Path) { let filter_fn = move |path: &Path| { let spath = match path.to_str() { Some(path) => path, @@ -549,60 +518,16 @@ pub fn rust_src(build: &Build) { }; // Copy the directories using our filter - for item in &src_dirs { - let dst = &plain_dst_src.join(item); - t!(fs::create_dir(dst)); + for item in src_dirs { + let dst = &dst_dir.join(item); + t!(fs::create_dir_all(dst)); cp_filtered(&build.src.join(item), dst, &filter_fn); } - // Copy the files normally - for item in &src_files { - copy(&build.src.join(item), &plain_dst_src.join(item)); - } - - // If we're building from git sources, we need to vendor a complete distribution. - if build.src_is_git { - // Get cargo-vendor installed, if it isn't already. - let mut has_cargo_vendor = false; - let mut cmd = Command::new(&build.cargo); - for line in output(cmd.arg("install").arg("--list")).lines() { - has_cargo_vendor |= line.starts_with("cargo-vendor "); - } - if !has_cargo_vendor { - let mut cmd = Command::new(&build.cargo); - cmd.arg("install") - .arg("--force") - .arg("--debug") - .arg("--vers").arg(CARGO_VENDOR_VERSION) - .arg("cargo-vendor") - .env("RUSTC", &build.rustc); - build.run(&mut cmd); - } - - // Vendor all Cargo dependencies - let mut cmd = Command::new(&build.cargo); - cmd.arg("vendor") - .current_dir(&plain_dst_src.join("src")); - build.run(&mut cmd); - } - - // Create the version file - write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes()); - - // Create plain source tarball - let mut tarball = rust_src_location(build); - tarball.set_extension(""); // strip .gz - tarball.set_extension(""); // strip .tar - if let Some(dir) = tarball.parent() { - t!(fs::create_dir_all(dir)); - } - let mut cmd = rust_installer(build); - cmd.arg("tarball") - .arg("--input").arg(&plain_name) - .arg("--output").arg(&tarball) - .arg("--work-dir=.") - .current_dir(tmpdir(build)); - build.run(&mut cmd); +} +/// Creates the `rust-src` installer component +pub fn rust_src(build: &Build) { + println!("Dist src"); let name = pkgname(build, "rust-src"); let image = tmpdir(build).join(format!("{}-image", name)); @@ -636,11 +561,7 @@ pub fn rust_src(build: &Build) { "src/rustc/libc_shim", ]; - for item in &std_src_dirs { - let dst = &dst_src.join(item); - t!(fs::create_dir_all(dst)); - cp_r(&plain_dst_src.join(item), dst); - } + copy_src_dirs(build, &std_src_dirs[..], &dst_src); // Create source tarball in rust-installer format let mut cmd = rust_installer(build); @@ -657,7 +578,86 @@ pub fn rust_src(build: &Build) { build.run(&mut cmd); t!(fs::remove_dir_all(&image)); - t!(fs::remove_dir_all(&plain_dst_src)); +} + +const CARGO_VENDOR_VERSION: &'static str = "0.1.4"; + +/// Creates the plain source tarball +pub fn plain_source_tarball(build: &Build) { + println!("Create plain source tarball"); + + // Make sure that the root folder of tarball has the correct name + let plain_name = format!("{}-src", pkgname(build, "rustc")); + let plain_dst_src = tmpdir(build).join(&plain_name); + let _ = fs::remove_dir_all(&plain_dst_src); + t!(fs::create_dir_all(&plain_dst_src)); + + // This is the set of root paths which will become part of the source package + let src_files = [ + "COPYRIGHT", + "LICENSE-APACHE", + "LICENSE-MIT", + "CONTRIBUTING.md", + "README.md", + "RELEASES.md", + "configure", + "x.py", + ]; + let src_dirs = [ + "man", + "src", + ]; + + copy_src_dirs(build, &src_dirs[..], &plain_dst_src); + + // Copy the files normally + for item in &src_files { + copy(&build.src.join(item), &plain_dst_src.join(item)); + } + + // Create the version file + write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes()); + + // If we're building from git sources, we need to vendor a complete distribution. + if build.src_is_git { + // Get cargo-vendor installed, if it isn't already. + let mut has_cargo_vendor = false; + let mut cmd = Command::new(&build.cargo); + for line in output(cmd.arg("install").arg("--list")).lines() { + has_cargo_vendor |= line.starts_with("cargo-vendor "); + } + if !has_cargo_vendor { + let mut cmd = Command::new(&build.cargo); + cmd.arg("install") + .arg("--force") + .arg("--debug") + .arg("--vers").arg(CARGO_VENDOR_VERSION) + .arg("cargo-vendor") + .env("RUSTC", &build.rustc); + build.run(&mut cmd); + } + + // Vendor all Cargo dependencies + let mut cmd = Command::new(&build.cargo); + cmd.arg("vendor") + .current_dir(&plain_dst_src.join("src")); + build.run(&mut cmd); + } + + // Create plain source tarball + let mut tarball = rust_src_location(build); + tarball.set_extension(""); // strip .gz + tarball.set_extension(""); // strip .tar + if let Some(dir) = tarball.parent() { + t!(fs::create_dir_all(dir)); + } + let mut cmd = rust_installer(build); + cmd.arg("tarball") + .arg("--input").arg(&plain_name) + .arg("--output").arg(&tarball) + .arg("--work-dir=.") + .current_dir(tmpdir(build)); + build.run(&mut cmd); } fn install(src: &Path, dstdir: &Path, perms: u32) { diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index a1466d68a135a..fe4e18ab622cd 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -69,7 +69,9 @@ pub enum Subcommand { Clean, Dist { paths: Vec, - install: bool, + }, + Install { + paths: Vec, }, } @@ -85,7 +87,8 @@ Subcommands: bench Build and run some benchmarks doc Build documentation clean Clean out build directories - dist Build and/or install distribution artifacts + dist Build distribution artifacts + install Install distribution artifacts To learn more about a subcommand, run `./x.py -h`"); @@ -125,7 +128,8 @@ To learn more about a subcommand, run `./x.py -h`"); || (s == "bench") || (s == "doc") || (s == "clean") - || (s == "dist")); + || (s == "dist") + || (s == "install")); let subcommand = match possible_subcommands.first() { Some(s) => s, None => { @@ -139,7 +143,6 @@ To learn more about a subcommand, run `./x.py -h`"); match subcommand.as_str() { "test" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); }, "bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); }, - "dist" => { opts.optflag("", "install", "run installer as well"); }, _ => { }, }; @@ -281,7 +284,11 @@ Arguments: "dist" => { Subcommand::Dist { paths: paths, - install: matches.opt_present("install"), + } + } + "install" => { + Subcommand::Install { + paths: paths, } } _ => { diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index dce0b1670e181..21e21628dc947 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -19,7 +19,7 @@ use std::path::{Path, PathBuf, Component}; use std::process::Command; use Build; -use dist::{sanitize_sh, tmpdir}; +use dist::{pkgname, sanitize_sh, tmpdir}; pub struct Installer<'a> { build: &'a Build, @@ -29,6 +29,13 @@ pub struct Installer<'a> { bindir: PathBuf, libdir: PathBuf, mandir: PathBuf, + empty_dir: PathBuf, +} + +impl<'a> Drop for Installer<'a> { + fn drop(&mut self) { + t!(fs::remove_dir_all(&self.empty_dir)); + } } impl<'a> Installer<'a> { @@ -61,6 +68,10 @@ impl<'a> Installer<'a> { let libdir = add_destdir(&libdir, &destdir); let mandir = add_destdir(&mandir, &destdir); + let empty_dir = build.out.join("tmp/empty_dir"); + + t!(fs::create_dir_all(&empty_dir)); + Installer { build, prefix, @@ -69,52 +80,49 @@ impl<'a> Installer<'a> { bindir, libdir, mandir, + empty_dir, } } - /// Installs everything. - pub fn install(&self, stage: u32, host: &str) { - let empty_dir = self.build.out.join("tmp/empty_dir"); - t!(fs::create_dir_all(&empty_dir)); - - if self.build.config.docs { - self.install_sh("docs", "rust-docs", &self.build.rust_package_vers(), - stage, Some(host), &empty_dir); - } + pub fn install_docs(&self, stage: u32, host: &str) { + self.install_sh("docs", "rust-docs", stage, Some(host)); + } + pub fn install_std(&self, stage: u32) { for target in self.build.config.target.iter() { - self.install_sh("std", "rust-std", &self.build.rust_package_vers(), - stage, Some(target), &empty_dir); + self.install_sh("std", "rust-std", stage, Some(target)); } + } - if self.build.config.extended { - self.install_sh("cargo", "cargo", &self.build.cargo_package_vers(), - stage, Some(host), &empty_dir); - self.install_sh("rls", "rls", &self.build.rls_package_vers(), - stage, Some(host), &empty_dir); - self.install_sh("analysis", "rust-analysis", &self.build.rust_package_vers(), - stage, Some(host), &empty_dir); - self.install_sh("src", "rust-src", &self.build.rust_package_vers(), - stage, None, &empty_dir); - } + pub fn install_cargo(&self, stage: u32, host: &str) { + self.install_sh("cargo", "cargo", stage, Some(host)); + } - self.install_sh("rustc", "rustc", &self.build.rust_package_vers(), - stage, Some(host), &empty_dir); + pub fn install_rls(&self, stage: u32, host: &str) { + self.install_sh("rls", "rls", stage, Some(host)); + } + + pub fn install_analysis(&self, stage: u32, host: &str) { + self.install_sh("analysis", "rust-analysis", stage, Some(host)); + } - t!(fs::remove_dir_all(&empty_dir)); + pub fn install_src(&self, stage: u32) { + self.install_sh("src", "rust-src", stage, None); + } + pub fn install_rustc(&self, stage: u32, host: &str) { + self.install_sh("rustc", "rustc", stage, Some(host)); } - fn install_sh(&self, package: &str, name: &str, version: &str, - stage: u32, host: Option<&str>, empty_dir: &Path) { + fn install_sh(&self, package: &str, name: &str, stage: u32, host: Option<&str>) { println!("Install {} stage{} ({:?})", package, stage, host); let package_name = if let Some(host) = host { - format!("{}-{}-{}", name, version, host) + format!("{}-{}", pkgname(self.build, name), host) } else { - format!("{}-{}", name, version) + pkgname(self.build, name) }; let mut cmd = Command::new("sh"); - cmd.current_dir(empty_dir) + cmd.current_dir(&self.empty_dir) .arg(sanitize_sh(&tmpdir(self.build).join(&package_name).join("install.sh"))) .arg(format!("--prefix={}", sanitize_sh(&self.prefix))) .arg(format!("--sysconfdir={}", sanitize_sh(&self.sysconfdir))) diff --git a/src/bootstrap/mk/Makefile.in b/src/bootstrap/mk/Makefile.in index a5df741e2bfc8..47c792a510b1b 100644 --- a/src/bootstrap/mk/Makefile.in +++ b/src/bootstrap/mk/Makefile.in @@ -69,7 +69,7 @@ distcheck: $(Q)$(BOOTSTRAP) dist $(BOOTSTRAP_ARGS) $(Q)$(BOOTSTRAP) test distcheck $(BOOTSTRAP_ARGS) install: - $(Q)$(BOOTSTRAP) dist --install $(BOOTSTRAP_ARGS) + $(Q)$(BOOTSTRAP) install $(BOOTSTRAP_ARGS) tidy: $(Q)$(BOOTSTRAP) test src/tools/tidy $(BOOTSTRAP_ARGS) prepare: diff --git a/src/bootstrap/step.rs b/src/bootstrap/step.rs index 57915446e1d1a..16029a8a0cccd 100644 --- a/src/bootstrap/step.rs +++ b/src/bootstrap/step.rs @@ -492,6 +492,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { .host(true) .run(move |s| check::docs(build, &s.compiler())); rules.test("check-distcheck", "distcheck") + .dep(|s| s.name("dist-plain-source-tarball")) .dep(|s| s.name("dist-src")) .run(move |_| check::distcheck(build)); @@ -734,6 +735,13 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { dist::mingw(build, s.target) } }); + rules.dist("dist-plain-source-tarball", "src") + .default(build.config.rust_dist_src) + .host(true) + .only_build(true) + .only_host_build(true) + .dep(move |s| tool_rust_installer(build, s)) + .run(move |_| dist::plain_source_tarball(build)); rules.dist("dist-src", "src") .default(true) .host(true) @@ -759,9 +767,6 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { .dep(|s| s.name("tool-rls")) .dep(move |s| tool_rust_installer(build, s)) .run(move |s| dist::rls(build, s.stage, s.target)); - rules.dist("install", "path/to/nowhere") - .dep(|s| s.name("default:dist")) - .run(move |s| install::Installer::new(build).install(s.stage, s.target)); rules.dist("dist-cargo", "cargo") .host(true) .only_host_build(true) @@ -789,6 +794,47 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules { .dep(move |s| s.name("tool-build-manifest").target(&build.config.build).stage(0)) .run(move |_| dist::hash_and_sign(build)); + rules.install("install-docs", "src/doc") + .default(build.config.docs) + .only_host_build(true) + .dep(|s| s.name("dist-docs")) + .run(move |s| install::Installer::new(build).install_docs(s.stage, s.target)); + rules.install("install-std", "src/libstd") + .default(true) + .only_host_build(true) + .dep(|s| s.name("dist-std")) + .run(move |s| install::Installer::new(build).install_std(s.stage)); + rules.install("install-cargo", "cargo") + .default(build.config.extended) + .host(true) + .only_host_build(true) + .dep(|s| s.name("dist-cargo")) + .run(move |s| install::Installer::new(build).install_cargo(s.stage, s.target)); + rules.install("install-rls", "rls") + .default(build.config.extended) + .host(true) + .only_host_build(true) + .dep(|s| s.name("dist-rls")) + .run(move |s| install::Installer::new(build).install_rls(s.stage, s.target)); + rules.install("install-analysis", "analysis") + .default(build.config.extended) + .only_host_build(true) + .dep(|s| s.name("dist-analysis")) + .run(move |s| install::Installer::new(build).install_analysis(s.stage, s.target)); + rules.install("install-src", "src") + .default(build.config.extended) + .host(true) + .only_build(true) + .only_host_build(true) + .dep(|s| s.name("dist-src")) + .run(move |s| install::Installer::new(build).install_src(s.stage)); + rules.install("install-rustc", "src/librustc") + .default(true) + .host(true) + .only_host_build(true) + .dep(|s| s.name("dist-rustc")) + .run(move |s| install::Installer::new(build).install_rustc(s.stage, s.target)); + rules.verify(); return rules; @@ -902,6 +948,7 @@ enum Kind { Bench, Dist, Doc, + Install, } impl<'a> Rule<'a> { @@ -1033,6 +1080,12 @@ impl<'a> Rules<'a> { self.rule(name, path, Kind::Dist) } + /// Same as `build`, but for `Kind::Install`. + fn install<'b>(&'b mut self, name: &'a str, path: &'a str) + -> RuleBuilder<'a, 'b> { + self.rule(name, path, Kind::Install) + } + fn rule<'b>(&'b mut self, name: &'a str, path: &'a str, @@ -1073,6 +1126,7 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd? "test" => Kind::Test, "bench" => Kind::Bench, "dist" => Kind::Dist, + "install" => Kind::Install, _ => return None, }; let rules = self.rules.values().filter(|r| r.kind == kind); @@ -1122,13 +1176,8 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd? Subcommand::Doc { ref paths } => (Kind::Doc, &paths[..]), Subcommand::Test { ref paths, test_args: _ } => (Kind::Test, &paths[..]), Subcommand::Bench { ref paths, test_args: _ } => (Kind::Bench, &paths[..]), - Subcommand::Dist { ref paths, install } => { - if install { - return vec![self.sbuild.name("install")] - } else { - (Kind::Dist, &paths[..]) - } - } + Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]), + Subcommand::Install { ref paths } => (Kind::Install, &paths[..]), Subcommand::Clean => panic!(), }; @@ -1347,10 +1396,6 @@ mod tests { use config::Config; use flags::Flags; - macro_rules! a { - ($($a:expr),*) => (vec![$($a.to_string()),*]) - } - fn build(args: &[&str], extra_host: &[&str], extra_target: &[&str]) -> Build { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 5ee0b1c9e5ea4..64e16c41d1132 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -40,7 +40,7 @@ use ty::layout::{Layout, TargetDataLayout}; use ty::inhabitedness::DefIdForest; use ty::maps; use ty::steal::Steal; -use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet}; +use util::nodemap::{NodeMap, NodeSet, DefIdSet}; use util::nodemap::{FxHashMap, FxHashSet}; use rustc_data_structures::accumulate_vec::AccumulateVec; @@ -499,33 +499,6 @@ pub struct GlobalCtxt<'tcx> { /// Maps Expr NodeId's to `true` iff `&expr` can have 'static lifetime. pub rvalue_promotable_to_static: RefCell>, - /// Maps Fn items to a collection of fragment infos. - /// - /// The main goal is to identify data (each of which may be moved - /// or assigned) whose subparts are not moved nor assigned - /// (i.e. their state is *unfragmented*) and corresponding ast - /// nodes where the path to that data is moved or assigned. - /// - /// In the long term, unfragmented values will have their - /// destructor entirely driven by a single stack-local drop-flag, - /// and their parents, the collections of the unfragmented values - /// (or more simply, "fragmented values"), are mapped to the - /// corresponding collections of stack-local drop-flags. - /// - /// (However, in the short term that is not the case; e.g. some - /// unfragmented paths still need to be zeroed, namely when they - /// reference parent data from an outer scope that was not - /// entirely moved, and therefore that needs to be zeroed so that - /// we do not get double-drop when we hit the end of the parent - /// scope.) - /// - /// Also: currently the table solely holds keys for node-ids of - /// unfragmented values (see `FragmentInfo` enum definition), but - /// longer-term we will need to also store mappings from - /// fragmented data to the set of unfragmented pieces that - /// constitute it. - pub fragment_infos: RefCell>>, - /// The definite name of the current crate after taking into account /// attributes, commandline parameters, etc. pub crate_name: Symbol, @@ -730,7 +703,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { selection_cache: traits::SelectionCache::new(), evaluation_cache: traits::EvaluationCache::new(), rvalue_promotable_to_static: RefCell::new(NodeMap()), - fragment_infos: RefCell::new(DefIdMap()), crate_name: Symbol::intern(crate_name), data_layout: data_layout, layout_cache: RefCell::new(FxHashMap()), diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 963ee9b7165e5..aeffd71a09649 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -444,17 +444,6 @@ pub struct CReaderCacheKey { pub pos: usize, } -/// Describes the fragment-state associated with a NodeId. -/// -/// Currently only unfragmented paths have entries in the table, -/// but longer-term this enum is expected to expand to also -/// include data for fragmented paths. -#[derive(Copy, Clone, Debug)] -pub enum FragmentInfo { - Moved { var: NodeId, move_expr: NodeId }, - Assigned { var: NodeId, assign_expr: NodeId, assignee_id: NodeId }, -} - // Flags that we track on types. These flags are propagated upwards // through the type during type construction, so that we can quickly // check whether the type has various kinds of types in it without diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 01fed11fc97af..eb7744e1213e7 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -266,13 +266,29 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// if not a structure at all. Corresponds to the only possible unsized /// field, and its type can be used to determine unsizing strategy. pub fn struct_tail(self, mut ty: Ty<'tcx>) -> Ty<'tcx> { - while let TyAdt(def, substs) = ty.sty { - if !def.is_struct() { - break; - } - match def.struct_variant().fields.last() { - Some(f) => ty = f.ty(self, substs), - None => break, + loop { + match ty.sty { + ty::TyAdt(def, substs) => { + if !def.is_struct() { + break; + } + match def.struct_variant().fields.last() { + Some(f) => ty = f.ty(self, substs), + None => break, + } + } + + ty::TyTuple(tys, _) => { + if let Some((&last_ty, _)) = tys.split_last() { + ty = last_ty; + } else { + break; + } + } + + _ => { + break; + } } } ty diff --git a/src/librustc_borrowck/borrowck/fragments.rs b/src/librustc_borrowck/borrowck/fragments.rs deleted file mode 100644 index b728d4d534516..0000000000000 --- a/src/librustc_borrowck/borrowck/fragments.rs +++ /dev/null @@ -1,542 +0,0 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Helper routines used for fragmenting structural paths due to moves for -//! tracking drop obligations. Please see the extensive comments in the -//! section "Structural fragments" in `README.md`. - -use self::Fragment::*; - -use borrowck::InteriorKind::{InteriorField, InteriorElement}; -use borrowck::{self, LoanPath}; -use borrowck::LoanPathKind::{LpVar, LpUpvar, LpDowncast, LpExtend}; -use borrowck::LoanPathElem::{LpDeref, LpInterior}; -use borrowck::move_data::InvalidMovePathIndex; -use borrowck::move_data::{MoveData, MovePathIndex}; -use rustc::hir::def_id::{DefId}; -use rustc::ty::{self, AdtKind, TyCtxt}; -use rustc::middle::mem_categorization as mc; - -use std::mem; -use std::rc::Rc; -use syntax::ast; -use syntax_pos::DUMMY_SP; - -#[derive(PartialEq, Eq, PartialOrd, Ord)] -enum Fragment { - // This represents the path described by the move path index - Just(MovePathIndex), - - // This represents the collection of all but one of the elements - // from an array at the path described by the move path index. - // Note that attached MovePathIndex should have mem_categorization - // of InteriorElement (i.e. array dereference `&foo[..]`). - AllButOneFrom(MovePathIndex), -} - -impl Fragment { - fn loan_path_repr(&self, move_data: &MoveData) -> String { - let lp = |mpi| move_data.path_loan_path(mpi); - match *self { - Just(mpi) => format!("{:?}", lp(mpi)), - AllButOneFrom(mpi) => format!("$(allbutone {:?})", lp(mpi)), - } - } - - fn loan_path_user_string(&self, move_data: &MoveData) -> String { - let lp = |mpi| move_data.path_loan_path(mpi); - match *self { - Just(mpi) => lp(mpi).to_string(), - AllButOneFrom(mpi) => format!("$(allbutone {})", lp(mpi)), - } - } -} - -pub fn build_unfragmented_map(this: &mut borrowck::BorrowckCtxt, - move_data: &MoveData, - id: ast::NodeId) { - let fr = &move_data.fragments.borrow(); - - // For now, don't care about other kinds of fragments; the precise - // classfication of all paths for non-zeroing *drop* needs them, - // but the loose approximation used by non-zeroing moves does not. - let moved_leaf_paths = fr.moved_leaf_paths(); - let assigned_leaf_paths = fr.assigned_leaf_paths(); - - let mut fragment_infos = Vec::with_capacity(moved_leaf_paths.len()); - - let find_var_id = |move_path_index: MovePathIndex| -> Option { - let lp = move_data.path_loan_path(move_path_index); - match lp.kind { - LpVar(var_id) => Some(var_id), - LpUpvar(ty::UpvarId { var_id, closure_expr_id }) => { - // The `var_id` is unique *relative to* the current function. - // (Check that we are indeed talking about the same function.) - assert_eq!(id, closure_expr_id); - Some(var_id) - } - LpDowncast(..) | LpExtend(..) => { - // This simple implementation of non-zeroing move does - // not attempt to deal with tracking substructure - // accurately in the general case. - None - } - } - }; - - let moves = move_data.moves.borrow(); - for &move_path_index in moved_leaf_paths { - let var_id = match find_var_id(move_path_index) { - None => continue, - Some(var_id) => var_id, - }; - - move_data.each_applicable_move(move_path_index, |move_index| { - let info = ty::FragmentInfo::Moved { - var: var_id, - move_expr: moves[move_index.get()].id, - }; - debug!("fragment_infos push({:?} \ - due to move_path_index: {} move_index: {}", - info, move_path_index.get(), move_index.get()); - fragment_infos.push(info); - true - }); - } - - for &move_path_index in assigned_leaf_paths { - let var_id = match find_var_id(move_path_index) { - None => continue, - Some(var_id) => var_id, - }; - - let var_assigns = move_data.var_assignments.borrow(); - for var_assign in var_assigns.iter() - .filter(|&assign| assign.path == move_path_index) - { - let info = ty::FragmentInfo::Assigned { - var: var_id, - assign_expr: var_assign.id, - assignee_id: var_assign.assignee_id, - }; - debug!("fragment_infos push({:?} due to var_assignment", info); - fragment_infos.push(info); - } - } - - let mut fraginfo_map = this.tcx.fragment_infos.borrow_mut(); - let fn_did = this.tcx.hir.local_def_id(id); - let prev = fraginfo_map.insert(fn_did, fragment_infos); - assert!(prev.is_none()); -} - -pub struct FragmentSets { - /// During move_data construction, `moved_leaf_paths` tracks paths - /// that have been used directly by being moved out of. When - /// move_data construction has been completed, `moved_leaf_paths` - /// tracks such paths that are *leaf fragments* (e.g. `a.j` if we - /// never move out any child like `a.j.x`); any parent paths - /// (e.g. `a` for the `a.j` example) are moved over to - /// `parents_of_fragments`. - moved_leaf_paths: Vec, - - /// `assigned_leaf_paths` tracks paths that have been used - /// directly by being overwritten, but is otherwise much like - /// `moved_leaf_paths`. - assigned_leaf_paths: Vec, - - /// `parents_of_fragments` tracks paths that are definitely - /// parents of paths that have been moved. - /// - /// FIXME(pnkfelix) probably do not want/need - /// `parents_of_fragments` at all, if we can avoid it. - /// - /// Update: I do not see a way to avoid it. Maybe just remove - /// above fixme, or at least document why doing this may be hard. - parents_of_fragments: Vec, - - /// During move_data construction (specifically the - /// fixup_fragment_sets call), `unmoved_fragments` tracks paths - /// that have been "left behind" after a sibling has been moved or - /// assigned. When move_data construction has been completed, - /// `unmoved_fragments` tracks paths that were *only* results of - /// being left-behind, and never directly moved themselves. - unmoved_fragments: Vec, -} - -impl FragmentSets { - pub fn new() -> FragmentSets { - FragmentSets { - unmoved_fragments: Vec::new(), - moved_leaf_paths: Vec::new(), - assigned_leaf_paths: Vec::new(), - parents_of_fragments: Vec::new(), - } - } - - pub fn moved_leaf_paths(&self) -> &[MovePathIndex] { - &self.moved_leaf_paths - } - - pub fn assigned_leaf_paths(&self) -> &[MovePathIndex] { - &self.assigned_leaf_paths - } - - pub fn add_move(&mut self, path_index: MovePathIndex) { - self.moved_leaf_paths.push(path_index); - } - - pub fn add_assignment(&mut self, path_index: MovePathIndex) { - self.assigned_leaf_paths.push(path_index); - } -} - -pub fn instrument_move_fragments<'a, 'tcx>(this: &MoveData<'tcx>, - tcx: TyCtxt<'a, 'tcx, 'tcx>, - id: ast::NodeId) { - let span_err = tcx.hir.attrs(id).iter() - .any(|a| a.check_name("rustc_move_fragments")); - let print = tcx.sess.opts.debugging_opts.print_move_fragments; - - if !span_err && !print { return; } - - let sp = tcx.hir.span(id); - - let instrument_all_paths = |kind, vec_rc: &Vec| { - for (i, mpi) in vec_rc.iter().enumerate() { - let lp = || this.path_loan_path(*mpi); - if span_err { - tcx.sess.span_err(sp, &format!("{}: `{}`", kind, lp())); - } - if print { - println!("id:{} {}[{}] `{}`", id, kind, i, lp()); - } - } - }; - - let instrument_all_fragments = |kind, vec_rc: &Vec| { - for (i, f) in vec_rc.iter().enumerate() { - let render = || f.loan_path_user_string(this); - if span_err { - tcx.sess.span_err(sp, &format!("{}: `{}`", kind, render())); - } - if print { - println!("id:{} {}[{}] `{}`", id, kind, i, render()); - } - } - }; - - let fragments = this.fragments.borrow(); - instrument_all_paths("moved_leaf_path", &fragments.moved_leaf_paths); - instrument_all_fragments("unmoved_fragment", &fragments.unmoved_fragments); - instrument_all_paths("parent_of_fragments", &fragments.parents_of_fragments); - instrument_all_paths("assigned_leaf_path", &fragments.assigned_leaf_paths); -} - -/// Normalizes the fragment sets in `this`; i.e., removes duplicate entries, constructs the set of -/// parents, and constructs the left-over fragments. -/// -/// Note: "left-over fragments" means paths that were not directly referenced in moves nor -/// assignments, but must nonetheless be tracked as potential drop obligations. -pub fn fixup_fragment_sets<'a, 'tcx>(this: &MoveData<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>) { - - let mut fragments = this.fragments.borrow_mut(); - - // Swap out contents of fragments so that we can modify the fields - // without borrowing the common fragments. - let mut unmoved = mem::replace(&mut fragments.unmoved_fragments, vec![]); - let mut parents = mem::replace(&mut fragments.parents_of_fragments, vec![]); - let mut moved = mem::replace(&mut fragments.moved_leaf_paths, vec![]); - let mut assigned = mem::replace(&mut fragments.assigned_leaf_paths, vec![]); - - let path_lps = |mpis: &[MovePathIndex]| -> Vec { - mpis.iter().map(|mpi| format!("{:?}", this.path_loan_path(*mpi))).collect() - }; - - let frag_lps = |fs: &[Fragment]| -> Vec { - fs.iter().map(|f| f.loan_path_repr(this)).collect() - }; - - // First, filter out duplicates - moved.sort(); - moved.dedup(); - debug!("fragments 1 moved: {:?}", path_lps(&moved)); - - assigned.sort(); - assigned.dedup(); - debug!("fragments 1 assigned: {:?}", path_lps(&assigned)); - - // Second, build parents from the moved and assigned. - for m in &moved { - let mut p = this.path_parent(*m); - while p != InvalidMovePathIndex { - parents.push(p); - p = this.path_parent(p); - } - } - for a in &assigned { - let mut p = this.path_parent(*a); - while p != InvalidMovePathIndex { - parents.push(p); - p = this.path_parent(p); - } - } - - parents.sort(); - parents.dedup(); - debug!("fragments 2 parents: {:?}", path_lps(&parents)); - - // Third, filter the moved and assigned fragments down to just the non-parents - moved.retain(|f| non_member(*f, &parents)); - debug!("fragments 3 moved: {:?}", path_lps(&moved)); - - assigned.retain(|f| non_member(*f, &parents)); - debug!("fragments 3 assigned: {:?}", path_lps(&assigned)); - - // Fourth, build the leftover from the moved, assigned, and parents. - for m in &moved { - let lp = this.path_loan_path(*m); - add_fragment_siblings(this, tcx, &mut unmoved, lp, None); - } - for a in &assigned { - let lp = this.path_loan_path(*a); - add_fragment_siblings(this, tcx, &mut unmoved, lp, None); - } - for p in &parents { - let lp = this.path_loan_path(*p); - add_fragment_siblings(this, tcx, &mut unmoved, lp, None); - } - - unmoved.sort(); - unmoved.dedup(); - debug!("fragments 4 unmoved: {:?}", frag_lps(&unmoved)); - - // Fifth, filter the leftover fragments down to its core. - unmoved.retain(|f| match *f { - AllButOneFrom(_) => true, - Just(mpi) => non_member(mpi, &parents) && - non_member(mpi, &moved) && - non_member(mpi, &assigned) - }); - debug!("fragments 5 unmoved: {:?}", frag_lps(&unmoved)); - - // Swap contents back in. - fragments.unmoved_fragments = unmoved; - fragments.parents_of_fragments = parents; - fragments.moved_leaf_paths = moved; - fragments.assigned_leaf_paths = assigned; - - return; - - fn non_member(elem: MovePathIndex, set: &[MovePathIndex]) -> bool { - match set.binary_search(&elem) { - Ok(_) => false, - Err(_) => true, - } - } -} - -/// Adds all of the precisely-tracked siblings of `lp` as potential move paths of interest. For -/// example, if `lp` represents `s.x.j`, then adds moves paths for `s.x.i` and `s.x.k`, the -/// siblings of `s.x.j`. -fn add_fragment_siblings<'a, 'tcx>(this: &MoveData<'tcx>, - tcx: TyCtxt<'a, 'tcx, 'tcx>, - gathered_fragments: &mut Vec, - lp: Rc>, - origin_id: Option) { - match lp.kind { - LpVar(_) | LpUpvar(..) => {} // Local variables have no siblings. - - // Consuming a downcast is like consuming the original value, so propage inward. - LpDowncast(ref loan_parent, _) => { - add_fragment_siblings(this, tcx, gathered_fragments, loan_parent.clone(), origin_id); - } - - // *LV for Unique consumes the contents of the box (at - // least when it is non-copy...), so propagate inward. - LpExtend(ref loan_parent, _, LpDeref(mc::Unique)) => { - add_fragment_siblings(this, tcx, gathered_fragments, loan_parent.clone(), origin_id); - } - - // *LV for unsafe and borrowed pointers do not consume their loan path, so stop here. - LpExtend(.., LpDeref(mc::UnsafePtr(..))) | - LpExtend(.., LpDeref(mc::Implicit(..))) | - LpExtend(.., LpDeref(mc::BorrowedPtr(..))) => {} - - // FIXME (pnkfelix): LV[j] should be tracked, at least in the - // sense of we will track the remaining drop obligation of the - // rest of the array. - // - // Well, either that or LV[j] should be made illegal. - // But even then, we will need to deal with destructuring - // bind. - // - // Anyway, for now: LV[j] is not tracked precisely - LpExtend(.., LpInterior(_, InteriorElement(..))) => { - let mp = this.move_path(tcx, lp.clone()); - gathered_fragments.push(AllButOneFrom(mp)); - } - - // field access LV.x and tuple access LV#k are the cases - // we are interested in - LpExtend(ref loan_parent, mc, - LpInterior(_, InteriorField(ref field_name))) => { - let enum_variant_info = match loan_parent.kind { - LpDowncast(ref loan_parent_2, variant_def_id) => - Some((variant_def_id, loan_parent_2.clone())), - LpExtend(..) | LpVar(..) | LpUpvar(..) => - None, - }; - add_fragment_siblings_for_extension( - this, - tcx, - gathered_fragments, - loan_parent, mc, field_name, &lp, origin_id, enum_variant_info); - } - } -} - -/// We have determined that `origin_lp` destructures to LpExtend(parent, original_field_name). -/// Based on this, add move paths for all of the siblings of `origin_lp`. -fn add_fragment_siblings_for_extension<'a, 'tcx>(this: &MoveData<'tcx>, - tcx: TyCtxt<'a, 'tcx, 'tcx>, - gathered_fragments: &mut Vec, - parent_lp: &Rc>, - mc: mc::MutabilityCategory, - origin_field_name: &mc::FieldName, - origin_lp: &Rc>, - origin_id: Option, - enum_variant_info: Option<(DefId, - Rc>)>) { - let parent_ty = parent_lp.to_type(); - - let mut add_fragment_sibling_local = |field_name, variant_did| { - add_fragment_sibling_core( - this, tcx, gathered_fragments, parent_lp.clone(), mc, field_name, origin_lp, - variant_did); - }; - - match parent_ty.sty { - ty::TyTuple(ref v, _) => { - let tuple_idx = match *origin_field_name { - mc::PositionalField(tuple_idx) => tuple_idx, - mc::NamedField(_) => - bug!("tuple type {:?} should not have named fields.", - parent_ty), - }; - let tuple_len = v.len(); - for i in 0..tuple_len { - if i == tuple_idx { continue } - let field_name = mc::PositionalField(i); - add_fragment_sibling_local(field_name, None); - } - } - - ty::TyAdt(def, ..) => match def.adt_kind() { - AdtKind::Struct => { - match *origin_field_name { - mc::NamedField(ast_name) => { - for f in &def.struct_variant().fields { - if f.name == ast_name { - continue; - } - let field_name = mc::NamedField(f.name); - add_fragment_sibling_local(field_name, None); - } - } - mc::PositionalField(tuple_idx) => { - for (i, _f) in def.struct_variant().fields.iter().enumerate() { - if i == tuple_idx { - continue - } - let field_name = mc::PositionalField(i); - add_fragment_sibling_local(field_name, None); - } - } - } - } - AdtKind::Union => { - // Do nothing, all union fields are moved/assigned together. - } - AdtKind::Enum => { - let variant = match enum_variant_info { - Some((vid, ref _lp2)) => def.variant_with_id(vid), - None => { - assert!(def.is_univariant()); - &def.variants[0] - } - }; - match *origin_field_name { - mc::NamedField(ast_name) => { - for field in &variant.fields { - if field.name == ast_name { - continue; - } - let field_name = mc::NamedField(field.name); - add_fragment_sibling_local(field_name, Some(variant.did)); - } - } - mc::PositionalField(tuple_idx) => { - for (i, _f) in variant.fields.iter().enumerate() { - if tuple_idx == i { - continue; - } - let field_name = mc::PositionalField(i); - add_fragment_sibling_local(field_name, None); - } - } - } - } - }, - - ref ty => { - let span = origin_id.map_or(DUMMY_SP, |id| tcx.hir.span(id)); - span_bug!(span, - "type {:?} ({:?}) is not fragmentable", - parent_ty, ty); - } - } -} - -/// Adds the single sibling `LpExtend(parent, new_field_name)` of `origin_lp` (the original -/// loan-path). -fn add_fragment_sibling_core<'a, 'tcx>(this: &MoveData<'tcx>, - tcx: TyCtxt<'a, 'tcx, 'tcx>, - gathered_fragments: &mut Vec, - parent: Rc>, - mc: mc::MutabilityCategory, - new_field_name: mc::FieldName, - origin_lp: &Rc>, - enum_variant_did: Option) - -> MovePathIndex { - let opt_variant_did = match parent.kind { - LpDowncast(_, variant_did) => Some(variant_did), - LpVar(..) | LpUpvar(..) | LpExtend(..) => enum_variant_did, - }; - - let loan_path_elem = LpInterior(opt_variant_did, InteriorField(new_field_name)); - let new_lp_type = match new_field_name { - mc::NamedField(ast_name) => - tcx.named_element_ty(parent.to_type(), ast_name, opt_variant_did), - mc::PositionalField(idx) => - tcx.positional_element_ty(parent.to_type(), idx, opt_variant_did), - }; - let new_lp_variant = LpExtend(parent, mc, loan_path_elem); - let new_lp = LoanPath::new(new_lp_variant, new_lp_type.unwrap()); - debug!("add_fragment_sibling_core(new_lp={:?}, origin_lp={:?})", - new_lp, origin_lp); - let mp = this.move_path(tcx, Rc::new(new_lp)); - - // Do not worry about checking for duplicates here; we will sort - // and dedup after all are added. - gathered_fragments.push(Just(mp)); - - mp -} diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index f7c20542cbf2e..ff5ebb9c1dc5d 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -129,13 +129,6 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) { move_data: flowed_moves } = build_borrowck_dataflow_data(bccx, &cfg, body_id); - move_data::fragments::instrument_move_fragments(&flowed_moves.move_data, - bccx.tcx, - owner_id); - move_data::fragments::build_unfragmented_map(bccx, - &flowed_moves.move_data, - owner_id); - check_loans::check_loans(bccx, &loan_dfcx, &flowed_moves, &all_loans, body); } diff --git a/src/librustc_borrowck/borrowck/move_data.rs b/src/librustc_borrowck/borrowck/move_data.rs index 3e23086ec7bdd..1b364596a23f7 100644 --- a/src/librustc_borrowck/borrowck/move_data.rs +++ b/src/librustc_borrowck/borrowck/move_data.rs @@ -33,9 +33,6 @@ use syntax_pos::Span; use rustc::hir; use rustc::hir::intravisit::IdRange; -#[path="fragments.rs"] -pub mod fragments; - pub struct MoveData<'tcx> { /// Move paths. See section "Move paths" in `README.md`. pub paths: RefCell>>, @@ -62,9 +59,6 @@ pub struct MoveData<'tcx> { /// Assignments to a variable or path, like `x = foo`, but not `x += foo`. pub assignee_ids: RefCell, - - /// Path-fragments from moves in to or out of parts of structured data. - pub fragments: RefCell, } pub struct FlowedMoveData<'a, 'tcx: 'a> { @@ -223,7 +217,6 @@ impl<'a, 'tcx> MoveData<'tcx> { var_assignments: RefCell::new(Vec::new()), variant_matches: RefCell::new(Vec::new()), assignee_ids: RefCell::new(NodeSet()), - fragments: RefCell::new(fragments::FragmentSets::new()), } } @@ -401,8 +394,6 @@ impl<'a, 'tcx> MoveData<'tcx> { let path_index = self.move_path(tcx, lp.clone()); let move_index = MoveIndex(self.moves.borrow().len()); - self.fragments.borrow_mut().add_move(path_index); - let next_move = self.path_first_move(path_index); self.set_path_first_move(path_index, move_index); @@ -458,8 +449,6 @@ impl<'a, 'tcx> MoveData<'tcx> { let path_index = self.move_path(tcx, lp.clone()); - self.fragments.borrow_mut().add_assignment(path_index); - match mode { MutateMode::Init | MutateMode::JustWrite => { self.assignee_ids.borrow_mut().insert(assignee_id); @@ -502,8 +491,6 @@ impl<'a, 'tcx> MoveData<'tcx> { let path_index = self.move_path(tcx, lp.clone()); let base_path_index = self.move_path(tcx, base_lp.clone()); - self.fragments.borrow_mut().add_assignment(path_index); - let variant_match = VariantMatch { path: path_index, base_path: base_path_index, @@ -514,10 +501,6 @@ impl<'a, 'tcx> MoveData<'tcx> { self.variant_matches.borrow_mut().push(variant_match); } - fn fixup_fragment_sets(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) { - fragments::fixup_fragment_sets(self, tcx) - } - /// Adds the gen/kills for the various moves and /// assignments into the provided data flow contexts. /// Moves are generated by moves and killed by assignments and @@ -677,8 +660,6 @@ impl<'a, 'tcx> FlowedMoveData<'a, 'tcx> { id_range, move_data.var_assignments.borrow().len()); - move_data.fixup_fragment_sets(tcx); - move_data.add_gen_kills(bccx, &mut dfcx_moves, &mut dfcx_assign); diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index f9ebe3fff5beb..18f33dc22e743 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -4078,7 +4078,7 @@ register_diagnostics! { // E0217, // ambiguous associated type, defined in multiple supertraits // E0218, // no associated type defined // E0219, // associated type defined in higher-ranked supertrait -// E0222, // Error code E0045 (variadic function must have C calling +// E0222, // Error code E0045 (variadic function must have C or cdecl calling // convention) duplicate E0224, // at least one non-builtin train is required for an object type E0227, // ambiguous lifetime bound, explicit lifetime bound required diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 6f2c73b892567..699b5f330d457 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -141,11 +141,10 @@ fn require_c_abi_if_variadic(tcx: TyCtxt, decl: &hir::FnDecl, abi: Abi, span: Span) { - if decl.variadic && abi != Abi::C { + if decl.variadic && !(abi == Abi::C || abi == Abi::Cdecl) { let mut err = struct_span_err!(tcx.sess, span, E0045, - "variadic function must have C calling convention"); - err.span_label(span, "variadics require C calling conventions") - .emit(); + "variadic function must have C or cdecl calling convention"); + err.span_label(span, "variadics require C or cdecl calling convention").emit(); } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index ca579409be430..17a73fea9611f 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -665,12 +665,6 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG "rustc_attrs", "internal rustc attributes will never be stable", cfg_fn!(rustc_attrs))), - ("rustc_move_fragments", Normal, Gated(Stability::Unstable, - "rustc_attrs", - "the `#[rustc_move_fragments]` attribute \ - is just used for rustc unit tests \ - and will never be stable", - cfg_fn!(rustc_attrs))), ("rustc_mir", Whitelisted, Gated(Stability::Unstable, "rustc_attrs", "the `#[rustc_mir]` attribute \ diff --git a/src/test/compile-fail/E0045.rs b/src/test/compile-fail/E0045.rs index a3fea8e0db299..3f098861eb60c 100644 --- a/src/test/compile-fail/E0045.rs +++ b/src/test/compile-fail/E0045.rs @@ -9,7 +9,7 @@ // except according to those terms. extern "Rust" { fn foo(x: u8, ...); } //~ ERROR E0045 - //~| NOTE variadics require C calling conventions + //~| NOTE variadics require C or cdecl calling convention fn main() { } diff --git a/src/test/compile-fail/feature-gate-rustc-attrs.rs b/src/test/compile-fail/feature-gate-rustc-attrs.rs index bb5b70829a163..8cfd3e020c69a 100644 --- a/src/test/compile-fail/feature-gate-rustc-attrs.rs +++ b/src/test/compile-fail/feature-gate-rustc-attrs.rs @@ -14,7 +14,6 @@ #[rustc_variance] //~ ERROR the `#[rustc_variance]` attribute is just used for rustc unit tests and will never be stable #[rustc_error] //~ ERROR the `#[rustc_error]` attribute is just used for rustc unit tests and will never be stable -#[rustc_move_fragments] //~ ERROR the `#[rustc_move_fragments]` attribute is just used for rustc unit tests and will never be stable #[rustc_foo] //~^ ERROR unless otherwise specified, attributes with the prefix `rustc_` are reserved for internal compiler diagnostics diff --git a/src/test/compile-fail/issue-39974.rs b/src/test/compile-fail/issue-39974.rs new file mode 100644 index 0000000000000..6f6b775a2a3c6 --- /dev/null +++ b/src/test/compile-fail/issue-39974.rs @@ -0,0 +1,21 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const LENGTH: f64 = 2; + +struct Thing { + f: [[f64; 2]; LENGTH], + //~^ ERROR mismatched types + //~| expected usize, found f64 +} + +fn main() { + let _t = Thing { f: [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]] }; +} diff --git a/src/test/compile-fail/move-fragments-1.rs b/src/test/compile-fail/move-fragments-1.rs deleted file mode 100644 index 0219f5b6becb3..0000000000000 --- a/src/test/compile-fail/move-fragments-1.rs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that we correctly compute the move fragments for a fn. -// -// Note that the code below is not actually incorrect; the -// `rustc_move_fragments` attribute is a hack that uses the error -// reporting mechanisms as a channel for communicating from the -// internals of the compiler. - -// These are all fairly trivial cases: unused variables or direct -// drops of substructure. - -#![feature(rustc_attrs)] - -pub struct D { d: isize } -impl Drop for D { fn drop(&mut self) { } } - -#[rustc_move_fragments] -pub fn test_noop() { -} - -#[rustc_move_fragments] -pub fn test_take(_x: D) { - //~^ ERROR assigned_leaf_path: `$(local _x)` -} - -pub struct Pair { x: X, y: Y } - -#[rustc_move_fragments] -pub fn test_take_struct(_p: Pair) { - //~^ ERROR assigned_leaf_path: `$(local _p)` -} - -#[rustc_move_fragments] -pub fn test_drop_struct_part(p: Pair) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR moved_leaf_path: `$(local p).x` - //~| ERROR unmoved_fragment: `$(local p).y` - drop(p.x); -} - -#[rustc_move_fragments] -pub fn test_drop_tuple_part(p: (D, D)) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR moved_leaf_path: `$(local p).#0` - //~| ERROR unmoved_fragment: `$(local p).#1` - drop(p.0); -} - -pub fn main() { } diff --git a/src/test/compile-fail/move-fragments-2.rs b/src/test/compile-fail/move-fragments-2.rs deleted file mode 100644 index 15c28ec2713e9..0000000000000 --- a/src/test/compile-fail/move-fragments-2.rs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that we correctly compute the move fragments for a fn. -// -// Note that the code below is not actually incorrect; the -// `rustc_move_fragments` attribute is a hack that uses the error -// reporting mechanisms as a channel for communicating from the -// internals of the compiler. - -// These are checking that enums are tracked; note that their output -// paths include "downcasts" of the path to a particular enum. - -#![feature(rustc_attrs)] - -use self::Lonely::{Zero, One, Two}; - -pub struct D { d: isize } -impl Drop for D { fn drop(&mut self) { } } - -pub enum Lonely { Zero, One(X), Two(X, Y) } - -#[rustc_move_fragments] -pub fn test_match_partial(p: Lonely) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)` - match p { - Zero => {} - _ => {} - } -} - -#[rustc_move_fragments] -pub fn test_match_full(p: Lonely) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)` - //~| ERROR assigned_leaf_path: `($(local p) as Lonely::One)` - //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Two)` - match p { - Zero => {} - One(..) => {} - Two(..) => {} - } -} - -#[rustc_move_fragments] -pub fn test_match_bind_one(p: Lonely) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)` - //~| ERROR parent_of_fragments: `($(local p) as Lonely::One)` - //~| ERROR moved_leaf_path: `($(local p) as Lonely::One).#0` - //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Two)` - //~| ERROR assigned_leaf_path: `$(local data)` - match p { - Zero => {} - One(data) => {} - Two(..) => {} - } -} - -#[rustc_move_fragments] -pub fn test_match_bind_many(p: Lonely) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)` - //~| ERROR parent_of_fragments: `($(local p) as Lonely::One)` - //~| ERROR moved_leaf_path: `($(local p) as Lonely::One).#0` - //~| ERROR assigned_leaf_path: `$(local data)` - //~| ERROR parent_of_fragments: `($(local p) as Lonely::Two)` - //~| ERROR moved_leaf_path: `($(local p) as Lonely::Two).#0` - //~| ERROR moved_leaf_path: `($(local p) as Lonely::Two).#1` - //~| ERROR assigned_leaf_path: `$(local left)` - //~| ERROR assigned_leaf_path: `$(local right)` - match p { - Zero => {} - One(data) => {} - Two(left, right) => {} - } -} - -pub fn main() { } diff --git a/src/test/compile-fail/move-fragments-3.rs b/src/test/compile-fail/move-fragments-3.rs deleted file mode 100644 index a1152333900a0..0000000000000 --- a/src/test/compile-fail/move-fragments-3.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that we correctly compute the move fragments for a fn. -// -// Note that the code below is not actually incorrect; the -// `rustc_move_fragments` attribute is a hack that uses the error -// reporting mechanisms as a channel for communicating from the -// internals of the compiler. - -// This checks the handling of `_` within variants, especially when mixed -// with bindings. - -#![feature(rustc_attrs)] - -use self::Lonely::{Zero, One, Two}; - -pub struct D { d: isize } -impl Drop for D { fn drop(&mut self) { } } - -pub enum Lonely { Zero, One(X), Two(X, Y) } - -#[rustc_move_fragments] -pub fn test_match_bind_and_underscore(p: Lonely) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)` - //~| ERROR assigned_leaf_path: `($(local p) as Lonely::One)` - //~| ERROR parent_of_fragments: `($(local p) as Lonely::Two)` - //~| ERROR moved_leaf_path: `($(local p) as Lonely::Two).#0` - //~| ERROR unmoved_fragment: `($(local p) as Lonely::Two).#1` - //~| ERROR assigned_leaf_path: `$(local left)` - - match p { - Zero => {} - - One(_) => {} // <-- does not fragment `($(local p) as One)` ... - - Two(left, _) => {} // <-- ... *does* fragment `($(local p) as Two)`. - } -} - -pub fn main() { } diff --git a/src/test/compile-fail/move-fragments-4.rs b/src/test/compile-fail/move-fragments-4.rs deleted file mode 100644 index 191e23a28638b..0000000000000 --- a/src/test/compile-fail/move-fragments-4.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that we correctly compute the move fragments for a fn. -// -// Note that the code below is not actually incorrect; the -// `rustc_move_fragments` attribute is a hack that uses the error -// reporting mechanisms as a channel for communicating from the -// internals of the compiler. - -// This checks that a move of deep structure is properly tracked. (An -// early draft of the code did not properly traverse up through all of -// the parents of the leaf fragment.) - -#![feature(rustc_attrs)] - -pub struct D { d: isize } -impl Drop for D { fn drop(&mut self) { } } - -pub struct Pair { x: X, y: Y } - -#[rustc_move_fragments] -pub fn test_move_substructure(pppp: Pair, D>, D>, D>) { - //~^ ERROR parent_of_fragments: `$(local pppp)` - //~| ERROR parent_of_fragments: `$(local pppp).x` - //~| ERROR parent_of_fragments: `$(local pppp).x.x` - //~| ERROR unmoved_fragment: `$(local pppp).x.x.x` - //~| ERROR moved_leaf_path: `$(local pppp).x.x.y` - //~| ERROR unmoved_fragment: `$(local pppp).x.y` - //~| ERROR unmoved_fragment: `$(local pppp).y` - drop(pppp.x.x.y); -} - -pub fn main() { } diff --git a/src/test/compile-fail/move-fragments-5.rs b/src/test/compile-fail/move-fragments-5.rs deleted file mode 100644 index 38a385eacac5c..0000000000000 --- a/src/test/compile-fail/move-fragments-5.rs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that we correctly compute the move fragments for a fn. -// -// Note that the code below is not actually incorrect; the -// `rustc_move_fragments` attribute is a hack that uses the error -// reporting mechanisms as a channel for communicating from the -// internals of the compiler. - -// This is the first test that checks moving into local variables. - -#![feature(rustc_attrs)] - -pub struct D { d: isize } -impl Drop for D { fn drop(&mut self) { } } - -pub struct Pair { x: X, y: Y } - -#[rustc_move_fragments] -pub fn test_move_field_to_local(p: Pair) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR moved_leaf_path: `$(local p).x` - //~| ERROR unmoved_fragment: `$(local p).y` - //~| ERROR assigned_leaf_path: `$(local _x)` - let _x = p.x; -} - -#[rustc_move_fragments] -pub fn test_move_field_to_local_to_local(p: Pair) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR moved_leaf_path: `$(local p).x` - //~| ERROR unmoved_fragment: `$(local p).y` - //~| ERROR assigned_leaf_path: `$(local _x)` - //~| ERROR moved_leaf_path: `$(local _x)` - //~| ERROR assigned_leaf_path: `$(local _y)` - let _x = p.x; - let _y = _x; -} - -// In the following fn's `test_move_field_to_local_delayed` and -// `test_uninitialized_local` , the instrumentation reports that `_x` -// is moved. This is unlike `test_move_field_to_local`, where `_x` is -// just reported as an assigned_leaf_path. Presumably because this is -// how we represent that it did not have an initializing expression at -// the binding site. - -#[rustc_move_fragments] -pub fn test_uninitialized_local(_p: Pair) { - //~^ ERROR assigned_leaf_path: `$(local _p)` - //~| ERROR moved_leaf_path: `$(local _x)` - let _x: D; -} - -#[rustc_move_fragments] -pub fn test_move_field_to_local_delayed(p: Pair) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR moved_leaf_path: `$(local p).x` - //~| ERROR unmoved_fragment: `$(local p).y` - //~| ERROR assigned_leaf_path: `$(local _x)` - //~| ERROR moved_leaf_path: `$(local _x)` - let _x; - _x = p.x; -} - -#[rustc_move_fragments] -pub fn test_move_field_mut_to_local(mut p: Pair) { - //~^ ERROR parent_of_fragments: `$(local mut p)` - //~| ERROR moved_leaf_path: `$(local mut p).x` - //~| ERROR unmoved_fragment: `$(local mut p).y` - //~| ERROR assigned_leaf_path: `$(local _x)` - let _x = p.x; -} - -#[rustc_move_fragments] -pub fn test_move_field_to_local_to_local_mut(p: Pair) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR moved_leaf_path: `$(local p).x` - //~| ERROR unmoved_fragment: `$(local p).y` - //~| ERROR assigned_leaf_path: `$(local mut _x)` - //~| ERROR moved_leaf_path: `$(local mut _x)` - //~| ERROR assigned_leaf_path: `$(local _y)` - let mut _x = p.x; - let _y = _x; -} - -pub fn main() {} diff --git a/src/test/compile-fail/move-fragments-6.rs b/src/test/compile-fail/move-fragments-6.rs deleted file mode 100644 index 122727c3f6b64..0000000000000 --- a/src/test/compile-fail/move-fragments-6.rs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that we correctly compute the move fragments for a fn. -// -// Note that the code below is not actually incorrect; the -// `rustc_move_fragments` attribute is a hack that uses the error -// reporting mechanisms as a channel for communicating from the -// internals of the compiler. - -// Test that moving into a field (i.e. overwriting it) fragments the -// receiver. - -#![feature(rustc_attrs)] - -use std::mem::drop; - -pub struct Pair { x: X, y: Y } - -#[rustc_move_fragments] -pub fn test_overwrite_uninit_field(z: Z) { - //~^ ERROR parent_of_fragments: `$(local mut p)` - //~| ERROR assigned_leaf_path: `$(local z)` - //~| ERROR moved_leaf_path: `$(local z)` - //~| ERROR assigned_leaf_path: `$(local mut p).x` - //~| ERROR unmoved_fragment: `$(local mut p).y` - - let mut p: Pair; - p.x = z; -} - -#[rustc_move_fragments] -pub fn test_overwrite_moved_field(mut p: Pair, z: Z) { - //~^ ERROR parent_of_fragments: `$(local mut p)` - //~| ERROR assigned_leaf_path: `$(local z)` - //~| ERROR moved_leaf_path: `$(local z)` - //~| ERROR assigned_leaf_path: `$(local mut p).y` - //~| ERROR unmoved_fragment: `$(local mut p).x` - - drop(p); - p.y = z; -} - -#[rustc_move_fragments] -pub fn test_overwrite_same_field(mut p: Pair) { - //~^ ERROR parent_of_fragments: `$(local mut p)` - //~| ERROR moved_leaf_path: `$(local mut p).x` - //~| ERROR assigned_leaf_path: `$(local mut p).x` - //~| ERROR unmoved_fragment: `$(local mut p).y` - - p.x = p.x; -} - -pub fn main() { } diff --git a/src/test/compile-fail/move-fragments-7.rs b/src/test/compile-fail/move-fragments-7.rs deleted file mode 100644 index a2a37208cd616..0000000000000 --- a/src/test/compile-fail/move-fragments-7.rs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that we correctly compute the move fragments for a fn. -// -// Note that the code below is not actually incorrect; the -// `rustc_move_fragments` attribute is a hack that uses the error -// reporting mechanisms as a channel for communicating from the -// internals of the compiler. - -// Test that moving a Box fragments its containing structure, for -// both moving out of the structure (i.e. reading `*p.x`) and writing -// into the container (i.e. writing `*p.x`). - -#![feature(rustc_attrs)] - -pub struct D { d: isize } -impl Drop for D { fn drop(&mut self) { } } - -pub struct Pair { x: X, y: Y } - -#[rustc_move_fragments] -pub fn test_deref_box_field(p: Pair, Box>) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR parent_of_fragments: `$(local p).x` - //~| ERROR moved_leaf_path: `$(local p).x.*` - //~| ERROR unmoved_fragment: `$(local p).y` - //~| ERROR assigned_leaf_path: `$(local i)` - let i : D = *p.x; -} - -#[rustc_move_fragments] -pub fn test_overwrite_deref_box_field(mut p: Pair, Box>) { - //~^ ERROR parent_of_fragments: `$(local mut p)` - //~| ERROR parent_of_fragments: `$(local mut p).x` - //~| ERROR assigned_leaf_path: `$(local mut p).x.*` - //~| ERROR unmoved_fragment: `$(local mut p).y` - *p.x = D { d: 3 }; -} - -pub fn main() { } diff --git a/src/test/compile-fail/move-fragments-8.rs b/src/test/compile-fail/move-fragments-8.rs deleted file mode 100644 index e57268dbfa32a..0000000000000 --- a/src/test/compile-fail/move-fragments-8.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that we correctly compute the move fragments for a fn. -// -// Note that the code below is not actually incorrect; the -// `rustc_move_fragments` attribute is a hack that uses the error -// reporting mechanisms as a channel for communicating from the -// internals of the compiler. - -// Test that assigning into a `&T` within structured container does -// *not* fragment its containing structure. -// -// Compare against the `Box` handling in move-fragments-7.rs. Note -// also that in this case we cannot do a move out of `&T`, so we only -// test writing `*p.x` here. - -#![feature(rustc_attrs)] - -pub struct D { d: isize } -impl Drop for D { fn drop(&mut self) { } } - -pub struct Pair { x: X, y: Y } - -#[rustc_move_fragments] -pub fn test_overwrite_deref_ampersand_field<'a>(p: Pair<&'a mut D, &'a D>) { - //~^ ERROR parent_of_fragments: `$(local p)` - //~| ERROR parent_of_fragments: `$(local p).x` - //~| ERROR assigned_leaf_path: `$(local p).x.*` - //~| ERROR unmoved_fragment: `$(local p).y` - *p.x = D { d: 3 }; -} - -pub fn main() { } diff --git a/src/test/compile-fail/move-fragments-9.rs b/src/test/compile-fail/move-fragments-9.rs deleted file mode 100644 index 350f416903400..0000000000000 --- a/src/test/compile-fail/move-fragments-9.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test moving array structures, e.g. `[T; 3]` as well as moving -// elements in and out of such arrays. -// -// Note also that the `test_move_array_then_overwrite` tests represent -// cases that we probably should make illegal. - -#![feature(rustc_attrs)] - -pub struct D { d: isize } -impl Drop for D { fn drop(&mut self) { } } - -#[rustc_move_fragments] -pub fn test_move_array_via_return(a: [D; 3]) -> [D; 3] { - //~^ ERROR assigned_leaf_path: `$(local a)` - //~| ERROR moved_leaf_path: `$(local a)` - return a; -} - -#[rustc_move_fragments] -pub fn test_move_array_into_recv(a: [D; 3], recv: &mut [D; 3]) { - //~^ ERROR parent_of_fragments: `$(local recv)` - //~| ERROR assigned_leaf_path: `$(local a)` - //~| ERROR moved_leaf_path: `$(local a)` - //~| ERROR assigned_leaf_path: `$(local recv).*` - *recv = a; -} - -#[rustc_move_fragments] -pub fn test_overwrite_array_elem(mut a: [D; 3], i: usize, d: D) { - //~^ ERROR parent_of_fragments: `$(local mut a)` - //~| ERROR assigned_leaf_path: `$(local i)` - //~| ERROR assigned_leaf_path: `$(local d)` - //~| ERROR moved_leaf_path: `$(local d)` - //~| ERROR assigned_leaf_path: `$(local mut a).[]` - //~| ERROR unmoved_fragment: `$(allbutone $(local mut a).[])` - a[i] = d; -} - -pub fn main() { } diff --git a/src/test/compile-fail/variadic-ffi-2.rs b/src/test/compile-fail/variadic-ffi-2.rs index afcad9d8f9614..fc33aec6ad97d 100644 --- a/src/test/compile-fail/variadic-ffi-2.rs +++ b/src/test/compile-fail/variadic-ffi-2.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn baz(f: extern "cdecl" fn(usize, ...)) { - //~^ ERROR: variadic function must have C calling convention +fn baz(f: extern "stdcall" fn(usize, ...)) { + //~^ ERROR: variadic function must have C or cdecl calling convention f(22, 44); } diff --git a/src/test/compile-fail/variadic-ffi.rs b/src/test/compile-fail/variadic-ffi.rs index af2b552e20f14..18db51acbc454 100644 --- a/src/test/compile-fail/variadic-ffi.rs +++ b/src/test/compile-fail/variadic-ffi.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern "cdecl" { - fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C calling convention +extern "stdcall" { + fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C or cdecl calling } extern { diff --git a/src/test/run-pass/issue-42210.rs b/src/test/run-pass/issue-42210.rs new file mode 100644 index 0000000000000..ecdf78cd5bdf8 --- /dev/null +++ b/src/test/run-pass/issue-42210.rs @@ -0,0 +1,29 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Regression test for #42210. + +// compile-flags: -g + +trait Foo { + fn foo() { } +} + +struct Bar; + +trait Baz { +} + +impl Foo for (Bar, Baz) { } + + +fn main() { + <(Bar, Baz) as Foo>::foo() +}