Commit Graph

24389 Commits

Author SHA1 Message Date
Gary Guo
47171e0c50 Use landingpad filter to encode aborting landing pad 2023-05-07 12:35:54 +01:00
Yuki Okushi
88a0204fcb
Rollup merge of #111300 - Flying-Toast:while_true_span_condition, r=compiler-errors
Emit while_true lint spanning the entire loop condition

The lint that suggests `loop {}` instead of `while true {}` has functionality to 'pierce' parenthesis in cases like `while (true) {}`. In these cases, the emitted span only went to the hi of the `true` itself, not spanning the entire loop condition.

Before:
```
warning: denote infinite loops with `loop { ... }`
 --> /tmp/foobar.rs:2:5
  |
2 |     while ((((((true)))))) {}
  |     ^^^^^^^^^^^^^^^^ help: use `loop`
  |
  = note: `#[warn(while_true)]` on by default
```

After:
```
warning: denote infinite loops with `loop { ... }`
 --> /tmp/foobar.rs:2:5
  |
2 |     while ((((((true)))))) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
  |
  = note: `#[warn(while_true)]` on by default
```

This is especially a problem for rustfix.
2023-05-07 14:12:16 +09:00
Yuki Okushi
4e4e5bf17d
Rollup merge of #111293 - Astroide:patch-1, r=compiler-errors
rustc --explain E0726 - grammar fixing (it's => its + add a `the` where it felt right to do so)

Very small fix
2023-05-07 14:12:16 +09:00
Yuki Okushi
61115cd753
Rollup merge of #111150 - mj10021:issue-111025-fix, r=petrochenkov
added TraitAlias to check_item() for missing_docs

As in issue #111025 the `missing_docs` was not being triggered for trait aliases.  I added `TraitAlias` to the pattern match for check_item(), and the lint seems to be behaving appropriately
2023-05-07 14:12:15 +09:00
Yuki Okushi
58597717e2
Rollup merge of #105583 - luqmana:bitcast-immediates, r=oli-obk
Operand::extract_field: only cast llval if it's a pointer and replace bitcast w/ pointercast.

Fixes #105439.

Also cc `@erikdesjardins,` looks like another place to cleanup as part of #105545
2023-05-07 14:12:14 +09:00
Astroide
d6ef6e0080
Update compiler/rustc_error_codes/src/error_codes/E0726.md
Co-authored-by: Michael Goulet <michael@errs.io>
2023-05-06 19:39:08 -04:00
James Dietz
fd005b06bb delete whitelist and add checks to check_item() for missing_docs
add test and bless
2023-05-06 18:31:50 -04:00
Matthias Krüger
1de257bd33
Rollup merge of #111289 - clubby789:fix-111280, r=jyn514
Check arguments length in trivial diagnostic lint

Fixes #111280
2023-05-06 23:32:03 +02:00
Matthias Krüger
ecc0615967
Rollup merge of #111274 - cuviper:print-target-cpus, r=Mark-Simulacrum
Expand the LLVM coverage of `--print target-cpus`

We've been relying on a custom patch to add `MCSubtargetInfo::getCPUTable`
for `rustc --print target-cpus`, and just printing that it's not supported
on external LLVM builds. LLVM `main` now has `getAllProcessorDescriptions`
that can replace ours, so now we try to use that. In addition, the fallback
path can at least print the native and default cpu options.

There were also some mismatches in the function signatures here between
`LLVM_RUSTLLVM` and otherwise; this is now mitigated by sharing these
functions and only using cpp to adjust the function bodies.
2023-05-06 23:32:03 +02:00
Matthias Krüger
a3af532518
Rollup merge of #111237 - loongarch-rs:clobber-abi, r=Amanieu
asm: loongarch64: Implementation of clobber_abi

r? ```@Amanieu```
2023-05-06 23:32:02 +02:00
Matthias Krüger
e4eaf319c1
Rollup merge of #111203 - Kobzol:remark-print-kind, r=tmiasko
Output LLVM optimization remark kind in `-Cremark` output

Since https://github.com/rust-lang/rust/pull/90833, the optimization remark kind has not been printed. Therefore it wasn't possible to easily determine from the log (in a programmatic way) which remark kind was produced. I think that the most interesting remarks are the missed ones, which can lead users to some code optimization.

Maybe we could also change the format closer to the "old" one:
```
note: optimization remark for tailcallelim at /checkout/src/libcore/num/mod.rs:1:0: marked this call a tail call candidate
```

I wanted to programatically parse the remarks so that they could work e.g. with https://github.com/OfekShilon/optview2. However, now that I think about it, probably the proper solution is to tell rustc to output them to YAML and then use the YAML as input for the opt remark visualization tools. The flag for enabling this does not seem to work though (https://github.com/rust-lang/rust/issues/96705#issuecomment-1117632322).

Still I think that it's good to output the remark kind anyway, it's an important piece of information.

r? ```@tmiasko```
2023-05-06 23:32:02 +02:00
Flying-Toast
faa797e7e7 Emit while_true lint spanning the entire loop condition
The lint that suggests `loop {}` instead of `while true {}` has functionality to 'pierce' parenthesis
in cases like `while (true) {}`. In these cases, the emitted span only went to the hi of the `true`
itself, not spanning the entire loop condition.

Before:
```
warning: denote infinite loops with `loop { ... }`
 --> /tmp/foobar.rs:2:5
  |
