Commit Graph

5251 Commits

Author SHA1 Message Date
bors
ee9c7c940c Auto merge of #120847 - oli-obk:track_errors9, r=compiler-errors
Continue compilation after check_mod_type_wf errors

The ICEs fixed here were probably reachable through const eval gymnastics before, but now they are easily reachable without that, too.

The new errors are often bugfixes, where useful errors were missing, because they were reported after the early abort. In other cases sometimes they are just duplication of already emitted errors, which won't be user-visible due to deduplication.

fixes https://github.com/rust-lang/rust/issues/120860
2024-02-14 18:32:19 +00:00
Guillaume Gomez
18c935d000
Rollup merge of #121075 - chenyukang:yukang-fix-121070-lint-range, r=oli-obk
Fix false positive with if let and ranges

Fixes #121070
2024-02-14 15:41:28 +01:00
Guillaume Gomez
8e690fdd6a
Rollup merge of #120966 - chenyukang:yukang-fix-120599-resolve, r=pnkfelix
Remove importing suggestions when there is a shadowed typo candidate

Fixes #120559
2024-02-14 15:41:27 +01:00
Guillaume Gomez
b36e094802
Rollup merge of #120893 - c410-f3r:testsssssss, r=petrochenkov
Move some tests

r? `@petrochenkov`
2024-02-14 15:41:26 +01:00
Oli Scherer
25806f8d80 Use the correct char type on all platforms 2024-02-14 11:12:19 +00:00
Oli Scherer
5f6390f947 Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
Oli Scherer
9e31121985
Rollup merge of #121049 - estebank:issue-121009, r=fmease
Do not point at `#[allow(_)]` as the reason for compat lint triggering

Fix #121009.
2024-02-14 11:53:42 +01:00
Oli Scherer
f77870e170
Rollup merge of #121045 - jieyouxu:fix-ui-tests, r=oli-obk
Fix two UI tests with incorrect directive / invalid revision

- `tests/ui/borrowck/copy-suggestion-region-vid.rs` had a `ui_test`-style directive on compiletest: `//`@run-rustfix`.`
- `tests/ui/asm/inline-syntax.rs` has directives for a undeclared revision `[x86_64_allowed]` which seems to have the same directives as declared revision `[x86_64]`.
2024-02-14 11:53:41 +01:00
Oli Scherer
f3e66edd63
Rollup merge of #120915 - OdenShirataki:master, r=fmease
Fix suggestion span for `?Sized` when param type has default

Fixes #120878

Diagnostic suggests adding `: ?Sized` in an incorrect place if a type parameter default is present

r? `@fmease`
2024-02-14 11:53:39 +01:00
Oli Scherer
c4371a79de
Rollup merge of #120530 - trevyn:issue-116434, r=compiler-errors
Be less confident when `dyn` suggestion is not checked for object safety

#120275 no longer checks bare traits for object safety when making a `dyn` suggestion on Rust < 2021. In this case, qualify the suggestion with a note that the trait must be object safe, to prevent user confusion as seen in #116434

r? ```@fmease```
2024-02-14 11:53:39 +01:00
许杰友 Jieyou Xu (Joe)
ee88f3435a
Fix two UI tests with incorrect directive / invalid revision 2024-02-14 09:13:53 +00:00
yukang
2fe73cea5e Fix false positive with if let and ranges 2024-02-14 15:15:22 +08:00
yukang
2a229c96e8 remove importing suggestions when there is a shadowed typo canddiate 2024-02-14 14:08:51 +08:00
Matthias Krüger
ab1fa19d08
Rollup merge of #121047 - compiler-errors:default-impls, r=lcnr
Do not assemble candidates for default impls

There is no reason (as far as I can tell?) that we should assemble an impl candidate for a default impl. This candidate itself does not prove that the impl holds, and any time that it *does* hold, there will be a more specializing non-default impl that also is assembled.

This is because `default impl<T> Foo for T {}` actually expands to `impl<T> Foo for T where T: Foo {}`. The only way to satisfy that where clause (without coinduction) is via *another* implementation that does hold -- precisely an impl that specializes it.

This should fix the specialization related regressions for #116494. That should lead to one root crate regression that doesn't have to do with specialization, which I think we can regress.

r? lcnr cc ``@rust-lang/types``

cc #31844
2024-02-13 22:51:57 +01:00
Matthias Krüger
147fd3f236
Rollup merge of #121002 - lcnr:cleanup-commit_if_ok, r=oli-obk
remove unnecessary calls to `commit_if_ok`

we propagate the error outwards, so anything which wants to discard the error should do so itself.

r? types
2024-02-13 22:51:55 +01:00
Matthias Krüger
db9591cfb6
Rollup merge of #118882 - compiler-errors:normalized-sig-wf, r=lcnr
Check normalized call signature for WF in mir typeck

