Commit graph

9206 commits

Author SHA1 Message Date
Mara Bos
09e4a75f29 Use span_suggestions instead of multipart_suggestions. 2021-11-16 19:53:00 +01:00
Mara Bos
b331b66082 Improve compatible enum variant suggestions. 2021-11-16 19:52:58 +01:00
Mara Bos
453e2423e6 Improve suggestion for unit Option/Result at the end of a block. 2021-11-16 19:52:58 +01:00
Mara Bos
483cff7ed3 Add SourceMap::indentation_before. 2021-11-16 19:52:58 +01:00
bors
d914f17ca7 Auto merge of #90919 - nnethercote:rm-DropArena, r=Mark-Simulacrum
Remove `DropArena`.

Most arena-allocate types that impl `Drop` get their own `TypedArena`, but a
few infrequently used ones share a `DropArena`. This sharing adds complexity
but doesn't help performance or memory usage. Perhaps it was more effective in
the past prior to some other improvements to arenas.

This commit removes `DropArena` and the sharing of arenas via the `few`
attribute of the `arena_types` macro. This change removes over 100 lines of
code and nine uses of `unsafe` (one of which affects the parallel compiler) and
makes the remaining code easier to read.
2021-11-16 11:48:37 +00:00
bors
934624fe5f Auto merge of #90945 - JohnTitor:rollup-wc35xss, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #86455 (check where-clause for explicit `Sized` before suggesting `?Sized`)
 - #90801 (Normalize both arguments of `equate_normalized_input_or_output`)
 - #90803 (Suggest `&str.chars()` on attempt to `&str.iter()`)
 - #90819 (Fixes incorrect handling of TraitRefs when emitting suggestions.)
 - #90910 (fix getting the discriminant of a zero-variant enum)
 - #90925 (rustc_mir_build: reorder bindings)
 - #90928 (Use a different server for checking clock drift)
 - #90936 (Add a regression test for #80772)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-16 08:22:55 +00:00
Yuki Okushi
cdc12ba5a3
Rollup merge of #90925 - krasimirgg:rustc_mir_build_fix, r=petrochenkov
rustc_mir_build: reorder bindings

No functional changes intended.

I'm playing around with building compiler components using nightly rust
(2021-11-02) in a non-standard way. I encountered the following error while
trying to build rustc_mir_build:

```
error[E0597]: `wildcard` does not live long enough
    --> rust/src/nightly/compiler/rustc_mir_build/src/build/matches/mod.rs:1767:82
     |
1767 |         let mut otherwise_candidate = Candidate::new(expr_place_builder.clone(), &wildcard, false);
     |                                                                                  ^^^^^^^^^ borrowed value does not live long enough
...
1799 |     }
     |     -
     |     |
     |     `wildcard` dropped here while still borrowed
     |     borrow might be used here, when `guard_candidate` is dropped and runs the destructor for type `Candidate<'_, '_>`
     |
     = note: values in a scope are dropped in the opposite order they are defined
```

I believe this flags an issue that may become an error in the future.
Swapping the order of `wildcard` and `guard_candidate` resolves it.
2021-11-16 15:59:42 +09:00
Yuki Okushi
6d9c3a1b97
Rollup merge of #90910 - RalfJung:const-discriminant-empty-enum, r=petrochenkov
fix getting the discriminant of a zero-variant enum

Fixes https://github.com/rust-lang/rust/issues/89765
2021-11-16 15:59:41 +09:00
Yuki Okushi
d44cec3453
Rollup merge of #90819 - JakobDegen:issue-90804, r=petrochenkov
Fixes incorrect handling of TraitRefs when emitting suggestions.

Closes #90804 , although there were more issues here that were hidden by the thing that caused this ICE.

Underlying problem was that substitutions were being thrown out, which not only leads to an ICE but also incorrect diagnostics. On top of that, in some cases the self types from the root obligations were being mixed in with those from derived obligations.

This makes a couple diagnostics arguable worse ("`B<C>` does not implement `Copy`" instead of "`C` does not implement `Copy`") but the worse diagnostics are at least still correct and that downside is in my opinion clearly outweighed by the benefits of fixing the ICE and unambiguously wrong diagnostics.
2021-11-16 15:59:40 +09:00
Yuki Okushi
b17de50a41
Rollup merge of #90803 - TaKO8Ki:suggest-chars-on-attempt-to-iter, r=estebank
Suggest `&str.chars()` on attempt to `&str.iter()`

