Commit Graph

15531 Commits

Author SHA1 Message Date
Preston From
d0ea440dfe Improve position named arguments lint underline and formatting names
For named arguments used as implicit position arguments, underline both
the opening curly brace and either:
* if there is formatting, the next character (which will either be the
  closing curl brace or the `:` denoting the start of formatting args)
* if there is no formatting, the entire arg span (important if there is
  whitespace like `{  }`)

This should make it more obvious where the named argument should be.

Additionally, in the lint message, emit the formatting argument names
without a dollar sign to avoid potentially confusion.

Fixes #99907
2022-08-02 00:20:44 -06:00
bors
21de280ccc Auto merge of #95884 - cjgillot:assoc-item, r=lcnr
Thin `AssocItem`

This PR removes a few fields from `AssocItem` that should be easily computed using other queries.
This simplifies some of the metadata decoding.
2022-08-01 21:43:35 +00:00
Camille GILLOT
212a06ee69 Match on TraitItem exhaustively. 2022-08-01 21:39:59 +02:00
Camille GILLOT
957548183d Remove trait_of_item query. 2022-08-01 21:39:26 +02:00
Camille GILLOT
d7ea161b7e Remove DefId from AssocItemContainer. 2022-08-01 21:38:45 +02:00
Camille GILLOT
8ee4446ee5 Remove visibility from AssocItem. 2022-08-01 21:38:20 +02:00
Camille GILLOT
110f0656cb Store associated item defaultness in impl_defaultness. 2022-08-01 21:38:16 +02:00
bors
fe3342816a Auto merge of #99476 - dpaoliello:rawdylibvectorcall, r=michaelwoerister
Add tests for raw-dylib with vectorcall, and fix vectorcall code generation

