Commit Graph

16192 Commits

Author SHA1 Message Date
Matthias Krüger
234e0f27c2
Rollup merge of #100887 - eholk:codegen_call_terminator-cleanup, r=fee1-dead
Refactor part of codegen_call_terminator

I was reading through this code and found the chain of `if let` and a nested match on the same value that was matched in the `if let` to be kind of hard to follow. This PR cleans it up by flattening the `if let` chain and nested match into a single `match` expression.
2022-08-23 06:55:30 +02:00
Matthias Krüger
f5fcac9978
Rollup merge of #100861 - RalfJung:const-ice, r=oli-obk
fix ICE with extra-const-ub-checks

Fixes https://github.com/rust-lang/rust/issues/100771
2022-08-23 06:55:28 +02:00
Matthias Krüger
579dfa42be
Rollup merge of #100789 - compiler-errors:issue-99662, r=spastorino
Use separate infcx to solve obligations during negative coherence

I feel like I fixed this already but I may have fixed it then forgot to push the branch...

Also fixes up some redundant param-envs being passed around (since they're already passed around in the `Obligation`)

Fixes #99662

r? ``@spastorino``
2022-08-23 06:55:26 +02:00
Matthias Krüger
44aa866488
Rollup merge of #100641 - corwinkuiper:add-armv4t-target, r=oli-obk
Add the armv4t-none-eabi target to the supported_targets

This target was added in #100244 but forgot to add it to the macro in the `mod.rs` file.

``@Lokathor``
2022-08-23 06:55:25 +02:00
Matthias Krüger
54d0f50677
Rollup merge of #100565 - TaKO8Ki:suggest-adding-missing-semicolon-before-item, r=compiler-errors
Suggest adding a missing semicolon before an item

fixes #100533
2022-08-23 06:55:24 +02:00
Matthias Krüger
e568cb45fe
Rollup merge of #100382 - jackh726:gat-self-outlives-input, r=compiler-errors
Make the GATS self outlives error take into GATs in the inputs

Before, the reasoning was that outlives should factor in to the outlives error, because that value is produced and inputs aren't. However, this is potentially confusing, and we can just require this for now and relax it later if we need. GATs in where clauses still don't count for the self outlives error, and I've added a test for that.

This now errors:
```rust
trait Input {
    type Item<'a>;
    //~^ missing required
    fn takes_item<'a>(&'a self, item: Self::Item<'a>);
}
```

I've also added a test that this does not:
```rust
trait WhereClause {
    type Item<'a>;
    fn takes_item<'a>(&'a self) where Self::Item<'a>: ;
}
```

r? ``@compiler-errors``
2022-08-23 06:55:23 +02:00
bors
8818b00b63 Auto merge of #99963 - cjgillot:iter-submodule, r=compiler-errors
Simplify implementation for par_for_each_module
2022-08-22 23:09:35 +00:00
bors
015a824f2d Auto merge of #99762 - Nilstrieb:unreachable-prop, r=oli-obk
UnreachableProp: Preserve unreachable branches for multiple targets

Before, UnreachablePropagation removed all unreachable branches. This was a pessimization, as it removed information about reachability that was used later in the optimization pipeline.

For example, this code
```rust
pub enum Two { A, B }
pub fn identity(x: Two) -> Two {
    match x {
        Two::A => Two::A,
        Two::B => Two::B,
    }
}
```

basically has `switchInt() -> [0: 0, 1: 1, otherwise: unreachable]` for the match. This allows it to be transformed into a simple `x`. If we remove the unreachable branch, the transformation becomes illegal.

This was the problem keeping `UnreachablePropagation` from being enabled, so we can enable it now.

Something similar already happened in #77800, but it did not show a perf improvement there. Let's try it again anyways!

Fixes #68105, although that issue has been fixed for a long time (see #77680).
2022-08-22 20:28:16 +00:00
Eric Holk
b562f95963 Refactor part of codegen_call_terminator 2022-08-22 11:34:06 -07:00
bors
a785176741 Auto merge of #100881 - Dylan-DPC:rollup-q9rr658, r=Dylan-DPC
Rollup of 8 pull requests

Successful merges:

 - #98200 (Expand potential inner `Or` pattern for THIR)
 - #99770 (Make some const prop mir-opt tests `unit-test`s)
 - #99957 (Rework Ipv6Addr::is_global to check for global reachability rather than global scope - rebase)
 - #100331 (Guarantee `try_reserve` preserves the contents on error)
 - #100336 (Fix two const_trait_impl issues)
 - #100713 (Convert diagnostics in parser/expr to SessionDiagnostic)
 - #100820 (Use pointer `is_aligned*` methods)
 - #100872 (Add guarantee that Vec::default() does not alloc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-22 17:46:57 +00:00
Dylan DPC
75b7089d1e
Rollup merge of #100713 - Xiretza:parser-expr-session-diagnostics, r=estebank
Convert diagnostics in parser/expr to SessionDiagnostic

This migrates all the easy cases in `rustc_parse::parser::expr` to `SessionDiagnostic`s, I've left things such as `multipart_suggestion`s out for now in the hopes of a derive API being developed soon.
2022-08-22 20:34:14 +05:30
Dylan DPC
14c8a68e49
Rollup merge of #100336 - fee1-dead-contrib:fix-wf-const-trait, r=oli-obk
Fix two const_trait_impl issues

r? ``@oli-obk``

Fixes #100222.
Fixes #100543.
2022-08-22 20:34:13 +05:30
Dylan DPC
56ba13ac7f
Rollup merge of #98200 - ouz-a:issue-98177, r=oli-obk
Expand potential inner `Or` pattern for THIR

Code assumed there wouldn't be a deeper `Or` pattern inside expanded `PatStack` this fixes it by looking for the `Or` pattern inside expanded `PatStack`.

A more ideal solution would be recursively doing this but I haven't found a good way to do that.
_fixes #97898_
2022-08-22 20:34:08 +05:30
bors
e0dc8d7801 Auto merge of #99908 - Nilstrieb:mir-opt-span, r=oli-obk
Show absolute line numbers if span is outside relative span

In the MIR pretty printing, it can sometimes happen that the span of the statement is outside the span of the body (for example through inlining). In this case, don't display a relative span but an absolute span. This will make the mir-opt-tests a little more prone to diffs again, but the impact should be small.

Fixes #99854

r? `@oli-obk`
2022-08-22 14:59:21 +00:00
Nilstrieb
135c24102c Fix span for consts in mir builder 2022-08-22 14:06:55 +02:00
Nilstrieb
455a55e681 Show absolute line numbers if span is outside relative span
In the MIR pretty printing, it can sometimes happen that the span of the
statement is outside the span of the body (for example through
inlining). In this case, don't display a relative span but an absolute
span. This will make the mir-opt-tests a little more prone to diffs
again, but the impact should be small.
2022-08-22 14:06:55 +02:00
Deadbeef
f1db3be9cf fix tidy 2022-08-22 11:44:04 +00:00
bors
a8a33cf271 Auto merge of #99702 - SparrowLii:transtive_relation, r=oli-obk
get rid of `RefCell` in `TransitiveRelation`

This is one of the jobs in `Pending refactorings` in #48685. The parallel-compiler's work has been suspended for quite some time, but I think I can pick it up gradually. I think this PR should be a start.

Regarding the refactoring of `TransitiveRelation`, `@nikomatsakis`  has proposed [two(three?) schemes](https://github.com/rust-lang/rust/pull/48587#issuecomment-369336651). In order to satisfy both compilation efficiency and robustness, I think adding the `freeze` method may be the best solution, although it requires relatively more code changes.
2022-08-22 11:39:53 +00:00
Deadbeef
f019b6c5e8 Overhaul 100222 test; wf always remap to nonconst 2022-08-22 11:28:01 +00:00
Deadbeef
460daf3434 remove stray comment 2022-08-22 11:06:07 +00:00
Deadbeef
d744f36ea2 Fix wf check on #[const_trait] return types 2022-08-22 10:53:26 +00:00
SparrowLii
a01ac5a699 re-base and use OutlivesEnvironment::with_bounds 2022-08-22 18:36:02 +08:00
SparrowLii
d39fefdd69 use type alias impl trait in outlives_bounds::InferCtxtExt 2022-08-22 18:10:28 +08:00
SparrowLii
d037f1843e add with_bounds to OutlivesEnvironment and implied_bounds_tys to outlives_bounds::InferCtxtExt 2022-08-22 18:09:59 +08:00
SparrowLii
5d9e4d07fc get rid of RefCell in TransitiveRelation 2022-08-22 18:08:46 +08:00
bors
ee8c31e64d Auto merge of #100868 - Dylan-DPC:rollup-a1hfi1r, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #93162 (Std module docs improvements)
 - #99386 (Add tests that check `Vec::retain` predicate execution order.)
 - #99915 (Recover keywords in trait bounds)
 - #100694 (Migrate rustc_ast_passes diagnostics to `SessionDiagnostic` and translatable messages (first part))
 - #100757 (Catch overflow early)

Failed merges:

 - #99917 (Move Error trait into core)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-22 08:32:41 +00:00
Dylan DPC
88e39b2c2e
Rollup merge of #100757 - ouz-a:issue-95134, r=jackh726
Catch overflow early

Although this code should raise an overflow error, it didn't because [check_recursion_limit](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_trait_selection/traits/select/struct.SelectionContext.html#method.check_recursion_limit) it checks for `depth = 128` but not for `129` which should have triggered the overflow error. Anyways this catches that error early.

Fixes #95134
2022-08-22 11:45:45 +05:30
Dylan DPC
57e521e0e5
Rollup merge of #100694 - finalchild:ast-passes-diag, r=TaKO8Ki
Migrate rustc_ast_passes diagnostics to `SessionDiagnostic` and translatable messages (first part)

Doing a full migration of the `rustc_ast_passes` crate.
Making a draft here since there's not yet a tracking issue for the migrations going on.

`@rustbot` label +A-translation
2022-08-22 11:45:44 +05:30
Dylan DPC
3842117ef2
Rollup merge of #99915 - WaffleLapkin:recover_keyword_bounds, r=compiler-errors
Recover keywords in trait bounds

(_this pr was inspired by [this tweet](https://twitter.com/Azumanga/status/1552982326409367561)_)

Recover keywords in trait bound, motivational example:
```rust
fn f(_: impl fn()) {} // mistyped, meant `Fn`
```

<details><summary>Current nightly (3 needless and confusing errors!)</summary>
<p>

```text
error: expected identifier, found keyword `fn`
 --> ./t.rs:1:15
  |
1 | fn _f(_: impl fn()) {}
  |               ^^ expected identifier, found keyword
  |
help: escape `fn` to use it as an identifier
  |
1 | fn _f(_: impl r#fn()) {}
  |               ++

error: expected one of `:` or `|`, found `)`
 --> ./t.rs:1:19
  |
1 | fn _f(_: impl fn()) {}
  |                   ^ expected one of `:` or `|`

error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, `~`, lifetime, or path, found keyword `fn`
 --> ./t.rs:1:15
  |
1 | fn _f(_: impl fn()) {}
  |              -^^ expected one of 9 possible tokens
  |              |
  |              help: missing `,`

error: at least one trait must be specified
 --> ./t.rs:1:10
  |
1 | fn _f(_: impl fn()) {}
  |          ^^^^
```

</p>
</details>

This PR:
```text
error: expected identifier, found keyword `fn`
 --> ./t.rs:1:15
  |
1 | fn _f(_: impl fn()) {}
  |               ^^ expected identifier, found keyword
  |
help: escape `fn` to use it as an identifier
  |
1 | fn _f(_: impl r#fn()) {}
  |               ++

error[E0405]: cannot find trait `r#fn` in this scope
  --> ./t.rs:1:15
   |
1  | fn _f(_: impl fn()) {}
   |               ^^ help: a trait with a similar name exists (notice the capitalization): `Fn`
   |
  ::: /home/waffle/projects/repos/rust/library/core/src/ops/function.rs:74:1
   |
74 | pub trait Fn<Args>: FnMut<Args> {
   | ------------------------------- similarly named trait `Fn` defined here
```

It would be nice to have suggestion in the first error like "have you meant `Fn` trait", instead of a separate error, but the recovery is deep inside ident parsing, which makes it a lot harder to do.

r? `@compiler-errors`
2022-08-22 11:45:42 +05:30
bors
a9bb589cd6 Auto merge of #100676 - lcnr:implied-bounds-yay, r=nikomatsakis
implied bounds: explicitly state which types are assumed to be wf

Adds a new query which maps each definition to the types which that definition assumes to be well formed. The intent is to make it easier to reason about implied bounds.

This change should not influence the user-facing behavior of rustc. Notably, `borrowck` still only assumes that the function signature of associated functions is well formed while `wfcheck` assumes that the both the function signature and the impl trait ref is well formed. Not sure if that by itself can trigger UB or whether it's just annoying.

As a next step, we can add `WellFormed` predicates to `predicates_of` of these items and can stop adding the wf bounds at each place which uses them. I also intend to move the computation from `assumed_wf_types` to `implied_bounds` into the `param_env` computation. This requires me to take a deeper look at `compare_predicate_entailment` which is currently somewhat weird wrt implied bounds so I am not touching this here.

r? `@nikomatsakis`
2022-08-22 06:10:26 +00:00
bors
d0ea1d7679 Auto merge of #100671 - Xiretza:tidy-fluent-files, r=davidtwco
tidy: check fluent files for style

Inspired by https://github.com/rust-lang/rust/pull/100651#discussion_r947600576

There were a lot of line length violations, so I've excepted that lint - I'm not sure if fluent files can be formatted to avoid long lines at all.
2022-08-22 03:02:50 +00:00
bors
3ce46b74aa Auto merge of #100668 - nnethercote:use-AttrVec-more, r=spastorino
Use `AttrVec` more

In some places we use `Vec<Attribute>` and some places we use
`ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points
where we have to convert between `Vec` and `ThinVec`.

This commit changes the places that use `Vec<Attribute>` to use
`AttrVec`. A lot of this is mechanical and boring, but there are
some interesting parts:
- It adds a few new methods to `ThinVec`.
- It implements `MapInPlace` for `ThinVec`, and introduces a macro to
  avoid the repetition of this trait for `Vec`, `SmallVec`, and
  `ThinVec`.

Overall, it makes the code a little nicer, and has little effect on
performance. But it is a precursor to removing
`rustc_data_structures::ThinVec` and replacing it with
`thin_vec::ThinVec`, which is implemented more efficiently.

r? `@spastorino`
2022-08-22 00:34:02 +00:00
Ralf Jung
d7ee421870 fix ICE with extra-const-ub-checks 2022-08-21 20:00:38 -04:00
bors
0b71ffca18 Auto merge of #100654 - compiler-errors:rework-point-at-arg, r=estebank
Rework "point at arg" suggestions to be more accurate

Fixes #100560

Introduce a new set of `ObligationCauseCode`s which have additional bookeeping for what expression caused the obligation, and which predicate caused the obligation. This allows us to look at the _unsubstituted_ signature to find out which parameter or generic type argument caused an obligaton to fail.

This means that (in most cases) we significantly improve the likelihood of pointing out the right argument that causes a fulfillment error. Also, since this logic isn't happening in just the `select_where_possible_and_mutate_fulfillment()` calls in the argument checking code, but instead during all trait selection in `FnCtxt`, we are also able to point out the correct argument even if inference means that we don't know whether an obligation has failed until well after a call expression has been checked.

r? `@ghost`
2022-08-21 21:52:56 +00:00
Nicholas Nethercote
619b8abaa6 Use AttrVec in more places.
In some places we use `Vec<Attribute>` and some places we use
`ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points
where we have to convert between `Vec` and `ThinVec`.

This commit changes the places that use `Vec<Attribute>` to use
`AttrVec`. A lot of this is mechanical and boring, but there are
some interesting parts:
- It adds a few new methods to `ThinVec`.
- It implements `MapInPlace` for `ThinVec`, and introduces a macro to
  avoid the repetition of this trait for `Vec`, `SmallVec`, and
  `ThinVec`.

Overall, it makes the code a little nicer, and has little effect on
performance. But it is a precursor to removing
`rustc_data_structures::thin_vec::ThinVec` and replacing it with
`thin_vec::ThinVec`, which is implemented more efficiently.
2022-08-22 07:35:33 +10:00
Nilstrieb
bc79557311 Enable UnreachablePropagation under mir-opt-level >= 2
It was disabled because of pathological behaviour of LLVM in some
benchmarks. As of #77680, this has been fixed. The problem there was
that it caused pessimizations in some cases. These have now been fixed
as well.
2022-08-21 21:15:28 +02:00
Nilstrieb
eafab66096 UnreachableProp: Preserve unreachable branches for multiple targets
Before, UnreachablePropagation removed all unreachable branches.
This was a pessimization, as it removed information about
reachability that was used later in the optimization pipeline.

For example, this code
```rust
pub enum Two { A, B }
pub fn identity(x: Two) -> Two {
    match x {
        Two::A => Two::A,
        Two::B => Two::B,
    }
}
```

basically has `switchInt() -> [0: 0, 1: 1, otherwise: unreachable]` for the match.
This allows it to be transformed into a simple `x`. If we remove the
unreachable branch, the transformation becomes illegal.
2022-08-21 21:15:28 +02:00
finalchild
09d495cc15 Replace #[error(..)] etc. to #[diag(..)] 2022-08-22 01:24:47 +09:00
Park Jaeon [파차]
70e0af632d Fix incorrect return type of emit_fatal
Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
2022-08-22 01:11:59 +09:00
finalchild
6a340741bd Remove redundant clone 2022-08-22 01:11:59 +09:00
finalchild
e331ae57df Migrate forbidden_default and *_without_body 2022-08-22 01:11:59 +09:00
finalchild
8ed8aac3ca Fix build_format not unescaping braces properly
Co-authored-by: RanolP <public.ranolp@gmail.com>
2022-08-22 01:11:59 +09:00
finalchild
b28cc097cf Support #[fatal(..)] 2022-08-22 01:11:55 +09:00
finalchild
bfefefbcfa Migrate fn_param_forbidden_self and rename others to have prefix fn_param_ 2022-08-22 00:57:22 +09:00
finalchild
07e0bc9600 Rename c_var_args_without_named_arg to c_var_args_is_sole_param 2022-08-22 00:57:22 +09:00
finalchild
c6903c04b1 Migrate doc_comment_on_fn_param, forbidden_attr_on_fn_param 2022-08-22 00:57:21 +09:00
finalchild
269c85390c Migrate forbidden_lifetime_bound, forbidden_non_lifetime_param, too_many_params, c_var_args_without_named_arg, c_var_args_not_last 2022-08-22 00:57:21 +09:00
finalchild
8d042f4483 Migrate trait_fn_const 2022-08-22 00:57:21 +09:00
finalchild
e3d4c4039a Migrate trait_fn_async 2022-08-22 00:57:21 +09:00
finalchild
88afae5d1a Tidy 2022-08-22 00:57:21 +09:00