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]
[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
[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
+**Note: this README is for _users_ rather than _contributors_.**
+If you wish to _contribute_ to the compiler, you should read [CONTRIBUTING.md](CONTRIBUTING.md) instead.
## Quick Start
[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
-2. Clone the [source] with `git`:
+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
+
+
+### Building on a Unix-like system
+
+1. Clone the [source] with `git`:
```sh
git clone https://github.com/rust-lang/rust.git
[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.
- 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
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
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
### 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.
- `x86_64-pc-windows-msvc`
The build triple can be specified by either specifying `--build=<triple>` 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.
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
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
}
}
+ pub fn is_range_separator(&self) -> bool {
+ [DotDot, DotDotDot, DotDotEq].contains(&self.kind)
+ }
+
pub fn is_op(&self) -> bool {
match self.kind {
Eq | Lt | Le | EqEq | Ne | Ge | Gt | AndAnd | OrOr | Not | Tilde | BinOp(_)
return Err(Unpromotable);
}
- // We cannot promote things that need dropping, since the promoted value
- // would not get dropped.
- if self.qualif_local::<qualifs::NeedsDrop>(place.local) {
- return Err(Unpromotable);
- }
-
Ok(())
}
_ => bug!(),
}
}
} else {
- let span = self.body.local_decls[local].source_info.span;
- span_bug!(span, "{:?} not promotable, qualif_local shouldn't have been called", local);
+ false
}
}
fn validate_local(&mut self, local: Local) -> Result<(), Unpromotable> {
if let TempState::Defined { location: loc, uses, valid } = self.temps[local] {
+ // We cannot promote things that need dropping, since the promoted value
+ // would not get dropped.
+ if self.qualif_local::<qualifs::NeedsDrop>(local) {
+ return Err(Unpromotable);
+ }
valid.or_else(|_| {
let ok = {
let block = &self.body[loc.block];
/// stable across compilation session boundaries. More formally:
///
/// ```txt
-/// Ord::cmp(a1, b1) == Ord:cmp(a2, b2)
+/// Ord::cmp(a1, b1) == Ord::cmp(a2, b2)
/// where a2 = decode(encode(a1, context1), context2)
/// b2 = decode(encode(b1, context1), context2)
/// ```
let e = self
.tcx()
.sess
- .delay_span_bug(path.span, "path with `Res:Err` but no error emitted");
+ .delay_span_bug(path.span, "path with `Res::Err` but no error emitted");
self.set_tainted_by_errors(e);
self.tcx().ty_error_with_guaranteed(e)
}
// 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)
}
}
+ 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) {
+ 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(
+ span,
+ "try removing the method call",
+ "",
+ Applicability::MachineApplicable,
+ );
+ return true;
+ }
+ false
+ }
+
pub fn suggest_deref_ref_or_into(
&self,
err: &mut Diagnostic,
let (res, opt_ty, segments) =
self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span);
if res == Res::Err {
- let e = tcx.sess.delay_span_bug(pat.span, "`Res:Err` but no error emitted");
+ let e = tcx.sess.delay_span_bug(pat.span, "`Res::Err` but no error emitted");
self.set_tainted_by_errors(e);
on_error(e);
return tcx.ty_error_with_guaranteed(e);
/// fn main() {
/// let x: String = "3".try_into().unwrap();
/// // ^^^^^^^^
- /// // This call to try_into matches both Foo:try_into and TryInto::try_into as
+ /// // This call to try_into matches both Foo::try_into and TryInto::try_into as
/// // `TryInto` has been added to the Rust prelude in 2021 edition.
/// println!("{x}");
/// }
symbol_table: FxHashMap<Symbol, usize>,
}
-/// If the current crate is a proc-macro, returns early with `Lazy:empty()`.
+/// If the current crate is a proc-macro, returns early with `LazyArray::empty()`.
/// This is useful for skipping the encoding of things that aren't needed
/// for proc-macro crates.
macro_rules! empty_proc_macro {
LhsExpr::AttributesParsed(attrs) => Some(attrs),
_ => None,
};
- if [token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token.kind) {
+ if self.token.is_range_separator() {
return self.parse_prefix_range_expr(attrs);
} else {
self.parse_prefix_expr(attrs)?
}
debug_assert!(
- [token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token.kind),
+ self.token.is_range_separator(),
"parse_prefix_range_expr: token {:?} is not DotDot/DotDotEq",
self.token
);
let has_lifetime = self.token.is_lifetime() && self.look_ahead(1, |t| t != &token::Colon);
let lifetime = has_lifetime.then(|| self.expect_lifetime()); // For recovery, see below.
let (borrow_kind, mutbl) = self.parse_borrow_modifiers(lo);
- let expr = self.parse_prefix_expr(None);
+ let expr = if self.token.is_range_separator() {
+ self.parse_prefix_range_expr(None)
+ } else {
+ self.parse_prefix_expr(None)
+ };
let (hi, expr) = self.interpolated_or_expr_span(expr)?;
let span = lo.to(hi);
if let Some(lt) = lifetime {
} else {
return Some(Err(format!(
"'{}' is not a valid value for lld-flavor. \
- Use 'darwin', 'gnu', 'link' or 'wasm.",
+ Use 'darwin', 'gnu', 'link' or 'wasm'.",
s)))
}
Some(Ok(()))
use std::cell::Cell;
use std::collections::TryReserveErrorKind::*;
use std::fmt::Debug;
+use std::hint;
use std::iter::InPlaceIterable;
+use std::mem;
use std::mem::{size_of, swap};
use std::ops::Bound::*;
use std::panic::{catch_unwind, AssertUnwindSafe};
#[test]
fn test_into_iter_zst() {
- for _ in vec![[0u64; 0]].into_iter() {}
- for _ in vec![[0u64; 0]; 5].into_iter().rev() {}
+ #[derive(Debug, Clone)]
+ struct AlignedZstWithDrop([u64; 0]);
+ impl Drop for AlignedZstWithDrop {
+ fn drop(&mut self) {
+ let addr = self as *mut _ as usize;
+ assert!(hint::black_box(addr) % mem::align_of::<u64>() == 0);
+ }
+ }
+
+ const C: AlignedZstWithDrop = AlignedZstWithDrop([0u64; 0]);
+
+ for _ in vec![C].into_iter() {}
+ for _ in vec![C; 5].into_iter().rev() {}
+
+ let mut it = vec![C, C].into_iter();
+ it.advance_by(1).unwrap();
+ drop(it);
+
+ let mut it = vec![C, C].into_iter();
+ it.next_chunk::<1>().unwrap();
+ drop(it);
+
+ let mut it = vec![C, C].into_iter();
+ it.next_chunk::<4>().unwrap_err();
+ drop(it);
}
#[test]
}
// all ok, so lets decode it.
- let c = (((u - 0xD800) as u32) << 10 | (u2 - 0xDC00) as u32) + 0x1_0000;
+ let c = (((u & 0x3ff) as u32) << 10 | (u2 & 0x3ff) as u32) + 0x1_0000;
// SAFETY: we checked that it's a legal unicode value
Some(Ok(unsafe { from_u32_unchecked(c) }))
}
from_raw_parts(invalid(0), ())
}
+/// Creates a null mutable raw pointer.
+///
+/// # Examples
+///
+/// ```
+/// use std::ptr;
+///
+/// let p: *mut i32 = ptr::null_mut();
+/// assert!(p.is_null());
+/// ```
+#[inline(always)]
+#[must_use]
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_promotable]
+#[rustc_const_stable(feature = "const_ptr_null", since = "1.24.0")]
+#[rustc_allow_const_fn_unstable(ptr_metadata)]
+#[rustc_diagnostic_item = "ptr_null_mut"]
+pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
+ from_raw_parts_mut(invalid_mut(0), ())
+}
+
/// Creates an invalid pointer with the given address.
///
/// This is different from `addr as *const T`, which creates a pointer that picks up a previously
addr as *mut T
}
-/// Creates a null mutable raw pointer.
+/// Convert a reference to a raw pointer.
///
-/// # Examples
-///
-/// ```
-/// use std::ptr;
+/// This is equivalent to `r as *const T`, but is a bit safer since it will never silently change
+/// type or mutability, in particular if the code is refactored.
+#[inline(always)]
+#[must_use]
+#[unstable(feature = "ptr_from_ref", issue = "106116")]
+pub fn from_ref<T: ?Sized>(r: &T) -> *const T {
+ r
+}
+
+/// Convert a mutable reference to a raw pointer.
///
-/// let p: *mut i32 = ptr::null_mut();
-/// assert!(p.is_null());
-/// ```
+/// This is equivalent to `r as *mut T`, but is a bit safer since it will never silently change
+/// type or mutability, in particular if the code is refactored.
#[inline(always)]
#[must_use]
-#[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_promotable]
-#[rustc_const_stable(feature = "const_ptr_null", since = "1.24.0")]
-#[rustc_allow_const_fn_unstable(ptr_metadata)]
-#[rustc_diagnostic_item = "ptr_null_mut"]
-pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
- from_raw_parts_mut(invalid_mut(0), ())
+#[unstable(feature = "ptr_from_ref", issue = "106116")]
+pub fn from_mut<T: ?Sized>(r: &mut T) -> *mut T {
+ r
}
/// Forms a raw slice from a pointer and a length.
}
check(&[0xD800, 0x41, 0x42], &[Err(0xD800), Ok('A'), Ok('B')]);
check(&[0xD800, 0], &[Err(0xD800), Ok('\0')]);
+ check(&[0xD800], &[Err(0xD800)]);
+ check(&[0xD840, 0xDC00], &[Ok('\u{20000}')]);
+ check(&[0xD840, 0xD840, 0xDC00], &[Err(0xD840), Ok('\u{20000}')]);
+ check(&[0xDC00, 0xD840], &[Err(0xDC00), Err(0xD840)]);
}
#[test]
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};
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};
)))]
'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 },
)))]
{
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 {
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};
))]
#[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};
## 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
/// 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
.source .content pre {
padding: 20px;
}
+.rustdoc.source .example-wrap > pre.src-line-numbers {
+ padding: 20px 0 20px 4px;
+}
img {
max-width: 100%;
display: none;
}
-.source .content pre.rust {
- padding-left: 0;
-}
-
.rustdoc .example-wrap {
display: flex;
position: relative;
-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);
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;
.toggle-line-inner {
min-width: 2px;
height: 100%;
+ background: var(--scrape-example-toggle-line-background);
+}
+
+.toggle-line:hover .toggle-line-inner {
+ background: var(--scrape-example-toggle-line-hover-background);
}
.more-scraped-examples .scraped-example, .example-links {
--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;
--source-sidebar-background-hover: #14191f;
--table-alt-row-background-color: #191f26;
--codeblock-link-background: #333;
+ --scrape-example-toggle-line-background: #999;
+ --scrape-example-toggle-line-hover-background: #c5c5c5;
}
h1, h2, h3, h4 {
.src-line-numbers .line-highlighted {
color: #708090;
- padding-right: 4px;
+ padding-right: 7px;
border-right: 1px solid #ffb44c;
}
.scraped-example:not(.expanded) .code-wrapper::after {
background: linear-gradient(to top, rgba(15, 20, 25, 1), rgba(15, 20, 25, 0));
}
-.toggle-line-inner {
- background: #999;
-}
-.toggle-line:hover .toggle-line-inner {
- background: #c5c5c5;
-}
--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;
--source-sidebar-background-hover: #444;
--table-alt-row-background-color: #2A2A2A;
--codeblock-link-background: #333;
+ --scrape-example-toggle-line-background: #999;
+ --scrape-example-toggle-line-hover-background: #c5c5c5;
}
#titles > button:not(.selected) {
.scraped-example:not(.expanded) .code-wrapper::after {
background: linear-gradient(to top, rgba(53, 53, 53, 1), rgba(53, 53, 53, 0));
}
-.toggle-line-inner {
- background: #999;
-}
-.toggle-line:hover .toggle-line-inner {
- background: #c5c5c5;
-}
--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;
--source-sidebar-background-hover: #e0e0e0;
--table-alt-row-background-color: #F5F5F5;
--codeblock-link-background: #eee;
+ --scrape-example-toggle-line-background: #ccc;
+ --scrape-example-toggle-line-hover-background: #999;
}
#titles > button:not(.selected) {
.scraped-example:not(.expanded) .code-wrapper::after {
background: linear-gradient(to top, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));
}
-.toggle-line-inner {
- background: #ccc;
-}
-.toggle-line:hover .toggle-line-inner {
- background: #999;
-}
--- /dev/null
+// The `derive(PartialOrd)` for a newtype doesn't override `lt`/`le`/`gt`/`ge`.
+// This double-checks that the `Option<Ordering>` 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
+}
// 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 `<pre>` elements lists both of them.
assert-text: ("pre.example-line-numbers", "1\n2")
// This tests checks that the "scraped examples" toggle is working as expected.
goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"
-// Clicking "More examples..." will open additional examples
-assert-attribute-false: (".more-examples-toggle", {"open": ""})
-click: ".more-examples-toggle"
-assert-attribute: (".more-examples-toggle", {"open": ""})
+// Checking the color of the toggle line.
+show-text: true
+define-function: (
+ "check-color",
+ (theme, toggle_line_color, toggle_line_hover_color),
+ [
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ ("reload"),
+
+ // Clicking "More examples..." will open additional examples
+ ("assert-attribute-false", (".more-examples-toggle", {"open": ""})),
+ ("click", ".more-examples-toggle"),
+ ("assert-attribute", (".more-examples-toggle", {"open": ""})),
+
+ ("assert-css", (".toggle-line-inner", {"background-color": |toggle_line_color|}, ALL)),
+ ("move-cursor-to", ".toggle-line"),
+ ("assert-css", (
+ ".toggle-line:hover .toggle-line-inner",
+ {"background-color": |toggle_line_hover_color|},
+ )),
+ // Moving cursor away from the toggle line to prevent disrupting next test.
+ ("move-cursor-to", ".search-input"),
+ ],
+)
+
+call-function: ("check-color", {
+ "theme": "ayu",
+ "toggle_line_color": "rgb(153, 153, 153)",
+ "toggle_line_hover_color": "rgb(197, 197, 197)",
+})
+call-function: ("check-color", {
+ "theme": "dark",
+ "toggle_line_color": "rgb(153, 153, 153)",
+ "toggle_line_hover_color": "rgb(197, 197, 197)",
+})
+call-function: ("check-color", {
+ "theme": "light",
+ "toggle_line_color": "rgb(204, 204, 204)",
+ "toggle_line_hover_color": "rgb(153, 153, 153)",
+})
// Toggling all docs will close additional examples
click: "#toggle-all-docs"
// 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" `<pre>`.
-click: (103, 103)
+click: (87, 103)
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
// Checking the source code sidebar.
--- /dev/null
+#![feature(const_mut_refs)]
+#![feature(const_trait_impl)]
+struct Panic;
+impl const Drop for Panic { fn drop(&mut self) { panic!(); } }
+pub const fn id<T>(x: T) -> T { x }
+pub const C: () = {
+ let _: &'static _ = &id(&Panic);
+ //~^ ERROR: temporary value dropped while borrowed
+ //~| ERROR: temporary value dropped while borrowed
+};
+
+fn main() {
+ let _: &'static _ = &id(&Panic);
+ //~^ ERROR: temporary value dropped while borrowed
+ //~| ERROR: temporary value dropped while borrowed
+ let _: &'static _ = &&(Panic, 0).1;
+ //~^ ERROR: temporary value dropped while borrowed
+ //~| ERROR: temporary value dropped while borrowed
+}
--- /dev/null
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call.rs:7:26
+ |
+LL | let _: &'static _ = &id(&Panic);
+ | ---------- ^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | };
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call.rs:7:30
+ |
+LL | let _: &'static _ = &id(&Panic);
+ | ---------- ^^^^^ - temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | type annotation requires that borrow lasts for `'static`
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call.rs:13:26
+ |
+LL | let _: &'static _ = &id(&Panic);
+ | ---------- ^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call.rs:13:30
+ |
+LL | let _: &'static _ = &id(&Panic);
+ | ---------- ^^^^^ - temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | type annotation requires that borrow lasts for `'static`
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call.rs:16:26
+ |
+LL | let _: &'static _ = &&(Panic, 0).1;
+ | ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call.rs:16:27
+ |
+LL | let _: &'static _ = &&(Panic, 0).1;
+ | ---------- ^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0716`.
--- /dev/null
+#![feature(const_precise_live_drops)]
+pub const fn id<T>(x: T) -> T { x }
+pub const C: () = {
+ let _: &'static _ = &id(&String::new());
+ //~^ ERROR: temporary value dropped while borrowed
+ //~| ERROR: temporary value dropped while borrowed
+ //~| ERROR: destructor of `String` cannot be evaluated at compile-time
+};
+
+fn main() {
+ let _: &'static _ = &id(&String::new());
+ //~^ ERROR: temporary value dropped while borrowed
+ //~| ERROR: temporary value dropped while borrowed
+}
--- /dev/null
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call2.rs:4:26
+ |
+LL | let _: &'static _ = &id(&String::new());
+ | ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | };
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call2.rs:4:30
+ |
+LL | let _: &'static _ = &id(&String::new());
+ | ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | type annotation requires that borrow lasts for `'static`
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call2.rs:11:26
+ |
+LL | let _: &'static _ = &id(&String::new());
+ | ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call2.rs:11:30
+ |
+LL | let _: &'static _ = &id(&String::new());
+ | ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | type annotation requires that borrow lasts for `'static`
+
+error[E0493]: destructor of `String` cannot be evaluated at compile-time
+ --> $DIR/promoted_const_call2.rs:4:30
+ |
+LL | let _: &'static _ = &id(&String::new());
+ | ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants
+
+error: aborting due to 5 previous errors
+
+Some errors have detailed explanations: E0493, E0716.
+For more information about an error, try `rustc --explain E0493`.
--- /dev/null
+pub const fn id<T>(x: T) -> T { x }
+pub const C: () = {
+ let _: &'static _ = &String::new();
+ //~^ ERROR: destructor of `String` cannot be evaluated at compile-time
+ //~| ERROR: temporary value dropped while borrowed
+
+ let _: &'static _ = &id(&String::new());
+ //~^ ERROR: destructor of `String` cannot be evaluated at compile-time
+ //~| ERROR: temporary value dropped while borrowed
+ //~| ERROR: temporary value dropped while borrowed
+
+ let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
+ //~^ ERROR: temporary value dropped while borrowed
+};
+
+fn main() {
+ let _: &'static _ = &String::new();
+ //~^ ERROR: temporary value dropped while borrowed
+
+ let _: &'static _ = &id(&String::new());
+ //~^ ERROR: temporary value dropped while borrowed
+ //~| ERROR: temporary value dropped while borrowed
+
+ let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
+ //~^ ERROR: temporary value dropped while borrowed
+}
--- /dev/null
+error[E0493]: destructor of `String` cannot be evaluated at compile-time
+ --> $DIR/promoted_const_call3.rs:7:30
+ |
+LL | let _: &'static _ = &id(&String::new());
+ | ^^^^^^^^^^^^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constants
+
+error[E0493]: destructor of `String` cannot be evaluated at compile-time
+ --> $DIR/promoted_const_call3.rs:3:26
+ |
+LL | let _: &'static _ = &String::new();
+ | ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants
+...
+LL | };
+ | - value is dropped here
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call3.rs:3:26
+ |
+LL | let _: &'static _ = &String::new();
+ | ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | };
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call3.rs:7:26
+ |
+LL | let _: &'static _ = &id(&String::new());
+ | ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | };
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call3.rs:7:30
+ |
+LL | let _: &'static _ = &id(&String::new());
+ | ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | type annotation requires that borrow lasts for `'static`
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call3.rs:12:26
+ |
+LL | let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
+ | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+LL |
+LL | };
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call3.rs:17:26
+ |
+LL | let _: &'static _ = &String::new();
+ | ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call3.rs:20:26
+ |
+LL | let _: &'static _ = &id(&String::new());
+ | ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call3.rs:20:30
+ |
+LL | let _: &'static _ = &id(&String::new());
+ | ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | type annotation requires that borrow lasts for `'static`
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call3.rs:24:26
+ |
+LL | let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
+ | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+LL |
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error: aborting due to 10 previous errors
+
+Some errors have detailed explanations: E0493, E0716.
+For more information about an error, try `rustc --explain E0493`.
--- /dev/null
+// run-pass
+
+use std::sync::atomic::*;
+
+static FLAG: AtomicBool = AtomicBool::new(false);
+
+struct NoisyDrop(&'static str);
+impl Drop for NoisyDrop {
+ fn drop(&mut self) {
+ FLAG.store(true, Ordering::SeqCst);
+ }
+}
+fn main() {
+ {
+ let _val = &&(NoisyDrop("drop!"), 0).1;
+ }
+ assert!(FLAG.load(Ordering::SeqCst));
+}
--- /dev/null
+#![feature(rustc_attrs)]
+#![feature(staged_api)]
+#![stable(feature = "a", since = "1.0.0")]
+
+#[rustc_promotable]
+#[stable(feature = "a", since = "1.0.0")]
+#[rustc_const_stable(feature = "a", since = "1.0.0")]
+pub const fn id<T>(x: &'static T) -> &'static T { x }
+
+#[rustc_promotable]
+#[stable(feature = "a", since = "1.0.0")]
+#[rustc_const_stable(feature = "a", since = "1.0.0")]
+pub const fn new_string() -> String {
+ String::new()
+}
+
+#[rustc_promotable]
+#[stable(feature = "a", since = "1.0.0")]
+#[rustc_const_stable(feature = "a", since = "1.0.0")]
+pub const fn new_manually_drop<T>(t: T) -> std::mem::ManuallyDrop<T> {
+ std::mem::ManuallyDrop::new(t)
+}
+
+
+const C: () = {
+ let _: &'static _ = &id(&new_string());
+ //~^ ERROR destructor of `String` cannot be evaluated at compile-time
+ //~| ERROR: temporary value dropped while borrowed
+ //~| ERROR: temporary value dropped while borrowed
+
+ let _: &'static _ = &new_manually_drop(new_string());
+ //~^ ERROR: temporary value dropped while borrowed
+};
+
+fn main() {
+ let _: &'static _ = &id(&new_string());
+ //~^ ERROR: temporary value dropped while borrowed
+ //~| ERROR: temporary value dropped while borrowed
+
+ let _: &'static _ = &new_manually_drop(new_string());
+ //~^ ERROR: temporary value dropped while borrowed
+}
--- /dev/null
+error[E0493]: destructor of `String` cannot be evaluated at compile-time
+ --> $DIR/promoted_const_call5.rs:26:30
+ |
+LL | let _: &'static _ = &id(&new_string());
+ | ^^^^^^^^^^^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constants
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call5.rs:26:26
+ |
+LL | let _: &'static _ = &id(&new_string());
+ | ---------- ^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | };
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call5.rs:26:30
+ |
+LL | let _: &'static _ = &id(&new_string());
+ | ----^^^^^^^^^^^^-- temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | argument requires that borrow lasts for `'static`
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call5.rs:31:26
+ |
+LL | let _: &'static _ = &new_manually_drop(new_string());
+ | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+LL |
+LL | };
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call5.rs:36:26
+ |
+LL | let _: &'static _ = &id(&new_string());
+ | ---------- ^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+...
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call5.rs:36:30
+ |
+LL | let _: &'static _ = &id(&new_string());
+ | ----^^^^^^^^^^^^-- temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | argument requires that borrow lasts for `'static`
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promoted_const_call5.rs:40:26
+ |
+LL | let _: &'static _ = &new_manually_drop(new_string());
+ | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+LL |
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error: aborting due to 7 previous errors
+
+Some errors have detailed explanations: E0493, E0716.
+For more information about an error, try `rustc --explain E0493`.
+++ /dev/null
-// run-rustfix
-
-macro_rules! my_wrapper {
- ($expr:expr) => { MyWrapper($expr) }
-}
-
-pub struct MyWrapper(u32);
-
-fn main() {
- let value = MyWrapper(123);
- some_fn(value); //~ ERROR mismatched types
- some_fn(my_wrapper!(123)); //~ ERROR mismatched types
-}
-
-fn some_fn(wrapped: MyWrapper) {
- drop(wrapped);
-}
+++ /dev/null
-// run-rustfix
-
-macro_rules! my_wrapper {
- ($expr:expr) => { MyWrapper($expr) }
-}
-
-pub struct MyWrapper(u32);
-
-fn main() {
- let value = MyWrapper(123);
- some_fn(value.0); //~ ERROR mismatched types
- some_fn(my_wrapper!(123).0); //~ ERROR mismatched types
-}
-
-fn some_fn(wrapped: MyWrapper) {
- drop(wrapped);
-}
+++ /dev/null
-error[E0308]: mismatched types
- --> $DIR/suggest-removing-tulpe-struct-field.rs:11:13
- |
-LL | some_fn(value.0);
- | ------- ^^^^^^^ expected struct `MyWrapper`, found `u32`
- | |
- | arguments to this function are incorrect
- |
-note: function defined here
- --> $DIR/suggest-removing-tulpe-struct-field.rs:15:4
- |
-LL | fn some_fn(wrapped: MyWrapper) {
- | ^^^^^^^ ------------------
-help: consider removing the tuple struct field `0`
- |
-LL - some_fn(value.0);
-LL + some_fn(value);
- |
-
-error[E0308]: mismatched types
- --> $DIR/suggest-removing-tulpe-struct-field.rs:12:13
- |
-LL | some_fn(my_wrapper!(123).0);
- | ------- ^^^^^^^^^^^^^^^^^^ expected struct `MyWrapper`, found `u32`
- | |
- | arguments to this function are incorrect
- |
-note: function defined here
- --> $DIR/suggest-removing-tulpe-struct-field.rs:15:4
- |
-LL | fn some_fn(wrapped: MyWrapper) {
- | ^^^^^^^ ------------------
-help: consider removing the tuple struct field `0`
- |
-LL - some_fn(my_wrapper!(123).0);
-LL + some_fn(my_wrapper!(123));
- |
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+// run-rustfix
+
+macro_rules! my_wrapper {
+ ($expr:expr) => { MyWrapper($expr) }
+}
+
+pub struct MyWrapper(u32);
+
+fn main() {
+ let value = MyWrapper(123);
+ some_fn(value); //~ ERROR mismatched types
+ some_fn(my_wrapper!(123)); //~ ERROR mismatched types
+}
+
+fn some_fn(wrapped: MyWrapper) {
+ drop(wrapped);
+}
--- /dev/null
+// run-rustfix
+
+macro_rules! my_wrapper {
+ ($expr:expr) => { MyWrapper($expr) }
+}
+
+pub struct MyWrapper(u32);
+
+fn main() {
+ let value = MyWrapper(123);
+ some_fn(value.0); //~ ERROR mismatched types
+ some_fn(my_wrapper!(123).0); //~ ERROR mismatched types
+}
+
+fn some_fn(wrapped: MyWrapper) {
+ drop(wrapped);
+}
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/suggest-removing-tuple-struct-field.rs:11:13
+ |
+LL | some_fn(value.0);
+ | ------- ^^^^^^^ expected struct `MyWrapper`, found `u32`
+ | |
+ | arguments to this function are incorrect
+ |
+note: function defined here
+ --> $DIR/suggest-removing-tuple-struct-field.rs:15:4
+ |
+LL | fn some_fn(wrapped: MyWrapper) {
+ | ^^^^^^^ ------------------
+help: consider removing the tuple struct field `0`
+ |
+LL - some_fn(value.0);
+LL + some_fn(value);
+ |
+
+error[E0308]: mismatched types
+ --> $DIR/suggest-removing-tuple-struct-field.rs:12:13
+ |
+LL | some_fn(my_wrapper!(123).0);
+ | ------- ^^^^^^^^^^^^^^^^^^ expected struct `MyWrapper`, found `u32`
+ | |
+ | arguments to this function are incorrect
+ |
+note: function defined here
+ --> $DIR/suggest-removing-tuple-struct-field.rs:15:4
+ |
+LL | fn some_fn(wrapped: MyWrapper) {
+ | ^^^^^^^ ------------------
+help: consider removing the tuple struct field `0`
+ |
+LL - some_fn(my_wrapper!(123).0);
+LL + some_fn(my_wrapper!(123));
+ |
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+// check-pass
+
+fn main() {
+ let _a = ..;
+ let _b = ..=10;
+ let _c = &..;
+ let _d = &..=10;
+}
--- /dev/null
+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();
+}
--- /dev/null
+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`.
} else {
filecheck.args(&["--check-prefixes", &prefixes]);
}
+ // Provide more context on failures.
+ filecheck.args(&["--dump-input-context", "100"]);
self.compose_and_run(filecheck, "", None, None)
}