Commit graph

14852 commits

Author SHA1 Message Date
许杰友 Jieyou Xu (Joe)
38bfd88db7 Add regression test for #134060
Mostly just to check that the lint impl doesn't ICE from an easy case.
2024-12-09 17:39:08 +08:00
许杰友 Jieyou Xu (Joe)
1fcbb1e338 Revert #131669 due to ICEs
Revert <https://github.com/rust-lang/rust/pull/131669> due to ICE
reports:

- <https://github.com/rust-lang/rust/issues/134059> (real-world)
- <https://github.com/rust-lang/rust/issues/134060> (fuzzing)

The changes can be re-landed with those cases addressed.

This reverts commit 703bb98230, reversing
changes made to f415c07494.
2024-12-09 17:31:16 +08:00
bors
1b3fb31675 Auto merge of #134052 - matthiaskrgr:rollup-puxwqrk, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #133567 (A bunch of cleanups)
 - #133789 (Add doc alias 'then_with' for `then` method on `bool`)
 - #133880 (Expand home_dir docs)
 - #134036 (crash tests: use individual mir opts instead of mir-opt-level where easily possible)
 - #134045 (Fix some triagebot mentions paths)
 - #134046 (Remove ignored tests for hangs w/ new solver)
 - #134050 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-09 03:24:24 +00:00
Matthias Krüger
86f3ed3e11
Rollup merge of #134046 - lqd:new-solver-hangs, r=compiler-errors
Remove ignored tests for hangs w/ new solver

As asked on zulip [here](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/needs_help.3A.20look.20through.20compare-mode.20hangs).

As far as I can tell there are no more UI tests that hang anymore, so this removes the ignore directives for the compare mode.

(As I was using `--compare-mode new-solver` and that failed in an obscure way without any info about what to do, I've also fixed its error handling in `compiletest`: it didn't show the invalid `--compare-mode`, nor the valid values one can pass).

r? lcnr
2024-12-09 01:56:35 +01:00
Matthias Krüger
273a359b90
Rollup merge of #134036 - matthiaskrgr:opppt, r=saethlin
crash tests: use individual mir opts instead of mir-opt-level where easily possible

r? `@saethlin`
2024-12-09 01:56:34 +01:00
Matthias Krüger
d2881e4eb5
Rollup merge of #133567 - bjorn3:various_cleanups, r=cjgillot
A bunch of cleanups

These are all extracted from a branch I have to get rid of driver queries. Most of the commits are not directly necessary for this, but were found in the process of implementing the removal of driver queries.

Previous PR: https://github.com/rust-lang/rust/pull/132410
2024-12-09 01:56:32 +01:00
Rémy Rakic
91cf0cb729 bless test expectations
(in a separate commit for easier review, one of them is huge)
2024-12-08 20:21:46 +00:00
Rémy Rakic
95a1351c4a mark previously hanging tests as good to go 2024-12-08 20:21:46 +00:00
Matthias Krüger
1aab767324
Rollup merge of #134024 - jieyouxu:ui-cleanup-2, r=Nadrieril
Advent of `tests/ui` (misc cleanups and improvements) [2/N]

Part of #133895.

Misc improvements to some ui tests immediately under `tests/ui/`.

Best reviewed commit-by-commit. Please see individual commit messages for some further rationale and change summaries.

r? compiler
2024-12-08 17:18:53 +01:00
Matthias Krüger
1868c8f66f
Rollup merge of #133424 - Nadrieril:guard-patterns-parsing, r=fee1-dead
Parse guard patterns