2 |     while ((((((true)))))) {}
  |     ^^^^^^^^^^^^^^^^ help: use `loop`
  |
  = note: `#[warn(while_true)]` on by default
```

After:
```
warning: denote infinite loops with `loop { ... }`
 --> /tmp/foobar.rs:2:5
  |
2 |     while ((((((true)))))) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
  |
  = note: `#[warn(while_true)]` on by default
```
2023-05-06 17:05:53 -04:00
bors
31a4f2da57 Auto merge of #110907 - Bryanskiy:privacy_ef, r=petrochenkov
Populate effective visibilities in 'rustc_privacy'

Next part of RFC https://github.com/rust-lang/rust/issues/48054.

r? `@petrochenkov`
2023-05-06 17:48:24 +00:00
Astroide
b2acf3ea64
rustc --explain E0726 - grammar fixing (it's => its + add a the where it felt right to do so) 2023-05-06 12:42:52 -04:00
bors
905d5a38d6 Auto merge of #111287 - matthiaskrgr:rollup-9lzax2c, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #110577 (Use fulfillment to check `Drop` impl compatibility)
 - #110610 (Add Terminator conversion from MIR to SMIR, part #1)
 - #110985 (Fix spans in LLVM-generated inline asm errors)
 - #110989 (Make the BUG_REPORT_URL configurable by tools )
 - #111167 (debuginfo: split method declaration and definition)
 - #111230 (add hint for =< as <=)
 - #111279 (More robust debug assertions for `Instance::resolve` on built-in traits with non-standard trait items)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-06 14:16:55 +00:00
clubby789
9027d208f2 Check arguments length in trivial diagnostic lint 2023-05-06 14:42:35 +01:00
Matthias Krüger
3cb1a4676a
Rollup merge of #111279 - compiler-errors:core-item-resolve, r=cjgillot
More robust debug assertions for `Instance::resolve` on built-in traits with non-standard trait items

In #111264, a user added a new item to the `Future` trait, but the code in [`resolve_associated_item`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ty_utils/instance/fn.resolve_associated_item.html) implicitly assumes that the `Future` trait is defined with only one method (`Future::poll`) and treats the generator body as the implementation of that method.

This PR adds some debug assertions to make sure that that new methods defined on `Future`/`Generator`/etc. don't accidentally resolve to the wrong item when they are added, and adds a helpful comment guiding a compiler dev (or curious `#![no_core]` user) to what must be done to support adding new associated items to these built-in implementations.

I am open to discuss whether a test should be added, but I chose against it because I opted to make these `bug!()`s instead of, e.g., diagnostics or fatal errors. Arguably it doesn't need a test because it's not a bug that can be triggered by an end user, and internal-facing misuses of core kind of touch on rust-lang/compiler-team#620 -- however, I think the assertions I added in this PR are still a very useful way to make sure this bug doesn't waste debugging resources down the line.

Fixes #111264
2023-05-06 13:30:06 +02:00
Matthias Krüger
83b29ec743
Rollup merge of #111230 - zacklukem:eq-less-to-less-eq, r=compiler-errors
add hint for =< as <=

Adds a compiler hint for when `=<` is typed instead of `<=`

