Commit Graph

29439 Commits

Author SHA1 Message Date
David Tolnay
0a82920b56
Declare rustc_target dependency on object/macho 2023-10-26 19:06:16 -07:00
David Tolnay
b7debe34e6
Parse rustc version at compile time 2023-10-26 18:55:05 -07:00
bors
aa91057796 Auto merge of #113183 - estebank:redundant-sized-errors, r=davidtwco
Only emit one error per unsized binding, instead of one per usage

Fix #56607.
2023-10-27 00:06:12 +00:00
clubby789
e81a5c65d9 Recover ternary expression as error 2023-10-26 23:04:20 +00:00
Kjetil Kjeka
4d33876778 Documentation and error message improvements related to PassMode::Direct assert
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2023-10-27 00:55:24 +02:00
Esteban Küber
87dc85d322 Suggest assoc fn new when trying to build tuple struct with private fields
Fix #22488.
2023-10-26 22:21:05 +00:00
Antoni Boucher
c797cccda6 Merge commit 'e4fe941b11a55c5005630696e9b6d81c65f7bd04' into subtree-update_cg_gcc_2023-10-25 2023-10-26 17:42:02 -04:00
Matthias Krüger
2656c987d6
Rollup merge of #117188 - dtolnay:symbolenv, r=cjgillot
Avoid repeated interning of `env!("CFG_RELEASE")`

Implements `@cjgillot's` suggestion from https://github.com/rust-lang/rust/pull/117148#discussion_r1372117485.
2023-10-26 22:26:12 +02:00
Matthias Krüger
a8f7acd8f8
Rollup merge of #117114 - nnethercote:improve-stringify-test, r=petrochenkov
Improve `stringify.rs` test

Best reviewed one commit at a time.

r? `@petrochenkov`
2023-10-26 22:26:11 +02:00
Matthias Krüger
d09c988791
Rollup merge of #117106 - estebank:issue-27300, r=petrochenkov
When expecting closure argument but finding block provide suggestion

Detect if there is a potential typo where the `{` meant to open the closure body was written before the body.

```
error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<usize>`
  --> $DIR/ruby_style_closure_successful_parse.rs:3:31
   |
LL |       let p = Some(45).and_then({|x|
   |  ______________________--------_^
   | |                      |
   | |                      required by a bound introduced by this call
LL | |         1 + 1;
LL | |         Some(x * 2)
   | |         ----------- this tail expression is of type `Option<usize>`
LL | |     });
   | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<usize>`
   |
   = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<usize>`
note: required by a bound in `Option::<T>::and_then`
  --> $SRC_DIR/core/src/option.rs:LL:COL
help: you might have meant to open the closure body instead of placing a closure within a block
   |