Unfortunately we don't check that the built-in implementations for `Fn*` traits are actually well-formed in the same way that we do for user-provided impls.

Essentially, when checking a call terminator, we end up with a signature that references an unnormalized `<[closure] as FnOnce<...>>::Output` in its output. That output type, due to the built-in impl, doesn't follow the expected rule that `WF(ty)` implies `WF(normalized(ty))`. We fix this by also checking the normalized signature here.

**See** boxy's detailed and useful explanation comment which explains this in more detail: https://github.com/rust-lang/rust/issues/114936#issuecomment-1710388741

Fixes #114936
Fixes #118876

r? types
cc ``@BoxyUwU`` ``@lcnr``
2024-02-13 22:51:53 +01:00
Caio
0e9aa75bcd Move tests 2024-02-13 18:08:25 -03:00
Esteban Küber
24b52fd9df Do not point at #[allow(_)] as the reason for compat lint triggering
Fix #121009.
2024-02-13 20:27:43 +00:00
Michael Goulet
b4eee2e8b3 Do not assemble candidates for default impls 2024-02-13 19:20:13 +00:00
Matthias Krüger
93e9579b5d
Rollup merge of #120959 - nnethercote:rm-good_path, r=oli-obk
Remove good path delayed bugs

Because they're not that useful, and kind of annoying. Details in the individual commits.

r? ```@compiler-errors```
2024-02-13 17:38:10 +01:00
Matthias Krüger
65ab663266
Rollup merge of #120549 - lcnr:errs-showcase, r=compiler-errors
modify alias-relate to also normalize ambiguous opaques

allows a bunch of further cleanups and generally simplifies the type system. To handle https://github.com/rust-lang/trait-system-refactor-initiative/issues/8 we'll have to add a some additional complexity to the `(Alias, Infer)` branches in alias-relate, so removing the opaque type special case here is really valuable.

It does worsen `deduce_closure_signature` and friends even more as they now receive an inference variable which is only constrained via an `AliasRelate` goal. These probably have to look into alias relate goals somehow. Leaving that for a future PR as this is something we'll have to tackle regardless.

r? `@compiler-errors`
2024-02-13 17:38:10 +01:00
Michael Goulet
2b4a2b95dd Check normalized call signature for WF in mir typeck 2024-02-13 16:00:01 +00:00
Matthias Krüger
d95f0000fb
Rollup merge of #120973 - RalfJung:static_mut_ref, r=compiler-errors
allow static_mut_ref in some tests that specifically test mutable statics

The lint just distracts from what these tests are about.
2024-02-13 06:27:39 +01:00
Matthias Krüger
30057f0266
Rollup merge of #120802 - oli-obk:drop_elab_ice, r=compiler-errors
Bail out of drop elaboration when encountering error types

fixes  #120788
2024-02-13 06:27:38 +01:00
Matthias Krüger
1b396913a9
Rollup merge of #120751 - estebank:issue-68982, r=nnethercote
Provide more suggestions on invalid equality where bounds

```
error: equality constraints are not yet supported in `where` clauses
  --> $DIR/equality-bound.rs:50:9
   |
LL |         IntoIterator::Item = A
   |         ^^^^^^^^^^^^^^^^^^^^^^ not supported
   |
   = note: see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information
help: if `IntoIterator::Item` is an associated type you're trying to set, use the associated type binding syntax
   |
LL ~     fn from_iter<T: IntoIterator<Item = A>>(_: T) -> Self
LL ~
   |

error: equality constraints are not yet supported in `where` clauses
  --> $DIR/equality-bound.rs:63:9
   |
LL |         T::Item = A
   |         ^^^^^^^^^^^ not supported
   |
   = note: see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information
help: if `IntoIterator::Item` is an associated type you're trying to set, use the associated type binding syntax
   |
LL ~     fn from_iter<T: IntoIterator<Item = A>>(_: T) -> Self
LL ~
   |
```

Fix #68982.
2024-02-13 06:27:37 +01:00
Matthias Krüger
020e84652d
Rollup merge of #120696 - estebank:issue-115405, r=oli-obk
Properly handle `async` block and `async fn` in `if` exprs without `else`

When encountering a tail expression in the then arm of an `if` expression without an `else` arm, account for `async fn` and `async` blocks to suggest `return`ing the value and pointing at the return type of the `async fn`.

We now also account for AFIT when looking for the return type to point at.