closes #90786
2021-11-16 15:59:39 +09:00
Yuki Okushi
21bff4a4c1
Rollup merge of #90801 - b-naber:missing_normalization_equate_inputs_output, r=jackh726
Normalize both arguments of `equate_normalized_input_or_output`

Fixes https://github.com/rust-lang/rust/issues/90638
Fixes https://github.com/rust-lang/rust/issues/90612

Temporary fix for a more complex underlying problem stemming from an inability to normalize closure substs during typecheck.

r? ````@jackh726````
2021-11-16 15:59:39 +09:00
Yuki Okushi
ebef3ce25b
Rollup merge of #86455 - tlyu:check-where-before-suggesting-unsized, r=estebank
check where-clause for explicit `Sized` before suggesting `?Sized`

Fixes #85945.

Based on #86454.

``@rustbot`` label +A-diagnostics +A-traits +A-typesystem +D-papercut +T-compiler
2021-11-16 15:59:38 +09:00
bors
a2a7683e8f Auto merge of #90845 - JakobDegen:adt-drop-perf, r=Mark-Simulacrum
Address performance regression introduced by #90218

As part of the changes in #90218 , the `adt_drop_tys` and friends code stopped recursing through the query system, meaning that intermediate computations did not get cached. This change adds the recursions back in without re-introducing any of the old issues.

On local benchmarks this fixes the 5% regressions in #90504 ; the wg-grammar regressions didn't seem to move too much. I may take some time later to look into those.

Not sure who to request for review here, so will leave it up to whoever gets it.
2021-11-16 05:18:57 +00:00
Taylor Yu
1a50725a4d refactor is_param_bound 2021-11-15 22:31:56 -06:00
Taylor Yu
c9fcbda389 check where clause before suggesting unsized 2021-11-15 22:31:55 -06:00
bors
02063124f9 Auto merge of #90934 - JohnTitor:rollup-5soqo0j, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #85766 (Stabilize File::options())
 - #88601 (Implement `Termination` for `Result<Infallible, E>`)
 - #90058 (Stabilize -Z strip as -C strip)
 - #90790 (Fix standard library test with read_link)
 - #90834 (Android is not GNU)
 - #90835 (Rename WASI's `is_character_device` to `is_char_device`.)
 - #90837 (Move some tests to more reasonable directories - 9)
 - #90848 (Remove bigint_helper_methods for *signed* types)
 - #90892 (fix ICE on Miri/CTFE copy of half a pointer)
 - #90909 (disable portable SIMD tests in Miri)

Failed merges:

 - #90128 (Stabilize -Z symbol-mangling-version=v0 as -C symbol-mangling-version=v0)

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-16 02:23:42 +00:00
Yuki Okushi
fff9055afb
Rollup merge of #90892 - RalfJung:miri-partial-ptr-copy, r=oli-obk
fix ICE on Miri/CTFE copy of half a pointer

Fixes https://github.com/rust-lang/miri/issues/1910
r? `````@oli-obk`````
2021-11-16 09:14:22 +09:00
Yuki Okushi
ed7ed5fc90
Rollup merge of #90834 - cuviper:android-gnu, r=petrochenkov
Android is not GNU

For a long time, the Android targets had `target_env=""`, but this changed to `"gnu"` in Rust 1.49.0. I tracked this down to #77729 which started setting `"gnu"` in the `linux_base` target options, and this was inherited by `android_base`. Then #78929 split the env into `linux_gnu_base`, but `android_base` was also changed to follow that. Android was not specifically mentioned in either pull request, so I believe this was an accident. Moving it back to `linux_base` will use an empty `env` again.

r? ````@Mark-Simulacrum````
cc ````@petrochenkov````
2021-11-16 09:14:18 +09:00
Yuki Okushi
a0dc4abe98
Rollup merge of #90058 - joshtriplett:stabilize-strip, r=wesleywiser
Stabilize -Z strip as -C strip