LL -     let p = Some(45).and_then({|x|
LL +     let p = Some(45).and_then(|x| {
   |
```

Detect the potential typo where the closure header is missing.

```
error[E0277]: expected a `FnOnce<(&bool,)>` closure, found `bool`
  --> $DIR/block_instead_of_closure_in_arg.rs:3:23
   |
LL |        Some(true).filter({
   |  _________________------_^
   | |                 |
   | |                 required by a bound introduced by this call
LL | |/         if number % 2 == 0 {
LL | ||             number == 0
LL | ||         } else {
LL | ||             number != 0
LL | ||         }
   | ||_________- this tail expression is of type `bool`
LL | |      });
   | |______^ expected an `FnOnce<(&bool,)>` closure, found `bool`
   |
   = help: the trait `for<'a> FnOnce<(&'a bool,)>` is not implemented for `bool`
note: required by a bound in `Option::<T>::filter`
  --> $SRC_DIR/core/src/option.rs:LL:COL
help: you might have meant to create the closure instead of a block
   |
LL |     Some(true).filter(|_| {
   |                       +++
```

Partially address #27300. Fix #104690.
2023-10-26 22:26:11 +02:00
Matthias Krüger
934cbe4637
Rollup merge of #116968 - eopb:116967, r=petrochenkov
Invalid `?` suggestion on mismatched `Ok(T)`

fixes: #116967
2023-10-26 22:26:10 +02:00
Kjetil Kjeka
84c9c4aca7 NVPTX: Allow PassMode::Direct for ptx kernels for now 2023-10-26 21:57:19 +02:00
Urgau
828f069c12 Remove most indentation in check-cfg impl 2023-10-26 20:43:17 +02:00
Esteban Küber
27919ceba7 Tweak suggestion spans for invalid crate-level inner attribute
CC #89566.
2023-10-26 18:35:09 +00:00
Esteban Küber
3bbc70a5f7 Restrict param constraint suggestion
When encountering an associated item with a type param that could be
constrained, do not look at the parent item if the type param comes from
the associated item.

Fix #117209.
2023-10-26 18:33:03 +00:00
Michael Goulet
1836c1fbbd Stash and cancel cycle errors for auto trait leakage in opaques 2023-10-26 17:58:02 +00:00
bors
8396efecf7 Auto merge of #117228 - matthiaskrgr:rollup-23zzepv, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #116905 (refactor(compiler/resolve): simplify some code)
 - #117095 (Add way to differentiate argument locals from other locals in Stable MIR)
 - #117143 (Avoid unbounded O(n^2) when parsing nested type args)
 - #117194 (Minor improvements to `rustc_incremental`)
 - #117202 (Revert "Remove TaKO8Ki from reviewers")
 - #117207 (The value of `-Cinstrument-coverage=` doesn't need to be `Option`)
 - #117214 (Quietly fail if an error has already occurred)
 - #117221 (Rename type flag `HAS_TY_GENERATOR` to `HAS_TY_COROUTINE`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-26 17:35:23 +00:00
Havard Eidnes
391b472a37 rustc_llvm/build.rs: improve comment for NetBSD/i386 targets
...explaining why we need -latomic (gcc & g++ built for i486,
and LLVM insisting on use of 64-bit atomics).
2023-10-26 17:10:16 +00:00
Matthias Krüger
a461de7309
Rollup merge of #117221 - fmease:TypeFlags-HAS_TY_GENERATOR-to-COROUTINE, r=lqd
Rename type flag `HAS_TY_GENERATOR` to `HAS_TY_COROUTINE`

r? oli-obk
2023-10-26 17:45:46 +02:00
Matthias Krüger
70a4678a77
Rollup merge of #117214 - oli-obk:error_shenanigans, r=compiler-errors
Quietly fail if an error has already occurred

fixes #117195
2023-10-26 17:45:46 +02:00
Matthias Krüger
24bdc372fe
Rollup merge of #117207 - Zalathar:no-option, r=compiler-errors
The value of `-Cinstrument-coverage=` doesn't need to be `Option`

(Extracted from #117199, since this is a purely internal cleanup that can land independently.)

Not using this flag is identical to passing `-Cinstrument-coverage=off`, so there's no need to distinguish between `None` and `Some(Off)`.
2023-10-26 17:45:45 +02:00
Matthias Krüger
577026c65c
Rollup merge of #117194 - nnethercote:rustc_incremental, r=cjgillot
Minor improvements to `rustc_incremental`

Just some things I spotted while looking at this code.

r? `@cjgillot`
2023-10-26 17:45:44 +02:00
Matthias Krüger
7eb05480e9
Rollup merge of #117143 - estebank:issue-117080, r=wesleywiser
Avoid unbounded O(n^2) when parsing nested type args

When encountering code like `f::<f::<f::<f::<f::<f::<f::<f::<...` with unmatched closing angle brackets, add a linear check that avoids the exponential behavior of the parse recovery mechanism.

Fix https://github.com/rust-lang/rust/issues/117080, fix https://github.com/rust-lang/rust/issues/115414.
2023-10-26 17:45:44 +02:00
Matthias Krüger
b66c6e719f
Rollup merge of #117095 - klinvill:smir-fn-arg-count, r=oli-obk
Add way to differentiate argument locals from other locals in Stable MIR

This PR resolves rust-lang/project-stable-mir#47 which request a way to differentiate argument locals in a SMIR `Body` from other locals.

Specifically, this PR exposes the `arg_count` field from the MIR `Body`. However, I'm opening this as a draft PR because I think there are a few outstanding questions on how this information should be exposed and described. Namely:

- Is exposing `arg_count` the best way to surface this information to SMIR users? Would it be better to leave `arg_count` as a private field and add public methods (e.g. `fn arguments(&self) -> Iter<'_, LocalDecls>`) that may use the underlying `arg_count` info from the MIR body, but expose this information to users in a more convenient form? Or is it best to stick close to the current MIR convention?
- If the answer to the above point is to stick with the current MIR convention (`arg_count`), is it reasonable to also commit to sticking to the current MIR convention that the first local is always the return local, while the next `arg_count` locals are always the (in-order) argument locals?
- Should `Body` in SMIR only represent function bodies (as implied by the comment I added)? That seems to be the current case in MIR, but should this restriction always be the case for SMIR?

r? `@celinval`
r? `@oli-obk`
2023-10-26 17:45:43 +02:00
Matthias Krüger
17fb2f4b31
Rollup merge of #116905 - Fenex:refactor/compiler/resolve, r=petrochenkov
refactor(compiler/resolve): simplify some code

Removes unnecessary allocate and double-sorting the same vector, makes the code a little nicer.
2023-10-26 17:45:43 +02:00
bors
698db856de Auto merge of #117171 - fee1-dead-contrib:deny-explicit-effect-params, r=oli-obk
Deny providing explicit effect params

r? `@oli-obk`

cc https://github.com/rust-lang/rust/issues/110395
2023-10-26 14:50:23 +00:00
León Orell Valerian Liehr
b1b1458233
Replace type flag HAS_TY_GENERATOR with HAS_TY_COROUTINE 2023-10-26 15:18:50 +02:00
bors
6f65201659 Auto merge of #113262 - Nilstrieb:rawr-casting, r=lcnr
Never consider raw pointer casts to be trival

HIR typeck tries to figure out which casts are trivial by doing them as
coercions and seeing whether this works. Since HIR typeck is oblivious
of lifetimes, this doesn't work for pointer casts that only change the
lifetime of the pointee, which are, as borrowck will tell you, not
trivial.

This change makes it so that raw pointer casts are never considered
trivial.

This also incidentally fixes the "trivial cast" lint false positive on
the same code. Unfortunately, "trivial cast" lints are now never emitted
on raw pointer casts, even if they truly are trivial. This could be
fixed by also doing the lint in borrowck for raw pointers specifically.

fixes #113257
2023-10-26 12:54:19 +00:00
Oli Scherer
d572729d59 Quietly fail if an error has already occurred 2023-10-26 11:14:53 +00:00
clubby789
041f0313cf Properly restore snapshot when failing to recover parsing ternary 2023-10-26 11:11:36 +00:00
bors
9ab0749ce3 Auto merge of #112875 - compiler-errors:negative-coherence-rework, r=lcnr
Rework negative coherence to properly consider impls that only partly overlap

This PR implements a modified negative coherence that handles impls that only have partial overlap.

It does this by:
1. taking both impl trait refs, instantiating them with infer vars
2. equating both trait refs
3. taking the equated trait ref (which represents the two impls' intersection), and resolving any vars
4. plugging all remaining infer vars with placeholder types

these placeholder-plugged trait refs can then be used normally with the new trait solver, since we no longer have to worry about the issue with infer vars in param-envs.

We use the **new trait solver** to reason correctly about unnormalized trait refs (due to deferred projection equality), since this avoid having to normalize anything under param-envs with infer vars in them.

This PR then additionally:
* removes the `FnPtr` knowable hack by implementing proper negative `FnPtr` trait bounds for rigid types.

---

An example:

Consider these two partially overlapping impls:

```
impl<T, U> PartialEq<&U> for &T where T: PartialEq<U> {}
impl<F> PartialEq<F> for F where F: FnPtr {}
```

Under the old algorithm, we would take one of these impls and replace it with infer vars, then try unifying it with the other impl under identity substitutions. This is not possible in either direction, since it either sets `T = U`, or tries to equate `F = &?0`.

Under the new algorithm, we try to unify `?0: PartialEq<?0>` with `&?1: PartialEq<&?2>`. This gives us `?0 = &?1 = &?2` and thus `?1 = ?2`. The intersection of these two trait refs therefore looks like: `&?1: PartialEq<&?1>`. After plugging this with placeholders, we get a trait ref that looks like `&!0: PartialEq<&!0>`, with the first impl having substs `?T = ?U = !0` and the second having substs `?F = &!0`[^1].

Then we can take the param-env from the first impl, and try to prove the negated where clause of the second.

We know that `&!0: !FnPtr` never holds, since it's a rigid type that is also not a fn ptr, we successfully detect that these impls may never overlap.

[^1]: For the purposes of this example, I just ignored lifetimes, since it doesn't really matter.
2023-10-26 10:57:21 +00:00
Oli Scherer
d55487d7e9
Use two slice expressions to save on an offset repetition 2023-10-26 12:32:47 +02:00
David Tolnay
c1552dfddd
Fix symbols::tests::test_symbols
---- symbols::tests::test_symbols stdout ----
    thread 'symbols::tests::test_symbols' panicked at library/proc_macro/src/bridge/client.rs:311:17:
    procedural macro API is used outside of a procedural macro
2023-10-26 02:02:22 -07:00
David Tolnay
ac4fa3f245
Pre-intern a symbol for env!("CFG_RELEASE") 2023-10-26 02:02:22 -07:00
David Tolnay
5563a9ba3d
Improve span of env-related errors 2023-10-26 01:57:12 -07:00
David Tolnay
1078250f48
Continue generating other symbols if an expr is not supported 2023-10-26 01:57:12 -07:00
David Tolnay
65f0253334
Support environment variable for interned Symbol value 2023-10-26 01:57:11 -07:00
David Tolnay
726a43c1de
Move symbols macro map into a struct 2023-10-26 01:57:10 -07:00
David Tolnay
8dea49ad7b
Delete counter from symbols proc macro in favor of hashmap as source of truth 2023-10-26 01:57:09 -07:00
David Tolnay
95742ff23c
Add a Parse impl for symbol Value 2023-10-26 01:57:08 -07:00
David Tolnay
ba17934bc1
Represent symbol value as enum to prepare for supporting env vars 2023-10-26 01:57:07 -07:00
David Tolnay
173dcb211a
Touch up syn parsing in symbols macro 2023-10-26 01:57:06 -07:00
Deadbeef
47efc90366 Deny providing explicit effect params 2023-10-26 08:24:25 +00:00
Oli Scherer
14423080f1 Add hir::GeneratorKind::Gen 2023-10-26 07:10:25 +00:00
bors
104ac7bb6a Auto merge of #117148 - dtolnay:sinceversion, r=cjgillot
Store #[stable] attribute's `since` value in structured form

Followup to https://github.com/rust-lang/rust/pull/116773#pullrequestreview-1680913901.

Prior to this PR, if you wrote an improper `since` version in a `stable` attribute, such as `#[stable(feature = "foo", since = "wat.0")]`, rustc would emit a diagnostic saying **_'since' must be a Rust version number, such as "1.31.0"_** and then throw out the whole `stable` attribute as if it weren't there. This strategy had 2 problems, both fixed in this PR:

1. If there was also a `#[deprecated]` attribute on the same item, rustc would want to enforce that the stabilization version is older than the deprecation version. This involved reparsing the `stable` attribute's `since` version, with a diagnostic **_invalid stability version found_** if it failed to parse. Of course this diagnostic was unreachable because an invalid `since` version would have already caused the `stable` attribute to be thrown out. This PR deletes that unreachable diagnostic.

2. By throwing out the `stable` attribute when `since` is invalid, you'd end up with a second diagnostic saying **_function has missing stability attribute_** even though your function is not missing a stability attribute. This PR preserves the `stable` attribute even when `since` cannot be parsed, avoiding the misleading second diagnostic.

Followups I plan to try next:

- Do the same for the `since` value of `#[deprecated]`.

- See whether it makes sense to also preserve `stable` and/or `unstable` attributes when they contain an invalid `feature`. What redundant/misleading diagnostics can this eliminate? What problems arise from not having a usable feature name for some API, in the situation that we're already failing compilation, so not concerned about anything that happens in downstream code?
2023-10-26 06:59:19 +00:00
Oli Scherer
a61cf673cd Reserve gen keyword for gen {} blocks and gen fn in 2024 edition 2023-10-26 06:49:17 +00:00
bors
ccb160d343 Auto merge of #117115 - zetafunction:linking, r=bjorn3
Mark .rmeta files as /SAFESEH on x86 Windows.

Chrome links .rlibs with /WHOLEARCHIVE or -Wl,--whole-archive to prevent the linker from discarding static initializers. This works well, except on Windows x86, where lld complains:

  error: /safeseh: lib.rmeta is not compatible with SEH

The fix is simply to mark the .rmeta as SAFESEH aware. This is trivially true, since the metadata file does not contain any executable code.
2023-10-26 04:04:50 +00:00
Zalathar
9f5fc0283c The value of -Cinstrument-coverage= doesn't need to be Option
Not using this flag is identical to passing `-Cinstrument-coverage=off`, so
there's no need to distinguish between `None` and `Some(Off)`.
2023-10-26 13:33:14 +11:00
bors
6d674af861 Auto merge of #116818 - Nilstrieb:stop-submitting-bug-reports, r=wesleywiser
Stop telling people to submit bugs for internal feature ICEs

This keeps track of usage of internal features, and changes the message to instead tell them that using internal features is not supported.

I thought about several ways to do this but now used the explicit threading of an `Arc<AtomicBool>` through `Session`. This is not exactly incremental-safe, but this is fine, as this is set during macro expansion, which is pre-incremental, and also only affects the output of ICEs, at which point incremental correctness doesn't matter much anyways.

See [MCP 620.](https://github.com/rust-lang/compiler-team/issues/596)

![image](https://github.com/rust-lang/rust/assets/48135649/be661f05-b78a-40a9-b01d-81ad2dbdb690)
2023-10-26 02:08:07 +00:00
Kirby Linvill
4b23bd4734
Update Place and Operand to take slices
The latest locals() method in stable MIR returns slices instead of vecs.
This commit also includes fixes to the existing tests that previously
referenced the private locals field.
2023-10-26 00:21:28 +01:00
Kirby Linvill
fe4dfb814b
Rename internal_locals to inner_locals
The word internal has connotations about information that's not exposed.
It's more accurate to say that the remaining locals apply only to the
inner part of the function, so I'm renaming them to inner locals.
2023-10-26 00:18:42 +01:00
Maybe Waffle
e36224118f Stabilize [const_]pointer_byte_offsets 2023-10-25 22:35:12 +00:00
Nicholas Nethercote
e0c990e32c Reduce some function exposure. 2023-10-26 09:04:26 +11:00
Nicholas Nethercote
3cf2a7441f Tiny comment fixes. 2023-10-26 09:04:17 +11:00
Nicholas Nethercote
8da1b33153 Move a use to a more sensible spot.
I.e. in the source file where it's used.
2023-10-26 08:46:10 +11:00
Nicholas Nethercote
ca29c272e7 Reduce exposure of three functions used only within rustc_incremental. 2023-10-26 08:46:10 +11:00
Nicholas Nethercote
72e8690c04 Remove unused never_type feature. 2023-10-26 08:46:10 +11:00
Matthias Krüger
4e4e5619af
Rollup merge of #117175 - oli-obk:gen_fn_split, r=compiler-errors
Rename AsyncCoroutineKind to CoroutineSource

pulled out of https://github.com/rust-lang/rust/pull/116447

Also refactors the printing infra of `CoroutineSource` to be ready for easily extending it with a `Gen` variant for `gen` blocks
2023-10-25 23:37:11 +02:00
Matthias Krüger
2a027faf68
Rollup merge of #117009 - fmease:diag-disambig-sugg-crate, r=b-naber
On unresolved imports, suggest a disambiguated path if necessary to avoid collision with local items

Fixes #116970.
2023-10-25 23:37:10 +02:00
Matthias Krüger
f783ce95ec
Rollup merge of #117008 - compiler-errors:canonical, r=lcnr
Uplift `Canonical` to `rustc_type_ir`

I plan on moving the new trait solver's canonicalizer into either `rustc_type_ir` or a child crate. One dependency on this is lifting `Canonical<V>` to `rustc_type_ir` so we can actually name the canonicalized values.

I may also later lift `CanonicalVarInfo` into the new trait solver. I can't really tell what other changes need to be done, but I'm just putting this up sooner than later since I'm almost certain it'll need to be done regardless of other design choices.

There are a couple of warts introduced by this PR, since we no longer can define inherent `Canonical` impls in `rustc_middle` -- see the changes to:
* `compiler/rustc_trait_selection/src/traits/query/normalize.rs`
* `compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs`

r? lcnr
2023-10-25 23:37:10 +02:00
Matthias Krüger
d30fe8b4e2
Rollup merge of #116931 - weiznich:improve_diagnostic_on_unimplemented_warnings, r=compiler-errors
Improve the warning messages for the `#[diagnostic::on_unimplemented]`

This commit improves warnings emitted for malformed on unimplemented attributes by:

* Improving the span of the warnings
* Adding a label message to them
* Separating the messages for missing and unexpected options
* Adding a help message that says which options are supported

r? `@compiler-errors`

I'm happy to work on further improvements, so feel free to make suggestions.
2023-10-25 23:37:09 +02:00
Matthias Krüger
824dbb53fb
Rollup merge of #116553 - gurry:116464-assoc-type-invalid-suggestion, r=compiler-errors
Do not suggest 'Trait<Assoc=arg>' when in trait impl

Fixes #116464

We now skip the suggestion if we're in an impl of the trait.
2023-10-25 23:37:09 +02:00
Matthias Krüger
d3fb29a422
Rollup merge of #116401 - WaffleLapkin:vtablin''', r=oli-obk
Return multiple object-safety violation errors and code improvements to the object-safety check

See individual commits for more information. Split off of #114260, since it turned out that the main intent of that PR was wrong.

r? oli-obk
2023-10-25 23:37:09 +02:00
Milo
991bf752f1 make E0277 use short paths
add note

change wording

short_ty_string on t
2023-10-25 21:33:11 +00:00
Nilstrieb
9d42b1e268 Stop telling people to submit bugs for internal feature ICEs
This keeps track of usage of internal features, and changes the message
to instead tell them that using internal features is not supported.

See MCP 620.
2023-10-25 23:23:04 +02:00
Kirby Linvill
39b293fb5a
Add a public API to get all body locals
This is particularly helpful for the ui tests, but also could be helpful
for Stable MIR users who just want all the locals without needing to
concatenate responses
2023-10-25 22:18:58 +01:00
Kirby Linvill
372c533532
Make locals field private 2023-10-25 22:15:47 +01:00
Kirby Linvill
f4d80a5f09
Add public API to retrieve internal locals 2023-10-25 22:15:47 +01:00
Kirby Linvill
93d1b3e92a
Replace arg_count in public API with return/arg getters
This commit hides the arg_count field in Body and instead exposes more
stable and user-friendly methods to get the return and argument locals.
As a result, Body instances must now be constructed using the `new`
function.
2023-10-25 22:15:47 +01:00
Kirby Linvill
e4c41b07f0
Add arg_count field to Body in Stable MIR
This field allows SMIR consumers to identify which locals correspond to
argument locals. It simply exposes the arg_count field from the MIR
representation.
2023-10-25 22:15:47 +01:00
Nilstrieb
e8a4814d6d Use let chains instead of let else
This makes it more obvious that we're looking at a special case.
2023-10-25 23:15:29 +02:00
Nilstrieb
b6657a8ad4 Never consider raw pointer casts to be trival
HIR typeck tries to figure out which casts are trivial by doing them as
coercions and seeing whether this works. Since HIR typeck is oblivious
of lifetimes, this doesn't work for pointer casts that only change the
lifetime of the pointee, which are, as borrowck will tell you, not
trivial.

This change makes it so that raw pointer casts are never considered
trivial.

This also incidentally fixes the "trivial cast" lint false positive on
the same code. Unfortunately, "trivial cast" lints are now never emitted
on raw pointer casts, even if they truly are trivial. This could be
fixed by also doing the lint in borrowck for raw pointers specifically.
2023-10-25 23:15:18 +02:00
Maybe Waffle
ecdbefa487 Return multiple object-safety violation errors 2023-10-25 20:26:07 +00:00
Maybe Waffle
89582351cf Don't allow dead code 2023-10-25 20:23:43 +00:00
Maybe Waffle
6cb3376434 Add a comment explaining some weird is_vtable_safe_method behavior 2023-10-25 20:23:43 +00:00
bors
ab5c841a1f Auto merge of #117180 - matthiaskrgr:rollup-rxhl6ep, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #117111 (Remove support for alias `-Z instrument-coverage`)
 - #117141 (Require target features to match exactly during inlining)
 - #117152 (Fix unwrap suggestion for async fn)
 - #117154 (implement C ABI lowering for CSKY)
 - #117159 (Work around the fact that `check_mod_type_wf` may spuriously return `ErrorGuaranteed`)
 - #117163 (compiletest: Display compilation errors in mir-opt tests)
 - #117173 (Make `Iterator` a lang item)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-25 19:29:58 +00:00
Esteban Küber
2dec1bc685 Avoid unbounded O(n^2) when parsing nested type args
When encountering code like `f::<f::<f::<f::<f::<f::<f::<f::<...` with
unmatched closing angle brackets, add a linear check that avoids the
exponential behavior of the parse recovery mechanism.

Fix #117080.
2023-10-25 19:07:34 +00:00
Camille GILLOT
856161886a Directly check provenance from the AllocId. 2023-10-25 17:59:30 +00:00
Camille GILLOT
72f0e0e795 Rename has_provance and tweaks comments. 2023-10-25 17:59:30 +00:00
Camille GILLOT
d80eb3a498 Verify that the alloc_id is Memory. 2023-10-25 17:59:30 +00:00
Matthias Krüger
b0521fe88e
Rollup merge of #117173 - oli-obk:gen_fn_split2, r=compiler-errors
Make `Iterator` a lang item

r? `@compiler-errors`

pulled out of https://github.com/rust-lang/rust/pull/116447

We're doing this change on its own, because iterator was the one diagnostic item that was load bearing on us correctly emitting errors about `diagnostic_item` mis-uses. It was used in some diagnostics as an early abort, before the actual checks of the diagnostic, so effectively the compiler was *unconditionally* checking for the iterator diagnostic item, even if it didn't emit any diagnostics. Changing those uses to use the lang item, caused us not to invoke the `all_diagnostic_items` query anymore, which then caused us to miss some issues around diagnostic items until they were actually used.

The reason we keep the diagnostic item around is that clippy uses it a lot and having `Iterator` be a lang item and a diagnostic item at the same time doesn't cost us anything, but makes clippy's internal code simpler
2023-10-25 19:51:16 +02:00
Matthias Krüger
26a9e08f0c
Rollup merge of #117159 - oli-obk:error_shenanigans, r=estebank
Work around the fact that `check_mod_type_wf` may spuriously return `ErrorGuaranteed`

Even if that error is only emitted by `check_mod_item_types`.

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

A cleaner refactoring would merge/chain these queries in ways that ensure we only actually get an `ErrorGuaranteed` if there was an error emitted.
2023-10-25 19:51:15 +02:00
Matthias Krüger
74c2b987fb
Rollup merge of #117154 - Dirreke:csky-unknown-linux-gunabiv2, r=bjorn3
implement C ABI lowering for CSKY

fix https://github.com/rust-lang/compiler-builtins/issues/551

 ​Reference: [CSKY ABI Manual](https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1695027452256/T-HEAD_800_Series_ABI_Standards_Manual.pdf)
 ​
Reference: [Clang CSKY lowering code](4a074f32a6/clang/lib/CodeGen/Targets/CSKY.cpp (L76-L162))

r? `@bjorn3`
2023-10-25 19:51:15 +02:00
Matthias Krüger
585a122264
Rollup merge of #117152 - compiler-errors:no-ret-coercion, r=chenyukang
Fix unwrap suggestion for async fn

Use `body_fn_sig` to get the expected return type of the function instead of `ret_coercion` in `FnCtxt`. This avoids accessing the `ret_coercion` when it's already mutably borrowed (e.g. when checking `return` expressions).

Fixes #117144

r? `@chenyukang`
2023-10-25 19:51:14 +02:00
Matthias Krüger
a1ab16792b
Rollup merge of #117141 - tmiasko:inline-target-features, r=oli-obk
Require target features to match exactly during inlining

In general it is not correct to inline a callee with a target features
that are subset of the callee. Require target features to match exactly
during inlining.

The exact match could be potentially relaxed, but this would require
identifying specific feature that are allowed to differ, those that need
to match, and those that can be present in caller but not in callee.

This resolves MIR part of #116573. For other concerns with respect to
the previous implementation also see areInlineCompatible in LLVM.
2023-10-25 19:51:14 +02:00
Matthias Krüger
24254d2142
Rollup merge of #117111 - Zalathar:zinstrument, r=compiler-errors
Remove support for alias `-Z instrument-coverage`

This flag was stabilized in rustc 1.60.0 (2022-04-07) as `-C instrument-coverage`, but the old unstable flag was kept around (with a warning) as an alias to ease migration.

It should now be reasonable to remove the somewhat tricky code that implemented that alias.

Fixes #116980.
2023-10-25 19:51:13 +02:00
Oli Scherer
c601ade3ad Refactor away the need for some descr methods.
Instead we use `Display` impls and their `alternate` render scheme to
decide whether we want backticks or not.
2023-10-25 16:40:32 +00:00
Oli Scherer
92b41eeee6 Rename in preparation for moving the async printing out of CoroutineSource 2023-10-25 16:37:14 +00:00
Michael Goulet
8f3b4f94ef Add a IsIdentity extension trait for CanonicalUserType 2023-10-25 16:25:11 +00:00
Michael Goulet
024ca99de5 Uplift Canonical to rustc_type_ir 2023-10-25 16:25:09 +00:00
Oli Scherer
268ec72839 Make Iterator a lang item 2023-10-25 16:18:57 +00:00
Oli Scherer
af8a998b1e Rename AsyncCoroutineKind to CoroutineSource
similar to how we have `MatchSource`, it explains where the desugaring came from.
2023-10-25 16:14:05 +00:00
DaniPopes
6aead74ff2
Remove unnecessary CVarArgs name skipping logic 2023-10-25 17:44:17 +02:00
Matthias Krüger
105efbb4b2
Rollup merge of #117158 - matthewjasper:thir-unused-unsafe, r=oli-obk
Update THIR unused_unsafe lint

Updates THIR unsafeck behaviour to match the changes from #93678
2023-10-25 17:40:31 +02:00
Matthias Krüger
acc68e90bc
Rollup merge of #117136 - compiler-errors:defid-list, r=oli-obk
Intern `LocalDefId` list from `opaque_types_defined_by` query

r? oli-obk
2023-10-25 17:40:29 +02:00
Matthias Krüger
96074bec97
Rollup merge of #117133 - compiler-errors:coherence-constrained, r=oli-obk
Merge `impl_wf_inference` (`check_mod_impl_wf`) check into coherence checking

Problem here is that we call `collect_impl_trait_in_trait_types` when checking `check_mod_impl_wf` which is performed before coherence. Due to the `tcx.sess.track_errors`, since we end up reporting an error, we never actually proceed to coherence checking, where we would be emitting a more useful impl overlap error.

This change means that we may report more errors in some cases, but can at least proceed far enough to leave a useful message for overlapping traits with RPITITs in them.

Fixes #116982

r? types
2023-10-25 17:40:29 +02:00
DaniPopes
2c1dbed4aa
Print variadic argument pattern in HIR pretty printer 2023-10-25 17:36:04 +02:00
Havard Eidnes
6642b4b1e2 Add support for i586-unknown-netbsd as target.
This restricts instructions to those offered by Pentium,
to support e.g. AMD Geode.

There is already an entry for this target in the NetBSD
platform support page at

  src/doc/rustc/src/platform-support/netbsd.md

...so this should forestall its removal.

Additional fixes are needed for some vendored modules, this
is the changes in the rust compiler core itself.
2023-10-25 15:23:34 +00:00
Oli Scherer
57d6a6f588 Only call mir_const_qualif if absolutely necessary 2023-10-25 14:32:14 +00:00
bors
b66fe58f68 Auto merge of #117113 - celinval:smir-stable-ty, r=oli-obk
Remove fold code and add `Const::internal()` to StableMIR

We are not planning to support user generated constant in the foreseeable future, so we are cleaning up the fold logic and user created type for now. Users should use `Instance::resolve` in order to trigger monomorphization.

The Instance::resolve was however incomplete, since we weren't handling internalizing constants yet. Thus, I added that.

I decided to keep the `Const` fields private in case we decide to translate them lazily.
2023-10-25 13:19:54 +00:00
dirreke
32339f8e80 implement C ABI lowering for CSKY 2023-10-25 20:47:06 +08:00
Oli Scherer
beaf46f7e5 Work around the fact that check_mod_type_wf may spuriously return ErrorGuaranteed, even if that error is only emitted by check_modwitem_types 2023-10-25 12:04:54 +00:00
Matthew Jasper
dc3d428a8a Make THIR unused_unsafe lint consistent with MIR
Updates THIR behavior to match the changes from #93678
2023-10-25 10:10:13 +00:00
bors
c2ef35161f Auto merge of #117076 - oli-obk:privacy_visitor_types, r=petrochenkov
Refactor type visitor walking

r? `@petrochenkov`

pulling out the uncontroversial parts of https://github.com/rust-lang/rust/pull/113671
2023-10-25 08:54:09 +00:00
bors
c716f180e8 Auto merge of #116236 - dtolnay:builtinmacrocomment, r=cjgillot
Modernize rustc_builtin_macros generics helpers

- Rustfmt-compatible formatting for the code snippets in comments
- Eliminate an _"Extra scope required"_ obsoleted by NLL
2023-10-25 06:57:37 +00:00
Camille GILLOT
c4cc9ca060 Do not merge fn pointer casts. 2023-10-25 06:47:04 +00:00
Camille GILLOT
50559ceec4 Valtrees for primitive types are fine. 2023-10-25 06:46:48 +00:00
Camille GILLOT
f6aa3ee7e8 Complete comments. 2023-10-25 06:46:48 +00:00
Camille GILLOT
5e78b9cdb3 Disambiguate non-deterministic constants. 2023-10-25 06:46:48 +00:00
Camille GILLOT
f08dc9be17 Take an AllocId in intern_const_alloc_for_constprop. 2023-10-25 06:46:48 +00:00
Camille GILLOT
e3538d11f1 Do not require absence of metadata. 2023-10-25 06:46:48 +00:00
Camille GILLOT
59235a7907 Fortify transmute check. 2023-10-25 06:46:48 +00:00
Camille GILLOT
fbf0a0c5ff Explain why we check variant equality. 2023-10-25 06:46:48 +00:00
Camille GILLOT
ff6812cd20 Move provenance checks out of interning method. 2023-10-25 06:46:48 +00:00
Camille GILLOT
ebc87bf567 Directly intern values instead of copying them. 2023-10-25 06:46:48 +00:00
Camille GILLOT
8162dc2433 Do not intern GVN temps. 2023-10-25 06:46:48 +00:00
Camille GILLOT
dbf9ea30dd Transform large arrays into Repeat expressions when possible. 2023-10-25 06:46:48 +00:00
Camille GILLOT
80a5e8522d Extract simplify_aggregate. 2023-10-25 06:46:47 +00:00
Camille GILLOT
23d4857080 Do not compute actual aggregate type. 2023-10-25 06:46:47 +00:00
Camille GILLOT
f110f22060 Simplify repeat expressions. 2023-10-25 06:46:47 +00:00
Camille GILLOT
48d2157a89 Simplify aggregate projections. 2023-10-25 06:46:47 +00:00
Camille GILLOT
692e528647 Simplify projections in GVN. 2023-10-25 06:46:47 +00:00
Camille GILLOT
9389373127 Do not transmute immediates to non-immediates. 2023-10-25 06:46:47 +00:00
Camille GILLOT
db9bd9bd8c Do not intern too large aggregates. 2023-10-25 06:46:47 +00:00
Camille GILLOT
38c86b0798 Evaluate computed values to constants. 2023-10-25 06:46:47 +00:00
Camille GILLOT
afd631cc0c Do not visit rvalues twice. 2023-10-25 06:46:47 +00:00
Camille GILLOT
d28405972f Do not remove unused definitions inside GVN. 2023-10-25 06:46:45 +00:00
bors
98108dc26c Auto merge of #116993 - compiler-errors:clause-kind, r=jackh726
Uplift `ClauseKind` and `PredicateKind` into `rustc_type_ir`

Uplift `ClauseKind` and `PredicateKind` into `rustc_type_ir`.

Blocked on #116951

r? `@ghost`
2023-10-25 05:02:04 +00:00
Gurinder Singh
079b290439 Do not suggest 'Trait<Assoc=arg>' when in trait impl
because that would be illegal syntax
2023-10-25 09:11:16 +05:30
Michael Goulet
23341434bd Fix unwrap suggestion for async fn 2023-10-25 02:29:51 +00:00
bors
2e4e2a8f28 Auto merge of #117139 - compiler-errors:vid-lifetimes, r=BoxyUwU
Get rid of `'tcx` lifetime on `ConstVid`, `EffectVid`

These are simply newtyped numbers, so don't really have a reason (per se) to have a lifetime -- `TyVid` and `RegionVid` do not, for example.

The only consequence of this is that we need to use a new key type for `UnifyKey` that mentions `'tcx`. This is already done for `RegionVid`, with `RegionVidKey<'tcx>`, but this `UnifyKey` trait implementation may have been the original reason to give `ConstVid` a lifetime. See the changes to `compiler/rustc_middle/src/infer/unify_key.rs` specifically.

I consider the code cleaner this way, though -- we removed quite a few unnecessary `'tcx` in the process. This also makes it easier to uplift these two ids to `rustc_type_ir`, which I plan on doing in a follow-up PR.

r? `@BoxyUwU`
2023-10-25 02:01:04 +00:00
David Tolnay
1a9ea1f1a5
Expose a non-Symbol way to access current rustc version string 2023-10-24 18:11:20 -07:00
David Tolnay
51f7fbab92
CFG_RELEASE is mandatory, no need for option_env
The same file already contains another env!("CFG_RELEASE") on line 632,
so it's impossible for this crate to compile without CFG_RELEASE set.
2023-10-24 18:04:47 -07:00
Zalathar
65b0f6adb0 Remove support for alias -Z instrument-coverage
This flag was stabilized in rustc 1.60.0 as `-C instrument-coverage`, but the
old unstable flag was kept around as an alias to ease migration.
2023-10-25 11:37:46 +11:00
David Tolnay
6933a671d3
Handle structured stable attribute 'since' version in rustdoc 2023-10-24 17:34:59 -07:00
bors
848a387967 Auto merge of #116482 - matthewjasper:thir-unsafeck-inline-constants, r=b-naber
Fix inline const pattern unsafety checking in THIR

Fix THIR unsafety checking of inline constants.
- Steal THIR in THIR unsafety checking (if enabled) instead of MIR lowering.
- Represent inline constants in THIR patterns.
2023-10-25 00:03:57 +00:00
David Tolnay
ddcb1833ff
Keep track of #[stable] attribute even if version cannot be parsed 2023-10-24 15:50:23 -07:00
David Tolnay
f2ae7b55ae
Store 'since' attribute as parsed Version 2023-10-24 15:50:23 -07:00
Celina G. Val
17f6df9c63 Use IndexMap for handling stable Ty 2023-10-24 15:37:43 -07:00
Celina G. Val
3f60165d27 Remove fold code and add Const::internal()
We are not planning to support user generated constant in the
foreseeable future, so we are removing the Fold logic for now in
favor of the Instance::resolve logic.

The Instance::resolve was however incomplete, since we weren't handling
internalizing constants yet. Thus, I added that.

I decided to keep the Const fields private in case we decide to
translate them lazily.
2023-10-24 14:50:58 -07:00
bors
df871fbf05 Auto merge of #115796 - cjgillot:const-prop-rvalue, r=oli-obk
Generate aggregate constants in DataflowConstProp.
2023-10-24 21:47:53 +00:00
Tomasz Miąsko
011b260cc8 Require target features to match exactly during inlining
In general it is not correct to inline a callee with a target features
that are subset of the callee. Require target features to match exactly
during inlining.

The exact match could be potentially relaxed, but this would require
identifying specific feature that are allowed to differ, those that need
to match, and those that can be present in caller but not in callee.

This resolves MIR part of #116573. For other concerns with respect to
the previous implementation also see areInlineCompatible in LLVM.
2023-10-24 22:49:15 +02:00
Daniel Cheng
8fa800db61 Mark .rmeta files as /SAFESEH on x86 Windows.
Chrome links .rlibs with /WHOLEARCHIVE or -Wl,--whole-archive to prevent
the linker from discarding static initializers. This works well, except
on Windows x86, where lld complains:

  error: /safeseh: lib.rmeta is not compatible with SEH

The fix is simply to mark the .rmeta as SAFESEH aware. This is trivially
true, since the metadata file does not contain any executable code.
2023-10-24 13:42:28 -07:00
Michael Goulet
a986ab4d4d Get rid of 'tcx on ConstVid, EffectVid 2023-10-24 20:13:36 +00:00
bors
151256bd4b Auto merge of #117135 - matthiaskrgr:rollup-zdh18i6, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #116094 (Introduce `-C instrument-coverage=branch` to gate branch coverage)
 - #116396 (Migrate diagnostics in `rustc_hir_analysis/src/coherence/orphan.rs`)
 - #116714 (Derive `Ord`, `PartialOrd` and `Hash` for `SocketAddr*`)
 - #116792 (Avoid unnecessary renumbering during borrowck)
 - #116841 (Suggest unwrap/expect for let binding type mismatch)
 - #116943 (Add target features for LoongArch)
 - #117010 (Add method to convert internal to stable constructs)
 - #117127 (Remove `#[allow(incomplete_features)]` from RPITIT/AFIT tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-24 19:32:19 +00:00
Michael Goulet
18b7d9eb8c Intern LocalDefId list from opaque query 2023-10-24 18:01:01 +00:00
Matthias Krüger
f131a0a771
Rollup merge of #117010 - celinval:smir-internal, r=oli-obk
Add method to convert internal to stable constructs

This is an alternative implementation to https://github.com/rust-lang/rust/pull/116999. I believe we can still improve the logic a bit here, but I wanted to see which direction we should go first.

In this implementation, the API is simpler and we keep Tables somewhat private. The definition is still public though, since we have to expose the Stable trait. However, there's a cost of keeping another thread-local and using `Rc`, but I'm hoping it will be a small cost.

r? ``@oli-obk``
r? ``@spastorino``
2023-10-24 19:29:56 +02:00
Matthias Krüger
84f0befac5
Rollup merge of #116943 - heiher:target-features, r=wesleywiser
Add target features for LoongArch
2023-10-24 19:29:55 +02:00
Matthias Krüger
7a0a2d2d23
Rollup merge of #116841 - chenyukang:yukang-suggest-unwrap-expect, r=b-naber
Suggest unwrap/expect for let binding type mismatch

Found it when investigating https://github.com/rust-lang/rust/issues/116738
I'm not sure whether it's a good style to suggest `unwrap`, seems it's may helpful for newcomers.

#116738 needs another fix to improve it.
2023-10-24 19:29:55 +02:00
Matthias Krüger
61ff4dbedd
Rollup merge of #116792 - JonasAlaif:renumber-fix, r=b-naber
Avoid unnecessary renumbering during borrowck

Currently, after renumbering there are always unused `RegionVid`s if the return type contains any regions, this is due to `visit_ty` being called twice on the same `Ty`: once with `TyContext::ReturnTy` and once with `TyContext::LocalDecl { local: _0 }`. This PR skips renumbering the first time around.
2023-10-24 19:29:54 +02:00
Matthias Krüger
f3e18e4a60
Rollup merge of #116396 - obeis:hir-analysis-migrate-diagnostics-7, r=oli-obk
Migrate diagnostics in `rustc_hir_analysis/src/coherence/orphan.rs`

r? ``@compiler-errors``
2023-10-24 19:29:53 +02:00
Matthias Krüger
c07ff9c810
Rollup merge of #116094 - Swatinem:coverage-branch-gate, r=wesleywiser
Introduce `-C instrument-coverage=branch` to gate branch coverage

This was extracted from https://github.com/rust-lang/rust/pull/115061 and can land independently from other coverage related work.

The flag is unused for now, but is added in advance of adding branch coverage support.
It is an unstable, nightly only flag that needs to be used in combination with `-Zunstable-options`, like so: `-Zunstable-options -C instrument-coverage=branch`.

The goal is to develop branch coverage as an unstable opt-in feature first, before it matures and can be turned on by default.
2023-10-24 19:29:53 +02:00
bors
98b4a64a16 Auto merge of #117126 - matthiaskrgr:rollup-8huie8f, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #117081 (fix typos in comments)
 - #117091 (`OptWithInfcx` naming nits, trait bound simplifications)
 - #117092 (Add regression test for #117058)
 - #117093 (Update books)
 - #117105 (remove change-id assertion in bootstrap test)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-24 17:28:45 +00:00
Michael Goulet
a947654a96 Merge impl_wf_inference into coherence checking 2023-10-24 17:01:25 +00:00
yukang
f3d20be42b suggest unwrap/expect for let binding type mismatch 2023-10-25 00:32:58 +08:00
Camille GILLOT
2dbbec34ab Update documentation. 2023-10-24 15:30:17 +00:00
Camille GILLOT
ec28dc7aa7 Use PlaceMention for match scrutinees. 2023-10-24 15:30:17 +00:00
Matthias Krüger
cb651300ec
Rollup merge of #117091 - compiler-errors:debug, r=lcnr
`OptWithInfcx` naming nits, trait bound simplifications

* Use an associated type `Interner` on `InferCtxtLike` to remove a redundant interner parameter (`I: Interner, Infcx: InferCtxtLike<I>` -> `Infcx: InferCtxtLike`).
* Remove double-`Option` between `infcx: Option<Infcx>` and `fn universe_of_ty(&self, ty: ty::InferTy) -> Option<ty::UniverseIndex>`. We don't need the infcx to be optional if we can provide a "noop" (`NoInfcx`) implementation that just always returns `None` for universe index.
    * Also removes the `core::convert::Infallible` implementation which I found a bit weird...
* Some naming nits with params.
    * I found `InferCtxt` + `InfCtx` and `Infcx` to be a lot of different ways to spell "inference context", so I got rid of the `InfCtx` type parameter name in favor of `Infcx` which is a more standard name.
    * I found `OptWithInfcx` to be a bit redundant -> `WithInfcx`.

I'm making these changes because I intend to reuse the `InferCtxtLike` trait for uplifting the canonicalizer into a new trait -- conveniently, the information I need for uplifting the canonicalizer also is just the universe information of a type var, so it's super convenient 😸

r? `@BoxyUwU` or `@lcnr`
2023-10-24 17:09:00 +02:00
Matthias Krüger
0aade2f0de
Rollup merge of #117081 - GoodDaisy:master, r=wesleywiser
fix typos in comments
2023-10-24 17:08:59 +02:00
bors
07a4b7e2a9 Auto merge of #116773 - dtolnay:validatestable, r=compiler-errors
Validate `feature` and `since` values inside `#[stable(…)]`

Previously the string passed to `#[unstable(feature = "...")]` would be validated as an identifier, but not `#[stable(feature = "...")]`. In the standard library there were `stable` attributes containing the empty string, and kebab-case string, neither of which should be allowed.

Pre-existing validation of `unstable`:

```rust
// src/lib.rs

#![allow(internal_features)]
#![feature(staged_api)]
#![unstable(feature = "kebab-case", issue = "none")]

#[unstable(feature = "kebab-case", issue = "none")]
pub struct Struct;
```

```console
error[E0546]: 'feature' is not an identifier
 --> src/lib.rs:5:1
  |
5 | #![unstable(feature = "kebab-case", issue = "none")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

For an `unstable` attribute, the need for an identifier is obvious because the downstream code needs to write a `#![feature(...)]` attribute containing that identifier. `#![feature(kebab-case)]` is not valid syntax and `#![feature(kebab_case)]` would not work if that is not the name of the feature.

Having a valid identifier even in `stable` is less essential but still useful because it allows for informative diagnostic about the stabilization of a feature. Compare:

```rust
// src/lib.rs

#![allow(internal_features)]
#![feature(staged_api)]
#![stable(feature = "kebab-case", since = "1.0.0")]

#[stable(feature = "kebab-case", since = "1.0.0")]
pub struct Struct;
```

```rust
// src/main.rs

#![feature(kebab_case)]

use repro::Struct;

fn main() {}
```

```console
error[E0635]: unknown feature `kebab_case`
 --> src/main.rs:3:12
  |
3 | #![feature(kebab_case)]
  |            ^^^^^^^^^^
```

vs the situation if we correctly use `feature = "snake_case"` and `#![feature(snake_case)]`, as enforced by this PR:

```console
warning: the feature `snake_case` has been stable since 1.0.0 and no longer requires an attribute to enable
 --> src/main.rs:3:12
  |
3 | #![feature(snake_case)]
  |            ^^^^^^^^^^
  |
  = note: `#[warn(stable_features)]` on by default
```
2023-10-24 15:06:20 +00:00
bjorn3
484bc7fc88 Merge commit '93a5433f17ab5ed48cc88f1e69b0713b16183373' into sync_cg_clif-2023-10-24 2023-10-24 12:22:23 +00:00
Obei Sideg
68f5536667 Migrate diagnostics in rustc_hir_analysis/src/coherence/orphan.rs 2023-10-24 14:46:13 +03:00
bors
271dcc1d40 Auto merge of #116435 - compiler-errors:re-erased, r=lcnr
Handle `ReErased` in responses in new solver

There are legitimate cases in the compiler where we return `ReErased` for lifetimes that are uncaptured in the hidden type of an opaque. For example, in the test committed below, we ignore ignore the bivariant lifetimes of an opaque when it's inferred as the hidden type of another opaque. This may result in a `type_of(Opaque)` call returning a type that references `ReErased`. Let's handle this gracefully in the new solver.

Also added a `rustc_hidden_type_of_opaques` attr to print hidden types. This seems useful for opaques.

r? lcnr
2023-10-24 08:08:45 +00:00
Arpad Borsos
2b36547e9c
Introduce -C instrument-coverage=branch to gate branch coverage
This flag has to be used in combination with `-Zunstable-options`,
and is added in advance of adding branch coverage instrumentation.
2023-10-24 09:51:26 +02:00
Nicholas Nethercote
2e2e7806ab Augment stringify.rs test.
By adding tests (or placeholders, or comments) for missing AST variants.
2023-10-24 16:00:45 +11:00
Celina G. Val
ae86f59cc9 Add test and remove double ref 2023-10-23 21:36:43 -07:00
WANG Rui
cb618162b1 compiler: Add target features for LoongArch 2023-10-24 09:36:47 +08:00
bors
cd674d6179 Auto merge of #116300 - cjgillot:split-move, r=petrochenkov
Separate move path tracking between borrowck and drop elaboration.

The primary goal of this PR is to skip creating a `MovePathIndex` for path that do not need dropping in drop elaboration.

The 2 first commits are cleanups.

The next 2 commits displace `move` errors from move-path builder to borrowck. Move-path builder keeps the same logic, but does not carry error information any more.

The remaining commits allow to filter `MovePathIndex` creation according to types. This is used in drop elaboration, to avoid computing dataflow for paths that do not need dropping.
2023-10-24 00:25:32 +00:00
Michael Goulet
0626f2e7d0 nits 2023-10-23 23:35:27 +00:00
Michael Goulet
1d99ddbfe8 Consider regions 2023-10-23 23:35:27 +00:00
Michael Goulet
8597bf1df7 Make things work by using the new solver 2023-10-23 23:35:27 +00:00
Michael Goulet
7f3c2c7e2c Rework negative coherence 2023-10-23 23:35:27 +00:00
Michael Goulet
66d7cfd3b5 Remove FnPtr hack from trait_ref_is_knowable 2023-10-23 23:35:27 +00:00
Michael Goulet
b706b9d176 pre-cleanups 2023-10-23 23:35:27 +00:00
bors
f654229c27 Auto merge of #117103 - matthiaskrgr:rollup-96zuuom, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #107159 (rand use getrandom for freebsd (available since 12.x))
 - #116859 (Make `ty::print::Printer` take `&mut self` instead of `self`)
 - #117046 (return unfixed len if pat has reported error)
 - #117070 (rustdoc: wrap Type with Box instead of Generics)
 - #117074 (Remove smir from triage and add me to stablemir)
 - #117086 (Update .mailmap to promote my livename)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-23 22:18:45 +00:00
Celina G. Val
421631a3a1 Remove unsafe and Rc 2023-10-23 14:22:04 -07:00
Esteban Küber
c1bfd46c7b When expecting closure argument but finding block provide suggestion
Detect if there is a potential typo where the `{` meant to open the
closure body was written before the body.

```
error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<usize>`
  --> $DIR/ruby_style_closure_successful_parse.rs:3:31
   |
LL |       let p = Some(45).and_then({|x|
   |  ______________________--------_^
   | |                      |
   | |                      required by a bound introduced by this call
LL | |         1 + 1;
LL | |         Some(x * 2)
   | |         ----------- this tail expression is of type `Option<usize>`
LL | |     });
   | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<usize>`
   |
   = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<usize>`
note: required by a bound in `Option::<T>::and_then`
  --> $SRC_DIR/core/src/option.rs:LL:COL
help: you might have meant to open the closure body instead of placing a closure within a block
   |
LL -     let p = Some(45).and_then({|x|
LL +     let p = Some(45).and_then(|x| {
   |
```

Detect the potential typo where the closure header is missing.

```
error[E0277]: expected a `FnOnce<(&bool,)>` closure, found `bool`
  --> $DIR/block_instead_of_closure_in_arg.rs:3:23
   |
LL |        Some(true).filter({
   |  _________________------_^
   | |                 |
   | |                 required by a bound introduced by this call
LL | |/         if number % 2 == 0 {
LL | ||             number == 0
LL | ||         } else {
LL | ||             number != 0
LL | ||         }
   | ||_________- this tail expression is of type `bool`
LL | |      });
   | |______^ expected an `FnOnce<(&bool,)>` closure, found `bool`
   |
   = help: the trait `for<'a> FnOnce<(&'a bool,)>` is not implemented for `bool`
note: required by a bound in `Option::<T>::filter`
  --> $SRC_DIR/core/src/option.rs:LL:COL
help: you might have meant to create the closure instead of a block
   |
LL |     Some(true).filter(|_| {
   |                       +++
```

Partially address #27300.
2023-10-23 20:41:15 +00:00
Matthias Krüger
7e607e8e32
Rollup merge of #117046 - bvanjoi:fix-116186, r=oli-obk
return unfixed len if pat has reported error

- Fixes #116186
- Fixes #113021

This issue arises due to the creation of a fixed-length pattern, as a result of the mir body corruption. The corruption taints `tcx.eval_to_allocation_raw`, causing it to return `AlreadyReported`. Consequently, this prevents `len.try_eval_target_usize` from evaluating correctly and returns `None`. Lastly, it results in the return of `[usize; min_len]`.

To rectify this issue, my approach is that to return unfixed when encountering `ErrorHandled::Reported`. Additionally, in instances of `ErrorHandled::TooGeneric`, the previous logic has been reinstated.
2023-10-23 22:26:30 +02:00
Matthias Krüger
8af4a3f9cd
Rollup merge of #116859 - Nilstrieb:more-more-funny-pretty-printers, r=oli-obk
Make `ty::print::Printer` take `&mut self` instead of `self`

based on #116815

This simplifies the code by removing all the `self` assignments and
makes the flow of data clearer - always into the printer.
Especially in v0 mangling, which already used  `&mut self` in some
places, it gets a lot more uniform.
2023-10-23 22:26:29 +02:00
bors
41aa06ecf9 Auto merge of #116033 - bvanjoi:fix-116032, r=petrochenkov
report `unused_import` for empty reexports even it is pub

Fixes #116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing #115993.)
2023-10-23 20:24:09 +00:00
Michael Goulet
a387a3cf9d Let's see what those opaque types actually are 2023-10-23 16:18:35 -04:00
Michael Goulet
fd92bc6021 Handle ReErased in responses in new solver 2023-10-23 16:12:32 -04:00
David Tolnay
82ed3f5e8b
Validate since value in stable attribute 2023-10-23 13:04:35 -07:00
David Tolnay
9853f6132f
Validate #[stable(feature = "…")] identifier 2023-10-23 13:02:18 -07:00
Michael Goulet
269d5a322e Remove redundant type parameter 2023-10-23 16:02:05 -04:00
Michael Goulet
8951342911 Naming nits 2023-10-23 16:02:05 -04:00
Celina G. Val
f613b26cfb Add internal() method counterpart to stable()
Note: We do not expect to provide internalizing methods for all
StableMIR constructs. They exist only to help migrating efforts to allow
users to mix StableMIR and internal constructs.
2023-10-23 12:11:07 -07:00
Celina G. Val
66a554b045 Add method to convert internal to stable constructs 2023-10-23 12:01:39 -07:00
bors
1322f92634 Auto merge of #107009 - cjgillot:jump-threading, r=pnkfelix
Implement jump threading MIR opt

This pass is an attempt to generalize `ConstGoto` and `SeparateConstSwitch` passes into a more complete jump threading pass.

This pass is rather heavy, as it performs a truncated backwards DFS on MIR starting from each `SwitchInt` terminator. This backwards DFS remains very limited, as it only walks through `Goto` terminators.

It is build to support constants and discriminants, and a propagating through a very limited set of operations.

The pass successfully manages to disentangle the `Some(x?)` use case and the DFA use case. It still needs a few tests before being ready.
2023-10-23 18:05:44 +00:00
Oli Scherer
3121576d70 Factor signature type walking out of opaque_types_defined_by 2023-10-23 16:55:26 +00:00
bors
e2068cdb09 Auto merge of #117087 - matthiaskrgr:rollup-08kkjkz, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #116960 (Location-insensitive polonius: consider a loan escaping if an SCC has member constraints applied only)
 - #116978 (Rewrite gdb pretty-printer registration)
 - #117040 (coverage: Add UI tests for values accepted by `-Cinstrument-coverage`)
 - #117064 (Eliminate rustc_attrs::builtin::handle_errors in favor of emitting errors directly)
 - #117073 (Fix suggestion for renamed coroutines feature)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-23 16:04:48 +00:00
Matthias Krüger
f4dfd8d497
Rollup merge of #117073 - yotamofek:fix-coroutines-feature-rename-suggestion, r=lqd
Fix suggestion for renamed coroutines feature

This fixes a small typo from #116958
2023-10-23 16:23:54 +02:00
Matthias Krüger
6814eb1052
Rollup merge of #117064 - dtolnay:handleerrors, r=cjgillot
Eliminate rustc_attrs::builtin::handle_errors in favor of emitting errors directly

Suggested in https://github.com/rust-lang/rust/pull/116773#pullrequestreview-1691411257.

This `handle_errors` function is originally from https://github.com/rust-lang/rust/pull/34531, in which it was useful because it allowed error messages and error codes (`E0542`) for multiple occurrences of the same error to be centralized in one place. For example rather than repeating this diagnostic in 2 places:

```rust
span_err!(diagnostic, attr.span, E0542, "missing 'since'");
```

one could repeat this instead:

```rust
handle_errors(diagnostic, attr.span, AttrError::MissingSince);
```

ensuring that all "missing 'since'" errors always remained consistent in message and error code.

Over time as error messages and error codes got factored to fluent diagnostics (https://github.com/rust-lang/rust/pull/100836), this rationale no longer applies. The new code has the same benefit while being less verbose (+73, -128).

```rust
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
```

r? `@cjgillot`
2023-10-23 16:23:53 +02:00
Matthias Krüger
726709bca4
Rollup merge of #116960 - lqd:applied-member-constraints-scope, r=matthewjasper
Location-insensitive polonius: consider a loan escaping if an SCC has member constraints applied only

The location-insensitive analysis considered loans to escape if there were member constraints, which makes *some* sense for scopes and matches the scopes that NLL computes on all the tests.

However, polonius and NLLs differ on the fuzzed case #116657, where an SCC has member constraints but no applied ones (and is kinda surprising). The existing UI tests with member constraints impacting scopes all have some constraint applied.

This PR changes the location-insensitive analysis to consider a loan to escape if there are applied member constraints, and for extra paranoia/insurance via fuzzing and crater: actually checks the constraint's min choice is indeed a universal region as we expect. (This could be turned into a `debug_assert` and early return as a slight optimization after these periods of verification)

The 4 UI tests where member constraints are meaningful for computing scopes still pass obviously, and this also fixes #116657.

r? `@matthewjasper`
2023-10-23 16:23:52 +02:00
bohan
6de40abc89 return unfixed len if pat has reported error 2023-10-23 22:14:39 +08:00
bors
858a42bf46 Auto merge of #116837 - oli-obk:smir_run_macro, r=spastorino
Avoid having `rustc_smir` depend on `rustc_interface` or `rustc_driver`

This is done by moving all the logic into a macro that performs the entire "run" operation in one go.

This makes https://github.com/rust-lang/rust/pull/116806 obsolete

as a follow up we should make the macro usable without manually having to write

```rust
#[macro_use]
extern crate rustc_smir;
extern crate stable_mir;
extern crate rustc_driver;
extern crate rustc_interface;
use rustc_smir::rustc_internal;
```

in every crate that uses the macro.

r? `@spastorino`
2023-10-23 13:57:19 +00:00
GoodDaisy
0d780b108b fix typos in comments 2023-10-23 20:52:14 +08:00
bors
8501f1c7ba Auto merge of #116835 - oli-obk:evaluated_static_in_metadata2, r=RalfJung
Various const eval cleanups

This pulls out the pure refactorings from https://github.com/rust-lang/rust/pull/116564

r? `@RalfJung`
2023-10-23 12:01:17 +00:00
Oli Scherer
5c9a74d88b Merge associated types with the other alias types 2023-10-23 10:10:22 +00:00
bors
a56bd2b944 Auto merge of #116849 - oli-obk:error_shenanigans, r=cjgillot
Avoid a `track_errors` by bubbling up most errors from `check_well_formed`

I believe `track_errors` is mostly papering over issues that a sufficiently convoluted query graph can hit. I made this change, while the actual change I want to do is to stop bailing out early on errors, and instead use this new `ErrorGuaranteed` to invoke `check_well_formed` for individual items before doing all the `typeck` logic on them.

This works towards resolving https://github.com/rust-lang/rust/issues/97477 and various other ICEs, as well as allowing us to use parallel rustc more (which is currently rather limited/bottlenecked due to the very sequential nature in which we do `rustc_hir_analysis::check_crate`)

cc `@SparrowLii` `@Zoxc` for the new `try_par_for_each_in` function
2023-10-23 09:59:40 +00:00