From 3e35b39d9dbfcd937c6b9163a3514d6a4775c198 Mon Sep 17 00:00:00 2001 From: mochaaP Date: Thu, 22 Dec 2022 15:51:52 +0800 Subject: [PATCH 01/10] std: only use LFS function on glibc see #94173 and commit 27011b4185f5341e579d2a02cabd3dc7d7aa7149. --- library/std/src/sys/unix/fs.rs | 4 ++-- library/std/src/sys/unix/kernel_copy.rs | 4 ++-- library/std/src/sys/unix/mod.rs | 8 ++++---- library/std/src/sys/unix/stack_overflow.rs | 4 ++-- library/std/src/sys/unix/thread.rs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index d5f50d77911fc..aea0c26ee8b60 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -1754,11 +1754,11 @@ mod remove_dir_impl { use crate::sys::{cvt, cvt_r}; #[cfg(not(any( - target_os = "linux", + all(target_os = "linux", target_env = "gnu"), all(target_os = "macos", not(target_arch = "aarch64")) )))] use libc::{fdopendir, openat, unlinkat}; - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", target_env = "gnu"))] use libc::{fdopendir, openat64 as openat, unlinkat}; #[cfg(all(target_os = "macos", not(target_arch = "aarch64")))] use macos_weak::{fdopendir, openat, unlinkat}; diff --git a/library/std/src/sys/unix/kernel_copy.rs b/library/std/src/sys/unix/kernel_copy.rs index 6fa85e859c05b..0f7107122b7e8 100644 --- a/library/std/src/sys/unix/kernel_copy.rs +++ b/library/std/src/sys/unix/kernel_copy.rs @@ -61,9 +61,9 @@ use crate::ptr; use crate::sync::atomic::{AtomicBool, AtomicU8, Ordering}; use crate::sys::cvt; use crate::sys::weak::syscall; -#[cfg(not(target_os = "linux"))] +#[cfg(not(all(target_os = "linux", target_env = "gnu")))] use libc::sendfile as sendfile64; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", target_env = "gnu"))] use libc::sendfile64; use libc::{EBADF, EINVAL, ENOSYS, EOPNOTSUPP, EOVERFLOW, EPERM, EXDEV}; diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 3d60941e84e39..83a43b6ee2697 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -95,9 +95,9 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { )))] 'poll: { use crate::sys::os::errno; - #[cfg(not(target_os = "linux"))] + #[cfg(not(all(target_os = "linux", target_env = "gnu")))] use libc::open as open64; - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", target_env = "gnu"))] use libc::open64; let pfds: &mut [_] = &mut [ libc::pollfd { fd: 0, events: 0, revents: 0 }, @@ -143,9 +143,9 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { )))] { use crate::sys::os::errno; - #[cfg(not(target_os = "linux"))] + #[cfg(not(all(target_os = "linux", target_env = "gnu")))] use libc::open as open64; - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", target_env = "gnu"))] use libc::open64; for fd in 0..3 { if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF { diff --git a/library/std/src/sys/unix/stack_overflow.rs b/library/std/src/sys/unix/stack_overflow.rs index 957e086798fd3..b59d4ba26afb9 100644 --- a/library/std/src/sys/unix/stack_overflow.rs +++ b/library/std/src/sys/unix/stack_overflow.rs @@ -45,9 +45,9 @@ mod imp { use crate::thread; use libc::MAP_FAILED; - #[cfg(not(target_os = "linux"))] + #[cfg(not(all(target_os = "linux", target_env = "gnu")))] use libc::{mmap as mmap64, munmap}; - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", target_env = "gnu"))] use libc::{mmap64, munmap}; use libc::{sigaction, sighandler_t, SA_ONSTACK, SA_SIGINFO, SIGBUS, SIG_DFL}; use libc::{sigaltstack, SIGSTKSZ, SS_DISABLE}; diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index d454a2a717c06..d847f2775ab76 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -653,9 +653,9 @@ pub mod guard { ))] #[cfg_attr(test, allow(dead_code))] pub mod guard { - #[cfg(not(target_os = "linux"))] + #[cfg(not(all(target_os = "linux", target_env = "gnu")))] use libc::{mmap as mmap64, mprotect}; - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", target_env = "gnu"))] use libc::{mmap64, mprotect}; use libc::{MAP_ANON, MAP_FAILED, MAP_FIXED, MAP_PRIVATE, PROT_NONE, PROT_READ, PROT_WRITE}; From 459b234e6ace06854a383aae02c656b3410ec344 Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 18 Dec 2022 02:56:56 +0800 Subject: [PATCH 02/10] fix #105494, Suggest remove last method call when type coerce with expected --- compiler/rustc_hir_typeck/src/demand.rs | 1 + .../src/fn_ctxt/suggestions.rs | 20 +++++++ src/test/ui/suggestions/issue-105494.rs | 22 ++++++++ src/test/ui/suggestions/issue-105494.stderr | 54 +++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 src/test/ui/suggestions/issue-105494.rs create mode 100644 src/test/ui/suggestions/issue-105494.stderr diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index e68bd1297c878..042ff0b46a5af 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -38,6 +38,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Use `||` to give these suggestions a precedence let _ = self.suggest_missing_parentheses(err, expr) + || self.suggest_remove_last_method_call(err, expr, expected) || self.suggest_associated_const(err, expr, expected) || self.suggest_deref_ref_or_into(err, expr, expected, expr_ty, expected_ty_expr) || self.suggest_option_to_bool(err, expr, expr_ty, expected) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index efec024463334..720fbd1ad147b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -329,6 +329,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } + pub fn suggest_remove_last_method_call( + &self, + err: &mut Diagnostic, + expr: &hir::Expr<'tcx>, + expected: Ty<'tcx>, + ) -> bool { + if let hir::ExprKind::MethodCall(hir::PathSegment { ident: method, .. }, recv_expr, &[], _) = expr.kind && + let Some(recv_ty) = self.typeck_results.borrow().expr_ty_opt(recv_expr) && + self.can_coerce(recv_ty, expected) { + err.span_suggestion_verbose( + expr.span.with_lo(method.span.lo() - rustc_span::BytePos(1)), + "try removing the method call", + "", + Applicability::MachineApplicable, + ); + return true; + } + false + } + pub fn suggest_deref_ref_or_into( &self, err: &mut Diagnostic, diff --git a/src/test/ui/suggestions/issue-105494.rs b/src/test/ui/suggestions/issue-105494.rs new file mode 100644 index 0000000000000..8b409232c202c --- /dev/null +++ b/src/test/ui/suggestions/issue-105494.rs @@ -0,0 +1,22 @@ +fn test1() { + let _v: i32 = (1 as i32).to_string(); //~ ERROR mismatched types + + // won't suggestion + let _v: i32 = (1 as i128).to_string(); //~ ERROR mismatched types + + let _v: &str = "foo".to_string(); //~ ERROR mismatched types +} + +fn test2() { + let mut path: String = "/usr".to_string(); + let folder: String = "lib".to_string(); + + path = format!("{}/{}", path, folder).as_str(); //~ ERROR mismatched types + + println!("{}", &path); +} + +fn main() { + test1(); + test2(); +} diff --git a/src/test/ui/suggestions/issue-105494.stderr b/src/test/ui/suggestions/issue-105494.stderr new file mode 100644 index 0000000000000..5aa3f2af738f4 --- /dev/null +++ b/src/test/ui/suggestions/issue-105494.stderr @@ -0,0 +1,54 @@ +error[E0308]: mismatched types + --> $DIR/issue-105494.rs:2:19 + | +LL | let _v: i32 = (1 as i32).to_string(); + | --- ^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `String` + | | + | expected due to this + | +help: try removing the method call + | +LL - let _v: i32 = (1 as i32).to_string(); +LL + let _v: i32 = (1 as i32); + | + +error[E0308]: mismatched types + --> $DIR/issue-105494.rs:5:19 + | +LL | let _v: i32 = (1 as i128).to_string(); + | --- ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `String` + | | + | expected due to this + +error[E0308]: mismatched types + --> $DIR/issue-105494.rs:7:20 + | +LL | let _v: &str = "foo".to_string(); + | ---- ^^^^^^^^^^^^^^^^^ expected `&str`, found struct `String` + | | + | expected due to this + | +help: try removing the method call + | +LL - let _v: &str = "foo".to_string(); +LL + let _v: &str = "foo"; + | + +error[E0308]: mismatched types + --> $DIR/issue-105494.rs:14:12 + | +LL | let mut path: String = "/usr".to_string(); + | ------ expected due to this type +... +LL | path = format!("{}/{}", path, folder).as_str(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `String`, found `&str` + | +help: try removing the method call + | +LL - path = format!("{}/{}", path, folder).as_str(); +LL + path = format!("{}/{}", path, folder); + | + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`. From 3b38adf5682c153ce58e67fa346624b7bc5286b2 Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 18 Dec 2022 17:38:01 +0800 Subject: [PATCH 03/10] fix suggest span for #105494 --- compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 720fbd1ad147b..9a7d753e66b8e 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -338,8 +338,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let hir::ExprKind::MethodCall(hir::PathSegment { ident: method, .. }, recv_expr, &[], _) = expr.kind && let Some(recv_ty) = self.typeck_results.borrow().expr_ty_opt(recv_expr) && self.can_coerce(recv_ty, expected) { + let span = if let Some(recv_span) = recv_expr.span.find_ancestor_inside(expr.span) { + expr.span.with_lo(recv_span.hi()) + } else { + expr.span.with_lo(method.span.lo() - rustc_span::BytePos(1)) + }; err.span_suggestion_verbose( - expr.span.with_lo(method.span.lo() - rustc_span::BytePos(1)), + span, "try removing the method call", "", Applicability::MachineApplicable, From a0b9c5a9bfe938b0aa74eef826fba7e8849a5df0 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 23 Dec 2022 09:40:24 +0100 Subject: [PATCH 04/10] Provide more context on FileCheck failures FileCheck provides 5 lines of context by default. This is often insufficient to analyze failures that happen in CI. Increase the amount of context to 100 lines. --- src/tools/compiletest/src/runtest.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 72a43108dc480..dc8b3bce1240f 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2299,6 +2299,8 @@ impl<'test> TestCx<'test> { } else { filecheck.args(&["--check-prefixes", &prefixes]); } + // Provide more context on failures. + filecheck.args(&["--dump-input-context", "100"]); self.compose_and_run(filecheck, "", None, None) } From 4cb7bd36d7809d656d585656b9002b12d6d40e4f Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Thu, 22 Dec 2022 13:44:51 -0800 Subject: [PATCH 05/10] Codegen test for derived `<` on trivial newtype [TEST ONLY] --- .../codegen/comparison-operators-newtype.rs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/codegen/comparison-operators-newtype.rs diff --git a/src/test/codegen/comparison-operators-newtype.rs b/src/test/codegen/comparison-operators-newtype.rs new file mode 100644 index 0000000000000..5cf6c3ac0a233 --- /dev/null +++ b/src/test/codegen/comparison-operators-newtype.rs @@ -0,0 +1,49 @@ +// The `derive(PartialOrd)` for a newtype doesn't override `lt`/`le`/`gt`/`ge`. +// This double-checks that the `Option` intermediate values used +// in the operators for such a type all optimize away. + +// compile-flags: -C opt-level=1 +// min-llvm-version: 15.0 + +#![crate_type = "lib"] + +use std::cmp::Ordering; + +#[derive(PartialOrd, PartialEq)] +pub struct Foo(u16); + +// CHECK-LABEL: @check_lt +// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]]) +#[no_mangle] +pub fn check_lt(a: Foo, b: Foo) -> bool { + // CHECK: %[[R:.+]] = icmp ult i16 %[[A]], %[[B]] + // CHECK-NEXT: ret i1 %[[R]] + a < b +} + +// CHECK-LABEL: @check_le +// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]]) +#[no_mangle] +pub fn check_le(a: Foo, b: Foo) -> bool { + // CHECK: %[[R:.+]] = icmp ule i16 %[[A]], %[[B]] + // CHECK-NEXT: ret i1 %[[R]] + a <= b +} + +// CHECK-LABEL: @check_gt +// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]]) +#[no_mangle] +pub fn check_gt(a: Foo, b: Foo) -> bool { + // CHECK: %[[R:.+]] = icmp ugt i16 %[[A]], %[[B]] + // CHECK-NEXT: ret i1 %[[R]] + a > b +} + +// CHECK-LABEL: @check_ge +// CHECK-SAME: (i16 %[[A:.+]], i16 %[[B:.+]]) +#[no_mangle] +pub fn check_ge(a: Foo, b: Foo) -> bool { + // CHECK: %[[R:.+]] = icmp uge i16 %[[A]], %[[B]] + // CHECK-NEXT: ret i1 %[[R]] + a >= b +} From a06e5decaf8a79db0bd9a0078f37a777e095584e Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 23 Dec 2022 19:03:50 -0600 Subject: [PATCH 06/10] Link to other resources instead of inlining their information The other places are more accurate and up-to-date. - Link to `std-dev-guide` in CONTRIBUTING.md Thom and Mara said the guide is in reasonably good shape, and it's tailored more closely to people working on the standard library. - Link to CONTRIBUTING.md instead of rustc-dev-guide in the main readme CONTRIBUTING.md has more information and also links the std-dev-guide. - Link to forge for the list of tested platforms; the one in the readme was hopelessly out of date. --- CONTRIBUTING.md | 7 ++++--- README.md | 37 ++++++------------------------------- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 223fd0065bf4a..d732075fb2d07 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,9 +8,9 @@ members](https://rust-lang.zulipchat.com/#narrow/stream/122652-new-members) Zulip stream. We have lots of docs below of how to get started on your own, but the Zulip stream is the best place to *ask* for help. -Documentation for contributing to Rust is located in the [Guide to Rustc Development](https://rustc-dev-guide.rust-lang.org/), -commonly known as the [rustc-dev-guide]. Despite the name, this guide documents -not just how to develop rustc (the Rust compiler), but also how to contribute to the standard library and rustdoc. +Documentation for contributing to the compiler or tooling is located in the [Guide to Rustc +Development][rustc-dev-guide], commonly known as the [rustc-dev-guide]. Documentation for the +standard library in the [Standard library developers Guide][std-dev-guide], commonly known as the [std-dev-guide]. ## About the [rustc-dev-guide] @@ -35,6 +35,7 @@ refer to [this section][contributing-bug-reports] and [open an issue][issue temp [Contributing to Rust]: https://rustc-dev-guide.rust-lang.org/contributing.html#contributing-to-rust [rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/ +[std-dev-guide]: https://std-dev-guide.rust-lang.org/ [contributing-bug-reports]: https://rustc-dev-guide.rust-lang.org/contributing.html#bug-reports [issue template]: https://github.com/rust-lang/rust/issues/new/choose [internals]: https://internals.rust-lang.org diff --git a/README.md b/README.md index 27e7145c5a99e..037d83ad71746 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,7 @@ standard library, and documentation. [Rust]: https://www.rust-lang.org **Note: this README is for _users_ rather than _contributors_. -If you wish to _contribute_ to the compiler, you should read the -[Getting Started][gettingstarted] section of the rustc-dev-guide instead. -You can ask for help in the [#new members Zulip stream][new-members].** - -[new-members]: https://rust-lang.zulipchat.com/#narrow/stream/122652-new-members +If you wish to _contribute_ to the compiler, you should read [CONTRIBUTING.md](CONTRIBUTING.md) instead. ## Quick Start @@ -227,41 +223,20 @@ precompiled "snapshot" version of itself (made in an earlier stage of development). As such, source builds require an Internet connection to fetch snapshots, and an OS that can execute the available snapshot binaries. -Snapshot binaries are currently built and tested on several platforms: - -| Platform / Architecture | x86 | x86_64 | -|---------------------------------------------|-----|--------| -| Windows (7, 8, 10, ...) | ✓ | ✓ | -| Linux (kernel 3.2, glibc 2.17 or later) | ✓ | ✓ | -| macOS (10.7 Lion or later) | (\*) | ✓ | - -(\*): Apple dropped support for running 32-bit binaries starting from macOS 10.15 and iOS 11. -Due to this decision from Apple, the targets are no longer useful to our users. -Please read [our blog post][macx32] for more info. - -[macx32]: https://blog.rust-lang.org/2020/01/03/reducing-support-for-32-bit-apple-targets.html +See https://doc.rust-lang.org/nightly/rustc/platform-support.html for a list of supported platforms. +Only "host tools" platforms have a pre-compiled snapshot binary available; to compile for a platform +without host tools you must cross-compile. You may find that other platforms work, but these are our officially supported build environments that are most likely to work. ## Getting Help -The Rust community congregates in a few places: - -* [Stack Overflow] - Direct questions about using the language. -* [users.rust-lang.org] - General discussion and broader questions. -* [/r/rust] - News and general discussion. - -[Stack Overflow]: https://stackoverflow.com/questions/tagged/rust -[/r/rust]: https://reddit.com/r/rust -[users.rust-lang.org]: https://users.rust-lang.org/ +See https://www.rust-lang.org/community for a list of chat platforms and forums. ## Contributing -If you are interested in contributing to the Rust project, please take a look -at the [Getting Started][gettingstarted] guide in the [rustc-dev-guide]. - -[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org +See [CONTRIBUTING.md](CONTRIBUTING.md). ## License From 7dae1b0b07b73d34989cf6ee8795b7437372eb28 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 23 Dec 2022 19:03:50 -0600 Subject: [PATCH 07/10] Add detail about dependencies from the dev-guide The goal is to remove this altogether from the dev-guide once this PR is merged. --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 037d83ad71746..471b66a88e16a 100644 --- a/README.md +++ b/README.md @@ -44,20 +44,37 @@ by running it with the `--help` flag or reading the [rustc dev guide][rustcguide [gettingstarted]: https://rustc-dev-guide.rust-lang.org/getting-started.html [rustcguidebuild]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html -### Building on a Unix-like system -1. Make sure you have installed the dependencies: +### Dependencies + +Make sure you have installed the dependencies: - * `g++` 5.1 or later or `clang++` 3.5 or later * `python` 3 or 2.7 - * GNU `make` 3.81 or later - * `cmake` 3.13.4 or later - * `ninja` - * `curl` * `git` - * `ssl` which comes in `libssl-dev` or `openssl-devel` + * A C compiler (when building for the host, `cc` is enough; cross-compiling may need additional compilers) + * `curl` (not needed on Windows) * `pkg-config` if you are compiling on Linux and targeting Linux + * `libiconv` (already included with glibc on Debian-based distros) + +To build cargo, you'll also need OpenSSL (`libssl-dev` or `openssl-devel` on most Unix distros). + +If building LLVM from source, you'll need additional tools: + +* `g++`, `clang++`, or MSVC with versions listed on + [LLVM's documentation](https://llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library) +* `ninja`, or GNU `make` 3.81 or later (ninja is recommended, especially on Windows) +* `cmake` 3.13.4 or later +* `libstdc++-static` may be required on some Linux distributions such as Fedora and Ubuntu + +On tier 1 or tier 2 with host tools platforms, you can also choose to download LLVM by setting `llvm.download-ci-llvm = true`. +Otherwise, you'll need LLVM installed and `llvm-config` in your path. +See [the rustc-dev-guide for more info][sysllvm]. + +[sysllvm]: https://rustc-dev-guide.rust-lang.org/building/new-target.html#using-pre-built-llvm + -2. Clone the [source] with `git`: +### Building on a Unix-like system + +1. Clone the [source] with `git`: ```sh git clone https://github.com/rust-lang/rust.git @@ -66,7 +83,7 @@ by running it with the `--help` flag or reading the [rustc dev guide][rustcguide [source]: https://github.com/rust-lang/rust -3. Configure the build settings: +2. Configure the build settings: The Rust build system uses a file named `config.toml` in the root of the source tree to determine various configuration settings for the build. @@ -79,9 +96,7 @@ by running it with the `--help` flag or reading the [rustc dev guide][rustcguide If you plan to use `x.py install` to create an installation, it is recommended that you set the `prefix` value in the `[install]` section to a directory. - Create an install directory if you are not installing in the default directory. - -4. Build and install: +3. Build and install: ```sh ./x.py build && ./x.py install @@ -98,6 +113,20 @@ by running it with the `--help` flag or reading the [rustc dev guide][rustcguide ### Building on Windows +On Windows, we suggest using [winget] to install dependencies by running the following in a terminal: + +```powershell +winget install -e Python.Python.3 +winget install -e Kitware.CMake +winget install -e Git.Git +``` + +Then edit your system's `PATH` variable and add: `C:\Program Files\CMake\bin`. See +[this guide on editing the system `PATH`](https://www.java.com/en/download/help/path.html) from the +Java documentation. + +[winget]: https://github.com/microsoft/winget-cli + There are two prominent ABIs in use on Windows: the native (MSVC) ABI used by Visual Studio and the GNU ABI used by the GCC toolchain. Which version of Rust you need depends largely on what C/C++ libraries you want to interoperate with. From 1bd1b25be8b4cc20358028108f8a35b8760b5cd3 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 23 Dec 2022 19:03:50 -0600 Subject: [PATCH 08/10] Suggest `profile = "user"` in the README This sets several useful defaults, like `extended = true`, and gives us a path forward for changing global defaults without breaking distros. --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 471b66a88e16a..e2042eb2d4577 100644 --- a/README.md +++ b/README.md @@ -87,10 +87,11 @@ See [the rustc-dev-guide for more info][sysllvm]. The Rust build system uses a file named `config.toml` in the root of the source tree to determine various configuration settings for the build. - Copy the default `config.toml.example` to `config.toml` to get started. + Set up the defaults intended for distros to get started. You can see a full list of options + in `config.toml.example`. ```sh - cp config.toml.example config.toml + printf 'profile = "user" \nchangelog-seen = 2 \n' > config.toml ``` If you plan to use `x.py install` to create an installation, it is recommended @@ -104,10 +105,8 @@ See [the rustc-dev-guide for more info][sysllvm]. When complete, `./x.py install` will place several programs into `$PREFIX/bin`: `rustc`, the Rust compiler, and `rustdoc`, the - API-documentation tool. This install does not include [Cargo], - Rust's package manager. To build and install Cargo, you may - run `./x.py install cargo` or set the `build.extended` key in - `config.toml` to `true` to build and install all tools. + API-documentation tool. If you've set `profile = "user"` or `build.extended = true`, it will + also include [Cargo], Rust's package manager. [Cargo]: https://github.com/rust-lang/cargo @@ -215,7 +214,7 @@ Windows build triples are: - `x86_64-pc-windows-msvc` The build triple can be specified by either specifying `--build=` when -invoking `x.py` commands, or by copying the `config.toml` file (as described +invoking `x.py` commands, or by creating a `config.toml` file (as described in [Installing From Source](#installing-from-source)), and modifying the `build` option under the `[build]` section. From 70a0e0a2779f04999d0f0e40f93e1697c37ec042 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 23 Dec 2022 19:03:51 -0600 Subject: [PATCH 09/10] Remove ancient and outdated references to `config.mk` --- README.md | 4 +--- src/bootstrap/README.md | 10 ++-------- src/bootstrap/config.rs | 5 +---- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e2042eb2d4577..014fab907fb96 100644 --- a/README.md +++ b/README.md @@ -228,9 +228,7 @@ configure script and makefile (the latter of which just invokes `x.py`). make && sudo make install ``` -When using the configure script, the generated `config.mk` file may override the -`config.toml` file. To go back to the `config.toml` file, delete the generated -`config.mk` file. +`configure` generates a `config.toml` which can also be used with normal `x.py` invocations. ## Building Documentation diff --git a/src/bootstrap/README.md b/src/bootstrap/README.md index 985727bddc533..79c2eb31cdae0 100644 --- a/src/bootstrap/README.md +++ b/src/bootstrap/README.md @@ -80,18 +80,12 @@ The script accepts commands, flags, and arguments to determine what to do: ## Configuring rustbuild -There are currently two methods for configuring the rustbuild build system. - -First, rustbuild offers a TOML-based configuration system with a `config.toml` +rustbuild offers a TOML-based configuration system with a `config.toml` file. An example of this configuration can be found at `config.toml.example`, and the configuration file can also be passed as `--config path/to/config.toml` if the build system is being invoked manually (via the python script). -Next, the `./configure` options serialized in `config.mk` will be -parsed and read. That is, if any `./configure` options are passed, they'll be -handled naturally. `./configure` should almost never be used for local -installations, and is primarily useful for CI. Prefer to customize behavior -using `config.toml`. +You can generate a config.toml using `./configure` options if you want to automate creating the file without having to edit it. Finally, rustbuild makes use of the [cc-rs crate] which has [its own method][env-vars] of configuring C compilers and C flags via environment diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index d8c15c76e2d61..3ae23db1d1cc8 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -46,10 +46,7 @@ pub enum DryRun { /// Global configuration for the entire build and/or bootstrap. /// -/// This structure is derived from a combination of both `config.toml` and -/// `config.mk`. As of the time of this writing it's unlikely that `config.toml` -/// is used all that much, so this is primarily filled out by `config.mk` which -/// is generated from `./configure`. +/// This structure is parsed from `config.toml`, and some of the fields are inferred from `git` or build-time parameters. /// /// Note that this structure is not decoded directly into, but rather it is /// filled out from the decoded forms of the structs below. For documentation From f4517171572fdc2d6d2880fc20bb2b689faae3c3 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 23 Dec 2022 22:55:04 -0700 Subject: [PATCH 10/10] rustdoc: make line number CSS for doc comment and scraped the same Discussed in https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Line.20number.20styling --- src/librustdoc/html/static/css/rustdoc.css | 30 ++++------- src/librustdoc/html/static/css/themes/ayu.css | 3 +- .../html/static/css/themes/dark.css | 1 - .../html/static/css/themes/light.css | 1 - .../docblock-code-block-line-number.goml | 54 ++++++++++++++----- src/test/rustdoc-gui/source-code-page.goml | 4 +- 6 files changed, 54 insertions(+), 39 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 2b2b148f05e07..53c8a1add780b 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -347,6 +347,9 @@ pre { .source .content pre { padding: 20px; } +.rustdoc.source .example-wrap > pre.src-line-numbers { + padding: 20px 0 20px 4px; +} img { max-width: 100%; @@ -519,10 +522,6 @@ ul.block, .block li { display: none; } -.source .content pre.rust { - padding-left: 0; -} - .rustdoc .example-wrap { display: flex; position: relative; @@ -550,23 +549,21 @@ ul.block, .block li { -moz-user-select: none; -ms-user-select: none; user-select: none; + padding: 14px 8px; + color: var(--src-line-numbers-span-color); } -.example-line-numbers { - border: 1px solid; - padding: 13px 8px; - border-top-left-radius: 5px; - border-bottom-left-radius: 5px; - border-color: var(--example-line-numbers-border-color); +.rustdoc .example-wrap > pre.src-line-numbers { + padding: 14px 0; } - .src-line-numbers a, .src-line-numbers span { color: var(--src-line-numbers-span-color); + padding: 0 8px; } .src-line-numbers :target { background-color: transparent; border-right: none; - padding-right: 0; + padding: 0 8px; } .src-line-numbers .line-highlighted { background-color: var(--src-line-number-highlighted-background-color); @@ -1958,15 +1955,6 @@ in storage.js bottom: 0; } -.scraped-example .code-wrapper .src-line-numbers { - padding: 14px 0; -} - -.scraped-example .code-wrapper .src-line-numbers a, -.scraped-example .code-wrapper .src-line-numbers span { - padding: 0 14px; -} - .scraped-example .code-wrapper .example-wrap { width: 100%; overflow-y: hidden; diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index ce416f77afe90..7377e2a17914e 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -62,7 +62,6 @@ Original by Dempfi (https://github.com/dempfi/ayu) --code-highlight-question-mark-color: #ff9011; --code-highlight-comment-color: #788797; --code-highlight-doc-comment-color: #a1ac88; - --example-line-numbers-border-color: none; --src-line-numbers-span-color: #5c6773; --src-line-number-highlighted-background-color: rgba(255, 236, 164, 0.06); --test-arrow-color: #788797; @@ -132,7 +131,7 @@ pre, .rustdoc.source .example-wrap { .src-line-numbers .line-highlighted { color: #708090; - padding-right: 4px; + padding-right: 7px; border-right: 1px solid #ffb44c; } diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 33d934ff3c312..2091f8dcca9f0 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -57,7 +57,6 @@ --code-highlight-question-mark-color: #ff9011; --code-highlight-comment-color: #8d8d8b; --code-highlight-doc-comment-color: #8ca375; - --example-line-numbers-border-color: #4a4949; --src-line-numbers-span-color: #3b91e2; --src-line-number-highlighted-background-color: #0a042f; --test-arrow-color: #dedede; diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 30e91077d33ff..f582796d5ddbc 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -57,7 +57,6 @@ --code-highlight-question-mark-color: #ff9011; --code-highlight-comment-color: #8e908c; --code-highlight-doc-comment-color: #4d4d4c; - --example-line-numbers-border-color: #c7c7c7; --src-line-numbers-span-color: #c67e2d; --src-line-number-highlighted-background-color: #fdffd3; --test-arrow-color: #f5f5f5; diff --git a/src/test/rustdoc-gui/docblock-code-block-line-number.goml b/src/test/rustdoc-gui/docblock-code-block-line-number.goml index b094c48387641..a3ed008719c00 100644 --- a/src/test/rustdoc-gui/docblock-code-block-line-number.goml +++ b/src/test/rustdoc-gui/docblock-code-block-line-number.goml @@ -1,23 +1,53 @@ // Checks that the setting "line numbers" is working as expected. goto: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" +// Otherwise, we can't check text color +show-text: true + // We check that without this setting, there is no line number displayed. assert-false: "pre.example-line-numbers" -// We now set the setting to show the line numbers on code examples. -local-storage: {"rustdoc-line-numbers": "true" } -// We reload to make the line numbers appear. -reload: - -// We wait for them to be added into the DOM by the JS... -wait-for: "pre.example-line-numbers" -// If the test didn't fail, it means that it was found! // Let's now check some CSS properties... -assert-css: ("pre.example-line-numbers", { - "margin": "0px", - "padding": "13px 8px", - "text-align": "right", +define-function: ( + "check-colors", + (theme, color), + [ + // We now set the setting to show the line numbers on code examples. + ("local-storage", { + "rustdoc-theme": |theme|, + "rustdoc-use-system-theme": "false", + "rustdoc-line-numbers": "true" + }), + // We reload to make the line numbers appear and change theme. + ("reload"), + // We wait for them to be added into the DOM by the JS... + ("wait-for", "pre.example-line-numbers"), + // If the test didn't fail, it means that it was found! + ("assert-css", ( + "pre.example-line-numbers", + { + "color": |color|, + "margin": "0px", + "padding": "14px 8px", + "text-align": "right", + }, + ALL, + )), + ], +) +call-function: ("check-colors", { + "theme": "ayu", + "color": "rgb(92, 103, 115)", }) +call-function: ("check-colors", { + "theme": "dark", + "color": "rgb(59, 145, 226)", +}) +call-function: ("check-colors", { + "theme": "light", + "color": "rgb(198, 126, 45)", +}) + // The first code block has two lines so let's check its `
` elements lists both of them.
 assert-text: ("pre.example-line-numbers", "1\n2")
 
diff --git a/src/test/rustdoc-gui/source-code-page.goml b/src/test/rustdoc-gui/source-code-page.goml
index 25da74e5173eb..8a33e71319129 100644
--- a/src/test/rustdoc-gui/source-code-page.goml
+++ b/src/test/rustdoc-gui/source-code-page.goml
@@ -89,9 +89,9 @@ assert-css: (".src-line-numbers", {"text-align": "right"})
 // do anything (and certainly not add a `#NaN` to the URL!).
 goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
 // We use this assert-position to know where we will click.
-assert-position: ("//*[@id='1']", {"x": 104, "y": 112})
+assert-position: ("//*[@id='1']", {"x": 88, "y": 112})
 // We click on the left of the "1" anchor but still in the "src-line-number" `
`.
-click: (103, 103)
+click: (87, 103)
 assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
 
 // Checking the source code sidebar.