mirror of
https://git.proxmox.com/git/rustc
synced 2026-03-25 15:54:11 +00:00
New upstream version 1.83.0+dfsg1
This commit is contained in:
parent
04c3a46a7c
commit
4626ec444e
760
Cargo.lock
generated
760
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
238
RELEASES.md
238
RELEASES.md
@ -1,3 +1,234 @@
|
||||
Version 1.83.0 (2024-11-28)
|
||||
==========================
|
||||
|
||||
<a id="1.83.0-Language"></a>
|
||||
|
||||
Language
|
||||
--------
|
||||
- [Stabilize `&mut`, `*mut`, `&Cell`, and `*const Cell` in const.](https://github.com/rust-lang/rust/pull/129195)
|
||||
- [Allow creating references to statics in `const` initializers.](https://github.com/rust-lang/rust/pull/129759)
|
||||
- [Implement raw lifetimes and labels (`'r#ident`).](https://github.com/rust-lang/rust/pull/126452)
|
||||
- [Define behavior when atomic and non-atomic reads race.](https://github.com/rust-lang/rust/pull/128778)
|
||||
- [Non-exhaustive structs may now be empty.](https://github.com/rust-lang/rust/pull/128934)
|
||||
- [Disallow implicit coercions from places of type `!`](https://github.com/rust-lang/rust/pull/129392)
|
||||
- [`const extern` functions can now be defined for other calling conventions.](https://github.com/rust-lang/rust/pull/129753)
|
||||
- [Stabilize `expr_2021` macro fragment specifier in all editions.](https://github.com/rust-lang/rust/pull/129972)
|
||||
- [The `non_local_definitions` lint now fires on less code and warns by default.](https://github.com/rust-lang/rust/pull/127117)
|
||||
|
||||
|
||||
<a id="1.83.0-Compiler"></a>
|
||||
|
||||
Compiler
|
||||
--------
|
||||
- [Deprecate unsound `-Csoft-float` flag.](https://github.com/rust-lang/rust/pull/129897)
|
||||
- Add many new tier 3 targets:
|
||||
- [`aarch64_unknown_nto_qnx700`](https://github.com/rust-lang/rust/pull/127897)
|
||||
- [`arm64e-apple-tvos`](https://github.com/rust-lang/rust/pull/130614)
|
||||
- [`armv7-rtems-eabihf`](https://github.com/rust-lang/rust/pull/127021)
|
||||
- [`loongarch64-unknown-linux-ohos`](https://github.com/rust-lang/rust/pull/130750)
|
||||
- [`riscv32-wrs-vxworks` and `riscv64-wrs-vxworks`](https://github.com/rust-lang/rust/pull/130549)
|
||||
- [`riscv32{e|em|emc}-unknown-none-elf`](https://github.com/rust-lang/rust/pull/130555)
|
||||
- [`x86_64-unknown-hurd-gnu`](https://github.com/rust-lang/rust/pull/128345)
|
||||
- [`x86_64-unknown-trusty`](https://github.com/rust-lang/rust/pull/130453)
|
||||
|
||||
Refer to Rust's [platform support page][platform-support-doc]
|
||||
for more information on Rust's tiered platform support.
|
||||
|
||||
|
||||
<a id="1.83.0-Libraries"></a>
|
||||
|
||||
Libraries
|
||||
---------
|
||||
- [Implement `PartialEq` for `ExitCode`.](https://github.com/rust-lang/rust/pull/127633)
|
||||
- [Document that `catch_unwind` can deal with foreign exceptions without UB, although the exact behavior is unspecified.](https://github.com/rust-lang/rust/pull/128321)
|
||||
- [Implement `Default` for `HashMap`/`HashSet` iterators that don't already have it.](https://github.com/rust-lang/rust/pull/128711)
|
||||
- [Bump Unicode to version 16.0.0.](https://github.com/rust-lang/rust/pull/130183)
|
||||
- [Change documentation of `ptr::add`/`sub` to not claim equivalence with `offset`.](https://github.com/rust-lang/rust/pull/130229).
|
||||
|
||||
|
||||
<a id="1.83.0-Stabilized-APIs"></a>
|
||||
|
||||
Stabilized APIs
|
||||
---------------
|
||||
|
||||
- [`BufRead::skip_until`](https://doc.rust-lang.org/stable/std/io/trait.BufRead.html#method.skip_until)
|
||||
- [`ControlFlow::break_value`](https://doc.rust-lang.org/stable/core/ops/enum.ControlFlow.html#method.break_value)
|
||||
- [`ControlFlow::continue_value`](https://doc.rust-lang.org/stable/core/ops/enum.ControlFlow.html#method.continue_value)
|
||||
- [`ControlFlow::map_break`](https://doc.rust-lang.org/stable/core/ops/enum.ControlFlow.html#method.map_break)
|
||||
- [`ControlFlow::map_continue`](https://doc.rust-lang.org/stable/core/ops/enum.ControlFlow.html#method.map_continue)
|
||||
- [`DebugList::finish_non_exhaustive`](https://doc.rust-lang.org/stable/core/fmt/struct.DebugList.html#method.finish_non_exhaustive)
|
||||
- [`DebugMap::finish_non_exhaustive`](https://doc.rust-lang.org/stable/core/fmt/struct.DebugMap.html#method.finish_non_exhaustive)
|
||||
- [`DebugSet::finish_non_exhaustive`](https://doc.rust-lang.org/stable/core/fmt/struct.DebugSet.html#method.finish_non_exhaustive)
|
||||
- [`DebugTuple::finish_non_exhaustive`](https://doc.rust-lang.org/stable/core/fmt/struct.DebugTuple.html#method.finish_non_exhaustive)
|
||||
- [`ErrorKind::ArgumentListTooLong`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.ArgumentListTooLong)
|
||||
- [`ErrorKind::Deadlock`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.Deadlock)
|
||||
- [`ErrorKind::DirectoryNotEmpty`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.DirectoryNotEmpty)
|
||||
- [`ErrorKind::ExecutableFileBusy`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.ExecutableFileBusy)
|
||||
- [`ErrorKind::FileTooLarge`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.FileTooLarge)
|
||||
- [`ErrorKind::HostUnreachable`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.HostUnreachable)
|
||||
- [`ErrorKind::IsADirectory`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.IsADirectory)
|
||||
- [`ErrorKind::NetworkDown`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.NetworkDown)
|
||||
- [`ErrorKind::NetworkUnreachable`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.NetworkUnreachable)
|
||||
- [`ErrorKind::NotADirectory`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.NotADirectory)
|
||||
- [`ErrorKind::NotSeekable`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.NotSeekable)
|
||||
- [`ErrorKind::ReadOnlyFilesystem`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.ReadOnlyFilesystem)
|
||||
- [`ErrorKind::ResourceBusy`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.ResourceBusy)
|
||||
- [`ErrorKind::StaleNetworkFileHandle`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.StaleNetworkFileHandle)
|
||||
- [`ErrorKind::StorageFull`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.StorageFull)
|
||||
- [`ErrorKind::TooManyLinks`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.TooManyLinks)
|
||||
- [`Option::get_or_insert_default`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.get_or_insert_default)
|
||||
- [`Waker::data`](https://doc.rust-lang.org/stable/core/task/struct.Waker.html#method.data)
|
||||
- [`Waker::new`](https://doc.rust-lang.org/stable/core/task/struct.Waker.html#method.new)
|
||||
- [`Waker::vtable`](https://doc.rust-lang.org/stable/core/task/struct.Waker.html#method.vtable)
|
||||
- [`char::MIN`](https://doc.rust-lang.org/stable/core/primitive.char.html#associatedconstant.MIN)
|
||||
- [`hash_map::Entry::insert_entry`](https://doc.rust-lang.org/stable/std/collections/hash_map/enum.Entry.html#method.insert_entry)
|
||||
- [`hash_map::VacantEntry::insert_entry`](https://doc.rust-lang.org/stable/std/collections/hash_map/struct.VacantEntry.html#method.insert_entry)
|
||||
|
||||
These APIs are now stable in const contexts:
|
||||
|
||||
- [`Cell::into_inner`](https://doc.rust-lang.org/stable/core/cell/struct.Cell.html#method.into_inner)
|
||||
- [`Duration::as_secs_f32`](https://doc.rust-lang.org/stable/core/time/struct.Duration.html#method.as_secs_f32)
|
||||
- [`Duration::as_secs_f64`](https://doc.rust-lang.org/stable/core/time/struct.Duration.html#method.as_secs_f64)
|
||||
- [`Duration::div_duration_f32`](https://doc.rust-lang.org/stable/core/time/struct.Duration.html#method.div_duration_f32)
|
||||
- [`Duration::div_duration_f64`](https://doc.rust-lang.org/stable/core/time/struct.Duration.html#method.div_duration_f64)
|
||||
- [`MaybeUninit::as_mut_ptr`](https://doc.rust-lang.org/stable/core/mem/union.MaybeUninit.html#method.as_mut_ptr)
|
||||
- [`NonNull::as_mut`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.as_mut)
|
||||
- [`NonNull::copy_from`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.copy_from)
|
||||
- [`NonNull::copy_from_nonoverlapping`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.copy_from_nonoverlapping)
|
||||
- [`NonNull::copy_to`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.copy_to)
|
||||
- [`NonNull::copy_to_nonoverlapping`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.copy_to_nonoverlapping)
|
||||
- [`NonNull::slice_from_raw_parts`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.slice_from_raw_parts)
|
||||
- [`NonNull::write`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.write)
|
||||
- [`NonNull::write_bytes`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.write_bytes)
|
||||
- [`NonNull::write_unaligned`](https://doc.rust-lang.org/stable/core/ptr/struct.NonNull.html#method.write_unaligned)
|
||||
- [`OnceCell::into_inner`](https://doc.rust-lang.org/stable/core/cell/struct.OnceCell.html#method.into_inner)
|
||||
- [`Option::as_mut`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.as_mut)
|
||||
- [`Option::expect`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.expect)
|
||||
- [`Option::replace`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.replace)
|
||||
- [`Option::take`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.take)
|
||||
- [`Option::unwrap`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.unwrap)
|
||||
- [`Option::unwrap_unchecked`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.unwrap_unchecked)
|
||||
- [`Option::<&_>::copied`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.copied)
|
||||
- [`Option::<&mut _>::copied`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.copied-1)
|
||||
- [`Option::<Option<_>>::flatten`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.flatten)
|
||||
- [`Option::<Result<_, _>>::transpose`](https://doc.rust-lang.org/stable/core/option/enum.Option.html#method.transpose)
|
||||
- [`RefCell::into_inner`](https://doc.rust-lang.org/stable/core/cell/struct.RefCell.html#method.into_inner)
|
||||
- [`Result::as_mut`](https://doc.rust-lang.org/stable/core/result/enum.Result.html#method.as_mut)
|
||||
- [`Result::<&_, _>::copied`](https://doc.rust-lang.org/stable/core/result/enum.Result.html#method.copied)
|
||||
- [`Result::<&mut _, _>::copied`](https://doc.rust-lang.org/stable/core/result/enum.Result.html#method.copied-1)
|
||||
- [`Result::<Option<_>, _>::transpose`](https://doc.rust-lang.org/stable/core/result/enum.Result.html#method.transpose)
|
||||
- [`UnsafeCell::get_mut`](https://doc.rust-lang.org/stable/core/cell/struct.UnsafeCell.html#method.get_mut)
|
||||
- [`UnsafeCell::into_inner`](https://doc.rust-lang.org/stable/core/cell/struct.UnsafeCell.html#method.into_inner)
|
||||
- [`array::from_mut`](https://doc.rust-lang.org/stable/core/array/fn.from_mut.html)
|
||||
- [`char::encode_utf8`](https://doc.rust-lang.org/stable/core/primitive.char.html#method.encode_utf8)
|
||||
- [`{float}::classify`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.classify)
|
||||
- [`{float}::is_finite`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.is_finite)
|
||||
- [`{float}::is_infinite`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.is_infinite)
|
||||
- [`{float}::is_nan`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.is_nan)
|
||||
- [`{float}::is_normal`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.is_normal)
|
||||
- [`{float}::is_sign_negative`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.is_sign_negative)
|
||||
- [`{float}::is_sign_positive`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.is_sign_positive)
|
||||
- [`{float}::is_subnormal`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.is_subnormal)
|
||||
- [`{float}::from_bits`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.from_bits)
|
||||
- [`{float}::from_be_bytes`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.from_be_bytes)
|
||||
- [`{float}::from_le_bytes`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.from_le_bytes)
|
||||
- [`{float}::from_ne_bytes`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.from_ne_bytes)
|
||||
- [`{float}::to_bits`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.to_bits)
|
||||
- [`{float}::to_be_bytes`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.to_be_bytes)
|
||||
- [`{float}::to_le_bytes`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.to_le_bytes)
|
||||
- [`{float}::to_ne_bytes`](https://doc.rust-lang.org/stable/core/primitive.f64.html#method.to_ne_bytes)
|
||||
- [`mem::replace`](https://doc.rust-lang.org/stable/core/mem/fn.replace.html)
|
||||
- [`ptr::replace`](https://doc.rust-lang.org/stable/core/ptr/fn.replace.html)
|
||||
- [`ptr::slice_from_raw_parts_mut`](https://doc.rust-lang.org/stable/core/ptr/fn.slice_from_raw_parts_mut.html)
|
||||
- [`ptr::write`](https://doc.rust-lang.org/stable/core/ptr/fn.write.html)
|
||||
- [`ptr::write_unaligned`](https://doc.rust-lang.org/stable/core/ptr/fn.write_unaligned.html)
|
||||
- [`<*const _>::copy_to`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.copy_to)
|
||||
- [`<*const _>::copy_to_nonoverlapping`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.copy_to_nonoverlapping)
|
||||
- [`<*mut _>::copy_from`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.copy_from)
|
||||
- [`<*mut _>::copy_from_nonoverlapping`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.copy_from_nonoverlapping)
|
||||
- [`<*mut _>::copy_to`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.copy_to-1)
|
||||
- [`<*mut _>::copy_to_nonoverlapping`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.copy_to_nonoverlapping-1)
|
||||
- [`<*mut _>::write`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.write)
|
||||
- [`<*mut _>::write_bytes`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.write_bytes)
|
||||
- [`<*mut _>::write_unaligned`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.write_unaligned)
|
||||
- [`slice::from_mut`](https://doc.rust-lang.org/stable/core/slice/fn.from_mut.html)
|
||||
- [`slice::from_raw_parts_mut`](https://doc.rust-lang.org/stable/core/slice/fn.from_raw_parts_mut.html)
|
||||
- [`<[_]>::first_mut`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.first_mut)
|
||||
- [`<[_]>::last_mut`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.last_mut)
|
||||
- [`<[_]>::first_chunk_mut`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.first_chunk_mut)
|
||||
- [`<[_]>::last_chunk_mut`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.last_chunk_mut)
|
||||
- [`<[_]>::split_at_mut`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.split_at_mut)
|
||||
- [`<[_]>::split_at_mut_checked`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.split_at_mut_checked)
|
||||
- [`<[_]>::split_at_mut_unchecked`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.split_at_mut_unchecked)
|
||||
- [`<[_]>::split_first_mut`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.split_first_mut)
|
||||
- [`<[_]>::split_last_mut`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.split_last_mut)
|
||||
- [`<[_]>::split_first_chunk_mut`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.split_first_chunk_mut)
|
||||
- [`<[_]>::split_last_chunk_mut`](https://doc.rust-lang.org/stable/core/primitive.slice.html#method.split_last_chunk_mut)
|
||||
- [`str::as_bytes_mut`](https://doc.rust-lang.org/stable/core/primitive.str.html#method.as_bytes_mut)
|
||||
- [`str::as_mut_ptr`](https://doc.rust-lang.org/stable/core/primitive.str.html#method.as_mut_ptr)
|
||||
- [`str::from_utf8_unchecked_mut`](https://doc.rust-lang.org/stable/core/str/fn.from_utf8_unchecked_mut.html)
|
||||
|
||||
|
||||
<a id="1.83.0-Cargo"></a>
|
||||
|
||||
Cargo
|
||||
-----
|
||||
- [Introduced a new `CARGO_MANIFEST_PATH` environment variable, similar to `CARGO_MANIFEST_DIR` but pointing directly to the manifest file.](https://github.com/rust-lang/cargo/pull/14404/)
|
||||
- [Added `package.autolib` to the manifest, allowing `[lib]` auto-discovery to be disabled.](https://github.com/rust-lang/cargo/pull/14591/)
|
||||
- [Declare support level for each crate in Cargo's Charter / crate docs.](https://github.com/rust-lang/cargo/pull/14600/)
|
||||
- [Declare new Intentional Artifacts as 'small' changes.](https://github.com/rust-lang/cargo/pull/14599/)
|
||||
|
||||
|
||||
<a id="1.83-Rustdoc"></a>
|
||||
|
||||
Rustdoc
|
||||
-------
|
||||
|
||||
- [The sidebar / hamburger menu table of contents now includes the `# headers` from the main item's doc comment](https://github.com/rust-lang/rust/pull/120736). This is similar to a third-party feature provided by the rustdoc-search-enhancements browser extension.
|
||||
|
||||
|
||||
<a id="1.83.0-Compatibility-Notes"></a>
|
||||
|
||||
Compatibility Notes
|
||||
-------------------
|
||||
- [Warn against function pointers using unsupported ABI strings.](https://github.com/rust-lang/rust/pull/128784)
|
||||
- [Check well-formedness of the source type's signature in fn pointer casts.](https://github.com/rust-lang/rust/pull/129021) This partly closes a soundness hole that comes when casting a function item to function pointer
|
||||
- [Use equality instead of subtyping when resolving type dependent paths.](https://github.com/rust-lang/rust/pull/129073)
|
||||
- Linking on macOS now correctly includes Rust's default deployment target. Due to a linker bug, you might have to pass `MACOSX_DEPLOYMENT_TARGET` or fix your `#[link]` attributes to point to the correct frameworks. See <https://github.com/rust-lang/rust/pull/129369>.
|
||||
- [Rust will now correctly raise an error for `repr(Rust)` written on non-`struct`/`enum`/`union` items, since it previous did not have any effect.](https://github.com/rust-lang/rust/pull/129422)
|
||||
- The future incompatibility lint `deprecated_cfg_attr_crate_type_name` [has been made into a hard error](https://github.com/rust-lang/rust/pull/129670). It was used to deny usage of `#![crate_type]` and `#![crate_name]` attributes in `#![cfg_attr]`, which required a hack in the compiler to be able to change the used crate type and crate name after cfg expansion.
|
||||
Users can use `--crate-type` instead of `#![cfg_attr(..., crate_type = "...")]` and `--crate-name` instead of `#![cfg_attr(..., crate_name = "...")]` when running `rustc`/`cargo rustc` on the command line.
|
||||
Use of those two attributes outside of `#![cfg_attr]` continue to be fully supported.
|
||||
- Until now, paths into the sysroot were always prefixed with `/rustc/$hash` in diagnostics, codegen, backtrace, e.g.
|
||||
```
|
||||
thread 'main' panicked at 'hello world', map-panic.rs:2:50
|
||||
stack backtrace:
|
||||
0: std::panicking::begin_panic
|
||||
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:616:12
|
||||
1: map_panic::main::{{closure}}
|
||||
at ./map-panic.rs:2:50
|
||||
2: core::option::Option<T>::map
|
||||
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/option.rs:929:29
|
||||
3: map_panic::main
|
||||
at ./map-panic.rs:2:30
|
||||
4: core::ops::function::FnOnce::call_once
|
||||
at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:248:5
|
||||
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
|
||||
```
|
||||
[RFC 3127 said](https://rust-lang.github.io/rfcs/3127-trim-paths.html#changing-handling-of-sysroot-path-in-rustc)
|
||||
> We want to change this behaviour such that, when `rust-src` source files can be discovered, the virtual path is discarded and therefore the local path will be embedded, unless there is a `--remap-path-prefix` that causes this local path to be remapped in the usual way.
|
||||
|
||||
[#129687](https://github.com/rust-lang/rust/pull/129687) implements this behaviour, when `rust-src` is present at compile time, `rustc` replaces `/rustc/$hash` with a real path into the local `rust-src` component with best effort.
|
||||
To sanitize this, users must explicitly supply `--remap-path-prefix=<path to rust-src>=foo` or not have the `rust-src` component installed.
|
||||
- The allow-by-default `missing_docs` lint used to disable itself when invoked through `rustc --test`/`cargo test`, resulting in `#[expect(missing_docs)]` emitting false positives due to the expectation being wrongly unfulfilled. This behavior [has now been removed](https://github.com/rust-lang/rust/pull/130025), which allows `#[expect(missing_docs)]` to be fulfilled in all scenarios, but will also report new `missing_docs` diagnostics for publicly reachable `#[cfg(test)]` items, [integration test](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#integration-tests) crate-level documentation, and publicly reachable items in integration tests.
|
||||
- [The `armv8r-none-eabihf` target now uses the Armv8-R required set of floating-point features.](https://github.com/rust-lang/rust/pull/130295)
|
||||
- [Fix a soundness bug where rustc wouldn't detect unconstrained higher-ranked lifetimes in a `dyn Trait`'s associated types that occur due to supertraits.](https://github.com/rust-lang/rust/pull/130367)
|
||||
- [Update the minimum external LLVM version to 18.](https://github.com/rust-lang/rust/pull/130487)
|
||||
- [Remove `aarch64-fuchsia` and `x86_64-fuchsia` target aliases in favor of `aarch64-unknown-fuchsia` and `x86_64-unknown-fuchsia` respectively.](https://github.com/rust-lang/rust/pull/130657)
|
||||
- [The ABI-level exception class of a Rust panic is now encoded with native-endian bytes, so it is legible in hex dumps.](https://github.com/rust-lang/rust/pull/130897)
|
||||
- [Visual Studio 2013 is no longer supported for MSVC targets.](https://github.com/rust-lang/rust/pull/131070)
|
||||
- [The sysroot no longer contains the `std` dynamic library in its top-level `lib/` dir.](https://github.com/rust-lang/rust/pull/131188)
|
||||
|
||||
Version 1.82.0 (2024-10-17)
|
||||
==========================
|
||||
|
||||
@ -68,15 +299,15 @@ Stabilized APIs
|
||||
- [`impl Default for std::collections::vec_deque::Iter`](https://doc.rust-lang.org/nightly/std/collections/vec_deque/struct.Iter.html#impl-Default-for-Iter%3C'_,+T%3E)
|
||||
- [`impl Default for std::collections::vec_deque::IterMut`](https://doc.rust-lang.org/nightly/std/collections/vec_deque/struct.IterMut.html#impl-Default-for-IterMut%3C'_,+T%3E)
|
||||
- [`Rc<T>::new_uninit`](https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.new_uninit)
|
||||
- [`Rc<T>::assume_init`](https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.assume_init)
|
||||
- [`Rc<MaybeUninit<T>>::assume_init`](https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.assume_init)
|
||||
- [`Rc<[T]>::new_uninit_slice`](https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.new_uninit_slice)
|
||||
- [`Rc<[MaybeUninit<T>]>::assume_init`](https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.assume_init-1)
|
||||
- [`Arc<T>::new_uninit`](https://doc.rust-lang.org/nightly/std/sync/struct.Arc.html#method.new_uninit)
|
||||
- [`Arc<T>::assume_init`](https://doc.rust-lang.org/nightly/std/sync/struct.Arc.html#method.assume_init)
|
||||
- [`Arc<MaybeUninit<T>>::assume_init`](https://doc.rust-lang.org/nightly/std/sync/struct.Arc.html#method.assume_init)
|
||||
- [`Arc<[T]>::new_uninit_slice`](https://doc.rust-lang.org/nightly/std/sync/struct.Arc.html#method.new_uninit_slice)
|
||||
- [`Arc<[MaybeUninit<T>]>::assume_init`](https://doc.rust-lang.org/nightly/std/sync/struct.Arc.html#method.assume_init-1)
|
||||
- [`Box<T>::new_uninit`](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.new_uninit)
|
||||
- [`Box<T>::assume_init`](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.assume_init)
|
||||
- [`Box<MaybeUninit<T>>::assume_init`](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.assume_init)
|
||||
- [`Box<[T]>::new_uninit_slice`](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.new_uninit_slice)
|
||||
- [`Box<[MaybeUninit<T>]>::assume_init`](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.assume_init-1)
|
||||
- [`core::arch::x86_64::_bextri_u64`](https://doc.rust-lang.org/stable/core/arch/x86_64/fn._bextri_u64.html)
|
||||
@ -123,7 +354,6 @@ Stabilized APIs
|
||||
These APIs are now stable in const contexts:
|
||||
|
||||
- [`std::task::Waker::from_raw`](https://doc.rust-lang.org/nightly/std/task/struct.Waker.html#method.from_raw)
|
||||
- [`std::task::Waker::waker`](https://doc.rust-lang.org/nightly/std/task/struct.Waker.html#method.from_raw)
|
||||
- [`std::task::Context::from_waker`](https://doc.rust-lang.org/nightly/std/task/struct.Context.html#method.from_waker)
|
||||
- [`std::task::Context::waker`](https://doc.rust-lang.org/nightly/std/task/struct.Context.html#method.waker)
|
||||
- [`$integer::from_str_radix`](https://doc.rust-lang.org/nightly/std/primitive.u32.html#method.from_str_radix)
|
||||
|
||||
@ -30,5 +30,6 @@ features = ['unprefixed_malloc_on_supported_platforms']
|
||||
jemalloc = ['dep:jemalloc-sys']
|
||||
llvm = ['rustc_driver_impl/llvm']
|
||||
max_level_info = ['rustc_driver_impl/max_level_info']
|
||||
rustc_randomized_layouts = ['rustc_driver_impl/rustc_randomized_layouts']
|
||||
rustc_use_parallel_compiler = ['rustc_driver_impl/rustc_use_parallel_compiler']
|
||||
# tidy-alphabetical-end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -26,7 +26,7 @@ mod layout;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub use layout::LayoutCalculator;
|
||||
pub use layout::{LayoutCalculator, LayoutCalculatorError};
|
||||
|
||||
/// Requirements for a `StableHashingContext` to be used in this crate.
|
||||
/// This is a hack to allow using the `HashStable_Generic` derive macro
|
||||
@ -43,14 +43,17 @@ bitflags! {
|
||||
const IS_SIMD = 1 << 1;
|
||||
const IS_TRANSPARENT = 1 << 2;
|
||||
// Internal only for now. If true, don't reorder fields.
|
||||
// On its own it does not prevent ABI optimizations.
|
||||
const IS_LINEAR = 1 << 3;
|
||||
// If true, the type's layout can be randomized using
|
||||
// the seed stored in `ReprOptions.field_shuffle_seed`
|
||||
// If true, the type's crate has opted into layout randomization.
|
||||
// Other flags can still inhibit reordering and thus randomization.
|
||||
// The seed stored in `ReprOptions.field_shuffle_seed`.
|
||||
const RANDOMIZE_LAYOUT = 1 << 4;
|
||||
// Any of these flags being set prevent field reordering optimisation.
|
||||
const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits()
|
||||
const FIELD_ORDER_UNOPTIMIZABLE = ReprFlags::IS_C.bits()
|
||||
| ReprFlags::IS_SIMD.bits()
|
||||
| ReprFlags::IS_LINEAR.bits();
|
||||
const ABI_UNOPTIMIZABLE = ReprFlags::IS_C.bits() | ReprFlags::IS_SIMD.bits();
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,10 +142,14 @@ impl ReprOptions {
|
||||
self.c() || self.int.is_some()
|
||||
}
|
||||
|
||||
pub fn inhibit_newtype_abi_optimization(&self) -> bool {
|
||||
self.flags.intersects(ReprFlags::ABI_UNOPTIMIZABLE)
|
||||
}
|
||||
|
||||
/// Returns `true` if this `#[repr()]` guarantees a fixed field order,
|
||||
/// e.g. `repr(C)` or `repr(<int>)`.
|
||||
pub fn inhibit_struct_field_reordering(&self) -> bool {
|
||||
self.flags.intersects(ReprFlags::IS_UNOPTIMISABLE) || self.int.is_some()
|
||||
self.flags.intersects(ReprFlags::FIELD_ORDER_UNOPTIMIZABLE) || self.int.is_some()
|
||||
}
|
||||
|
||||
/// Returns `true` if this type is valid for reordering and `-Z randomize-layout`
|
||||
@ -330,23 +337,21 @@ impl TargetDataLayout {
|
||||
Ok(dl)
|
||||
}
|
||||
|
||||
/// Returns exclusive upper bound on object size.
|
||||
/// Returns **exclusive** upper bound on object size in bytes.
|
||||
///
|
||||
/// The theoretical maximum object size is defined as the maximum positive `isize` value.
|
||||
/// This ensures that the `offset` semantics remain well-defined by allowing it to correctly
|
||||
/// index every address within an object along with one byte past the end, along with allowing
|
||||
/// `isize` to store the difference between any two pointers into an object.
|
||||
///
|
||||
/// The upper bound on 64-bit currently needs to be lower because LLVM uses a 64-bit integer
|
||||
/// to represent object size in bits. It would need to be 1 << 61 to account for this, but is
|
||||
/// currently conservatively bounded to 1 << 47 as that is enough to cover the current usable
|
||||
/// address space on 64-bit ARMv8 and x86_64.
|
||||
/// LLVM uses a 64-bit integer to represent object size in *bits*, but we care only for bytes,
|
||||
/// so we adopt such a more-constrained size bound due to its technical limitations.
|
||||
#[inline]
|
||||
pub fn obj_size_bound(&self) -> u64 {
|
||||
match self.pointer_size.bits() {
|
||||
16 => 1 << 15,
|
||||
32 => 1 << 31,
|
||||
64 => 1 << 47,
|
||||
64 => 1 << 61,
|
||||
bits => panic!("obj_size_bound: unknown pointer bit size {bits}"),
|
||||
}
|
||||
}
|
||||
@ -386,6 +391,14 @@ impl HasDataLayout for TargetDataLayout {
|
||||
}
|
||||
}
|
||||
|
||||
// used by rust-analyzer
|
||||
impl HasDataLayout for &TargetDataLayout {
|
||||
#[inline]
|
||||
fn data_layout(&self) -> &TargetDataLayout {
|
||||
(**self).data_layout()
|
||||
}
|
||||
}
|
||||
|
||||
/// Endianness of the target, which must match cfg(target-endian).
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Endian {
|
||||
@ -774,6 +787,14 @@ impl Align {
|
||||
}
|
||||
|
||||
/// A pair of alignments, ABI-mandated and preferred.
|
||||
///
|
||||
/// The "preferred" alignment is an LLVM concept that is virtually meaningless to Rust code:
|
||||
/// it is not exposed semantically to programmers nor can they meaningfully affect it.
|
||||
/// The only concern for us is that preferred alignment must not be less than the mandated alignment
|
||||
/// and thus in practice the two values are almost always identical.
|
||||
///
|
||||
/// An example of a rare thing actually affected by preferred alignment is aligning of statics.
|
||||
/// It is of effectively no consequence for layout in structs and on the stack.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
|
||||
pub struct AbiAndPrefAlign {
|
||||
@ -810,6 +831,28 @@ pub enum Integer {
|
||||
}
|
||||
|
||||
impl Integer {
|
||||
pub fn int_ty_str(self) -> &'static str {
|
||||
use Integer::*;
|
||||
match self {
|
||||
I8 => "i8",
|
||||
I16 => "i16",
|
||||
I32 => "i32",
|
||||
I64 => "i64",
|
||||
I128 => "i128",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn uint_ty_str(self) -> &'static str {
|
||||
use Integer::*;
|
||||
match self {
|
||||
I8 => "u8",
|
||||
I16 => "u16",
|
||||
I32 => "u32",
|
||||
I64 => "u64",
|
||||
I128 => "u128",
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn size(self) -> Size {
|
||||
use Integer::*;
|
||||
@ -1095,13 +1138,10 @@ impl Scalar {
|
||||
#[inline]
|
||||
pub fn is_bool(&self) -> bool {
|
||||
use Integer::*;
|
||||
matches!(
|
||||
self,
|
||||
Scalar::Initialized {
|
||||
value: Primitive::Int(I8, false),
|
||||
valid_range: WrappingRange { start: 0, end: 1 }
|
||||
}
|
||||
)
|
||||
matches!(self, Scalar::Initialized {
|
||||
value: Primitive::Int(I8, false),
|
||||
valid_range: WrappingRange { start: 0, end: 1 }
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the primitive representation of this type, ignoring the valid range and whether the
|
||||
|
||||
@ -614,34 +614,34 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
||||
|
||||
pub trait ArenaAllocatable<'tcx, C = rustc_arena::IsNotCopy>: Sized {
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self;
|
||||
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self;
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn allocate_from_iter<'a>(
|
||||
arena: &'a Arena<'tcx>,
|
||||
fn allocate_from_iter(
|
||||
arena: &'tcx Arena<'tcx>,
|
||||
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
||||
) -> &'a mut [Self];
|
||||
) -> &'tcx mut [Self];
|
||||
}
|
||||
|
||||
// Any type that impls `Copy` can be arena-allocated in the `DroplessArena`.
|
||||
impl<'tcx, T: Copy> ArenaAllocatable<'tcx, rustc_arena::IsCopy> for T {
|
||||
#[inline]
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self {
|
||||
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self {
|
||||
arena.dropless.alloc(self)
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn allocate_from_iter<'a>(
|
||||
arena: &'a Arena<'tcx>,
|
||||
fn allocate_from_iter(
|
||||
arena: &'tcx Arena<'tcx>,
|
||||
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
||||
) -> &'a mut [Self] {
|
||||
) -> &'tcx mut [Self] {
|
||||
arena.dropless.alloc_from_iter(iter)
|
||||
}
|
||||
}
|
||||
$(
|
||||
impl<'tcx> ArenaAllocatable<'tcx, rustc_arena::IsNotCopy> for $ty {
|
||||
#[inline]
|
||||
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self {
|
||||
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self {
|
||||
if !::std::mem::needs_drop::<Self>() {
|
||||
arena.dropless.alloc(self)
|
||||
} else {
|
||||
@ -651,10 +651,10 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn allocate_from_iter<'a>(
|
||||
arena: &'a Arena<'tcx>,
|
||||
fn allocate_from_iter(
|
||||
arena: &'tcx Arena<'tcx>,
|
||||
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
||||
) -> &'a mut [Self] {
|
||||
) -> &'tcx mut [Self] {
|
||||
if !::std::mem::needs_drop::<Self>() {
|
||||
arena.dropless.alloc_from_iter(iter)
|
||||
} else {
|
||||
@ -667,7 +667,7 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
||||
impl<'tcx> Arena<'tcx> {
|
||||
#[inline]
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
pub fn alloc<T: ArenaAllocatable<'tcx, C>, C>(&self, value: T) -> &mut T {
|
||||
pub fn alloc<T: ArenaAllocatable<'tcx, C>, C>(&'tcx self, value: T) -> &mut T {
|
||||
value.allocate_on(self)
|
||||
}
|
||||
|
||||
@ -691,7 +691,7 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
||||
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
pub fn alloc_from_iter<T: ArenaAllocatable<'tcx, C>, C>(
|
||||
&self,
|
||||
&'tcx self,
|
||||
iter: impl ::std::iter::IntoIterator<Item = T>,
|
||||
) -> &mut [T] {
|
||||
T::allocate_from_iter(self, iter)
|
||||
|
||||
@ -4,10 +4,9 @@ version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
# FIXME: bumping memchr to 2.7.1 causes linker errors in MSVC thin-lto
|
||||
# tidy-alphabetical-start
|
||||
bitflags = "2.4.1"
|
||||
memchr = "=2.5.0"
|
||||
memchr = "2.7.4"
|
||||
rustc_ast_ir = { path = "../rustc_ast_ir" }
|
||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||
rustc_index = { path = "../rustc_index" }
|
||||
|
||||
@ -21,19 +21,19 @@
|
||||
use std::borrow::Cow;
|
||||
use std::{cmp, fmt, mem};
|
||||
|
||||
pub use GenericArgs::*;
|
||||
pub use UnsafeSource::*;
|
||||
pub use rustc_ast_ir::{Movability, Mutability};
|
||||
use rustc_data_structures::packed::Pu128;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_span::source_map::{respan, Spanned};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
pub use rustc_span::AttrId;
|
||||
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
pub use GenericArgs::*;
|
||||
pub use UnsafeSource::*;
|
||||
use rustc_span::source_map::{Spanned, respan};
|
||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
pub use crate::format::*;
|
||||
use crate::ptr::P;
|
||||
@ -288,7 +288,7 @@ impl ParenthesizedArgs {
|
||||
}
|
||||
}
|
||||
|
||||
pub use crate::node_id::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID};
|
||||
pub use crate::node_id::{CRATE_NODE_ID, DUMMY_NODE_ID, NodeId};
|
||||
|
||||
/// Modifiers on a trait bound like `~const`, `?` and `!`.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)]
|
||||
@ -511,7 +511,7 @@ pub enum MetaItemKind {
|
||||
/// List meta item.
|
||||
///
|
||||
/// E.g., `#[derive(..)]`, where the field represents the `..`.
|
||||
List(ThinVec<NestedMetaItem>),
|
||||
List(ThinVec<MetaItemInner>),
|
||||
|
||||
/// Name value meta item.
|
||||
///
|
||||
@ -523,7 +523,7 @@ pub enum MetaItemKind {
|
||||
///
|
||||
/// E.g., each of `Clone`, `Copy` in `#[derive(Clone, Copy)]`.
|
||||
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
|
||||
pub enum NestedMetaItem {
|
||||
pub enum MetaItemInner {
|
||||
/// A full MetaItem, for recursive meta items.
|
||||
MetaItem(MetaItem),
|
||||
|
||||
@ -1187,15 +1187,8 @@ impl Expr {
|
||||
/// `min_const_generics` as more complex expressions are not supported.
|
||||
///
|
||||
/// Does not ensure that the path resolves to a const param, the caller should check this.
|
||||
pub fn is_potential_trivial_const_arg(&self) -> bool {
|
||||
let this = if let ExprKind::Block(block, None) = &self.kind
|
||||
&& let [stmt] = block.stmts.as_slice()
|
||||
&& let StmtKind::Expr(expr) = &stmt.kind
|
||||
{
|
||||
expr
|
||||
} else {
|
||||
self
|
||||
};
|
||||
pub fn is_potential_trivial_const_arg(&self, strip_identity_block: bool) -> bool {
|
||||
let this = if strip_identity_block { self.maybe_unwrap_block().1 } else { self };
|
||||
|
||||
if let ExprKind::Path(None, path) = &this.kind
|
||||
&& path.is_potential_trivial_const_arg()
|
||||
@ -1206,6 +1199,18 @@ impl Expr {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an expression with (when possible) *one* outter brace removed
|
||||
pub fn maybe_unwrap_block(&self) -> (bool, &Expr) {
|
||||
if let ExprKind::Block(block, None) = &self.kind
|
||||
&& let [stmt] = block.stmts.as_slice()
|
||||
&& let StmtKind::Expr(expr) = &stmt.kind
|
||||
{
|
||||
(true, expr)
|
||||
} else {
|
||||
(false, self)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_bound(&self) -> Option<GenericBound> {
|
||||
match &self.kind {
|
||||
ExprKind::Path(None, path) => Some(GenericBound::Trait(
|
||||
@ -1289,7 +1294,7 @@ impl Expr {
|
||||
ExprKind::Binary(op, ..) => ExprPrecedence::Binary(op.node),
|
||||
ExprKind::Unary(..) => ExprPrecedence::Unary,
|
||||
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) => ExprPrecedence::Lit,
|
||||
ExprKind::Type(..) | ExprKind::Cast(..) => ExprPrecedence::Cast,
|
||||
ExprKind::Cast(..) => ExprPrecedence::Cast,
|
||||
ExprKind::Let(..) => ExprPrecedence::Let,
|
||||
ExprKind::If(..) => ExprPrecedence::If,
|
||||
ExprKind::While(..) => ExprPrecedence::While,
|
||||
@ -1313,17 +1318,18 @@ impl Expr {
|
||||
ExprKind::Break(..) => ExprPrecedence::Break,
|
||||
ExprKind::Continue(..) => ExprPrecedence::Continue,
|
||||
ExprKind::Ret(..) => ExprPrecedence::Ret,
|
||||
ExprKind::InlineAsm(..) => ExprPrecedence::InlineAsm,
|
||||
ExprKind::OffsetOf(..) => ExprPrecedence::OffsetOf,
|
||||
ExprKind::MacCall(..) => ExprPrecedence::Mac,
|
||||
ExprKind::Struct(..) => ExprPrecedence::Struct,
|
||||
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
|
||||
ExprKind::Paren(..) => ExprPrecedence::Paren,
|
||||
ExprKind::Try(..) => ExprPrecedence::Try,
|
||||
ExprKind::Yield(..) => ExprPrecedence::Yield,
|
||||
ExprKind::Yeet(..) => ExprPrecedence::Yeet,
|
||||
ExprKind::FormatArgs(..) => ExprPrecedence::FormatArgs,
|
||||
ExprKind::Become(..) => ExprPrecedence::Become,
|
||||
ExprKind::InlineAsm(..)
|
||||
| ExprKind::Type(..)
|
||||
| ExprKind::OffsetOf(..)
|
||||
| ExprKind::FormatArgs(..)
|
||||
| ExprKind::MacCall(..) => ExprPrecedence::Mac,
|
||||
ExprKind::Err(_) | ExprKind::Dummy => ExprPrecedence::Err,
|
||||
}
|
||||
}
|
||||
@ -2161,10 +2167,6 @@ pub enum TyKind {
|
||||
Never,
|
||||
/// A tuple (`(A, B, C, D,...)`).
|
||||
Tup(ThinVec<P<Ty>>),
|
||||
/// An anonymous struct type i.e. `struct { foo: Type }`.
|
||||
AnonStruct(NodeId, ThinVec<FieldDef>),
|
||||
/// An anonymous union type i.e. `union { bar: Type }`.
|
||||
AnonUnion(NodeId, ThinVec<FieldDef>),
|
||||
/// A path (`module::module::...::Type`), optionally
|
||||
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
|
||||
///
|
||||
@ -2221,10 +2223,6 @@ impl TyKind {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_anon_adt(&self) -> bool {
|
||||
matches!(self, TyKind::AnonStruct(..) | TyKind::AnonUnion(..))
|
||||
}
|
||||
}
|
||||
|
||||
/// Syntax used to declare a trait object.
|
||||
@ -2272,7 +2270,7 @@ impl InlineAsmOptions {
|
||||
pub const COUNT: usize = Self::all().bits().count_ones() as usize;
|
||||
|
||||
pub const GLOBAL_OPTIONS: Self = Self::ATT_SYNTAX.union(Self::RAW);
|
||||
pub const NAKED_OPTIONS: Self = Self::ATT_SYNTAX.union(Self::RAW).union(Self::NORETURN);
|
||||
pub const NAKED_OPTIONS: Self = Self::ATT_SYNTAX.union(Self::RAW);
|
||||
|
||||
pub fn human_readable_names(&self) -> Vec<&'static str> {
|
||||
let mut options = vec![];
|
||||
@ -2418,11 +2416,48 @@ impl InlineAsmOperand {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Encodable, Decodable, Debug, HashStable_Generic)]
|
||||
pub enum AsmMacro {
|
||||
/// The `asm!` macro
|
||||
Asm,
|
||||
/// The `global_asm!` macro
|
||||
GlobalAsm,
|
||||
/// The `naked_asm!` macro
|
||||
NakedAsm,
|
||||
}
|
||||
|
||||
impl AsmMacro {
|
||||
pub const fn macro_name(self) -> &'static str {
|
||||
match self {
|
||||
AsmMacro::Asm => "asm",
|
||||
AsmMacro::GlobalAsm => "global_asm",
|
||||
AsmMacro::NakedAsm => "naked_asm",
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn is_supported_option(self, option: InlineAsmOptions) -> bool {
|
||||
match self {
|
||||
AsmMacro::Asm => true,
|
||||
AsmMacro::GlobalAsm => InlineAsmOptions::GLOBAL_OPTIONS.contains(option),
|
||||
AsmMacro::NakedAsm => InlineAsmOptions::NAKED_OPTIONS.contains(option),
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn diverges(self, options: InlineAsmOptions) -> bool {
|
||||
match self {
|
||||
AsmMacro::Asm => options.contains(InlineAsmOptions::NORETURN),
|
||||
AsmMacro::GlobalAsm => true,
|
||||
AsmMacro::NakedAsm => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Inline assembly.
|
||||
///
|
||||
/// E.g., `asm!("NOP");`.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct InlineAsm {
|
||||
pub asm_macro: AsmMacro,
|
||||
pub template: Vec<InlineAsmTemplatePiece>,
|
||||
pub template_strs: Box<[(Symbol, Option<Symbol>, Span)]>,
|
||||
pub operands: Vec<(InlineAsmOperand, Span)>,
|
||||
@ -2591,12 +2626,12 @@ impl CoroutineKind {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_async(self) -> bool {
|
||||
matches!(self, CoroutineKind::Async { .. })
|
||||
}
|
||||
|
||||
pub fn is_gen(self) -> bool {
|
||||
matches!(self, CoroutineKind::Gen { .. })
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
CoroutineKind::Async { .. } => "async",
|
||||
CoroutineKind::Gen { .. } => "gen",
|
||||
CoroutineKind::AsyncGen { .. } => "async gen",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn closure_id(self) -> NodeId {
|
||||
@ -3475,7 +3510,7 @@ impl From<ForeignItemKind> for ItemKind {
|
||||
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
|
||||
match foreign_item_kind {
|
||||
ForeignItemKind::Static(box static_foreign_item) => {
|
||||
ItemKind::Static(Box::new(static_foreign_item.into()))
|
||||
ItemKind::Static(Box::new(static_foreign_item))
|
||||
}
|
||||
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
|
||||
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
|
||||
@ -3489,9 +3524,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
|
||||
|
||||
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
|
||||
Ok(match item_kind {
|
||||
ItemKind::Static(box static_item) => {
|
||||
ForeignItemKind::Static(Box::new(static_item.into()))
|
||||
}
|
||||
ItemKind::Static(box static_item) => ForeignItemKind::Static(Box::new(static_item)),
|
||||
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
|
||||
ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind),
|
||||
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),
|
||||
|
||||
@ -153,7 +153,7 @@ impl HasTokens for StmtKind {
|
||||
StmtKind::Let(local) => local.tokens.as_ref(),
|
||||
StmtKind::Item(item) => item.tokens(),
|
||||
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens(),
|
||||
StmtKind::Empty => return None,
|
||||
StmtKind::Empty => None,
|
||||
StmtKind::MacCall(mac) => mac.tokens.as_ref(),
|
||||
}
|
||||
}
|
||||
@ -162,7 +162,7 @@ impl HasTokens for StmtKind {
|
||||
StmtKind::Let(local) => Some(&mut local.tokens),
|
||||
StmtKind::Item(item) => item.tokens_mut(),
|
||||
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens_mut(),
|
||||
StmtKind::Empty => return None,
|
||||
StmtKind::Empty => None,
|
||||
StmtKind::MacCall(mac) => Some(&mut mac.tokens),
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,15 +4,15 @@ use std::iter;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
use rustc_index::bit_set::GrowableBitSet;
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, Symbol, sym};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::ast::{
|
||||
AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute, DelimArgs,
|
||||
Expr, ExprKind, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem, NormalAttr, Path,
|
||||
PathSegment, Safety, DUMMY_NODE_ID,
|
||||
AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute, DUMMY_NODE_ID,
|
||||
DelimArgs, Expr, ExprKind, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit,
|
||||
NormalAttr, Path, PathSegment, Safety,
|
||||
};
|
||||
use crate::ptr::P;
|
||||
use crate::token::{self, CommentKind, Delimiter, Token};
|
||||
@ -136,7 +136,7 @@ impl Attribute {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn meta_item_list(&self) -> Option<ThinVec<NestedMetaItem>> {
|
||||
pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
|
||||
match &self.kind {
|
||||
AttrKind::Normal(normal) => normal.item.meta_item_list(),
|
||||
AttrKind::DocComment(..) => None,
|
||||
@ -223,7 +223,7 @@ impl AttrItem {
|
||||
self.args.span().map_or(self.path.span, |args_span| self.path.span.to(args_span))
|
||||
}
|
||||
|
||||
fn meta_item_list(&self) -> Option<ThinVec<NestedMetaItem>> {
|
||||
fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
|
||||
match &self.args {
|
||||
AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => {
|
||||
MetaItemKind::list_from_tokens(args.tokens.clone())
|
||||
@ -285,7 +285,7 @@ impl MetaItem {
|
||||
matches!(self.kind, MetaItemKind::Word)
|
||||
}
|
||||
|
||||
pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
|
||||
pub fn meta_item_list(&self) -> Option<&[MetaItemInner]> {
|
||||
match &self.kind {
|
||||
MetaItemKind::List(l) => Some(&**l),
|
||||
_ => None,
|
||||
@ -393,11 +393,11 @@ impl MetaItem {
|
||||
}
|
||||
|
||||
impl MetaItemKind {
|
||||
fn list_from_tokens(tokens: TokenStream) -> Option<ThinVec<NestedMetaItem>> {
|
||||
fn list_from_tokens(tokens: TokenStream) -> Option<ThinVec<MetaItemInner>> {
|
||||
let mut tokens = tokens.trees().peekable();
|
||||
let mut result = ThinVec::new();
|
||||
while tokens.peek().is_some() {
|
||||
let item = NestedMetaItem::from_tokens(&mut tokens)?;
|
||||
let item = MetaItemInner::from_tokens(&mut tokens)?;
|
||||
result.push(item);
|
||||
match tokens.next() {
|
||||
None | Some(TokenTree::Token(Token { kind: token::Comma, .. }, _)) => {}
|
||||
@ -460,11 +460,11 @@ impl MetaItemKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl NestedMetaItem {
|
||||
impl MetaItemInner {
|
||||
pub fn span(&self) -> Span {
|
||||
match self {
|
||||
NestedMetaItem::MetaItem(item) => item.span,
|
||||
NestedMetaItem::Lit(lit) => lit.span,
|
||||
MetaItemInner::MetaItem(item) => item.span,
|
||||
MetaItemInner::Lit(lit) => lit.span,
|
||||
}
|
||||
}
|
||||
|
||||
@ -488,7 +488,7 @@ impl NestedMetaItem {
|
||||
}
|
||||
|
||||
/// Gets a list of inner meta items from a list `MetaItem` type.
|
||||
pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
|
||||
pub fn meta_item_list(&self) -> Option<&[MetaItemInner]> {
|
||||
self.meta_item().and_then(|meta_item| meta_item.meta_item_list())
|
||||
}
|
||||
|
||||
@ -519,18 +519,28 @@ impl NestedMetaItem {
|
||||
self.meta_item().and_then(|meta_item| meta_item.value_str())
|
||||
}
|
||||
|
||||
/// Returns the `MetaItemLit` if `self` is a `NestedMetaItem::Literal`s.
|
||||
/// Returns the `MetaItemLit` if `self` is a `MetaItemInner::Literal`s.
|
||||
pub fn lit(&self) -> Option<&MetaItemLit> {
|
||||
match self {
|
||||
NestedMetaItem::Lit(lit) => Some(lit),
|
||||
MetaItemInner::Lit(lit) => Some(lit),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`.
|
||||
/// Returns the `MetaItem` if `self` is a `MetaItemInner::MetaItem` or if it's
|
||||
/// `MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(_), .. })`.
|
||||
pub fn meta_item_or_bool(&self) -> Option<&MetaItemInner> {
|
||||
match self {
|
||||
MetaItemInner::MetaItem(_item) => Some(self),
|
||||
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(_), .. }) => Some(self),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the `MetaItem` if `self` is a `MetaItemInner::MetaItem`.
|
||||
pub fn meta_item(&self) -> Option<&MetaItem> {
|
||||
match self {
|
||||
NestedMetaItem::MetaItem(item) => Some(item),
|
||||
MetaItemInner::MetaItem(item) => Some(item),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -540,22 +550,22 @@ impl NestedMetaItem {
|
||||
self.meta_item().is_some()
|
||||
}
|
||||
|
||||
fn from_tokens<'a, I>(tokens: &mut iter::Peekable<I>) -> Option<NestedMetaItem>
|
||||
fn from_tokens<'a, I>(tokens: &mut iter::Peekable<I>) -> Option<MetaItemInner>
|
||||
where
|
||||
I: Iterator<Item = &'a TokenTree>,
|
||||
{
|
||||
match tokens.peek() {
|
||||
Some(TokenTree::Token(token, _)) if let Some(lit) = MetaItemLit::from_token(token) => {
|
||||
tokens.next();
|
||||
return Some(NestedMetaItem::Lit(lit));
|
||||
return Some(MetaItemInner::Lit(lit));
|
||||
}
|
||||
Some(TokenTree::Delimited(.., Delimiter::Invisible, inner_tokens)) => {
|
||||
tokens.next();
|
||||
return NestedMetaItem::from_tokens(&mut inner_tokens.trees().peekable());
|
||||
return MetaItemInner::from_tokens(&mut inner_tokens.trees().peekable());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
MetaItem::from_tokens(tokens).map(NestedMetaItem::MetaItem)
|
||||
MetaItem::from_tokens(tokens).map(MetaItemInner::MetaItem)
|
||||
}
|
||||
}
|
||||
|
||||
@ -666,6 +676,6 @@ pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {
|
||||
find_by_name(attrs, name).is_some()
|
||||
}
|
||||
|
||||
pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
|
||||
pub fn list_contains_name(items: &[MetaItemInner], name: Symbol) -> bool {
|
||||
items.iter().any(|item| item.has_name(name))
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
use crate::{attr, Attribute};
|
||||
use crate::{Attribute, attr};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum EntryPointType {
|
||||
@ -45,18 +45,16 @@ pub fn entry_point_type(
|
||||
EntryPointType::Start
|
||||
} else if attr::contains_name(attrs, sym::rustc_main) {
|
||||
EntryPointType::RustcMainAttr
|
||||
} else {
|
||||
if let Some(name) = name
|
||||
&& name == sym::main
|
||||
{
|
||||
if at_root {
|
||||
// This is a top-level function so it can be `main`.
|
||||
EntryPointType::MainNamed
|
||||
} else {
|
||||
EntryPointType::OtherMain
|
||||
}
|
||||
} else if let Some(name) = name
|
||||
&& name == sym::main
|
||||
{
|
||||
if at_root {
|
||||
// This is a top-level function so it can be `main`.
|
||||
EntryPointType::MainNamed
|
||||
} else {
|
||||
EntryPointType::None
|
||||
EntryPointType::OtherMain
|
||||
}
|
||||
} else {
|
||||
EntryPointType::None
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::symbol::{Symbol, sym};
|
||||
|
||||
#[derive(Clone, Debug, Copy, Eq, PartialEq, HashStable_Generic)]
|
||||
pub enum AllocatorKind {
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_macros::{Decodable, Encodable};
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
|
||||
use crate::ptr::P;
|
||||
use crate::Expr;
|
||||
use crate::ptr::P;
|
||||
|
||||
// Definitions:
|
||||
//
|
||||
|
||||
@ -13,10 +13,10 @@ use std::panic;
|
||||
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
use smallvec::{smallvec, Array, SmallVec};
|
||||
use smallvec::{Array, SmallVec, smallvec};
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
use crate::ast::*;
|
||||
@ -83,7 +83,7 @@ pub trait MutVisitor: Sized {
|
||||
walk_crate(self, c)
|
||||
}
|
||||
|
||||
fn visit_meta_list_item(&mut self, list_item: &mut NestedMetaItem) {
|
||||
fn visit_meta_list_item(&mut self, list_item: &mut MetaItemInner) {
|
||||
walk_meta_list_item(self, list_item);
|
||||
}
|
||||
|
||||
@ -519,10 +519,6 @@ pub fn walk_ty<T: MutVisitor>(vis: &mut T, ty: &mut P<Ty>) {
|
||||
visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::Impl));
|
||||
}
|
||||
TyKind::MacCall(mac) => vis.visit_mac_call(mac),
|
||||
TyKind::AnonStruct(id, fields) | TyKind::AnonUnion(id, fields) => {
|
||||
vis.visit_id(id);
|
||||
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
|
||||
}
|
||||
}
|
||||
visit_lazy_tts(vis, tokens);
|
||||
vis.visit_span(span);
|
||||
@ -659,10 +655,10 @@ fn walk_macro_def<T: MutVisitor>(vis: &mut T, macro_def: &mut MacroDef) {
|
||||
visit_delim_args(vis, body);
|
||||
}
|
||||
|
||||
fn walk_meta_list_item<T: MutVisitor>(vis: &mut T, li: &mut NestedMetaItem) {
|
||||
fn walk_meta_list_item<T: MutVisitor>(vis: &mut T, li: &mut MetaItemInner) {
|
||||
match li {
|
||||
NestedMetaItem::MetaItem(mi) => vis.visit_meta_item(mi),
|
||||
NestedMetaItem::Lit(_lit) => {}
|
||||
MetaItemInner::MetaItem(mi) => vis.visit_meta_item(mi),
|
||||
MetaItemInner::Lit(_lit) => {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -752,7 +748,7 @@ fn visit_lazy_tts<T: MutVisitor>(vis: &mut T, lazy_tts: &mut Option<LazyAttrToke
|
||||
pub fn visit_token<T: MutVisitor>(vis: &mut T, t: &mut Token) {
|
||||
let Token { kind, span } = t;
|
||||
match kind {
|
||||
token::Ident(name, _ /*raw*/) | token::Lifetime(name) => {
|
||||
token::Ident(name, _is_raw) | token::Lifetime(name, _is_raw) => {
|
||||
let mut ident = Ident::new(*name, *span);
|
||||
vis.visit_ident(&mut ident);
|
||||
*name = ident.name;
|
||||
@ -762,7 +758,7 @@ pub fn visit_token<T: MutVisitor>(vis: &mut T, t: &mut Token) {
|
||||
token::NtIdent(ident, _is_raw) => {
|
||||
vis.visit_ident(ident);
|
||||
}
|
||||
token::NtLifetime(ident) => {
|
||||
token::NtLifetime(ident, _is_raw) => {
|
||||
vis.visit_ident(ident);
|
||||
}
|
||||
token::Interpolated(nt) => {
|
||||
@ -1388,6 +1384,7 @@ fn walk_anon_const<T: MutVisitor>(vis: &mut T, AnonConst { id, value }: &mut Ano
|
||||
fn walk_inline_asm<T: MutVisitor>(vis: &mut T, asm: &mut InlineAsm) {
|
||||
// FIXME: Visit spans inside all this currently ignored stuff.
|
||||
let InlineAsm {
|
||||
asm_macro: _,
|
||||
template: _,
|
||||
template_strs: _,
|
||||
operands,
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::symbol::{kw, sym};
|
||||
#[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
|
||||
#[allow(hidden_glob_reexports)]
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
|
||||
pub use BinOpToken::*;
|
||||
pub use LitKind::*;
|
||||
pub use Nonterminal::*;
|
||||
pub use NtExprKind::*;
|
||||
pub use NtPatKind::*;
|
||||
pub use TokenKind::*;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_span::edition::Edition;
|
||||
#[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
|
||||
#[allow(hidden_glob_reexports)]
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::symbol::{kw, sym};
|
||||
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
|
||||
|
||||
use crate::ast;
|
||||
use crate::ptr::P;
|
||||
@ -331,11 +331,11 @@ pub enum TokenKind {
|
||||
/// Do not forget about `NtLifetime` when you want to match on lifetime identifiers.
|
||||
/// It's recommended to use `Token::(lifetime,uninterpolate,uninterpolated_span)` to
|
||||
/// treat regular and interpolated lifetime identifiers in the same way.
|
||||
Lifetime(Symbol),
|
||||
Lifetime(Symbol, IdentIsRaw),
|
||||
/// This identifier (and its span) is the lifetime passed to the
|
||||
/// declarative macro. The span in the surrounding `Token` is the span of
|
||||
/// the `lifetime` metavariable in the macro's RHS.
|
||||
NtLifetime(Ident),
|
||||
NtLifetime(Ident, IdentIsRaw),
|
||||
|
||||
/// An embedded AST node, as produced by a macro. This only exists for
|
||||
/// historical reasons. We'd like to get rid of it, for multiple reasons.
|
||||
@ -385,35 +385,41 @@ impl TokenKind {
|
||||
Literal(Lit::new(kind, symbol, suffix))
|
||||
}
|
||||
|
||||
/// An approximation to proc-macro-style single-character operators used by rustc parser.
|
||||
/// If the operator token can be broken into two tokens, the first of which is single-character,
|
||||
/// then this function performs that operation, otherwise it returns `None`.
|
||||
pub fn break_two_token_op(&self) -> Option<(TokenKind, TokenKind)> {
|
||||
Some(match *self {
|
||||
Le => (Lt, Eq),
|
||||
EqEq => (Eq, Eq),
|
||||
Ne => (Not, Eq),
|
||||
Ge => (Gt, Eq),
|
||||
AndAnd => (BinOp(And), BinOp(And)),
|
||||
OrOr => (BinOp(Or), BinOp(Or)),
|
||||
BinOp(Shl) => (Lt, Lt),
|
||||
BinOp(Shr) => (Gt, Gt),
|
||||
BinOpEq(Plus) => (BinOp(Plus), Eq),
|
||||
BinOpEq(Minus) => (BinOp(Minus), Eq),
|
||||
BinOpEq(Star) => (BinOp(Star), Eq),
|
||||
BinOpEq(Slash) => (BinOp(Slash), Eq),
|
||||
BinOpEq(Percent) => (BinOp(Percent), Eq),
|
||||
BinOpEq(Caret) => (BinOp(Caret), Eq),
|
||||
BinOpEq(And) => (BinOp(And), Eq),
|
||||
BinOpEq(Or) => (BinOp(Or), Eq),
|
||||
BinOpEq(Shl) => (Lt, Le),
|
||||
BinOpEq(Shr) => (Gt, Ge),
|
||||
DotDot => (Dot, Dot),
|
||||
DotDotDot => (Dot, DotDot),
|
||||
PathSep => (Colon, Colon),
|
||||
RArrow => (BinOp(Minus), Gt),
|
||||
LArrow => (Lt, BinOp(Minus)),
|
||||
FatArrow => (Eq, Gt),
|
||||
/// An approximation to proc-macro-style single-character operators used by
|
||||
/// rustc parser. If the operator token can be broken into two tokens, the
|
||||
/// first of which has `n` (1 or 2) chars, then this function performs that
|
||||
/// operation, otherwise it returns `None`.
|
||||
pub fn break_two_token_op(&self, n: u32) -> Option<(TokenKind, TokenKind)> {
|
||||
assert!(n == 1 || n == 2);
|
||||
Some(match (self, n) {
|
||||
(Le, 1) => (Lt, Eq),
|
||||
(EqEq, 1) => (Eq, Eq),
|
||||
(Ne, 1) => (Not, Eq),
|
||||
(Ge, 1) => (Gt, Eq),
|
||||
(AndAnd, 1) => (BinOp(And), BinOp(And)),
|
||||
(OrOr, 1) => (BinOp(Or), BinOp(Or)),
|
||||
(BinOp(Shl), 1) => (Lt, Lt),
|
||||
(BinOp(Shr), 1) => (Gt, Gt),
|
||||
(BinOpEq(Plus), 1) => (BinOp(Plus), Eq),
|
||||
(BinOpEq(Minus), 1) => (BinOp(Minus), Eq),
|
||||
(BinOpEq(Star), 1) => (BinOp(Star), Eq),
|
||||
(BinOpEq(Slash), 1) => (BinOp(Slash), Eq),
|
||||
(BinOpEq(Percent), 1) => (BinOp(Percent), Eq),
|
||||
(BinOpEq(Caret), 1) => (BinOp(Caret), Eq),
|
||||
(BinOpEq(And), 1) => (BinOp(And), Eq),
|
||||
(BinOpEq(Or), 1) => (BinOp(Or), Eq),
|
||||
(BinOpEq(Shl), 1) => (Lt, Le), // `<` + `<=`
|
||||
(BinOpEq(Shl), 2) => (BinOp(Shl), Eq), // `<<` + `=`
|
||||
(BinOpEq(Shr), 1) => (Gt, Ge), // `>` + `>=`
|
||||
(BinOpEq(Shr), 2) => (BinOp(Shr), Eq), // `>>` + `=`
|
||||
(DotDot, 1) => (Dot, Dot),
|
||||
(DotDotDot, 1) => (Dot, DotDot), // `.` + `..`
|
||||
(DotDotDot, 2) => (DotDot, Dot), // `..` + `.`
|
||||
(DotDotEq, 2) => (DotDot, Eq),
|
||||
(PathSep, 1) => (Colon, Colon),
|
||||
(RArrow, 1) => (BinOp(Minus), Gt),
|
||||
(LArrow, 1) => (Lt, BinOp(Minus)),
|
||||
(FatArrow, 1) => (Eq, Gt),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@ -458,7 +464,7 @@ impl Token {
|
||||
/// if they keep spans or perform edition checks.
|
||||
pub fn uninterpolated_span(&self) -> Span {
|
||||
match self.kind {
|
||||
NtIdent(ident, _) | NtLifetime(ident) => ident.span,
|
||||
NtIdent(ident, _) | NtLifetime(ident, _) => ident.span,
|
||||
Interpolated(ref nt) => nt.use_span(),
|
||||
_ => self.span,
|
||||
}
|
||||
@ -661,7 +667,9 @@ impl Token {
|
||||
pub fn uninterpolate(&self) -> Cow<'_, Token> {
|
||||
match self.kind {
|
||||
NtIdent(ident, is_raw) => Cow::Owned(Token::new(Ident(ident.name, is_raw), ident.span)),
|
||||
NtLifetime(ident) => Cow::Owned(Token::new(Lifetime(ident.name), ident.span)),
|
||||
NtLifetime(ident, is_raw) => {
|
||||
Cow::Owned(Token::new(Lifetime(ident.name, is_raw), ident.span))
|
||||
}
|
||||
_ => Cow::Borrowed(self),
|
||||
}
|
||||
}
|
||||
@ -679,11 +687,11 @@ impl Token {
|
||||
|
||||
/// Returns a lifetime identifier if this token is a lifetime.
|
||||
#[inline]
|
||||
pub fn lifetime(&self) -> Option<Ident> {
|
||||
pub fn lifetime(&self) -> Option<(Ident, IdentIsRaw)> {
|
||||
// We avoid using `Token::uninterpolate` here because it's slow.
|
||||
match self.kind {
|
||||
Lifetime(name) => Some(Ident::new(name, self.span)),
|
||||
NtLifetime(ident) => Some(ident),
|
||||
Lifetime(name, is_raw) => Some((Ident::new(name, self.span), is_raw)),
|
||||
NtLifetime(ident, is_raw) => Some((ident, is_raw)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -865,7 +873,7 @@ impl Token {
|
||||
_ => return None,
|
||||
},
|
||||
SingleQuote => match joint.kind {
|
||||
Ident(name, IdentIsRaw::No) => Lifetime(Symbol::intern(&format!("'{name}"))),
|
||||
Ident(name, is_raw) => Lifetime(Symbol::intern(&format!("'{name}")), is_raw),
|
||||
_ => return None,
|
||||
},
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::{self, Lrc};
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
use rustc_span::{sym, Span, SpanDecoder, SpanEncoder, Symbol, DUMMY_SP};
|
||||
use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
|
||||
|
||||
use crate::ast::{AttrStyle, StmtKind};
|
||||
use crate::ast_traits::{HasAttrs, HasTokens};
|
||||
@ -482,11 +482,11 @@ impl TokenStream {
|
||||
token::NtIdent(ident, is_raw) => {
|
||||
TokenTree::Token(Token::new(token::Ident(ident.name, is_raw), ident.span), spacing)
|
||||
}
|
||||
token::NtLifetime(ident) => TokenTree::Delimited(
|
||||
token::NtLifetime(ident, is_raw) => TokenTree::Delimited(
|
||||
DelimSpan::from_single(token.span),
|
||||
DelimSpacing::new(Spacing::JointHidden, spacing),
|
||||
Delimiter::Invisible,
|
||||
TokenStream::token_alone(token::Lifetime(ident.name), ident.span),
|
||||
TokenStream::token_alone(token::Lifetime(ident.name, is_raw), ident.span),
|
||||
),
|
||||
token::Interpolated(ref nt) => TokenTree::Delimited(
|
||||
DelimSpan::from_single(token.span),
|
||||
|
||||
@ -287,12 +287,6 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
|
||||
| ast::TyKind::Pat(..)
|
||||
| ast::TyKind::Dummy
|
||||
| ast::TyKind::Err(..) => break None,
|
||||
|
||||
// These end in brace, but cannot occur in a let-else statement.
|
||||
// They are only parsed as fields of a data structure. For the
|
||||
// purpose of denying trailing braces in the expression of a
|
||||
// let-else, we can disregard these.
|
||||
ast::TyKind::AnonStruct(..) | ast::TyKind::AnonUnion(..) => break None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
use std::{ascii, fmt, str};
|
||||
|
||||
use rustc_lexer::unescape::{
|
||||
byte_from_char, unescape_byte, unescape_char, unescape_mixed, unescape_unicode, MixedUnit, Mode,
|
||||
MixedUnit, Mode, byte_from_char, unescape_byte, unescape_char, unescape_mixed, unescape_unicode,
|
||||
};
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Symbol, kw, sym};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::ast::{self, LitKind, MetaItemLit, StrStyle};
|
||||
|
||||
@ -265,10 +265,7 @@ pub enum ExprPrecedence {
|
||||
Field,
|
||||
Index,
|
||||
Try,
|
||||
InlineAsm,
|
||||
OffsetOf,
|
||||
Mac,
|
||||
FormatArgs,
|
||||
|
||||
Array,
|
||||
Repeat,
|
||||
@ -333,17 +330,14 @@ impl ExprPrecedence {
|
||||
| ExprPrecedence::ConstBlock
|
||||
| ExprPrecedence::Field
|
||||
| ExprPrecedence::ForLoop
|
||||
| ExprPrecedence::FormatArgs
|
||||
| ExprPrecedence::Gen
|
||||
| ExprPrecedence::If
|
||||
| ExprPrecedence::Index
|
||||
| ExprPrecedence::InlineAsm
|
||||
| ExprPrecedence::Lit
|
||||
| ExprPrecedence::Loop
|
||||
| ExprPrecedence::Mac
|
||||
| ExprPrecedence::Match
|
||||
| ExprPrecedence::MethodCall
|
||||
| ExprPrecedence::OffsetOf
|
||||
| ExprPrecedence::Paren
|
||||
| ExprPrecedence::Path
|
||||
| ExprPrecedence::PostfixMatch
|
||||
|
||||
@ -15,8 +15,8 @@
|
||||
|
||||
pub use rustc_ast_ir::visit::VisitorResult;
|
||||
pub use rustc_ast_ir::{try_visit, visit_opt, walk_list, walk_visitable_list};
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::Ident;
|
||||
|
||||
use crate::ast::*;
|
||||
use crate::ptr::P;
|
||||
@ -69,14 +69,14 @@ pub enum FnKind<'a> {
|
||||
Fn(FnCtxt, Ident, &'a FnSig, &'a Visibility, &'a Generics, Option<&'a Block>),
|
||||
|
||||
/// E.g., `|x, y| body`.
|
||||
Closure(&'a ClosureBinder, &'a FnDecl, &'a Expr),
|
||||
Closure(&'a ClosureBinder, &'a Option<CoroutineKind>, &'a FnDecl, &'a Expr),
|
||||
}
|
||||
|
||||
impl<'a> FnKind<'a> {
|
||||
pub fn header(&self) -> Option<&'a FnHeader> {
|
||||
match *self {
|
||||
FnKind::Fn(_, _, sig, _, _, _) => Some(&sig.header),
|
||||
FnKind::Closure(_, _, _) => None,
|
||||
FnKind::Closure(..) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ impl<'a> FnKind<'a> {
|
||||
pub fn decl(&self) -> &'a FnDecl {
|
||||
match self {
|
||||
FnKind::Fn(_, _, sig, _, _, _) => &sig.decl,
|
||||
FnKind::Closure(_, decl, _) => decl,
|
||||
FnKind::Closure(_, _, decl, _) => decl,
|
||||
}
|
||||
}
|
||||
|
||||
@ -535,9 +535,6 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) -> V::Result {
|
||||
TyKind::Err(_guar) => {}
|
||||
TyKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
|
||||
TyKind::Never | TyKind::CVarArgs => {}
|
||||
TyKind::AnonStruct(_id, ref fields) | TyKind::AnonUnion(_id, ref fields) => {
|
||||
walk_list!(visitor, visit_field_def, fields);
|
||||
}
|
||||
}
|
||||
V::Result::output()
|
||||
}
|
||||
@ -839,7 +836,7 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
|
||||
try_visit!(walk_fn_decl(visitor, decl));
|
||||
visit_opt!(visitor, visit_block, body);
|
||||
}
|
||||
FnKind::Closure(binder, decl, body) => {
|
||||
FnKind::Closure(binder, _coroutine_kind, decl, body) => {
|
||||
try_visit!(visitor.visit_closure_binder(binder));
|
||||
try_visit!(walk_fn_decl(visitor, decl));
|
||||
try_visit!(visitor.visit_expr(body));
|
||||
@ -976,6 +973,7 @@ pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonCo
|
||||
|
||||
pub fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) -> V::Result {
|
||||
let InlineAsm {
|
||||
asm_macro: _,
|
||||
template: _,
|
||||
template_strs: _,
|
||||
operands,
|
||||
@ -1107,7 +1105,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
|
||||
ExprKind::Closure(box Closure {
|
||||
binder,
|
||||
capture_clause,
|
||||
coroutine_kind: _,
|
||||
coroutine_kind,
|
||||
constness: _,
|
||||
movability: _,
|
||||
fn_decl,
|
||||
@ -1116,7 +1114,11 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
|
||||
fn_arg_span: _,
|
||||
}) => {
|
||||
try_visit!(visitor.visit_capture_by(capture_clause));
|
||||
try_visit!(visitor.visit_fn(FnKind::Closure(binder, fn_decl, body), *span, *id))
|
||||
try_visit!(visitor.visit_fn(
|
||||
FnKind::Closure(binder, coroutine_kind, fn_decl, body),
|
||||
*span,
|
||||
*id
|
||||
))
|
||||
}
|
||||
ExprKind::Block(block, opt_label) => {
|
||||
visit_opt!(visitor, visit_label, opt_label);
|
||||
|
||||
@ -8,9 +8,10 @@ use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::symbol::kw;
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_span::{Span, sym};
|
||||
use rustc_target::asm;
|
||||
|
||||
use super::LoweringContext;
|
||||
use super::errors::{
|
||||
AbiSpecifiedMultipleTimes, AttSyntaxOnlyX86, ClobberAbiNotSupported,
|
||||
InlineAsmUnsupportedTarget, InvalidAbiClobberAbi, InvalidAsmTemplateModifierConst,
|
||||
@ -18,10 +19,9 @@ use super::errors::{
|
||||
InvalidAsmTemplateModifierRegClassSub, InvalidAsmTemplateModifierSym, InvalidRegister,
|
||||
InvalidRegisterClass, RegisterClassOnlyClobber, RegisterConflict,
|
||||
};
|
||||
use super::LoweringContext;
|
||||
use crate::{
|
||||
fluent_generated as fluent, ImplTraitContext, ImplTraitPosition, ParamMode,
|
||||
ResolverAstLoweringExt,
|
||||
AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, ParamMode,
|
||||
ResolverAstLoweringExt, fluent_generated as fluent,
|
||||
};
|
||||
|
||||
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
@ -201,6 +201,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
&sym.qself,
|
||||
&sym.path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
@ -220,9 +221,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
let parent_def_id = self.current_def_id_parent;
|
||||
let node_id = self.next_node_id();
|
||||
// HACK(min_generic_const_args): see lower_anon_const
|
||||
if !self.tcx.features().const_arg_path
|
||||
|| !expr.is_potential_trivial_const_arg()
|
||||
{
|
||||
if !expr.is_potential_trivial_const_arg(true) {
|
||||
self.create_def(
|
||||
parent_def_id,
|
||||
node_id,
|
||||
@ -474,8 +473,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
);
|
||||
let line_spans =
|
||||
self.arena.alloc_from_iter(asm.line_spans.iter().map(|span| self.lower_span(*span)));
|
||||
let hir_asm =
|
||||
hir::InlineAsm { template, template_strs, operands, options: asm.options, line_spans };
|
||||
let hir_asm = hir::InlineAsm {
|
||||
asm_macro: asm.asm_macro,
|
||||
template,
|
||||
template_strs,
|
||||
operands,
|
||||
options: asm.options,
|
||||
line_spans,
|
||||
};
|
||||
self.arena.alloc(hir_asm)
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,13 +46,13 @@ use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{Asyncness, ResolverAstLowering};
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_target::spec::abi;
|
||||
use {rustc_ast as ast, rustc_hir as hir};
|
||||
|
||||
use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
|
||||
use crate::{ImplTraitPosition, ResolverAstLoweringExt};
|
||||
use crate::{AllowReturnTypeNotation, ImplTraitPosition, ResolverAstLoweringExt};
|
||||
|
||||
pub(crate) struct DelegationResults<'hir> {
|
||||
pub body_id: hir::BodyId,
|
||||
@ -72,7 +72,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
fn has_self(&self, def_id: DefId, span: Span) -> bool {
|
||||
if let Some(local_sig_id) = def_id.as_local() {
|
||||
// The value may be missing due to recursive delegation.
|
||||
// Error will be emmited later during HIR ty lowering.
|
||||
// Error will be emitted later during HIR ty lowering.
|
||||
self.resolver.delegation_fn_sigs.get(&local_sig_id).map_or(false, |sig| sig.has_self)
|
||||
} else {
|
||||
match self.tcx.def_kind(def_id) {
|
||||
@ -139,7 +139,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
fn param_count(&self, sig_id: DefId) -> (usize, bool /*c_variadic*/) {
|
||||
if let Some(local_sig_id) = sig_id.as_local() {
|
||||
// Map may be filled incorrectly due to recursive delegation.
|
||||
// Error will be emmited later during HIR ty lowering.
|
||||
// Error will be emitted later during HIR ty lowering.
|
||||
match self.resolver.delegation_fn_sigs.get(&local_sig_id) {
|
||||
Some(sig) => (sig.param_count, sig.c_variadic),
|
||||
None => (0, false),
|
||||
@ -340,6 +340,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
&delegation.qself,
|
||||
&delegation.path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
|
||||
@ -4,14 +4,14 @@ use rustc_ast::ptr::P as AstP;
|
||||
use rustc_ast::*;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::HirId;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_session::errors::report_lit_error;
|
||||
use rustc_span::source_map::{respan, Spanned};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::source_map::{Spanned, respan};
|
||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||
use rustc_span::{DUMMY_SP, DesugaringKind, Span};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use super::errors::{
|
||||
AsyncCoroutinesNotSupported, AwaitOnlyInAsyncFnAndBlocks, BaseExpressionDoubleDot,
|
||||
@ -23,7 +23,7 @@ use super::{
|
||||
GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode, ResolverAstLoweringExt,
|
||||
};
|
||||
use crate::errors::YieldInClosure;
|
||||
use crate::{fluent_generated, FnDeclKind, ImplTraitPosition};
|
||||
use crate::{AllowReturnTypeNotation, FnDeclKind, ImplTraitPosition, fluent_generated};
|
||||
|
||||
impl<'hir> LoweringContext<'_, 'hir> {
|
||||
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
|
||||
@ -281,6 +281,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
qself,
|
||||
path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
@ -328,6 +329,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
&se.qself,
|
||||
&se.path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
)),
|
||||
@ -387,7 +389,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
let node_id = self.next_node_id();
|
||||
|
||||
// HACK(min_generic_const_args): see lower_anon_const
|
||||
if !self.tcx.features().const_arg_path || !arg.is_potential_trivial_const_arg() {
|
||||
if !arg.is_potential_trivial_const_arg(true) {
|
||||
// Add a definition for the in-band const def.
|
||||
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
|
||||
}
|
||||
@ -723,18 +725,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
span,
|
||||
Some(self.allow_gen_future.clone()),
|
||||
);
|
||||
self.lower_attrs(
|
||||
inner_hir_id,
|
||||
&[Attribute {
|
||||
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(
|
||||
sym::track_caller,
|
||||
span,
|
||||
)))),
|
||||
id: self.tcx.sess.psess.attr_id_generator.mk_attr_id(),
|
||||
style: AttrStyle::Outer,
|
||||
span: unstable_span,
|
||||
}],
|
||||
);
|
||||
self.lower_attrs(inner_hir_id, &[Attribute {
|
||||
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(
|
||||
sym::track_caller,
|
||||
span,
|
||||
)))),
|
||||
id: self.tcx.sess.psess.attr_id_generator.mk_attr_id(),
|
||||
style: AttrStyle::Outer,
|
||||
span: unstable_span,
|
||||
}]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1291,6 +1290,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
qself,
|
||||
path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
@ -1311,6 +1311,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
qself,
|
||||
path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
@ -1336,6 +1337,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
&se.qself,
|
||||
&se.path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
@ -1837,7 +1839,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
Safety::Default,
|
||||
sym::allow,
|
||||
sym::unreachable_code,
|
||||
self.lower_span(span),
|
||||
try_span,
|
||||
);
|
||||
let attrs: AttrVec = thin_vec![attr];
|
||||
|
||||
|
||||
@ -6,8 +6,8 @@ use rustc_ast::*;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_hir as hir;
|
||||
use rustc_session::config::FmtDebug;
|
||||
use rustc_span::symbol::{kw, Ident};
|
||||
use rustc_span::{sym, Span, Symbol};
|
||||
use rustc_span::symbol::{Ident, kw};
|
||||
use rustc_span::{Span, Symbol, sym};
|
||||
|
||||
use super::LoweringContext;
|
||||
|
||||
@ -363,16 +363,13 @@ fn make_format_spec<'hir>(
|
||||
debug_hex,
|
||||
} = &placeholder.format_options;
|
||||
let fill = ctx.expr_char(sp, fill.unwrap_or(' '));
|
||||
let align = ctx.expr_lang_item_type_relative(
|
||||
sp,
|
||||
hir::LangItem::FormatAlignment,
|
||||
match alignment {
|
||||
let align =
|
||||
ctx.expr_lang_item_type_relative(sp, hir::LangItem::FormatAlignment, match alignment {
|
||||
Some(FormatAlignment::Left) => sym::Left,
|
||||
Some(FormatAlignment::Right) => sym::Right,
|
||||
Some(FormatAlignment::Center) => sym::Center,
|
||||
None => sym::Unknown,
|
||||
},
|
||||
);
|
||||
});
|
||||
// This needs to match `Flag` in library/core/src/fmt/rt.rs.
|
||||
let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32)
|
||||
| ((sign == Some(FormatSign::Minus)) as u32) << 1
|
||||
|
||||
@ -6,7 +6,7 @@ use rustc_hir::*;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
|
||||
@ -78,26 +78,24 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||
|
||||
// Make sure that the DepNode of some node coincides with the HirId
|
||||
// owner of that node.
|
||||
if cfg!(debug_assertions) {
|
||||
if hir_id.owner != self.owner {
|
||||
span_bug!(
|
||||
span,
|
||||
"inconsistent HirId at `{:?}` for `{:?}`: \
|
||||
if cfg!(debug_assertions) && hir_id.owner != self.owner {
|
||||
span_bug!(
|
||||
span,
|
||||
"inconsistent HirId at `{:?}` for `{:?}`: \
|
||||
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
|
||||
self.tcx.sess.source_map().span_to_diagnostic_string(span),
|
||||
node,
|
||||
self.tcx
|
||||
.definitions_untracked()
|
||||
.def_path(self.owner.def_id)
|
||||
.to_string_no_crate_verbose(),
|
||||
self.owner,
|
||||
self.tcx
|
||||
.definitions_untracked()
|
||||
.def_path(hir_id.owner.def_id)
|
||||
.to_string_no_crate_verbose(),
|
||||
hir_id.owner,
|
||||
)
|
||||
}
|
||||
self.tcx.sess.source_map().span_to_diagnostic_string(span),
|
||||
node,
|
||||
self.tcx
|
||||
.definitions_untracked()
|
||||
.def_path(self.owner.def_id)
|
||||
.to_string_no_crate_verbose(),
|
||||
self.owner,
|
||||
self.tcx
|
||||
.definitions_untracked()
|
||||
.def_path(hir_id.owner.def_id)
|
||||
.to_string_no_crate_verbose(),
|
||||
hir_id.owner,
|
||||
)
|
||||
}
|
||||
|
||||
self.nodes[hir_id.local_id] = ParentedNode { parent: self.parent_node, node };
|
||||
@ -228,6 +226,14 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_opaque_ty(&mut self, opaq: &'hir OpaqueTy<'hir>) {
|
||||
self.insert(opaq.span, opaq.hir_id, Node::OpaqueTy(opaq));
|
||||
|
||||
self.with_parent(opaq.hir_id, |this| {
|
||||
intravisit::walk_opaque_ty(this, opaq);
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_anon_const(&mut self, constant: &'hir AnonConst) {
|
||||
// FIXME: use real span?
|
||||
self.insert(DUMMY_SP, constant.hir_id, Node::AnonConst(constant));
|
||||
|
||||
@ -3,17 +3,17 @@ use rustc_ast::visit::AssocCtxt;
|
||||
use rustc_ast::*;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||
use rustc_hir::PredicateOrigin;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
|
||||
use rustc_span::edit_distance::find_best_match_for_name;
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::symbol::{Ident, kw, sym};
|
||||
use rustc_span::{DesugaringKind, Span, Symbol};
|
||||
use rustc_target::spec::abi;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use thin_vec::ThinVec;
|
||||
use tracing::instrument;
|
||||
|
||||
@ -281,16 +281,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
);
|
||||
this.arena.alloc(this.ty(span, hir::TyKind::Err(guar)))
|
||||
}
|
||||
Some(ty) => this.lower_ty(
|
||||
ty,
|
||||
ImplTraitContext::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::TyAlias {
|
||||
parent: this.local_def_id(id),
|
||||
in_assoc_ty: false,
|
||||
},
|
||||
fn_kind: None,
|
||||
Some(ty) => this.lower_ty(ty, ImplTraitContext::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::TyAlias {
|
||||
parent: this.local_def_id(id),
|
||||
in_assoc_ty: false,
|
||||
},
|
||||
),
|
||||
}),
|
||||
},
|
||||
);
|
||||
hir::ItemKind::TyAlias(ty, generics)
|
||||
@ -628,13 +624,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
.map_or(Const::No, |attr| Const::Yes(attr.span)),
|
||||
_ => Const::No,
|
||||
}
|
||||
} else if self.tcx.is_const_trait(def_id) {
|
||||
// FIXME(effects) span
|
||||
Const::Yes(self.tcx.def_ident_span(def_id).unwrap())
|
||||
} else {
|
||||
if self.tcx.is_const_trait(def_id) {
|
||||
// FIXME(effects) span
|
||||
Const::Yes(self.tcx.def_ident_span(def_id).unwrap())
|
||||
} else {
|
||||
Const::No
|
||||
}
|
||||
Const::No
|
||||
}
|
||||
} else {
|
||||
Const::No
|
||||
@ -983,16 +977,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
hir::ImplItemKind::Type(ty)
|
||||
}
|
||||
Some(ty) => {
|
||||
let ty = this.lower_ty(
|
||||
ty,
|
||||
ImplTraitContext::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::TyAlias {
|
||||
parent: this.local_def_id(i.id),
|
||||
in_assoc_ty: true,
|
||||
},
|
||||
fn_kind: None,
|
||||
let ty = this.lower_ty(ty, ImplTraitContext::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::TyAlias {
|
||||
parent: this.local_def_id(i.id),
|
||||
in_assoc_ty: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
hir::ImplItemKind::Type(ty)
|
||||
}
|
||||
},
|
||||
@ -1131,13 +1121,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
|
||||
pub(super) fn lower_const_body(&mut self, span: Span, expr: Option<&Expr>) -> hir::BodyId {
|
||||
self.lower_body(|this| {
|
||||
(
|
||||
&[],
|
||||
match expr {
|
||||
Some(expr) => this.lower_expr_mut(expr),
|
||||
None => this.expr_err(span, this.dcx().span_delayed_bug(span, "no block")),
|
||||
},
|
||||
)
|
||||
(&[], match expr {
|
||||
Some(expr) => this.lower_expr_mut(expr),
|
||||
None => this.expr_err(span, this.dcx().span_delayed_bug(span, "no block")),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -1517,10 +1504,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
for bound in &bound_pred.bounds {
|
||||
if !matches!(
|
||||
*bound,
|
||||
GenericBound::Trait(
|
||||
_,
|
||||
TraitBoundModifiers { polarity: BoundPolarity::Maybe(_), .. }
|
||||
)
|
||||
GenericBound::Trait(_, TraitBoundModifiers {
|
||||
polarity: BoundPolarity::Maybe(_),
|
||||
..
|
||||
})
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
@ -1621,16 +1608,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
self.children.push((anon_const_did, hir::MaybeOwner::NonOwner(const_id)));
|
||||
|
||||
let const_body = self.lower_body(|this| {
|
||||
(
|
||||
&[],
|
||||
hir::Expr {
|
||||
hir_id: const_expr_id,
|
||||
kind: hir::ExprKind::Lit(
|
||||
this.arena.alloc(hir::Lit { node: LitKind::Bool(true), span }),
|
||||
),
|
||||
span,
|
||||
},
|
||||
)
|
||||
(&[], hir::Expr {
|
||||
hir_id: const_expr_id,
|
||||
kind: hir::ExprKind::Lit(
|
||||
this.arena.alloc(hir::Lit { node: LitKind::Bool(true), span }),
|
||||
),
|
||||
span,
|
||||
})
|
||||
});
|
||||
|
||||
let default_ac = self.arena.alloc(hir::AnonConst {
|
||||
|
||||
@ -45,7 +45,6 @@ use std::collections::hash_map::Entry;
|
||||
use rustc_ast::node_id::NodeMap;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, *};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
@ -54,7 +53,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
|
||||
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
|
||||
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
|
||||
use rustc_hir::{
|
||||
self as hir, ConstArg, GenericArg, HirId, ItemLocalMap, MissingLifetimeKind, ParamName,
|
||||
TraitCandidate,
|
||||
@ -64,9 +63,9 @@ use rustc_macros::extension;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
|
||||
use rustc_session::parse::{add_feature_diagnostics, feature_err};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||
use rustc_span::{DUMMY_SP, DesugaringKind, Span};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use thin_vec::ThinVec;
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
@ -289,12 +288,7 @@ enum ImplTraitContext {
|
||||
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
|
||||
/// equivalent to a new opaque type like `type T = impl Debug; fn foo() -> T`.
|
||||
///
|
||||
OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin,
|
||||
/// Only used to change the lifetime capture rules, since
|
||||
/// RPITIT captures all in scope, RPIT does not.
|
||||
fn_kind: Option<FnDeclKind>,
|
||||
},
|
||||
OpaqueTy { origin: hir::OpaqueTyOrigin },
|
||||
/// `impl Trait` is unstably accepted in this position.
|
||||
FeatureGated(ImplTraitPosition, Symbol),
|
||||
/// `impl Trait` is not accepted in this position.
|
||||
@ -486,9 +480,23 @@ enum ParamMode {
|
||||
Optional,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
enum AllowReturnTypeNotation {
|
||||
/// Only in types, since RTN is denied later during HIR lowering.
|
||||
Yes,
|
||||
/// All other positions (path expr, method, use tree).
|
||||
No,
|
||||
}
|
||||
|
||||
enum GenericArgsMode {
|
||||
/// Allow paren sugar, don't allow RTN.
|
||||
ParenSugar,
|
||||
/// Allow RTN, don't allow paren sugar.
|
||||
ReturnTypeNotation,
|
||||
// Error if parenthesized generics or RTN are encountered.
|
||||
Err,
|
||||
/// Silence errors when lowering generics. Only used with `Res::Err`.
|
||||
Silence,
|
||||
}
|
||||
|
||||
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
@ -837,7 +845,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
|
||||
(hir::ParamName::Fresh, hir::LifetimeParamKind::Elided(kind))
|
||||
}
|
||||
LifetimeRes::Static | LifetimeRes::Error => return None,
|
||||
LifetimeRes::Static { .. } | LifetimeRes::Error => return None,
|
||||
res => panic!(
|
||||
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
|
||||
res, ident, ident.span
|
||||
@ -1227,7 +1235,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
}
|
||||
|
||||
let id = self.lower_node_id(t.id);
|
||||
let qpath = self.lower_qpath(t.id, qself, path, param_mode, itctx, None);
|
||||
let qpath = self.lower_qpath(
|
||||
t.id,
|
||||
qself,
|
||||
path,
|
||||
param_mode,
|
||||
AllowReturnTypeNotation::Yes,
|
||||
itctx,
|
||||
None,
|
||||
);
|
||||
self.ty_path(id, t.span, qpath)
|
||||
}
|
||||
|
||||
@ -1243,46 +1259,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
let kind = match &t.kind {
|
||||
TyKind::Infer => hir::TyKind::Infer,
|
||||
TyKind::Err(guar) => hir::TyKind::Err(*guar),
|
||||
// Lower the anonymous structs or unions in a nested lowering context.
|
||||
//
|
||||
// ```
|
||||
// struct Foo {
|
||||
// _: union {
|
||||
// // ^__________________ <-- within the nested lowering context,
|
||||
// /* fields */ // | we lower all fields defined into an
|
||||
// } // | owner node of struct or union item
|
||||
// // ^_____________________|
|
||||
// }
|
||||
// ```
|
||||
TyKind::AnonStruct(node_id, fields) | TyKind::AnonUnion(node_id, fields) => {
|
||||
// Here its `def_id` is created in `build_reduced_graph`.
|
||||
let def_id = self.local_def_id(*node_id);
|
||||
debug!(?def_id);
|
||||
let owner_id = hir::OwnerId { def_id };
|
||||
self.with_hir_id_owner(*node_id, |this| {
|
||||
let fields = this.arena.alloc_from_iter(
|
||||
fields.iter().enumerate().map(|f| this.lower_field_def(f)),
|
||||
);
|
||||
let span = t.span;
|
||||
let variant_data =
|
||||
hir::VariantData::Struct { fields, recovered: ast::Recovered::No };
|
||||
// FIXME: capture the generics from the outer adt.
|
||||
let generics = hir::Generics::empty();
|
||||
let kind = match t.kind {
|
||||
TyKind::AnonStruct(..) => hir::ItemKind::Struct(variant_data, generics),
|
||||
TyKind::AnonUnion(..) => hir::ItemKind::Union(variant_data, generics),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
hir::OwnerNode::Item(this.arena.alloc(hir::Item {
|
||||
ident: Ident::new(kw::Empty, span),
|
||||
owner_id,
|
||||
kind,
|
||||
span: this.lower_span(span),
|
||||
vis_span: this.lower_span(span.shrink_to_lo()),
|
||||
}))
|
||||
});
|
||||
hir::TyKind::AnonAdt(hir::ItemId { owner_id })
|
||||
}
|
||||
TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
|
||||
TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
|
||||
TyKind::Ref(region, mt) => {
|
||||
@ -1383,14 +1359,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
TyKind::ImplTrait(def_node_id, bounds) => {
|
||||
let span = t.span;
|
||||
match itctx {
|
||||
ImplTraitContext::OpaqueTy { origin, fn_kind } => self.lower_opaque_impl_trait(
|
||||
span,
|
||||
origin,
|
||||
*def_node_id,
|
||||
bounds,
|
||||
fn_kind,
|
||||
itctx,
|
||||
),
|
||||
ImplTraitContext::OpaqueTy { origin } => {
|
||||
self.lower_opaque_impl_trait(span, origin, *def_node_id, bounds, itctx)
|
||||
}
|
||||
ImplTraitContext::Universal => {
|
||||
if let Some(span) = bounds.iter().find_map(|bound| match *bound {
|
||||
ast::GenericBound::Use(_, span) => Some(span),
|
||||
@ -1399,24 +1370,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
self.tcx.dcx().emit_err(errors::NoPreciseCapturesOnApit { span });
|
||||
}
|
||||
|
||||
let span = t.span;
|
||||
|
||||
// HACK: pprust breaks strings with newlines when the type
|
||||
// gets too long. We don't want these to show up in compiler
|
||||
// output or built artifacts, so replace them here...
|
||||
// Perhaps we should instead format APITs more robustly.
|
||||
let ident = Ident::from_str_and_span(
|
||||
&pprust::ty_to_string(t).replace('\n', " "),
|
||||
span,
|
||||
);
|
||||
|
||||
self.create_def(
|
||||
self.current_hir_id_owner.def_id, // FIXME: should this use self.current_def_id_parent?
|
||||
*def_node_id,
|
||||
ident.name,
|
||||
DefKind::TyParam,
|
||||
span,
|
||||
);
|
||||
let def_id = self.local_def_id(*def_node_id);
|
||||
let name = self.tcx.item_name(def_id.to_def_id());
|
||||
let ident = Ident::new(name, span);
|
||||
let (param, bounds, path) = self.lower_universal_param_and_bounds(
|
||||
*def_node_id,
|
||||
span,
|
||||
@ -1507,7 +1463,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
origin: hir::OpaqueTyOrigin,
|
||||
opaque_ty_node_id: NodeId,
|
||||
bounds: &GenericBounds,
|
||||
fn_kind: Option<FnDeclKind>,
|
||||
itctx: ImplTraitContext,
|
||||
) -> hir::TyKind<'hir> {
|
||||
// Make sure we know that some funky desugaring has been going on here.
|
||||
@ -1549,11 +1504,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
.map(|(ident, id, _)| Lifetime { id, ident })
|
||||
.collect()
|
||||
}
|
||||
hir::OpaqueTyOrigin::FnReturn(..) => {
|
||||
if matches!(
|
||||
fn_kind.expect("expected RPITs to be lowered with a FnKind"),
|
||||
FnDeclKind::Impl | FnDeclKind::Trait
|
||||
) || self.tcx.features().lifetime_capture_rules_2024
|
||||
hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl, .. } => {
|
||||
if in_trait_or_impl.is_some()
|
||||
|| self.tcx.features().lifetime_capture_rules_2024
|
||||
|| span.at_least_rust_2024()
|
||||
{
|
||||
// return-position impl trait in trait was decided to capture all
|
||||
@ -1570,37 +1523,38 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
lifetime_collector::lifetimes_in_bounds(self.resolver, bounds)
|
||||
}
|
||||
}
|
||||
hir::OpaqueTyOrigin::AsyncFn(..) => {
|
||||
hir::OpaqueTyOrigin::AsyncFn { .. } => {
|
||||
unreachable!("should be using `lower_async_fn_ret_ty`")
|
||||
}
|
||||
}
|
||||
};
|
||||
debug!(?captured_lifetimes_to_duplicate);
|
||||
|
||||
match fn_kind {
|
||||
// Deny `use<>` on RPITIT in trait/trait-impl for now.
|
||||
Some(FnDeclKind::Trait | FnDeclKind::Impl) => {
|
||||
if let Some(span) = bounds.iter().find_map(|bound| match *bound {
|
||||
ast::GenericBound::Use(_, span) => Some(span),
|
||||
_ => None,
|
||||
}) {
|
||||
self.tcx.dcx().emit_err(errors::NoPreciseCapturesOnRpitit { span });
|
||||
// Feature gate for RPITIT + use<..>
|
||||
match origin {
|
||||
rustc_hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl: Some(_), .. } => {
|
||||
if !self.tcx.features().precise_capturing_in_traits
|
||||
&& let Some(span) = bounds.iter().find_map(|bound| match *bound {
|
||||
ast::GenericBound::Use(_, span) => Some(span),
|
||||
_ => None,
|
||||
})
|
||||
{
|
||||
let mut diag =
|
||||
self.tcx.dcx().create_err(errors::NoPreciseCapturesOnRpitit { span });
|
||||
add_feature_diagnostics(
|
||||
&mut diag,
|
||||
self.tcx.sess,
|
||||
sym::precise_capturing_in_traits,
|
||||
);
|
||||
diag.emit();
|
||||
}
|
||||
}
|
||||
None
|
||||
| Some(
|
||||
FnDeclKind::Fn
|
||||
| FnDeclKind::Inherent
|
||||
| FnDeclKind::ExternFn
|
||||
| FnDeclKind::Closure
|
||||
| FnDeclKind::Pointer,
|
||||
) => {}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.lower_opaque_inner(
|
||||
opaque_ty_node_id,
|
||||
origin,
|
||||
matches!(fn_kind, Some(FnDeclKind::Trait)),
|
||||
captured_lifetimes_to_duplicate,
|
||||
span,
|
||||
opaque_ty_span,
|
||||
@ -1612,20 +1566,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
&mut self,
|
||||
opaque_ty_node_id: NodeId,
|
||||
origin: hir::OpaqueTyOrigin,
|
||||
in_trait: bool,
|
||||
captured_lifetimes_to_duplicate: FxIndexSet<Lifetime>,
|
||||
span: Span,
|
||||
opaque_ty_span: Span,
|
||||
lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],
|
||||
) -> hir::TyKind<'hir> {
|
||||
let opaque_ty_def_id = self.create_def(
|
||||
self.current_hir_id_owner.def_id, // FIXME: should this use self.current_def_id_parent?
|
||||
opaque_ty_node_id,
|
||||
kw::Empty,
|
||||
DefKind::OpaqueTy,
|
||||
opaque_ty_span,
|
||||
);
|
||||
debug!(?opaque_ty_def_id);
|
||||
let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
|
||||
let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
|
||||
debug!(?opaque_ty_def_id, ?opaque_ty_hir_id);
|
||||
|
||||
// Map from captured (old) lifetime to synthetic (new) lifetime.
|
||||
// Used to resolve lifetimes in the bounds of the opaque.
|
||||
@ -1656,7 +1604,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
}
|
||||
|
||||
// Opaques do not capture `'static`
|
||||
LifetimeRes::Static | LifetimeRes::Error => {
|
||||
LifetimeRes::Static { .. } | LifetimeRes::Error => {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1698,7 +1646,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
self.with_hir_id_owner(opaque_ty_node_id, |this| {
|
||||
let opaque_ty_def = self.with_def_id_parent(opaque_ty_def_id, |this| {
|
||||
// Install the remapping from old to new (if any). This makes sure that
|
||||
// any lifetimes that would have resolved to the def-id of captured
|
||||
// lifetimes are remapped to the new *synthetic* lifetimes of the opaque.
|
||||
@ -1736,7 +1684,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
|
||||
let lifetime_mapping = self.arena.alloc_slice(&synthesized_lifetime_args);
|
||||
|
||||
let opaque_ty_item = hir::OpaqueTy {
|
||||
trace!("registering opaque type with id {:#?}", opaque_ty_def_id);
|
||||
let opaque_ty_def = hir::OpaqueTy {
|
||||
hir_id: opaque_ty_hir_id,
|
||||
def_id: opaque_ty_def_id,
|
||||
generics: this.arena.alloc(hir::Generics {
|
||||
params: generic_params,
|
||||
predicates: &[],
|
||||
@ -1747,20 +1698,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
bounds,
|
||||
origin,
|
||||
lifetime_mapping,
|
||||
in_trait,
|
||||
};
|
||||
|
||||
// Generate an `type Foo = impl Trait;` declaration.
|
||||
trace!("registering opaque type with id {:#?}", opaque_ty_def_id);
|
||||
let opaque_ty_item = hir::Item {
|
||||
owner_id: hir::OwnerId { def_id: opaque_ty_def_id },
|
||||
ident: Ident::empty(),
|
||||
kind: hir::ItemKind::OpaqueTy(this.arena.alloc(opaque_ty_item)),
|
||||
vis_span: this.lower_span(span.shrink_to_lo()),
|
||||
span: this.lower_span(opaque_ty_span),
|
||||
};
|
||||
|
||||
hir::OwnerNode::Item(this.arena.alloc(opaque_ty_item))
|
||||
this.arena.alloc(opaque_ty_def)
|
||||
});
|
||||
|
||||
let generic_args = self.arena.alloc_from_iter(
|
||||
@ -1773,11 +1713,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
// Foo = impl Trait` is, internally, created as a child of the
|
||||
// async fn, so the *type parameters* are inherited. It's
|
||||
// only the lifetime parameters that we must supply.
|
||||
hir::TyKind::OpaqueDef(
|
||||
hir::ItemId { owner_id: hir::OwnerId { def_id: opaque_ty_def_id } },
|
||||
generic_args,
|
||||
in_trait,
|
||||
)
|
||||
hir::TyKind::OpaqueDef(opaque_ty_def, generic_args)
|
||||
}
|
||||
|
||||
fn lower_precise_capturing_args(
|
||||
@ -1864,12 +1800,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
None => match &decl.output {
|
||||
FnRetTy::Ty(ty) => {
|
||||
let itctx = match kind {
|
||||
FnDeclKind::Fn
|
||||
| FnDeclKind::Inherent
|
||||
| FnDeclKind::Trait
|
||||
| FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::FnReturn(self.local_def_id(fn_node_id)),
|
||||
fn_kind: Some(kind),
|
||||
FnDeclKind::Fn | FnDeclKind::Inherent => ImplTraitContext::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::FnReturn {
|
||||
parent: self.local_def_id(fn_node_id),
|
||||
in_trait_or_impl: None,
|
||||
},
|
||||
},
|
||||
FnDeclKind::Trait => ImplTraitContext::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::FnReturn {
|
||||
parent: self.local_def_id(fn_node_id),
|
||||
in_trait_or_impl: Some(hir::RpitContext::Trait),
|
||||
},
|
||||
},
|
||||
FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::FnReturn {
|
||||
parent: self.local_def_id(fn_node_id),
|
||||
in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
|
||||
},
|
||||
},
|
||||
FnDeclKind::ExternFn => {
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
|
||||
@ -1951,10 +1898,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
.map(|(ident, id, _)| Lifetime { id, ident })
|
||||
.collect();
|
||||
|
||||
let in_trait_or_impl = match fn_kind {
|
||||
FnDeclKind::Trait => Some(hir::RpitContext::Trait),
|
||||
FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
|
||||
FnDeclKind::Fn | FnDeclKind::Inherent => None,
|
||||
FnDeclKind::ExternFn | FnDeclKind::Closure | FnDeclKind::Pointer => unreachable!(),
|
||||
};
|
||||
|
||||
let opaque_ty_ref = self.lower_opaque_inner(
|
||||
opaque_ty_node_id,
|
||||
hir::OpaqueTyOrigin::AsyncFn(fn_def_id),
|
||||
matches!(fn_kind, FnDeclKind::Trait),
|
||||
hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, in_trait_or_impl },
|
||||
captured_lifetimes,
|
||||
span,
|
||||
opaque_ty_span,
|
||||
@ -1964,8 +1917,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
coro,
|
||||
opaque_ty_span,
|
||||
ImplTraitContext::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
|
||||
fn_kind: Some(fn_kind),
|
||||
origin: hir::OpaqueTyOrigin::FnReturn {
|
||||
parent: fn_def_id,
|
||||
in_trait_or_impl,
|
||||
},
|
||||
},
|
||||
);
|
||||
arena_vec![this; bound]
|
||||
@ -2069,7 +2024,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
hir::LifetimeName::Param(param)
|
||||
}
|
||||
LifetimeRes::Infer => hir::LifetimeName::Infer,
|
||||
LifetimeRes::Static => hir::LifetimeName::Static,
|
||||
LifetimeRes::Static { .. } => hir::LifetimeName::Static,
|
||||
LifetimeRes::Error => hir::LifetimeName::Error,
|
||||
res => panic!(
|
||||
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
|
||||
@ -2225,6 +2180,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
&None,
|
||||
&p.path,
|
||||
ParamMode::Explicit,
|
||||
AllowReturnTypeNotation::No,
|
||||
itctx,
|
||||
Some(modifiers),
|
||||
) {
|
||||
@ -2357,12 +2313,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
span: Span,
|
||||
) -> &'hir hir::ConstArg<'hir> {
|
||||
let ct_kind = match res {
|
||||
Res::Def(DefKind::ConstParam, _) if self.tcx.features().const_arg_path => {
|
||||
Res::Def(DefKind::ConstParam, _) => {
|
||||
let qpath = self.lower_qpath(
|
||||
ty_id,
|
||||
&None,
|
||||
path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
@ -2432,8 +2389,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
|
||||
debug!("res={:?}", maybe_res);
|
||||
// FIXME(min_generic_const_args): for now we only lower params to ConstArgKind::Path
|
||||
if self.tcx.features().const_arg_path
|
||||
&& let Some(res) = maybe_res
|
||||
if let Some(res) = maybe_res
|
||||
&& let Res::Def(DefKind::ConstParam, _) = res
|
||||
&& let ExprKind::Path(qself, path) = &expr.kind
|
||||
{
|
||||
@ -2442,6 +2398,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
qself,
|
||||
path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
@ -2464,7 +2421,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
/// See [`hir::ConstArg`] for when to use this function vs
|
||||
/// [`Self::lower_anon_const_to_const_arg`].
|
||||
fn lower_anon_const_to_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
|
||||
if self.tcx.features().const_arg_path && c.value.is_potential_trivial_const_arg() {
|
||||
if c.value.is_potential_trivial_const_arg(true) {
|
||||
// HACK(min_generic_const_args): see DefCollector::visit_anon_const
|
||||
// Over there, we guess if this is a bare param and only create a def if
|
||||
// we think it's not. However we may can guess wrong (see there for example)
|
||||
|
||||
@ -4,8 +4,8 @@ use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_hir::def::{DefKind, LifetimeRes, Res};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::ResolverAstLowering;
|
||||
use rustc_span::symbol::{kw, Ident};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, kw};
|
||||
|
||||
use super::ResolverAstLoweringExt;
|
||||
|
||||
@ -27,7 +27,7 @@ impl<'ast> LifetimeCollectVisitor<'ast> {
|
||||
self.collected_lifetimes.insert(lifetime);
|
||||
}
|
||||
}
|
||||
LifetimeRes::Static | LifetimeRes::Error => {
|
||||
LifetimeRes::Static { .. } | LifetimeRes::Error => {
|
||||
self.collected_lifetimes.insert(lifetime);
|
||||
}
|
||||
LifetimeRes::Infer => {}
|
||||
|
||||
@ -3,15 +3,15 @@ use rustc_ast::*;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
|
||||
use super::errors::{
|
||||
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
|
||||
};
|
||||
use super::{ImplTraitContext, LoweringContext, ParamMode, ResolverAstLoweringExt};
|
||||
use crate::ImplTraitPosition;
|
||||
use crate::{AllowReturnTypeNotation, ImplTraitPosition};
|
||||
|
||||
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
pub(crate) fn lower_pat(&mut self, pattern: &Pat) -> &'hir hir::Pat<'hir> {
|
||||
@ -38,6 +38,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
qself,
|
||||
path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
@ -55,6 +56,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
qself,
|
||||
path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
@ -66,6 +68,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
qself,
|
||||
path,
|
||||
ParamMode::Optional,
|
||||
AllowReturnTypeNotation::No,
|
||||
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
|
||||
None,
|
||||
);
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
use rustc_ast::{self as ast, *};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::GenericArg;
|
||||
use rustc_hir::def::{DefKind, PartialRes, Res};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::GenericArg;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::{BytePos, DesugaringKind, Span, Symbol, DUMMY_SP};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use rustc_session::parse::add_feature_diagnostics;
|
||||
use rustc_span::symbol::{Ident, kw, sym};
|
||||
use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Span, Symbol};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use super::errors::{
|
||||
@ -15,10 +16,9 @@ use super::errors::{
|
||||
GenericTypeWithParentheses, UseAngleBrackets,
|
||||
};
|
||||
use super::{
|
||||
GenericArgsCtor, GenericArgsMode, ImplTraitContext, LifetimeRes, LoweringContext, ParamMode,
|
||||
ResolverAstLoweringExt,
|
||||
AllowReturnTypeNotation, GenericArgsCtor, GenericArgsMode, ImplTraitContext, ImplTraitPosition,
|
||||
LifetimeRes, LoweringContext, ParamMode, ResolverAstLoweringExt,
|
||||
};
|
||||
use crate::ImplTraitPosition;
|
||||
|
||||
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
@ -28,6 +28,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
qself: &Option<ptr::P<QSelf>>,
|
||||
p: &Path,
|
||||
param_mode: ParamMode,
|
||||
allow_return_type_notation: AllowReturnTypeNotation,
|
||||
itctx: ImplTraitContext,
|
||||
// modifiers of the impl/bound if this is a trait path
|
||||
modifiers: Option<ast::TraitBoundModifiers>,
|
||||
@ -103,8 +104,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
{
|
||||
GenericArgsMode::ParenSugar
|
||||
}
|
||||
Res::Def(DefKind::AssocFn, _) if i + 1 == proj_start => {
|
||||
match allow_return_type_notation {
|
||||
AllowReturnTypeNotation::Yes => GenericArgsMode::ReturnTypeNotation,
|
||||
AllowReturnTypeNotation::No => GenericArgsMode::Err,
|
||||
}
|
||||
}
|
||||
// Avoid duplicated errors.
|
||||
Res::Err => GenericArgsMode::ParenSugar,
|
||||
Res::Err => GenericArgsMode::Silence,
|
||||
// An error
|
||||
_ => GenericArgsMode::Err,
|
||||
};
|
||||
@ -164,11 +171,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
// 3. `<<std::vec::Vec<T>>::IntoIter>::Item`
|
||||
// * final path is `<<<std::vec::Vec<T>>::IntoIter>::Item>::clone`
|
||||
for (i, segment) in p.segments.iter().enumerate().skip(proj_start) {
|
||||
// If this is a type-dependent `T::method(..)`.
|
||||
let generic_args_mode = if i + 1 == p.segments.len()
|
||||
&& matches!(allow_return_type_notation, AllowReturnTypeNotation::Yes)
|
||||
{
|
||||
GenericArgsMode::ReturnTypeNotation
|
||||
} else {
|
||||
GenericArgsMode::Err
|
||||
};
|
||||
|
||||
let hir_segment = self.arena.alloc(self.lower_path_segment(
|
||||
p.span,
|
||||
segment,
|
||||
param_mode,
|
||||
GenericArgsMode::Err,
|
||||
generic_args_mode,
|
||||
itctx,
|
||||
None,
|
||||
));
|
||||
@ -238,11 +254,46 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
self.lower_angle_bracketed_parameter_data(data, param_mode, itctx)
|
||||
}
|
||||
GenericArgs::Parenthesized(data) => match generic_args_mode {
|
||||
GenericArgsMode::ParenSugar => self.lower_parenthesized_parameter_data(
|
||||
data,
|
||||
itctx,
|
||||
bound_modifier_allowed_features,
|
||||
),
|
||||
GenericArgsMode::ReturnTypeNotation => {
|
||||
let mut err = if !data.inputs.is_empty() {
|
||||
self.dcx().create_err(BadReturnTypeNotation::Inputs {
|
||||
span: data.inputs_span,
|
||||
})
|
||||
} else if let FnRetTy::Ty(ty) = &data.output {
|
||||
self.dcx().create_err(BadReturnTypeNotation::Output {
|
||||
span: data.inputs_span.shrink_to_hi().to(ty.span),
|
||||
})
|
||||
} else {
|
||||
self.dcx().create_err(BadReturnTypeNotation::NeedsDots {
|
||||
span: data.inputs_span,
|
||||
})
|
||||
};
|
||||
if !self.tcx.features().return_type_notation
|
||||
&& self.tcx.sess.is_nightly_build()
|
||||
{
|
||||
add_feature_diagnostics(
|
||||
&mut err,
|
||||
&self.tcx.sess,
|
||||
sym::return_type_notation,
|
||||
);
|
||||
}
|
||||
err.emit();
|
||||
(
|
||||
GenericArgsCtor {
|
||||
args: Default::default(),
|
||||
constraints: &[],
|
||||
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
|
||||
span: path_span,
|
||||
},
|
||||
false,
|
||||
)
|
||||
}
|
||||
GenericArgsMode::ParenSugar | GenericArgsMode::Silence => self
|
||||
.lower_parenthesized_parameter_data(
|
||||
data,
|
||||
itctx,
|
||||
bound_modifier_allowed_features,
|
||||
),
|
||||
GenericArgsMode::Err => {
|
||||
// Suggest replacing parentheses with angle brackets `Trait(params...)` to `Trait<params...>`
|
||||
let sub = if !data.inputs.is_empty() {
|
||||
@ -279,7 +330,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
}
|
||||
},
|
||||
GenericArgs::ParenthesizedElided(span) => {
|
||||
self.dcx().emit_err(BadReturnTypeNotation::Position { span: *span });
|
||||
match generic_args_mode {
|
||||
GenericArgsMode::ReturnTypeNotation | GenericArgsMode::Silence => {
|
||||
// Ok
|
||||
}
|
||||
GenericArgsMode::ParenSugar | GenericArgsMode::Err => {
|
||||
self.dcx().emit_err(BadReturnTypeNotation::Position { span: *span });
|
||||
}
|
||||
}
|
||||
(
|
||||
GenericArgsCtor {
|
||||
args: Default::default(),
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
ast_passes_anon_struct_or_union_not_allowed =
|
||||
anonymous {$struct_or_union}s are not allowed outside of unnamed struct or union fields
|
||||
.label = anonymous {$struct_or_union} declared here
|
||||
|
||||
ast_passes_assoc_const_without_body =
|
||||
associated constant in `impl` without body
|
||||
.suggestion = provide a definition for the constant
|
||||
@ -40,15 +36,15 @@ ast_passes_body_in_extern = incorrect `{$kind}` inside `extern` block
|
||||
|
||||
ast_passes_bound_in_context = bounds on `type`s in {$ctx} have no effect
|
||||
|
||||
ast_passes_const_and_async = functions cannot be both `const` and `async`
|
||||
.const = `const` because of this
|
||||
.async = `async` because of this
|
||||
.label = {""}
|
||||
|
||||
ast_passes_const_and_c_variadic = functions cannot be both `const` and C-variadic
|
||||
.const = `const` because of this
|
||||
.variadic = C-variadic because of this
|
||||
|
||||
ast_passes_const_and_coroutine = functions cannot be both `const` and `{$coroutine_kind}`
|
||||
.const = `const` because of this
|
||||
.coroutine = `{$coroutine_kind}` because of this
|
||||
.label = {""}
|
||||
|
||||
ast_passes_const_bound_trait_object = const trait bounds are not allowed in trait object types
|
||||
|
||||
ast_passes_const_without_body =
|
||||
@ -160,14 +156,6 @@ ast_passes_inherent_cannot_be = inherent impls cannot be {$annotation}
|
||||
.type = inherent impl for this type
|
||||
.only_trait = only trait implementations may be annotated with {$annotation}
|
||||
|
||||
ast_passes_invalid_unnamed_field =
|
||||
unnamed fields are not allowed outside of structs or unions
|
||||
.label = unnamed field declared here
|
||||
|
||||
ast_passes_invalid_unnamed_field_ty =
|
||||
unnamed fields can only have struct or union types
|
||||
.label = not a struct or union
|
||||
|
||||
ast_passes_item_invalid_safety = items outside of `unsafe extern {"{ }"}` cannot be declared with `safe` safety qualifier
|
||||
.suggestion = remove safe from this item
|
||||
|
||||
|
||||
@ -21,21 +21,21 @@ use std::ops::{Deref, DerefMut};
|
||||
|
||||
use itertools::{Either, Itertools};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::visit::{walk_list, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor};
|
||||
use rustc_ast::visit::{AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor, walk_list};
|
||||
use rustc_ast::*;
|
||||
use rustc_ast_pretty::pprust::{self, State};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_errors::DiagCtxtHandle;
|
||||
use rustc_feature::Features;
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_session::Session;
|
||||
use rustc_session::lint::builtin::{
|
||||
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, MISSING_UNSAFE_ON_EXTERN,
|
||||
PATTERNS_IN_FNS_WITHOUT_BODY,
|
||||
};
|
||||
use rustc_session::lint::{BuiltinLintDiag, LintBuffer};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, kw, sym};
|
||||
use rustc_target::spec::abi;
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
@ -63,7 +63,7 @@ impl TraitOrTraitImpl {
|
||||
}
|
||||
|
||||
struct AstValidator<'a> {
|
||||
session: &'a Session,
|
||||
sess: &'a Session,
|
||||
features: &'a Features,
|
||||
|
||||
/// The span of the `extern` in an `extern { ... }` block, if any.
|
||||
@ -244,9 +244,6 @@ impl<'a> AstValidator<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
TyKind::AnonStruct(_, ref fields) | TyKind::AnonUnion(_, ref fields) => {
|
||||
walk_list!(self, visit_struct_field_def, fields)
|
||||
}
|
||||
_ => visit::walk_ty(self, t),
|
||||
}
|
||||
}
|
||||
@ -255,7 +252,6 @@ impl<'a> AstValidator<'a> {
|
||||
if let Some(ident) = field.ident
|
||||
&& ident.name == kw::Underscore
|
||||
{
|
||||
self.check_unnamed_field_ty(&field.ty, ident.span);
|
||||
self.visit_vis(&field.vis);
|
||||
self.visit_ident(ident);
|
||||
self.visit_ty_common(&field.ty);
|
||||
@ -267,7 +263,7 @@ impl<'a> AstValidator<'a> {
|
||||
}
|
||||
|
||||
fn dcx(&self) -> DiagCtxtHandle<'a> {
|
||||
self.session.dcx()
|
||||
self.sess.dcx()
|
||||
}
|
||||
|
||||
fn visibility_not_permitted(&self, vis: &Visibility, note: errors::VisibilityNotPermittedNote) {
|
||||
@ -294,39 +290,6 @@ impl<'a> AstValidator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_unnamed_field_ty(&self, ty: &Ty, span: Span) {
|
||||
if matches!(
|
||||
&ty.kind,
|
||||
// We already checked for `kw::Underscore` before calling this function,
|
||||
// so skip the check
|
||||
TyKind::AnonStruct(..) | TyKind::AnonUnion(..)
|
||||
// If the anonymous field contains a Path as type, we can't determine
|
||||
// if the path is a valid struct or union, so skip the check
|
||||
| TyKind::Path(..)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
self.dcx().emit_err(errors::InvalidUnnamedFieldTy { span, ty_span: ty.span });
|
||||
}
|
||||
|
||||
fn deny_anon_struct_or_union(&self, ty: &Ty) {
|
||||
let struct_or_union = match &ty.kind {
|
||||
TyKind::AnonStruct(..) => "struct",
|
||||
TyKind::AnonUnion(..) => "union",
|
||||
_ => return,
|
||||
};
|
||||
self.dcx().emit_err(errors::AnonStructOrUnionNotAllowed { struct_or_union, span: ty.span });
|
||||
}
|
||||
|
||||
fn deny_unnamed_field(&self, field: &FieldDef) {
|
||||
if let Some(ident) = field.ident
|
||||
&& ident.name == kw::Underscore
|
||||
{
|
||||
self.dcx()
|
||||
.emit_err(errors::InvalidUnnamedField { span: field.span, ident_span: ident.span });
|
||||
}
|
||||
}
|
||||
|
||||
fn check_trait_fn_not_const(&self, constness: Const, parent: &TraitOrTraitImpl) {
|
||||
let Const::Yes(span) = constness else {
|
||||
return;
|
||||
@ -359,7 +322,7 @@ impl<'a> AstValidator<'a> {
|
||||
in_impl: matches!(parent, TraitOrTraitImpl::TraitImpl { .. }),
|
||||
const_context_label: parent_constness,
|
||||
remove_const_sugg: (
|
||||
self.session.source_map().span_extend_while_whitespace(span),
|
||||
self.sess.source_map().span_extend_while_whitespace(span),
|
||||
match parent_constness {
|
||||
Some(_) => rustc_errors::Applicability::MachineApplicable,
|
||||
None => rustc_errors::Applicability::MaybeIncorrect,
|
||||
@ -447,13 +410,13 @@ impl<'a> AstValidator<'a> {
|
||||
fn check_item_safety(&self, span: Span, safety: Safety) {
|
||||
match self.extern_mod_safety {
|
||||
Some(extern_safety) => {
|
||||
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_)) {
|
||||
if extern_safety == Safety::Default {
|
||||
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
|
||||
item_span: span,
|
||||
block: Some(self.current_extern_span().shrink_to_lo()),
|
||||
});
|
||||
}
|
||||
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_))
|
||||
&& extern_safety == Safety::Default
|
||||
{
|
||||
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
|
||||
item_span: span,
|
||||
block: Some(self.current_extern_span().shrink_to_lo()),
|
||||
});
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@ -472,7 +435,7 @@ impl<'a> AstValidator<'a> {
|
||||
|
||||
fn check_defaultness(&self, span: Span, defaultness: Defaultness) {
|
||||
if let Defaultness::Default(def_span) = defaultness {
|
||||
let span = self.session.source_map().guess_head_span(span);
|
||||
let span = self.sess.source_map().guess_head_span(span);
|
||||
self.dcx().emit_err(errors::ForbiddenDefault { span, def_span });
|
||||
}
|
||||
}
|
||||
@ -480,7 +443,7 @@ impl<'a> AstValidator<'a> {
|
||||
/// If `sp` ends with a semicolon, returns it as a `Span`
|
||||
/// Otherwise, returns `sp.shrink_to_hi()`
|
||||
fn ending_semi_or_hi(&self, sp: Span) -> Span {
|
||||
let source_map = self.session.source_map();
|
||||
let source_map = self.sess.source_map();
|
||||
let end = source_map.end_point(sp);
|
||||
|
||||
if source_map.span_to_snippet(end).is_ok_and(|s| s == ";") {
|
||||
@ -552,7 +515,7 @@ impl<'a> AstValidator<'a> {
|
||||
}
|
||||
|
||||
fn current_extern_span(&self) -> Span {
|
||||
self.session.source_map().guess_head_span(self.extern_mod.unwrap())
|
||||
self.sess.source_map().guess_head_span(self.extern_mod.unwrap())
|
||||
}
|
||||
|
||||
/// An `fn` in `extern { ... }` cannot have qualifiers, e.g. `async fn`.
|
||||
@ -648,7 +611,7 @@ impl<'a> AstValidator<'a> {
|
||||
if ident.name.as_str().is_ascii() {
|
||||
return;
|
||||
}
|
||||
let span = self.session.source_map().guess_head_span(item_span);
|
||||
let span = self.sess.source_map().guess_head_span(item_span);
|
||||
self.dcx().emit_err(errors::NoMangleAscii { span });
|
||||
}
|
||||
|
||||
@ -753,7 +716,7 @@ impl<'a> AstValidator<'a> {
|
||||
self.dcx().emit_err(errors::PatternFnPointer { span });
|
||||
});
|
||||
if let Extern::Implicit(_) = bfty.ext {
|
||||
let sig_span = self.session.source_map().next_point(ty.span.shrink_to_lo());
|
||||
let sig_span = self.sess.source_map().next_point(ty.span.shrink_to_lo());
|
||||
self.maybe_lint_missing_abi(sig_span, ty.id);
|
||||
}
|
||||
}
|
||||
@ -795,7 +758,7 @@ impl<'a> AstValidator<'a> {
|
||||
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
|
||||
// call site which do not have a macro backtrace. See #61963.
|
||||
if self
|
||||
.session
|
||||
.sess
|
||||
.source_map()
|
||||
.span_to_snippet(span)
|
||||
.is_ok_and(|snippet| !snippet.starts_with("#["))
|
||||
@ -885,20 +848,14 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara
|
||||
|
||||
impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||
fn visit_attribute(&mut self, attr: &Attribute) {
|
||||
validate_attr::check_attr(&self.session.psess, attr);
|
||||
validate_attr::check_attr(&self.sess.psess, attr);
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: &'a Ty) {
|
||||
self.visit_ty_common(ty);
|
||||
self.deny_anon_struct_or_union(ty);
|
||||
self.walk_ty(ty)
|
||||
}
|
||||
|
||||
fn visit_field_def(&mut self, field: &'a FieldDef) {
|
||||
self.deny_unnamed_field(field);
|
||||
visit::walk_field_def(self, field)
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, item: &'a Item) {
|
||||
if item.attrs.iter().any(|attr| attr.is_proc_macro_attr()) {
|
||||
self.has_proc_macro_decls = true;
|
||||
@ -1192,7 +1149,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||
} else if where_clauses.after.has_where_token {
|
||||
self.dcx().emit_err(errors::WhereClauseAfterTypeAlias {
|
||||
span: where_clauses.after.span,
|
||||
help: self.session.is_nightly_build(),
|
||||
help: self.sess.is_nightly_build(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1328,7 +1285,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||
(BoundKind::SuperTraits, BoundConstness::Never, BoundPolarity::Maybe(_))
|
||||
if !self.features.more_maybe_bounds =>
|
||||
{
|
||||
self.session
|
||||
self.sess
|
||||
.create_feature_err(
|
||||
errors::OptionalTraitSupertrait {
|
||||
span: trait_ref.span,
|
||||
@ -1341,7 +1298,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||
(BoundKind::TraitObject, BoundConstness::Never, BoundPolarity::Maybe(_))
|
||||
if !self.features.more_maybe_bounds =>
|
||||
{
|
||||
self.session
|
||||
self.sess
|
||||
.create_feature_err(
|
||||
errors::OptionalTraitObject { span: trait_ref.span },
|
||||
sym::more_maybe_bounds,
|
||||
@ -1418,21 +1375,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||
|
||||
// Functions cannot both be `const async` or `const gen`
|
||||
if let Some(&FnHeader {
|
||||
constness: Const::Yes(cspan),
|
||||
constness: Const::Yes(const_span),
|
||||
coroutine_kind: Some(coroutine_kind),
|
||||
..
|
||||
}) = fk.header()
|
||||
{
|
||||
let aspan = match coroutine_kind {
|
||||
CoroutineKind::Async { span: aspan, .. }
|
||||
| CoroutineKind::Gen { span: aspan, .. }
|
||||
| CoroutineKind::AsyncGen { span: aspan, .. } => aspan,
|
||||
};
|
||||
// FIXME(gen_blocks): Report a different error for `const gen`
|
||||
self.dcx().emit_err(errors::ConstAndAsync {
|
||||
spans: vec![cspan, aspan],
|
||||
cspan,
|
||||
aspan,
|
||||
self.dcx().emit_err(errors::ConstAndCoroutine {
|
||||
spans: vec![coroutine_kind.span(), const_span],
|
||||
const_span,
|
||||
coroutine_span: coroutine_kind.span(),
|
||||
coroutine_kind: coroutine_kind.as_str(),
|
||||
span,
|
||||
});
|
||||
}
|
||||
@ -1485,7 +1437,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||
|
||||
let disallowed = (!tilde_const_allowed).then(|| match fk {
|
||||
FnKind::Fn(_, ident, _, _, _, _) => TildeConstReason::Function { ident: ident.span },
|
||||
FnKind::Closure(_, _, _) => TildeConstReason::Closure,
|
||||
FnKind::Closure(..) => TildeConstReason::Closure,
|
||||
});
|
||||
self.with_tilde_const(disallowed, |this| visit::walk_fn(this, fk));
|
||||
}
|
||||
@ -1757,13 +1709,13 @@ fn deny_equality_constraints(
|
||||
}
|
||||
|
||||
pub fn check_crate(
|
||||
session: &Session,
|
||||
sess: &Session,
|
||||
features: &Features,
|
||||
krate: &Crate,
|
||||
lints: &mut LintBuffer,
|
||||
) -> bool {
|
||||
let mut validator = AstValidator {
|
||||
session,
|
||||
sess,
|
||||
features,
|
||||
extern_mod: None,
|
||||
outer_trait_or_trait_impl: None,
|
||||
|
||||
@ -657,16 +657,17 @@ pub(crate) enum TildeConstReason {
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_const_and_async)]
|
||||
pub(crate) struct ConstAndAsync {
|
||||
#[diag(ast_passes_const_and_coroutine)]
|
||||
pub(crate) struct ConstAndCoroutine {
|
||||
#[primary_span]
|
||||
pub spans: Vec<Span>,
|
||||
#[label(ast_passes_const)]
|
||||
pub cspan: Span,
|
||||
#[label(ast_passes_async)]
|
||||
pub aspan: Span,
|
||||
pub const_span: Span,
|
||||
#[label(ast_passes_coroutine)]
|
||||
pub coroutine_span: Span,
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub coroutine_kind: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
@ -813,33 +814,6 @@ pub(crate) struct NegativeBoundWithParentheticalNotation {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_invalid_unnamed_field_ty)]
|
||||
pub(crate) struct InvalidUnnamedFieldTy {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[label]
|
||||
pub ty_span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_invalid_unnamed_field)]
|
||||
pub(crate) struct InvalidUnnamedField {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[label]
|
||||
pub ident_span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_anon_struct_or_union_not_allowed)]
|
||||
pub(crate) struct AnonStructOrUnionNotAllowed {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub struct_or_union: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_match_arm_with_no_body)]
|
||||
pub(crate) struct MatchArmWithNoBody {
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
|
||||
use rustc_ast::{attr, token, NodeId, PatKind};
|
||||
use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP};
|
||||
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
|
||||
use rustc_ast::{NodeId, PatKind, attr, token};
|
||||
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features, GateIssue};
|
||||
use rustc_session::Session;
|
||||
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_target::spec::abi;
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
@ -75,22 +75,9 @@ struct PostExpansionVisitor<'a> {
|
||||
|
||||
impl<'a> PostExpansionVisitor<'a> {
|
||||
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
|
||||
fn check_abi(&self, abi: ast::StrLit, constness: ast::Const) {
|
||||
fn check_abi(&self, abi: ast::StrLit) {
|
||||
let ast::StrLit { symbol_unescaped, span, .. } = abi;
|
||||
|
||||
if let ast::Const::Yes(_) = constness {
|
||||
match symbol_unescaped {
|
||||
// Stable
|
||||
sym::Rust | sym::C => {}
|
||||
abi => gate!(
|
||||
&self,
|
||||
const_extern_fn,
|
||||
span,
|
||||
format!("`{}` as a `const fn` ABI is unstable", abi)
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
match abi::is_enabled(self.features, span, symbol_unescaped.as_str()) {
|
||||
Ok(()) => (),
|
||||
Err(abi::AbiDisabled::Unstable { feature, explain }) => {
|
||||
@ -110,9 +97,9 @@ impl<'a> PostExpansionVisitor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_extern(&self, ext: ast::Extern, constness: ast::Const) {
|
||||
fn check_extern(&self, ext: ast::Extern) {
|
||||
if let ast::Extern::Explicit(abi, _) = ext {
|
||||
self.check_abi(abi, constness);
|
||||
self.check_abi(abi);
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,9 +186,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
}
|
||||
// Check unstable flavors of the `#[doc]` attribute.
|
||||
if attr.has_name(sym::doc) {
|
||||
for nested_meta in attr.meta_item_list().unwrap_or_default() {
|
||||
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
|
||||
macro_rules! gate_doc { ($($s:literal { $($name:ident => $feature:ident)* })*) => {
|
||||
$($(if nested_meta.has_name(sym::$name) {
|
||||
$($(if meta_item_inner.has_name(sym::$name) {
|
||||
let msg = concat!("`#[doc(", stringify!($name), ")]` is ", $s);
|
||||
gate!(self, $feature, attr.span, msg);
|
||||
})*)*
|
||||
@ -239,7 +226,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
match &i.kind {
|
||||
ast::ItemKind::ForeignMod(foreign_module) => {
|
||||
if let Some(abi) = foreign_module.abi {
|
||||
self.check_abi(abi, ast::Const::No);
|
||||
self.check_abi(abi);
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,7 +328,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
match &ty.kind {
|
||||
ast::TyKind::BareFn(bare_fn_ty) => {
|
||||
// Function pointers cannot be `const`
|
||||
self.check_extern(bare_fn_ty.ext, ast::Const::No);
|
||||
self.check_extern(bare_fn_ty.ext);
|
||||
self.check_late_bound_lifetime_defs(&bare_fn_ty.generic_params);
|
||||
}
|
||||
ast::TyKind::Never => {
|
||||
@ -446,7 +433,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
|
||||
if let Some(header) = fn_kind.header() {
|
||||
// Stability of const fn methods are covered in `visit_assoc_item` below.
|
||||
self.check_extern(header.ext, header.constness);
|
||||
self.check_extern(header.ext);
|
||||
}
|
||||
|
||||
if let FnKind::Closure(ast::ClosureBinder::For { generic_params, .. }, ..) = fn_kind {
|
||||
@ -496,6 +483,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||
pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
|
||||
maybe_stage_features(sess, features, krate);
|
||||
check_incompatible_features(sess, features);
|
||||
check_new_solver_banned_features(sess, features);
|
||||
|
||||
let mut visitor = PostExpansionVisitor { sess, features };
|
||||
|
||||
let spans = sess.psess.gated_spans.spans.borrow();
|
||||
@ -552,7 +541,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
|
||||
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
|
||||
gate_all!(explicit_tail_calls, "`become` expression is experimental");
|
||||
gate_all!(generic_const_items, "generic const items are experimental");
|
||||
gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented");
|
||||
gate_all!(fn_delegation, "functions delegation is not yet fully implemented");
|
||||
gate_all!(postfix_match, "postfix match is experimental");
|
||||
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
|
||||
@ -675,3 +663,22 @@ fn check_incompatible_features(sess: &Session, features: &Features) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_new_solver_banned_features(sess: &Session, features: &Features) {
|
||||
if !sess.opts.unstable_opts.next_solver.is_some_and(|n| n.globally) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ban GCE with the new solver, because it does not implement GCE correctly.
|
||||
if let Some(&(_, gce_span, _)) = features
|
||||
.declared_lang_features
|
||||
.iter()
|
||||
.find(|&&(feat, _, _)| feat == sym::generic_const_exprs)
|
||||
{
|
||||
sess.dcx().emit_err(errors::IncompatibleFeatures {
|
||||
spans: vec![gce_span],
|
||||
f1: Symbol::intern("-Znext-solver=globally"),
|
||||
f2: sym::generic_const_exprs,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
|
||||
use rustc_ast::visit::*;
|
||||
use rustc_ast::*;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::Ident;
|
||||
|
||||
pub struct NodeCounter {
|
||||
pub count: usize,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::pp::{BeginToken, BreakToken, Breaks, IndentStyle, Printer, Token, SIZE_INFINITY};
|
||||
use crate::pp::{BeginToken, BreakToken, Breaks, IndentStyle, Printer, SIZE_INFINITY, Token};
|
||||
|
||||
impl Printer {
|
||||
/// "raw box"
|
||||
|
||||
@ -7,7 +7,7 @@ use std::borrow::Cow;
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::token::{Nonterminal, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::{TokenStream, TokenTree};
|
||||
pub use state::{print_crate, AnnNode, Comments, PpAnn, PrintState, State};
|
||||
pub use state::{AnnNode, Comments, PpAnn, PrintState, State, print_crate};
|
||||
|
||||
pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
|
||||
State::new().nonterminal_to_string(nt)
|
||||
@ -67,7 +67,7 @@ pub fn vis_to_string(v: &ast::Visibility) -> String {
|
||||
State::new().vis_to_string(v)
|
||||
}
|
||||
|
||||
pub fn meta_list_item_to_string(li: &ast::NestedMetaItem) -> String {
|
||||
pub fn meta_list_item_to_string(li: &ast::MetaItemInner) -> String {
|
||||
State::new().meta_list_item_to_string(li)
|
||||
}
|
||||
|
||||
|
||||
@ -11,19 +11,21 @@ use std::borrow::Cow;
|
||||
use ast::TraitBoundModifiers;
|
||||
use rustc_ast::attr::AttrIdGenerator;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, BinOpToken, CommentKind, Delimiter, Nonterminal, Token, TokenKind};
|
||||
use rustc_ast::token::{
|
||||
self, BinOpToken, CommentKind, Delimiter, IdentIsRaw, Nonterminal, Token, TokenKind,
|
||||
};
|
||||
use rustc_ast::tokenstream::{Spacing, TokenStream, TokenTree};
|
||||
use rustc_ast::util::classify;
|
||||
use rustc_ast::util::comments::{Comment, CommentStyle};
|
||||
use rustc_ast::{
|
||||
self as ast, attr, AttrArgs, AttrArgsEq, BindingMode, BlockCheckMode, ByRef, DelimArgs,
|
||||
GenericArg, GenericBound, InlineAsmOperand, InlineAsmOptions, InlineAsmRegOrRegClass,
|
||||
InlineAsmTemplatePiece, PatKind, RangeEnd, RangeSyntax, Safety, SelfKind, Term,
|
||||
self as ast, AttrArgs, AttrArgsEq, BindingMode, BlockCheckMode, ByRef, DelimArgs, GenericArg,
|
||||
GenericBound, InlineAsmOperand, InlineAsmOptions, InlineAsmRegOrRegClass,
|
||||
InlineAsmTemplatePiece, PatKind, RangeEnd, RangeSyntax, Safety, SelfKind, Term, attr,
|
||||
};
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::source_map::{SourceMap, Spanned};
|
||||
use rustc_span::symbol::{kw, sym, Ident, IdentPrinter, Symbol};
|
||||
use rustc_span::{BytePos, CharPos, FileName, Pos, Span, DUMMY_SP};
|
||||
use rustc_span::symbol::{Ident, IdentPrinter, Symbol, kw, sym};
|
||||
use rustc_span::{BytePos, CharPos, DUMMY_SP, FileName, Pos, Span};
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
use crate::pp::Breaks::{Consistent, Inconsistent};
|
||||
@ -290,9 +292,9 @@ pub fn print_crate<'a>(
|
||||
/// - #73345: `#[allow(unused)]` must be printed rather than `# [allow(unused)]`
|
||||
///
|
||||
fn space_between(tt1: &TokenTree, tt2: &TokenTree) -> bool {
|
||||
use token::*;
|
||||
use Delimiter::*;
|
||||
use TokenTree::{Delimited as Del, Token as Tok};
|
||||
use token::*;
|
||||
|
||||
fn is_punct(tt: &TokenTree) -> bool {
|
||||
matches!(tt, TokenTree::Token(tok, _) if tok.is_punct())
|
||||
@ -947,8 +949,13 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
token::NtIdent(ident, is_raw) => {
|
||||
IdentPrinter::for_ast_ident(ident, is_raw.into()).to_string().into()
|
||||
}
|
||||
token::Lifetime(name) => name.to_string().into(),
|
||||
token::NtLifetime(ident) => ident.name.to_string().into(),
|
||||
|
||||
token::Lifetime(name, IdentIsRaw::No)
|
||||
| token::NtLifetime(Ident { name, .. }, IdentIsRaw::No) => name.to_string().into(),
|
||||
token::Lifetime(name, IdentIsRaw::Yes)
|
||||
| token::NtLifetime(Ident { name, .. }, IdentIsRaw::Yes) => {
|
||||
format!("'r#{}", &name.as_str()[1..]).into()
|
||||
}
|
||||
|
||||
/* Other */
|
||||
token::DocComment(comment_kind, attr_style, data) => {
|
||||
@ -1167,14 +1174,6 @@ impl<'a> State<'a> {
|
||||
}
|
||||
self.pclose();
|
||||
}
|
||||
ast::TyKind::AnonStruct(_, fields) => {
|
||||
self.head("struct");
|
||||
self.print_record_struct_body(fields, ty.span);
|
||||
}
|
||||
ast::TyKind::AnonUnion(_, fields) => {
|
||||
self.head("union");
|
||||
self.print_record_struct_body(fields, ty.span);
|
||||
}
|
||||
ast::TyKind::Paren(typ) => {
|
||||
self.popen();
|
||||
self.print_type(typ);
|
||||
@ -1999,10 +1998,10 @@ impl<'a> State<'a> {
|
||||
self.print_attribute_inline(attr, false)
|
||||
}
|
||||
|
||||
fn print_meta_list_item(&mut self, item: &ast::NestedMetaItem) {
|
||||
fn print_meta_list_item(&mut self, item: &ast::MetaItemInner) {
|
||||
match item {
|
||||
ast::NestedMetaItem::MetaItem(mi) => self.print_meta_item(mi),
|
||||
ast::NestedMetaItem::Lit(lit) => self.print_meta_item_lit(lit),
|
||||
ast::MetaItemInner::MetaItem(mi) => self.print_meta_item(mi),
|
||||
ast::MetaItemInner::Lit(lit) => self.print_meta_item_lit(lit),
|
||||
}
|
||||
}
|
||||
|
||||
@ -2047,7 +2046,7 @@ impl<'a> State<'a> {
|
||||
Self::to_string(|s| s.print_path_segment(p, false))
|
||||
}
|
||||
|
||||
pub(crate) fn meta_list_item_to_string(&self, li: &ast::NestedMetaItem) -> String {
|
||||
pub(crate) fn meta_list_item_to_string(&self, li: &ast::MetaItemInner) -> String {
|
||||
Self::to_string(|s| s.print_meta_list_item(li))
|
||||
}
|
||||
|
||||
|
||||
@ -7,13 +7,13 @@ use rustc_ast::util::classify;
|
||||
use rustc_ast::util::literal::escape_byte_str_symbol;
|
||||
use rustc_ast::util::parser::{self, AssocOp, Fixity};
|
||||
use rustc_ast::{
|
||||
self as ast, token, BlockCheckMode, FormatAlignment, FormatArgPosition, FormatArgsPiece,
|
||||
FormatCount, FormatDebugHex, FormatSign, FormatTrait,
|
||||
self as ast, BlockCheckMode, FormatAlignment, FormatArgPosition, FormatArgsPiece, FormatCount,
|
||||
FormatDebugHex, FormatSign, FormatTrait, token,
|
||||
};
|
||||
|
||||
use crate::pp::Breaks::Inconsistent;
|
||||
use crate::pprust::state::fixup::FixupContext;
|
||||
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
|
||||
use crate::pprust::state::{AnnNode, INDENT_UNIT, PrintState, State};
|
||||
|
||||
impl<'a> State<'a> {
|
||||
fn print_else(&mut self, els: Option<&ast::Expr>) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use rustc_ast::util::{classify, parser};
|
||||
use rustc_ast::Expr;
|
||||
use rustc_ast::util::{classify, parser};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub(crate) struct FixupContext {
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
use ast::StaticItem;
|
||||
use itertools::{Itertools, Position};
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::ModKind;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_span::symbol::Ident;
|
||||
|
||||
use crate::pp::Breaks::Inconsistent;
|
||||
use crate::pprust::state::fixup::FixupContext;
|
||||
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
|
||||
use crate::pprust::state::{AnnNode, INDENT_UNIT, PrintState, State};
|
||||
|
||||
enum DelegationKind<'a> {
|
||||
Single,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use rustc_ast as ast;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{create_default_session_globals_then, DUMMY_SP};
|
||||
use rustc_span::{DUMMY_SP, create_default_session_globals_then};
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -107,6 +107,8 @@ attr_unknown_version_literal =
|
||||
attr_unstable_cfg_target_compact =
|
||||
compact `cfg(target(..))` is experimental and subject to change
|
||||
|
||||
attr_unsupported_literal_cfg_boolean =
|
||||
literal in `cfg` predicate value must be a boolean
|
||||
attr_unsupported_literal_cfg_string =
|
||||
literal in `cfg` predicate value must be a string
|
||||
attr_unsupported_literal_deprecated_kv_pair =
|
||||
|
||||
@ -4,21 +4,21 @@ use std::num::NonZero;
|
||||
|
||||
use rustc_abi::Align;
|
||||
use rustc_ast::{
|
||||
self as ast, attr, Attribute, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem,
|
||||
NodeId,
|
||||
self as ast, Attribute, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NodeId,
|
||||
attr,
|
||||
};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
|
||||
use rustc_feature::{Features, GatedCfg, find_gated_cfg, is_builtin_attr_name};
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_session::config::ExpectedValues;
|
||||
use rustc_session::lint::builtin::UNEXPECTED_CFGS;
|
||||
use rustc_session::lint::BuiltinLintDiag;
|
||||
use rustc_session::lint::builtin::UNEXPECTED_CFGS;
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_session::{RustcVersion, Session};
|
||||
use rustc_span::hygiene::Transparency;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::hygiene::Transparency;
|
||||
use rustc_span::symbol::{Symbol, kw, sym};
|
||||
|
||||
use crate::fluent_generated;
|
||||
use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause};
|
||||
@ -36,6 +36,7 @@ pub fn is_builtin_attr(attr: &Attribute) -> bool {
|
||||
pub(crate) enum UnsupportedLiteralReason {
|
||||
Generic,
|
||||
CfgString,
|
||||
CfgBoolean,
|
||||
DeprecatedString,
|
||||
DeprecatedKvPair,
|
||||
}
|
||||
@ -80,6 +81,10 @@ impl Stability {
|
||||
pub fn is_stable(&self) -> bool {
|
||||
self.level.is_stable()
|
||||
}
|
||||
|
||||
pub fn stable_since(&self) -> Option<StableSince> {
|
||||
self.level.stable_since()
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
|
||||
@ -153,7 +158,7 @@ pub enum StabilityLevel {
|
||||
}
|
||||
|
||||
/// Rust release in which a feature is stabilized.
|
||||
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
||||
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub enum StableSince {
|
||||
Version(RustcVersion),
|
||||
@ -170,6 +175,12 @@ impl StabilityLevel {
|
||||
pub fn is_stable(&self) -> bool {
|
||||
matches!(self, StabilityLevel::Stable { .. })
|
||||
}
|
||||
pub fn stable_since(&self) -> Option<StableSince> {
|
||||
match *self {
|
||||
StabilityLevel::Stable { since, .. } => Some(since),
|
||||
StabilityLevel::Unstable { .. } => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
||||
@ -523,7 +534,7 @@ pub struct Condition {
|
||||
|
||||
/// Tests if a cfg-pattern matches the cfg set
|
||||
pub fn cfg_matches(
|
||||
cfg: &ast::MetaItem,
|
||||
cfg: &ast::MetaItemInner,
|
||||
sess: &Session,
|
||||
lint_node_id: NodeId,
|
||||
features: Option<&Features>,
|
||||
@ -594,22 +605,53 @@ pub fn parse_version(s: Symbol) -> Option<RustcVersion> {
|
||||
/// Evaluate a cfg-like condition (with `any` and `all`), using `eval` to
|
||||
/// evaluate individual items.
|
||||
pub fn eval_condition(
|
||||
cfg: &ast::MetaItem,
|
||||
cfg: &ast::MetaItemInner,
|
||||
sess: &Session,
|
||||
features: Option<&Features>,
|
||||
eval: &mut impl FnMut(Condition) -> bool,
|
||||
) -> bool {
|
||||
let dcx = sess.dcx();
|
||||
|
||||
let cfg = match cfg {
|
||||
ast::MetaItemInner::MetaItem(meta_item) => meta_item,
|
||||
ast::MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
|
||||
if let Some(features) = features {
|
||||
// we can't use `try_gate_cfg` as symbols don't differentiate between `r#true`
|
||||
// and `true`, and we want to keep the former working without feature gate
|
||||
gate_cfg(
|
||||
&((
|
||||
if *b { kw::True } else { kw::False },
|
||||
sym::cfg_boolean_literals,
|
||||
|features: &Features| features.cfg_boolean_literals,
|
||||
)),
|
||||
cfg.span(),
|
||||
sess,
|
||||
features,
|
||||
);
|
||||
}
|
||||
return *b;
|
||||
}
|
||||
_ => {
|
||||
dcx.emit_err(session_diagnostics::UnsupportedLiteral {
|
||||
span: cfg.span(),
|
||||
reason: UnsupportedLiteralReason::CfgBoolean,
|
||||
is_bytestr: false,
|
||||
start_point_span: sess.source_map().start_point(cfg.span()),
|
||||
});
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
match &cfg.kind {
|
||||
ast::MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
|
||||
try_gate_cfg(sym::version, cfg.span, sess, features);
|
||||
let (min_version, span) = match &mis[..] {
|
||||
[NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
|
||||
[MetaItemInner::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
|
||||
(sym, span)
|
||||
}
|
||||
[
|
||||
NestedMetaItem::Lit(MetaItemLit { span, .. })
|
||||
| NestedMetaItem::MetaItem(MetaItem { span, .. }),
|
||||
MetaItemInner::Lit(MetaItemLit { span, .. })
|
||||
| MetaItemInner::MetaItem(MetaItem { span, .. }),
|
||||
] => {
|
||||
dcx.emit_err(session_diagnostics::ExpectedVersionLiteral { span: *span });
|
||||
return false;
|
||||
@ -635,7 +677,7 @@ pub fn eval_condition(
|
||||
}
|
||||
ast::MetaItemKind::List(mis) => {
|
||||
for mi in mis.iter() {
|
||||
if !mi.is_meta_item() {
|
||||
if mi.meta_item_or_bool().is_none() {
|
||||
dcx.emit_err(session_diagnostics::UnsupportedLiteral {
|
||||
span: mi.span(),
|
||||
reason: UnsupportedLiteralReason::Generic,
|
||||
@ -653,23 +695,19 @@ pub fn eval_condition(
|
||||
.iter()
|
||||
// We don't use any() here, because we want to evaluate all cfg condition
|
||||
// as eval_condition can (and does) extra checks
|
||||
.fold(false, |res, mi| {
|
||||
res | eval_condition(mi.meta_item().unwrap(), sess, features, eval)
|
||||
}),
|
||||
.fold(false, |res, mi| res | eval_condition(mi, sess, features, eval)),
|
||||
sym::all => mis
|
||||
.iter()
|
||||
// We don't use all() here, because we want to evaluate all cfg condition
|
||||
// as eval_condition can (and does) extra checks
|
||||
.fold(true, |res, mi| {
|
||||
res & eval_condition(mi.meta_item().unwrap(), sess, features, eval)
|
||||
}),
|
||||
.fold(true, |res, mi| res & eval_condition(mi, sess, features, eval)),
|
||||
sym::not => {
|
||||
let [mi] = mis.as_slice() else {
|
||||
dcx.emit_err(session_diagnostics::ExpectedOneCfgPattern { span: cfg.span });
|
||||
return false;
|
||||
};
|
||||
|
||||
!eval_condition(mi.meta_item().unwrap(), sess, features, eval)
|
||||
!eval_condition(mi, sess, features, eval)
|
||||
}
|
||||
sym::target => {
|
||||
if let Some(features) = features
|
||||
@ -690,7 +728,12 @@ pub fn eval_condition(
|
||||
seg.ident.name = Symbol::intern(&format!("target_{}", seg.ident.name));
|
||||
}
|
||||
|
||||
res & eval_condition(&mi, sess, features, eval)
|
||||
res & eval_condition(
|
||||
&ast::MetaItemInner::MetaItem(mi),
|
||||
sess,
|
||||
features,
|
||||
eval,
|
||||
)
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
@ -830,7 +873,7 @@ pub fn find_deprecation(
|
||||
|
||||
for meta in list {
|
||||
match meta {
|
||||
NestedMetaItem::MetaItem(mi) => match mi.name_or_empty() {
|
||||
MetaItemInner::MetaItem(mi) => match mi.name_or_empty() {
|
||||
sym::since => {
|
||||
if !get(mi, &mut since) {
|
||||
continue 'outer;
|
||||
@ -869,7 +912,7 @@ pub fn find_deprecation(
|
||||
continue 'outer;
|
||||
}
|
||||
},
|
||||
NestedMetaItem::Lit(lit) => {
|
||||
MetaItemInner::Lit(lit) => {
|
||||
sess.dcx().emit_err(session_diagnostics::UnsupportedLiteral {
|
||||
span: lit.span,
|
||||
reason: UnsupportedLiteralReason::DeprecatedKvPair,
|
||||
@ -1234,11 +1277,11 @@ pub fn parse_confusables(attr: &Attribute) -> Option<Vec<Symbol>> {
|
||||
let mut candidates = Vec::new();
|
||||
|
||||
for meta in metas {
|
||||
let NestedMetaItem::Lit(meta_lit) = meta else {
|
||||
let MetaItemInner::Lit(meta_lit) = meta else {
|
||||
return None;
|
||||
};
|
||||
candidates.push(meta_lit.symbol);
|
||||
}
|
||||
|
||||
return Some(candidates);
|
||||
Some(candidates)
|
||||
}
|
||||
|
||||
@ -15,11 +15,11 @@
|
||||
mod builtin;
|
||||
mod session_diagnostics;
|
||||
|
||||
pub use builtin::*;
|
||||
pub use rustc_ast::attr::*;
|
||||
pub(crate) use rustc_session::HashStableContext;
|
||||
pub use IntType::*;
|
||||
pub use ReprAttr::*;
|
||||
pub use StabilityLevel::*;
|
||||
pub use builtin::*;
|
||||
pub use rustc_ast::attr::*;
|
||||
pub(crate) use rustc_session::HashStableContext;
|
||||
|
||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
||||
|
||||
@ -6,7 +6,7 @@ use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, EmissionGuar
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
use crate::{fluent_generated as fluent, UnsupportedLiteralReason};
|
||||
use crate::{UnsupportedLiteralReason, fluent_generated as fluent};
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(attr_expected_one_cfg_pattern, code = E0536)]
|
||||
@ -203,20 +203,17 @@ pub(crate) struct UnsupportedLiteral {
|
||||
|
||||
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnsupportedLiteral {
|
||||
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
|
||||
let mut diag = Diag::new(
|
||||
dcx,
|
||||
level,
|
||||
match self.reason {
|
||||
UnsupportedLiteralReason::Generic => fluent::attr_unsupported_literal_generic,
|
||||
UnsupportedLiteralReason::CfgString => fluent::attr_unsupported_literal_cfg_string,
|
||||
UnsupportedLiteralReason::DeprecatedString => {
|
||||
fluent::attr_unsupported_literal_deprecated_string
|
||||
}
|
||||
UnsupportedLiteralReason::DeprecatedKvPair => {
|
||||
fluent::attr_unsupported_literal_deprecated_kv_pair
|
||||
}
|
||||
},
|
||||
);
|
||||
let mut diag = Diag::new(dcx, level, match self.reason {
|
||||
UnsupportedLiteralReason::Generic => fluent::attr_unsupported_literal_generic,
|
||||
UnsupportedLiteralReason::CfgString => fluent::attr_unsupported_literal_cfg_string,
|
||||
UnsupportedLiteralReason::CfgBoolean => fluent::attr_unsupported_literal_cfg_boolean,
|
||||
UnsupportedLiteralReason::DeprecatedString => {
|
||||
fluent::attr_unsupported_literal_deprecated_string
|
||||
}
|
||||
UnsupportedLiteralReason::DeprecatedKvPair => {
|
||||
fluent::attr_unsupported_literal_deprecated_kv_pair
|
||||
}
|
||||
});
|
||||
diag.span(self.span);
|
||||
diag.code(E0565);
|
||||
if self.is_bytestr {
|
||||
|
||||
@ -207,7 +207,7 @@ borrowck_simd_intrinsic_arg_const =
|
||||
*[other] {$arg}th
|
||||
} argument of `{$intrinsic}` is required to be a `const` item
|
||||
|
||||
borrowck_suggest_create_freash_reborrow =
|
||||
borrowck_suggest_create_fresh_reborrow =
|
||||
consider reborrowing the `Pin` instead of moving it
|
||||
|
||||
borrowck_suggest_iterate_over_slice =
|
||||
|
||||
@ -4,15 +4,15 @@ use std::ops::Index;
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
|
||||
use rustc_middle::mir::{self, traversal, Body, Local, Location};
|
||||
use rustc_middle::mir::{self, Body, Local, Location, traversal};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{RegionVid, TyCtxt};
|
||||
use rustc_mir_dataflow::move_paths::MoveData;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::BorrowIndex;
|
||||
use crate::path_utils::allow_two_phase_borrow;
|
||||
use crate::place_ext::PlaceExt;
|
||||
use crate::BorrowIndex;
|
||||
|
||||
pub struct BorrowSet<'tcx> {
|
||||
/// The fundamental map relating bitvector indexes to the borrows
|
||||
|
||||
@ -2,13 +2,13 @@
|
||||
#![allow(rustc::untranslatable_diagnostic)]
|
||||
|
||||
use rustc_errors::codes::*;
|
||||
use rustc_errors::{struct_span_code_err, Applicability, Diag, DiagCtxtHandle};
|
||||
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, struct_span_code_err};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
|
||||
impl<'infcx, 'tcx> crate::MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
impl<'infcx, 'tcx> crate::MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
pub(crate) fn dcx(&self) -> DiagCtxtHandle<'infcx> {
|
||||
self.infcx.dcx()
|
||||
}
|
||||
|
||||
@ -97,11 +97,11 @@ impl<D: ConstraintGraphDirection> ConstraintGraph<D> {
|
||||
/// Given the constraint set from which this graph was built
|
||||
/// creates a region graph so that you can iterate over *regions*
|
||||
/// and not constraints.
|
||||
pub(crate) fn region_graph<'rg, 'tcx>(
|
||||
&'rg self,
|
||||
set: &'rg OutlivesConstraintSet<'tcx>,
|
||||
pub(crate) fn region_graph<'a, 'tcx>(
|
||||
&'a self,
|
||||
set: &'a OutlivesConstraintSet<'tcx>,
|
||||
static_region: RegionVid,
|
||||
) -> RegionGraph<'rg, 'tcx, D> {
|
||||
) -> RegionGraph<'a, 'tcx, D> {
|
||||
RegionGraph::new(set, self, static_region)
|
||||
}
|
||||
|
||||
@ -130,15 +130,15 @@ impl<D: ConstraintGraphDirection> ConstraintGraph<D> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Edges<'s, 'tcx, D: ConstraintGraphDirection> {
|
||||
graph: &'s ConstraintGraph<D>,
|
||||
constraints: &'s OutlivesConstraintSet<'tcx>,
|
||||
pub(crate) struct Edges<'a, 'tcx, D: ConstraintGraphDirection> {
|
||||
graph: &'a ConstraintGraph<D>,
|
||||
constraints: &'a OutlivesConstraintSet<'tcx>,
|
||||
pointer: Option<OutlivesConstraintIndex>,
|
||||
next_static_idx: Option<usize>,
|
||||
static_region: RegionVid,
|
||||
}
|
||||
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirection> Iterator for Edges<'s, 'tcx, D> {
|
||||
impl<'a, 'tcx, D: ConstraintGraphDirection> Iterator for Edges<'a, 'tcx, D> {
|
||||
type Item = OutlivesConstraint<'tcx>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
@ -171,20 +171,20 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> Iterator for Edges<'s, 'tcx, D> {
|
||||
/// This struct brings together a constraint set and a (normal, not
|
||||
/// reverse) constraint graph. It implements the graph traits and is
|
||||
/// usd for doing the SCC computation.
|
||||
pub(crate) struct RegionGraph<'s, 'tcx, D: ConstraintGraphDirection> {
|
||||
set: &'s OutlivesConstraintSet<'tcx>,
|
||||
constraint_graph: &'s ConstraintGraph<D>,
|
||||
pub(crate) struct RegionGraph<'a, 'tcx, D: ConstraintGraphDirection> {
|
||||
set: &'a OutlivesConstraintSet<'tcx>,
|
||||
constraint_graph: &'a ConstraintGraph<D>,
|
||||
static_region: RegionVid,
|
||||
}
|
||||
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirection> RegionGraph<'s, 'tcx, D> {
|
||||
impl<'a, 'tcx, D: ConstraintGraphDirection> RegionGraph<'a, 'tcx, D> {
|
||||
/// Creates a "dependency graph" where each region constraint `R1:
|
||||
/// R2` is treated as an edge `R1 -> R2`. We use this graph to
|
||||
/// construct SCCs for region inference but also for error
|
||||
/// reporting.
|
||||
pub(crate) fn new(
|
||||
set: &'s OutlivesConstraintSet<'tcx>,
|
||||
constraint_graph: &'s ConstraintGraph<D>,
|
||||
set: &'a OutlivesConstraintSet<'tcx>,
|
||||
constraint_graph: &'a ConstraintGraph<D>,
|
||||
static_region: RegionVid,
|
||||
) -> Self {
|
||||
Self { set, constraint_graph, static_region }
|
||||
@ -192,18 +192,18 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> RegionGraph<'s, 'tcx, D> {
|
||||
|
||||
/// Given a region `R`, iterate over all regions `R1` such that
|
||||
/// there exists a constraint `R: R1`.
|
||||
pub(crate) fn outgoing_regions(&self, region_sup: RegionVid) -> Successors<'s, 'tcx, D> {
|
||||
pub(crate) fn outgoing_regions(&self, region_sup: RegionVid) -> Successors<'a, 'tcx, D> {
|
||||
Successors {
|
||||
edges: self.constraint_graph.outgoing_edges(region_sup, self.set, self.static_region),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Successors<'s, 'tcx, D: ConstraintGraphDirection> {
|
||||
edges: Edges<'s, 'tcx, D>,
|
||||
pub(crate) struct Successors<'a, 'tcx, D: ConstraintGraphDirection> {
|
||||
edges: Edges<'a, 'tcx, D>,
|
||||
}
|
||||
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirection> Iterator for Successors<'s, 'tcx, D> {
|
||||
impl<'a, 'tcx, D: ConstraintGraphDirection> Iterator for Successors<'a, 'tcx, D> {
|
||||
type Item = RegionVid;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
@ -211,7 +211,7 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> Iterator for Successors<'s, 'tcx, D>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirection> graph::DirectedGraph for RegionGraph<'s, 'tcx, D> {
|
||||
impl<'a, 'tcx, D: ConstraintGraphDirection> graph::DirectedGraph for RegionGraph<'a, 'tcx, D> {
|
||||
type Node = RegionVid;
|
||||
|
||||
fn num_nodes(&self) -> usize {
|
||||
@ -219,7 +219,7 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> graph::DirectedGraph for RegionGraph
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirection> graph::Successors for RegionGraph<'s, 'tcx, D> {
|
||||
impl<'a, 'tcx, D: ConstraintGraphDirection> graph::Successors for RegionGraph<'a, 'tcx, D> {
|
||||
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
|
||||
self.outgoing_regions(node)
|
||||
}
|
||||
|
||||
@ -1,19 +1,17 @@
|
||||
//! This file provides API for compiler consumers.
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use rustc_middle::mir::{Body, Promoted};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
||||
pub use super::constraints::OutlivesConstraint;
|
||||
pub use super::dataflow::{calculate_borrows_out_of_scope_at_location, BorrowIndex, Borrows};
|
||||
pub use super::dataflow::{BorrowIndex, Borrows, calculate_borrows_out_of_scope_at_location};
|
||||
pub use super::facts::{AllFacts as PoloniusInput, RustcFacts};
|
||||
pub use super::location::{LocationTable, RichLocation};
|
||||
pub use super::nll::PoloniusOutput;
|
||||
pub use super::place_ext::PlaceExt;
|
||||
pub use super::places_conflict::{places_conflict, PlaceConflictBias};
|
||||
pub use super::places_conflict::{PlaceConflictBias, places_conflict};
|
||||
pub use super::region_infer::RegionInferenceContext;
|
||||
use crate::borrow_set::BorrowSet;
|
||||
|
||||
@ -65,10 +63,10 @@ pub struct BodyWithBorrowckFacts<'tcx> {
|
||||
/// The mir bodies of promoteds.
|
||||
pub promoted: IndexVec<Promoted, Body<'tcx>>,
|
||||
/// The set of borrows occurring in `body` with data about them.
|
||||
pub borrow_set: Rc<BorrowSet<'tcx>>,
|
||||
pub borrow_set: BorrowSet<'tcx>,
|
||||
/// Context generated during borrowck, intended to be passed to
|
||||
/// [`calculate_borrows_out_of_scope_at_location`].
|
||||
pub region_inference_context: Rc<RegionInferenceContext<'tcx>>,
|
||||
pub region_inference_context: RegionInferenceContext<'tcx>,
|
||||
/// The table that maps Polonius points to locations in the table.
|
||||
/// Populated when using [`ConsumerOptions::PoloniusInputFacts`]
|
||||
/// or [`ConsumerOptions::PoloniusOutputFacts`].
|
||||
@ -79,7 +77,7 @@ pub struct BodyWithBorrowckFacts<'tcx> {
|
||||
pub input_facts: Option<Box<PoloniusInput>>,
|
||||
/// Polonius output facts. Populated when using
|
||||
/// [`ConsumerOptions::PoloniusOutputFacts`].
|
||||
pub output_facts: Option<Rc<PoloniusOutput>>,
|
||||
pub output_facts: Option<Box<PoloniusOutput>>,
|
||||
}
|
||||
|
||||
/// This function computes borrowck facts for the given body. The [`ConsumerOptions`]
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
use std::fmt;
|
||||
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::graph;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
@ -9,40 +7,39 @@ use rustc_middle::mir::{
|
||||
use rustc_middle::ty::{RegionVid, TyCtxt};
|
||||
use rustc_mir_dataflow::fmt::DebugWithContext;
|
||||
use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
|
||||
use rustc_mir_dataflow::{Analysis, AnalysisDomain, GenKill, Results, ResultsVisitable};
|
||||
use rustc_mir_dataflow::{Analysis, AnalysisDomain, Forward, GenKill, Results, ResultsVisitable};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::{places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext};
|
||||
use crate::{BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext, places_conflict};
|
||||
|
||||
/// The results of the dataflow analyses used by the borrow checker.
|
||||
pub(crate) struct BorrowckResults<'a, 'mir, 'tcx> {
|
||||
pub(crate) borrows: Results<'tcx, Borrows<'a, 'mir, 'tcx>>,
|
||||
pub(crate) uninits: Results<'tcx, MaybeUninitializedPlaces<'a, 'mir, 'tcx>>,
|
||||
pub(crate) ever_inits: Results<'tcx, EverInitializedPlaces<'a, 'mir, 'tcx>>,
|
||||
pub(crate) struct BorrowckResults<'a, 'tcx> {
|
||||
pub(crate) borrows: Results<'tcx, Borrows<'a, 'tcx>>,
|
||||
pub(crate) uninits: Results<'tcx, MaybeUninitializedPlaces<'a, 'tcx>>,
|
||||
pub(crate) ever_inits: Results<'tcx, EverInitializedPlaces<'a, 'tcx>>,
|
||||
}
|
||||
|
||||
/// The transient state of the dataflow analyses used by the borrow checker.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct BorrowckFlowState<'a, 'mir, 'tcx> {
|
||||
pub(crate) borrows: <Borrows<'a, 'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
|
||||
pub(crate) uninits: <MaybeUninitializedPlaces<'a, 'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
|
||||
pub(crate) ever_inits: <EverInitializedPlaces<'a, 'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
|
||||
pub(crate) struct BorrowckDomain<'a, 'tcx> {
|
||||
pub(crate) borrows: <Borrows<'a, 'tcx> as AnalysisDomain<'tcx>>::Domain,
|
||||
pub(crate) uninits: <MaybeUninitializedPlaces<'a, 'tcx> as AnalysisDomain<'tcx>>::Domain,
|
||||
pub(crate) ever_inits: <EverInitializedPlaces<'a, 'tcx> as AnalysisDomain<'tcx>>::Domain,
|
||||
}
|
||||
|
||||
impl<'a, 'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'mir, 'tcx> {
|
||||
// All three analyses are forward, but we have to use just one here.
|
||||
type Direction = <Borrows<'a, 'mir, 'tcx> as AnalysisDomain<'tcx>>::Direction;
|
||||
type FlowState = BorrowckFlowState<'a, 'mir, 'tcx>;
|
||||
impl<'a, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'tcx> {
|
||||
type Direction = Forward;
|
||||
type Domain = BorrowckDomain<'a, 'tcx>;
|
||||
|
||||
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
|
||||
BorrowckFlowState {
|
||||
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain {
|
||||
BorrowckDomain {
|
||||
borrows: self.borrows.analysis.bottom_value(body),
|
||||
uninits: self.uninits.analysis.bottom_value(body),
|
||||
ever_inits: self.ever_inits.analysis.bottom_value(body),
|
||||
}
|
||||
}
|
||||
|
||||
fn reset_to_block_entry(&self, state: &mut Self::FlowState, block: BasicBlock) {
|
||||
fn reset_to_block_entry(&self, state: &mut Self::Domain, block: BasicBlock) {
|
||||
state.borrows.clone_from(self.borrows.entry_set_for_block(block));
|
||||
state.uninits.clone_from(self.uninits.entry_set_for_block(block));
|
||||
state.ever_inits.clone_from(self.ever_inits.entry_set_for_block(block));
|
||||
@ -50,7 +47,7 @@ impl<'a, 'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'mir, 'tcx>
|
||||
|
||||
fn reconstruct_before_statement_effect(
|
||||
&mut self,
|
||||
state: &mut Self::FlowState,
|
||||
state: &mut Self::Domain,
|
||||
stmt: &mir::Statement<'tcx>,
|
||||
loc: Location,
|
||||
) {
|
||||
@ -61,7 +58,7 @@ impl<'a, 'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'mir, 'tcx>
|
||||
|
||||
fn reconstruct_statement_effect(
|
||||
&mut self,
|
||||
state: &mut Self::FlowState,
|
||||
state: &mut Self::Domain,
|
||||
stmt: &mir::Statement<'tcx>,
|
||||
loc: Location,
|
||||
) {
|
||||
@ -72,7 +69,7 @@ impl<'a, 'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'mir, 'tcx>
|
||||
|
||||
fn reconstruct_before_terminator_effect(
|
||||
&mut self,
|
||||
state: &mut Self::FlowState,
|
||||
state: &mut Self::Domain,
|
||||
term: &mir::Terminator<'tcx>,
|
||||
loc: Location,
|
||||
) {
|
||||
@ -83,7 +80,7 @@ impl<'a, 'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'mir, 'tcx>
|
||||
|
||||
fn reconstruct_terminator_effect(
|
||||
&mut self,
|
||||
state: &mut Self::FlowState,
|
||||
state: &mut Self::Domain,
|
||||
term: &mir::Terminator<'tcx>,
|
||||
loc: Location,
|
||||
) {
|
||||
@ -106,24 +103,23 @@ rustc_index::newtype_index! {
|
||||
/// `BorrowIndex`, and maps each such index to a `BorrowData`
|
||||
/// describing the borrow. These indexes are used for representing the
|
||||
/// borrows in compact bitvectors.
|
||||
pub struct Borrows<'a, 'mir, 'tcx> {
|
||||
pub struct Borrows<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &'mir Body<'tcx>,
|
||||
|
||||
body: &'a Body<'tcx>,
|
||||
borrow_set: &'a BorrowSet<'tcx>,
|
||||
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
|
||||
}
|
||||
|
||||
struct OutOfScopePrecomputer<'mir, 'tcx> {
|
||||
struct OutOfScopePrecomputer<'a, 'tcx> {
|
||||
visited: BitSet<mir::BasicBlock>,
|
||||
visit_stack: Vec<mir::BasicBlock>,
|
||||
body: &'mir Body<'tcx>,
|
||||
regioncx: &'mir RegionInferenceContext<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
regioncx: &'a RegionInferenceContext<'tcx>,
|
||||
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
|
||||
}
|
||||
|
||||
impl<'mir, 'tcx> OutOfScopePrecomputer<'mir, 'tcx> {
|
||||
fn new(body: &'mir Body<'tcx>, regioncx: &'mir RegionInferenceContext<'tcx>) -> Self {
|
||||
impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
|
||||
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
|
||||
OutOfScopePrecomputer {
|
||||
visited: BitSet::new_empty(body.basic_blocks.len()),
|
||||
visit_stack: vec![],
|
||||
@ -226,17 +222,17 @@ pub fn calculate_borrows_out_of_scope_at_location<'tcx>(
|
||||
prec.borrows_out_of_scope_at_location
|
||||
}
|
||||
|
||||
struct PoloniusOutOfScopePrecomputer<'mir, 'tcx> {
|
||||
struct PoloniusOutOfScopePrecomputer<'a, 'tcx> {
|
||||
visited: BitSet<mir::BasicBlock>,
|
||||
visit_stack: Vec<mir::BasicBlock>,
|
||||
body: &'mir Body<'tcx>,
|
||||
regioncx: &'mir RegionInferenceContext<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
regioncx: &'a RegionInferenceContext<'tcx>,
|
||||
|
||||
loans_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
|
||||
}
|
||||
|
||||
impl<'mir, 'tcx> PoloniusOutOfScopePrecomputer<'mir, 'tcx> {
|
||||
fn new(body: &'mir Body<'tcx>, regioncx: &'mir RegionInferenceContext<'tcx>) -> Self {
|
||||
impl<'a, 'tcx> PoloniusOutOfScopePrecomputer<'a, 'tcx> {
|
||||
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
|
||||
Self {
|
||||
visited: BitSet::new_empty(body.basic_blocks.len()),
|
||||
visit_stack: vec![],
|
||||
@ -389,10 +385,10 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'mir, 'tcx> Borrows<'a, 'mir, 'tcx> {
|
||||
impl<'a, 'tcx> Borrows<'a, 'tcx> {
|
||||
pub fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &'mir Body<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
regioncx: &RegionInferenceContext<'tcx>,
|
||||
borrow_set: &'a BorrowSet<'tcx>,
|
||||
) -> Self {
|
||||
@ -427,10 +423,6 @@ impl<'a, 'mir, 'tcx> Borrows<'a, 'mir, 'tcx> {
|
||||
Borrows { tcx, body, borrow_set, borrows_out_of_scope_at_location }
|
||||
}
|
||||
|
||||
pub fn location(&self, idx: BorrowIndex) -> &Location {
|
||||
&self.borrow_set[idx].reserve_location
|
||||
}
|
||||
|
||||
/// Add all borrows to the kill set, if those borrows are out of scope at `location`.
|
||||
/// That means they went out of a nonlexical scope
|
||||
fn kill_loans_out_of_scope_at_location(
|
||||
@ -494,7 +486,7 @@ impl<'a, 'mir, 'tcx> Borrows<'a, 'mir, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, '_, 'tcx> {
|
||||
impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> {
|
||||
type Domain = BitSet<BorrowIndex>;
|
||||
|
||||
const NAME: &'static str = "borrows";
|
||||
@ -517,7 +509,7 @@ impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, '_, 'tcx> {
|
||||
/// region stops containing the CFG points reachable from the issuing location.
|
||||
/// - we also kill loans of conflicting places when overwriting a shared path: e.g. borrows of
|
||||
/// `a.b.c` when `a` is overwritten.
|
||||
impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, '_, 'tcx> {
|
||||
impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
|
||||
type Idx = BorrowIndex;
|
||||
|
||||
fn domain_size(&self, _: &mir::Body<'tcx>) -> usize {
|
||||
@ -617,8 +609,4 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, '_, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl DebugWithContext<Borrows<'_, '_, '_>> for BorrowIndex {
|
||||
fn fmt_with(&self, ctxt: &Borrows<'_, '_, '_>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}", ctxt.location(*self))
|
||||
}
|
||||
}
|
||||
impl<C> DebugWithContext<C> for BorrowIndex {}
|
||||
|
||||
@ -14,18 +14,18 @@ use rustc_middle::ty::{
|
||||
self, RePlaceholder, Region, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex,
|
||||
};
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::error_reporting::infer::nice_region_error::NiceRegionError;
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
use rustc_trait_selection::traits::query::type_op;
|
||||
use rustc_trait_selection::error_reporting::infer::nice_region_error::NiceRegionError;
|
||||
use rustc_trait_selection::traits::ObligationCtxt;
|
||||
use rustc_trait_selection::traits::query::type_op;
|
||||
use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_cause};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::MirBorrowckCtxt;
|
||||
use crate::region_infer::values::RegionElement;
|
||||
use crate::session_diagnostics::{
|
||||
HigherRankedErrorCause, HigherRankedLifetimeError, HigherRankedSubtypeError,
|
||||
};
|
||||
use crate::MirBorrowckCtxt;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct UniverseInfo<'tcx>(UniverseInfoInner<'tcx>);
|
||||
@ -52,7 +52,7 @@ impl<'tcx> UniverseInfo<'tcx> {
|
||||
|
||||
pub(crate) fn report_error(
|
||||
&self,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, '_, 'tcx>,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
|
||||
placeholder: ty::PlaceholderRegion,
|
||||
error_element: RegionElement,
|
||||
cause: ObligationCause<'tcx>,
|
||||
@ -151,7 +151,7 @@ trait TypeOpInfo<'tcx> {
|
||||
|
||||
fn nice_error<'infcx>(
|
||||
&self,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, 'infcx, 'tcx>,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, 'infcx, 'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
@ -160,7 +160,7 @@ trait TypeOpInfo<'tcx> {
|
||||
#[instrument(level = "debug", skip(self, mbcx))]
|
||||
fn report_error(
|
||||
&self,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, '_, 'tcx>,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
|
||||
placeholder: ty::PlaceholderRegion,
|
||||
error_element: RegionElement,
|
||||
cause: ObligationCause<'tcx>,
|
||||
@ -176,25 +176,24 @@ trait TypeOpInfo<'tcx> {
|
||||
return;
|
||||
};
|
||||
|
||||
let placeholder_region = ty::Region::new_placeholder(
|
||||
tcx,
|
||||
ty::Placeholder { universe: adjusted_universe.into(), bound: placeholder.bound },
|
||||
);
|
||||
let placeholder_region = ty::Region::new_placeholder(tcx, ty::Placeholder {
|
||||
universe: adjusted_universe.into(),
|
||||
bound: placeholder.bound,
|
||||
});
|
||||
|
||||
let error_region = if let RegionElement::PlaceholderRegion(error_placeholder) =
|
||||
error_element
|
||||
{
|
||||
let adjusted_universe =
|
||||
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
|
||||
adjusted_universe.map(|adjusted| {
|
||||
ty::Region::new_placeholder(
|
||||
tcx,
|
||||
ty::Placeholder { universe: adjusted.into(), bound: error_placeholder.bound },
|
||||
)
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let error_region =
|
||||
if let RegionElement::PlaceholderRegion(error_placeholder) = error_element {
|
||||
let adjusted_universe =
|
||||
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
|
||||
adjusted_universe.map(|adjusted| {
|
||||
ty::Region::new_placeholder(tcx, ty::Placeholder {
|
||||
universe: adjusted.into(),
|
||||
bound: error_placeholder.bound,
|
||||
})
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
debug!(?placeholder_region);
|
||||
|
||||
@ -233,7 +232,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
|
||||
|
||||
fn nice_error<'infcx>(
|
||||
&self,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, 'infcx, 'tcx>,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, 'infcx, 'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
@ -277,7 +276,7 @@ where
|
||||
|
||||
fn nice_error<'infcx>(
|
||||
&self,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, 'infcx, 'tcx>,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, 'infcx, 'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
@ -324,7 +323,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
|
||||
|
||||
fn nice_error<'infcx>(
|
||||
&self,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, 'infcx, 'tcx>,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, 'infcx, 'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
@ -357,7 +356,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
|
||||
|
||||
fn nice_error<'infcx>(
|
||||
&self,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, 'infcx, 'tcx>,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, 'infcx, 'tcx>,
|
||||
_cause: ObligationCause<'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
|
||||
@ -11,10 +11,10 @@ use hir::{ClosureKind, Path};
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::codes::*;
|
||||
use rustc_errors::{struct_span_code_err, Applicability, Diag, MultiSpan};
|
||||
use rustc_errors::{Applicability, Diag, MultiSpan, struct_span_code_err};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::intravisit::{walk_block, walk_expr, Map, Visitor};
|
||||
use rustc_hir::intravisit::{Map, Visitor, walk_block, walk_expr};
|
||||
use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, LangItem, PatField};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::hir::nested_filter::OnlyBodies;
|
||||
@ -27,17 +27,17 @@ use rustc_middle::mir::{
|
||||
};
|
||||
use rustc_middle::ty::print::PrintTraitRefExt as _;
|
||||
use rustc_middle::ty::{
|
||||
self, suggest_constraining_type_params, PredicateKind, Ty, TyCtxt, TypeSuperVisitable,
|
||||
TypeVisitor, Upcast,
|
||||
self, PredicateKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, Upcast,
|
||||
suggest_constraining_type_params,
|
||||
};
|
||||
use rustc_middle::util::CallKind;
|
||||
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
|
||||
use rustc_span::def_id::{DefId, LocalDefId};
|
||||
use rustc_span::hygiene::DesugaringKind;
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::symbol::{Ident, kw, sym};
|
||||
use rustc_span::{BytePos, Span, Symbol};
|
||||
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
|
||||
use tracing::{debug, instrument};
|
||||
@ -46,9 +46,9 @@ use super::explain_borrow::{BorrowExplanation, LaterUseKind};
|
||||
use super::{DescribePlaceOpt, RegionName, RegionNameSource, UseSpans};
|
||||
use crate::borrow_set::{BorrowData, TwoPhaseActivation};
|
||||
use crate::diagnostics::conflict_errors::StorageDeadOrDrop::LocalStorageDead;
|
||||
use crate::diagnostics::{find_all_local_uses, CapturedMessageOpt, Instance};
|
||||
use crate::diagnostics::{CapturedMessageOpt, Instance, find_all_local_uses};
|
||||
use crate::prefixes::IsPrefixOf;
|
||||
use crate::{borrowck_errors, InitializationRequiringAction, MirBorrowckCtxt, WriteKind};
|
||||
use crate::{InitializationRequiringAction, MirBorrowckCtxt, WriteKind, borrowck_errors};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct MoveSite {
|
||||
@ -69,7 +69,7 @@ enum StorageDeadOrDrop<'tcx> {
|
||||
Destructor(Ty<'tcx>),
|
||||
}
|
||||
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
pub(crate) fn report_use_of_moved_or_uninitialized(
|
||||
&mut self,
|
||||
location: Location,
|
||||
@ -145,10 +145,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
span,
|
||||
desired_action.as_noun(),
|
||||
partially_str,
|
||||
self.describe_place_with_options(
|
||||
moved_place,
|
||||
DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
|
||||
),
|
||||
self.describe_place_with_options(moved_place, DescribePlaceOpt {
|
||||
including_downcast: true,
|
||||
including_tuple_field: true,
|
||||
}),
|
||||
);
|
||||
|
||||
let reinit_spans = maybe_reinitialized_locations
|
||||
@ -266,10 +266,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
let opt_name = self.describe_place_with_options(
|
||||
place.as_ref(),
|
||||
DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
|
||||
);
|
||||
let opt_name = self.describe_place_with_options(place.as_ref(), DescribePlaceOpt {
|
||||
including_downcast: true,
|
||||
including_tuple_field: true,
|
||||
});
|
||||
let note_msg = match opt_name {
|
||||
Some(name) => format!("`{name}`"),
|
||||
None => "value".to_owned(),
|
||||
@ -689,17 +689,17 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
}
|
||||
let spans: Vec<_> = spans_set.into_iter().collect();
|
||||
|
||||
let (name, desc) = match self.describe_place_with_options(
|
||||
moved_place,
|
||||
DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
|
||||
) {
|
||||
let (name, desc) = match self.describe_place_with_options(moved_place, DescribePlaceOpt {
|
||||
including_downcast: true,
|
||||
including_tuple_field: true,
|
||||
}) {
|
||||
Some(name) => (format!("`{name}`"), format!("`{name}` ")),
|
||||
None => ("the variable".to_string(), String::new()),
|
||||
};
|
||||
let path = match self.describe_place_with_options(
|
||||
used_place,
|
||||
DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
|
||||
) {
|
||||
let path = match self.describe_place_with_options(used_place, DescribePlaceOpt {
|
||||
including_downcast: true,
|
||||
including_tuple_field: true,
|
||||
}) {
|
||||
Some(name) => format!("`{name}`"),
|
||||
None => "value".to_string(),
|
||||
};
|
||||
@ -708,9 +708,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
// for the branching codepaths that aren't covered, to point at them.
|
||||
let map = self.infcx.tcx.hir();
|
||||
let body = map.body_owned_by(self.mir_def_id());
|
||||
let mut visitor =
|
||||
ConditionVisitor { tcx: self.infcx.tcx, spans: &spans, name: &name, errors: vec![] };
|
||||
let mut visitor = ConditionVisitor { tcx: self.infcx.tcx, spans, name, errors: vec![] };
|
||||
visitor.visit_body(&body);
|
||||
let spans = visitor.spans;
|
||||
|
||||
let mut show_assign_sugg = false;
|
||||
let isnt_initialized = if let InitializationRequiringAction::PartialAssignment
|
||||
@ -1179,7 +1179,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
for field in &variant.fields {
|
||||
// In practice unless there are more than one field with the same type, we'll be
|
||||
// suggesting a single field at a type, because we don't aggregate multiple borrow
|
||||
// checker errors involving the functional record update sytnax into a single one.
|
||||
// checker errors involving the functional record update syntax into a single one.
|
||||
let field_ty = field.ty(self.infcx.tcx, args);
|
||||
let ident = field.ident(self.infcx.tcx);
|
||||
if field_ty == ty && fields.iter().all(|field| field.ident.name != ident.name) {
|
||||
@ -1999,19 +1999,32 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
) {
|
||||
let used_in_call = matches!(
|
||||
explanation,
|
||||
BorrowExplanation::UsedLater(LaterUseKind::Call | LaterUseKind::Other, _call_span, _)
|
||||
BorrowExplanation::UsedLater(
|
||||
_,
|
||||
LaterUseKind::Call | LaterUseKind::Other,
|
||||
_call_span,
|
||||
_
|
||||
)
|
||||
);
|
||||
if !used_in_call {
|
||||
debug!("not later used in call");
|
||||
return;
|
||||
}
|
||||
if matches!(
|
||||
self.body.local_decls[issued_borrow.borrowed_place.local].local_info(),
|
||||
LocalInfo::IfThenRescopeTemp { .. }
|
||||
) {
|
||||
// A better suggestion will be issued by the `if_let_rescope` lint
|
||||
return;
|
||||
}
|
||||
|
||||
let use_span =
|
||||
if let BorrowExplanation::UsedLater(LaterUseKind::Other, use_span, _) = explanation {
|
||||
Some(use_span)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let use_span = if let BorrowExplanation::UsedLater(_, LaterUseKind::Other, use_span, _) =
|
||||
explanation
|
||||
{
|
||||
Some(use_span)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let outer_call_loc =
|
||||
if let TwoPhaseActivation::ActivatedAt(loc) = issued_borrow.activation_location {
|
||||
@ -2574,33 +2587,31 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
}
|
||||
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
|
||||
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
|
||||
if e.span.contains(self.capture_span) {
|
||||
if let hir::ExprKind::Closure(&hir::Closure {
|
||||
if e.span.contains(self.capture_span)
|
||||
&& let hir::ExprKind::Closure(&hir::Closure {
|
||||
kind: hir::ClosureKind::Closure,
|
||||
body,
|
||||
fn_arg_span,
|
||||
fn_decl: hir::FnDecl { inputs, .. },
|
||||
..
|
||||
}) = e.kind
|
||||
&& let hir::Node::Expr(body) = self.tcx.hir_node(body.hir_id)
|
||||
{
|
||||
self.suggest_arg = "this: &Self".to_string();
|
||||
if inputs.len() > 0 {
|
||||
self.suggest_arg.push_str(", ");
|
||||
}
|
||||
self.in_closure = true;
|
||||
self.closure_arg_span = fn_arg_span;
|
||||
self.visit_expr(body);
|
||||
self.in_closure = false;
|
||||
&& let hir::Node::Expr(body) = self.tcx.hir_node(body.hir_id)
|
||||
{
|
||||
self.suggest_arg = "this: &Self".to_string();
|
||||
if inputs.len() > 0 {
|
||||
self.suggest_arg.push_str(", ");
|
||||
}
|
||||
self.in_closure = true;
|
||||
self.closure_arg_span = fn_arg_span;
|
||||
self.visit_expr(body);
|
||||
self.in_closure = false;
|
||||
}
|
||||
if let hir::Expr { kind: hir::ExprKind::Path(path), .. } = e {
|
||||
if let hir::QPath::Resolved(_, hir::Path { segments: [seg], .. }) = path
|
||||
&& seg.ident.name == kw::SelfLower
|
||||
&& self.in_closure
|
||||
{
|
||||
self.closure_change_spans.push(e.span);
|
||||
}
|
||||
if let hir::Expr { kind: hir::ExprKind::Path(path), .. } = e
|
||||
&& let hir::QPath::Resolved(_, hir::Path { segments: [seg], .. }) = path
|
||||
&& seg.ident.name == kw::SelfLower
|
||||
&& self.in_closure
|
||||
{
|
||||
self.closure_change_spans.push(e.span);
|
||||
}
|
||||
hir::intravisit::walk_expr(self, e);
|
||||
}
|
||||
@ -2609,8 +2620,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
if let hir::Pat { kind: hir::PatKind::Binding(_, hir_id, _ident, _), .. } =
|
||||
local.pat
|
||||
&& let Some(init) = local.init
|
||||
{
|
||||
if let hir::Expr {
|
||||
&& let hir::Expr {
|
||||
kind:
|
||||
hir::ExprKind::Closure(&hir::Closure {
|
||||
kind: hir::ClosureKind::Closure,
|
||||
@ -2618,11 +2628,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
}),
|
||||
..
|
||||
} = init
|
||||
&& init.span.contains(self.capture_span)
|
||||
{
|
||||
self.closure_local_id = Some(*hir_id);
|
||||
}
|
||||
&& init.span.contains(self.capture_span)
|
||||
{
|
||||
self.closure_local_id = Some(*hir_id);
|
||||
}
|
||||
|
||||
hir::intravisit::walk_local(self, local);
|
||||
}
|
||||
|
||||
@ -2862,7 +2872,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
// and `move` will not help here.
|
||||
(
|
||||
Some(name),
|
||||
BorrowExplanation::UsedLater(LaterUseKind::ClosureCapture, var_or_use_span, _),
|
||||
BorrowExplanation::UsedLater(_, LaterUseKind::ClosureCapture, var_or_use_span, _),
|
||||
) if borrow_spans.for_coroutine() || borrow_spans.for_closure() => self
|
||||
.report_escaping_closure_capture(
|
||||
borrow_spans,
|
||||
@ -3543,7 +3553,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
location: Location,
|
||||
mpi: MovePathIndex,
|
||||
) -> (Vec<MoveSite>, Vec<Location>) {
|
||||
fn predecessor_locations<'tcx, 'a>(
|
||||
fn predecessor_locations<'a, 'tcx>(
|
||||
body: &'a mir::Body<'tcx>,
|
||||
location: Location,
|
||||
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
|
||||
@ -3669,7 +3679,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
reinits.push(location);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
false
|
||||
};
|
||||
|
||||
while let Some(location) = stack.pop() {
|
||||
@ -4358,11 +4368,7 @@ enum AnnotatedBorrowFnSignature<'tcx> {
|
||||
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
|
||||
/// Annotate the provided diagnostic with information about borrow from the fn signature that
|
||||
/// helps explain.
|
||||
pub(crate) fn emit(
|
||||
&self,
|
||||
cx: &MirBorrowckCtxt<'_, '_, '_, 'tcx>,
|
||||
diag: &mut Diag<'_>,
|
||||
) -> String {
|
||||
pub(crate) fn emit(&self, cx: &MirBorrowckCtxt<'_, '_, 'tcx>, diag: &mut Diag<'_>) -> String {
|
||||
match self {
|
||||
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
|
||||
diag.span_label(
|
||||
@ -4459,20 +4465,20 @@ impl<'hir> Visitor<'hir> for BreakFinder {
|
||||
|
||||
/// Given a set of spans representing statements initializing the relevant binding, visit all the
|
||||
/// function expressions looking for branching code paths that *do not* initialize the binding.
|
||||
struct ConditionVisitor<'b, 'tcx> {
|
||||
struct ConditionVisitor<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
spans: &'b [Span],
|
||||
name: &'b str,
|
||||
spans: Vec<Span>,
|
||||
name: String,
|
||||
errors: Vec<(Span, String)>,
|
||||
}
|
||||
|
||||
impl<'b, 'v, 'tcx> Visitor<'v> for ConditionVisitor<'b, 'tcx> {
|
||||
impl<'v, 'tcx> Visitor<'v> for ConditionVisitor<'tcx> {
|
||||
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
|
||||
match ex.kind {
|
||||
hir::ExprKind::If(cond, body, None) => {
|
||||
// `if` expressions with no `else` that initialize the binding might be missing an
|
||||
// `else` arm.
|
||||
if ReferencedStatementsVisitor(self.spans).visit_expr(body).is_break() {
|
||||
if ReferencedStatementsVisitor(&self.spans).visit_expr(body).is_break() {
|
||||
self.errors.push((
|
||||
cond.span,
|
||||
format!(
|
||||
@ -4489,8 +4495,8 @@ impl<'b, 'v, 'tcx> Visitor<'v> for ConditionVisitor<'b, 'tcx> {
|
||||
hir::ExprKind::If(cond, body, Some(other)) => {
|
||||
// `if` expressions where the binding is only initialized in one of the two arms
|
||||
// might be missing a binding initialization.
|
||||
let a = ReferencedStatementsVisitor(self.spans).visit_expr(body).is_break();
|
||||
let b = ReferencedStatementsVisitor(self.spans).visit_expr(other).is_break();
|
||||
let a = ReferencedStatementsVisitor(&self.spans).visit_expr(body).is_break();
|
||||
let b = ReferencedStatementsVisitor(&self.spans).visit_expr(other).is_break();
|
||||
match (a, b) {
|
||||
(true, true) | (false, false) => {}
|
||||
(true, false) => {
|
||||
@ -4530,7 +4536,7 @@ impl<'b, 'v, 'tcx> Visitor<'v> for ConditionVisitor<'b, 'tcx> {
|
||||
// arms might be missing an initialization.
|
||||
let results: Vec<bool> = arms
|
||||
.iter()
|
||||
.map(|arm| ReferencedStatementsVisitor(self.spans).visit_arm(arm).is_break())
|
||||
.map(|arm| ReferencedStatementsVisitor(&self.spans).visit_arm(arm).is_break())
|
||||
.collect();
|
||||
if results.iter().any(|x| *x) && !results.iter().all(|x| *x) {
|
||||
for (arm, seen) in arms.iter().zip(results) {
|
||||
|
||||
@ -17,12 +17,12 @@ use rustc_middle::mir::{
|
||||
};
|
||||
use rustc_middle::ty::adjustment::PointerCoercion;
|
||||
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
|
||||
use rustc_span::symbol::{kw, Symbol};
|
||||
use rustc_span::{sym, DesugaringKind, Span};
|
||||
use rustc_span::symbol::{Symbol, kw};
|
||||
use rustc_span::{DesugaringKind, Span, sym};
|
||||
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use super::{find_use, RegionName, UseSpans};
|
||||
use super::{RegionName, UseSpans, find_use};
|
||||
use crate::borrow_set::BorrowData;
|
||||
use crate::nll::ConstraintDescription;
|
||||
use crate::region_infer::{BlameConstraint, Cause, ExtraConstraintInfo};
|
||||
@ -30,7 +30,7 @@ use crate::{MirBorrowckCtxt, WriteKind};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum BorrowExplanation<'tcx> {
|
||||
UsedLater(LaterUseKind, Span, Option<Span>),
|
||||
UsedLater(Local, LaterUseKind, Span, Option<Span>),
|
||||
UsedLaterInLoop(LaterUseKind, Span, Option<Span>),
|
||||
UsedLaterWhenDropped {
|
||||
drop_loc: Location,
|
||||
@ -99,7 +99,12 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||
}
|
||||
}
|
||||
match *self {
|
||||
BorrowExplanation::UsedLater(later_use_kind, var_or_use_span, path_span) => {
|
||||
BorrowExplanation::UsedLater(
|
||||
dropped_local,
|
||||
later_use_kind,
|
||||
var_or_use_span,
|
||||
path_span,
|
||||
) => {
|
||||
let message = match later_use_kind {
|
||||
LaterUseKind::TraitCapture => "captured here by trait object",
|
||||
LaterUseKind::ClosureCapture => "captured here by closure",
|
||||
@ -107,9 +112,26 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||
LaterUseKind::FakeLetRead => "stored here",
|
||||
LaterUseKind::Other => "used here",
|
||||
};
|
||||
// We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same
|
||||
if path_span.map(|path_span| path_span == var_or_use_span).unwrap_or(true) {
|
||||
if borrow_span.map(|sp| !sp.overlaps(var_or_use_span)).unwrap_or(true) {
|
||||
let local_decl = &body.local_decls[dropped_local];
|
||||
|
||||
if let &LocalInfo::IfThenRescopeTemp { if_then } = local_decl.local_info()
|
||||
&& let Some((_, hir::Node::Expr(expr))) = tcx.hir().parent_iter(if_then).next()
|
||||
&& let hir::ExprKind::If(cond, conseq, alt) = expr.kind
|
||||
&& let hir::ExprKind::Let(&hir::LetExpr {
|
||||
span: _,
|
||||
pat,
|
||||
init,
|
||||
// FIXME(#101728): enable rewrite when type ascription is stabilized again
|
||||
ty: None,
|
||||
recovered: _,
|
||||
}) = cond.kind
|
||||
&& pat.span.can_be_used_for_suggestions()
|
||||
&& let Ok(pat) = tcx.sess.source_map().span_to_snippet(pat.span)
|
||||
{
|
||||
suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err);
|
||||
} else if path_span.map_or(true, |path_span| path_span == var_or_use_span) {
|
||||
// We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same
|
||||
if borrow_span.map_or(true, |sp| !sp.overlaps(var_or_use_span)) {
|
||||
err.span_label(
|
||||
var_or_use_span,
|
||||
format!("{borrow_desc}borrow later {message}"),
|
||||
@ -255,6 +277,22 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
};
|
||||
} else if let &LocalInfo::IfThenRescopeTemp { if_then } =
|
||||
local_decl.local_info()
|
||||
&& let hir::Node::Expr(expr) = tcx.hir_node(if_then)
|
||||
&& let hir::ExprKind::If(cond, conseq, alt) = expr.kind
|
||||
&& let hir::ExprKind::Let(&hir::LetExpr {
|
||||
span: _,
|
||||
pat,
|
||||
init,
|
||||
// FIXME(#101728): enable rewrite when type ascription is stabilized again
|
||||
ty: None,
|
||||
recovered: _,
|
||||
}) = cond.kind
|
||||
&& pat.span.can_be_used_for_suggestions()
|
||||
&& let Ok(pat) = tcx.sess.source_map().span_to_snippet(pat.span)
|
||||
{
|
||||
suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -295,7 +333,11 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
if let ConstraintCategory::Cast { unsize_to: Some(unsize_ty) } = category {
|
||||
if let ConstraintCategory::Cast {
|
||||
is_implicit_coercion: true,
|
||||
unsize_to: Some(unsize_ty),
|
||||
} = category
|
||||
{
|
||||
self.add_object_lifetime_default_note(tcx, err, unsize_ty);
|
||||
}
|
||||
self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name);
|
||||
@ -390,7 +432,54 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
|
||||
fn suggest_rewrite_if_let(
|
||||
tcx: TyCtxt<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
pat: &str,
|
||||
init: &hir::Expr<'_>,
|
||||
conseq: &hir::Expr<'_>,
|
||||
alt: Option<&hir::Expr<'_>>,
|
||||
err: &mut Diag<'_>,
|
||||
) {
|
||||
let source_map = tcx.sess.source_map();
|
||||
err.span_note(
|
||||
source_map.end_point(conseq.span),
|
||||
"lifetimes for temporaries generated in `if let`s have been shortened in Edition 2024 so that they are dropped here instead",
|
||||
);
|
||||
if expr.span.can_be_used_for_suggestions() && conseq.span.can_be_used_for_suggestions() {
|
||||
let needs_block = if let Some(hir::Node::Expr(expr)) =
|
||||
alt.and_then(|alt| tcx.hir().parent_iter(alt.hir_id).next()).map(|(_, node)| node)
|
||||
{
|
||||
matches!(expr.kind, hir::ExprKind::If(..))
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let mut sugg = vec![
|
||||
(
|
||||
expr.span.shrink_to_lo().between(init.span),
|
||||
if needs_block { "{ match ".into() } else { "match ".into() },
|
||||
),
|
||||
(conseq.span.shrink_to_lo(), format!(" {{ {pat} => ")),
|
||||
];
|
||||
let expr_end = expr.span.shrink_to_hi();
|
||||
let mut expr_end_code;
|
||||
if let Some(alt) = alt {
|
||||
sugg.push((conseq.span.between(alt.span), " _ => ".into()));
|
||||
expr_end_code = "}".to_string();
|
||||
} else {
|
||||
expr_end_code = " _ => {} }".into();
|
||||
}
|
||||
expr_end_code.push('}');
|
||||
sugg.push((expr_end, expr_end_code));
|
||||
err.multipart_suggestion(
|
||||
"consider rewriting the `if` into `match` which preserves the extended lifetime",
|
||||
sugg,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||
fn free_region_constraint_info(
|
||||
&self,
|
||||
borrow_region: RegionVid,
|
||||
@ -465,14 +554,21 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
|
||||
.or_else(|| self.borrow_spans(span, location));
|
||||
|
||||
if use_in_later_iteration_of_loop {
|
||||
let later_use = self.later_use_kind(borrow, spans, use_location);
|
||||
BorrowExplanation::UsedLaterInLoop(later_use.0, later_use.1, later_use.2)
|
||||
let (later_use_kind, var_or_use_span, path_span) =
|
||||
self.later_use_kind(borrow, spans, use_location);
|
||||
BorrowExplanation::UsedLaterInLoop(later_use_kind, var_or_use_span, path_span)
|
||||
} else {
|
||||
// Check if the location represents a `FakeRead`, and adapt the error
|
||||
// message to the `FakeReadCause` it is from: in particular,
|
||||
// the ones inserted in optimized `let var = <expr>` patterns.
|
||||
let later_use = self.later_use_kind(borrow, spans, location);
|
||||
BorrowExplanation::UsedLater(later_use.0, later_use.1, later_use.2)
|
||||
let (later_use_kind, var_or_use_span, path_span) =
|
||||
self.later_use_kind(borrow, spans, location);
|
||||
BorrowExplanation::UsedLater(
|
||||
borrow.borrowed_place.local,
|
||||
later_use_kind,
|
||||
var_or_use_span,
|
||||
path_span,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -648,7 +744,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
|
||||
// If we see an unsized cast, then if it is our data we should check
|
||||
// whether it is being cast to a trait object.
|
||||
Rvalue::Cast(
|
||||
CastKind::PointerCoercion(PointerCoercion::Unsize),
|
||||
CastKind::PointerCoercion(PointerCoercion::Unsize, _),
|
||||
operand,
|
||||
ty,
|
||||
) => {
|
||||
@ -662,9 +758,10 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
|
||||
// `&dyn Trait`
|
||||
ty::Ref(_, ty, _) if ty.is_trait() => true,
|
||||
// `Box<dyn Trait>`
|
||||
_ if ty.is_box() && ty.boxed_ty().is_trait() => {
|
||||
_ if ty.boxed_ty().is_some_and(Ty::is_trait) => {
|
||||
true
|
||||
}
|
||||
|
||||
// `dyn Trait`
|
||||
_ if ty.is_trait() => true,
|
||||
// Anything else.
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use std::collections::VecDeque;
|
||||
use std::rc::Rc;
|
||||
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_middle::mir::visit::{MirVisitable, PlaceContext, Visitor};
|
||||
@ -11,7 +10,7 @@ use crate::region_infer::{Cause, RegionInferenceContext};
|
||||
|
||||
pub(crate) fn find<'tcx>(
|
||||
body: &Body<'tcx>,
|
||||
regioncx: &Rc<RegionInferenceContext<'tcx>>,
|
||||
regioncx: &RegionInferenceContext<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
region_vid: RegionVid,
|
||||
start_point: Location,
|
||||
@ -21,15 +20,15 @@ pub(crate) fn find<'tcx>(
|
||||
uf.find()
|
||||
}
|
||||
|
||||
struct UseFinder<'cx, 'tcx> {
|
||||
body: &'cx Body<'tcx>,
|
||||
regioncx: &'cx Rc<RegionInferenceContext<'tcx>>,
|
||||
struct UseFinder<'a, 'tcx> {
|
||||
body: &'a Body<'tcx>,
|
||||
regioncx: &'a RegionInferenceContext<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
region_vid: RegionVid,
|
||||
start_point: Location,
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> UseFinder<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> UseFinder<'a, 'tcx> {
|
||||
fn find(&mut self) -> Option<Cause> {
|
||||
let mut queue = VecDeque::new();
|
||||
let mut visited = FxIndexSet::default();
|
||||
@ -93,8 +92,8 @@ impl<'cx, 'tcx> UseFinder<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
struct DefUseVisitor<'cx, 'tcx> {
|
||||
body: &'cx Body<'tcx>,
|
||||
struct DefUseVisitor<'a, 'tcx> {
|
||||
body: &'a Body<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
region_vid: RegionVid,
|
||||
def_use_result: Option<DefUseResult>,
|
||||
@ -106,7 +105,7 @@ enum DefUseResult {
|
||||
UseDrop { local: Local },
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> Visitor<'tcx> for DefUseVisitor<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for DefUseVisitor<'a, 'tcx> {
|
||||
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
|
||||
let local_ty = self.body.local_decls[local].ty;
|
||||
|
||||
|
||||
@ -15,22 +15,22 @@ use rustc_middle::mir::{
|
||||
};
|
||||
use rustc_middle::ty::print::Print;
|
||||
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
|
||||
use rustc_middle::util::{call_kind, CallDesugaringKind};
|
||||
use rustc_middle::util::{CallDesugaringKind, call_kind};
|
||||
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::{Span, Symbol, DUMMY_SP};
|
||||
use rustc_span::{DUMMY_SP, Span, Symbol};
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::{
|
||||
type_known_to_meet_bound_modulo_regions, FulfillmentErrorCode,
|
||||
FulfillmentErrorCode, type_known_to_meet_bound_modulo_regions,
|
||||
};
|
||||
use tracing::debug;
|
||||
|
||||
use super::borrow_set::BorrowData;
|
||||
use super::MirBorrowckCtxt;
|
||||
use super::borrow_set::BorrowData;
|
||||
use crate::fluent_generated as fluent;
|
||||
use crate::session_diagnostics::{
|
||||
CaptureArgLabel, CaptureReasonLabel, CaptureReasonNote, CaptureReasonSuggest, CaptureVarCause,
|
||||
@ -68,7 +68,7 @@ pub(super) struct DescribePlaceOpt {
|
||||
|
||||
pub(super) struct IncludingTupleField(pub(super) bool);
|
||||
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
/// Adds a suggestion when a closure is invoked twice with a moved variable or when a closure
|
||||
/// is moved after being invoked.
|
||||
///
|
||||
@ -177,10 +177,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
/// End-user visible description of `place` if one can be found.
|
||||
/// If the place is a temporary for instance, `None` will be returned.
|
||||
pub(super) fn describe_place(&self, place_ref: PlaceRef<'tcx>) -> Option<String> {
|
||||
self.describe_place_with_options(
|
||||
place_ref,
|
||||
DescribePlaceOpt { including_downcast: false, including_tuple_field: true },
|
||||
)
|
||||
self.describe_place_with_options(place_ref, DescribePlaceOpt {
|
||||
including_downcast: false,
|
||||
including_tuple_field: true,
|
||||
})
|
||||
}
|
||||
|
||||
/// End-user visible description of `place` if one can be found. If the place is a temporary
|
||||
@ -345,9 +345,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
variant_index: Option<VariantIdx>,
|
||||
including_tuple_field: IncludingTupleField,
|
||||
) -> Option<String> {
|
||||
if ty.is_box() {
|
||||
if let Some(boxed_ty) = ty.boxed_ty() {
|
||||
// If the type is a box, the field is described from the boxed type
|
||||
self.describe_field_from_ty(ty.boxed_ty(), field, variant_index, including_tuple_field)
|
||||
self.describe_field_from_ty(boxed_ty, field, variant_index, including_tuple_field)
|
||||
} else {
|
||||
match *ty.kind() {
|
||||
ty::Adt(def, _) => {
|
||||
@ -772,7 +772,7 @@ struct CapturedMessageOpt {
|
||||
maybe_reinitialized_locations_is_empty: bool,
|
||||
}
|
||||
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
/// Finds the spans associated to a move or copy of move_place at location.
|
||||
pub(super) fn move_spans(
|
||||
&self,
|
||||
|
||||
@ -12,9 +12,9 @@ use rustc_span::{BytePos, ExpnKind, MacroKind, Span};
|
||||
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::MirBorrowckCtxt;
|
||||
use crate::diagnostics::{CapturedMessageOpt, DescribePlaceOpt, UseSpans};
|
||||
use crate::prefixes::PrefixSet;
|
||||
use crate::MirBorrowckCtxt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum IllegalMoveOriginKind<'tcx> {
|
||||
@ -93,7 +93,7 @@ enum GroupedMoveError<'tcx> {
|
||||
},
|
||||
}
|
||||
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
pub(crate) fn report_move_errors(&mut self) {
|
||||
let grouped_errors = self.group_move_errors();
|
||||
for error in grouped_errors {
|
||||
@ -706,7 +706,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
suggestions.push((
|
||||
pat_span,
|
||||
format!("consider removing the {to_remove}"),
|
||||
suggestion.to_string(),
|
||||
suggestion,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,8 +14,8 @@ use rustc_middle::mir::{
|
||||
PlaceRef, ProjectionElem,
|
||||
};
|
||||
use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, Upcast};
|
||||
use rustc_span::symbol::{kw, Symbol};
|
||||
use rustc_span::{sym, BytePos, DesugaringKind, Span};
|
||||
use rustc_span::symbol::{Symbol, kw};
|
||||
use rustc_span::{BytePos, DesugaringKind, Span, sym};
|
||||
use rustc_target::abi::FieldIdx;
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
@ -24,7 +24,7 @@ use tracing::debug;
|
||||
|
||||
use crate::diagnostics::BorrowedContentSource;
|
||||
use crate::util::FindAssignments;
|
||||
use crate::{session_diagnostics, MirBorrowckCtxt};
|
||||
use crate::{MirBorrowckCtxt, session_diagnostics};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub(crate) enum AccessKind {
|
||||
@ -32,7 +32,7 @@ pub(crate) enum AccessKind {
|
||||
Mutate,
|
||||
}
|
||||
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
pub(crate) fn report_mutability_error(
|
||||
&mut self,
|
||||
access_place: Place<'tcx>,
|
||||
@ -558,7 +558,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
ty: Ty<'tcx>,
|
||||
suggested: bool,
|
||||
}
|
||||
impl<'a, 'cx, 'tcx> Visitor<'tcx> for SuggestIndexOperatorAlternativeVisitor<'a, 'cx, 'tcx> {
|
||||
impl<'a, 'infcx, 'tcx> Visitor<'tcx> for SuggestIndexOperatorAlternativeVisitor<'a, 'infcx, 'tcx> {
|
||||
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
|
||||
hir::intravisit::walk_stmt(self, stmt);
|
||||
let expr = match stmt.kind {
|
||||
|
||||
@ -76,7 +76,7 @@ impl OutlivesSuggestionBuilder {
|
||||
/// Returns a name for the region if it is suggestable. See `region_name_is_suggestable`.
|
||||
fn region_vid_to_name(
|
||||
&self,
|
||||
mbcx: &MirBorrowckCtxt<'_, '_, '_, '_>,
|
||||
mbcx: &MirBorrowckCtxt<'_, '_, '_>,
|
||||
region: RegionVid,
|
||||
) -> Option<RegionName> {
|
||||
mbcx.give_region_a_name(region).filter(Self::region_name_is_suggestable)
|
||||
@ -85,7 +85,7 @@ impl OutlivesSuggestionBuilder {
|
||||
/// Compiles a list of all suggestions to be printed in the final big suggestion.
|
||||
fn compile_all_suggestions(
|
||||
&self,
|
||||
mbcx: &MirBorrowckCtxt<'_, '_, '_, '_>,
|
||||
mbcx: &MirBorrowckCtxt<'_, '_, '_>,
|
||||
) -> SmallVec<[SuggestedConstraint; 2]> {
|
||||
let mut suggested = SmallVec::new();
|
||||
|
||||
@ -161,7 +161,7 @@ impl OutlivesSuggestionBuilder {
|
||||
/// Emit an intermediate note on the given `Diag` if the involved regions are suggestable.
|
||||
pub(crate) fn intermediate_suggestion(
|
||||
&mut self,
|
||||
mbcx: &MirBorrowckCtxt<'_, '_, '_, '_>,
|
||||
mbcx: &MirBorrowckCtxt<'_, '_, '_>,
|
||||
errci: &ErrorConstraintInfo<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
) {
|
||||
@ -180,7 +180,7 @@ impl OutlivesSuggestionBuilder {
|
||||
|
||||
/// If there is a suggestion to emit, add a diagnostic to the buffer. This is the final
|
||||
/// suggestion including all collected constraints.
|
||||
pub(crate) fn add_suggestion(&self, mbcx: &mut MirBorrowckCtxt<'_, '_, '_, '_>) {
|
||||
pub(crate) fn add_suggestion(&self, mbcx: &mut MirBorrowckCtxt<'_, '_, '_>) {
|
||||
// No constraints to add? Done.
|
||||
if self.constraints_to_add.is_empty() {
|
||||
debug!("No constraints to suggest.");
|
||||
|
||||
@ -3,26 +3,26 @@
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res::Def;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::GenericBound::Trait;
|
||||
use rustc_hir::QPath::Resolved;
|
||||
use rustc_hir::WherePredicate::BoundPredicate;
|
||||
use rustc_hir::def::Res::Def;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::{PolyTraitRef, TyKind, WhereBoundPredicate};
|
||||
use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::hir::place::PlaceBase;
|
||||
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
|
||||
use rustc_middle::ty::{self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeVisitor};
|
||||
use rustc_span::symbol::{kw, Ident};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, kw};
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
use rustc_trait_selection::error_reporting::infer::nice_region_error::{
|
||||
self, find_anon_type, find_param_with_region, suggest_adding_lifetime_params,
|
||||
HirTraitObjectVisitor, NiceRegionError, TraitObjectVisitor,
|
||||
self, HirTraitObjectVisitor, NiceRegionError, TraitObjectVisitor, find_anon_type,
|
||||
find_param_with_region, suggest_adding_lifetime_params,
|
||||
};
|
||||
use rustc_trait_selection::error_reporting::infer::region::unexpected_hidden_region_diagnostic;
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::{Obligation, ObligationCtxt};
|
||||
use tracing::{debug, instrument, trace};
|
||||
@ -36,7 +36,7 @@ use crate::session_diagnostics::{
|
||||
LifetimeReturnCategoryErr, RequireStaticErr, VarHereDenote,
|
||||
};
|
||||
use crate::universal_regions::DefiningTy;
|
||||
use crate::{borrowck_errors, fluent_generated as fluent, MirBorrowckCtxt};
|
||||
use crate::{MirBorrowckCtxt, borrowck_errors, fluent_generated as fluent};
|
||||
|
||||
impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
|
||||
fn description(&self) -> &'static str {
|
||||
@ -47,7 +47,8 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
|
||||
ConstraintCategory::Yield => "yielding this value ",
|
||||
ConstraintCategory::UseAsConst => "using this value as a constant ",
|
||||
ConstraintCategory::UseAsStatic => "using this value as a static ",
|
||||
ConstraintCategory::Cast { .. } => "cast ",
|
||||
ConstraintCategory::Cast { is_implicit_coercion: false, .. } => "cast ",
|
||||
ConstraintCategory::Cast { is_implicit_coercion: true, .. } => "coercion ",
|
||||
ConstraintCategory::CallArgument(_) => "argument ",
|
||||
ConstraintCategory::TypeAnnotation => "type annotation ",
|
||||
ConstraintCategory::ClosureBounds => "closure body ",
|
||||
@ -156,7 +157,7 @@ pub(crate) struct ErrorConstraintInfo<'tcx> {
|
||||
pub(super) span: Span,
|
||||
}
|
||||
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
/// Converts a region inference variable into a `ty::Region` that
|
||||
/// we can use for error reporting. If `r` is universally bound,
|
||||
/// then we use the name that we have on record for it. If `r` is
|
||||
@ -1108,15 +1109,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
let closure_ty = Ty::new_closure(
|
||||
tcx,
|
||||
closure_def_id.to_def_id(),
|
||||
ty::ClosureArgs::new(
|
||||
tcx,
|
||||
ty::ClosureArgsParts {
|
||||
parent_args: args.parent_args(),
|
||||
closure_kind_ty: args.kind_ty(),
|
||||
tupled_upvars_ty: args.tupled_upvars_ty(),
|
||||
closure_sig_as_fn_ptr_ty,
|
||||
},
|
||||
)
|
||||
ty::ClosureArgs::new(tcx, ty::ClosureArgsParts {
|
||||
parent_args: args.parent_args(),
|
||||
closure_kind_ty: args.kind_ty(),
|
||||
tupled_upvars_ty: args.tupled_upvars_ty(),
|
||||
closure_sig_as_fn_ptr_ty,
|
||||
})
|
||||
.args,
|
||||
);
|
||||
|
||||
|
||||
@ -11,13 +11,13 @@ use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_middle::ty::print::RegionHighlightMode;
|
||||
use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, RegionVid, Ty};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::symbol::{Symbol, kw, sym};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::universal_regions::DefiningTy;
|
||||
use crate::MirBorrowckCtxt;
|
||||
use crate::universal_regions::DefiningTy;
|
||||
|
||||
/// A name for a particular region used in emitting diagnostics. This name could be a generated
|
||||
/// name like `'1`, a name used by the user like `'a`, or a name like `'static`.
|
||||
@ -200,7 +200,7 @@ impl rustc_errors::IntoDiagArg for RegionName {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
|
||||
impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||
pub(crate) fn mir_def_id(&self) -> hir::def_id::LocalDefId {
|
||||
self.body.source.def_id().expect_local()
|
||||
}
|
||||
@ -830,20 +830,14 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
|
||||
///
|
||||
/// [`OpaqueDef`]: hir::TyKind::OpaqueDef
|
||||
fn get_future_inner_return_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {
|
||||
let hir = self.infcx.tcx.hir();
|
||||
|
||||
let hir::TyKind::OpaqueDef(id, _, _) = hir_ty.kind else {
|
||||
let hir::TyKind::OpaqueDef(opaque_ty, _) = hir_ty.kind else {
|
||||
span_bug!(
|
||||
hir_ty.span,
|
||||
"lowered return type of async fn is not OpaqueDef: {:?}",
|
||||
hir_ty
|
||||
);
|
||||
};
|
||||
let opaque_ty = hir.item(id);
|
||||
if let hir::ItemKind::OpaqueTy(hir::OpaqueTy {
|
||||
bounds: [hir::GenericBound::Trait(trait_ref, _)],
|
||||
..
|
||||
}) = opaque_ty.kind
|
||||
if let hir::OpaqueTy { bounds: [hir::GenericBound::Trait(trait_ref, _)], .. } = opaque_ty
|
||||
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
|
||||
&& let Some(args) = segment.args
|
||||
&& let [constraint] = args.constraints
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
use rustc_index::IndexSlice;
|
||||
use rustc_middle::mir::{Body, Local};
|
||||
use rustc_middle::ty::{self, RegionVid, TyCtxt};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::region_infer::RegionInferenceContext;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::error::Error;
|
||||
use std::fmt::Debug;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{BufWriter, Write};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
use polonius_engine::{AllFacts as PoloniusFacts, Atom};
|
||||
@ -10,8 +10,8 @@ use rustc_middle::mir::Local;
|
||||
use rustc_middle::ty::{RegionVid, TyCtxt};
|
||||
use rustc_mir_dataflow::move_paths::MovePathIndex;
|
||||
|
||||
use crate::location::{LocationIndex, LocationTable};
|
||||
use crate::BorrowIndex;
|
||||
use crate::location::{LocationIndex, LocationTable};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct RustcFacts;
|
||||
@ -127,7 +127,7 @@ impl<'w> FactWriter<'w> {
|
||||
T: FactRow,
|
||||
{
|
||||
let file = &self.dir.join(file_name);
|
||||
let mut file = BufWriter::new(File::create(file)?);
|
||||
let mut file = File::create_buffered(file)?;
|
||||
for row in rows {
|
||||
row.write(&mut file, self.location_table)?;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#![doc(rust_logo)]
|
||||
#![feature(assert_matches)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![feature(file_buffered)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(never_type)]
|
||||
#![feature(rustc_attrs)]
|
||||
@ -19,7 +19,6 @@ use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
|
||||
use consumers::{BodyWithBorrowckFacts, ConsumerOptions};
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
@ -37,13 +36,13 @@ use rustc_middle::mir::*;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_mir_dataflow::Analysis;
|
||||
use rustc_mir_dataflow::impls::{
|
||||
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
|
||||
};
|
||||
use rustc_mir_dataflow::move_paths::{
|
||||
InitIndex, InitLocation, LookupResult, MoveData, MoveOutIndex, MovePathIndex,
|
||||
};
|
||||
use rustc_mir_dataflow::Analysis;
|
||||
use rustc_session::lint::builtin::UNUSED_MUT;
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_target::abi::FieldIdx;
|
||||
@ -83,10 +82,10 @@ mod util;
|
||||
pub mod consumers;
|
||||
|
||||
use borrow_set::{BorrowData, BorrowSet};
|
||||
use dataflow::{BorrowIndex, BorrowckFlowState as Flows, BorrowckResults, Borrows};
|
||||
use dataflow::{BorrowIndex, BorrowckDomain, BorrowckResults, Borrows};
|
||||
use nll::PoloniusOutput;
|
||||
use place_ext::PlaceExt;
|
||||
use places_conflict::{places_conflict, PlaceConflictBias};
|
||||
use places_conflict::{PlaceConflictBias, places_conflict};
|
||||
use region_infer::RegionInferenceContext;
|
||||
use renumber::RegionCtxt;
|
||||
|
||||
@ -200,8 +199,7 @@ fn do_mir_borrowck<'tcx>(
|
||||
.into_results_cursor(body);
|
||||
|
||||
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(def).is_fn_or_closure();
|
||||
let borrow_set =
|
||||
Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data));
|
||||
let borrow_set = BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data);
|
||||
|
||||
// Compute non-lexical lifetimes.
|
||||
let nll::NllOutput {
|
||||
@ -245,8 +243,6 @@ fn do_mir_borrowck<'tcx>(
|
||||
// usage significantly on some benchmarks.
|
||||
drop(flow_inits);
|
||||
|
||||
let regioncx = Rc::new(regioncx);
|
||||
|
||||
let flow_borrows = Borrows::new(tcx, body, ®ioncx, &borrow_set)
|
||||
.into_engine(tcx, body)
|
||||
.pass_name("borrowck")
|
||||
@ -288,10 +284,10 @@ fn do_mir_borrowck<'tcx>(
|
||||
access_place_error_reported: Default::default(),
|
||||
reservation_error_reported: Default::default(),
|
||||
uninitialized_error_reported: Default::default(),
|
||||
regioncx: regioncx.clone(),
|
||||
regioncx: ®ioncx,
|
||||
used_mut: Default::default(),
|
||||
used_mut_upvars: SmallVec::new(),
|
||||
borrow_set: Rc::clone(&borrow_set),
|
||||
borrow_set: &borrow_set,
|
||||
upvars: &[],
|
||||
local_names: IndexVec::from_elem(None, &promoted_body.local_decls),
|
||||
region_names: RefCell::default(),
|
||||
@ -304,11 +300,11 @@ fn do_mir_borrowck<'tcx>(
|
||||
promoted_mbcx.report_move_errors();
|
||||
diags = promoted_mbcx.diags;
|
||||
|
||||
struct MoveVisitor<'a, 'b, 'mir, 'infcx, 'tcx> {
|
||||
ctxt: &'a mut MirBorrowckCtxt<'b, 'mir, 'infcx, 'tcx>,
|
||||
struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
|
||||
ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for MoveVisitor<'_, '_, '_, '_, 'tcx> {
|
||||
impl<'tcx> Visitor<'tcx> for MoveVisitor<'_, '_, '_, 'tcx> {
|
||||
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
|
||||
if let Operand::Move(place) = operand {
|
||||
self.ctxt.check_movable_place(location, *place);
|
||||
@ -329,10 +325,10 @@ fn do_mir_borrowck<'tcx>(
|
||||
access_place_error_reported: Default::default(),
|
||||
reservation_error_reported: Default::default(),
|
||||
uninitialized_error_reported: Default::default(),
|
||||
regioncx: Rc::clone(®ioncx),
|
||||
regioncx: ®ioncx,
|
||||
used_mut: Default::default(),
|
||||
used_mut_upvars: SmallVec::new(),
|
||||
borrow_set: Rc::clone(&borrow_set),
|
||||
borrow_set: &borrow_set,
|
||||
upvars: tcx.closure_captures(def),
|
||||
local_names,
|
||||
region_names: RefCell::default(),
|
||||
@ -522,10 +518,10 @@ impl<'tcx> Deref for BorrowckInferCtxt<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
struct MirBorrowckCtxt<'a, 'mir, 'infcx, 'tcx> {
|
||||
struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
|
||||
infcx: &'infcx BorrowckInferCtxt<'tcx>,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
body: &'mir Body<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
move_data: &'a MoveData<'tcx>,
|
||||
|
||||
/// Map from MIR `Location` to `LocationIndex`; created
|
||||
@ -569,10 +565,10 @@ struct MirBorrowckCtxt<'a, 'mir, 'infcx, 'tcx> {
|
||||
used_mut_upvars: SmallVec<[FieldIdx; 8]>,
|
||||
/// Region inference context. This contains the results from region inference and lets us e.g.
|
||||
/// find out which CFG points are contained in each borrow region.
|
||||
regioncx: Rc<RegionInferenceContext<'tcx>>,
|
||||
regioncx: &'a RegionInferenceContext<'tcx>,
|
||||
|
||||
/// The set of borrows extracted from the MIR
|
||||
borrow_set: Rc<BorrowSet<'tcx>>,
|
||||
borrow_set: &'a BorrowSet<'tcx>,
|
||||
|
||||
/// Information about upvars not necessarily preserved in types or MIR
|
||||
upvars: &'tcx [&'tcx ty::CapturedPlace<'tcx>],
|
||||
@ -588,7 +584,7 @@ struct MirBorrowckCtxt<'a, 'mir, 'infcx, 'tcx> {
|
||||
next_region_name: RefCell<usize>,
|
||||
|
||||
/// Results of Polonius analysis.
|
||||
polonius_output: Option<Rc<PoloniusOutput>>,
|
||||
polonius_output: Option<Box<PoloniusOutput>>,
|
||||
|
||||
diags: diags::BorrowckDiags<'infcx, 'tcx>,
|
||||
move_errors: Vec<MoveError<'tcx>>,
|
||||
@ -599,28 +595,28 @@ struct MirBorrowckCtxt<'a, 'mir, 'infcx, 'tcx> {
|
||||
// 2. loans made in overlapping scopes do not conflict
|
||||
// 3. assignments do not affect things loaned out as immutable
|
||||
// 4. moves do not affect things loaned out in any way
|
||||
impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
|
||||
for MirBorrowckCtxt<'a, 'mir, '_, 'tcx>
|
||||
impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
|
||||
for MirBorrowckCtxt<'a, '_, 'tcx>
|
||||
{
|
||||
type FlowState = Flows<'a, 'mir, 'tcx>;
|
||||
type Domain = BorrowckDomain<'a, 'tcx>;
|
||||
|
||||
fn visit_statement_before_primary_effect(
|
||||
&mut self,
|
||||
_results: &mut R,
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
stmt: &'mir Statement<'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
stmt: &'a Statement<'tcx>,
|
||||
location: Location,
|
||||
) {
|
||||
debug!("MirBorrowckCtxt::process_statement({:?}, {:?}): {:?}", location, stmt, flow_state);
|
||||
debug!("MirBorrowckCtxt::process_statement({:?}, {:?}): {:?}", location, stmt, state);
|
||||
let span = stmt.source_info.span;
|
||||
|
||||
self.check_activations(location, span, flow_state);
|
||||
self.check_activations(location, span, state);
|
||||
|
||||
match &stmt.kind {
|
||||
StatementKind::Assign(box (lhs, rhs)) => {
|
||||
self.consume_rvalue(location, (rhs, span), flow_state);
|
||||
self.consume_rvalue(location, (rhs, span), state);
|
||||
|
||||
self.mutate_place(location, (*lhs, span), Shallow(None), flow_state);
|
||||
self.mutate_place(location, (*lhs, span), Shallow(None), state);
|
||||
}
|
||||
StatementKind::FakeRead(box (_, place)) => {
|
||||
// Read for match doesn't access any memory and is used to
|
||||
@ -637,11 +633,11 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
|
||||
location,
|
||||
InitializationRequiringAction::Use,
|
||||
(place.as_ref(), span),
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
}
|
||||
StatementKind::Intrinsic(box kind) => match kind {
|
||||
NonDivergingIntrinsic::Assume(op) => self.consume_operand(location, (op, span), flow_state),
|
||||
NonDivergingIntrinsic::Assume(op) => self.consume_operand(location, (op, span), state),
|
||||
NonDivergingIntrinsic::CopyNonOverlapping(..) => span_bug!(
|
||||
span,
|
||||
"Unexpected CopyNonOverlapping, should only appear after lower_intrinsics",
|
||||
@ -662,7 +658,7 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
|
||||
(Place::from(*local), span),
|
||||
(Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
|
||||
LocalMutationIsAllowed::Yes,
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
}
|
||||
StatementKind::Nop
|
||||
@ -677,18 +673,18 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
|
||||
fn visit_terminator_before_primary_effect(
|
||||
&mut self,
|
||||
_results: &mut R,
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
term: &'mir Terminator<'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
term: &'a Terminator<'tcx>,
|
||||
loc: Location,
|
||||
) {
|
||||
debug!("MirBorrowckCtxt::process_terminator({:?}, {:?}): {:?}", loc, term, flow_state);
|
||||
debug!("MirBorrowckCtxt::process_terminator({:?}, {:?}): {:?}", loc, term, state);
|
||||
let span = term.source_info.span;
|
||||
|
||||
self.check_activations(loc, span, flow_state);
|
||||
self.check_activations(loc, span, state);
|
||||
|
||||
match &term.kind {
|
||||
TerminatorKind::SwitchInt { discr, targets: _ } => {
|
||||
self.consume_operand(loc, (discr, span), flow_state);
|
||||
self.consume_operand(loc, (discr, span), state);
|
||||
}
|
||||
TerminatorKind::Drop { place, target: _, unwind: _, replace } => {
|
||||
debug!(
|
||||
@ -704,7 +700,7 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
|
||||
(*place, span),
|
||||
(AccessDepth::Drop, Write(write_kind)),
|
||||
LocalMutationIsAllowed::Yes,
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
}
|
||||
TerminatorKind::Call {
|
||||
@ -716,32 +712,33 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
|
||||
call_source: _,
|
||||
fn_span: _,
|
||||
} => {
|
||||
self.consume_operand(loc, (func, span), flow_state);
|
||||
self.consume_operand(loc, (func, span), state);
|
||||
for arg in args {
|
||||
self.consume_operand(loc, (&arg.node, arg.span), flow_state);
|
||||
self.consume_operand(loc, (&arg.node, arg.span), state);
|
||||
}
|
||||
self.mutate_place(loc, (*destination, span), Deep, flow_state);
|
||||
self.mutate_place(loc, (*destination, span), Deep, state);
|
||||
}
|
||||
TerminatorKind::TailCall { func, args, fn_span: _ } => {
|
||||
self.consume_operand(loc, (func, span), flow_state);
|
||||
self.consume_operand(loc, (func, span), state);
|
||||
for arg in args {
|
||||
self.consume_operand(loc, (&arg.node, arg.span), flow_state);
|
||||
self.consume_operand(loc, (&arg.node, arg.span), state);
|
||||
}
|
||||
}
|
||||
TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
|
||||
self.consume_operand(loc, (cond, span), flow_state);
|
||||
self.consume_operand(loc, (cond, span), state);
|
||||
if let AssertKind::BoundsCheck { len, index } = &**msg {
|
||||
self.consume_operand(loc, (len, span), flow_state);
|
||||
self.consume_operand(loc, (index, span), flow_state);
|
||||
self.consume_operand(loc, (len, span), state);
|
||||
self.consume_operand(loc, (index, span), state);
|
||||
}
|
||||
}
|
||||
|
||||
TerminatorKind::Yield { value, resume: _, resume_arg, drop: _ } => {
|
||||
self.consume_operand(loc, (value, span), flow_state);
|
||||
self.mutate_place(loc, (*resume_arg, span), Deep, flow_state);
|
||||
self.consume_operand(loc, (value, span), state);
|
||||
self.mutate_place(loc, (*resume_arg, span), Deep, state);
|
||||
}
|
||||
|
||||
TerminatorKind::InlineAsm {
|
||||
asm_macro: _,
|
||||
template: _,
|
||||
operands,
|
||||
options: _,
|
||||
@ -752,22 +749,17 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
|
||||
for op in operands {
|
||||
match op {
|
||||
InlineAsmOperand::In { reg: _, value } => {
|
||||
self.consume_operand(loc, (value, span), flow_state);
|
||||
self.consume_operand(loc, (value, span), state);
|
||||
}
|
||||
InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
|
||||
if let Some(place) = place {
|
||||
self.mutate_place(loc, (*place, span), Shallow(None), flow_state);
|
||||
self.mutate_place(loc, (*place, span), Shallow(None), state);
|
||||
}
|
||||
}
|
||||
InlineAsmOperand::InOut { reg: _, late: _, in_value, out_place } => {
|
||||
self.consume_operand(loc, (in_value, span), flow_state);
|
||||
self.consume_operand(loc, (in_value, span), state);
|
||||
if let &Some(out_place) = out_place {
|
||||
self.mutate_place(
|
||||
loc,
|
||||
(out_place, span),
|
||||
Shallow(None),
|
||||
flow_state,
|
||||
);
|
||||
self.mutate_place(loc, (out_place, span), Shallow(None), state);
|
||||
}
|
||||
}
|
||||
InlineAsmOperand::Const { value: _ }
|
||||
@ -794,8 +786,8 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
|
||||
fn visit_terminator_after_primary_effect(
|
||||
&mut self,
|
||||
_results: &mut R,
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
term: &'mir Terminator<'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
term: &'a Terminator<'tcx>,
|
||||
loc: Location,
|
||||
) {
|
||||
let span = term.source_info.span;
|
||||
@ -804,9 +796,8 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
|
||||
TerminatorKind::Yield { value: _, resume: _, resume_arg: _, drop: _ } => {
|
||||
if self.movable_coroutine {
|
||||
// Look for any active borrows to locals
|
||||
let borrow_set = self.borrow_set.clone();
|
||||
for i in flow_state.borrows.iter() {
|
||||
let borrow = &borrow_set[i];
|
||||
for i in state.borrows.iter() {
|
||||
let borrow = &self.borrow_set[i];
|
||||
self.check_for_local_borrow(borrow, span);
|
||||
}
|
||||
}
|
||||
@ -820,9 +811,8 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
|
||||
// Often, the storage will already have been killed by an explicit
|
||||
// StorageDead, but we don't always emit those (notably on unwind paths),
|
||||
// so this "extra check" serves as a kind of backup.
|
||||
let borrow_set = self.borrow_set.clone();
|
||||
for i in flow_state.borrows.iter() {
|
||||
let borrow = &borrow_set[i];
|
||||
for i in state.borrows.iter() {
|
||||
let borrow = &self.borrow_set[i];
|
||||
self.check_for_invalidation_at_exit(loc, borrow, span);
|
||||
}
|
||||
}
|
||||
@ -972,8 +962,8 @@ impl InitializationRequiringAction {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
fn body(&self) -> &'mir Body<'tcx> {
|
||||
impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
|
||||
fn body(&self) -> &'a Body<'tcx> {
|
||||
self.body
|
||||
}
|
||||
|
||||
@ -989,7 +979,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
place_span: (Place<'tcx>, Span),
|
||||
kind: (AccessDepth, ReadOrWrite),
|
||||
is_local_mutation_allowed: LocalMutationIsAllowed,
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) {
|
||||
let (sd, rw) = kind;
|
||||
|
||||
@ -1020,11 +1010,10 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
place_span,
|
||||
rw,
|
||||
is_local_mutation_allowed,
|
||||
flow_state,
|
||||
state,
|
||||
location,
|
||||
);
|
||||
let conflict_error =
|
||||
self.check_access_for_conflict(location, place_span, sd, rw, flow_state);
|
||||
let conflict_error = self.check_access_for_conflict(location, place_span, sd, rw, state);
|
||||
|
||||
if conflict_error || mutability_error {
|
||||
debug!("access_place: logging error place_span=`{:?}` kind=`{:?}`", place_span, kind);
|
||||
@ -1032,29 +1021,28 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self, flow_state))]
|
||||
#[instrument(level = "debug", skip(self, state))]
|
||||
fn check_access_for_conflict(
|
||||
&mut self,
|
||||
location: Location,
|
||||
place_span: (Place<'tcx>, Span),
|
||||
sd: AccessDepth,
|
||||
rw: ReadOrWrite,
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) -> bool {
|
||||
let mut error_reported = false;
|
||||
let borrow_set = Rc::clone(&self.borrow_set);
|
||||
|
||||
// Use polonius output if it has been enabled.
|
||||
let mut polonius_output;
|
||||
let borrows_in_scope = if let Some(polonius) = &self.polonius_output {
|
||||
let location = self.location_table.start_index(location);
|
||||
polonius_output = BitSet::new_empty(borrow_set.len());
|
||||
polonius_output = BitSet::new_empty(self.borrow_set.len());
|
||||
for &idx in polonius.errors_at(location) {
|
||||
polonius_output.insert(idx);
|
||||
}
|
||||
&polonius_output
|
||||
} else {
|
||||
&flow_state.borrows
|
||||
&state.borrows
|
||||
};
|
||||
|
||||
each_borrow_involving_path(
|
||||
@ -1062,7 +1050,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
self.infcx.tcx,
|
||||
self.body,
|
||||
(sd, place_span.0),
|
||||
&borrow_set,
|
||||
self.borrow_set,
|
||||
|borrow_index| borrows_in_scope.contains(borrow_index),
|
||||
|this, borrow_index, borrow| match (rw, borrow.kind) {
|
||||
// Obviously an activation is compatible with its own
|
||||
@ -1180,25 +1168,25 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
location: Location,
|
||||
place_span: (Place<'tcx>, Span),
|
||||
kind: AccessDepth,
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) {
|
||||
// Write of P[i] or *P requires P init'd.
|
||||
self.check_if_assigned_path_is_moved(location, place_span, flow_state);
|
||||
self.check_if_assigned_path_is_moved(location, place_span, state);
|
||||
|
||||
self.access_place(
|
||||
location,
|
||||
place_span,
|
||||
(kind, Write(WriteKind::Mutate)),
|
||||
LocalMutationIsAllowed::No,
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
}
|
||||
|
||||
fn consume_rvalue(
|
||||
&mut self,
|
||||
location: Location,
|
||||
(rvalue, span): (&'mir Rvalue<'tcx>, Span),
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
(rvalue, span): (&'a Rvalue<'tcx>, Span),
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) {
|
||||
match rvalue {
|
||||
&Rvalue::Ref(_ /*rgn*/, bk, place) => {
|
||||
@ -1224,7 +1212,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
(place, span),
|
||||
access_kind,
|
||||
LocalMutationIsAllowed::No,
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
|
||||
let action = if bk == BorrowKind::Fake(FakeBorrowKind::Shallow) {
|
||||
@ -1237,7 +1225,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
location,
|
||||
action,
|
||||
(place.as_ref(), span),
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
}
|
||||
|
||||
@ -1257,14 +1245,14 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
(place, span),
|
||||
access_kind,
|
||||
LocalMutationIsAllowed::No,
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
|
||||
self.check_if_path_or_subpath_is_moved(
|
||||
location,
|
||||
InitializationRequiringAction::Borrow,
|
||||
(place.as_ref(), span),
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
}
|
||||
|
||||
@ -1275,7 +1263,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
| Rvalue::UnaryOp(_ /*un_op*/, operand)
|
||||
| Rvalue::Cast(_ /*cast_kind*/, operand, _ /*ty*/)
|
||||
| Rvalue::ShallowInitBox(operand, _ /*ty*/) => {
|
||||
self.consume_operand(location, (operand, span), flow_state)
|
||||
self.consume_operand(location, (operand, span), state)
|
||||
}
|
||||
|
||||
&Rvalue::CopyForDeref(place) => {
|
||||
@ -1284,7 +1272,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
(place, span),
|
||||
(Deep, Read(ReadKind::Copy)),
|
||||
LocalMutationIsAllowed::No,
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
|
||||
// Finally, check if path was already moved.
|
||||
@ -1292,7 +1280,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
location,
|
||||
InitializationRequiringAction::Use,
|
||||
(place.as_ref(), span),
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
}
|
||||
|
||||
@ -1307,19 +1295,19 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
(place, span),
|
||||
(Shallow(af), Read(ReadKind::Copy)),
|
||||
LocalMutationIsAllowed::No,
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
self.check_if_path_or_subpath_is_moved(
|
||||
location,
|
||||
InitializationRequiringAction::Use,
|
||||
(place.as_ref(), span),
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
}
|
||||
|
||||
Rvalue::BinaryOp(_bin_op, box (operand1, operand2)) => {
|
||||
self.consume_operand(location, (operand1, span), flow_state);
|
||||
self.consume_operand(location, (operand2, span), flow_state);
|
||||
self.consume_operand(location, (operand1, span), state);
|
||||
self.consume_operand(location, (operand2, span), state);
|
||||
}
|
||||
|
||||
Rvalue::NullaryOp(_op, _ty) => {
|
||||
@ -1349,7 +1337,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
}
|
||||
|
||||
for operand in operands {
|
||||
self.consume_operand(location, (operand, span), flow_state);
|
||||
self.consume_operand(location, (operand, span), state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1455,8 +1443,8 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
fn consume_operand(
|
||||
&mut self,
|
||||
location: Location,
|
||||
(operand, span): (&'mir Operand<'tcx>, Span),
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
(operand, span): (&'a Operand<'tcx>, Span),
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) {
|
||||
match *operand {
|
||||
Operand::Copy(place) => {
|
||||
@ -1467,7 +1455,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
(place, span),
|
||||
(Deep, Read(ReadKind::Copy)),
|
||||
LocalMutationIsAllowed::No,
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
|
||||
// Finally, check if path was already moved.
|
||||
@ -1475,7 +1463,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
location,
|
||||
InitializationRequiringAction::Use,
|
||||
(place.as_ref(), span),
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
}
|
||||
Operand::Move(place) => {
|
||||
@ -1488,7 +1476,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
(place, span),
|
||||
(Deep, Write(WriteKind::Move)),
|
||||
LocalMutationIsAllowed::Yes,
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
|
||||
// Finally, check if path was already moved.
|
||||
@ -1496,7 +1484,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
location,
|
||||
InitializationRequiringAction::Use,
|
||||
(place.as_ref(), span),
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
}
|
||||
Operand::Constant(_) => {}
|
||||
@ -1580,14 +1568,13 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
&mut self,
|
||||
location: Location,
|
||||
span: Span,
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) {
|
||||
// Two-phase borrow support: For each activation that is newly
|
||||
// generated at this statement, check if it interferes with
|
||||
// another borrow.
|
||||
let borrow_set = self.borrow_set.clone();
|
||||
for &borrow_index in borrow_set.activations_at_location(location) {
|
||||
let borrow = &borrow_set[borrow_index];
|
||||
for &borrow_index in self.borrow_set.activations_at_location(location) {
|
||||
let borrow = &self.borrow_set[borrow_index];
|
||||
|
||||
// only mutable borrows should be 2-phase
|
||||
assert!(match borrow.kind {
|
||||
@ -1600,7 +1587,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
(borrow.borrowed_place, span),
|
||||
(Deep, Activation(WriteKind::MutableBorrow(borrow.kind), borrow_index)),
|
||||
LocalMutationIsAllowed::No,
|
||||
flow_state,
|
||||
state,
|
||||
);
|
||||
// We do not need to call `check_if_path_or_subpath_is_moved`
|
||||
// again, as we already called it when we made the
|
||||
@ -1618,13 +1605,9 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
match elem {
|
||||
ProjectionElem::Deref => match place_ty.ty.kind() {
|
||||
ty::Ref(..) | ty::RawPtr(..) => {
|
||||
self.move_errors.push(MoveError::new(
|
||||
place,
|
||||
location,
|
||||
BorrowedContent {
|
||||
target_place: place_ref.project_deeper(&[elem], tcx),
|
||||
},
|
||||
));
|
||||
self.move_errors.push(MoveError::new(place, location, BorrowedContent {
|
||||
target_place: place_ref.project_deeper(&[elem], tcx),
|
||||
}));
|
||||
return;
|
||||
}
|
||||
ty::Adt(adt, _) => {
|
||||
@ -1744,9 +1727,9 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
location: Location,
|
||||
desired_action: InitializationRequiringAction,
|
||||
place_span: (PlaceRef<'tcx>, Span),
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) {
|
||||
let maybe_uninits = &flow_state.uninits;
|
||||
let maybe_uninits = &state.uninits;
|
||||
|
||||
// Bad scenarios:
|
||||
//
|
||||
@ -1849,9 +1832,9 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
location: Location,
|
||||
desired_action: InitializationRequiringAction,
|
||||
place_span: (PlaceRef<'tcx>, Span),
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) {
|
||||
let maybe_uninits = &flow_state.uninits;
|
||||
let maybe_uninits = &state.uninits;
|
||||
|
||||
// Bad scenarios:
|
||||
//
|
||||
@ -1868,7 +1851,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
// must have been initialized for the use to be sound.
|
||||
// 6. Move of `a.b.c` then reinit of `a.b.c.d`, use of `a.b.c.d`
|
||||
|
||||
self.check_if_full_path_is_moved(location, desired_action, place_span, flow_state);
|
||||
self.check_if_full_path_is_moved(location, desired_action, place_span, state);
|
||||
|
||||
if let Some((place_base, ProjectionElem::Subslice { from, to, from_end: false })) =
|
||||
place_span.0.last_projection()
|
||||
@ -1948,7 +1931,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
&mut self,
|
||||
location: Location,
|
||||
(place, span): (Place<'tcx>, Span),
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) {
|
||||
debug!("check_if_assigned_path_is_moved place: {:?}", place);
|
||||
|
||||
@ -1970,7 +1953,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
ProjectionElem::Deref => {
|
||||
self.check_if_full_path_is_moved(
|
||||
location, InitializationRequiringAction::Use,
|
||||
(place_base, span), flow_state);
|
||||
(place_base, span), state);
|
||||
// (base initialized; no need to
|
||||
// recur further)
|
||||
break;
|
||||
@ -1990,7 +1973,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
ty::Adt(def, _) if def.has_dtor(tcx) => {
|
||||
self.check_if_path_or_subpath_is_moved(
|
||||
location, InitializationRequiringAction::Assignment,
|
||||
(place_base, span), flow_state);
|
||||
(place_base, span), state);
|
||||
|
||||
// (base initialized; no need to
|
||||
// recur further)
|
||||
@ -2000,7 +1983,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
// Once `let s; s.x = V; read(s.x);`,
|
||||
// is allowed, remove this match arm.
|
||||
ty::Adt(..) | ty::Tuple(..) => {
|
||||
check_parent_of_field(self, location, place_base, span, flow_state);
|
||||
check_parent_of_field(self, location, place_base, span, state);
|
||||
}
|
||||
|
||||
_ => {}
|
||||
@ -2009,12 +1992,12 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_parent_of_field<'mir, 'tcx>(
|
||||
this: &mut MirBorrowckCtxt<'_, 'mir, '_, 'tcx>,
|
||||
fn check_parent_of_field<'a, 'tcx>(
|
||||
this: &mut MirBorrowckCtxt<'a, '_, 'tcx>,
|
||||
location: Location,
|
||||
base: PlaceRef<'tcx>,
|
||||
span: Span,
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) {
|
||||
// rust-lang/rust#21232: Until Rust allows reads from the
|
||||
// initialized parts of partially initialized structs, we
|
||||
@ -2047,7 +2030,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
|
||||
// Shallow so that we'll stop at any dereference; we'll
|
||||
// report errors about issues with such bases elsewhere.
|
||||
let maybe_uninits = &flow_state.uninits;
|
||||
let maybe_uninits = &state.uninits;
|
||||
|
||||
// Find the shortest uninitialized prefix you can reach
|
||||
// without going over a Deref.
|
||||
@ -2074,12 +2057,12 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
// no move out from an earlier location) then this is an attempt at initialization
|
||||
// of the union - we should error in that case.
|
||||
let tcx = this.infcx.tcx;
|
||||
if base.ty(this.body(), tcx).ty.is_union() {
|
||||
if this.move_data.path_map[mpi].iter().any(|moi| {
|
||||
if base.ty(this.body(), tcx).ty.is_union()
|
||||
&& this.move_data.path_map[mpi].iter().any(|moi| {
|
||||
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
|
||||
}) {
|
||||
return;
|
||||
}
|
||||
})
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.report_use_of_moved_or_uninitialized(
|
||||
@ -2105,7 +2088,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
(place, span): (Place<'tcx>, Span),
|
||||
kind: ReadOrWrite,
|
||||
is_local_mutation_allowed: LocalMutationIsAllowed,
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
location: Location,
|
||||
) -> bool {
|
||||
debug!(
|
||||
@ -2129,7 +2112,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
};
|
||||
match self.is_mutable(place.as_ref(), is_local_mutation_allowed) {
|
||||
Ok(root_place) => {
|
||||
self.add_used_mut(root_place, flow_state);
|
||||
self.add_used_mut(root_place, state);
|
||||
return false;
|
||||
}
|
||||
Err(place_err) => {
|
||||
@ -2141,7 +2124,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
Reservation(WriteKind::Mutate) | Write(WriteKind::Mutate) => {
|
||||
match self.is_mutable(place.as_ref(), is_local_mutation_allowed) {
|
||||
Ok(root_place) => {
|
||||
self.add_used_mut(root_place, flow_state);
|
||||
self.add_used_mut(root_place, state);
|
||||
return false;
|
||||
}
|
||||
Err(place_err) => {
|
||||
@ -2199,7 +2182,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
// partial initialization, do not complain about mutability
|
||||
// errors except for actual mutation (as opposed to an attempt
|
||||
// to do a partial initialization).
|
||||
let previously_initialized = self.is_local_ever_initialized(place.local, flow_state);
|
||||
let previously_initialized = self.is_local_ever_initialized(place.local, state);
|
||||
|
||||
// at this point, we have set up the error reporting state.
|
||||
if let Some(init_index) = previously_initialized {
|
||||
@ -2221,22 +2204,22 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
|
||||
fn is_local_ever_initialized(
|
||||
&self,
|
||||
local: Local,
|
||||
flow_state: &Flows<'_, 'mir, 'tcx>,
|
||||
state: &BorrowckDomain<'a, 'tcx>,
|
||||
) -> Option<InitIndex> {
|
||||
let mpi = self.move_data.rev_lookup.find_local(local)?;
|
||||
let ii = &self.move_data.init_path_map[mpi];
|
||||
ii.into_iter().find(|&&index| flow_state.ever_inits.contains(index)).copied()
|
||||
ii.into_iter().find(|&&index| state.ever_inits.contains(index)).copied()
|
||||
}
|
||||
|
||||
/// Adds the place into the used mutable variables set
|
||||
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, flow_state: &Flows<'_, 'mir, 'tcx>) {
|
||||
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, state: &BorrowckDomain<'a, 'tcx>) {
|
||||
match root_place {
|
||||
RootPlace { place_local: local, place_projection: [], is_local_mutation_allowed } => {
|
||||
// If the local may have been initialized, and it is now currently being
|
||||
// mutated, then it is justified to be annotated with the `mut`
|
||||
// keyword, since the mutation may be a possible reassignment.
|
||||
if is_local_mutation_allowed != LocalMutationIsAllowed::Yes
|
||||
&& self.is_local_ever_initialized(local, flow_state).is_some()
|
||||
&& self.is_local_ever_initialized(local, state).is_some()
|
||||
{
|
||||
self.used_mut.insert(local);
|
||||
}
|
||||
@ -2484,7 +2467,7 @@ mod diags {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) {
|
||||
self.diags.buffer_error(diag);
|
||||
}
|
||||
@ -2522,7 +2505,7 @@ mod diags {
|
||||
}
|
||||
|
||||
pub(crate) fn emit_errors(&mut self) -> Option<ErrorGuaranteed> {
|
||||
let mut res = None;
|
||||
let mut res = self.infcx.tainted_by_errors();
|
||||
|
||||
// Buffer any move errors that we collected and de-duplicated.
|
||||
for (_, (_, diag)) in std::mem::take(&mut self.diags.buffered_move_errors) {
|
||||
|
||||
@ -9,17 +9,17 @@ use polonius_engine::{Algorithm, Output};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_index::IndexSlice;
|
||||
use rustc_middle::mir::pretty::{dump_mir_with_options, PrettyPrintMirOptions};
|
||||
use rustc_middle::mir::pretty::{PrettyPrintMirOptions, dump_mir_with_options};
|
||||
use rustc_middle::mir::{
|
||||
create_dump_file, dump_enabled, dump_mir, Body, ClosureOutlivesSubject,
|
||||
ClosureRegionRequirements, PassWhere, Promoted,
|
||||
Body, ClosureOutlivesSubject, ClosureRegionRequirements, PassWhere, Promoted, create_dump_file,
|
||||
dump_enabled, dump_mir,
|
||||
};
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{self, OpaqueHiddenType, TyCtxt};
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
use rustc_mir_dataflow::move_paths::MoveData;
|
||||
use rustc_mir_dataflow::points::DenseLocationMap;
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_session::config::MirIncludeSpans;
|
||||
use rustc_span::symbol::sym;
|
||||
use tracing::{debug, instrument};
|
||||
@ -32,7 +32,7 @@ use crate::location::LocationTable;
|
||||
use crate::region_infer::RegionInferenceContext;
|
||||
use crate::type_check::{self, MirTypeckRegionConstraints, MirTypeckResults};
|
||||
use crate::universal_regions::UniversalRegions;
|
||||
use crate::{polonius, renumber, BorrowckInferCtxt};
|
||||
use crate::{BorrowckInferCtxt, polonius, renumber};
|
||||
|
||||
pub type PoloniusOutput = Output<RustcFacts>;
|
||||
|
||||
@ -42,7 +42,7 @@ pub(crate) struct NllOutput<'tcx> {
|
||||
pub regioncx: RegionInferenceContext<'tcx>,
|
||||
pub opaque_type_values: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
|
||||
pub polonius_input: Option<Box<AllFacts>>,
|
||||
pub polonius_output: Option<Rc<PoloniusOutput>>,
|
||||
pub polonius_output: Option<Box<PoloniusOutput>>,
|
||||
pub opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
|
||||
pub nll_errors: RegionErrors<'tcx>,
|
||||
}
|
||||
@ -75,14 +75,14 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
|
||||
/// Computes the (non-lexical) regions from the input MIR.
|
||||
///
|
||||
/// This may result in errors being reported.
|
||||
pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
pub(crate) fn compute_regions<'a, 'tcx>(
|
||||
infcx: &BorrowckInferCtxt<'tcx>,
|
||||
universal_regions: UniversalRegions<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
promoted: &IndexSlice<Promoted, Body<'tcx>>,
|
||||
location_table: &LocationTable,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
flow_inits: &mut ResultsCursor<'cx, 'tcx, MaybeInitializedPlaces<'_, 'cx, 'tcx>>,
|
||||
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
borrow_set: &BorrowSet<'tcx>,
|
||||
upvars: &[&ty::CapturedPlace<'tcx>],
|
||||
@ -98,7 +98,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
|
||||
let universal_regions = Rc::new(universal_regions);
|
||||
|
||||
let elements = &Rc::new(DenseLocationMap::new(body));
|
||||
let elements = Rc::new(DenseLocationMap::new(body));
|
||||
|
||||
// Run the MIR type-checker.
|
||||
let MirTypeckResults { constraints, universal_region_relations, opaque_type_values } =
|
||||
@ -107,13 +107,13 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
param_env,
|
||||
body,
|
||||
promoted,
|
||||
&universal_regions,
|
||||
universal_regions.clone(),
|
||||
location_table,
|
||||
borrow_set,
|
||||
&mut all_facts,
|
||||
flow_inits,
|
||||
move_data,
|
||||
elements,
|
||||
elements.clone(),
|
||||
upvars,
|
||||
);
|
||||
|
||||
@ -184,7 +184,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
let algorithm = Algorithm::from_str(&algorithm).unwrap();
|
||||
debug!("compute_regions: using polonius algorithm {:?}", algorithm);
|
||||
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_analysis");
|
||||
Some(Rc::new(Output::compute(all_facts, algorithm, false)))
|
||||
Some(Box::new(Output::compute(all_facts, algorithm, false)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -301,13 +301,13 @@ pub(super) fn dump_nll_mir<'tcx>(
|
||||
|
||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
pub(super) fn dump_annotation<'tcx, 'cx>(
|
||||
infcx: &'cx BorrowckInferCtxt<'tcx>,
|
||||
pub(super) fn dump_annotation<'tcx, 'infcx>(
|
||||
infcx: &'infcx BorrowckInferCtxt<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
regioncx: &RegionInferenceContext<'tcx>,
|
||||
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
|
||||
opaque_type_values: &FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
|
||||
diags: &mut crate::diags::BorrowckDiags<'cx, 'tcx>,
|
||||
diags: &mut crate::diags::BorrowckDiags<'infcx, 'tcx>,
|
||||
) {
|
||||
let tcx = infcx.tcx;
|
||||
let base_def_id = tcx.typeck_root_def_id(body.source.def_id());
|
||||
|
||||
@ -5,7 +5,7 @@ use rustc_target::abi::FieldIdx;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation};
|
||||
use crate::{places_conflict, AccessDepth, BorrowIndex};
|
||||
use crate::{AccessDepth, BorrowIndex, places_conflict};
|
||||
|
||||
/// Returns `true` if the borrow represented by `kind` is
|
||||
/// allowed to be split into separate Reservation and
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
//! we can prove overlap one way or another. Essentially, we treat `Overlap` as
|
||||
//! a monoid and report a conflict if the product ends up not being `Disjoint`.
|
||||
//!
|
||||
//! At each step, if we didn't run out of borrow or place, we know that our elements
|
||||
//! On each step, if we didn't run out of borrow or place, we know that our elements
|
||||
//! have the same type, and that they only overlap if they are the identical.
|
||||
//!
|
||||
//! For example, if we are comparing these:
|
||||
|
||||
@ -32,18 +32,18 @@ pub(super) fn emit_loan_invalidations<'tcx>(
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
|
||||
struct LoanInvalidationsGenerator<'cx, 'tcx> {
|
||||
struct LoanInvalidationsGenerator<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
all_facts: &'cx mut AllFacts,
|
||||
location_table: &'cx LocationTable,
|
||||
body: &'cx Body<'tcx>,
|
||||
dominators: &'cx Dominators<BasicBlock>,
|
||||
borrow_set: &'cx BorrowSet<'tcx>,
|
||||
all_facts: &'a mut AllFacts,
|
||||
location_table: &'a LocationTable,
|
||||
body: &'a Body<'tcx>,
|
||||
dominators: &'a Dominators<BasicBlock>,
|
||||
borrow_set: &'a BorrowSet<'tcx>,
|
||||
}
|
||||
|
||||
/// Visits the whole MIR and generates `invalidates()` facts.
|
||||
/// Most of the code implementing this was stolen from `borrow_check/mod.rs`.
|
||||
impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
|
||||
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
|
||||
self.check_activations(location);
|
||||
|
||||
@ -169,6 +169,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
TerminatorKind::InlineAsm {
|
||||
asm_macro: _,
|
||||
template: _,
|
||||
operands,
|
||||
options: _,
|
||||
@ -212,7 +213,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> LoanInvalidationsGenerator<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
|
||||
/// Simulates mutation of a place.
|
||||
fn mutate_place(&mut self, location: Location, place: Place<'tcx>, kind: AccessDepth) {
|
||||
self.access_place(
|
||||
|
||||
@ -25,15 +25,15 @@ pub(super) fn emit_loan_kills<'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
struct LoanKillsGenerator<'cx, 'tcx> {
|
||||
struct LoanKillsGenerator<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
all_facts: &'cx mut AllFacts,
|
||||
location_table: &'cx LocationTable,
|
||||
borrow_set: &'cx BorrowSet<'tcx>,
|
||||
body: &'cx Body<'tcx>,
|
||||
all_facts: &'a mut AllFacts,
|
||||
location_table: &'a LocationTable,
|
||||
borrow_set: &'a BorrowSet<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> Visitor<'tcx> for LoanKillsGenerator<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for LoanKillsGenerator<'a, 'tcx> {
|
||||
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
|
||||
// Also record CFG facts here.
|
||||
self.all_facts.cfg_edge.push((
|
||||
|
||||
@ -34,7 +34,7 @@ pub(super) enum PrefixSet {
|
||||
Shallow,
|
||||
}
|
||||
|
||||
impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
|
||||
impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||
/// Returns an iterator over the prefixes of `place`
|
||||
/// (inclusive) from longest to smallest, potentially
|
||||
/// terminating the iteration early based on `kind`.
|
||||
|
||||
@ -23,6 +23,7 @@ use rustc_mir_dataflow::points::DenseLocationMap;
|
||||
use rustc_span::Span;
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
use crate::BorrowckInferCtxt;
|
||||
use crate::constraints::graph::{self, NormalConstraintGraph, RegionGraph};
|
||||
use crate::constraints::{ConstraintSccIndex, OutlivesConstraint, OutlivesConstraintSet};
|
||||
use crate::dataflow::BorrowIndex;
|
||||
@ -33,10 +34,9 @@ use crate::region_infer::reverse_sccs::ReverseSccGraph;
|
||||
use crate::region_infer::values::{
|
||||
LivenessValues, PlaceholderIndices, RegionElement, RegionValues, ToElementIndex,
|
||||
};
|
||||
use crate::type_check::free_region_relations::UniversalRegionRelations;
|
||||
use crate::type_check::Locations;
|
||||
use crate::type_check::free_region_relations::UniversalRegionRelations;
|
||||
use crate::universal_regions::UniversalRegions;
|
||||
use crate::BorrowckInferCtxt;
|
||||
|
||||
mod dump_mir;
|
||||
mod graphviz;
|
||||
@ -407,7 +407,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
|
||||
type_tests: Vec<TypeTest<'tcx>>,
|
||||
liveness_constraints: LivenessValues,
|
||||
elements: &Rc<DenseLocationMap>,
|
||||
elements: Rc<DenseLocationMap>,
|
||||
) -> Self {
|
||||
debug!("universal_regions: {:#?}", universal_regions);
|
||||
debug!("outlives constraints: {:#?}", outlives_constraints);
|
||||
@ -430,7 +430,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
}
|
||||
|
||||
let mut scc_values =
|
||||
RegionValues::new(elements, universal_regions.len(), &placeholder_indices);
|
||||
RegionValues::new(elements, universal_regions.len(), placeholder_indices);
|
||||
|
||||
for region in liveness_constraints.regions() {
|
||||
let scc = constraint_sccs.scc(region);
|
||||
@ -637,7 +637,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
polonius_output: Option<Rc<PoloniusOutput>>,
|
||||
polonius_output: Option<Box<PoloniusOutput>>,
|
||||
) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
|
||||
let mir_def_id = body.source.def_id();
|
||||
self.propagate_constraints();
|
||||
@ -663,7 +663,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
self.check_polonius_subset_errors(
|
||||
outlives_requirements.as_mut(),
|
||||
&mut errors_buffer,
|
||||
polonius_output.expect("Polonius output is unavailable despite `-Z polonius`"),
|
||||
polonius_output
|
||||
.as_ref()
|
||||
.expect("Polonius output is unavailable despite `-Z polonius`"),
|
||||
);
|
||||
} else {
|
||||
self.check_universal_regions(outlives_requirements.as_mut(), &mut errors_buffer);
|
||||
@ -1411,7 +1413,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
&self,
|
||||
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
|
||||
errors_buffer: &mut RegionErrors<'tcx>,
|
||||
polonius_output: Rc<PoloniusOutput>,
|
||||
polonius_output: &PoloniusOutput,
|
||||
) {
|
||||
debug!(
|
||||
"check_polonius_subset_errors: {} subset_errors",
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::OpaqueTyOrigin;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::OpaqueTyOrigin;
|
||||
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, TyCtxtInferExt as _};
|
||||
use rustc_infer::traits::{Obligation, ObligationCause};
|
||||
use rustc_macros::extension;
|
||||
@ -165,10 +165,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
// FIXME(oli-obk): collect multiple spans for better diagnostics down the road.
|
||||
prev.span = prev.span.substitute_dummy(concrete_type.span);
|
||||
} else {
|
||||
result.insert(
|
||||
opaque_type_key.def_id,
|
||||
OpaqueHiddenType { ty, span: concrete_type.span },
|
||||
);
|
||||
result.insert(opaque_type_key.def_id, OpaqueHiddenType {
|
||||
ty,
|
||||
span: concrete_type.span,
|
||||
});
|
||||
}
|
||||
|
||||
// Check that all opaque types have the same region parameters if they have the same
|
||||
@ -329,8 +329,8 @@ fn check_opaque_type_well_formed<'tcx>(
|
||||
) -> Result<Ty<'tcx>, ErrorGuaranteed> {
|
||||
// Only check this for TAIT. RPIT already supports `tests/ui/impl-trait/nested-return-type2.rs`
|
||||
// on stable and we'd break that.
|
||||
let opaque_ty_hir = tcx.hir().expect_item(def_id);
|
||||
let OpaqueTyOrigin::TyAlias { .. } = opaque_ty_hir.expect_opaque_ty().origin else {
|
||||
let opaque_ty_hir = tcx.hir().expect_opaque_ty(def_id);
|
||||
let OpaqueTyOrigin::TyAlias { .. } = opaque_ty_hir.origin else {
|
||||
return Ok(definition_ty);
|
||||
};
|
||||
let param_env = tcx.param_env(def_id);
|
||||
@ -503,8 +503,8 @@ impl<'tcx> LazyOpaqueTyEnv<'tcx> {
|
||||
let &Self { tcx, def_id, .. } = self;
|
||||
let origin = tcx.opaque_type_origin(def_id);
|
||||
let parent = match origin {
|
||||
hir::OpaqueTyOrigin::FnReturn(parent)
|
||||
| hir::OpaqueTyOrigin::AsyncFn(parent)
|
||||
hir::OpaqueTyOrigin::FnReturn { parent, .. }
|
||||
| hir::OpaqueTyOrigin::AsyncFn { parent, .. }
|
||||
| hir::OpaqueTyOrigin::TyAlias { parent, .. } => parent,
|
||||
};
|
||||
let param_env = tcx.param_env(parent);
|
||||
|
||||
@ -5,8 +5,8 @@ use rustc_data_structures::graph;
|
||||
use rustc_data_structures::graph::vec_graph::VecGraph;
|
||||
use rustc_middle::ty::RegionVid;
|
||||
|
||||
use crate::constraints::ConstraintSccIndex;
|
||||
use crate::RegionInferenceContext;
|
||||
use crate::constraints::ConstraintSccIndex;
|
||||
|
||||
pub(crate) struct ReverseSccGraph {
|
||||
graph: VecGraph<ConstraintSccIndex>,
|
||||
|
||||
@ -2,9 +2,9 @@ use std::fmt::Debug;
|
||||
use std::rc::Rc;
|
||||
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
|
||||
use rustc_index::Idx;
|
||||
use rustc_index::bit_set::SparseBitMatrix;
|
||||
use rustc_index::interval::{IntervalSet, SparseIntervalMatrix};
|
||||
use rustc_index::Idx;
|
||||
use rustc_middle::mir::{BasicBlock, Location};
|
||||
use rustc_middle::ty::{self, RegionVid};
|
||||
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
|
||||
@ -118,10 +118,8 @@ impl LivenessValues {
|
||||
debug!("LivenessValues::add_location(region={:?}, location={:?})", region, location);
|
||||
if let Some(points) = &mut self.points {
|
||||
points.insert(region, point);
|
||||
} else {
|
||||
if self.elements.point_in_range(point) {
|
||||
self.live_regions.as_mut().unwrap().insert(region);
|
||||
}
|
||||
} else if self.elements.point_in_range(point) {
|
||||
self.live_regions.as_mut().unwrap().insert(region);
|
||||
}
|
||||
|
||||
// When available, record the loans flowing into this region as live at the given point.
|
||||
@ -137,10 +135,8 @@ impl LivenessValues {
|
||||
debug!("LivenessValues::add_points(region={:?}, points={:?})", region, points);
|
||||
if let Some(this) = &mut self.points {
|
||||
this.union_row(region, points);
|
||||
} else {
|
||||
if points.iter().any(|point| self.elements.point_in_range(point)) {
|
||||
self.live_regions.as_mut().unwrap().insert(region);
|
||||
}
|
||||
} else if points.iter().any(|point| self.elements.point_in_range(point)) {
|
||||
self.live_regions.as_mut().unwrap().insert(region);
|
||||
}
|
||||
|
||||
// When available, record the loans flowing into this region as live at the given points.
|
||||
@ -279,15 +275,16 @@ impl<N: Idx> RegionValues<N> {
|
||||
/// Each of the regions in num_region_variables will be initialized with an
|
||||
/// empty set of points and no causal information.
|
||||
pub(crate) fn new(
|
||||
elements: &Rc<DenseLocationMap>,
|
||||
elements: Rc<DenseLocationMap>,
|
||||
num_universal_regions: usize,
|
||||
placeholder_indices: &Rc<PlaceholderIndices>,
|
||||
placeholder_indices: Rc<PlaceholderIndices>,
|
||||
) -> Self {
|
||||
let num_points = elements.num_points();
|
||||
let num_placeholders = placeholder_indices.len();
|
||||
Self {
|
||||
elements: elements.clone(),
|
||||
points: SparseIntervalMatrix::new(elements.num_points()),
|
||||
placeholder_indices: placeholder_indices.clone(),
|
||||
elements,
|
||||
points: SparseIntervalMatrix::new(num_points),
|
||||
placeholder_indices,
|
||||
free_regions: SparseBitMatrix::new(num_universal_regions),
|
||||
placeholders: SparseBitMatrix::new(num_placeholders),
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ use crate::BorrowckInferCtxt;
|
||||
/// Replaces all free regions appearing in the MIR with fresh
|
||||
/// inference variables, returning the number of variables created.
|
||||
#[instrument(skip(infcx, body, promoted), level = "debug")]
|
||||
pub fn renumber_mir<'tcx>(
|
||||
pub(crate) fn renumber_mir<'tcx>(
|
||||
infcx: &BorrowckInferCtxt<'tcx>,
|
||||
body: &mut Body<'tcx>,
|
||||
promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use rustc_errors::codes::*;
|
||||
use rustc_errors::MultiSpan;
|
||||
use rustc_errors::codes::*;
|
||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
use rustc_middle::ty::{GenericArg, Ty};
|
||||
use rustc_span::Span;
|
||||
@ -415,7 +415,7 @@ pub(crate) enum CaptureReasonSuggest<'tcx> {
|
||||
span: Span,
|
||||
},
|
||||
#[suggestion(
|
||||
borrowck_suggest_create_freash_reborrow,
|
||||
borrowck_suggest_create_fresh_reborrow,
|
||||
applicability = "maybe-incorrect",
|
||||
code = ".as_mut()",
|
||||
style = "verbose"
|
||||
|
||||
@ -5,11 +5,11 @@ use rustc_infer::infer::canonical::Canonical;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Upcast};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_trait_selection::traits::ObligationCause;
|
||||
use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
|
||||
use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput};
|
||||
use rustc_trait_selection::traits::ObligationCause;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use super::{Locations, NormalizeLocation, TypeChecker};
|
||||
|
||||
@ -6,13 +6,13 @@ use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
|
||||
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategory};
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::traits::ScrubbedTraitError;
|
||||
use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
|
||||
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
|
||||
use rustc_trait_selection::traits::ScrubbedTraitError;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::constraints::OutlivesConstraint;
|
||||
@ -97,7 +97,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
|
||||
/// that we computed for the closure. This has the effect of adding new outlives obligations
|
||||
/// to existing region variables in `closure_args`.
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn apply_closure_requirements(
|
||||
pub(crate) fn apply_closure_requirements(
|
||||
&mut self,
|
||||
closure_requirements: &ClosureRegionRequirements<'tcx>,
|
||||
closure_def_id: DefId,
|
||||
|
||||
@ -6,10 +6,10 @@ use rustc_hir::def::DefKind;
|
||||
use rustc_infer::infer::canonical::QueryRegionConstraints;
|
||||
use rustc_infer::infer::outlives::env::RegionBoundPairs;
|
||||
use rustc_infer::infer::region_constraints::GenericKind;
|
||||
use rustc_infer::infer::{outlives, InferCtxt};
|
||||
use rustc_infer::infer::{InferCtxt, outlives};
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::traits::query::OutlivesBound;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::traits::query::OutlivesBound;
|
||||
use rustc_middle::ty::{self, RegionVid, Ty, TypeVisitableExt};
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
@ -18,7 +18,7 @@ use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
|
||||
use tracing::{debug, instrument};
|
||||
use type_op::TypeOpOutput;
|
||||
|
||||
use crate::type_check::{constraint_conversion, Locations, MirTypeckRegionConstraints};
|
||||
use crate::type_check::{Locations, MirTypeckRegionConstraints, constraint_conversion};
|
||||
use crate::universal_regions::UniversalRegions;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -54,7 +54,7 @@ pub(crate) fn create<'tcx>(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
implicit_region_bound: ty::Region<'tcx>,
|
||||
universal_regions: &Rc<UniversalRegions<'tcx>>,
|
||||
universal_regions: Rc<UniversalRegions<'tcx>>,
|
||||
constraints: &mut MirTypeckRegionConstraints<'tcx>,
|
||||
) -> CreateResult<'tcx> {
|
||||
UniversalRegionRelationsBuilder {
|
||||
@ -62,7 +62,7 @@ pub(crate) fn create<'tcx>(
|
||||
param_env,
|
||||
implicit_region_bound,
|
||||
constraints,
|
||||
universal_regions: universal_regions.clone(),
|
||||
universal_regions,
|
||||
region_bound_pairs: Default::default(),
|
||||
outlives: Default::default(),
|
||||
inverse_outlives: Default::default(),
|
||||
@ -181,12 +181,12 @@ impl UniversalRegionRelations<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
struct UniversalRegionRelationsBuilder<'this, 'tcx> {
|
||||
infcx: &'this InferCtxt<'tcx>,
|
||||
struct UniversalRegionRelationsBuilder<'a, 'tcx> {
|
||||
infcx: &'a InferCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
universal_regions: Rc<UniversalRegions<'tcx>>,
|
||||
implicit_region_bound: ty::Region<'tcx>,
|
||||
constraints: &'this mut MirTypeckRegionConstraints<'tcx>,
|
||||
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
|
||||
|
||||
// outputs:
|
||||
outlives: TransitiveRelationBuilder<RegionVid>,
|
||||
|
||||
@ -77,20 +77,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
let output_ty = Ty::new_coroutine(
|
||||
self.tcx(),
|
||||
self.tcx().coroutine_for_closure(mir_def_id),
|
||||
ty::CoroutineArgs::new(
|
||||
self.tcx(),
|
||||
ty::CoroutineArgsParts {
|
||||
parent_args: args.parent_args(),
|
||||
kind_ty: Ty::from_coroutine_closure_kind(self.tcx(), args.kind()),
|
||||
return_ty: user_provided_sig.output(),
|
||||
tupled_upvars_ty,
|
||||
// For async closures, none of these can be annotated, so just fill
|
||||
// them with fresh ty vars.
|
||||
resume_ty: next_ty_var(),
|
||||
yield_ty: next_ty_var(),
|
||||
witness: next_ty_var(),
|
||||
},
|
||||
)
|
||||
ty::CoroutineArgs::new(self.tcx(), ty::CoroutineArgsParts {
|
||||
parent_args: args.parent_args(),
|
||||
kind_ty: Ty::from_coroutine_closure_kind(self.tcx(), args.kind()),
|
||||
return_ty: user_provided_sig.output(),
|
||||
tupled_upvars_ty,
|
||||
// For async closures, none of these can be annotated, so just fill
|
||||
// them with fresh ty vars.
|
||||
resume_ty: next_ty_var(),
|
||||
yield_ty: next_ty_var(),
|
||||
witness: next_ty_var(),
|
||||
})
|
||||
.args,
|
||||
);
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use itertools::{Either, Itertools};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_middle::mir::visit::{TyContext, Visitor};
|
||||
@ -7,10 +5,10 @@ use rustc_middle::mir::{Body, Local, Location, SourceInfo};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::visit::TypeVisitable;
|
||||
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt};
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
use rustc_mir_dataflow::move_paths::MoveData;
|
||||
use rustc_mir_dataflow::points::DenseLocationMap;
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use tracing::debug;
|
||||
|
||||
use super::TypeChecker;
|
||||
@ -30,11 +28,11 @@ mod trace;
|
||||
///
|
||||
/// N.B., this computation requires normalization; therefore, it must be
|
||||
/// performed before
|
||||
pub(super) fn generate<'mir, 'tcx>(
|
||||
pub(super) fn generate<'a, 'tcx>(
|
||||
typeck: &mut TypeChecker<'_, 'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
elements: &Rc<DenseLocationMap>,
|
||||
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'_, 'mir, 'tcx>>,
|
||||
elements: &DenseLocationMap,
|
||||
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
) {
|
||||
debug!("liveness::generate");
|
||||
@ -148,12 +146,12 @@ fn record_regular_live_regions<'tcx>(
|
||||
}
|
||||
|
||||
/// Visitor looking for regions that should be live within rvalues or calls.
|
||||
struct LiveVariablesVisitor<'cx, 'tcx> {
|
||||
struct LiveVariablesVisitor<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
liveness_constraints: &'cx mut LivenessValues,
|
||||
liveness_constraints: &'a mut LivenessValues,
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> Visitor<'tcx> for LiveVariablesVisitor<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for LiveVariablesVisitor<'a, 'tcx> {
|
||||
/// We sometimes have `args` within an rvalue, or within a
|
||||
/// call. Make them live at the location where they appear.
|
||||
fn visit_args(&mut self, args: &GenericArgsRef<'tcx>, location: Location) {
|
||||
@ -188,7 +186,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for LiveVariablesVisitor<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> LiveVariablesVisitor<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> LiveVariablesVisitor<'a, 'tcx> {
|
||||
/// Some variable is "regular live" at `location` -- i.e., it may be used later. This means that
|
||||
/// all regions appearing in the type of `value` must be live at `location`.
|
||||
fn record_regions_live_at<T>(&mut self, value: T, location: Location)
|
||||
|
||||
@ -11,13 +11,13 @@ use crate::location::{LocationIndex, LocationTable};
|
||||
type VarPointRelation = Vec<(Local, LocationIndex)>;
|
||||
type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>;
|
||||
|
||||
struct UseFactsExtractor<'me, 'tcx> {
|
||||
var_defined_at: &'me mut VarPointRelation,
|
||||
var_used_at: &'me mut VarPointRelation,
|
||||
location_table: &'me LocationTable,
|
||||
var_dropped_at: &'me mut VarPointRelation,
|
||||
move_data: &'me MoveData<'tcx>,
|
||||
path_accessed_at_base: &'me mut PathPointRelation,
|
||||
struct UseFactsExtractor<'a, 'tcx> {
|
||||
var_defined_at: &'a mut VarPointRelation,
|
||||
var_used_at: &'a mut VarPointRelation,
|
||||
location_table: &'a LocationTable,
|
||||
var_dropped_at: &'a mut VarPointRelation,
|
||||
move_data: &'a MoveData<'tcx>,
|
||||
path_accessed_at_base: &'a mut PathPointRelation,
|
||||
}
|
||||
|
||||
// A Visitor to walk through the MIR and extract point-wise facts
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::interval::IntervalSet;
|
||||
@ -8,10 +6,10 @@ use rustc_infer::infer::outlives::for_liveness;
|
||||
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
|
||||
use rustc_middle::traits::query::DropckOutlivesResult;
|
||||
use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt};
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex};
|
||||
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives;
|
||||
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
|
||||
@ -37,11 +35,11 @@ use crate::type_check::{NormalizeLocation, TypeChecker};
|
||||
/// DROP-LIVE set are to the liveness sets for regions found in the
|
||||
/// `dropck_outlives` result of the variable's type (in particular,
|
||||
/// this respects `#[may_dangle]` annotations).
|
||||
pub(super) fn trace<'mir, 'tcx>(
|
||||
pub(super) fn trace<'a, 'tcx>(
|
||||
typeck: &mut TypeChecker<'_, 'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
elements: &Rc<DenseLocationMap>,
|
||||
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'_, 'mir, 'tcx>>,
|
||||
elements: &DenseLocationMap,
|
||||
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
relevant_live_locals: Vec<Local>,
|
||||
boring_locals: Vec<Local>,
|
||||
@ -99,29 +97,29 @@ pub(super) fn trace<'mir, 'tcx>(
|
||||
}
|
||||
|
||||
/// Contextual state for the type-liveness coroutine.
|
||||
struct LivenessContext<'a, 'me, 'typeck, 'flow, 'tcx> {
|
||||
struct LivenessContext<'a, 'typeck, 'b, 'tcx> {
|
||||
/// Current type-checker, giving us our inference context etc.
|
||||
typeck: &'me mut TypeChecker<'typeck, 'tcx>,
|
||||
typeck: &'a mut TypeChecker<'typeck, 'tcx>,
|
||||
|
||||
/// Defines the `PointIndex` mapping
|
||||
elements: &'me DenseLocationMap,
|
||||
elements: &'a DenseLocationMap,
|
||||
|
||||
/// MIR we are analyzing.
|
||||
body: &'me Body<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
|
||||
/// Mapping to/from the various indices used for initialization tracking.
|
||||
move_data: &'me MoveData<'tcx>,
|
||||
move_data: &'a MoveData<'tcx>,
|
||||
|
||||
/// Cache for the results of `dropck_outlives` query.
|
||||
drop_data: FxIndexMap<Ty<'tcx>, DropData<'tcx>>,
|
||||
|
||||
/// Results of dataflow tracking which variables (and paths) have been
|
||||
/// initialized.
|
||||
flow_inits: &'me mut ResultsCursor<'flow, 'tcx, MaybeInitializedPlaces<'a, 'flow, 'tcx>>,
|
||||
flow_inits: &'a mut ResultsCursor<'b, 'tcx, MaybeInitializedPlaces<'b, 'tcx>>,
|
||||
|
||||
/// Index indicating where each variable is assigned, used, or
|
||||
/// dropped.
|
||||
local_use_map: &'me LocalUseMap,
|
||||
local_use_map: &'a LocalUseMap,
|
||||
}
|
||||
|
||||
struct DropData<'tcx> {
|
||||
@ -129,8 +127,8 @@ struct DropData<'tcx> {
|
||||
region_constraint_data: Option<&'tcx QueryRegionConstraints<'tcx>>,
|
||||
}
|
||||
|
||||
struct LivenessResults<'a, 'me, 'typeck, 'flow, 'tcx> {
|
||||
cx: LivenessContext<'a, 'me, 'typeck, 'flow, 'tcx>,
|
||||
struct LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||
cx: LivenessContext<'a, 'typeck, 'b, 'tcx>,
|
||||
|
||||
/// Set of points that define the current local.
|
||||
defs: BitSet<PointIndex>,
|
||||
@ -151,8 +149,8 @@ struct LivenessResults<'a, 'me, 'typeck, 'flow, 'tcx> {
|
||||
stack: Vec<PointIndex>,
|
||||
}
|
||||
|
||||
impl<'a, 'me, 'typeck, 'flow, 'tcx> LivenessResults<'a, 'me, 'typeck, 'flow, 'tcx> {
|
||||
fn new(cx: LivenessContext<'a, 'me, 'typeck, 'flow, 'tcx>) -> Self {
|
||||
impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||
fn new(cx: LivenessContext<'a, 'typeck, 'b, 'tcx>) -> Self {
|
||||
let num_points = cx.elements.num_points();
|
||||
LivenessResults {
|
||||
cx,
|
||||
@ -218,7 +216,7 @@ impl<'a, 'me, 'typeck, 'flow, 'tcx> LivenessResults<'a, 'me, 'typeck, 'flow, 'tc
|
||||
// This collect is more necessary than immediately apparent
|
||||
// because these facts go into `add_drop_live_facts_for()`,
|
||||
// which also writes to `all_facts`, and so this is genuinely
|
||||
// a simulatneous overlapping mutable borrow.
|
||||
// a simultaneous overlapping mutable borrow.
|
||||
// FIXME for future hackers: investigate whether this is
|
||||
// actually necessary; these facts come from Polonius
|
||||
// and probably maybe plausibly does not need to go back in.
|
||||
@ -353,11 +351,11 @@ impl<'a, 'me, 'typeck, 'flow, 'tcx> LivenessResults<'a, 'me, 'typeck, 'flow, 'tc
|
||||
let location = self.cx.elements.to_location(drop_point);
|
||||
debug_assert_eq!(self.cx.body.terminator_loc(location.block), location,);
|
||||
|
||||
if self.cx.initialized_at_terminator(location.block, mpi) {
|
||||
if self.drop_live_at.insert(drop_point) {
|
||||
self.drop_locations.push(location);
|
||||
self.stack.push(drop_point);
|
||||
}
|
||||
if self.cx.initialized_at_terminator(location.block, mpi)
|
||||
&& self.drop_live_at.insert(drop_point)
|
||||
{
|
||||
self.drop_locations.push(location);
|
||||
self.stack.push(drop_point);
|
||||
}
|
||||
}
|
||||
|
||||
@ -505,7 +503,7 @@ impl<'a, 'me, 'typeck, 'flow, 'tcx> LivenessResults<'a, 'me, 'typeck, 'flow, 'tc
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LivenessContext<'_, '_, '_, '_, 'tcx> {
|
||||
impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||
/// Returns `true` if the local variable (or some part of it) is initialized at the current
|
||||
/// cursor position. Callers should call one of the `seek` methods immediately before to point
|
||||
/// the cursor to the desired location.
|
||||
|
||||
@ -31,20 +31,20 @@ use rustc_middle::ty::{
|
||||
UserType, UserTypeAnnotationIndex,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
|
||||
use rustc_mir_dataflow::move_paths::MoveData;
|
||||
use rustc_mir_dataflow::points::DenseLocationMap;
|
||||
use rustc_mir_dataflow::ResultsCursor;
|
||||
use rustc_span::def_id::CRATE_DEF_ID;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use rustc_target::abi::{FIRST_VARIANT, FieldIdx};
|
||||
use rustc_trait_selection::traits::PredicateObligation;
|
||||
use rustc_trait_selection::traits::query::type_op::custom::{
|
||||
scrape_region_constraints, CustomTypeOp,
|
||||
CustomTypeOp, scrape_region_constraints,
|
||||
};
|
||||
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
|
||||
use rustc_trait_selection::traits::PredicateObligation;
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
use crate::borrow_set::BorrowSet;
|
||||
@ -53,13 +53,13 @@ use crate::diagnostics::UniverseInfo;
|
||||
use crate::facts::AllFacts;
|
||||
use crate::location::LocationTable;
|
||||
use crate::member_constraints::MemberConstraintSet;
|
||||
use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices};
|
||||
use crate::region_infer::TypeTest;
|
||||
use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices};
|
||||
use crate::renumber::RegionCtxt;
|
||||
use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst};
|
||||
use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations};
|
||||
use crate::universal_regions::{DefiningTy, UniversalRegions};
|
||||
use crate::{path_utils, BorrowckInferCtxt};
|
||||
use crate::{BorrowckInferCtxt, path_utils};
|
||||
|
||||
macro_rules! span_mirbug {
|
||||
($context:expr, $elem:expr, $($message:tt)*) => ({
|
||||
@ -116,18 +116,18 @@ mod relate_tys;
|
||||
/// - `flow_inits` -- results of a maybe-init dataflow analysis
|
||||
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
|
||||
/// - `elements` -- MIR region map
|
||||
pub(crate) fn type_check<'mir, 'tcx>(
|
||||
pub(crate) fn type_check<'a, 'tcx>(
|
||||
infcx: &BorrowckInferCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
promoted: &IndexSlice<Promoted, Body<'tcx>>,
|
||||
universal_regions: &Rc<UniversalRegions<'tcx>>,
|
||||
universal_regions: Rc<UniversalRegions<'tcx>>,
|
||||
location_table: &LocationTable,
|
||||
borrow_set: &BorrowSet<'tcx>,
|
||||
all_facts: &mut Option<AllFacts>,
|
||||
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'_, 'mir, 'tcx>>,
|
||||
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
elements: &Rc<DenseLocationMap>,
|
||||
elements: Rc<DenseLocationMap>,
|
||||
upvars: &[&ty::CapturedPlace<'tcx>],
|
||||
) -> MirTypeckResults<'tcx> {
|
||||
let implicit_region_bound = ty::Region::new_var(infcx.tcx, universal_regions.fr_fn_body);
|
||||
@ -150,14 +150,14 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||
infcx,
|
||||
param_env,
|
||||
implicit_region_bound,
|
||||
universal_regions,
|
||||
universal_regions.clone(),
|
||||
&mut constraints,
|
||||
);
|
||||
|
||||
debug!(?normalized_inputs_and_output);
|
||||
|
||||
let mut borrowck_context = BorrowCheckContext {
|
||||
universal_regions,
|
||||
universal_regions: &universal_regions,
|
||||
location_table,
|
||||
borrow_set,
|
||||
all_facts,
|
||||
@ -181,10 +181,10 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||
verifier.visit_body(body);
|
||||
|
||||
checker.typeck_mir(body);
|
||||
checker.equate_inputs_and_outputs(body, universal_regions, &normalized_inputs_and_output);
|
||||
checker.equate_inputs_and_outputs(body, &universal_regions, &normalized_inputs_and_output);
|
||||
checker.check_signature_annotation(body);
|
||||
|
||||
liveness::generate(&mut checker, body, elements, flow_inits, move_data);
|
||||
liveness::generate(&mut checker, body, &elements, flow_inits, move_data);
|
||||
|
||||
translate_outlives_facts(&mut checker);
|
||||
let opaque_type_values = infcx.take_opaque_types();
|
||||
@ -1944,11 +1944,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
|
||||
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
|
||||
let trait_ref = ty::TraitRef::new(
|
||||
tcx,
|
||||
tcx.require_lang_item(LangItem::Sized, Some(span)),
|
||||
[ty],
|
||||
);
|
||||
let trait_ref =
|
||||
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, Some(span)), [
|
||||
ty,
|
||||
]);
|
||||
|
||||
self.prove_trait_ref(
|
||||
trait_ref,
|
||||
@ -1961,11 +1960,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
Rvalue::ShallowInitBox(operand, ty) => {
|
||||
self.check_operand(operand, location);
|
||||
|
||||
let trait_ref = ty::TraitRef::new(
|
||||
tcx,
|
||||
tcx.require_lang_item(LangItem::Sized, Some(span)),
|
||||
[*ty],
|
||||
);
|
||||
let trait_ref =
|
||||
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, Some(span)), [
|
||||
*ty,
|
||||
]);
|
||||
|
||||
self.prove_trait_ref(
|
||||
trait_ref,
|
||||
@ -1977,49 +1975,111 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
Rvalue::Cast(cast_kind, op, ty) => {
|
||||
self.check_operand(op, location);
|
||||
|
||||
match cast_kind {
|
||||
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer) => {
|
||||
let fn_sig = op.ty(body, tcx).fn_sig(tcx);
|
||||
match *cast_kind {
|
||||
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, coercion_source) => {
|
||||
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
|
||||
let src_sig = op.ty(body, tcx).fn_sig(tcx);
|
||||
|
||||
// HACK: This shouldn't be necessary... We can remove this when we actually
|
||||
// get binders with where clauses, then elaborate implied bounds into that
|
||||
// binder, and implement a higher-ranked subtyping algorithm that actually
|
||||
// respects these implied bounds.
|
||||
//
|
||||
// This protects against the case where we are casting from a higher-ranked
|
||||
// fn item to a non-higher-ranked fn pointer, where the cast throws away
|
||||
// implied bounds that would've needed to be checked at the call site. This
|
||||
// only works when we're casting to a non-higher-ranked fn ptr, since
|
||||
// placeholders in the target signature could have untracked implied
|
||||
// bounds, resulting in incorrect errors.
|
||||
//
|
||||
// We check that this signature is WF before subtyping the signature with
|
||||
// the target fn sig.
|
||||
if src_sig.has_bound_regions()
|
||||
&& let ty::FnPtr(target_fn_tys, target_hdr) = *ty.kind()
|
||||
&& let target_sig = target_fn_tys.with(target_hdr)
|
||||
&& let Some(target_sig) = target_sig.no_bound_vars()
|
||||
{
|
||||
let src_sig = self.infcx.instantiate_binder_with_fresh_vars(
|
||||
span,
|
||||
BoundRegionConversionTime::HigherRankedType,
|
||||
src_sig,
|
||||
);
|
||||
let src_ty = Ty::new_fn_ptr(self.tcx(), ty::Binder::dummy(src_sig));
|
||||
self.prove_predicate(
|
||||
ty::ClauseKind::WellFormed(src_ty.into()),
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
|
||||
);
|
||||
|
||||
let src_ty = self.normalize(src_ty, location);
|
||||
if let Err(terr) = self.sub_types(
|
||||
src_ty,
|
||||
*ty,
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
|
||||
) {
|
||||
span_mirbug!(
|
||||
self,
|
||||
rvalue,
|
||||
"equating {:?} with {:?} yields {:?}",
|
||||
target_sig,
|
||||
src_sig,
|
||||
terr
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
let src_ty = Ty::new_fn_ptr(tcx, src_sig);
|
||||
// HACK: We want to assert that the signature of the source fn is
|
||||
// well-formed, because we don't enforce that via the WF of FnDef
|
||||
// types normally. This should be removed when we improve the tracking
|
||||
// of implied bounds of fn signatures.
|
||||
self.prove_predicate(
|
||||
ty::ClauseKind::WellFormed(src_ty.into()),
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
|
||||
);
|
||||
|
||||
// The type that we see in the fcx is like
|
||||
// `foo::<'a, 'b>`, where `foo` is the path to a
|
||||
// function definition. When we extract the
|
||||
// signature, it comes from the `fn_sig` query,
|
||||
// and hence may contain unnormalized results.
|
||||
let fn_sig = self.normalize(fn_sig, location);
|
||||
|
||||
let ty_fn_ptr_from = Ty::new_fn_ptr(tcx, fn_sig);
|
||||
|
||||
let src_ty = self.normalize(src_ty, location);
|
||||
if let Err(terr) = self.sub_types(
|
||||
ty_fn_ptr_from,
|
||||
src_ty,
|
||||
*ty,
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { unsize_to: None },
|
||||
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
|
||||
) {
|
||||
span_mirbug!(
|
||||
self,
|
||||
rvalue,
|
||||
"equating {:?} with {:?} yields {:?}",
|
||||
ty_fn_ptr_from,
|
||||
src_ty,
|
||||
ty,
|
||||
terr
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(safety)) => {
|
||||
CastKind::PointerCoercion(
|
||||
PointerCoercion::ClosureFnPointer(safety),
|
||||
coercion_source,
|
||||
) => {
|
||||
let sig = match op.ty(body, tcx).kind() {
|
||||
ty::Closure(_, args) => args.as_closure().sig(),
|
||||
_ => bug!(),
|
||||
};
|
||||
let ty_fn_ptr_from =
|
||||
Ty::new_fn_ptr(tcx, tcx.signature_unclosure(sig, *safety));
|
||||
Ty::new_fn_ptr(tcx, tcx.signature_unclosure(sig, safety));
|
||||
|
||||
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
|
||||
if let Err(terr) = self.sub_types(
|
||||
ty_fn_ptr_from,
|
||||
*ty,
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { unsize_to: None },
|
||||
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
|
||||
) {
|
||||
span_mirbug!(
|
||||
self,
|
||||
@ -2032,7 +2092,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer) => {
|
||||
CastKind::PointerCoercion(
|
||||
PointerCoercion::UnsafeFnPointer,
|
||||
coercion_source,
|
||||
) => {
|
||||
let fn_sig = op.ty(body, tcx).fn_sig(tcx);
|
||||
|
||||
// The type that we see in the fcx is like
|
||||
@ -2044,11 +2107,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
|
||||
let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
|
||||
|
||||
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
|
||||
if let Err(terr) = self.sub_types(
|
||||
ty_fn_ptr_from,
|
||||
*ty,
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { unsize_to: None },
|
||||
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
|
||||
) {
|
||||
span_mirbug!(
|
||||
self,
|
||||
@ -2061,7 +2125,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
CastKind::PointerCoercion(PointerCoercion::Unsize) => {
|
||||
CastKind::PointerCoercion(PointerCoercion::Unsize, coercion_source) => {
|
||||
let &ty = ty;
|
||||
let trait_ref = ty::TraitRef::new(
|
||||
tcx,
|
||||
@ -2069,22 +2133,21 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
[op.ty(body, tcx), ty],
|
||||
);
|
||||
|
||||
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
|
||||
let unsize_to = tcx.fold_regions(ty, |r, _| {
|
||||
if let ty::ReVar(_) = r.kind() { tcx.lifetimes.re_erased } else { r }
|
||||
});
|
||||
self.prove_trait_ref(
|
||||
trait_ref,
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast {
|
||||
unsize_to: Some(tcx.fold_regions(ty, |r, _| {
|
||||
if let ty::ReVar(_) = r.kind() {
|
||||
tcx.lifetimes.re_erased
|
||||
} else {
|
||||
r
|
||||
}
|
||||
})),
|
||||
is_implicit_coercion,
|
||||
unsize_to: Some(unsize_to),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
CastKind::DynStar => {
|
||||
CastKind::PointerCoercion(PointerCoercion::DynStar, coercion_source) => {
|
||||
// get the constraints from the target type (`dyn* Clone`)
|
||||
//
|
||||
// apply them to prove that the source type `Foo` implements `Clone` etc
|
||||
@ -2095,12 +2158,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
|
||||
let self_ty = op.ty(body, tcx);
|
||||
|
||||
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
|
||||
self.prove_predicates(
|
||||
existential_predicates
|
||||
.iter()
|
||||
.map(|predicate| predicate.with_self_ty(tcx, self_ty)),
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { unsize_to: None },
|
||||
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
|
||||
);
|
||||
|
||||
let outlives_predicate = tcx.mk_predicate(Binder::dummy(
|
||||
@ -2111,11 +2175,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
self.prove_predicate(
|
||||
outlives_predicate,
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { unsize_to: None },
|
||||
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
|
||||
);
|
||||
}
|
||||
|
||||
CastKind::PointerCoercion(PointerCoercion::MutToConstPointer) => {
|
||||
CastKind::PointerCoercion(
|
||||
PointerCoercion::MutToConstPointer,
|
||||
coercion_source,
|
||||
) => {
|
||||
let ty::RawPtr(ty_from, hir::Mutability::Mut) = op.ty(body, tcx).kind()
|
||||
else {
|
||||
span_mirbug!(self, rvalue, "unexpected base type for cast {:?}", ty,);
|
||||
@ -2125,11 +2192,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
span_mirbug!(self, rvalue, "unexpected target type for cast {:?}", ty,);
|
||||
return;
|
||||
};
|
||||
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
|
||||
if let Err(terr) = self.sub_types(
|
||||
*ty_from,
|
||||
*ty_to,
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { unsize_to: None },
|
||||
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
|
||||
) {
|
||||
span_mirbug!(
|
||||
self,
|
||||
@ -2142,7 +2210,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
CastKind::PointerCoercion(PointerCoercion::ArrayToPointer) => {
|
||||
CastKind::PointerCoercion(PointerCoercion::ArrayToPointer, coercion_source) => {
|
||||
let ty_from = op.ty(body, tcx);
|
||||
|
||||
let opt_ty_elem_mut = match ty_from.kind() {
|
||||
@ -2187,11 +2255,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
return;
|
||||
}
|
||||
|
||||
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
|
||||
if let Err(terr) = self.sub_types(
|
||||
*ty_elem,
|
||||
*ty_to,
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { unsize_to: None },
|
||||
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
|
||||
) {
|
||||
span_mirbug!(
|
||||
self,
|
||||
@ -2368,11 +2437,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
|
||||
debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);
|
||||
|
||||
self.eq_types(
|
||||
self.sub_types(
|
||||
src_obj,
|
||||
dst_obj,
|
||||
location.to_locations(),
|
||||
ConstraintCategory::Cast { unsize_to: None },
|
||||
ConstraintCategory::Cast {
|
||||
is_implicit_coercion: false,
|
||||
unsize_to: None,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@ -4,13 +4,14 @@ use rustc_infer::infer::relate::{
|
||||
PredicateEmittingRelation, Relate, RelateResult, StructurallyRelateAliases, TypeRelation,
|
||||
};
|
||||
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
|
||||
use rustc_infer::traits::solve::Goal;
|
||||
use rustc_infer::traits::Obligation;
|
||||
use rustc_infer::traits::solve::Goal;
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::ty::fold::FnMutDelegate;
|
||||
use rustc_middle::ty::relate::combine::{super_combine_consts, super_combine_tys};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::{Span, Symbol};
|
||||
@ -58,8 +59,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
struct NllTypeRelating<'me, 'bccx, 'tcx> {
|
||||
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
|
||||
struct NllTypeRelating<'a, 'b, 'tcx> {
|
||||
type_checker: &'a mut TypeChecker<'b, 'tcx>,
|
||||
|
||||
/// Where (and why) is this relation taking place?
|
||||
locations: Locations,
|
||||
@ -82,9 +83,9 @@ struct NllTypeRelating<'me, 'bccx, 'tcx> {
|
||||
ambient_variance_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
|
||||
impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
|
||||
fn new(
|
||||
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
|
||||
type_checker: &'a mut TypeChecker<'b, 'tcx>,
|
||||
locations: Locations,
|
||||
category: ConstraintCategory<'tcx>,
|
||||
universe_info: UniverseInfo<'tcx>,
|
||||
@ -214,7 +215,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
|
||||
let delegate = FnMutDelegate {
|
||||
regions: &mut |br: ty::BoundRegion| {
|
||||
if let Some(ex_reg_var) = reg_map.get(&br) {
|
||||
return *ex_reg_var;
|
||||
*ex_reg_var
|
||||
} else {
|
||||
let ex_reg_var = self.next_existential_region_var(true, br.kind.get_name());
|
||||
debug!(?ex_reg_var);
|
||||
@ -309,7 +310,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx> {
|
||||
impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
|
||||
fn cx(&self) -> TyCtxt<'tcx> {
|
||||
self.type_checker.infcx.tcx
|
||||
}
|
||||
@ -362,7 +363,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }),
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }),
|
||||
) if a_def_id == b_def_id || infcx.next_trait_solver() => {
|
||||
infcx.super_combine_tys(self, a, b).map(|_| ()).or_else(|err| {
|
||||
super_combine_tys(&infcx.infcx, self, a, b).map(|_| ()).or_else(|err| {
|
||||
// This behavior is only there for the old solver, the new solver
|
||||
// shouldn't ever fail. Instead, it unconditionally emits an
|
||||
// alias-relate goal.
|
||||
@ -385,7 +386,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
|
||||
debug!(?a, ?b, ?self.ambient_variance);
|
||||
|
||||
// Will also handle unification of `IntVar` and `FloatVar`.
|
||||
self.type_checker.infcx.super_combine_tys(self, a, b)?;
|
||||
super_combine_tys(&self.type_checker.infcx.infcx, self, a, b)?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -422,7 +423,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
|
||||
assert!(!a.has_non_region_infer(), "unexpected inference var {:?}", a);
|
||||
assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
|
||||
|
||||
self.type_checker.infcx.super_combine_consts(self, a, b)
|
||||
super_combine_consts(&self.type_checker.infcx.infcx, self, a, b)
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "trace")]
|
||||
@ -520,7 +521,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
|
||||
}
|
||||
}
|
||||
|
||||
impl<'bccx, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx> {
|
||||
impl<'b, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
|
||||
fn span(&self) -> Span {
|
||||
self.locations.span(self.type_checker.body)
|
||||
}
|
||||
|
||||
@ -20,24 +20,25 @@ use std::iter;
|
||||
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_errors::Diag;
|
||||
use rustc_hir::BodyOwnerKind;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_hir::BodyOwnerKind;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||
use rustc_macros::extension;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{
|
||||
self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, TyCtxt,
|
||||
self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty,
|
||||
TyCtxt, TypeVisitableExt,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::symbol::{kw, sym};
|
||||
use rustc_span::{ErrorGuaranteed, Symbol};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::renumber::RegionCtxt;
|
||||
use crate::BorrowckInferCtxt;
|
||||
use crate::renumber::RegionCtxt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct UniversalRegions<'tcx> {
|
||||
@ -422,8 +423,8 @@ impl<'tcx> UniversalRegions<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
struct UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
infcx: &'cx BorrowckInferCtxt<'tcx>,
|
||||
struct UniversalRegionsBuilder<'infcx, 'tcx> {
|
||||
infcx: &'infcx BorrowckInferCtxt<'tcx>,
|
||||
mir_def: LocalDefId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
}
|
||||
@ -628,10 +629,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
let ty = tcx
|
||||
.typeck(self.mir_def)
|
||||
.node_type(tcx.local_def_id_to_hir_id(self.mir_def));
|
||||
let args = InlineConstArgs::new(
|
||||
tcx,
|
||||
InlineConstArgsParts { parent_args: identity_args, ty },
|
||||
)
|
||||
let args = InlineConstArgs::new(tcx, InlineConstArgsParts {
|
||||
parent_args: identity_args,
|
||||
ty,
|
||||
})
|
||||
.args;
|
||||
let args = self.infcx.replace_free_regions_with_nll_infer_vars(FR, args);
|
||||
DefiningTy::InlineConst(self.mir_def.to_def_id(), args)
|
||||
@ -688,7 +689,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
defining_ty: DefiningTy<'tcx>,
|
||||
) -> ty::Binder<'tcx, &'tcx ty::List<Ty<'tcx>>> {
|
||||
let tcx = self.infcx.tcx;
|
||||
match defining_ty {
|
||||
|
||||
let inputs_and_output = match defining_ty {
|
||||
DefiningTy::Closure(def_id, args) => {
|
||||
assert_eq!(self.mir_def.to_def_id(), def_id);
|
||||
let closure_sig = args.as_closure().sig();
|
||||
@ -798,6 +800,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
// "output" (the type of the constant).
|
||||
assert_eq!(self.mir_def.to_def_id(), def_id);
|
||||
let ty = tcx.type_of(self.mir_def).instantiate_identity();
|
||||
|
||||
let ty = indices.fold_to_region_vids(tcx, ty);
|
||||
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
|
||||
}
|
||||
@ -807,7 +810,14 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
let ty = args.as_inline_const().ty();
|
||||
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
|
||||
}
|
||||
};
|
||||
|
||||
// FIXME(#129952): We probably want a more principled approach here.
|
||||
if let Err(terr) = inputs_and_output.skip_binder().error_reported() {
|
||||
self.infcx.set_tainted_by_errors(terr);
|
||||
}
|
||||
|
||||
inputs_and_output
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ use tracing::debug;
|
||||
|
||||
use crate::MirBorrowckCtxt;
|
||||
|
||||
impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
|
||||
impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||
/// Walks the MIR adding to the set of `used_mut` locals that will be ignored for the purposes
|
||||
/// of the `unused_mut` lint.
|
||||
///
|
||||
@ -46,13 +46,13 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
|
||||
|
||||
/// MIR visitor for collecting used mutable variables.
|
||||
/// The 'visit lifetime represents the duration of the MIR walk.
|
||||
struct GatherUsedMutsVisitor<'visit, 'a, 'mir, 'infcx, 'tcx> {
|
||||
struct GatherUsedMutsVisitor<'a, 'b, 'infcx, 'tcx> {
|
||||
temporary_used_locals: FxIndexSet<Local>,
|
||||
never_initialized_mut_locals: &'visit mut FxIndexSet<Local>,
|
||||
mbcx: &'visit mut MirBorrowckCtxt<'a, 'mir, 'infcx, 'tcx>,
|
||||
never_initialized_mut_locals: &'a mut FxIndexSet<Local>,
|
||||
mbcx: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
|
||||
}
|
||||
|
||||
impl GatherUsedMutsVisitor<'_, '_, '_, '_, '_> {
|
||||
impl GatherUsedMutsVisitor<'_, '_, '_, '_> {
|
||||
fn remove_never_initialized_mut_locals(&mut self, into: Place<'_>) {
|
||||
// Remove any locals that we found were initialized from the
|
||||
// `never_initialized_mut_locals` set. At the end, the only remaining locals will
|
||||
@ -64,7 +64,7 @@ impl GatherUsedMutsVisitor<'_, '_, '_, '_, '_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'_, '_, '_, '_, 'tcx> {
|
||||
impl<'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'_, '_, '_, 'tcx> {
|
||||
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
|
||||
debug!("visit_terminator: terminator={:?}", terminator);
|
||||
match &terminator.kind {
|
||||
|
||||
@ -12,9 +12,9 @@ builtin_macros_asm_duplicate_arg = duplicate argument named `{$name}`
|
||||
builtin_macros_asm_expected_comma = expected token: `,`
|
||||
.label = expected `,`
|
||||
|
||||
builtin_macros_asm_expected_other = expected operand, {$is_global_asm ->
|
||||
[true] options
|
||||
*[false] clobber_abi, options
|
||||
builtin_macros_asm_expected_other = expected operand, {$is_inline_asm ->
|
||||
[false] options
|
||||
*[true] clobber_abi, options
|
||||
}, or additional template string
|
||||
|
||||
builtin_macros_asm_expected_string_literal = expected string literal
|
||||
@ -51,6 +51,15 @@ builtin_macros_asm_sym_no_path = expected a path for argument to `sym`
|
||||
|
||||
builtin_macros_asm_underscore_input = _ cannot be used for input operands
|
||||
|
||||
builtin_macros_asm_unsupported_clobber_abi = `clobber_abi` cannot be used with `{$macro_name}!`
|
||||
|
||||
builtin_macros_asm_unsupported_operand = the `{$symbol}` operand cannot be used with `{$macro_name}!`
|
||||
.label = the `{$symbol}` operand is not meaningful for global-scoped inline assembly, remove it
|
||||
|
||||
builtin_macros_asm_unsupported_option = the `{$symbol}` option cannot be used with `{$macro_name}!`
|
||||
.label = the `{$symbol}` option is not meaningful for global-scoped inline assembly
|
||||
.suggestion = remove this option
|
||||
|
||||
builtin_macros_assert_missing_comma = unexpected string literal
|
||||
.suggestion = try adding a comma
|
||||
|
||||
@ -194,15 +203,6 @@ builtin_macros_format_unused_args = multiple unused formatting arguments
|
||||
|
||||
builtin_macros_format_use_positional = consider using a positional formatting argument instead
|
||||
|
||||
builtin_macros_global_asm_clobber_abi = `clobber_abi` cannot be used with `global_asm!`
|
||||
|
||||
builtin_macros_global_asm_unsupported_operand = the `{$symbol}` operand cannot be used with `global_asm!`
|
||||
.label = the `{$symbol}` operand is not meaningful for global-scoped inline assembly, remove it
|
||||
|
||||
builtin_macros_global_asm_unsupported_option = the `{$symbol}` option cannot be used with `global_asm!`
|
||||
.label = the `{$symbol}` option is not meaningful for global-scoped inline assembly
|
||||
.suggestion = remove this option
|
||||
|
||||
builtin_macros_invalid_crate_attribute = invalid crate attribute
|
||||
|
||||
builtin_macros_multiple_default_attrs = multiple `#[default]` attributes
|
||||
@ -235,6 +235,8 @@ builtin_macros_non_exhaustive_default = default variant must be exhaustive
|
||||
.label = declared `#[non_exhaustive]` here
|
||||
.help = consider a manual implementation of `Default`
|
||||
|
||||
builtin_macros_non_generic_pointee = the `#[pointee]` attribute may only be used on generic parameters
|
||||
|
||||
builtin_macros_non_unit_default = the `#[default]` attribute may only be used on unit enum variants
|
||||
.help = consider a manual implementation of `Default`
|
||||
|
||||
|
||||
@ -3,9 +3,9 @@ use rustc_ast::{
|
||||
self as ast, Fn, FnHeader, FnSig, Generics, ItemKind, Safety, Stmt, StmtKind, TyKind,
|
||||
};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, kw, sym};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
use crate::errors;
|
||||
use crate::util::check_builtin_macro_attribute;
|
||||
@ -68,11 +68,10 @@ fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span
|
||||
|
||||
let layout_new = cx.std_path(&[sym::alloc, sym::Layout, sym::from_size_align_unchecked]);
|
||||
let layout_new = cx.expr_path(cx.path(span, layout_new));
|
||||
let layout = cx.expr_call(
|
||||
span,
|
||||
layout_new,
|
||||
thin_vec![cx.expr_ident(span, size), cx.expr_ident(span, align)],
|
||||
);
|
||||
let layout = cx.expr_call(span, layout_new, thin_vec![
|
||||
cx.expr_ident(span, size),
|
||||
cx.expr_ident(span, align)
|
||||
]);
|
||||
|
||||
let call = cx.expr_call_ident(sig_span, handler, thin_vec![layout]);
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use ast::token::IdentIsRaw;
|
||||
use lint::BuiltinLintDiag;
|
||||
use rustc_ast::AsmMacro;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Delimiter};
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
@ -9,7 +10,7 @@ use rustc_expand::base::*;
|
||||
use rustc_index::bit_set::GrowableBitSet;
|
||||
use rustc_parse::parser::Parser;
|
||||
use rustc_session::lint;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||
use rustc_span::{ErrorGuaranteed, InnerSpan, Span};
|
||||
use rustc_target::asm::InlineAsmArch;
|
||||
use smallvec::smallvec;
|
||||
@ -36,15 +37,23 @@ pub struct AsmArgs {
|
||||
/// - `Ok(true)` if the current token matches the keyword, and was expected
|
||||
/// - `Ok(false)` if the current token does not match the keyword
|
||||
/// - `Err(_)` if the current token matches the keyword, but was not expected
|
||||
fn eat_operand_keyword<'a>(p: &mut Parser<'a>, symbol: Symbol, expect: bool) -> PResult<'a, bool> {
|
||||
if expect {
|
||||
fn eat_operand_keyword<'a>(
|
||||
p: &mut Parser<'a>,
|
||||
symbol: Symbol,
|
||||
asm_macro: AsmMacro,
|
||||
) -> PResult<'a, bool> {
|
||||
if matches!(asm_macro, AsmMacro::Asm) {
|
||||
Ok(p.eat_keyword(symbol))
|
||||
} else {
|
||||
let span = p.token.span;
|
||||
if p.eat_keyword_noexpect(symbol) {
|
||||
// in gets printed as `r#in` otherwise
|
||||
let symbol = if symbol == kw::In { "in" } else { symbol.as_str() };
|
||||
Err(p.dcx().create_err(errors::GlobalAsmUnsupportedOperand { span, symbol }))
|
||||
Err(p.dcx().create_err(errors::AsmUnsupportedOperand {
|
||||
span,
|
||||
symbol,
|
||||
macro_name: asm_macro.macro_name(),
|
||||
}))
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
@ -55,10 +64,10 @@ fn parse_args<'a>(
|
||||
ecx: &ExtCtxt<'a>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
is_global_asm: bool,
|
||||
asm_macro: AsmMacro,
|
||||
) -> PResult<'a, AsmArgs> {
|
||||
let mut p = ecx.new_parser_from_tts(tts);
|
||||
parse_asm_args(&mut p, sp, is_global_asm)
|
||||
parse_asm_args(&mut p, sp, asm_macro)
|
||||
}
|
||||
|
||||
// Primarily public for rustfmt consumption.
|
||||
@ -66,7 +75,7 @@ fn parse_args<'a>(
|
||||
pub fn parse_asm_args<'a>(
|
||||
p: &mut Parser<'a>,
|
||||
sp: Span,
|
||||
is_global_asm: bool,
|
||||
asm_macro: AsmMacro,
|
||||
) -> PResult<'a, AsmArgs> {
|
||||
let dcx = p.dcx();
|
||||
|
||||
@ -109,7 +118,7 @@ pub fn parse_asm_args<'a>(
|
||||
|
||||
// Parse options
|
||||
if p.eat_keyword(sym::options) {
|
||||
parse_options(p, &mut args, is_global_asm)?;
|
||||
parse_options(p, &mut args, asm_macro)?;
|
||||
allow_templates = false;
|
||||
continue;
|
||||
}
|
||||
@ -128,7 +137,7 @@ pub fn parse_asm_args<'a>(
|
||||
};
|
||||
|
||||
let mut explicit_reg = false;
|
||||
let op = if eat_operand_keyword(p, kw::In, !is_global_asm)? {
|
||||
let op = if eat_operand_keyword(p, kw::In, asm_macro)? {
|
||||
let reg = parse_reg(p, &mut explicit_reg)?;
|
||||
if p.eat_keyword(kw::Underscore) {
|
||||
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
|
||||
@ -136,15 +145,15 @@ pub fn parse_asm_args<'a>(
|
||||
}
|
||||
let expr = p.parse_expr()?;
|
||||
ast::InlineAsmOperand::In { reg, expr }
|
||||
} else if eat_operand_keyword(p, sym::out, !is_global_asm)? {
|
||||
} else if eat_operand_keyword(p, sym::out, asm_macro)? {
|
||||
let reg = parse_reg(p, &mut explicit_reg)?;
|
||||
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
|
||||
ast::InlineAsmOperand::Out { reg, expr, late: false }
|
||||
} else if eat_operand_keyword(p, sym::lateout, !is_global_asm)? {
|
||||
} else if eat_operand_keyword(p, sym::lateout, asm_macro)? {
|
||||
let reg = parse_reg(p, &mut explicit_reg)?;
|
||||
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
|
||||
ast::InlineAsmOperand::Out { reg, expr, late: true }
|
||||
} else if eat_operand_keyword(p, sym::inout, !is_global_asm)? {
|
||||
} else if eat_operand_keyword(p, sym::inout, asm_macro)? {
|
||||
let reg = parse_reg(p, &mut explicit_reg)?;
|
||||
if p.eat_keyword(kw::Underscore) {
|
||||
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
|
||||
@ -158,7 +167,7 @@ pub fn parse_asm_args<'a>(
|
||||
} else {
|
||||
ast::InlineAsmOperand::InOut { reg, expr, late: false }
|
||||
}
|
||||
} else if eat_operand_keyword(p, sym::inlateout, !is_global_asm)? {
|
||||
} else if eat_operand_keyword(p, sym::inlateout, asm_macro)? {
|
||||
let reg = parse_reg(p, &mut explicit_reg)?;
|
||||
if p.eat_keyword(kw::Underscore) {
|
||||
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
|
||||
@ -172,7 +181,7 @@ pub fn parse_asm_args<'a>(
|
||||
} else {
|
||||
ast::InlineAsmOperand::InOut { reg, expr, late: true }
|
||||
}
|
||||
} else if eat_operand_keyword(p, sym::label, !is_global_asm)? {
|
||||
} else if eat_operand_keyword(p, sym::label, asm_macro)? {
|
||||
let block = p.parse_block()?;
|
||||
ast::InlineAsmOperand::Label { block }
|
||||
} else if p.eat_keyword(kw::Const) {
|
||||
@ -204,7 +213,7 @@ pub fn parse_asm_args<'a>(
|
||||
_ => {
|
||||
let err = dcx.create_err(errors::AsmExpectedOther {
|
||||
span: template.span,
|
||||
is_global_asm,
|
||||
is_inline_asm: matches!(asm_macro, AsmMacro::Asm),
|
||||
});
|
||||
return Err(err);
|
||||
}
|
||||
@ -234,13 +243,11 @@ pub fn parse_asm_args<'a>(
|
||||
continue;
|
||||
}
|
||||
args.named_args.insert(name, slot);
|
||||
} else {
|
||||
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
|
||||
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
|
||||
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
|
||||
} else if !args.named_args.is_empty() || !args.reg_args.is_empty() {
|
||||
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
|
||||
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
|
||||
|
||||
dcx.emit_err(errors::AsmPositionalAfter { span, named, explicit });
|
||||
}
|
||||
dcx.emit_err(errors::AsmPositionalAfter { span, named, explicit });
|
||||
}
|
||||
}
|
||||
|
||||
@ -302,20 +309,25 @@ pub fn parse_asm_args<'a>(
|
||||
dcx.emit_err(errors::AsmMayUnwind { labels_sp });
|
||||
}
|
||||
|
||||
if args.clobber_abis.len() > 0 {
|
||||
if is_global_asm {
|
||||
let err = dcx.create_err(errors::GlobalAsmClobberAbi {
|
||||
spans: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
|
||||
});
|
||||
if !args.clobber_abis.is_empty() {
|
||||
match asm_macro {
|
||||
AsmMacro::GlobalAsm | AsmMacro::NakedAsm => {
|
||||
let err = dcx.create_err(errors::AsmUnsupportedClobberAbi {
|
||||
spans: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
|
||||
macro_name: asm_macro.macro_name(),
|
||||
});
|
||||
|
||||
// Bail out now since this is likely to confuse later stages
|
||||
return Err(err);
|
||||
}
|
||||
if !regclass_outputs.is_empty() {
|
||||
dcx.emit_err(errors::AsmClobberNoReg {
|
||||
spans: regclass_outputs,
|
||||
clobbers: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
|
||||
});
|
||||
// Bail out now since this is likely to confuse later stages
|
||||
return Err(err);
|
||||
}
|
||||
AsmMacro::Asm => {
|
||||
if !regclass_outputs.is_empty() {
|
||||
dcx.emit_err(errors::AsmClobberNoReg {
|
||||
spans: regclass_outputs,
|
||||
clobbers: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,10 +348,15 @@ fn err_duplicate_option(p: &Parser<'_>, symbol: Symbol, span: Span) {
|
||||
///
|
||||
/// This function must be called immediately after the option token is parsed.
|
||||
/// Otherwise, the suggestion will be incorrect.
|
||||
fn err_unsupported_option(p: &Parser<'_>, symbol: Symbol, span: Span) {
|
||||
fn err_unsupported_option(p: &Parser<'_>, asm_macro: AsmMacro, symbol: Symbol, span: Span) {
|
||||
// Tool-only output
|
||||
let full_span = if p.token == token::Comma { span.to(p.token.span) } else { span };
|
||||
p.dcx().emit_err(errors::GlobalAsmUnsupportedOption { span, symbol, full_span });
|
||||
p.dcx().emit_err(errors::AsmUnsupportedOption {
|
||||
span,
|
||||
symbol,
|
||||
full_span,
|
||||
macro_name: asm_macro.macro_name(),
|
||||
});
|
||||
}
|
||||
|
||||
/// Try to set the provided option in the provided `AsmArgs`.
|
||||
@ -350,12 +367,12 @@ fn err_unsupported_option(p: &Parser<'_>, symbol: Symbol, span: Span) {
|
||||
fn try_set_option<'a>(
|
||||
p: &Parser<'a>,
|
||||
args: &mut AsmArgs,
|
||||
is_global_asm: bool,
|
||||
asm_macro: AsmMacro,
|
||||
symbol: Symbol,
|
||||
option: ast::InlineAsmOptions,
|
||||
) {
|
||||
if is_global_asm && !ast::InlineAsmOptions::GLOBAL_OPTIONS.contains(option) {
|
||||
err_unsupported_option(p, symbol, p.prev_token.span);
|
||||
if !asm_macro.is_supported_option(option) {
|
||||
err_unsupported_option(p, asm_macro, symbol, p.prev_token.span);
|
||||
} else if args.options.contains(option) {
|
||||
err_duplicate_option(p, symbol, p.prev_token.span);
|
||||
} else {
|
||||
@ -366,7 +383,7 @@ fn try_set_option<'a>(
|
||||
fn parse_options<'a>(
|
||||
p: &mut Parser<'a>,
|
||||
args: &mut AsmArgs,
|
||||
is_global_asm: bool,
|
||||
asm_macro: AsmMacro,
|
||||
) -> PResult<'a, ()> {
|
||||
let span_start = p.prev_token.span;
|
||||
|
||||
@ -387,15 +404,14 @@ fn parse_options<'a>(
|
||||
|
||||
'blk: {
|
||||
for (symbol, option) in OPTIONS {
|
||||
let kw_matched =
|
||||
if !is_global_asm || ast::InlineAsmOptions::GLOBAL_OPTIONS.contains(option) {
|
||||
p.eat_keyword(symbol)
|
||||
} else {
|
||||
p.eat_keyword_noexpect(symbol)
|
||||
};
|
||||
let kw_matched = if asm_macro.is_supported_option(option) {
|
||||
p.eat_keyword(symbol)
|
||||
} else {
|
||||
p.eat_keyword_noexpect(symbol)
|
||||
};
|
||||
|
||||
if kw_matched {
|
||||
try_set_option(p, args, is_global_asm, symbol, option);
|
||||
try_set_option(p, args, asm_macro, symbol, option);
|
||||
break 'blk;
|
||||
}
|
||||
}
|
||||
@ -484,6 +500,7 @@ fn parse_reg<'a>(
|
||||
|
||||
fn expand_preparsed_asm(
|
||||
ecx: &mut ExtCtxt<'_>,
|
||||
asm_macro: AsmMacro,
|
||||
args: AsmArgs,
|
||||
) -> ExpandResult<Result<ast::InlineAsm, ErrorGuaranteed>, ()> {
|
||||
let mut template = vec![];
|
||||
@ -507,6 +524,7 @@ fn expand_preparsed_asm(
|
||||
|
||||
let msg = "asm template must be a string literal";
|
||||
let template_sp = template_expr.span;
|
||||
let template_is_mac_call = matches!(template_expr.kind, ast::ExprKind::MacCall(_));
|
||||
let (template_str, template_style, template_span) = {
|
||||
let ExpandResult::Ready(mac) = expr_to_spanned_string(ecx, template_expr, msg) else {
|
||||
return ExpandResult::Retry(());
|
||||
@ -596,7 +614,14 @@ fn expand_preparsed_asm(
|
||||
|
||||
if !parser.errors.is_empty() {
|
||||
let err = parser.errors.remove(0);
|
||||
let err_sp = template_span.from_inner(InnerSpan::new(err.span.start, err.span.end));
|
||||
let err_sp = if template_is_mac_call {
|
||||
// If the template is a macro call we can't reliably point to the error's
|
||||
// span so just use the template's span as the error span (fixes #129503)
|
||||
template_span
|
||||
} else {
|
||||
template_span.from_inner(InnerSpan::new(err.span.start, err.span.end))
|
||||
};
|
||||
|
||||
let msg = format!("invalid asm template string: {}", err.description);
|
||||
let mut e = ecx.dcx().struct_span_err(err_sp, msg);
|
||||
e.span_label(err_sp, err.label + " in asm template string");
|
||||
@ -774,6 +799,7 @@ fn expand_preparsed_asm(
|
||||
}
|
||||
|
||||
ExpandResult::Ready(Ok(ast::InlineAsm {
|
||||
asm_macro,
|
||||
template,
|
||||
template_strs: template_strs.into_boxed_slice(),
|
||||
operands: args.operands,
|
||||
@ -788,9 +814,39 @@ pub(super) fn expand_asm<'cx>(
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
) -> MacroExpanderResult<'cx> {
|
||||
ExpandResult::Ready(match parse_args(ecx, sp, tts, false) {
|
||||
ExpandResult::Ready(match parse_args(ecx, sp, tts, AsmMacro::Asm) {
|
||||
Ok(args) => {
|
||||
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, args) else {
|
||||
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, AsmMacro::Asm, args) else {
|
||||
return ExpandResult::Retry(());
|
||||
};
|
||||
let expr = match mac {
|
||||
Ok(inline_asm) => P(ast::Expr {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: ast::ExprKind::InlineAsm(P(inline_asm)),
|
||||
span: sp,
|
||||
attrs: ast::AttrVec::new(),
|
||||
tokens: None,
|
||||
}),
|
||||
Err(guar) => DummyResult::raw_expr(sp, Some(guar)),
|
||||
};
|
||||
MacEager::expr(expr)
|
||||
}
|
||||
Err(err) => {
|
||||
let guar = err.emit();
|
||||
DummyResult::any(sp, guar)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn expand_naked_asm<'cx>(
|
||||
ecx: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
) -> MacroExpanderResult<'cx> {
|
||||
ExpandResult::Ready(match parse_args(ecx, sp, tts, AsmMacro::NakedAsm) {
|
||||
Ok(args) => {
|
||||
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, AsmMacro::NakedAsm, args)
|
||||
else {
|
||||
return ExpandResult::Retry(());
|
||||
};
|
||||
let expr = match mac {
|
||||
@ -817,9 +873,10 @@ pub(super) fn expand_global_asm<'cx>(
|
||||
sp: Span,
|
||||
tts: TokenStream,
|
||||
) -> MacroExpanderResult<'cx> {
|
||||
ExpandResult::Ready(match parse_args(ecx, sp, tts, true) {
|
||||
ExpandResult::Ready(match parse_args(ecx, sp, tts, AsmMacro::GlobalAsm) {
|
||||
Ok(args) => {
|
||||
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, args) else {
|
||||
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, AsmMacro::GlobalAsm, args)
|
||||
else {
|
||||
return ExpandResult::Retry(());
|
||||
};
|
||||
match mac {
|
||||
|
||||
@ -3,13 +3,13 @@ mod context;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::Delimiter;
|
||||
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
|
||||
use rustc_ast::{token, DelimArgs, Expr, ExprKind, MacCall, Path, PathSegment, UnOp};
|
||||
use rustc_ast::{DelimArgs, Expr, ExprKind, MacCall, Path, PathSegment, UnOp, token};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::PResult;
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_parse::parser::Parser;
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::symbol::{Ident, Symbol, sym};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
use crate::edition_panic::use_panic_2021;
|
||||
|
||||
@ -2,15 +2,15 @@ use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Delimiter, IdentIsRaw};
|
||||
use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree};
|
||||
use rustc_ast::{
|
||||
BinOpKind, BorrowKind, DelimArgs, Expr, ExprKind, ItemKind, MacCall, MethodCall, Mutability,
|
||||
Path, PathSegment, Stmt, StructRest, UnOp, UseTree, UseTreeKind, DUMMY_NODE_ID,
|
||||
BinOpKind, BorrowKind, DUMMY_NODE_ID, DelimArgs, Expr, ExprKind, ItemKind, MacCall, MethodCall,
|
||||
Mutability, Path, PathSegment, Stmt, StructRest, UnOp, UseTree, UseTreeKind,
|
||||
};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_expand::base::ExtCtxt;
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use rustc_span::symbol::{Ident, Symbol, sym};
|
||||
use thin_vec::{ThinVec, thin_vec};
|
||||
|
||||
pub(super) struct Context<'cx, 'a> {
|
||||
// An optimization.
|
||||
|
||||
@ -6,7 +6,6 @@ use rustc_ast::token;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_errors::PResult;
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_parse::parser::attr::AllowLeadingUnsafe;
|
||||
use rustc_span::Span;
|
||||
use {rustc_ast as ast, rustc_attr as attr};
|
||||
|
||||
@ -36,14 +35,18 @@ pub(crate) fn expand_cfg(
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_cfg<'a>(cx: &ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
|
||||
fn parse_cfg<'a>(
|
||||
cx: &ExtCtxt<'a>,
|
||||
span: Span,
|
||||
tts: TokenStream,
|
||||
) -> PResult<'a, ast::MetaItemInner> {
|
||||
let mut p = cx.new_parser_from_tts(tts);
|
||||
|
||||
if p.token == token::Eof {
|
||||
return Err(cx.dcx().create_err(errors::RequiresCfgPattern { span }));
|
||||
}
|
||||
|
||||
let cfg = p.parse_meta_item(AllowLeadingUnsafe::No)?;
|
||||
let cfg = p.parse_meta_item_inner()?;
|
||||
|
||||
let _ = p.eat(&token::Comma);
|
||||
|
||||
|
||||
@ -4,8 +4,8 @@ use rustc_ast as ast;
|
||||
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier};
|
||||
use rustc_feature::AttributeTemplate;
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ use rustc_ast as ast;
|
||||
use rustc_ast::mut_visit::MutVisitor;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::visit::{AssocCtxt, Visitor};
|
||||
use rustc_ast::{mut_visit, visit, Attribute, HasAttrs, HasTokens, NodeId};
|
||||
use rustc_ast::{Attribute, HasAttrs, HasTokens, NodeId, mut_visit, visit};
|
||||
use rustc_errors::PResult;
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_expand::config::StripUnconfigured;
|
||||
@ -12,8 +12,8 @@ use rustc_expand::configure;
|
||||
use rustc_feature::Features;
|
||||
use rustc_parse::parser::{ForceCollect, Parser};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::sym;
|
||||
use smallvec::SmallVec;
|
||||
use tracing::instrument;
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! Attributes injected into the crate root from command line using `-Z crate-attr`.
|
||||
|
||||
use rustc_ast::attr::mk_attr;
|
||||
use rustc_ast::{self as ast, token, AttrItem, AttrStyle};
|
||||
use rustc_ast::{self as ast, AttrItem, AttrStyle, token};
|
||||
use rustc_parse::parser::ForceCollect;
|
||||
use rustc_parse::{new_parser_from_source_str, unwrap_or_emit_fatal};
|
||||
use rustc_session::parse::ParseSess;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{token, ExprKind, LitIntType, LitKind, UintTy};
|
||||
use rustc_ast::{ExprKind, LitIntType, LitKind, UintTy, token};
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_session::errors::report_lit_error;
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Token};
|
||||
use rustc_ast::tokenstream::{TokenStream, TokenTree};
|
||||
use rustc_ast::{AttrVec, Expr, ExprKind, Path, Ty, TyKind, DUMMY_NODE_ID};
|
||||
use rustc_ast::{AttrVec, DUMMY_NODE_ID, Expr, ExprKind, Path, Ty, TyKind};
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacResult, MacroExpanderResult};
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
|
||||
use crate::errors;
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::{GenericParamKind, ItemKind, MetaItemKind, NestedMetaItem, StmtKind};
|
||||
use rustc_ast::{GenericParamKind, ItemKind, MetaItemInner, MetaItemKind, StmtKind};
|
||||
use rustc_expand::base::{
|
||||
Annotatable, DeriveResolution, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier,
|
||||
};
|
||||
use rustc_feature::AttributeTemplate;
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
use rustc_span::symbol::{Ident, sym};
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
|
||||
use crate::cfg_eval::cfg_eval;
|
||||
@ -49,9 +49,9 @@ impl MultiItemModifier for Expander {
|
||||
let mut resolutions = match &meta_item.kind {
|
||||
MetaItemKind::List(list) => {
|
||||
list.iter()
|
||||
.filter_map(|nested_meta| match nested_meta {
|
||||
NestedMetaItem::MetaItem(meta) => Some(meta),
|
||||
NestedMetaItem::Lit(lit) => {
|
||||
.filter_map(|meta_item_inner| match meta_item_inner {
|
||||
MetaItemInner::MetaItem(meta) => Some(meta),
|
||||
MetaItemInner::Lit(lit) => {
|
||||
// Reject `#[derive("Debug")]`.
|
||||
report_unexpected_meta_item_lit(sess, lit);
|
||||
None
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user