Leave -Z strip available temporarily as an alias, to avoid breaking
cargo until cargo transitions to using -C strip.
2021-11-16 09:14:16 +09:00
bors
b053550847 Auto merge of #90827 - matthewjasper:assoc-item-cleanup-2, r=cjgillot
Assoc item cleanup Part 2

- Remove `AssocItem` from `RegionVariableOrigin::AutoRef`
- Use the `associated_item_def_ids` query instead of the `associated_items` query when possible

The change to `ObligationCauseCode` from #90639 is omitted because it caused a perf regression.

r? `@cjgillot`
2021-11-15 23:27:59 +00:00
bors
c26746af5a Auto merge of #90473 - joshtriplett:stabilize-format-args-capture, r=Mark-Simulacrum
stabilize format args capture

Works as expected, and there are widespread reports of success with it, as well as interest in it.

RFC: rust-lang/rfcs#2795
Tracking issue: https://github.com/rust-lang/rust/issues/67984

Addressing items from the tracking issue:

- We don't support capturing arguments from a non-literal format string like `format_args!(concat!(...))`. We could add that in a future enhancement, or we can decide that it isn't supported (as suggested in https://github.com/rust-lang/rust/issues/67984#issuecomment-801394736 ).
- I've updated the documentation.
- `panic!` now supports capture as well.
- There are potentially opportunities to further improve diagnostics for invalid usage, such as if it looks like the user tried to use an expression rather than a variable. However, such cases are all already caught and provide reasonable syntax errors now, and we can always provided even friendlier diagnostics in the future.
2021-11-15 16:10:19 +00:00
Krasimir Georgiev
c1c20138a9 rustc_mir_build: reorder bindings
No functional changes intended.

I'm playing around with building compiler components using nightly rust
(2021-11-02) in a non-standard way. I encountered the following error while
trying to build rustc_mir_build:

```
error[E0597]: `wildcard` does not live long enough
    --> rust/src/nightly/compiler/rustc_mir_build/src/build/matches/mod.rs:1767:82
     |
1767 |         let mut otherwise_candidate = Candidate::new(expr_place_builder.clone(), &wildcard, false);
     |                                                                                  ^^^^^^^^^ borrowed value does not live long enough
...
1799 |     }
     |     -
     |     |
     |     `wildcard` dropped here while still borrowed
     |     borrow might be used here, when `guard_candidate` is dropped and runs the destructor for type `Candidate<'_, '_>`
     |
     = note: values in a scope are dropped in the opposite order they are defined
```

I believe this flags an issue that may become an error in the future.
Swapping the order of `wildcard` and `guard_candidate` resolves it.
2021-11-15 16:23:02 +01:00
bors
eab2d7519a Auto merge of #90717 - kit-981:fix-ld64-flags, r=petrochenkov
Fix ld64 flags

- The `-exported_symbols_list` argument appears to be malformed for `ld64` (if you are not going through `clang`).
- The `-dynamiclib` argument isn't support for `ld64`. It should be guarded behind a compiler flag.

These problems are fixed by these changes. I have also refactored the way linker arguments are generated to be ld/compiler agnostic and therefore less error prone.

These changes are necessary to support cross-compilation to darwin targets.
2021-11-15 11:18:44 +00:00
Josh Triplett
e35b7bbdf8 Stabilize -Z strip as -C strip
Leave -Z strip available temporarily as an alias, to avoid breaking
cargo until cargo transitions to using -C strip. (If the user passes
both, the -C version wins.)
2021-11-15 10:21:02 +01:00
Josh Triplett
c4884bbec7 Support having -Z and -C options with the same name
Tweak the `options!` macro to allow for -Z and -C options with the same
name without generating conflicting internal parsing functions.

Split out of the commit stabilizing -Z strip as -C strip.
2021-11-15 10:18:30 +01:00
Josh Triplett
8c9bfaa5f3 Stabilize format_args_capture
Works as expected, and there are widespread reports of success with it,
as well as interest in it.
2021-11-15 10:14:29 +01:00
Nicholas Nethercote
fb80c73fb3 Remove DropArena.
Most arena-allocate types that impl `Drop` get their own `TypedArena`, but a
few infrequently used ones share a `DropArena`. This sharing adds complexity
but doesn't help performance or memory usage. Perhaps it was more effective in
the past prior to some other improvements to arenas.

This commit removes `DropArena` and the sharing of arenas via the `few`
attribute of the `arena_types` macro. This change removes over 100 lines of
code and nine uses of `unsafe` (one of which affects the parallel compiler) and
makes the remaining code easier to read.
2021-11-15 18:33:43 +11:00
bors
d5a0c7cb03 Auto merge of #90645 - terrarier2111:master, r=estebank
Implement diagnostic for String conversion

This is my first real contribution to rustc, any feedback is highly appreciated.
This should fix https://github.com/rust-lang/rust/issues/89856

Thanks to `@estebank` for guiding me.
2021-11-15 06:55:01 +00:00
Takayuki Maeda
d562f487c9 suggest &str.chars() on attempt to &str.iter()
check if `String` or `&String` or `&str`

Update compiler/rustc_typeck/src/check/method/suggest.rs

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>

remove some trailing whitespace
2021-11-15 12:37:01 +09:00
Ralf Jung
eebf676bf8 fix getting the discriminant of a zero-variant enum 2021-11-14 13:29:21 -05:00
bors
3b2c45441d Auto merge of #90839 - pierwill:docs-rustc-newtype-index, r=jackh726
Generate documentation in rustc `rustc_index::newtype_index` macro

The macro now documents all generated items. Documentation notes possible panics and unsafety.
2021-11-14 12:17:32 +00:00
kit
f44fa6348f Only use the -dynamiclib flag when the linker is not ld
This is not a valid flag for ld64. When the ld64 linker is explicitly
provided through `config.toml`, rustc will not successfully compile.
2021-11-14 18:49:18 +11:00
kit
32ddd0206c Refactor linker argument generation
This commit refactors linker argument generation to leverage a helper
function that abstracts away details governing how these arguments are
transformed and provided to the linker.

This fixes the misuse of the `-exported_symbols_list` when an ld-like
linker is used rather than a compiler. A compiler would expect
`-Wl,-exported_symbols_list,path` but ld would expect
`-exported_symbols_list` and `path` as two seperate arguments. Prior
to this change, an ld-like linker was given
`-exported_symbols_list,path`.
2021-11-14 18:49:17 +11:00
kit
9bbc9cb597 Add a helper method for linker arguments
Linker arguments must transformed when Rust is interacting with the
linker through a compiler. This commit introduces a helper function
that abstracts away details of this transformation.
2021-11-14 18:49:15 +11:00
Ralf Jung
94ca0b392d fix ICE on Miri/CTFE copy of half a pointer 2021-11-13 20:56:01 -05:00
pierwill
845c25d1b4 Generate documentation in rustc rustc_index::newtype_index macro
The macro now documents all generated items. Documentation notes
possible panics and unsafety.
2021-11-13 18:50:29 -06:00
Matthias Krüger
e273fab434
Rollup merge of #90840 - BoxyUwU:lolripme, r=jackh726
relate lifetime in `TypeOutlives` bounds on drop impls

Fixes #90838
2021-11-13 22:35:04 +01:00
Matthias Krüger
b35af0d04d
Rollup merge of #90771 - asterycs:fix/trait-object-error-code, r=michaelwoerister
Fix trait object error code

closes #90768

I `grep`:d and changed the occurrences that seemed relevant. Please let me know what you think and if anything is missing!
2021-11-13 22:35:03 +01:00
Jakob Degen
d58d52a397 Fix handling of substitutions and binders when deciding whether to suggest references
When suggesting references, substitutions were being forgotten and some types were misused. This led to at
least one ICE and other incorrectly emitted diagnostics. This has been fixed; in some cases this leads to
diagnostics changing, and tests have been adjusted.
2021-11-13 16:28:41 -05:00
Jakob Degen
746091c610 Recurse through query system when checking ADT drop types, hopefully improving perf 2021-11-13 14:47:17 -05:00
bors
d212d902ae Auto merge of #89551 - jhpratt:stabilize-const_raw_ptr_deref, r=oli-obk
Stabilize `const_raw_ptr_deref` for `*const T`

This stabilizes dereferencing immutable raw pointers in const contexts.
It does not stabilize `*mut T` dereferencing. This is behind the
same feature gate as mutable references.

closes https://github.com/rust-lang/rust/issues/51911
2021-11-13 17:10:15 +00:00
threadexception
829a5288ec Implement diagnostic for String conversion
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2021-11-13 15:17:44 +01:00
bors
3e018ce194 Auto merge of #87264 - mystor:expand_literal, r=petrochenkov
proc_macro: Add an expand_expr method to TokenStream

This feature is aimed at giving proc macros access to powers similar to those used by builtin macros such as `format_args!` or `concat!`. These macros are able to accept macros in place of string literal parameters, such as the format string, as they perform recursive macro expansion while being expanded.

This can be especially useful in many cases thanks to helper macros like `concat!`, `stringify!` and `include_str!` which are often used to construct string literals at compile-time in user code.

For now, this method only allows expanding macros which produce literals, although more expressions will be supported before the method is stabilized.

In earlier versions of this PR, this method exclusively returned `Literal`, and spans on returned literals were stripped of expansion context before being returned to be as conservative as possible about permission leakage. The method's naming has been generalized to eventually support arbitrary expressions, and the context stripping has been removed (https://github.com/rust-lang/rust/pull/87264#discussion_r674863279), which should allow for more general APIs like "format_args_implicits" (https://github.com/rust-lang/rust/issues/67984) to be supported as well.

## API Surface

```rust
impl TokenStream {
    pub fn expand_expr(&self) -> Result<TokenStream, ExpandError>;
}

#[non_exhaustive]
pub struct ExpandError;

impl Debug for ExpandError { ... }
impl Display for ExpandError { ... }
impl Error for ExpandError {}
impl !Send for ExpandError {}
impl !Sync for ExpandError {}
```
2021-11-13 08:22:52 +00:00
Ellen
875024ca6b oops... 2021-11-12 20:50:25 +00:00
Nika Layzell
3e4d3d2a29 proc_macro: Add an expand_expr method to TokenStream
This feature is aimed at giving proc macros access to powers similar to
those used by builtin macros such as `format_args!` or `concat!`. These
macros are able to accept macros in place of string literal parameters,
such as the format string, as they perform recursive macro expansion
while being expanded.

This can be especially useful in many cases thanks to helper macros like
`concat!`, `stringify!` and `include_str!` which are often used to
construct string literals at compile-time in user code.

For now, this method only allows expanding macros which produce
literals, although more expresisons will be supported before the method
is stabilized.
2021-11-12 15:41:40 -05:00
bors
e90c5fbbc5 Auto merge of #90836 - matthiaskrgr:rollup-ou6yrlw, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #90589 (rustc_llvm: update PassWrapper for recent LLVM)
 - #90644 (Extend the const swap feature)
 - #90704 (Unix ExitStatus comments and a tiny docs fix)
 - #90761 (Shorten Span of unused macro lints)
 - #90795 (Add more comments to explain the code to generate the search index)
 - #90798 (Document `unreachable!` custom panic message)
 - #90826 (rustc_feature: Convert `BuiltinAttribute` from tuple to a struct)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-12 19:28:04 +00:00
Matthias Krüger
5e7c031397
Rollup merge of #90826 - petrochenkov:binattr, r=cjgillot
rustc_feature: Convert `BuiltinAttribute` from tuple to a struct

The tuple starts having too many fields.
Noticed while reviewing https://github.com/rust-lang/rust/pull/88681.
2021-11-12 19:17:34 +01:00
Matthias Krüger
640f365bff
Rollup merge of #90761 - hellow554:macro_span, r=estebank
Shorten Span of unused macro lints

The span has been reduced to the actual ident of the macro, instead of linting the
*whole* macro.

Closes #90745

r? ``@estebank``
2021-11-12 19:17:31 +01:00
Matthias Krüger
1fe15be34c
Rollup merge of #90589 - durin42:llvm-14-ASO-now-struct, r=nikic
rustc_llvm: update PassWrapper for recent LLVM

Now AddressSanitizerOptions is a struct, but at least the change was
tiny.

r? `@nikic`
2021-11-12 19:17:28 +01:00
Josh Stone
a24e2eddb1 Android is not GNU 2021-11-12 09:09:08 -08:00