Commit graph

17803 commits

Author SHA1 Message Date
Nicholas Nethercote
f8edc831ca Pretty-print PatKind::Missing as _.
Printing "no pattern" as `_` isn't ideal, but better than crashing, and
HIR pretty-printing already has plenty of imperfections. The added `f2`
and `f6` examples are ones that triggered the crash.

Note that some of the added examples are printed badly, e.g.
`fn(, ...)`. The next commit will fix those.

Fixes #139633.
2025-04-15 10:40:58 +10:00
Matthias Krüger
7dc3feccdd
Rollup merge of #139799 - clubby789:print=file, r=jieyouxu
Specify `--print info=file` syntax in `--help`

Closes #139794

I moved the listing of information that can be printed to the help string as it's getting rather long and it makes the `[=FILE]` part easier to see
2025-04-14 21:55:39 +02:00
Matthias Krüger
1bceed826e
Rollup merge of #139797 - folkertdev:naked-allow-unsafe, r=tgross35
Allow (but don't require) `#[unsafe(naked)]` so that `compiler-builtins` can upgrade to it

tracking issue: https://github.com/rust-lang/rust/issues/138997

Per https://github.com/rust-lang/rust/pull/134213#issuecomment-2755984503, we want to make the `#[naked]` attribute an unsafe attribute. Making that change runs into a cyclic dependency with `compiler-builtins` which uses `#[naked]`, where `rustc` needs an updated `compiler-builtins` and vice versa.

So based on https://github.com/rust-lang/rust/pull/139753 and [#t-compiler/help > updating `compiler-builtins` and `rustc`](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/updating.20.60compiler-builtins.60.20and.20.60rustc.60), this PR allows, but does not require `#[unsafe(naked)]`, and makes that change for some of the tests to check that both `#[naked]` and `#[unsafe(naked)]` are accepted.

Then we can upgrade and synchronize `compiler-builtins`, and then make `#[naked]` (without `unsafe`) invalid.

r? `@traviscross` (or someone from t-compiler if you're faster and this look allright)
2025-04-14 21:55:39 +02:00
Matthias Krüger
6b3531e915
Rollup merge of #139783 - jieyouxu:ignore-dir, r=Zalathar
Use `compiletest-ignore-dir` for bootstrap self-tests

Follow-up to #139705 and #139740.

I did another survey pass over `//@ ignore-test` under `tests/`, and this is the only 2 non-tests that should use `compiletest-ignore-dir`.

r? `@Zalathar` (or compiler/bootstrap)
2025-04-14 21:55:38 +02:00
Matthias Krüger
bf247c7086
Rollup merge of #139778 - reddevilmidzy:add-success-test, r=lcnr
Add test for issue 34834

closes: #34834

This PR adds a UI test for a case where a trait with an associated type using a higher-ranked trait bound (HRTB) failed to compile in Rust 1.55.0 but succeeded starting from 1.56.0.

```rust
pub trait Provides<'a> {
    type Item;
}

pub trait Selector: for<'a> Provides<'a> {
    type Namespace: PartialEq + for<'a> PartialEq<<Self as Provides<'a>>::Item>;

    fn get_namespace(&self) -> <Self as Provides>::Item;
}

pub struct MySelector;

impl<'a> Provides<'a> for MySelector {
    type Item = &'a str;
}

impl Selector for MySelector {
    type Namespace = String;

    fn get_namespace(&self) -> &str {
        unimplemented!()
    }
}

fn main() {}
```

*  [compile fail (rustc: 1.55.0)](https://godbolt.org/z/T1jY1Ebo6)
*  [compile pass (rustc: 1.56.0)](https://godbolt.org/z/e4jo11Ma7)
2025-04-14 21:55:38 +02:00
bors
2da29dbe8f Auto merge of #139577 - davidtwco:sizedness-go-vroom, r=oli-obk
re-use `Sized` fast-path

There's an existing fast path for the `type_op_prove_predicate` predicate, checking for trivially `Sized` types, which can be re-used when evaluating obligations within queries. This should improve performance and was found to be beneficial in #137944.

r? types
2025-04-14 19:54:27 +00:00
Folkert de Vries
cb22c1d5e9
Allow (but don't require) #[unsafe(naked)] so that compiler-builtins can upgrade to it 2025-04-14 20:44:15 +02:00
Michael Goulet
3df7882272 Normalize ADT fields in find_tails_for_unsizing 2025-04-14 16:51:00 +00:00
bors
990039ec53 Auto merge of #139814 - matthiaskrgr:rollup-lxkkcz6, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #139127 (Fix up partial res of segment in primitive resolution hack)
 - #139392 (Detect and provide suggestion for `&raw EXPR`)
 - #139767 (Visit place in `BackwardIncompatibleDropHint` statement)
 - #139777 (Remove `define_debug_via_print` for `ExistentialProjection`, use regular structural debug impl)
 - #139796 (ptr docs: add missing backtics around 'usize')
 - #139801 (Add myself to mailmap)
 - #139804 (use `realpath` in `bootstrap.py` when creating build-dir)
 - #139807 (Improve wording of post-merge report)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-14 16:45:11 +00:00
Matthias Krüger
143f5d7696
Rollup merge of #139767 - compiler-errors:www, r=oli-obk
Visit place in `BackwardIncompatibleDropHint` statement

Remove a weird hack from the `LocalUpdater` where we were manually visiting the place stored in a `StatementKind::BackwardIncompatibleDropHint` because the MIR visitor impls weren't doing so.

Also, clean up `BackwardIncompatibleDropHint`s in `CleanupPostBorrowck`, since they're not needed for runtime MIR.
2025-04-14 18:15:32 +02:00
Matthias Krüger
bf49dfc943
Rollup merge of #139392 - compiler-errors:raw-expr, r=oli-obk
Detect and provide suggestion for `&raw EXPR`

When emitting an error in the parser, and we detect that the previous token was `raw` and we *could* have consumed `const`/`mut`, suggest that this may have been a mistyped raw ref expr. To do this, we add `const`/`mut` to the expected token set when parsing `&raw` as an expression (which does not affect the "good path" of parsing, for the record).

This is kind of a rudimentary error improvement, since it doesn't actually attempt to recover anything, leading to some other knock-on errors b/c we still treat `&raw` as the expression that was parsed... but at least we add the suggestion! I don't think the parser grammar means we can faithfully recover `&raw EXPR` early, i.e. during `parse_expr_borrow`.

Fixes #133231
2025-04-14 18:15:31 +02:00
Matthias Krüger
a4adc005a1
Rollup merge of #139127 - compiler-errors:prim-ty-hack, r=oli-obk
Fix up partial res of segment in primitive resolution hack

There is a hack in the resolver:

```
// In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we
// don't report an error right away, but try to fallback to a primitive type.
```

This fixes up the resolution for primitives which would otherwise resolve to a module, but we weren't also updating the res of the path segment, leading to weird diagnostics.

We explicitly call `self.r.partial_res_map.insert` instead of `record_partial_res` b/c we have recorded a partial res already, and we specifically want to override it.

cc https://github.com/rust-lang/rust/issues/139095#issuecomment-2764371934
2025-04-14 18:15:30 +02:00
Oli Scherer
7ad16974b9 Allow const patterns of matches to contain pattern types 2025-04-14 14:27:35 +00:00
clubby789
1b46969a11 Specify --print info=file syntax in --help 2025-04-14 14:52:27 +01:00
bors
07d3fd1d9b Auto merge of #138603 - xizheyin:issue-137405, r=chenyukang
Report line number of test when should_panic test failed

Closes #137405

---

try-job: x86_64-gnu-llvm-19-3
try-job: test-various
2025-04-14 13:33:44 +00:00
lcnr
9c88eb6c43 normalize: prefer ParamEnv over AliasBound 2025-04-14 14:46:48 +02:00
lcnr
836ea25b4d add RPITIT tests: method compat auto trait leakage 2025-04-14 13:26:13 +02:00
lcnr
2e79f7cd61 move tests 2025-04-14 13:26:13 +02:00
lcnr
ce9d8678ca do not leak auto traits in item bounds 2025-04-14 13:26:13 +02:00
lcnr
2c2c9df653 drop global where-bounds before merging candidates 2025-04-14 12:59:22 +02:00
reddevilmidzy
6a8718cab7 Add test for issue 34834 2025-04-14 17:16:23 +09:00
Eddy (Eduard) Stefes
1ac3d6bba7 Let CStrings be either 1 or 2 byte aligned.
Some architectures (like s390x) require strings to be 2 byte aligned.
Therefor the section name will be marked with a .2  postfix on this
architectures.

Allowing a section name with a .1 or .2 postfix will make the test pass
on either platform.
2025-04-14 10:03:31 +02:00
Jieyou Xu
f3344ef4bd
tests: use compiletest-ignore-dir for bootstrap self-tests 2025-04-14 15:28:41 +08:00
bors
5961e5ba3d Auto merge of #139781 - jhpratt:rollup-qadsjvb, r=jhpratt
Rollup of 9 pull requests

Successful merges:

 - #138336 (Improve `-Z crate-attr` diagnostics)
 - #139636 (Encode dep node edge count as u32 instead of usize)
 - #139666 (cleanup `mir_borrowck`)
 - #139695 (compiletest: consistently use `camino::{Utf8Path,Utf8PathBuf}` throughout)
 - #139699 (Proactively update coroutine drop shim's phase to account for later passes applied during shim query)
 - #139718 (enforce unsafe attributes in pre-2024 editions by default)
 - #139722 (Move some things to rustc_type_ir)
 - #139760 (UI tests: migrate remaining compile time `error-pattern`s to line annotations when possible)
 - #139776 (Switch attrs to `diagnostic::on_unimplemented`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-14 07:07:54 +00:00
xizheyin
8c8212ef12
Consistent with treating Ctor Call as Struct in liveness analysis
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-14 14:29:14 +08:00
Nicholas Nethercote
ce2aa97cd6 Move has_self field to hir::AssocKind::Fn.
`hir::AssocItem` currently has a boolean `fn_has_self_parameter` field,
which is misplaced, because it's only relevant for associated fns, not
for associated consts or types. This commit moves it (and renames it) to
the `AssocKind::Fn` variant, where it belongs.

This requires introducing a new C-style enum, `AssocTag`, which is like
`AssocKind` but without the fields. This is because `AssocKind` values
are passed to various functions like `find_by_ident_and_kind` to
indicate what kind of associated item should be searched for, and having
to specify `has_self` isn't relevant there.

New methods:
- Predicates `AssocItem::is_fn` and `AssocItem::is_method`.
- `AssocItem::as_tag` which converts `AssocItem::kind` to `AssocTag`.

Removed `find_by_name_and_kinds`, which is unused.

`AssocItem::descr` can now distinguish between methods and associated
functions, which slightly improves some error messages.
2025-04-14 16:13:04 +10:00
xizheyin
edfdb9205c
Add ui test unreachable-by-call-arguments-issue-139627.rs
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-14 14:00:04 +08:00
Jacob Pratt
883c8dd52e
Rollup merge of #139760 - petrochenkov:noerrpat2, r=jieyouxu
UI tests: migrate remaining compile time `error-pattern`s to line annotations when possible

There's a number of cases in which `error-pattern` is still necessary even for compile time checking.
- It checks something that compiler writes directly into stderr as text, and not to the structured json output. This includes some stuff reported during compiler panics, and also diagnostics that happen very early, for example when parsing the command line.
- It checks something that exists only in the full rendered diagnostic test, but not in its structured components, for example code fragments or output of `-Ztrack-diagnostics`. (The latter can probably be converted to structured form though.)

This is continuation of https://github.com/rust-lang/rust/pull/139137.
r? `@jieyouxu`
2025-04-13 23:57:41 -04:00
Jacob Pratt
4a1d0cd1bd
Rollup merge of #139718 - folkertdev:unsafe-attributes-earlier-editions, r=fmease
enforce unsafe attributes in pre-2024 editions by default

New unsafe attributes should emit an error when used without the `unsafe(...)` in all editions.

The `no_mangle`, `link_section` and `export_name` attributes are exceptions, and can still be used without an unsafe in earlier editions. The only attributes for which this change is relevant right now are `#[ffi_const]` and `#[ffi_pure]`.

This change is required for making `#[unsafe(naked)]` sound in pre-2024 editions.
2025-04-13 23:57:40 -04:00
Jacob Pratt
c0ad72ef6a
Rollup merge of #139699 - compiler-errors:coroutine-drop-phase, r=scottmcm
Proactively update coroutine drop shim's phase to account for later passes applied during shim query

See comments in the pass and on test. Also see https://github.com/rust-lang/rust/pull/137264#issuecomment-2669706718.

Fixes https://github.com/rust-lang/rust/issues/137243
Fixes https://github.com/rust-lang/rust/issues/139698

r? scottmcm
2025-04-13 23:57:39 -04:00
Jacob Pratt
2b6835bf54
Rollup merge of #138336 - jyn514:crate-attr-diagnostics, r=compiler-errors
Improve `-Z crate-attr` diagnostics

- Show the `#![ ... ]` in the span (to make it clear that it should not
  be included in the CLI argument)
- Show more detailed errors when the crate has valid token trees but
  invalid syntax.
  Previously, `crate-attr=feature(foo),feature(bar)` would just say
  "invalid crate attribute" and point at the comma. Now, it explicitly
  says that the comma was unexpected, which is useful when using
  `--error-format=short`. It also fixes the column to show the correct
  span.
- Recover from parse errors. Previously we would abort immediately on
  syntax errors; now we go on to try and type-check the rest of the
  crate.

The new diagnostic code also happens to be slightly shorter.

r? diagnostics
2025-04-13 23:57:37 -04:00
bors
f836ae4e66 Auto merge of #124141 - nnethercote:rm-Nonterminal-and-TokenKind-Interpolated, r=petrochenkov
Remove `Nonterminal` and `TokenKind::Interpolated`

A third attempt at this; the first attempt was #96724 and the second was #114647.

r? `@ghost`
2025-04-14 03:56:55 +00:00
xizheyin
dc3a586eed Adjust test directives
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-14 10:36:13 +08:00
xizheyin
c73598f0fb Report span of test when should_panic test failed
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-14 10:36:11 +08:00
bors
15f58c46da Auto merge of #139766 - jhpratt:rollup-afrfmnk, r=jhpratt
Rollup of 10 pull requests

Successful merges:

 - #137043 (Initial `UnsafePinned` implementation [Part 1: Libs])
 - #138962 (Expect an array when expected and acutal types are both arrays during cast)
 - #139001 (add `naked_functions_rustic_abi` feature gate)
 - #139379 (Use delayed bug for normalization errors in drop elaboration)
 - #139582 (Various coercion cleanups)
 - #139628 (Suggest remove redundant `$()?` around `vis`)
 - #139644 (Micro-optimize `InstSimplify`'s `simplify_primitive_clone`)
 - #139674 (In `rustc_mir_transform`, iterate over index newtypes instead of ints)
 - #139740 (Convert `tests/ui/lint/dead-code/self-assign.rs` to a known-bug test)
 - #139741 (fix smir's run! doc and import)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-14 00:47:02 +00:00
mejrs
4a5369b476 Remove rustc_on_unimplemented on impl tests 2025-04-14 00:12:37 +02:00
mejrs
40e76c1575 Test that Self properly works in filters 2025-04-14 00:12:37 +02:00
mejrs
10ec5cbe96 Raise errors on bad rustc_on_unimplemented format strings again 2025-04-14 00:12:37 +02:00
mejrs
9abaa9d4df Disable usage on trait impls and aliases 2025-04-14 00:12:37 +02:00
Michael Goulet
2f96e784e2 Visit place in BackwardIncompatibleDropHint statement 2025-04-13 22:01:54 +00:00
Jacob Pratt
7ce62af35a
Rollup merge of #139741 - os-checker:smir-run-macro, r=scottmcm
fix smir's run! doc and import

This PR
* adds missing `extern crate rustc_middle` in `rustc_smir::run!` docstring
* adds missing `use rustc_smir::rustc_internal` in `run_driver!` scope
  * also adjust some tests that don't need to import rustc_internalany more
2025-04-13 17:37:56 -04:00
Jacob Pratt
7ba09db7f2
Rollup merge of #139740 - jieyouxu:known-bug, r=nnethercote
Convert `tests/ui/lint/dead-code/self-assign.rs` to a known-bug test

I did a survey pass over `tests/`, and this test seems like the only candidate suitable for conversion into a known-bug test. (Other tests had varying degrees of other issues that known-bug would not be suitable.)

r? compiler
2025-04-13 17:37:55 -04:00
Jacob Pratt
a04a03720e
Rollup merge of #139628 - makai410:suggest-vis, r=compiler-errors
Suggest remove redundant `$()?` around `vis`

Resolves: #139480 .
2025-04-13 17:37:54 -04:00
Jacob Pratt
346d33a5b7
Rollup merge of #139379 - matthewjasper:drop-elab-normalization, r=compiler-errors
Use delayed bug for normalization errors in drop elaboration

Normalization can fail due to a lot of different earlier errors, so just use span_delayed_bug if normalization failed.

Closes #137287
Closes #135668

r? compiler-errors
2025-04-13 17:37:53 -04:00
Jacob Pratt
7f691d28f1
Rollup merge of #139001 - folkertdev:naked-function-rustic-abi, r=traviscross,compiler-errors
add `naked_functions_rustic_abi` feature gate

tracking issue: https://github.com/rust-lang/rust/issues/138997

Because the details of the rust abi are unstable, and a naked function must match its stated ABI, this feature gate keeps naked functions with a rustic abi ("Rust", "rust-cold", "rust-call" and "rust-intrinsic") unstable.

r? ````@traviscross````
2025-04-13 17:37:52 -04:00
Jacob Pratt
60c76b9dfd
Rollup merge of #138962 - xizheyin:issue-138836, r=compiler-errors
Expect an array when expected and acutal types are both arrays during cast

Closes #138836
2025-04-13 17:37:52 -04:00
Jacob Pratt
d04df1cba9
Rollup merge of #137043 - Sky9x:unsafe-pinned-pt1-libs, r=tgross35,RalfJung,WaffleLapkin
Initial `UnsafePinned` implementation [Part 1: Libs]

Initial libs changes necessary to unblock further work on [RFC 3467](https://rust-lang.github.io/rfcs/3467-unsafe-pinned.html).
Tracking issue: #125735

This PR is split off from #136964, and includes just the libs changes:
- `UnsafePinned` struct
- private `UnsafeUnpin` structural auto trait
- Lang items for both
- Compiler changes necessary to block niches on `UnsafePinned`

This PR does not change codegen, miri, the existing `!Unpin` hack, or anything else. That work is to be split into later PRs.

---

cc ``@RalfJung`` ``@Noratrieb``

``@rustbot`` label F-unsafe_pinned T-libs-api
2025-04-13 17:37:51 -04:00
jyn
d50a8d5fb3 Improve -Z crate-attr diagnostics
- Show the `#![ ... ]` in the span (to make it clear that it should not
  be included in the CLI argument)
- Show more detailed errors when the crate has valid token trees but
  invalid syntax.
  Previously, `crate-attr=feature(foo),feature(bar)` would just say
  "invalid crate attribute" and point at the comma. Now, it explicitly
  says that the comma was unexpected, which is useful when using
  `--error-format=short`. It also fixes the column to show the correct
  span.
- Recover from parse errors. Previously we would abort immediately on
  syntax errors; now we go on to try and type-check the rest of the
  crate.

The new diagnostic code also happens to be slightly shorter.
2025-04-13 16:46:02 -04:00
clubby789
9f35fe47c7 JumpThreading: Re-enable and fix Not ops on non-booleans 2025-04-13 20:29:49 +00:00
Vadim Petrochenkov
93bee0789a UI tests: migrate remaining compile time error-patterns to line annotations
when possible.
2025-04-13 21:48:53 +03:00