Commit Graph

2035 Commits

Author SHA1 Message Date
Mara Bos
190c3ad64e Improve panic_fmt error messages for invalid format strings too. 2020-10-20 22:59:53 +02:00
Mara Bos
6b44662669 Parse the format string for the panic_fmt lint for better warnings. 2020-10-20 22:25:42 +02:00
Mara Bos
0f193d1a62 Small cleanups in assert!() and panic_fmt lint.
(From the PR feedback.)

Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
2020-10-19 21:14:05 +02:00
Mara Bos
d3b41497fe Also apply panic_fmt lint suggestions to debug_assert!(). 2020-10-19 00:45:07 +02:00
Mara Bos
9a840a30d6 Fix brace problem in panic message in rustc_expand. 2020-10-19 00:05:45 +02:00
Mara Bos
9615d27ab7 Don't see {{}} as placeholder in panic_fmt lint. 2020-10-19 00:05:19 +02:00
Mara Bos
b8a8b681b8 Formatting. 2020-10-18 23:25:57 +02:00
Mara Bos
ded269fa10 Improve panic_fmt message for panic!("{}") with a fmt placeholder. 2020-10-18 23:25:06 +02:00
Mara Bos
3beb2e95a9 Expand assert!(expr) to panic() function instead of panic!() macro.
The panic message might contain braces which should never be
interpreted as format placeholders, which panic!() will do in a future
edition.
2020-10-18 22:30:16 +02:00
Mara Bos
f228efc3f5 Make panic_fmt lint work properly for assert!(expr, msg) too. 2020-10-18 22:29:40 +02:00
Mara Bos
da66a501f6 Specialize panic_fmt lint for the {core,std}::panic!() macros.
It now only reacts to expansion of those macros, and suggests
inserting `"{}", ` in the right place.
2020-10-18 22:26:36 +02:00
Mara Bos
5b3b80a710 Allow #[rustc_diagnostic_item] on macros. 2020-10-18 22:19:13 +02:00
Mara Bos
a46679098f Add lint to warn about braces in a panic message. 2020-10-18 22:24:15 +02:00
bors
675f114d95 Auto merge of #79106 - tmiasko:inline-hint, r=nagisa,eddyb
Fix setting inline hint based on `InstanceDef::requires_inline`

For instances where `InstanceDef::requires_inline` is true, an attempt
is made to set an inline hint though a call to the `inline` function.
The attempt is ineffective, since all attributes will be usually removed
by the second call.

Fix the issue by applying the attributes only once, with user provided
attributes having a priority when provided.

Closes #79108.
2020-11-18 23:44:54 +00:00
bors
8256379832 Auto merge of #78995 - Nadrieril:clean-empty-match, r=varkor
Handle empty matches cleanly in exhaustiveness checking

This removes the special-casing of empty matches that was done in `check_match`. This fixes most of https://github.com/rust-lang/rust/issues/55123.
Somewhat unrelatedly, I also made `_match.rs` more self-contained, because I think it's cleaner.

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-11-18 21:24:40 +00:00
Mara Bos
43d13e2d58
Rollup merge of #79158 - lcnr:lazy-norm-coerce, r=oli-obk
type is too big -> values of the type are too big

strictly speaking, `[u8; usize::MAX]` or even `[[[u128; usize::MAX]; usize::MAX]; usize::MAX]` are absolutely fine types as long as you don't try to deal with any values of it.

This error message seems to cause some confusion imo, for example in https://github.com/rust-lang/rust/pull/79135#issuecomment-729361380 so I would prefer us to be more precise here.

See the added test case which uses one of these types without causing an error.

r? ``@oli-obk``
2020-11-18 15:46:40 +01:00
Mara Bos
f85c3f72a4
Rollup merge of #79079 - camelid:mir-visit-docs, r=matthewjasper
Turn top-level comments into module docs in MIR visitor
2020-11-18 15:46:29 +01:00
Mara Bos
92dcf6d733
Rollup merge of #78999 - petrochenkov:deprid, r=eddyb
stability: More precise location for deprecation lint on macros

One missing piece of https://github.com/rust-lang/rust/pull/73178.
2020-11-18 15:46:25 +01:00
Mara Bos
c7e9029b80
Rollup merge of #78361 - DevJPM:master, r=workingjubilee
Updated the list of white-listed target features for x86

