Commit Graph

20005 Commits

Author SHA1 Message Date
Nicholas Nethercote d049be30cf Split `EarlyContextAndPasses::check_id` in two. 2022-12-07 19:29:31 +11:00
Nicholas Nethercote b08fd6e8ef Inline some hot lint pass functions.
These each have a single call site, due to being called from a
"combined" lint pass.
2022-12-07 19:29:31 +11:00
Nicholas Nethercote ec117c0ebd Rename `$passes` as `$pass` in several macros.
Because it makes more sense that way.
2022-12-07 19:29:31 +11:00
Nicholas Nethercote ac1e69c903 Add some useful comments. 2022-12-07 19:29:31 +11:00
Nicholas Nethercote 0c844730d3 Remove `$hir` argument from `late_lint_methods!`.
Because it's always `'tcx`.
2022-12-07 19:29:26 +11:00
yukang 5599f2ad09 fix #105226, Detect spurious ; before assoc fn body 2022-12-07 16:13:39 +08:00
Takayuki Maeda cb596e3015 consider `parent_count` for const param defaults 2022-12-07 12:55:30 +09:00
bors e491d2b24d Auto merge of #105291 - nnethercote:remove-LintPassObjects, r=cjgillot
Remove `{Early,Late}LintPassObjects`.

`EarlyContextAndPass` wraps a single early lint pass. We aggregate multiple passes into that single pass by using `EarlyLintPassObjects`.

This commit removes `EarlyLintPassObjects` by changing `EarlyContextAndPass` into `EarlyContextAndPasses`. I.e. it just removes a level of indirection. This makes the code simpler and slightly faster.

The commit does likewise for late lints.

r? `@cjgillot`
2022-12-07 03:52:19 +00:00
Michael Goulet b45b9489bb Compute generator sizes with -Zprint_type_sizes 2022-12-07 03:10:56 +00:00
Josh Stone e9dd59131b Add help for `#![feature(impl_trait_in_fn_trait_return)]`
This adds a new variant `ImplTraitContext::FeatureGated`, so we can
generalize the help for `return_position_impl_trait_in_trait` to also
work for `impl_trait_in_fn_trait_return`.
2022-12-06 17:53:50 -08:00
Dan Gohman 3a07aa9b5e Stop passing -export-dynamic to wasm-ld.
-export-dynamic was a temporary hack added in the early days of the Rust
wasm32 target when Rust didn't have a way to specify wasm exports in the
source code. This flag causes all global symbols, and some compiler-internal
symbols, to be exported, which is often more than needed.

Rust now does have a way to specify exports in the source code:
`#[export_name = "..."]`.

So as the original comment suggests, -export-dynamic can now be removed,
allowing users to have smaller binaries and better encapsulation in
their wasm32-unknown-unknown modules.

It's possible that this change will require existing wasm32-unknown-unknown
users will to add explicit `#[export_name = "..."]` directives to
exporrt the symbols that their programs depend on having exported.
2022-12-06 16:50:29 -08:00
Boxy 9f438bef0b normalize before matching on `ConstKind` 2022-12-06 22:53:13 +00:00
Matthias Krüger 280501d6bc
Rollup merge of #105382 - BoxyUwU:fixme_typo_sadface, r=lcnr
remove an excess `this`
2022-12-06 23:13:51 +01:00
Matthias Krüger e434f613fd
Rollup merge of #105298 - krasimirgg:llvm-16-dec-1, r=cuviper
llvm-wrapper: adapt for an LLVM API change

Adapts llvm-wrapper for 8c7c20f033.
No functional changes intended.

Found via our experimental rust + llvm @ HEAD bot: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/15404#0184d95d-5a68-4db6-ad32-51ddbc3ab543/202-571
2022-12-06 23:13:49 +01:00
Oli Scherer f89d6236aa Properly indent messages 2022-12-06 18:59:46 +00:00
Oli Scherer 99348a5330 Change CTFE backtraces to use `note` instead of `label` to preserve their order
labels are reordered within the file in which they are reported, which can mess up the stack trace
2022-12-06 18:59:46 +00:00
Oli Scherer 7782a2b70d Remove now-redundant file/line info from const backtraces 2022-12-06 18:59:46 +00:00
Oli Scherer 10b75cbbb0 Start emitting labels even if their pointed to file is not available locally 2022-12-06 18:59:46 +00:00
Oli Scherer 19d7dceed3 remove an unnecessary `?` 2022-12-06 18:59:45 +00:00
Oli Scherer 9eb9176b08 Simplify span fallback 2022-12-06 18:59:45 +00:00
Oli Scherer b9bf119c4f Simplify some nested conditions 2022-12-06 18:59:45 +00:00
bors b28d30e1e3 Auto merge of #105378 - matthiaskrgr:rollup-fjeorw5, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104898 (Put all cached values into a central struct instead of just the stable hash)
 - #105004 (Fix `emit_unused_delims_expr` ICE)
 - #105174 (Suggest removing struct field from destructive binding only in shorthand scenario)
 - #105250 (Replace usage of `ResumeTy` in async lowering with `Context`)
 - #105286 (Add -Z maximal-hir-to-mir-coverage flag)
 - #105320 (rustdoc: simplify CSS selectors on top-doc and non-exhaustive toggles)
 - #105349 (Point at args in associated const fn pointers)
 - #105362 (Cleanup macro-expanded code in `rustc_type_ir`)
 - #105370 (Remove outdated syntax from trait alias pretty printing)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-06 18:51:14 +00:00