Fix #115405.
2024-02-13 06:27:37 +01:00
lcnr
ae92334c0f remove questionable calls to commit_if_ok 2024-02-13 05:44:46 +01:00
lcnr
51a1000cda one must imagine ci happy 2024-02-13 05:08:53 +01:00
lcnr
e5541cf895 add revisions 2024-02-13 05:08:53 +01:00
lcnr
3e3e207ad7 use alias-relate to structurally normalize in the solver 2024-02-13 05:08:51 +01:00
Nicholas Nethercote
9f2aa09765 Remove good_path_delayed_bug.
It's only has a single remaining purpose: to ensure that a diagnostic is
printed when `trimmed_def_paths` is used. It's an annoying mechanism:
weak, with odd semantics, badly named, and gets in the way of other
changes.

This commit replaces it with a simpler `must_produce_diag` mechanism,
getting rid of a diagnostic `Level` along the way.
2024-02-13 09:33:35 +11:00
Matthias Krüger
f759c23b5c
Rollup merge of #120970 - RalfJung:static-promoted-test, r=oli-obk
add another test for promoteds-in-static

https://github.com/rust-lang/rust/pull/119614 led to validation of promoteds recursing into statics. These statics can point to `static mut` and interior mutable `static` and do other things we don't allow in `const`, but promoteds are validated as `const`, so we get strange errors (saying "in `const`" when there is no const) and surprising validation failures.

https://github.com/rust-lang/rust/pull/120960 fixes that; this here adds another test.

r? ``@oli-obk``
Fixes https://github.com/rust-lang/rust/issues/120968
2024-02-12 23:18:55 +01:00
Matthias Krüger
7075502b15
Rollup merge of #120965 - ChrisDenton:sahf, r=michaelwoerister
Add lahfsahf and prfchw target feature