Example hint:
```rust
fn foo() {
    if 1 =< 3 {
        println!("Hello, World!");
    }
}
```
```
error: expected type, found `3`
 --> main.rs:2:13
  |
2 |     if 1 =< 3 {
  |          -- ^ expected type
  |          |
  |          help: did you mean: `<=`
```

This PR only emits the suggestion if there is no space between the `=` and `<`.  This hopefully narrows the scope of when this error is emitted, however this still allows this error to be emitted in cases such as this:
```
error: expected expression, found `;`
 --> main.rs:2:18
  |
2 |     if 1 =< [i32;; 3]>::hello() {
  |          --      ^ expected expression
  |          |
  |          help: did you mean: `<=`
```

Which could be a good reason not to merge since I haven't been able to think of any other ways of narrowing the scope of this diagnostic.

closes #111128
2023-05-06 13:30:05 +02:00
Matthias Krüger
f440999bb2
Rollup merge of #111167 - cuviper:type-decl-disubprogram, r=michaelwoerister
debuginfo: split method declaration and definition

When we're adding a method to a type DIE, we only want a DW_AT_declaration
there, because LLVM LTO can't unify type definitions when a child DIE is a
full subprogram definition. Now the subprogram definition gets added at the
CU level with a specification link back to the abstract declaration.

Both GCC and Clang write debuginfo this way for C++ class methods.

Fixes #109730.
Fixes #109934.
2023-05-06 13:30:05 +02:00
Matthias Krüger
8ec84dd523
Rollup merge of #110989 - jyn514:bug-report-url, r=WaffleLapkin
Make the BUG_REPORT_URL configurable by tools

This greatly simplifies how hard it is to set a custom bug report url; previously tools had to copy
the entire hook implementation.

I haven't changed clippy in case they want to make the change upstream instead of the subtree, but
I'm happy to do so here if the maintainers want - cc ````@rust-lang/clippy````

Fixes https://github.com/rust-lang/rust/issues/109486.
2023-05-06 13:30:04 +02:00
Matthias Krüger
8172ada984
Rollup merge of #110985 - Amanieu:normalize_asm_spans, r=b-naber
Fix spans in LLVM-generated inline asm errors

Previously, incorrect spans were reported if inline assembly contained CRLF (Windows) line endings.

Fixes #110885
2023-05-06 13:30:04 +02:00
Matthias Krüger
77004eafea
Rollup merge of #110610 - spastorino:smir-terminator, r=oli-obk
Add Terminator conversion from MIR to SMIR, part #1

This adds internal MIR TerminatorKind to SMIR Terminator conversion.

r? ```@oli-obk```
2023-05-06 13:30:03 +02:00
Matthias Krüger
bcc9aa01b5
Rollup merge of #110577 - compiler-errors:drop-impl-fulfill, r=lcnr
Use fulfillment to check `Drop` impl compatibility

Use an `ObligationCtxt` to ensure that a `Drop` impl does not have stricter requirements than the ADT that it's implemented for, rather than using a `SimpleEqRelation` to (more or less) syntactically equate predicates on an ADT with predicates on an impl.

r? types

### Some background

The old code reads:

```rust
// An earlier version of this code attempted to do this checking
// via the traits::fulfill machinery. However, it ran into trouble
// since the fulfill machinery merely turns outlives-predicates
// 'a:'b and T:'b into region inference constraints. It is simpler
// just to look for all the predicates directly.
```

I'm not sure what this means, but perhaps in the 8 years since that this comment was written (cc #23638) it's gotten easier to process region constraints after doing fulfillment? I don't know how this logic differs from anything we do in the `compare_impl_item` module. Ironically, later on it says:

```rust
// However, it may be more efficient in the future to batch
// the analysis together via the fulfill (see comment above regarding
// the usage of the fulfill machinery), rather than the
// repeated `.iter().any(..)` calls.
```

Also:
* Removes `SimpleEqRelation` which was far too syntactical in its relation.
* Fixes #110557
2023-05-06 13:30:03 +02:00
bors
333b920fee Auto merge of #109421 - mhammerly:extern-force-option, r=petrochenkov
Add `force` option for `--extern` flag

When `--extern force:foo=libfoo.so` is passed to `rustc` and `foo` is not actually used in the crate, ~inject an `extern crate foo;` statement into the AST~ force it to be resolved anyway in `CrateLoader::postprocess()`. This allows you to, for instance, inject a `#[panic_handler]` implementation into a `#![no_std]` crate without modifying its source so that it can be built as a `dylib`. It may also be useful for `#![panic_runtime]` or `#[global_allocator]`/`#![default_lib_allocator]` implementations.