This implements the parsing of [RFC3637 Guard Patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see also [tracking issue](https://github.com/rust-lang/rust/issues/129967)). This PR is extracted from https://github.com/rust-lang/rust/pull/129996 with minor modifications.

cc `@max-niederman`
2024-12-08 17:18:50 +01:00
Matthias Krüger
8d5236fa1c crash tests: use individual mir opts instead of mir-opt-level where easily possible 2024-12-08 16:52:32 +01:00
Matthias Krüger
d4b5345248
Rollup merge of #133992 - compiler-errors:walk-fully, r=jieyouxu
Actually walk into lifetimes and attrs in `EarlyContextAndPass`

Visitors that don't also call `walk_*` are kinda a footgun...

I believe all the other early lint functions walk into their types correctly at this point.
2024-12-08 14:28:26 +01:00
Matthias Krüger
a369714a29
Rollup merge of #133767 - estebank:multiple-dep-version-tests, r=Nadrieril
Add more info on type/trait mismatches for different crate versions

When encountering a type or trait mismatch for two types coming from two different crates with the same name, detect if it is either mixing two types/traits from the same crate on different versions:

```
error[E0308]: mismatched types
  --> replaced
   |
LL |     do_something_type(Type);
   |     ----------------- ^^^^ expected `dependency::Type`, found `dep_2_reexport::Type`
   |     |
   |     arguments to this function are incorrect
   |
note: two different versions of crate `dependency` are being used; two types coming from two different versions of the same crate are different types even if they look the same
  --> replaced
   |
LL | pub struct Type(pub i32);
   | ^^^^^^^^^^^^^^^ this is the expected type `dependency::Type`
   |
  ::: replaced
   |
LL | pub struct Type;
   | ^^^^^^^^^^^^^^^ this is the found type `dep_2_reexport::Type`
   |
  ::: replaced
   |
LL | extern crate dep_2_reexport;
   | ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
LL | extern crate dependency;
   | ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate
   = help: you can use `cargo tree` to explore your dependency tree
note: function defined here
  --> replaced
   |
LL | pub fn do_something_type(_: Type) {}
   |        ^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
  --> replaced
   |
LL |     do_something_trait(Box::new(Type) as Box<dyn Trait2>);
   |     ------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `dependency::Trait2`, found trait `dep_2_reexport::Trait2`
   |     |
   |     arguments to this function are incorrect
   |
note: two different versions of crate `dependency` are being used; two types coming from two different versions of the same crate are different types even if they look the same
  --> replaced
   |
LL | pub trait Trait2 {}
   | ^^^^^^^^^^^^^^^^ this is the expected trait `dependency::Trait2`
   |
  ::: replaced
   |
LL | pub trait Trait2 {}
   | ^^^^^^^^^^^^^^^^ this is the found trait `dep_2_reexport::Trait2`
   |
  ::: replaced
   |
LL | extern crate dep_2_reexport;
   | ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
LL | extern crate dependency;
   | ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate
   = help: you can use `cargo tree` to explore your dependency tree
note: function defined here
  --> replaced
   |
LL | pub fn do_something_trait(_: Box<dyn Trait2>) {}
   |        ^^^^^^^^^^^^^^^^^^
```

or if it is different crates that were renamed to the same name:

```
error[E0308]: mismatched types
  --> $DIR/type-mismatch-same-crate-name.rs:21:20
   |
LL |         a::try_foo(foo2);
   |         ---------- ^^^^ expected `main:🅰️:Foo`, found a different `main:🅰️:Foo`
   |         |
   |         arguments to this function are incorrect
   |
note: two types coming from two different crates are different types even if they look the same
  --> $DIR/auxiliary/crate_a2.rs:1:1
   |
LL | pub struct Foo;
   | ^^^^^^^^^^^^^^ this is the found type `crate_a2::Foo`
   |
  ::: $DIR/auxiliary/crate_a1.rs:1:1
   |
LL | pub struct Foo;
   | ^^^^^^^^^^^^^^ this is the expected type `crate_a1::Foo`
   |
  ::: $DIR/type-mismatch-same-crate-name.rs:13:17
   |
LL |     let foo2 = {extern crate crate_a2 as a; a::Foo};
   |                 --------------------------- one type comes from crate `crate_a2` is used here, which is renamed locally to `a`
...
LL |         extern crate crate_a1 as a;
   |         --------------------------- one type comes from crate `crate_a1` is used here, which is renamed locally to `a`
note: function defined here
  --> $DIR/auxiliary/crate_a1.rs:10:8
   |
LL | pub fn try_foo(x: Foo){}
   |        ^^^^^^^

error[E0308]: mismatched types
  --> $DIR/type-mismatch-same-crate-name.rs:27:20
   |
LL |         a::try_bar(bar2);
   |         ---------- ^^^^ expected trait `main:🅰️:Bar`, found a different trait `main:🅰️:Bar`
   |         |
   |         arguments to this function are incorrect
   |
note: two types coming from two different crates are different types even if they look the same
  --> $DIR/auxiliary/crate_a2.rs:3:1
   |
LL | pub trait Bar {}
   | ^^^^^^^^^^^^^ this is the found trait `crate_a2::Bar`
   |
  ::: $DIR/auxiliary/crate_a1.rs:3:1
   |
LL | pub trait Bar {}
   | ^^^^^^^^^^^^^ this is the expected trait `crate_a1::Bar`
   |
  ::: $DIR/type-mismatch-same-crate-name.rs:13:17
   |
LL |     let foo2 = {extern crate crate_a2 as a; a::Foo};
   |                 --------------------------- one trait comes from crate `crate_a2` is used here, which is renamed locally to `a`
...
LL |         extern crate crate_a1 as a;
   |         --------------------------- one trait comes from crate `crate_a1` is used here, which is renamed locally to `a`
note: function defined here
  --> $DIR/auxiliary/crate_a1.rs:11:8
   |
LL | pub fn try_bar(x: Box<Bar>){}
   |        ^^^^^^^
```

This new output unifies the E0308 errors detail with the pre-existing E0277 errors, and better differentiates the "`extern crate` renamed" and "same crate, different versions" cases.
2024-12-08 14:28:24 +01:00
Matthias Krüger
5101833d7a
Rollup merge of #133104 - matthiaskrgr:crashtest_debugass_131451.rs, r=saethlin
crashes: add test for #131451

r? `@saethlin`
How do I find out which mir opts are involved here? 😅
2024-12-08 14:28:23 +01:00
Matthias Krüger
703bb98230
Rollup merge of #131669 - niacdoial:linting-ptrdyn-ffi, r=workingjubilee
lint: change help for pointers to dyn types in FFI

### Context
while playing around, I encountered the warning for dyn types in `extern "C"` functions, but even after that I assumed that a (rust) raw pointer could be interpreted in C ('s ABI) as a `void *`... to be fair part of why I ignored the warning is because I wanted to poke at the generated assembly, not make useful code.

### Example

```rust
extern "C"
fn caller(callee: *const dyn Fn(i32)->i32){
    // -- snip --
}
```

old warning:
```
warning: `extern` fn uses type `dyn Fn(i32) -> i32`, which is not FFI-safe
 --> file/name.rs:42:19
   |
42 | fn caller(callee: *const dyn Fn(i32)->i32) {
   |                   ^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
   |
  = note: trait objects have no C equivalent
  = note: `#[warn(improper_ctypes_definitions)]` on by default
  ```

new warning:
```
warning: `extern` fn uses type `dyn Fn(i32) -> i32`, which is not FFI-safe
 --> file/name.rs:42:19
   |
42 | fn caller(callee: *const dyn Fn(i32)->i32) -> (){
   |                   ^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
   |
  = note: this pointer to an unsized type contains metadata, which makes it incompatible with a C pointer
  = note: `#[warn(improper_ctypes_definitions)]` on by default
```
2024-12-08 14:28:22 +01:00
Matthias Krüger
159ed85d24 crashes: add test for #131451 2024-12-08 13:09:46 +01:00
许杰友 Jieyou Xu (Joe)
754dec3fbc Adjust atomic-from-mut-not-available.rs
- Introduce two revisions: one for 32-bit x86 vs one for 64-bit x86_64
  and compare & contrast the errors.
- Document the test intention and note its limitations.
2024-12-08 15:32:04 +08:00
许杰友 Jieyou Xu (Joe)
1247f01a3c Move atomic-from-mut-not-available.rs to tests/ui/stdlib-unit-tests/
This test exercises the combined effect of the
`cfg(target_has_atomic_equal_alignment = "...")` implementation in the
compiler as well as the usage of said
`cfg(target_has_atomic_equal_alignment)` in `core`.
2024-12-08 15:32:04 +08:00
许杰友 Jieyou Xu (Joe)
3a33522ca8 Adjust assoc-oddities-3.rs
- Include the original MCVE as reported in
  <https://github.com/rust-lang/rust/issues/28777>.
- Document the intention of the test.
2024-12-08 15:32:04 +08:00
许杰友 Jieyou Xu (Joe)
b815a93614 Move assoc-oddities-3.rs under tests/ui/parser/assoc/
This is where `assoc-oddities-{1,2}.rs` are located, reunite them!
2024-12-08 15:32:04 +08:00
许杰友 Jieyou Xu (Joe)
6959582ac6 Move assoc-lang-items.rs to tests/ui/lang-items/ 2024-12-08 15:32:04 +08:00
许杰友 Jieyou Xu (Joe)
1e3328dd72 Document assoc-lang-items.rs 2024-12-08 15:32:04 +08:00
许杰友 Jieyou Xu (Joe)
5e07f6e197 Move assign-imm-local-twice.rs to tests/ui/borrowck/ 2024-12-08 15:32:04 +08:00
许杰友 Jieyou Xu (Joe)
62c3160a29 Adjust assign-imm-local-twice.rs
- Document the test intention, including both the language semantics it
  is checking, as well as the borrowck diagnostics that this is
  exercising.
- Tag this test with `//@ run-rustfix` as this ui test exercises a
  suggestion diagnostics to make an immutable local var mutable.
- Minor error annotation reformatting.
2024-12-08 15:32:04 +08:00
许杰友 Jieyou Xu (Joe)
5a79963179 Move assign-assign.rs to tests/ui/codegen/assign-expr-unit-type.rs 2024-12-08 15:32:04 +08:00
许杰友 Jieyou Xu (Joe)
73b00ca8c6 Document assign-assign.rs 2024-12-08 15:31:40 +08:00
Esteban Küber
25ad0478cb Tweak wording 2024-12-07 22:18:51 +00:00
Esteban Küber
6277fb0a3f Use run-make diff output for stable output test 2024-12-07 21:37:15 +00:00
Esteban Küber
b466405890 Do not talk about "trait <Foo = Bar>"
Pass in an appropriate `Option<DefId>` in more cases from hir ty lowering.
2024-12-07 21:37:15 +00:00
Esteban Küber
af09423967 fix rustdoc test 2024-12-07 21:37:15 +00:00
Esteban Küber
cb4db0a6c6 Account for impl Trait in "add bound" suggestion message 2024-12-07 21:37:15 +00:00
Esteban Küber
d860e5b088 Mention type parameter in more cases and don't suggest ~const bound already there 2024-12-07 21:37:13 +00:00
Esteban Küber
3f2a63a68b Use trait name instead of full constraint in suggestion message
```
help: consider restricting type parameter `T` with traits `Copy` and `Trait`
   |
LL | fn duplicate_custom<T: Copy + Trait>(t: S<T>) -> (S<T>, S<T>) {
   |                      ++++++++++++++
```

```
help: consider restricting type parameter `V` with trait `Copy`
   |
LL | fn index<'a, K, V: std::marker::Copy>(map: &'a HashMap<K, V>, k: K) -> &'a V {
   |                  +++++++++++++++++++
```
2024-12-07 21:29:58 +00:00
Esteban Küber
568b0ac624 Add test for lack of suggestion in stable
This test will break when `Step` gets stabilized, but punt until then.
2024-12-07 21:26:23 +00:00
Esteban Küber
d13c34828e reword trait bound suggestion message to include the bounds 2024-12-07 21:26:20 +00:00
Esteban Küber
68253e14ee Don't suggest restricting bound with unstable traits on stable
On nightly, we mention the trait is unstable

```
error[E0277]: the trait bound `T: Unstable` is not satisfied
  --> $DIR/unstable-trait-suggestion.rs:13:9
   |
LL |     foo(t)
   |     --- ^ the trait `Unstable` is not implemented for `T`
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `foo`
  --> $DIR/unstable-trait-suggestion.rs:9:11
   |
LL | fn foo<T: Unstable>(_: T) {}
   |           ^^^^^^^^ required by this bound in `foo`
help: consider restricting type parameter `T` but it is an `unstable` trait
   |
LL | pub fn demo<T: Unstable>(t: T) {
   |              ++++++++++
```

On stable, we don't suggest the trait at all

```
error[E0277]: the trait bound `T: Unstable` is not satisfied
  --> $DIR/unstable-trait-suggestion.rs:13:9
   |
LL |     foo(t)
   |     --- ^ the trait `Unstable` is not implemented for `T`
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `foo`
  --> $DIR/unstable-trait-suggestion.rs:9:11
   |
LL | fn foo<T: Unstable>(_: T) {}
   |           ^^^^^^^^ required by this bound in `foo`
```
2024-12-07 21:10:44 +00:00
Esteban Küber
16bf7223ea Add more info on type/trait mismatches for different crate versions
When encountering a type or trait mismatch for two types coming from two different crates with the same name, detect if it is either mixing two types/traits from the same crate on different versions:

```
error[E0308]: mismatched types
  --> replaced
   |
LL |     do_something_type(Type);
   |     ----------------- ^^^^ expected `dependency::Type`, found `dep_2_reexport::Type`
   |     |
   |     arguments to this function are incorrect
   |
note: two different versions of crate `dependency` are being used; two types coming from two different versions of the same crate are different types even if they look the same
  --> replaced
   |
LL | pub struct Type(pub i32);
   | ^^^^^^^^^^^^^^^ this is the expected type `dependency::Type`
   |
  ::: replaced
   |
LL | pub struct Type;
   | ^^^^^^^^^^^^^^^ this is the found type `dep_2_reexport::Type`
   |
  ::: replaced
   |
LL | extern crate dep_2_reexport;
   | ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
LL | extern crate dependency;
   | ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate
   = help: you can use `cargo tree` to explore your dependency tree
note: function defined here
  --> replaced
   |
LL | pub fn do_something_type(_: Type) {}
   |        ^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
  --> replaced
   |
LL |     do_something_trait(Box::new(Type) as Box<dyn Trait2>);
   |     ------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `dependency::Trait2`, found trait `dep_2_reexport::Trait2`
   |     |
   |     arguments to this function are incorrect
   |
note: two different versions of crate `dependency` are being used; two types coming from two different versions of the same crate are different types even if they look the same
  --> replaced
   |
LL | pub trait Trait2 {}
   | ^^^^^^^^^^^^^^^^ this is the expected trait `dependency::Trait2`
   |
  ::: replaced
   |
LL | pub trait Trait2 {}
   | ^^^^^^^^^^^^^^^^ this is the found trait `dep_2_reexport::Trait2`
   |
  ::: replaced
   |
LL | extern crate dep_2_reexport;
   | ---------------------------- one version of crate `dependency` is used here, as a dependency of crate `foo`
LL | extern crate dependency;
   | ------------------------ one version of crate `dependency` is used here, as a direct dependency of the current crate
   = help: you can use `cargo tree` to explore your dependency tree
note: function defined here
  --> replaced
   |
LL | pub fn do_something_trait(_: Box<dyn Trait2>) {}
   |        ^^^^^^^^^^^^^^^^^^
```

or if it is different crates that were renamed to the same name:

```
error[E0308]: mismatched types
  --> $DIR/type-mismatch-same-crate-name.rs:21:20
   |
LL |         a::try_foo(foo2);
   |         ---------- ^^^^ expected `main:🅰️:Foo`, found a different `main:🅰️:Foo`
   |         |
   |         arguments to this function are incorrect
   |
note: two types coming from two different crates are different types even if they look the same
  --> $DIR/auxiliary/crate_a2.rs:1:1
   |
LL | pub struct Foo;
   | ^^^^^^^^^^^^^^ this is the found type `crate_a2::Foo`
   |
  ::: $DIR/auxiliary/crate_a1.rs:1:1
   |
LL | pub struct Foo;
   | ^^^^^^^^^^^^^^ this is the expected type `crate_a1::Foo`
   |
  ::: $DIR/type-mismatch-same-crate-name.rs:13:17
   |
LL |     let foo2 = {extern crate crate_a2 as a; a::Foo};
   |                 --------------------------- one type comes from crate `crate_a2` is used here, which is renamed locally to `a`
...
LL |         extern crate crate_a1 as a;
   |         --------------------------- one type comes from crate `crate_a1` is used here, which is renamed locally to `a`
note: function defined here
  --> $DIR/auxiliary/crate_a1.rs:10:8
   |
LL | pub fn try_foo(x: Foo){}
   |        ^^^^^^^

error[E0308]: mismatched types
  --> $DIR/type-mismatch-same-crate-name.rs:27:20
   |
LL |         a::try_bar(bar2);
   |         ---------- ^^^^ expected trait `main:🅰️:Bar`, found a different trait `main:🅰️:Bar`
   |         |
   |         arguments to this function are incorrect
   |
note: two types coming from two different crates are different types even if they look the same
  --> $DIR/auxiliary/crate_a2.rs:3:1
   |
LL | pub trait Bar {}
   | ^^^^^^^^^^^^^ this is the found trait `crate_a2::Bar`
   |
  ::: $DIR/auxiliary/crate_a1.rs:3:1
   |
LL | pub trait Bar {}
   | ^^^^^^^^^^^^^ this is the expected trait `crate_a1::Bar`
   |
  ::: $DIR/type-mismatch-same-crate-name.rs:13:17
   |
LL |     let foo2 = {extern crate crate_a2 as a; a::Foo};
   |                 --------------------------- one trait comes from crate `crate_a2` is used here, which is renamed locally to `a`
...
LL |         extern crate crate_a1 as a;
   |         --------------------------- one trait comes from crate `crate_a1` is used here, which is renamed locally to `a`
note: function defined here
  --> $DIR/auxiliary/crate_a1.rs:11:8
   |
LL | pub fn try_bar(x: Box<Bar>){}
   |        ^^^^^^^
```

This new output unifies the E0308 errors detail with the pre-existing E0277 errors, and better differentiates the "`extern crate` renamed" and "same crate, different versions" cases.
2024-12-07 18:18:08 +00:00
Nadrieril
2459dbb4ba Address review comments 2024-12-07 13:37:35 +01:00
bors
9c707a8b76 Auto merge of #133978 - matthiaskrgr:rollup-6gh1iho, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #130209 (Stabilize `std::io::ErrorKind::CrossesDevices`)
 - #130254 (Stabilize `std::io::ErrorKind::QuotaExceeded`)
 - #132187 (Add Extend impls for tuples of arity 1 through 12)
 - #133875 (handle `--json-output` properly)
 - #133934 (Do not implement unsafe auto traits for types with unsafe fields)
 - #133954 (Hide errors whose suggestions would contain error constants or types)
 - #133960 (rustdoc: remove eq for clean::Attributes)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-07 09:38:00 +00:00
bors
ca13e9169f Auto merge of #133883 - saethlin:remove-polymorphization, r=compiler-errors
Remove polymorphization

This PR removes the flag `-Zpolymorphize` and all the infrastructure in the compiler that exists only to support it, per https://github.com/rust-lang/compiler-team/issues/810.
2024-12-07 03:04:18 +00:00
Michael Goulet
db9e3681f9 Actually walk into lifetimes and attrs in EarlyContextAndPass 2024-12-07 02:08:40 +00:00
bors
75716b4510 Auto merge of #118159 - EliasHolzmann:formatting_options, r=m-ou-se
Implementation of `fmt::FormattingOptions`

Tracking issue: #118117

Public API:
```rust
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct FormattingOptions { … }
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Sign {
    Plus,
    Minus
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DebugAsHex {
    Lower,
    Upper
}

impl FormattingOptions {
    pub fn new() -> Self;
    pub fn sign(&mut self, sign: Option<Sign>) -> &mut Self;
    pub fn sign_aware_zero_pad(&mut self, sign_aware_zero_pad: bool) -> &mut Self;
    pub fn alternate(&mut self, alternate: bool) -> &mut Self;
    pub fn fill(&mut self, fill: char) -> &mut Self;
    pub fn align(&mut self, alignment: Option<Alignment>) -> &mut Self;
    pub fn width(&mut self, width: Option<usize>) -> &mut Self;
    pub fn precision(&mut self, precision: Option<usize>) -> &mut Self;
    pub fn debug_as_hex(&mut self, debug_as_hex: Option<DebugAsHex>) -> &mut Self;

    pub fn get_sign(&self) -> Option<Sign>;
    pub fn get_sign_aware_zero_pad(&self) -> bool;
    pub fn get_alternate(&self) -> bool;
    pub fn get_fill(&self) -> char;
    pub fn get_align(&self) -> Option<Alignment>;
    pub fn get_width(&self) -> Option<usize>;
    pub fn get_precision(&self) -> Option<usize>;
    pub fn get_debug_as_hex(&self) -> Option<DebugAsHex>;

    pub fn create_formatter<'a>(self, write: &'a mut (dyn Write + 'a)) -> Formatter<'a>;
    }

impl<'a> Formatter<'a> {
    pub fn new(write: &'a mut (dyn Write + 'a), options: FormattingOptions) -> Self;
    pub fn with_options<'b>(&'b mut self, options: FormattingOptions) -> Formatter<'b>;
    pub fn sign(&self) -> Option<Sign>;

    pub fn options(&self) -> FormattingOptions;
}
```

Relevant changes from the public API in the tracking issue (I'm leaving out some stuff I consider obvious mistakes, like missing `#[derive(..)]`s and `pub` specifiers):

- `enum DebugAsHex`/`FormattingOptions::debug_as_hex`/`FormattingOptions::get_debug_as_hex`: To support `{:x?}` as well as `{:X?}`. I had completely missed these options in the ACP. I'm open for any and all bikeshedding, not married to the name.
- `fill`/`get_fill` now takes/returns `char` instead of `Option<char>`. This simply mirrors what `Formatter::fill` returns (with default being `' '`).
- Changed `zero_pad`/`get_zero_pad` to `sign_aware_zero_pad`/`get_sign_aware_zero_pad`. This also mirrors `Formatter::sign_aware_zero_pad`. While I'm not a fan of this quite verbose name, I do believe that having the interface of `Formatter` and `FormattingOptions` be compatible is more important.
- For the same reason, renamed `alignment`/`get_alignment` to `aling`/`get_align`.
- Deviating from my initial idea, `Formatter::with_options` returns a `Formatter` which has the lifetime of the `self` reference as its generic lifetime parameter (in the original API spec, the generic lifetime of the returned `Formatter` was the generic lifetime used by `self` instead). Otherwise, one could construct two `Formatter`s that both mutably borrow the same underlying buffer, which would be unsound. This solution still has performance benefits over simply using `Formatter::new`, so I believe it is worthwhile to keep this method.
2024-12-06 22:28:42 +00:00
Ben Kimock
711c8cc690 Remove polymorphization 2024-12-06 16:42:09 -05:00
niacdoial
8b6289f6ae lint ImproperCTypes: message tweaks and refactoring from code review 2024-12-06 22:23:13 +01:00
niacdoial
9b59dd8178 lint ImproperCTypes: confirm that Box<FfiSafeType> and Option<Box<FfiSafeType>> are FFI-safe in function declarations too 2024-12-06 22:23:13 +01:00
niacdoial
7962a2de3a lint: fix ImproperCTypes edge case for unsized structs due to foreign types 2024-12-06 22:23:13 +01:00
niacdoial
1d52131043 lint: rework some ImproperCTypes messages (especially around indirections to !Sized) 2024-12-06 22:23:13 +01:00
Matthias Krüger
5d3a96346d
Rollup merge of #133954 - oli-obk:push-lxrmszqzszzu, r=jieyouxu
Hide errors whose suggestions would contain error constants or types

best reviewed commit-by-commit.

This is work towards cleaning up everything around `lit_to_const` and its mir equivalent.

fixes #123809
2024-12-06 21:21:07 +01:00
Matthias Krüger
6457761f80
Rollup merge of #133934 - jswrenn:unsafe-fields-auto-traits, r=compiler-errors
Do not implement unsafe auto traits for types with unsafe fields

If a type has unsafe fields, its safety invariants are not simply the conjunction of its field types' safety invariants. Consequently, it's invalid to reason about the safety properties of these types in a purely structural manner — i.e., the manner in which `auto` traits are implemented. Consequently, auto implementations of unsafe auto traits should not be generated for types with unsafe fields.

Tracking: #132922

r? `@compiler-errors`
2024-12-06 21:21:07 +01:00
bjorn3
85414ebea7 Fix ui-fulldep tests 2024-12-06 18:42:31 +00:00