This PR both adds in-source documentation on what to look out for when adding a new (X86) feature set and [adds all that are detectable at run-time in Rust stable as of 1.27.0](https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/src/detect/arch/x86.rs).

This should only enable the use of the corresponding LLVM intrinsics.
Actual intrinsics need to be added separately in rust-lang/stdarch.

It also re-orders the run-time-detect test statements to be more consistent
with the actual list of intrinsics whitelisted and removes underscores not present
in the actual names (which might be mistaken as being part of the name)

The reference for LLVM's feature names used is [this file](https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/Support/X86TargetParser.def).

This PR was motivated as the compiler end's part for allowing #67329 to be adressed over on rust-lang/stdarch
2020-11-18 15:46:19 +01:00
Bastian Kauschke
88584d5800 change error for LayoutErr::SizeOverflow 2020-11-18 11:38:30 +01:00
Joshua Nelson
c9a17b1d3f Fix broken handling of MacroDef in Map::attrs
This also uses an exhaustive match to avoid future similar bugs.
2020-11-17 15:13:25 -05:00
Mara Bos
b6f52410bb
Rollup merge of #79072 - oli-obk:byte_str_pat, r=estebank
Fix exhaustiveness in case a byte string literal is used at slice type

fixes #79048
2020-11-17 16:13:53 +01:00
Mara Bos
fa45fce0d3
Rollup merge of #78702 - wesleywiser:self_profile_cgu_sizes, r=Mark-Simulacrum
[self-profiling] Include the estimated size of each cgu in the profile

This is helpful when looking for CGUs where the size estimate isn't a
good indicator of compilation time.

I verified that moving the profiling timer call doesn't affect the
results.

Results:

<img width="297" alt="Screen Shot 2020-11-03 at 7 25 04 AM" src="https://user-images.githubusercontent.com/831192/97985503-5901d100-1da6-11eb-9f10-f3e399702952.png">

`measureme` doesn't have support for custom arg names yet so `arg0` is the CGU name and `arg1` is the estimated size.
2020-11-17 16:13:49 +01:00
Mara Bos
81f9feba97
Rollup merge of #74293 - GuillaumeGomez:rustdoc-test-compiler-output-color, r=jyn514
Rustdoc test compiler output color

Fixes #72915

We just need to be sure it doesn't break rustdoc doctests' compilation checks. Maybe some other unforeseen consequences too?

r? `@ehuss`
cc `@rust-lang/rustdoc`
2020-11-17 16:13:46 +01:00
bors
e0ef0fc392 Auto merge of #78779 - LeSeulArtichaut:ty-visitor-return, r=oli-obk
Introduce `TypeVisitor::BreakTy`

Implements MCP rust-lang/compiler-team#383.
r? `@ghost`
cc `@lcnr` `@oli-obk`

~~Blocked on FCP in rust-lang/compiler-team#383.~~
2020-11-17 12:24:34 +00:00
Guillaume Gomez
32d64edcf9 Simplfy color availability check 2020-11-17 10:33:14 +01:00
oli
a1cdf722f4 Fix exhaustiveness in case a byte string literal is used at slice type 2020-11-17 09:07:23 +00:00
Mara Bos
c459ab3a0f
Rollup merge of #79088 - euclio:span-label-doc, r=estebank
clarify `span_label` documentation

Fixes #71857.

r? ``@estebank``

cc ``@RalfJung``
2020-11-17 10:06:25 +01:00
Mara Bos
336dc18aa3
Rollup merge of #79027 - tmiasko:inline-always-live-locals, r=oli-obk
Limit storage duration of inlined always live locals

Closes #76375.
2020-11-17 10:06:21 +01:00
bors
b5c37e86ff Auto merge of #78801 - sexxi-goose:min_capture, r=nikomatsakis
RFC-2229: Implement Precise Capture Analysis

### This PR introduces
- Feature gate for RFC-2229 (incomplete) `capture_disjoint_field`
- Rustc Attribute to print out the capture analysis `rustc_capture_analysis`
- Precise capture analysis