* Adds tests for using `raw-dylib` (#58713) with `vectorcall`.
* Fixed code generation for `vectorcall` (parameters have to be marked with `InReg`, just like `fastcall`).
* Enabled running the `raw-dylib` `fastcall` tests when using MSVC (since I had to add support in the test for running MSVC-only tests since GCC doesn't support `vectorcall`).
2022-08-01 18:43:57 +00:00
bors
c9e134e1b6 Auto merge of #100024 - matthiaskrgr:rollup-36ab4wx, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #99340 (Fix ICE in Definitions::create_def)
 - #99629 (Improve `cannot move out of` error message)
 - #99864 (bootstrap: don't emit warn about duplicated deps with same/different features if some of sets actually empty)
 - #99911 (Remove some uses of `guess_head_span`)
 - #99976 (Make Rustdoc exit with correct error code when scraping examples from invalid files)
 - #100003 (Improve size assertions.)
 - #100012 (Avoid `Ty` to `String` conversions)
 - #100020 (better error when python is not found in x - issue #99648)

Failed merges:

 - #99994 (Replace `guess_head_span` with `opt_span`)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-01 15:40:43 +00:00
Matthias Krüger
4606830f83
Rollup merge of #100012 - TaKO8Ki:avoid-ty-to-string-conversions, r=fee1-dead
Avoid `Ty` to `String` conversions

follow-up to #98668
2022-08-01 16:49:34 +02:00
Matthias Krüger
e6bb00fff5
Rollup merge of #100003 - nnethercote:improve-size-assertions, r=lqd
Improve size assertions.

- For any file with four or more size assertions, move them into a
  separate module (as is already done for `hir.rs`).
- Add some more for AST nodes and THIR nodes.
- Put the `hir.rs` ones in alphabetical order.

r? `@lqd`
2022-08-01 16:49:33 +02:00
Matthias Krüger
8db3d7cfb6
Rollup merge of #99911 - cjgillot:no-guess, r=davidtwco
Remove some uses of `guess_head_span`

That function cuts a span at the first occurrence of `{`.  Using `def_span` is almost always more precise.
2022-08-01 16:49:31 +02:00
Matthias Krüger
f9aa989eac
Rollup merge of #99629 - obeis:issue-99470, r=compiler-errors
Improve `cannot move out of` error message

Closes #99470
r? `@bjorn3`
2022-08-01 16:49:28 +02:00
Matthias Krüger
58042bffac
Rollup merge of #99340 - GoldsteinE:fix-localdefid-debug-ice, r=lcnr
Fix ICE in Definitions::create_def

`Debug` implementation for `LocalDefId` uses global `Definitions`. Normally it’s ok, but we can’t do it while holding a mutable reference to `Definitions`, since it causes ICE or deadlock (depending on whether `parallel_compiler` is enabled).

This PR effectively copies the `Debug` implementation into the problematic method. I don’t particularly love this solution (since it creates code duplication), but I don’t see any other options.

This issue was discovered when running `rustdoc` with `RUSTDOC_LOG=trace` on the following file:
```rust
pub struct SomeStruct;

fn asdf() {
    impl SomeStruct {
        pub fn qwop(&self) {
            println!("hidden function");
        }
    }
}
```

I’m not sure how to create a test for this behavior.
2022-08-01 16:49:27 +02:00
Goldstein
d9f28b7b70
fix ICE in Definitions::create_def 2022-08-01 16:15:55 +03:00
bors
dcb444af0a Auto merge of #99884 - nnethercote:lexer-improvements, r=matklad
Lexer improvements

Some cleanups and small speed improvements.

r? `@matklad`
2022-08-01 12:52:49 +00:00
bors
25bb1c13bd Auto merge of #99944 - bjorn3:hide_proc_macro_symbols, r=eddyb
Limit symbols exported from proc macros

Only `__rustc_proc_macro_decls_*__` and `rust_metadata_*` need to be
exported for proc macros to work. All other symbols only increase binary
size and have the potential to conflict with symbols from the host
compiler.

Fixes https://github.com/rust-lang/rust/issues/99909
Fixes #59998

cc `@eddyb`
2022-08-01 03:58:52 +00:00
Takayuki Maeda
92b31ccb73 avoid Ty to String conversions 2022-08-01 12:52:30 +09:00
bors
6423ab3a75 Auto merge of #99998 - matthiaskrgr:rollup-igafy0r, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #99519 (Remove implicit names and values from `--cfg` in `--check-cfg`)
 - #99620 (`-Z location-detail`: provide option to disable all location details)
 - #99932 (Fix unwinding on certain platforms when debug assertions are enabled)
 - #99973 (Layout things)
 - #99980 (Remove more Clean trait implementations)
 - #99984 (Fix compat.rs for `cfg(miri)`)
 - #99986 (Add wrap suggestions for record variants)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-01 01:11:08 +00:00
Nicholas Nethercote
9037ebba0c Improve size assertions.
- For any file with four or more size assertions, move them into a
  separate module (as is already done for `hir.rs`).
- Add some more for AST nodes and THIR nodes.
- Put the `hir.rs` ones in alphabetical order.
2022-08-01 09:15:05 +10:00
Nicholas Nethercote
99f5c79d64 Shrink Token.
From 72 bytes to 12 bytes (on x86-64).

There are two parts to this:
- Changing various source code offsets from 64-bit to 32-bit. This is
  not a problem because the rest of rustc also uses 32-bit source code
  offsets. This means `Token` is no longer `Copy` but this causes no
  problems.
- Removing the `RawStrError` from `LiteralKind`. Raw string literal
  invalidity is now indicated by a `None` value within
  `RawStr`/`RawByteStr`, and the new `validate_raw_str` function can be
  used to re-lex an invalid raw string literal to get the `RawStrError`.

There is one very small change in behaviour. Previously, if a raw string
literal matched both the `InvalidStarter` and `TooManyHashes` cases,
the latter would override the former. This has now changed, because
`raw_double_quoted_string` now uses `?` and so returns immediately upon
detecting the `InvalidStarter` case. I think this is a slight
improvement to report the earlier-detected error, and it explains the
change in the `test_too_many_hashes` test.

The commit also removes a couple of comments that refer to #77629 and
say that the size of these types don't affect performance. These
comments are wrong, though the performance effect is small.
2022-08-01 08:53:04 +10:00
Nicholas Nethercote
e6b9fccfb1 Add a size assertion for Token. 2022-08-01 08:27:43 +10:00
Nicholas Nethercote
ddf62b5bd4 Inline TokenStreamBuilder::push.
Because it's small and hot.
2022-08-01 08:27:41 +10:00
Nicholas Nethercote
c01a36d5e4 Avoid an unnecessary return. 2022-08-01 08:25:56 +10:00
Nicholas Nethercote
b4fdf648ea Inline first_token.
Because it's tiny and hot.
2022-08-01 08:11:15 +10:00
Nicholas Nethercote
bd23d68b41 Remove StringReader::end_src_index.
It not needed, always being set to the end of the text.
2022-08-01 08:11:15 +10:00
Nicholas Nethercote
55185992d6 Improve shebang handling.
Avoid doing stuff until it's necessary.
2022-08-01 08:11:15 +10:00
bors
34805f3675 Auto merge of #99052 - tmiasko:bitset-clone-from, r=Mark-Simulacrum
Fix cloning from a BitSet with a different domain size

The previous implementation incorrectly assumed that the
number of words in a bit set is equal to the domain size.

The new implementation delegates to `Vec::clone_from` which
is specialized for `Copy` elements.

Fixes #99006.
2022-07-31 21:40:21 +00:00
Matthias Krüger
20a5e9fd7c
Rollup merge of #99986 - WaffleLapkin:record_struct_wrap_suggestion, r=compiler-errors
Add wrap suggestions for record variants

This PR adds a suggestions to wrap an expression in a record struct/variant when encountering mismatched types, similarly to a suggestion to wrap expression in a tuple struct that was added before.

An example:
```rust
struct B {
    f: u8,
}

enum E {
    A(u32),
    B { f: u8 },
}

fn main() {
    let _: B = 1;
    let _: E = 1;
}
```
```text
error[E0308]: mismatched types
  --> ./t.rs:11:16
   |
11 |     let _: B = 1;
   |            -   ^ expected struct `B`, found integer
   |            |
   |            expected due to this
   |
help: try wrapping the expression in `B`
   |
11 |     let _: B = B { f: 1 };
   |                ++++++   +

error[E0308]: mismatched types
  --> ./t.rs:12:16
   |
12 |     let _: E = 1;
   |            -   ^ expected enum `E`, found integer
   |            |
   |            expected due to this
   |
help: try wrapping the expression in a variant of `E`
   |
12 |     let _: E = E::A(1);
   |                +++++ +
12 |     let _: E = E::B { f: 1 };
   |                +++++++++   +
```

r? `@compiler-errors`
2022-07-31 23:39:44 +02:00
Matthias Krüger
549463f114
Rollup merge of #99973 - RalfJung:layout-things, r=eddyb
Layout things

These two commits are pretty independent, but didn't seem worth doing individual PRs for:
- Always check that size is a multiple of align, even without debug assertions
- Change Layout debug printing to put `variants` last, since it often huge and not usually the part we are most interested in

Cc `@eddyb`
2022-07-31 23:39:42 +02:00
Matthias Krüger
9cc06eb54d
Rollup merge of #99620 - hudson-ayers:fix-location-detail, r=davidtwco
`-Z location-detail`: provide option to disable all location details

As reported [here](https://github.com/rust-lang/rust/pull/89920#issuecomment-1190598924), when I first implemented the `-Z location-detail` flag there was a bug, where passing an empty list was not correctly supported, and instead rejected by the compiler. This PR fixes that such that passing an empty list results in no location details being tracked, as originally specified in https://github.com/rust-lang/rfcs/pull/2091 .

This PR also adds a test case to verify that this option continues to work as intended.
2022-07-31 23:39:40 +02:00
Matthias Krüger
e820ecdba1
Rollup merge of #99519 - Urgau:check-cfg-implicit, r=petrochenkov
Remove implicit names and values from `--cfg` in `--check-cfg`

This PR remove the implicit names and values from `--cfg` in `--check-cfg` because the behavior is quite surprising but also because it's really easy to inadvertently really on the implicitness and when the `--cfg` is not set anymore to have an unexpected warning from an unexpected condition that pass with the implicitness.

This change in behavior will also enable us to warn when an unexpected `--cfg` is passed, ex: the user wrote `--cfg=unstabl` instead of `--cfg=unstable`. The implementation of the warning will be done in a follow-up PR.

cc `@petrochenkov`
2022-07-31 23:39:38 +02:00
Obei Sideg
86dd457e6a Improve cannot move out of error message 2022-07-31 21:06:43 +03:00
Maybe Waffle
1c2ea78f29 Skip unstable fields when suggesting wrapping expression in structs 2022-07-31 19:12:53 +04:00
Maybe Waffle
260a840543 Refactor wrap suggestion code (just a bit) 2022-07-31 17:53:47 +04:00
Maybe Waffle
506c98f291 Suggest wrapping expressions in single-field record variants 2022-07-31 17:38:28 +04:00
Ralf Jung
abd80d904b reorder fields in Laout debug output 2022-07-31 08:23:27 -04:00
Dylan DPC
990bce4da0
Rollup merge of #99974 - TaKO8Ki:suggest-removing-semicolon-and-boxing-the-expressions, r=compiler-errors
Suggest removing a semicolon and boxing the expressions for if-else

`InferCtxt::suggest_remove_semi_or_return_binding` was not working well, so I fixed it and added a ui test.
2022-07-31 17:36:44 +05:30
Dylan DPC
1d010d4382
Rollup merge of #99844 - bjorn3:archive_builder_interface_refactor, r=nagisa
Introduce an ArchiveBuilderBuilder

This avoids monomorphizing all linker code for each codegen backend and will allow passing in extra information to the archive builder from the codegen backend. I'm going to use this in https://github.com/rust-lang/rust/pull/97485 to allow passing in the right function to extract symbols from object files to a generic archive builder to be used by cg_llvm, cg_clif and cg_gcc.
2022-07-31 17:36:42 +05:30
Dylan DPC
2c14bc3b55
Rollup merge of #99741 - compiler-errors:copy-impl-impl-generics, r=fee1-dead
Use `impl`'s generics when suggesting fix on bad `impl Copy`

See the UI test for a more complicated example, but we weren't correctly suggesting to add bounds given a manual `impl` whose generics didn't match the struct generics.

```rust
#[derive(Clone)]
struct Wrapper<T>(T);

impl<S> Copy for Wrapper<S> {}
```

Coincidentally this fix didn't cause any regressions for `derive(Copy)` impls, I think because those use the same spans in the impl generics as the struct generics, so the machinery still applies the same change.
2022-07-31 17:36:41 +05:30
Dylan DPC
403c1b3802
Rollup merge of #99186 - camsteffen:closure-localdefid, r=cjgillot
Use LocalDefId for closures more
2022-07-31 17:36:40 +05:30
bjorn3
b87f8a4d9c Add issue reference 2022-07-31 10:33:44 +00:00
Ralf Jung
98e52c2a27 check 'size multiple of align' for all layouts 2022-07-31 06:29:57 -04:00
Takayuki Maeda
03622552ec use appropriate HirID for finding else_span 2022-07-31 11:33:01 +09:00
bors
a2318651d4 Auto merge of #99959 - cuviper:niche-size, r=eddyb
Fix the size of niche enums with ZST alignment

For enums with an aligned ZST variant, like `[T; 0]`, the niche layout
was not computing a sufficient size to be consistent with alignment. Now
we pad that size up to the alignment, and also make sure to only use the
niche variant's ABI when the size and alignment still match.

Fixes #99836
r? `@eddyb`
2022-07-30 23:47:51 +00:00
Cameron Steffen
cf2433a74f Use LocalDefId for closures more 2022-07-30 15:59:17 -05:00
Matthias Krüger
b9ad36c387
Rollup merge of #99956 - est31:fix_llvm_wrapper_warning, r=cuviper
Also gate AllocatedPointer and AllocAlign definitions by LLVM_VERSION_GE

Fixes a warning:

```
warning: llvm-wrapper/RustWrapper.cpp:159:11: warning: enumeration values 'AllocatedPointer' and 'AllocAlign' not handled in switch [-Wswitch]
warning:   switch (Kind) {
warning:           ^
```

Which was fall out from 130a1df71e.

Fixes #99955
2022-07-30 22:51:02 +02:00
Matthias Krüger
686cb110a7
Rollup merge of #99890 - compiler-errors:issue-99828, r=lcnr
Do not allow bad projection term to leak into the type checker

Fixes #99828
2022-07-30 22:50:59 +02:00
Matthias Krüger
451349a634
Rollup merge of #99889 - compiler-errors:cleanup-ti, r=cjgillot
Remove `parent_pat` from `TopInfo`

We can get the parent pat from the hir map.
2022-07-30 22:50:58 +02:00
Josh Stone
4a1e4ea32a Fix the size of niche enums with ZST alignment
For enums with an aligned ZST variant, like `[T; 0]`, the niche layout
was not computing a sufficient size to be consistent with alignment. Now
we pad that size up to the alignment, and also make sure to only use the
niche variant's ABI when the size and alignment still match.
2022-07-30 10:45:48 -07:00