This adds target features for LAHF/SAHF and PrefetchW. These came up. along with the existing CMPXCHG16b. as [baseline features](https://download.microsoft.com/download/c/1/5/c150e1ca-4a55-4a7e-94c5-bfc8c2e785c5/Windows%2010%20Minimum%20Hardware%20Requirements.pdf) required for x86_64 Windows 10+.
2024-02-12 23:18:54 +01:00
Matthias Krüger
cb0d74be28
Rollup merge of #120958 - ShoyuVanilla:remove-subst, r=oli-obk
Dejargonize `subst`

In favor of #110793, replace almost every occurence of `subst` and `substitution` from rustc codes, but they still remains in subtrees under `src/tools/` like clippy and test codes (I'd like to replace them after this)
2024-02-12 23:18:54 +01:00
Matthias Krüger
74f5e1f140
Rollup merge of #118983 - Urgau:invalid_ref_casting-bigger-layout, r=oli-obk
Warn on references casting to bigger memory layout

This PR extends the [`invalid_reference_casting`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#invalid-reference-casting) lint (*deny-by-default*) which currently lint on `&T -> &mut T` casting to also lint on `&(mut) A -> &(mut) B` where `size_of::<B>() > size_of::<A>()` (bigger memory layout requirement).

The goal is to detect such cases:

```rust
let u8_ref: &u8 = &0u8;
let u64_ref: &u64 = unsafe { &*(u8_ref as *const u8 as *const u64) };
//~^ ERROR casting references to a bigger memory layout is undefined behavior

let mat3 = Mat3 { a: Vec3(0i32, 0, 0), b: Vec3(0, 0, 0), c: Vec3(0, 0, 0) };
let mat3 = unsafe { &*(&mat3 as *const _ as *const [[i64; 3]; 3]) };
//~^ ERROR casting references to a bigger memory layout is undefined behavior
```

This is added to help people who write unsafe code, especially when people have matrix struct that they cast to simple array of arrays.

EDIT: One caveat, due to the [`&Header`](https://github.com/rust-lang/unsafe-code-guidelines/issues/256) uncertainty the lint only fires when it can find the underline allocation.

~~I have manually tested all the new expressions that warn against Miri, and they all report immediate UB.~~

r? ``@est31``
2024-02-12 23:18:52 +01:00
Ralf Jung
6fe4d66e64 allow static_mut_ref in some tests that specifically test mutable statics 2024-02-12 23:07:07 +01:00
Esteban Küber
37d2ea2fa0 Properly handle async blocks and fns in if exprs without else
When encountering a tail expression in the then arm of an `if` expression
without an `else` arm, account for `async fn` and `async` blocks to
suggest `return`ing the value and pointing at the return type of the
`async fn`.

We now also account for AFIT when looking for the return type to point at.

Fix #115405.
2024-02-12 20:26:34 +00:00
Urgau
915200fbe0 Lint on reference casting to bigger underlying allocation 2024-02-12 19:40:17 +01:00
bors
b381d3ab27 Auto merge of #120980 - matthiaskrgr:rollup-dsjsqql, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #120765 (Reorder diagnostics API)
 - #120833 (More internal emit diagnostics cleanups)
 - #120899 (Gracefully handle non-WF alias in `assemble_alias_bound_candidates_recur`)
 - #120917 (Remove a bunch of dead parameters in functions)
 - #120928 (Add test for recently fixed issue)
 - #120933 (check_consts: fix duplicate errors, make importance consistent)
 - #120936 (improve `btree_cursors` functions documentation)
 - #120944 (Check that the ABI of the instance we are inlining is correct)
 - #120956 (Clean inlined type alias with correct param-env)
 - #120962 (Add myself to library/std review)
 - #120972 (fix ICE for deref coercions with type errors)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-12 17:06:22 +00:00
Matthias Krüger
8e5f722ece
Rollup merge of #120972 - lukas-code:autoderef-type-error, r=compiler-errors
fix ICE for deref coercions with type errors

Follow-up to https://github.com/rust-lang/rust/pull/120895, where I made types with errors go through the full coercion code, which is necessary if we want to build MIR for bodies with errors (https://github.com/rust-lang/rust/pull/120550).

The code for coercing `&T` to `&U` currently assumes that autoderef for `&T` will succeed for at least two steps (`&T` and `T`):

b17491c8f6/compiler/rustc_hir_typeck/src/coercion.rs (L339-L464)

But for types with errors, we previously only returned the no-op autoderef step (`&{type error}` -> `&{type error}`) and then stopped early. This PR changes autoderef for types with errors to still go through the built-in derefs (e.g. `&&{type error}` -> `&{type error}` -> `{type error}`) and only stop early when it would have to go looking for `Deref` trait impls.

fixes https://github.com/rust-lang/rust/issues/120945

r? ``@compiler-errors`` or compiler
2024-02-12 18:04:11 +01:00
Matthias Krüger
8ec144d738
Rollup merge of #120944 - compiler-errors:inliner-abi, r=oli-obk
Check that the ABI of the instance we are inlining is correct

When computing the `CallSite` in the mir inliner, double check that the instance of the function that we are inlining is compatible with the signature from the trait definition that we acquire from the MIR.

Fixes #120940

r? ``@oli-obk`` or ``@cjgillot``
2024-02-12 18:04:10 +01:00
Matthias Krüger
3f67169a5f
Rollup merge of #120933 - RalfJung:const-check-misc, r=oli-obk
check_consts: fix duplicate errors, make importance consistent

This is stuff I noticed while working on https://github.com/rust-lang/rust/pull/120932, but it's orthogonal to that PR.

r? ``@oli-obk``
2024-02-12 18:04:09 +01:00
Matthias Krüger
02c1e3ed07
Rollup merge of #120928 - c410-f3r:tests-tests-tests, r=davidtwco
Add test for recently fixed issue

Adds a test for issue #116864.
2024-02-12 18:04:09 +01:00
Matthias Krüger
733f93d60c
Rollup merge of #120899 - compiler-errors:non-wf-alias, r=lcnr
Gracefully handle non-WF alias in `assemble_alias_bound_candidates_recur`

See explanation in test. I think it's fine to delay a bug here -- I don't believe we ever construct a non-wf alias on the good path? If so, then we can just remove the delay.

Fixes #120891

r? lcnr
2024-02-12 18:04:08 +01:00
Matthias Krüger
f08ece38a8
Rollup merge of #120833 - nnethercote:more-internal-emit_diagnostics-cleanups, r=oli-obk
More internal emit diagnostics cleanups

Miscellaneous improvements.

r? ``@oli-obk``
2024-02-12 18:04:07 +01:00
bors
bdc15928c8 Auto merge of #115367 - frank-king:feature/unnamed-fields-hir, r=davidtwco
Lowering unnamed fields and anonymous adt

This implements #49804.

Goals:
- [x] lowering anonymous ADTs from AST to HIR
- [x] generating definitions of anonymous ADTs
- [x] uniqueness check of the unnamed fields
- [x] field projection of anonymous ADTs
- [x] `#[repr(C)]` check of the anonymous ADTs

Non-Goals (will be in the next PRs)
- capturing generic params for the anonymous ADTs from the parent ADT
- pattern matching of anonymous ADTs
- structural expressions of anonymous ADTs
- rustdoc support of anonymous ADTs
2024-02-12 14:51:15 +00:00
Ralf Jung
a313ffb884 add another test for promoteds-in-static 2024-02-12 15:27:32 +01:00
Lukas Markeffsky
95c5b06000 fix ICE for deref coercions with type errors 2024-02-12 14:37:35 +01:00
Chris Denton
83a850f2a1
Add lahfsahf and prfchw target feature 2024-02-12 10:31:12 -03:00
bors
ed19532868 Auto merge of #120960 - RalfJung:static-promoted-cycle, r=oli-obk
fix cycle error when a static and a promoted are mutually recursive

This also now allows promoteds everywhere to point to 'extern static', because why not? We still check that constants cannot transitively reach 'extern static' through references. (We allow it through raw pointers.)

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/120949
2024-02-12 12:09:20 +00:00