### Description of the analysis
1. If the feature gate is not set then all variables that are not local to the closure will be added to the list of captures. (This is for backcompat)
2. The rest of the analysis is based entirely on how the captured `Place`s are used within the closure. Precise information (i.e. projections) about the `Place` is maintained throughout.
3. To reduce the amount of information we need to keep track of, we do a minimization step. In this step, we determine a list such that no Place within this list represents an ancestor path to another entry in the list.  Check rust-lang/project-rfc-2229#9 for more detailed examples.
4. To keep the compiler functional as before we implement a Bridge between the results of this new analysis to existing data structures used for closure captures. Note the new capture analysis results are only part of MaybeTypeckTables that is the information is only available during typeck-ing.

### Known issues
- Statements like `let _ = x` will make the compiler ICE when used within a closure with the feature enabled. More generally speaking the issue is caused by `let` statements that create no bindings and are init'ed using a Place expression.

### Testing
We removed the code that would handle the case where the feature gate is not set, to enable the feature as default and did a bors try and perf run. More information here: #78762

### Thanks
This has been slowly in the works for a while now.
I want to call out `@Azhng` `@ChrisPardy` `@null-sleep` `@jenniferwills` `@logmosier` `@roxelo` for working on this and the previous PRs that led up to this, `@nikomatsakis` for guiding us.

Closes rust-lang/project-rfc-2229#7
Closes rust-lang/project-rfc-2229#9
Closes rust-lang/project-rfc-2229#6
Closes rust-lang/project-rfc-2229#19

r? `@nikomatsakis`
2020-11-17 03:56:03 +00:00
bors
9b2b02a840 Auto merge of #78313 - lcnr:somebody-fold-me, r=nikomatsakis
TypeFoldable: take self by value

Implements https://github.com/rust-lang/compiler-team/issues/371 which is currently still in FCP.

r? `@nikomatsakis`
2020-11-17 01:14:54 +00:00
Tomasz Miąsko
4ea25da237 Fix setting inline hint based on InstanceDef::requires_inline
For instances where `InstanceDef::requires_inline` is true, an attempt
is made to set an inline hint though a call to the `inline` function.
The attempt is ineffective, since all attributes will be usually removed
by the second call.

Fix the issue by applying the attributes only once, with user provided
attributes having a priority when provided.
2020-11-17 00:00:00 +00:00
Andy Russell
a78966df83
clarify span_label documentation 2020-11-16 18:05:45 -05:00
Bastian Kauschke
7f45668af6 update cg_clif 2020-11-16 22:42:09 +01:00
lcnr
a6cbd64dae words 2020-11-16 22:42:09 +01:00
Bastian Kauschke
2bf93bd852 compiler: fold by value 2020-11-16 22:34:57 +01:00
Bastian Kauschke
3ec6720bf1 add IdFunctor to rustc_data_structures 2020-11-16 22:27:20 +01:00
Mara Bos
e6b6c8e4fc
Rollup merge of #79087 - ThePuzzlemaker:issue-79083-docfix, r=RalfJung
Update E0744 about control flow in `const` contexts to accurately describe when the error is triggered and why

This PR fixes #79083. `const fn` currently supports `if`, `match`, `loop`, and `while` in terms of control flow. The error relating to control flow in `const` contexts currently states that those control flow constructs are not allowed in `const` contexts. That is no longer true, as RFC 2342 and 2344 were [stabilized](https://github.com/rust-lang/rust/pull/72437). `for` loops, however, as well as `?` and `.await` are still not allowed, so I changed the error message to be more descriptive of the error as it is not just control flow that could trigger this error. I also added links to tracking issues that mark things that are blocking the usage of these expressions.
2020-11-16 17:26:38 +01:00
Mara Bos
835faa532f
Rollup merge of #79032 - lcnr:arg-count, r=varkor
improve type const mismatch errors

Doesn't completely remove `check_generic_arg_count` as that would have required some more complex changes but
instead checks type and const params in only one step. Also moved the help added by `@JulianKnodt` in #75611 to `generic_arg_mismatch_err`.

r? `@varkor` cc `@petrochenkov`
2020-11-16 17:26:35 +01:00
Mara Bos
11ce918c75
Rollup merge of #78714 - m-ou-se:simplify-local-streams, r=KodrAus
Simplify output capturing

This is a sequence of incremental improvements to the unstable/internal `set_panic` and `set_print` mechanism used by the `test` crate:

1. Remove the `LocalOutput` trait and use `Arc<Mutex<dyn Write>>` instead of `Box<dyn LocalOutput>`. In practice, all implementations of `LocalOutput` were just `Arc<Mutex<..>>`. This simplifies some logic and removes all custom `Sink` implementations such as `library/test/src/helpers/sink.rs`. Also removes a layer of indirection, as the outermost `Box` is now gone. It also means that locking now happens per `write_fmt`, not per individual `write` within. (So `"{} {}\n"` now results in one `lock()`, not four or more.)

2. Since in all cases the `dyn Write`s were just `Vec<u8>`s, replace the type with `Arc<Mutex<Vec<u8>>>`. This simplifies things more, as error handling and flushing can be removed now. This also removes the hack needed in the default panic handler to make this work with `::realstd`, as (unlike `Write`) `Vec<u8>` is from `alloc`, not `std`.

3. Replace the `RefCell`s by regular `Cell`s. The `RefCell`s were mostly used as `mem::replace(&mut *cell.borrow_mut(), something)`, which is just `Cell::replace`. This removes an unecessary bookkeeping and makes the code a bit easier to read.

4. Merge `set_panic` and `set_print` into a single `set_output_capture`. Neither the test crate nor rustc (the only users of this feature) have a use for using these separately. Merging them simplifies things even more. This uses a new function name and feature name, to make it clearer this is internal and not supposed to be used by other crates.

Might be easier to review per commit.
2020-11-16 17:26:27 +01:00
James
0bc04e327c
Update E0744 about control flow in const contexts to reflect the current status of const fn.
This is a squash of these commits:
- Update E0744 about control flow in `const` contexts to reflect current status of `const fn`.
- E0744 isn't just about `for` loops or control flow
- Fix formatting on E0744 cause my editor decided to not copy it well
- Improve wording
- Fix a markdown formatting error
- Fix E0744's description as I interpreted some code wrong
- Fix a minor wording issue again
- Add a few more links to blocking issues
- Improve links to tracking issues
2020-11-16 09:30:29 -06:00
Bastian Kauschke
69b43c209c improve error message for const ty param mismatch 2020-11-16 16:07:59 +01:00
Bastian Kauschke
dcc194ce2f instrument QueryNormalizer::fold_ty 2020-11-16 10:48:31 +01:00
Nadrieril
36e3409f67 Apply suggestions from code review
Co-authored-by: varkor <github@varkor.com>
2020-11-16 01:00:33 +00:00
Aman Arora
40dfe1eddd Ignore doctest for capture analysis examples 2020-11-15 18:53:03 -05:00
Aman Arora
bb8c5e5d8b Fix case when ExprUseVisitor is called after typeck writeback
Clippy uses `ExprUseVisitor` and atleast in some cases it runs
after writeback.

We currently don't writeback the min_capture results of closure
capture analysis since no place within the compiler itself uses it.

In the short term to fix clippy we add a fallback when walking captures
of a closure to check if closure_capture analysis has any entries in it.

Writeback for closure_min_captures will be implemented in
rust-lang/project-rfc-2229#18
2020-11-15 17:09:51 -05:00
Camelid
c82a258ad4 Turn top-level comments into module docs in MIR visitor 2020-11-15 12:36:28 -08:00
LeSeulArtichaut
f6e6a15f07 Remove dead TypeFoldable::visit_tys_shallow method 2020-11-15 14:45:41 +01:00
Jonas Schievink
ae1916b3b4
Rollup merge of #79058 - dtolnay:likelymacro, r=Mark-Simulacrum
Move likely/unlikely argument outside of invisible unsafe block

The previous `likely!`/`unlikely!` macros were unsound because it permits the caller's expr to contain arbitrary unsafe code.

```rust
pub fn huh() -> bool {
    likely!(std::ptr::read(&() as *const () as *const bool))
}
```

**Before:** compiles cleanly.
**After:**

```console
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
   |
70 |     likely!(std::ptr::read(&() as *const () as *const bool))
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
   |
   = note: consult the function's documentation for information on how to avoid undefined behavior
```
2020-11-15 13:40:03 +01:00
Jonas Schievink
ce775bc4f6
Rollup merge of #79036 - cjgillot:steal, r=oli-obk
Move Steal to rustc_data_structures.
2020-11-15 13:39:59 +01:00