My work previously involved integrating Rust into an existing C/C++ codebase which was built with Buck and shipped on, among other platforms, Android. When targeting Android, Buck builds all "native" code with shared linkage* so it can be loaded from Java/Kotlin. My project was not itself `#![no_std]`, but many of our dependencies were, and they would fail to build with shared linkage due to a lack of a panic handler. With this change, that project can add the new `force` option to the `std` dependency it already explicitly provides to every crate to solve this problem.

*This is an oversimplification - Buck has a couple features for aggregating dependencies into larger shared libraries, but none that I think sustainably solve this problem.

~The AST injection happens after macro expansion around where we similarly inject a test harness and proc-macro harness. The resolver's list of actually-used extern flags is populated during macro expansion, and if any of our `--extern` arguments have the `force` option and weren't already used, we inject an `extern crate` statement for them. The injection logic was added in `rustc_builtin_macros` as that's where similar injections for tests, proc-macros, and std/core already live.~

(New contributor - grateful for feedback and guidance!)
2023-05-06 11:24:37 +00:00
Amanieu d'Antras
bba2a1e071 Fix spans in LLVM-generated inline asm errors
Previously, incorrect spans were reported if inline assembly contained
CRLF (Windows) line endings.

Fixes #110885
2023-05-06 09:31:57 +01:00
bors
151a070afe Auto merge of #104872 - luqmana:packed-union-align, r=oli-obk
Avoid alignment mismatch between ABI and layout for unions.

Fixes #104802
Fixes #103634

r? `@eddyb` cc `@RalfJung`
2023-05-06 07:25:50 +00:00
Michael Goulet
2a1ef34223 More robust debug assertions for Instance::resolve on built-in traits with custom items 2023-05-06 05:58:04 +00:00
Josh Stone
67ae38a336 Expand the LLVM coverage of --print target-cpus
We've been relying on a custom patch to add `MCSubtargetInfo::getCPUTable`
for `rustc --print target-cpus`, and just printing that it's not supported
on external LLVM builds. LLVM `main` now has `getAllProcessorDescriptions`
that can replace ours, so now we try to use that. In addition, the fallback
path can at least print the native and default cpu options.

There were also some mismatches in the function signatures here between
`LLVM_RUSTLLVM` and otherwise; this is now mitigated by sharing these
functions and only using cpp to adjust the function bodies.
2023-05-05 17:27:59 -07:00
Yuki Okushi
393e285e14
Rollup merge of #111261 - compiler-errors:error-guaranteed-should-be-scarier-to-construct, r=BoxyUwU
Mark `ErrorGuaranteed` constructor as deprecated so people don't use it

You should never ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever use this function unless you know what you're doing, so make it harder to accidentally use it!