Krasimir Georgiev 75aec4703d llvm-wrapper: adapt for and LLVM API change 2022-12-06 18:25:33 +00:00
Boxy 0070fae2dc typo :( 2022-12-06 16:40:57 +00:00
Matthias Krüger 97008a23fc
Rollup merge of #105370 - WaffleLapkin:pp, r=oli-obk
Remove outdated syntax from trait alias pretty printing

Given the following program:
```rust
#![feature(trait_alias)]
trait A = ?Sized;

fn main() {}
```
Old output of `rustc +nightly ./t.rs -Zunpretty=normal`:
```rust
#![feature(trait_alias)]
trait A for ? Sized ;

fn main() {}
```
New output of `rustc +a ./t.rs -Zunpretty=normal`:
```rust
#![feature(trait_alias)]
trait A = ?Sized;

fn main() {}
```

cc `@durka` (you've written the `FIXME` in #45047, see https://github.com/rust-lang/rust/pull/45047#discussion_r144960751)
2022-12-06 16:54:57 +01:00
Matthias Krüger 4f527a55de
Rollup merge of #105362 - WaffleLapkin:🙅, r=oli-obk
Cleanup macro-expanded code in `rustc_type_ir`

We could of course just leave this as-is, but every time I go-to-def to this file it's painful to see all this `(&A(ref __self_1_0),)` stuff.
2022-12-06 16:54:56 +01:00
Matthias Krüger 4f919e4628
Rollup merge of #105349 - compiler-errors:point-at-assoc-ct-fn-ptr-arg, r=cjgillot
Point at args in associated const fn pointers

Tiny follow-up to #105201, not so sure it's worth it but 🤷

The UI test example is a bit more compelling when it's `GlUniformScalar::FACTORY`

r? `@cjgillot`
2022-12-06 16:54:56 +01:00
Matthias Krüger c699b05306
Rollup merge of #105286 - willcrichton:maximal-hir-to-mir-coverage, r=cjgillot
Add -Z maximal-hir-to-mir-coverage flag

This PR adds a new unstable flag `-Z maximal-hir-to-mir-coverage` that changes the behavior of `maybe_lint_level_root_bounded`, pursuant to [a discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Mapping.20MIR.20to.20HIR). When enabled, this function will not search upwards for a lint root, but rather immediately return the provided HIR node ID. This change increases the granularity of the mapping between MIR locations and HIR nodes inside the `SourceScopeLocalData` data structures. This increase in granularity is useful for rustc consumers like [Flowistry](https://github.com/willcrichton/flowistry) that rely on getting source-mapping information about the MIR CFG that is as precise as possible.

A test `maximal_mir_to_hir_coverage.rs` has been added to verify that this flag does not break anything.

r? `@cjgillot`

cc `@gavinleroy`
2022-12-06 16:54:55 +01:00
Matthias Krüger 967085ecdf
Rollup merge of #105250 - Swatinem:async-rm-resumety, r=oli-obk
Replace usage of `ResumeTy` in async lowering with `Context`

Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces the raw pointer in `ResumeTy` and the `get_context` fn that pulls the correct lifetimes out of thin air.

fixes https://github.com/rust-lang/rust/issues/104828 and https://github.com/rust-lang/rust/pull/104321#issuecomment-1336363077

r? `@oli-obk`
2022-12-06 16:54:54 +01:00
Matthias Krüger 90d84ce3a2
Rollup merge of #105174 - chenyukang:yukang/fix-105028-unused, r=eholk
Suggest removing struct field from destructive binding only in shorthand scenario

Fixes #105028
2022-12-06 16:54:53 +01:00
Matthias Krüger b29a4f9bac
Rollup merge of #105004 - TaKO8Ki:fix-104897, r=wesleywiser
Fix `emit_unused_delims_expr` ICE

Fixes #104897

This is also related to #104433.
2022-12-06 16:54:53 +01:00
Matthias Krüger db416ea195
Rollup merge of #104898 - oli-obk:group_all_the_things, r=wesleywiser
Put all cached values into a central struct instead of just the stable hash

cc `@nnethercote`

this allows re-use of the type for Predicate without duplicating all the logic for the non-hash cached fields
2022-12-06 16:54:52 +01:00
bors e60fbaf4ce Auto merge of #105229 - saethlin:zst-writes-to-unions, r=oli-obk
Re-enable removal of ZST writes to unions

This was previously disabled because Miri was lazily allocating unsized locals. But we aren't doing that anymore since  https://github.com/rust-lang/rust/pull/98831, so we can have this optimization back.
2022-12-06 15:35:55 +00:00
Maybe Waffle 700c095306 `rustc_builtin_macros`: remove `ref` patterns
... and other pattern matching improvements
2022-12-06 14:45:58 +00:00
Maybe Waffle 244990a6e9 `rustc_attr` remove `ref` patterns
...and some if-let-elses too :P
2022-12-06 14:45:58 +00:00
Maybe Waffle c75817fb1b `rustc_borrowck`: remove `ref` patterns 2022-12-06 14:45:58 +00:00
Maybe Waffle 12ce0c2a89 Remove outdated syntax from trait alias pretty printing 2022-12-06 13:45:11 +00:00
Maybe Waffle e12d22239a Add debug asserts to hand-implemented `Ord`/`Eq` impls 2022-12-06 13:38:50 +00:00
Matthias Krüger a9ffe7c738
Rollup merge of #105342 - compiler-errors:note_cause_code-takes-predicate, r=fee1-dead
Make `note_obligation_cause_code`  take a `impl ToPredicate` for predicate

The only usecase that wasn't `impl ToPredicate` was noting overflow errors while revealing opaque types, which passed in an `Obligation<'tcx, Ty<'tcx>>`... Since this only happens in a `RevealAll` environment, which is after typeck (and probably primarily within `normalize_erasing_regions`) we're unlikely to display anything useful while noting this code, evidenced by the lack of UI test changes.
2022-12-06 13:27:45 +01:00
Matthias Krüger 07fd8089a4
Rollup merge of #105340 - estebank:ice-ice-baby, r=compiler-errors
Avoid ICE by accounting for missing type

Fix #105330
2022-12-06 13:27:45 +01:00
Matthias Krüger 762d2545f4
Rollup merge of #105339 - BoxyUwU:wf_ct_kind_expr, r=TaKO8Ki
support `ConstKind::Expr` in `is_const_evaluatable` and `WfPredicates::compute`

Fixes #105205

Currently we haven't implemented a way to evaluate `ConstKind::Expr(Expr::Binop(Add, 1, 2))` so I just left that with a `FIXME` and a `delay_span_bug` since I have no idea how to do that and it would make this a much larger (and more complicated) PR :P
2022-12-06 13:27:44 +01:00
Matthias Krüger e29a510ff0
Rollup merge of #105318 - compiler-errors:issue-105304, r=jackh726
Make `get_impl_future_output_ty` work with AFIT

Fixes #105304
2022-12-06 13:27:44 +01:00
Matthias Krüger 61189b6ae3
Rollup merge of #105310 - compiler-errors:issue-105288, r=eholk
Be more careful about unresolved exprs in suggestion

Fixes #105288
2022-12-06 13:27:43 +01:00
Matthias Krüger 0a07ffe4ad
Rollup merge of #105287 - compiler-errors:issue-105275, r=eholk
Synthesize substitutions for bad auto traits in dyn types

Auto traits are stored as just `DefId`s inside a `dyn Trait`'s existential predicates list. This is usually fine, since auto traits are forbidden to have generics -- but this becomes a problem for an ill-formed auto trait.

But since this will always result in an error, just synthesize some dummy (error) substitutions which are used at least to keep trait selection code happy about the number of substs in a trait ref.

Fixes #104808
2022-12-06 13:27:43 +01:00
Matthias Krüger ddb98e0aac
Rollup merge of #105254 - cjgillot:issue-105251, r=oli-obk
Recurse into nested impl-trait when computing variance.

Fixes https://github.com/rust-lang/rust/issues/105251
2022-12-06 13:27:42 +01:00
Matthias Krüger 48172ff64b
Rollup merge of #105098 - lyming2007:issue-103869-fix, r=eholk
propagate the error from parsing enum variant to the parser and emit out

While parsing enum variant, the error message always disappear
Because the error message that emit out is from main error of parser
The information of enum variant disappears while parsing enum variant with error
We only check the syntax of expecting token, i.e, in case https://github.com/rust-lang/rust/issues/103869
It will error it without telling the message that this error is from pasring enum variant.
Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err
Check the sub-error before emitting the main error of parser and attach it.
Fix https://github.com/rust-lang/rust/issues/103869
2022-12-06 13:27:41 +01:00
Matthias Krüger be3ad5d6b0
Rollup merge of #105005 - estebank:where-clause-lts, r=compiler-errors
On E0195 point at where clause lifetime bounds

Fix #104733
2022-12-06 13:27:41 +01:00
Maybe Waffle 78060cb6de Box `rustc_parse_format::Piece::NextArgument`
This makes both variants closer together in size (previously they were
different by 208 bytes -- 16 vs 224). This may make things worse, but
it's worth a try.
2022-12-06 12:02:56 +00:00
Maybe Waffle 07fbb1b372 Cleanup macro-expanded code in `rustc_type_ir` 2022-12-06 11:17:49 +00:00
Ralf Jung 9397ea1368 make retagging work even with 'unstable' places 2022-12-06 10:33:34 +01:00
bors 9db224fc90 Auto merge of #105175 - michaelwoerister:add-stable-ord-trait, r=nagisa
Add StableOrd trait as proposed in MCP 533.

The `StableOrd` trait can be used to mark types as having a stable sort order across compilation sessions. Collections that sort their items in a stable way can safely implement HashStable by hashing items in sort order.

See https://github.com/rust-lang/compiler-team/issues/533 for more information.
2022-12-06 09:21:49 +00:00
Arpad Borsos cf031a3355
Replace usage of `ResumeTy` in async lowering with `Context`
Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces
the raw pointer in `ResumeTy` and the `get_context` fn that pulls the
correct lifetimes out of thin air.
2022-12-06 10:16:23 +01:00
bors c5351ad4dc Auto merge of #105348 - JohnTitor:rollup-q9bichr, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #104967 (Fix UI issues with Rustdoc scrape-examples feature.)
 - #105207 (interpret: clobber return place when calling function)
 - #105246 (Fix --pass in compiletest)
 - #105256 (Add small comment explaining what `method-margins.goml` test is about)
 - #105289 (Fix dupe word typos)
 - #105309 (rustdoc: remove no-op mobile CSS `.sidebar { margin: 0; padding: 0 }`)
 - #105313 (Update books)
 - #105315 (Normalize inherent associated types after substitution)
 - #105324 (Point at GAT `where` clause when an obligation is unsatisfied)
 - #105338 (Tweak "the following other types implement trait")

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-06 06:34:13 +00:00
Esteban Küber e802165dfe On E0195 point at where clause lifetime bounds
Fix #104733
2022-12-05 20:43:41 -08:00
Esteban Küber eff76455fd Avoid ICE by accounting for missing type
Fix #105330
2022-12-05 20:30:17 -08:00
Michael Goulet 9c9c476774 Point at args in associated const fn pointers 2022-12-06 03:51:19 +00:00
Yuki Okushi 1310d9bd2b
Rollup merge of #105338 - estebank:other-impls, r=compiler-errors
Tweak "the following other types implement trait"

When *any* of the suggested impls is an exact match, *only* show the exact matches. This is particularly relevant for integer types.

r? `@compiler-errors`
2022-12-06 12:48:54 +09:00
Yuki Okushi e09c71e4c1
Rollup merge of #105324 - compiler-errors:gat-where-clause-binding-obl, r=jackh726
Point at GAT `where` clause when an obligation is unsatisfied

Slightly helps with #105306
2022-12-06 12:48:54 +09:00
Yuki Okushi 7ba37adbfd
Rollup merge of #105315 - fmease:norm-subst-iat, r=compiler-errors
Normalize inherent associated types after substitution

Fixes #105314.

r? ````@cjgillot```` (#105224)
````@rustbot```` label F-inherent_associated_types
2022-12-06 12:48:53 +09:00
Yuki Okushi fa7d3ec630
Rollup merge of #105289 - Rageking8:fix-dupe-word-typos, r=cjgillot
Fix dupe word typos
2022-12-06 12:48:52 +09:00
Yuki Okushi aa0831092b
Rollup merge of #105207 - RalfJung:interpret-clobber-return, r=oli-obk
interpret: clobber return place when calling function

Makes sure the callee cannot observe the previous contents of the return place, and the caller cannot read any of the old return place contents even if the function unwinds.

I don't think we can test for this though, that would require some strange hand-written MIR.

r? `````@oli-obk`````
2022-12-06 12:48:50 +09:00
bors ed61c139c2 Auto merge of #105220 - oli-obk:feeding, r=cjgillot
feed resolver_for_lowering instead of storing it in a field

r? `@cjgillot`

opening this as

* a discussion for `no_hash` + `feedable` queries. I think we'll want those, but I don't quite understand why they are rejected beyond a double check of the stable hashes for situations where the query is fed but also read from incremental caches.
* and a discussion on removing all untracked fields from TyCtxt and setting it up so that they are fed queries instead
2022-12-06 03:47:41 +00:00
Michael Goulet 6dc2aa2675 Add GenericParamDef::to_error and InternalSubsts::extend_with_error 2022-12-06 01:53:01 +00:00
Gary Guo c559cf62c2 Simplify attribute handling in rustc_ast_lowering
Given that attributes is stored in a separate BTreeMap, it's not necessary
to pass it in when constructing `hir::Expr`. We can just construct
`hir::Expr` and then call `self.lower_attrs` later if it needs attributes.

As most desugaring code don't use attributes, this allows some code cleanup.
2022-12-06 01:05:17 +00:00
bors 226202d902 Auto merge of #105119 - JakobDegen:inline-experiments, r=cjgillot
Disable top down MIR inlining

The current MIR inliner has exponential behavior in some cases: <https://godbolt.org/z/7jnWah4fE>. The cause of this is top-down inlining, where we repeatedly do inlining like `call_a() => { call_b(); call_b(); }`. Each decision on its own seems to make sense, but the result is exponential.

Disabling top-down inlining fundamentally prevents this. Each call site in the original, unoptimized source code is now considered for inlining exactly one time, which means that the total growth in MIR size is limited to number of call sites * inlining threshold.

Top down inlining may be worth re-introducing at some point, but it needs to be accompanied with a principled way to prevent this kind of behavior.
2022-12-06 00:53:01 +00:00
Michael Goulet d2a80c1571 Avoid noting cause code (which is usually misc, b/c codegen) for opaque type reveal overflow 2022-12-06 00:19:55 +00:00
Michael Goulet e940f845be drive-by: Default param for ToPredicate 2022-12-06 00:19:55 +00:00
Boxy c9bab74fb2 support `Expr` in `is_const_evaluatable` and `compute` 2022-12-05 23:17:55 +00:00
Peter Collingbourne f44a0153bc Support Option and similar enums as type of static variable with linkage attribute.
Compiler MCP:
https://github.com/rust-lang/compiler-team/issues/565
2022-12-05 15:05:43 -08:00
Peter Collingbourne 5873ebeef3 Move linkage type check to HIR analysis and fix semantics issues.
This ensures that the error is printed even for unused variables,
as well as unifying the handling between the LLVM and GCC backends.

This also fixes unusual behavior around exported Rust-defined variables
with linkage attributes. With the previous behavior, it appears to be
impossible to define such a variable such that it can actually be imported
and used by another crate. This is because on the importing side, the
variable is required to be a pointer, but on the exporting side, the
type checker rejects static variables of pointer type because they do
not implement `Sync`. Even if it were possible to import such a type, it
appears that code generation on the importing side would add an unexpected
additional level of pointer indirection, which would break type safety.

This highlighted that the semantics of linkage on Rust-defined variables
is different to linkage on foreign items. As such, we now model the
difference with two different codegen attributes: linkage for Rust-defined
variables, and import_linkage for foreign items.

This change gives semantics to the test
src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs which was
previously expected to fail to compile. Therefore, convert it into a
test that is expected to successfully compile.

The update to the GCC backend is speculative and untested.
2022-12-05 15:05:43 -08:00
Esteban Küber e1649c442f Tweak "the following other types implement trait"
When *any* of the suggested impls is an exact match, *only* show the
exact matches. This is particularly relevant for integer types.

fix fmt
2022-12-05 14:59:30 -08:00
Will Crichton d595884302 Move -Z maximal-hir-to-mir-coverage implementation to new `maybe_new_source_scope` method 2022-12-05 12:47:44 -08:00
Matthias Krüger 4ebbb20dad
Rollup merge of #105230 - cjgillot:issue-104312, r=petrochenkov
Skip recording resolution for duplicated generic params.

Turns out the fix was simpler than I thought.

Fixes https://github.com/rust-lang/rust/issues/104312
2022-12-05 20:43:44 +01:00
Matthias Krüger 66a4cb5368
Rollup merge of #105223 - lukas-code:(ExprWithBlock), r=petrochenkov
suggest parenthesis around ExprWithBlock BinOp ExprWithBlock

fix https://github.com/rust-lang/rust/issues/105179
fix https://github.com/rust-lang/rust/issues/102171
2022-12-05 20:43:44 +01:00
Matthias Krüger 78cf0b916a
Rollup merge of #105180 - nbdd0121:async_track_caller, r=compiler-errors
Use proper HirId for async track_caller attribute check

Fix #105134
2022-12-05 20:43:42 +01:00
Michael Goulet a1fbc14372 Point at GAT where clause when unsatisfied 2022-12-05 19:11:31 +00:00
Michael Goulet da929fa63c Make get_impl_future_output_ty work with AFIT 2022-12-05 17:34:42 +00:00
León Orell Valerian Liehr d5cb5fb185
normalize inherent associated types after substitution 2022-12-05 18:02:47 +01:00
Michael Goulet f4c76b193d Be more careful about unresolved exprs in suggestion 2022-12-05 08:15:30 -08:00
Oli Scherer f693b7848e feed resolver_for_lowering instead of storing it in a field 2022-12-05 10:58:55 +00:00
Oli Scherer 125b729ddd Allow arbitrary keys in feeding API 2022-12-05 10:58:55 +00:00
Michael Woerister 56aacb245c StableOrd: Address review comments. 2022-12-05 10:45:31 +01:00
Nicholas Nethercote 8980d9a76d Remove `{Early,Late}LintPassObjects`.
`EarlyContextAndPass` wraps a single early lint pass. We aggregate
multiple passes into that single pass by using `EarlyLintPassObjects`.

This commit removes `EarlyLintPassObjects` by changing
`EarlyContextAndPass` into `EarlyContextAndPasses`. I.e. it just removes
a level of indirection. This makes the code simpler and slightly faster.

The commit does likewise for late lints.
2022-12-05 19:50:10 +11:00
Rageking8 58110572fb fix dupe word typos 2022-12-05 16:42:36 +08:00
Will Crichton 3bf7d88ef1 Add -Z maximal-hir-to-mir-coverage flag 2022-12-04 23:58:20 -08:00
bors e72ea1dc37 Auto merge of #104824 - klensy:bump-some, r=Mark-Simulacrum
deps: update cpufeatures, swap difference to dissimilar

Updating cpufeatures v0.2.1 -> v0.2.5: https://github.com/RustCrypto/utils/blob/master/cpufeatures/CHANGELOG.md#025-2022-09-04, was yanked bc of miscompile (https://github.com/RustCrypto/utils/pull/800, https://github.com/rust-lang/rust/issues/101346)

Removing difference v2.0.0
     Adding dissimilar v1.0.4
   Updating expect-test v1.0.1 -> v1.4.0

difference unmaintened https://rustsec.org/advisories/RUSTSEC-2020-0095.html, so replaced with https://github.com/dtolnay/dissimilar (as dependency of `expect-test`)
2022-12-05 05:54:33 +00:00
Michael Goulet 19175e9b75 Synthesize generics for bad auto traits in dyn types 2022-12-05 05:45:12 +00:00
Nicholas Nethercote 7e0c6dba0d Remove `LitKind::synthesize_token_lit`.
It has a single call site in the HIR pretty printer, where the resulting
token lit is immediately converted to a string.

This commit replaces `LitKind::synthesize_token_lit` with a `Display`
impl for `LitKind`, which can be used by the HIR pretty printer.
2022-12-05 16:33:24 +11:00
Nicholas Nethercote 568e647047 Remove three uses of `LitKind::synthesize_token_lit`. 2022-12-05 16:33:20 +11:00
Nicholas Nethercote d887615b4c Parameterise `Parser::{recover_unclosed_char,handle_missing_lit}`.
These two methods both produce a `MetaItemLit`, and then some of the
call sites convert the `MetaItemLit` to a `token::Lit` with
`as_token_lit`.

This commit parameterises these two methods with a `mk_lit_char`
closure, which can be used to produce either `MetaItemLit` or
`token::Lit` directly as necessary.
2022-12-05 15:04:33 +11:00
Nicholas Nethercote 4ae956f600 Remove `ExtCtxt::expr_lit`. 2022-12-05 14:20:38 +11:00
Michael Goulet 64ad337a3b Don't call diagnostic_hir_wf_check query if we have infer variables 2022-12-05 03:18:57 +00:00
Gary Guo 34c377335b Add fixme note 2022-12-05 03:18:26 +00:00
bors b9341bfdb1 Auto merge of #104920 - compiler-errors:avoid-infcx-build, r=jackh726
Avoid some `InferCtxt::build` calls

Either because we're inside of an `InferCtxt` already, or because we're not in a place where we'd ever see inference vars.

r? types
2022-12-05 02:51:06 +00:00
Michael Goulet 1c81540206 Unconditional check FRU expression, even if there are errors present 2022-12-05 00:42:40 +00:00
Nicholas Nethercote 7d30472180 Remove `mk_name_value_item{,_str}`.
There are better ways to create the meta items.
- In the rustdoc tests, the commit adds `dummy_meta_item_name_value`,
  which matches the existing `dummy_meta_item_word` function and
  `dummy_meta_item_list` macro.
- In `types.rs` the commit clones the existing meta item and then
  modifies the clone.
2022-12-05 11:24:48 +11:00
bors d1449560e3 Auto merge of #105094 - Swatinem:generator-not-future, r=compiler-errors
Make sure async constructs do not `impl Generator`

Async lowering turns async functions and blocks into generators internally.
Though these special kinds of generators should not `impl Generator` themselves.
The other way around, normal generators should not `impl Future`.

This was discovered in https://github.com/rust-lang/rust/pull/105082#issuecomment-1332210907 and is a regression from https://github.com/rust-lang/rust/pull/104321.

r? `@compiler-errors`
2022-12-04 22:46:11 +00:00
Michael Goulet a68eae2f70 Avoid InferCtxt::build in generic_arg_mismatch_err 2022-12-04 20:54:30 +00:00
Michael Goulet e3072a24ad Avoid InferCtxt::build in report_similar_impl_candidates 2022-12-04 20:54:30 +00:00
bors 53e4b9dd74 Auto merge of #104535 - mikebenfield:discr-fix, r=pnkfelix
rustc_codegen_ssa: Fix for codegen_get_discr

When doing the optimized implementation of getting the discriminant, the arithmetic needs to be done in the tag type so wrapping behavior works correctly.

Fixes #104519
2022-12-04 20:05:32 +00:00
Michael Goulet d442c015d6 Don't ICE in ExprUseVisitor on FRU for non-existent struct 2022-12-04 18:53:50 +00:00
Michael Goulet 26b24cd755 drive-by: move field_index to typeck results 2022-12-04 17:59:21 +00:00
bors 0f0d5d716a Auto merge of #105261 - matthiaskrgr:rollup-9ghhc9c, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #101975 (Suggest to use . instead of :: when accessing a method of an object)
 - #105141 (Fix ICE on invalid variable declarations in macro calls)
 - #105224 (Properly substitute inherent associated types.)
 - #105236 (Add regression test for #47814)
 - #105247 (Use parent function WfCheckingContext to check RPITIT.)
 - #105253 (Update a couple of rustbuild deps)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-04 16:32:21 +00:00
Matthias Krüger d055d6ad5e
Rollup merge of #105247 - cjgillot:issue-102682, r=compiler-errors
Use parent function WfCheckingContext to check RPITIT.

WF-check for RPITIT was done in the opaque type's param-env, so it could not benefit from assumed wf types from the function's parameters.

cc `@compiler-errors` since you chose that param-env in fd2766e7fd

Fixes https://github.com/rust-lang/rust/issues/102682
Fixes https://github.com/rust-lang/rust/issues/104908
Fixes https://github.com/rust-lang/rust/issues/102552
Fixes https://github.com/rust-lang/rust/issues/104529
2022-12-04 16:25:34 +01:00
Matthias Krüger f2e223c576
Rollup merge of #105224 - cjgillot:issue-104240, r=compiler-errors
Properly substitute inherent associated types.

Fixes https://github.com/rust-lang/rust/issues/104240
2022-12-04 16:25:33 +01:00
Matthias Krüger b1816833bd
Rollup merge of #105141 - ohno418:fix-ice-on-invalid-var-decl-in-macro-call, r=compiler-errors
Fix ICE on invalid variable declarations in macro calls

This fixes ICE that happens with invalid variable declarations in macro calls like:

```rust
macro_rules! m { ($s:stmt) => {} }
m! { var x }
m! { auto x }
m! { mut x }
```

Found this is because of not collecting tokens on recovery, so I changed to force collect them.

Fixes https://github.com/rust-lang/rust/issues/103529.
2022-12-04 16:25:32 +01:00
Matthias Krüger 7dbd1603b8
Rollup merge of #101975 - chenyukang:fix-101749, r=compiler-errors
Suggest to use . instead of :: when accessing a method of an object

Fixes #101749
Fixes #101542
2022-12-04 16:25:32 +01:00
Camille GILLOT e2d41f4c97 Make nested RPITIT inherit the parent opaque's generics. 2022-12-04 14:38:20 +00:00
bors 19c250aa12 Auto merge of #103293 - est31:untwist_and_drop_order, r=nagisa
Remove drop order twist of && and || and make them associative

Previously a short circuiting binop chain (chain of && or ||s) would drop the temporaries created by the first element after all the other elements, and otherwise follow evaluation order. So `f(1).g() && f(2).g() && f(3).g() && f(4).g()` would drop the temporaries in the order `2,3,4,1`. This made `&&` and `||` non-associative regarding drop order. In other words, adding ()'s to the expression would change drop order: `f(1).g() && (f(2).g() && f(3).g()) && f(4).g()` for example would drop in the order `3,2,4,1`.

As, except for the bool result, there is no data returned by the sub-expressions of the short circuiting binops, we can safely discard of any temporaries created by the sub-expr. Previously, code was already putting the rhs's into terminating scopes, but missed it for the lhs's.

This commit addresses this "twist". We now also put the lhs into a terminating scope. The drop order of the above expressions becomes `1,2,3,4`.

There might be code relying on the current order, and therefore I'd recommend doing a crater run to gauge the impact. I'd argue that such code is already quite wonky as it is one `foo() &&` addition away from breaking. ~~For the impact, I don't expect any *build* failures, as the compiler gets strictly more tolerant: shortening the lifetime of temporaries only expands the list of programs the compiler accepts as valid. There might be *runtime* failures caused by this change however.~~ Edit: both build and runtime failures are possible, e.g. see the example provided by dtolnay [below](https://github.com/rust-lang/rust/pull/103293#issuecomment-1285341113). Edit2: the crater run has finished and [results](https://github.com/rust-lang/rust/pull/103293#issuecomment-1292275203) are that there is only one build failure which is easy to fix with a +/- 1 line diff.

I've included a testcase that now compiles thanks to this patch.

The breakage is also limited to drop order relative to conditionals in the && chain: that is, in code like this:

```Rust
let hello = foo().hi() && bar().world();
println!("hi");
```

we already drop the temporaries of `foo().hi()` before we reach "hi".

I'd ideally have this PR merged before let chains are stabilized. If this PR is taking too long, I'd love to have a more restricted version of this change limited to `&&`'s in let chains: the `&&`'s of such chains are quite special anyways as they accept `let` bindings, in there the `&&` is therefore more a part of the "if let chain" construct than a construct of its own.

Fixes #103107

Status: waiting on [this accepted FCP](https://github.com/rust-lang/rust/pull/103293#issuecomment-1293411354) finishing.
2022-12-04 14:03:12 +00:00
Camille GILLOT 44948d1fdc Recurse into nested impl-trait when computing variance. 2022-12-04 13:54:56 +00:00
bjorn3 262ace5284 Avoid from_immediate_or_packed_pair in ThreadLocalRef codegen 2022-12-04 12:53:46 +00:00
Matthias Krüger 3c4a430900
Rollup merge of #105142 - nbdd0121:inline_const, r=petrochenkov
Make inline const block `ExprWithBlock`

Fix https://github.com/rust-lang/rust/pull/104087#issuecomment-1324190817

`@rustbot` label: +T-lang +F-inline_const
2022-12-04 11:38:51 +01:00
Matthias Krüger 7fe9597775
Rollup merge of #105123 - BlackHoleFox:fixing-the-macos-deployment, r=oli-obk
Fix passing MACOSX_DEPLOYMENT_TARGET to the linker

I messed up in https://github.com/rust-lang/rust/pull/103929 when merging the two base files together and as a result, started ignoring `MACOSX_DEPLOYMENT_TARGET` at the linker level. This ended up being the cause of nighty builds not running on older macOS versions.

My original hope with the previous PR was that CI would have caught something like that but there were only tests checking the compiler target definitions in codegen tests. Because of how badly this sucks to break, I put together a new test via `run-make` that actually confirms the deployment target set makes it to the linker instead of just LLVM.

Closes https://github.com/rust-lang/rust/issues/104570 (for real this time)
2022-12-04 11:38:51 +01:00
Matthias Krüger 785b47d92a
Rollup merge of #104856 - luqmana:associated-const-bad-suggestion, r=compiler-errors
Don't suggest associated function call for associated const.

Fixes #104801.

r? `@compiler-errors`
2022-12-04 11:38:50 +01:00
Camille GILLOT 12473d3f36 Use parent function WfCheckingContext to check RPITIT. 2022-12-04 10:33:07 +00:00
bors fd02567705 Auto merge of #105121 - oli-obk:simpler-cheaper-dump_mir, r=nnethercote
Cheaper `dump_mir` take two

alternative to #105083

r? `@nnethercote`
2022-12-04 05:47:10 +00:00
est31 a59a2d3f6a Also avoid creating a terminating scope in mixed chains
This avoids creation of a terminating scope in
chains that contain both && and ||, because
also there we know that a terminating scope is
not neccessary: all the chain members are already
in such terminating scopes.

Also add a mixed && / || test.
2022-12-04 04:09:40 +01:00
est31 a2076dc0a6 Improve comments 2022-12-04 04:09:40 +01:00
Ben Kimock 74a270ac93 Re-enable removal of ZST writes to unions 2022-12-03 19:17:45 -05:00
Lukas Markeffsky c808d0b289 more comments 2022-12-03 23:54:06 +01:00
Camille GILLOT b1514108e2 Skip recording resolution for duplicated generic params. 2022-12-03 22:40:30 +00:00
est31 8cf521d80e Remove drop order twist of && and || and make them associative
Previously a short circuiting && chain would drop the
first element after all the other elements, and otherwise
follow evaluation order, so code like:

f(1).g() && f(2).g() && f(3).g() && f(4).g()

would drop the temporaries in the order 2,3,4,1. This made
&& and || non-associative regarding drop order, so
adding ()'s to the expression would change drop order:

f(1).g() && (f(2).g() && f(3).g()) && f(4).g()

for example would drop in the order 3,2,4,1.

As, except for the bool result, there is no data returned
by the sub-expressions of the short circuiting binops,
we can safely discard of any temporaries created by the
sub-expr. Previously, code was already putting the rhs's
into terminating scopes, but missed it for the lhs's.

This commit addresses this "twist". In the expression,
we now also put the lhs into a terminating scope.
The drop order for the above expressions is 1,2,3,4
now.
2022-12-03 23:32:08 +01:00
bors b8a52e3a4b Auto merge of #105218 - matthiaskrgr:rollup-8d3k08n, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104199 (Keep track of the start of the argument block of a closure)
 - #105050 (Remove useless borrows and derefs)
 - #105153 (Create a hacky fail-fast mode that stops tests at the first failure)
 - #105164 (Restore `use` suggestion for `dyn` method call requiring `Sized`)
 - #105193 (Disable coverage instrumentation for naked functions)
 - #105200 (Remove useless filter in unused extern crate check.)
 - #105201 (Do not call fn_sig on non-functions.)
 - #105208 (Add AmbiguityError for inconsistent resolution for an import)
 - #105214 (update Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-03 21:25:45 +00:00
Camille GILLOT 8a7ae23f75 Properly substitute inherent associated types. 2022-12-03 19:08:00 +00:00
Lukas Markeffsky 35c00a9731 suggest parenthesis around ExprWithBlock BinOp ExprWithBlock 2022-12-03 20:02:39 +01:00
Alex Gaynor bd8e476d8b
Avoid a temporary file when processing macOS fat archives 2022-12-03 14:02:35 -05:00
Alex Gaynor 047c7cc60c
Remove macOS fat archive support from LlvmArchiveBuilder
its only ever used for wasm targets
2022-12-03 13:29:22 -05:00
bjorn3 b2e0db93e7 Directly return loaded value from type_checked_load 2022-12-03 18:27:43 +00:00
bjorn3 fff6296b62 Destruct landing_pad return value before passing it to cg_ssa 2022-12-03 18:27:18 +00:00
Matthias Krüger af8f72292b
Rollup merge of #105208 - chenyukang:yukang/fix-105069, r=cjgillot
Add AmbiguityError for inconsistent resolution for an import

Fixes #105069
Fixes #83950
2022-12-03 17:37:45 +01:00
Matthias Krüger f91fa512d1
Rollup merge of #105201 - cjgillot:issue-105040, r=compiler-errors
Do not call fn_sig on non-functions.

Fixes https://github.com/rust-lang/rust/issues/105040
Fixes https://github.com/rust-lang/rust/issues/89271
2022-12-03 17:37:45 +01:00
Matthias Krüger b1e680650e
Rollup merge of #105200 - cjgillot:issue-104562, r=compiler-errors
Remove useless filter in unused extern crate check.

Fixes https://github.com/rust-lang/rust/issues/104562
2022-12-03 17:37:44 +01:00
Matthias Krüger ed9a21eb0c
Rollup merge of #105193 - tmiasko:naked-nocoverage, r=wesleywiser
Disable coverage instrumentation for naked functions

Fixes #105170.
2022-12-03 17:37:44 +01:00
Matthias Krüger a739fc8153
Rollup merge of #105164 - compiler-errors:revert-import-filter, r=estebank
Restore `use` suggestion for `dyn` method call requiring `Sized`

Add the suggestion back that I accidentally removed in 88f2140d87 because I didn't understand that suggestion was actually useful...

Fixes #105159
2022-12-03 17:37:43 +01:00
Matthias Krüger 1a2f79b82c
Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514
Remove useless borrows and derefs

They are nothing more than noise.
<sub>These are not all of them, but my clippy started crashing (stack overflow), so rip :(</sub>
2022-12-03 17:37:42 +01:00
Matthias Krüger c89bff29e5
Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillot
Keep track of the start of the argument block of a closure

This removes a call to `tcx.sess.source_map()` from [compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs](https://github.com/rust-lang/rust/compare/master...SarthakSingh31:issue-97417-1?expand=1#diff-8406bbc0d0b43d84c91b1933305df896ecdba0d1f9269e6744f13d87a2ab268a) as required by #97417.

VsCode automatically applied `rustfmt` to the files I edited under `src/tools`. I can undo that if its a problem.

r? `@cjgillot`
2022-12-03 17:37:41 +01:00
bors cab4fd678c Auto merge of #97485 - bjorn3:new_archive_writer, r=wesleywiser
Rewrite LLVM's archive writer in Rust

This allows it to be used by other codegen backends.

Fixes https://github.com/bjorn3/rustc_codegen_cranelift/issues/1155
2022-12-03 15:07:39 +00:00
Yutaro Ohno e4812583c7 parser: refactoring on recovery from invalid variable declarations
Previously, the `recover_local_after_let` function was called from the
body of the `recover_stmt_local` function. Unifying these two functions
make it more simple and more readable.
2022-12-03 23:41:42 +09:00
yukang fb004e9a95 fix #101749, use . instead of :: when accessing a method of an object 2022-12-03 22:41:12 +08:00
yukang 795b2afd20 fix #105069, Add AmbiguityError for inconsistent resolution for an import 2022-12-03 22:28:35 +08:00
Yutaro Ohno 690addc6ec parser: fix ICE with invalid variable declaration in macro call
Fix ICE on parsing an invalid variable declaration as a statement like:

```
macro_rules! m { ($s:stmt) => {} }
m! { var x }
```
2022-12-03 23:24:49 +09:00
bjorn3 a99838a115 Make sure all input archives are unmapped before persisting the output archive 2022-12-03 12:53:47 +00:00
Ralf Jung 51ac2af99f interpret: clobber return place when calling function 2022-12-03 13:37:13 +01:00
Oli Scherer c38ff3b385 Remove all but one call site of `prepare_outputs` and fetch the value from the TyCtxt instead 2022-12-03 12:28:01 +00:00
Camille GILLOT e973240d18 Do not call fn_sig on non-functions. 2022-12-03 09:34:06 +00:00
Camille GILLOT 59cc6cd4ac Remove useless filter in unused extern crate check. 2022-12-03 09:23:03 +00:00
bors 703d95e183 Auto merge of #105133 - oli-obk:promoted_def_ids, r=cjgillot
Ensure query backtraces work for `DefId`s created after ast lowering

r? `@cjgillot`
2022-12-03 08:17:46 +00:00
Yuki Okushi 7d4af8852c
Rollup merge of #105188 - compiler-errors:verbose-ty-err, r=TaKO8Ki
Don't elide type information when printing E0308 with `-Zverbose`

When we pass `-Zverbose`, we kinda expect for all `_` to be replaced with more descriptive information, for example --

```
   = note: expected fn pointer `fn(_, u32)`
                 found fn item `fn(_, i32) {foo}`
```

Where `_` is the "identical" part of the fn signatures, now gets rendered as:

```
   = note: expected fn pointer `fn(i32, u32)`
                 found fn item `fn(i32, i32) {foo}`
```
2022-12-03 12:51:30 +09:00
Yuki Okushi 8f368666b5
Rollup merge of #105181 - bhbs:skip-note, r=estebank
Don't add a note for implementing a trait if its inner type is erroneous

Fix #105138
2022-12-03 12:51:29 +09:00
Yuki Okushi 52e886279a
Rollup merge of #104903 - spastorino:consolidate-normalize-in-report_projection_error, r=lcnr
Use ocx.normalize in report_projection_error

r? `@lcnr`

cc `@compiler-errors`
2022-12-03 12:51:27 +09:00
BlackHoleFox 56592d310f Fix passing MACOSX_DEPLOYMENT_TARGET to the linker 2022-12-02 18:12:16 -06:00
bhbs 715d4a8949 Don't add a note for implementing a trait if its inner type is erroneous 2022-12-03 09:06:47 +09:00
Tomasz Miąsko b740cdcf43 Mark naked functions as never inline in codegen_fn_attrs
Use code generation attributes to ensure that naked functions are never
inline, replacing separate checks in MIR inliner and LLVM code
generation.
2022-12-03 01:04:42 +01:00
Tomasz Miąsko c955add18c Disable coverage instrumentation for naked functions 2022-12-03 01:03:28 +01:00
Michael Goulet 5c642d7d1c Don't elide information when printing E0308 with Zverbose 2022-12-02 21:01:59 +00:00
Santiago Pastorino 89047430f1
Define values and err as non mutable 2022-12-02 17:31:45 -03:00
Santiago Pastorino 4dacf4f469
Use ocx.normalize in report_projection_error 2022-12-02 17:31:40 -03:00
Matthias Krüger 8e0d83a70c
Rollup merge of #105185 - compiler-errors:normalize_fn_sig-in-err-ctxt, r=lcnr
Move `normalize_fn_sig` to `TypeErrCtxt`

r? `@lcnr`
2022-12-02 21:22:50 +01:00
Matthias Krüger 09e2d0f289
Rollup merge of #105163 - compiler-errors:afit-lt-arity, r=jackh726
Check lifetime param count in `collect_trait_impl_trait_tys`

We checked the type and const generics count, but not the lifetimes, which were handled in a different function.

Fixes #105154
2022-12-02 21:22:50 +01:00
Matthias Krüger babdf86952
Rollup merge of #105162 - compiler-errors:fn-sig-arity, r=cjgillot
Properly synthesize `FnSig` value during cycle

Get the arity correct when creating a `FnSig` type during `tcx.fn_sig` cycle recovery

Fixes #105152
2022-12-02 21:22:49 +01:00
Matthias Krüger b5b2d03c0c
Rollup merge of #105144 - compiler-errors:normalization-doc, r=lcnr
Document normalization methods `At::{normalize,query_normalize}`

r? ``@lcnr``
2022-12-02 21:22:48 +01:00
Matthias Krüger dab14348e9
Rollup merge of #105026 - oToToT:aarch64-v8a, r=davidtwco
v8a as default aarch64 target

After https://github.com/llvm/llvm-project/commit/8689f5e landed, LLVM takes the intersection of v8a and v8r as default. This commit brings back v8a support by explicitly specifying v8a in the feature list.

This should solve #97724.

p.s. a bit more context can also be found in https://github.com/llvm/llvm-project/issues/57904#issuecomment-1329555590.
2022-12-02 21:22:47 +01:00
Michael Goulet ffca711760 Move normalize_fn_sig to TypeErrCtxt 2022-12-02 19:29:14 +00:00
Gary Guo ec4080b236 Fix async track caller for assoc fn and trait impl fn 2022-12-02 16:47:57 +00:00
Gary Guo 4c73b64632 Use proper HirId for async track_caller attribute check 2022-12-02 16:47:57 +00:00
Oli Scherer c7e94b0efd Use zero based indexing for pass_count 2022-12-02 15:55:24 +00:00
Oli Scherer 80dcc52934 Remove an impl and replace its only use with a method call 2022-12-02 15:43:36 +00:00
bors e960b5e774 Auto merge of #104863 - nnethercote:reduce-lint-macros, r=cjgillot
Reduce macro usage for lints

r? `@cjgillot`
2022-12-02 15:31:15 +00:00
Michael Woerister 3a58309798 Add StableOrd trait as proposed in MCP 533.
The StableOrd trait can be used to mark types as having a stable
sort order across compilation sessions. Collections that sort their
items in a stable way can safely implement HashStable by
hashing items in sort order.
2022-12-02 15:19:30 +01:00
bjorn3 e1edc13afb Write to temp file before renaming to the final name 2022-12-02 13:18:20 +00:00
Takayuki Maeda 5c7278a364 return when expr has error
fmt

add a comment
2022-12-02 17:01:21 +09:00
Matthias Krüger 46c50af977
Rollup merge of #105136 - RalfJung:deref-promotion-comment, r=oli-obk
clarify comment on Deref promotion

r? `@oli-obk`
2022-12-02 08:28:10 +01:00
Matthias Krüger 4fdc3eb176
Rollup merge of #104614 - Nilstrieb:type-ascribe!, r=TaKO8Ki
Add `type_ascribe!` macro as placeholder syntax for type ascription

This makes it still possible to test the internal semantics of type ascription even once the `:`-syntax is removed from the parser. The macro now gets used in a bunch of UI tests that test the semantics and not syntax of type ascription.

I might have forgotten a few tests but this should hopefully be most of them. The remaining ones will certainly be found once type ascription is removed from the parser altogether.

Part of #101728
2022-12-02 08:28:08 +01:00
Yiming Lei 0e19fb92e1 While parsing enum variant, the error message always disappear
Because the error message that emit out is from main error of parser
The information of enum variant disappears while parsing enum variant with error
We only check the syntax of expecting token, i.e, in case #103869
It will error it without telling the message that this error is from pasring enum variant.
Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err
Check the sub-error before emitting the main error of parser and attach it.
Fix #103869
2022-12-01 22:48:52 -08:00
Michael Goulet dc45eb93f7 Revert 88f2140 2022-12-02 00:05:35 -05:00
Michael Goulet 5809a0591d Properly synthesize fn sig value during cycle 2022-12-01 23:56:57 -05:00
bors 11663b1b48 Auto merge of #104963 - petrochenkov:noaddids2, r=cjgillot
rustc_ast_lowering: Stop lowering imports into multiple items

Lower them into a single item with multiple resolutions instead.
This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-02 04:24:57 +00:00
Nicholas Nethercote 406dace6f2 Inline and remove `early_lint_node`.
It has a single call site.
2022-12-02 15:24:01 +11:00
Nicholas Nethercote a9b02af62b Merge `builtins` into `EarlyLintPassObjects`.
This avoids calling `early_lint_node` twice.

Note: one `early_lint_node` call had `!pre_expansion` for the second
argument and the other had `false`. The new single call just has
`!pre_expansion`. This results in a reduction of duplicate error
messages in some `ui-fulldeps` tests. The order of some `ui-fulldeps`
output also changes, but that doesn't matter.
2022-12-02 15:23:28 +11:00
Michael Goulet 3e7e1b1f83 Avoid InferCtxt::build in suggest_missing_break_or_return_expr 2022-12-02 04:11:48 +00:00
Michael Goulet bd7ee07d02 Check lifetime param count in collect_trait_impl_trait_tys 2022-12-02 04:05:39 +00:00
Nicholas Nethercote 44cb4f70a8 Remove some unnecessary `Send` bounds.
Required to get the parallel compiler building again.
2022-12-02 13:59:28 +11:00
Nicholas Nethercote 357aee9320 Inline and remove `late_lint_pass_crate`.
It has a single call site.
2022-12-02 13:59:28 +11:00
Nicholas Nethercote 0e4f55d63f Inline and remove `late_lint_mod_pass`.
It has a single call site.
2022-12-02 13:59:28 +11:00
Nicholas Nethercote 890c5ead20 Merge `builtins` into `LateLintPassObjects`.
This avoids calling the `late_lint_{mod_pass,pass_crate}` twice.
2022-12-02 13:59:28 +11:00
Nicholas Nethercote 99e9c1ddb7 Remove six macros relating to lint definitions.
These were enabled by the removal of `-Zno-interleave-lints`.
2022-12-02 13:59:28 +11:00
Nicholas Nethercote 67cfe2cfbb Remove `-Zno-interleave-lints`.
Because it complicates lint implementation greatly.
2022-12-02 13:59:28 +11:00
Nicholas Nethercote 33faf01690 Eliminate four unnecessary lint macros.
The lint definitions use macros heavily. This commit merges some of them
that are split unnecessarily. I find the reduced indirection makes it
easier to imagine what the generated code will look like.
2022-12-02 13:59:28 +11:00
Nicholas Nethercote d5526ff40d Reorder `StrLit` fields.
To better match `MetaItemLit`.
2022-12-02 13:50:00 +11:00
Nicholas Nethercote 2fd364acff Remove `token::Lit` from `ast::MetaItemLit`.
`token::Lit` contains a `kind` field that indicates what kind of literal
it is. `ast::MetaItemLit` currently wraps a `token::Lit` but also has
its own `kind` field. This means that `ast::MetaItemLit` encodes the
literal kind in two different ways.

This commit changes `ast::MetaItemLit` so it no longer wraps
`token::Lit`. It now contains the `symbol` and `suffix` fields from
`token::Lit`, but not the `kind` field, eliminating the redundancy.
2022-12-02 13:49:19 +11:00
Jakob Degen f4f777772e Disable top-down inlining 2022-12-01 18:32:45 -08:00
Nicholas Nethercote a7f35c42d4 Add `StrStyle` to `ast::LitKind::ByteStr`.
This is required to distinguish between cooked and raw byte string
literals in an `ast::LitKind`, without referring to an adjacent
`token::Lit`. It's a prerequisite for the next commit.
2022-12-02 10:38:58 +11:00
Nicholas Nethercote e658144586 Rename `LitKind::to_token_lit` as `LitKind::synthesize_token_lit`.
This makes it clearer that it's not a lossless conversion, which I find
helpful.
2022-12-02 10:23:44 +11:00
Michael Goulet 02b64c5d26 Document normalization methods on At 2022-12-01 19:00:09 +00:00
Michael Goulet e45daa9856 Drive-by: remove unused type alias 2022-12-01 19:00:09 +00:00
Gary Guo 171b7d62ad Make inline const block `ExprWithBlock` 2022-12-01 17:54:50 +00:00
bors c090c6880c Auto merge of #105125 - matthiaskrgr:rollup-fr0snmj, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #105078 (Fix `expr_to_spanned_string` ICE)
 - #105087 (Extract llvm datalayout parsing out of spec module)
 - #105088 (rustdoc: remove redundant CSS `div.desc { display: block }`)
 - #105106 (Fix ICE from #105101)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-01 17:47:12 +00:00
Maybe Waffle 083ef45458 `rustc_data_structures` deref in a more humane way 2022-12-01 17:34:45 +00:00
Maybe Waffle f2b97a8bfe Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
Vadim Petrochenkov b32a4edb20 rustc_ast_lowering: Stop lowering imports into multiple items
Lower them into a single item with multiple resolutions instead.
This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-01 18:51:20 +03:00
Vadim Petrochenkov 1f259ae679 rustc_hir: Change representation of import paths to support multiple resolutions 2022-12-01 18:51:05 +03:00
Ralf Jung b7f2b1cd5c clarify comment on Deref promotion 2022-12-01 16:42:33 +01:00
Vadim Petrochenkov 6cd4dd3091 rustc_hir: Relax lifetime requirements on `Visitor::visit_path` 2022-12-01 17:04:02 +03:00
Matthias Krüger ee9eaa695c
Rollup merge of #105106 - jhpratt:issue-105101, r=TaKO8Ki
Fix ICE from #105101

Fixes #105101

Rather than comparing idents, compare spans, which should be unique to each variant.
2022-12-01 11:59:01 +01:00
Matthias Krüger adec7eeb17
Rollup merge of #105087 - HKalbasi:master, r=eddyb
Extract llvm datalayout parsing out of spec module

fix https://github.com/rust-lang/rust/pull/103693#discussion_r1033250846
2022-12-01 11:59:00 +01:00
Matthias Krüger 741f8c9166
Rollup merge of #105078 - TaKO8Ki:fix-105011, r=nnethercote
Fix `expr_to_spanned_string` ICE

Fixes #105011
2022-12-01 11:58:59 +01:00
bors 9c0bc3028a Auto merge of #104975 - JakobDegen:custom_mir_let, r=oli-obk
`#![custom_mir]`: Various improvements

This PR makes a bunch of improvements to `#![custom_mir]`. Ideally this would be 4 PRs, one for each commit, but those would take forever to get merged and be a pain to juggle. Should still be reviewed one commit at a time though.

### Commit 1: Support arbitrary `let`

Before this change, all locals used in the body need to be declared at the top of the `mir!` invocation, which is rather annoying. We attempt to change that.

Unfortunately, we still have the requirement that the output of the `mir!` macro must resolve, typecheck, etc. Because of that, we can't just accept this in the THIR -> MIR parser because something like
```rust
{
    let x = 0;
    Goto(other)
}
other = {
    RET = x;
    Return()
}
```
will fail to resolve. Instead, the implementation does macro shenanigans to find the let declarations and extract them as part of the `mir!` macro. That *works*, but it is fairly complicated and degrades debuginfo by quite a bit. Specifically, the spans for any statements and declarations that are affected by this are completely wrong. My guess is that this is a net improvement though.

One way to recover some of the debuginfo would be to not support type annotations in the `let` statements, which would allow us to parse like `let $stmt:stmt`. That seems quite surprising though.

### Commit 2: Parse consts

Reuses most of the const parsing from regular Mir building for building custom mir

### Commit 3: Parse statics

Statics are slightly weird because the Mir primitive associated with them is a reference/pointer to them, so this is factored out separately.

### Commit 4: Fix some spans

A bunch of the spans were non-ideal, so we adjust them to be much more helpful.

r? `@oli-obk`
2022-12-01 10:40:10 +00:00
Oli Scherer ab75d777de Fill in `def_span` when creating def ids.
This makes sure that ICEing because of def ids created outside of ast lowering will be able to produce a query backtrace and not cause a double panic because of trying to call the  `def_span` query
2022-12-01 10:33:28 +00:00
Oli Scherer a0bdb4b498 Don't allow feeding a query cache entry twice 2022-12-01 09:48:33 +00:00
Oli Scherer 4f593ce5d8 Create `format_args` as late as possible 2022-12-01 08:49:51 +00:00
Oli Scherer 66797fa54f Remove needless `Cow` 2022-12-01 08:38:47 +00:00
Oli Scherer c2166ec628 Don't go through the formatting infrastructure just to get the name of a phase 2022-12-01 08:31:54 +00:00
bors d6c4de0fb2 Auto merge of #104861 - nnethercote:attr-cleanups, r=petrochenkov
Attribute cleanups

Best reviewed one commit at a time.

r? `@petrochenkov`
2022-12-01 07:13:45 +00:00
bors 744a97b98c Auto merge of #105095 - matthiaskrgr:rollup-9pu7vrx, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #103065 (rustdoc-json: Document and Test that args can be patterns.)
 - #104865 (Don't overwrite local changes when updating submodules)
 - #104895 (Avoid Invalid code suggested when encountering unsatisfied trait bounds in derive macro code)
 - #105063 (Rustdoc Json Tests: Don't assume that core::fmt::Debug will always have one item.)
 - #105064 (rustdoc: add comment to confusing CSS `main { min-width: 0 }`)
 - #105074 (Add Nicholas Bishop to `.mailmap`)
 - #105081 (Add a regression test for #104322)
 - #105086 (rustdoc: clean up sidebar link CSS)
 - #105091 (add Tshepang Mbambo to .mailmap)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-01 04:16:30 +00:00
Jacob Pratt ab264ae612
Fix ICE from #105101 2022-11-30 21:18:31 +00:00
Arpad Borsos b5ae4c9629
Make sure async constructs do not `impl Generator`
Async lowering turns async functions and blocks into generators internally.
Though these special kinds of generators should not `impl Generator` themselves.
The other way around, normal generators should not `impl Future`.
2022-11-30 19:53:59 +01:00
Matthias Krüger eabc0720a6
Rollup merge of #104895 - chenyukang:yukang/fix-104884-serde, r=TaKO8Ki
Avoid Invalid code suggested when encountering unsatisfied trait bounds in derive macro code

Fixes #104884
2022-11-30 19:53:18 +01:00
yukang 0e24cee063 fix #105028, Only suggest removing struct field from destructive binding in shorthand scenario 2022-12-01 02:22:18 +08:00
hkalbasi 56126fb149 Extract llvm datalayout parsing out of spec module 2022-11-30 21:13:54 +03:30
bors c97b539e40 Auto merge of #104940 - cjgillot:query-feed-simple, r=oli-obk
Allow to feed a value in another query's cache

Restricted version of https://github.com/rust-lang/rust/pull/96840

A query can create new definitions.

If those definitions are created after HIR lowering, they do not appear in the initial HIR map, and information for them cannot be provided in the normal pull-based way.

In order to make those definitions useful, we allow to feed values as query results for the newly created definition.

The API is as follows:
```rust
let feed = tcx.create_def(<parent def id>, <DefPathData>);
// `feed` is a TyCtxtFeed<'tcx>.

// Access the created definition.
let def_id: LocalDefId = feed.def_id;

// Assign `my_query(def_id) := my_value`.
feed.my_query(my_value).
```

This PR keeps the consistency checks introduced by https://github.com/rust-lang/rust/pull/96840, even if they are not reachable. This allows to extend the behaviour later without forgetting them.

cc `@oli-obk` `@spastorino`
2022-11-30 17:20:14 +00:00
Oli Scherer 14a9cf2ba2 Generalize some InternedInSet impls 2022-11-30 14:52:05 +00:00
Oli Scherer 907ef227ef Remove PredicateS type 2022-11-30 14:47:40 +00:00
bors 90711a86e5 Auto merge of #99814 - aliemjay:patch-2, r=jackh726
fix universe map in ifcx.instantiate_canonical_*

Previously, `infcx.instantiate_canonical_*` maps the root universe in `canonical` into `ty::UniverseIndex::Root`, I think because it assumes it works with a fresh `infcx` but this is not true for the use cases in mir typeck. Now the root universe is mapped into `infcx.universe()`.

I catched this accidentally while reviewing the code. I'm not sure if this is the right fix or if it is really a bug!
2022-11-30 14:03:36 +00:00
Oli Scherer 46ba1545b8 Update documentation 2022-11-30 12:17:54 +00:00
Oli Scherer 147b854ded Remove TyS 2022-11-30 12:17:54 +00:00
Oli Scherer 87a04f51ba move WithCachedTypeInfo to rustc_type_ir 2022-11-30 12:17:13 +00:00
Oli Scherer 3d31e5c981 s/WithStableHash/WithCachedTypeInfo/ 2022-11-30 12:11:19 +00:00
bors 24606deaf4 Auto merge of #104905 - compiler-errors:normalization-changes, r=spastorino
Some initial normalization method changes

1. Rename `AtExt::normalize` to `QueryNormalizeExt::query_normalize` (using the `QueryNormalizer`)
2. Introduce `NormalizeExt::normalize` to replace `partially_normalize_associated_types_in` (using the `AssocTypeNormalizer`)
3. Rename `FnCtxt::normalize_associated_types_in` to `FnCtxt::normalize`
4. Remove some unused other normalization fns in `Inherited` and `FnCtxt`

Also includes one drive-by where we're no longer creating a `FnCtxt` inside of `check_fn`, but passing it in. This means we don't need such weird `FnCtxt` construction logic.

Stacked on top of #104835 for convenience.

r? types
2022-11-30 11:13:09 +00:00
bors a569a88f55 Auto merge of #105080 - matthiaskrgr:rollup-7ffj4oe, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #104697 (Restore control flow on error in EUV)
 - #104811 (feat: implement TcpStream shutdown for wasm32-wasi)
 - #105039 (Fix an ICE parsing a malformed literal in `concat_bytes!`.)
 - #105071 (Add Nicholas Nethercote to `.mailmap`.)
 - #105079 (Add bots to `.mailmap`)

Failed merges:

 - #105074 (Add Nicholas Bishop to `.mailmap`)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-30 07:59:24 +00:00
Matthias Krüger 084bbcc2ca
Rollup merge of #105039 - nnethercote:fix-104769, r=petrochenkov
Fix an ICE parsing a malformed literal in `concat_bytes!`.

Fixes #104769.

r? `@petrochenkov`
2022-11-30 07:00:31 +01:00
Matthias Krüger 0c14551fe5
Rollup merge of #104697 - dingxiangfei2009:fix-euv-control-flow, r=oli-obk
Restore control flow on error in EUV

cc `@Nilstrieb`

Fix #104649

Since #98574 refactored a piece of scrutinee memory categorization out as a subroutine, there is a subtle change in handling match arms especially when the categorization process faults and bails. In the correct case, it is not supposed to continue to process the arms any more. This PR restores the original control flow in EUV.

I promise to add a compile-fail test to demonstrate that this indeed fixes the issue after coming back from a nap.
2022-11-30 07:00:30 +01:00
Takayuki Maeda 02eaecc767 avoid an unnecessary `&str` to `String` conversion 2022-11-30 13:31:35 +09:00
Takayuki Maeda 97f0c58b37 report literal errors when `token_lit` has errors 2022-11-30 13:31:11 +09:00
bors 8de4b13845 Auto merge of #104679 - dvdhrm:rw/dso, r=petrochenkov
codegen-llvm: never combine DSOLocal and DllImport

Prevent DllImport from being attached to DSOLocal definitions in the LLVM IR. The combination makes no sense, since definitions local to the compilation unit will never be imported from external objects.

Additionally, LLVM will refuse the IR if it encounters the combination (introduced in [1]):

```
  if (GV.hasDLLImportStorageClass())
    Assert(!GV.isDSOLocal(),
           "GlobalValue with DLLImport Storage is dso_local!", &GV);
```

Right now, codegen-llvm will only apply DllImport to constants and rely on call-stubs for functions. Hence, we simply extend the codegen of constants to skip DllImport for any local definitions.

This was discovered when switching the EFI targets to the static relocation model [2]. With this fixed, we can start another attempt at this.

[1] 509132b368
[2] https://github.com/rust-lang/rust/issues/101656
2022-11-30 04:18:15 +00:00
Jakob Degen 5a34dbf193 Improve spans in custom mir 2022-11-29 19:27:26 -08:00
Jakob Degen 52ce1f7697 Support statics in custom mir 2022-11-29 19:27:26 -08:00
Jakob Degen 7578100317 Support most constant kinds in custom mir 2022-11-29 19:26:04 -08:00
Nicholas Nethercote bf4a62c381 Fix an ICE parsing a malformed literal in `concat_bytes!`.
Fixes #104769.
2022-11-30 12:19:07 +11:00
bors d38a99078c Auto merge of #105070 - matthiaskrgr:rollup-9b25khj, r=matthiaskrgr
Rollup of 14 pull requests

Successful merges:

 - #103876 (type alias impl trait: add tests showing that hidden type only outlives lifetimes that occur in bounds)
 - #104427 (Explain why `rematch_impl` fails to be infallible)
 - #104436 (Add slice to the stack allocated string comment)
 - #104523 (Don't use periods in target names)
 - #104627 (Print all features with --print target-features)
 - #104911 (Make inferred_outlives_crate return Clause)
 - #105002 (Add `PathBuf::as_mut_os_string` and `Path::as_mut_os_str`)
 - #105023 (Statics used in reachable function's inline asm are reachable)
 - #105045 (`rustc_ast_{passes,pretty}`: remove `ref` patterns)
 - #105049 (Hermit: Minor build fixes)
 - #105051 (Replace a macro with a function)
 - #105062 (rustdoc: use shorthand background for rustdoc toggle CSS)
 - #105066 (move `candidate_from_obligation` out of assembly)
 - #105068 (Run patchelf also on rust-analyzer-proc-macro-srv.)

Failed merges:

 - #105050 (Remove useless borrows and derefs)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-30 00:42:43 +00:00
Matthias Krüger 08a6c939a5
Rollup merge of #105066 - lcnr:mv-candidate_from_obligation, r=compiler-errors
move `candidate_from_obligation` out of assembly

it doesn't belong there as it also does winnowing

r? `@compiler-errors`
2022-11-29 22:43:22 +01:00
Matthias Krüger 776e4a36c7
Rollup merge of #105051 - WaffleLapkin:unmacro, r=oli-obk
Replace a macro with a function

🌸
2022-11-29 22:43:21 +01:00
Matthias Krüger b596d6be7f
Rollup merge of #105045 - WaffleLapkin:deref-ahhhh~, r=compiler-errors
`rustc_ast_{passes,pretty}`: remove `ref` patterns

r? `@compiler-errors`
Previous PR: https://github.com/rust-lang/rust/pull/104721
2022-11-29 22:43:19 +01:00
Matthias Krüger 581ca3e836
Rollup merge of #105023 - tmiasko:asm-sym-static-reachable, r=wesleywiser
Statics used in reachable function's inline asm are reachable

Fixes #104925.
2022-11-29 22:43:19 +01:00
Matthias Krüger ca8f4c8d72
Rollup merge of #104911 - spastorino:inferred_outlives_crate-return-clause, r=oli-obk
Make inferred_outlives_crate return Clause

r? ``@oli-obk``
2022-11-29 22:43:18 +01:00
Matthias Krüger 3539cf9344
Rollup merge of #104627 - calebzulawski:print-target-features, r=compiler-errors
Print all features with --print target-features

This fixes `rustc --print target-features` with respect to aliases and tied features.

Before this change, the print command assumed that each LLVM feature corresponds exactly to one rustc feature.  In the case of aliases and tied features, this assumption failed and some features (such as aarch64's "pacg") were missing.  With this change, every target feature is listed.
2022-11-29 22:43:17 +01:00
Matthias Krüger 3e9a2233d0
Rollup merge of #104523 - flba-eb:fix_nto_target_name, r=wesleywiser
Don't use periods in target names

Using a period in the target name can cause issues in e.g. cargo, see also https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Running.20tests.20on.20remote.20target
2022-11-29 22:43:17 +01:00
Matthias Krüger d88699f9f5
Rollup merge of #104427 - compiler-errors:rematch-impl-may-fail-actually, r=lcnr
Explain why `rematch_impl` fails to be infallible

Fixes #104395

r? `@lcnr`
2022-11-29 22:43:16 +01:00
Matthias Krüger 3617adfaee
Rollup merge of #103876 - oli-obk:tait_implications, r=lcnr
type alias impl trait: add tests showing that hidden type only outlives lifetimes that occur in bounds

fixes #103642

https://github.com/rust-lang/rust/pull/102417 only made sure that hidden types cannot outlive lifetimes other than the ones mentioned on bounds, but didn't allow us to actually infer anything from that.

cc `@aliemjay`
2022-11-29 22:43:15 +01:00
bors bddad597fe Auto merge of #94487 - oli-obk:stable_hash_ty, r=fee1-dead
Also cache the stable hash of interned Predicates

continuation of https://github.com/rust-lang/rust/pull/94299

This is a small perf improvement and shares more code between `Ty` and `Predicate`
2022-11-29 21:35:02 +00:00
lcnr bb982df771 move `candidate_from_obligation` out of assembly
it doesn't belong there as it also does winnowing
2022-11-29 20:32:48 +00:00