Add integer truncation and extension methods
Tracking issue: https://github.com/rust-lang/rust/issues/154330
This provides `.truncate()`, `.saturating_truncate()`, `.checked_truncate()`, and `.extend()`.
These only work within the same signedness (use `.cast_signed()` and `.cast_unsigned()` to change sign).
The truncation methods only work to smaller (or equal) types. `.extend()` only works to larger (or equal) types.
For the purposes of truncation and extending, `u128` is considered larger than or equal to the size of `usize`, and `usize` is considered larger than `u16` or `u8`. We might, in the future, want to consider ways to expand this.
Much of this was pair-programmed with @Amanieu.
In order to seal the new traits, this PR also adds a `core::sealed::Sealed`, like the one in `std`. I didn't modify `std` to re-export the same one, since by definition it isn't nameable, and since doing that would require that it be nameable (even if it was `#[unstable]`).
Rollup of 5 pull requests
Successful merges:
- rust-lang/rust#152935 (c-variadic: error when we can't guarantee that the backend does the right thing)
- rust-lang/rust#153207 (std::net: clamp linger timeout value to prevent silent truncation.)
- rust-lang/rust#154592 (Fix `mismatched_lifetime_syntaxes` suggestions for hidden path lifetimes)
- rust-lang/rust#154643 (fix pin docs)
- rust-lang/rust#154648 (Clarify `ty::List`)
This provides `.truncate()`, `.saturating_truncate()`,
`.checked_truncate()`, and `.extend()`.
These only work within the same signedness (use `.cast_signed()` and
`.cast_unsigned()` to change sign).
The truncation methods only work to smaller (or equal) types.
`.extend()` only works to larger (or equal) types.
For the purposes of truncation and extending, `usize` is considered
larger than `u16` or `u8`. This is consistent with `From`/`Into`
conversions.
Adding these methods results in needing to update the output of one test
that gets a new method-name similarity result.
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
add rustc option -Zpacked-stack
this enables `-Zpacked-stack` just as `-mpacked-stack` in clang and gcc. packed-stack is needed on s390x for kernel development.
For reference: rust-lang/rust#151154 and rust-lang/rust#150766
look at @uweigand s post for full explanation of what this does. Here a wrap-up:
https://github.com/rust-lang/rust/pull/150766#issuecomment-3729074303
> [...]
> packed-stack [...] modifies how the compiler-generated function prolog/epilog code makes use of the 160 byte register save area provided by a caller to the callee [...] this variant is not actually incompatible with the ABI - packed-stack and regular functions can freely call each other without ABI issues.
> [...]
> combination of -mpacked-stack and -mbackchain [...] the location in the stack frame where the backchain link ought to be stored is not available. [...] is not supported at all with the default ABI
> [...]
> However, in the special case of also using soft-float, our (implied) soft-float ABI provides a different location for the backchain that is compatible with -mpacked-stack, so that combination should be supported
> [...]
Add a test for a now fixed ICE with `offset_of!()`
Adds a test for rust-lang/rust#125805, which was an ICE with `offset_of!()` on a field with the type of a trait object missing `dyn` and a required lifetime parameter.
Closesrust-lang/rust#125805.
misc test cleanups
These are some mixed cleanups to `tests/ui` that individually seemed too small for a PR of their own. Some duplicated tests are removed, `issues-*` tests are renamed and more FIXMEs are added to `ui/README.md`.
Reasoning for the deleted tests:
* `tests/ui/associated-types/issue-47814.rs`: duplicate of `tests/ui/associated-consts/issue-47814.rs`
* rename `tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs` to `.../nested-copy-drops-83176.rs` since rust-lang/rust#78720 was not the correct issue, rust-lang/rust#83176 was.
* `tests/ui/specialization/defaultimpl/specialization-feature-gate-default.rs`: duplicate of `tests/ui/specialization/specialization-feature-gate-default.rs`
* `fn/issue-1900.rs`: duplicate of `error-codes/E0131.rs`
r? @Kivooeo
Update `mir-opt` 64-bit panic-abort tests for `Alignment` rename
These seem to have been missed when the PR originally merged.
cc https://github.com/rust-lang/rust/pull/154004, @GrigorenkoPV
delete several `ui/consts` tests
* `tests/ui/consts/const.rs`: meaningless
* `tests/ui/consts/const-bound.rs`: has nothing to do with const bounds or const at all (anymore?)
* `tests/ui/consts/const-enum-tuplestruct2.rs`, `tests/ui/consts/const-enum-tuple2.rs`, `tests/ui/consts/const-enum-tuple.rs`: duplicates of `tests/ui/consts/const-enum-tuplestruct.rs`
r? @Kivooeo
Skip suggestions pointing to macro def for assert_eq
Fixesrust-lang/rust#146204
It's better to suggest:
```console
help: consider borrowing here
--> src/main.rs:3:16
|
3| assert_ne!(&buf, b"----");
| +
```
but i don't want to give a too heuristic but not general enough fix, let suppress them.
Fix regression when dealing with generics/values with unresolved inference
Follow up for rust-lang/rust#151703, fixing regression caused in rollup rust-lang/rust#152825
Forgot to handle generics & unresolved inference variables (as in `get_safe_transmute_error_and_reason`) in my previous PR. This followup checks for them before trying to normalize.
I am not completely sure its right approach to have this check cloned but as `select_transmute_obligation_for_reporting` fn just chooses obligation and doesn't actually return an error, this check shouldn't be removed from `get_safe_transmute_error_and_reasnon`. If there is any better solution, let me kmow.
Fixes: rust-lang/rust#153755
r? @jdonszelmann
Avoid ICE when param-env normalization leaves unresolved inference variables
Fixesrust-lang/rust#153354
Because the impl is already ill-formed, those variables are not fully constrained, so zfully_resolve` fails. We previously treated that as an immediate compiler bug with `span_bug!`, which caused an ICE on invalid input.
this enables packed-stack just as -mpacked-stack in clang and gcc.
packed-stack is needed on s390x for kernel development.
Co-authored-by: Ralf Jung <post@ralfj.de>
stabilizes `core::range::Range`
stabilizes `core::range::RangeIter`
stabilizes `std::range` which was missed in prior PRs
Updates docs to reflect stabilization (removed "experimental")
`RangeIter::remainder` is excluded from stabilization
Tweak wording of E0275 WF errors
Modify the main error message to read better:
```
error[E0275]: overflow evaluating whether `&'a mut Bar` is well-formed
```
Add regression test for TransmuteFrom ICE with min_generic_const_args
Regression test for rust-lang/rust#150457.
The wfcheck ICE with TransmuteFrom + min_generic_const_args was fixed by rust-lang/rust#150707 but didn't get a test.
Closesrust-lang/rust#150457
Add regression test for recursive lazy type alias normalization ICE
Regression test for rust-lang/rust#152633.
The normalization ICE with recursive lazy_type_alias + min_generic_const_args was fixed by rust-lang/rust#152040 but didn't get a test. Compiler now reports E0275 instead of crashing.
Closesrust-lang/rust#152633