Alternatives are to change the name to sound scarier, make it `unsafe` (though it's not really a soundness thing), or work on deeper refactors to make it private.

r? `@BoxyUwU`
2023-05-06 09:09:34 +09:00
Yuki Okushi
ce71f570f4
Rollup merge of #111246 - lcnr:no-escaping-bound-vars, r=compiler-errors
forbid escaping bound vars in combine

removes the `CollectAllMismatches` in favor of a slightly more manual approach.

r? types cc ``@estebank``
2023-05-06 09:09:33 +09:00
Yuki Okushi
bc4a1198fc
Rollup merge of #111239 - TaKO8Ki:fix-111232, r=compiler-errors
Remove unnecessary attribute from a diagnostic

Fixes #111232

ref: 06ff310cf9
2023-05-06 09:09:33 +09:00
Yuki Okushi
923a5a2ca7
Rollup merge of #109677 - dpaoliello:rawdylib, r=michaelwoerister,wesleywiser
Stabilize raw-dylib, link_ordinal, import_name_type and -Cdlltool

This stabilizes the `raw-dylib` feature (#58713) for all architectures (i.e., `x86` as it is already stable for all other architectures).

Changes:
* Permit the use of the `raw-dylib` link kind for x86, the `link_ordinal` attribute and the `import_name_type` key for the `link` attribute.
* Mark the `raw_dylib` feature as stable.
* Stabilized the `-Zdlltool` argument as `-Cdlltool`.
* Note the path to `dlltool` if invoking it failed (we don't need to do this if `dlltool` returns an error since it prints its path in the error message).
* Adds tests for `-Cdlltool`.
* Adds tests for being unable to find the dlltool executable, and dlltool failing.
* Fixes a bug where we were checking the exit code of dlltool to see if it failed, but dlltool always returns 0 (indicating success), so instead we need to check if anything was written to `stderr`.

NOTE: As previously noted (https://github.com/rust-lang/rust/pull/104218#issuecomment-1315895618) using dlltool within rustc is temporary, but this is not the first time that Rust has added a temporary tool use and argument: https://github.com/rust-lang/rust/pull/104218#issuecomment-1318720482

Big thanks to ``````@tbu-`````` for the first version of this PR (#104218)
2023-05-06 09:09:30 +09:00
Luqman Aden
8e7714d3bb Reorder to keep duplicate checks in sync. 2023-05-05 16:30:32 -07:00
Luqman Aden
012f9a333b Review feedback 2023-05-05 16:14:36 -07:00
Luqman Aden
c63a204e23 Don't discard preferred alignment in scalar pair. 2023-05-05 16:11:08 -07:00
Luqman Aden
3b1e535f36 Factor out checks in layout check and add helper inherent_size. 2023-05-05 16:11:03 -07:00
Luqman Aden
4f4f22b11c Incorporate review feedback from 103926. 2023-05-05 16:04:59 -07:00
Luqman Aden
a3800535b1 Add helper methods inherent_align and to_union on Abi. 2023-05-05 16:00:19 -07:00
Oli Scherer
23d09aebc8 Do not use scalar layout if there are ZSTs with alignment > 1 2023-05-05 16:00:12 -07:00
Luqman Aden
c7c042ad31 Address review comments.
Remove bitcasts in OperandRef::extract_field; only pointercasts should
be needed.
2023-05-05 15:13:18 -07:00
Luqman Aden
6a5ee11027 Don't bitcast aggregate field. 2023-05-05 14:25:56 -07:00
Luqman Aden
48af94c080 Operand::extract_field: only cast llval if it's a pointer and replace bitcast w/ pointercast. 2023-05-05 14:25:55 -07:00
Matt Hammerly
812f2d75e1 add "force" option to --extern 2023-05-05 13:02:43 -07:00
Michael Goulet
6077fdd219 Mark ErrorGuaranteed constructor as deprecated so people don't use it 2023-05-05 17:58:46 +00:00
Zachary Mayhew
a183ac6f90
add hint for =< as <= 2023-05-05 11:17:14 -04:00
Bryanskiy
cff85f22f5 Populate effective visibilities in rustc_privacy 2023-05-05 17:33:10 +03:00
Santiago Pastorino
698acc645e
Add GeneratorDrop terminator to SMIR 2023-05-05 10:34:55 -03:00
Santiago Pastorino
4b85bea4ae
Add Assert terminator to SMIR 2023-05-05 10:34:52 -03:00
Dylan DPC
ded0a9e15f
Rollup merge of #111068 - Urgau:check-cfg-improvements, r=petrochenkov
Improve check-cfg implementation

This PR makes multiple improvements into the implementation of check-cfg, it is a prerequisite to a follow-up PR that will introduce a simpler and more explicit syntax.

The 2 main area of improvements are:
 1. Internal representation of expected values:
    - now uses `FxHashSet<Option<Symbol>>` instead of `FxHashSet<Symbol>`, it made the no value expected case only possible when no values where in the `HashSet` which is now represented as `None` (same as cfg represent-it).
    - a enum with `Some` and `Any` makes it now clear if some values are expected or not, necessary for `feature` and `target_feature`.
 2. Diagnostics: Improve the diagnostics in multiple case and fix case where a missing value could have had a new name suggestion instead of the value diagnostic; and some drive by improvements

I highly recommend reviewing commit by commit.

r? `@petrochenkov`
2023-05-05 18:40:35 +05:30
Dylan DPC
65702bfd6b
Rollup merge of #110876 - mj10021:issue-110647-fix, r=b-naber
Added default target cpu to `--print target-cpus` output and updated docs

Added default target cpu info as requested in issue #110647 and noted the new output in the documentation
2023-05-05 18:40:35 +05:30