Commit graph

850 commits

Author SHA1 Message Date
Eduard-Mihai Burtescu
6165d1cc72 Print -Ztime-passes (and misc stats/logs) on stderr, not stdout. 2021-02-18 14:13:38 +02:00
Yuki Okushi
ce6367f479
Rollup merge of #82240 - matthiaskrgr:qmark, r=Dylan-DPC
remove useless ?s (clippy::needless_question_marks)

Example code:
```rust
fn opts() -> Option<String> {
    let s: Option<String> = Some(String::new());
    Some(s?) // this can just be "s"
}
```
2021-02-18 15:57:33 +09:00
Yuki Okushi
53b5c6b58d
Rollup merge of #82212 - est31:graph_graph_graph, r=oli-obk
Remove redundant rustc_data_structures path component
2021-02-18 15:57:32 +09:00
Matthias Krüger
f7b834831f remove useless ?s (clippy::needless_question_marks)
Example code:
```
fn opts() -> Option<String> {
    let s: Option<String> = Some(String::new());
    Some(s?) // this can just be "s"
}
```
2021-02-17 23:23:57 +01:00
bors
152f660924 Auto merge of #82235 - GuillaumeGomez:rollup-oflxc08, r=GuillaumeGomez
Rollup of 11 pull requests

Successful merges:

 - #79981 (Add 'consider using' message to overflowing_literals)
 - #82094 (To digit simplification)
 - #82105 (Don't fail to remove files if they are missing)
 - #82136 (Fix ICE: Use delay_span_bug for mismatched subst/hir arg)
 - #82169 (Document that `assert!` format arguments are evaluated lazily)
 - #82174 (Replace File::create and write_all with fs::write)
 - #82196 (Add caveat to Path::display() about lossiness)
 - #82198 (Use internal iteration in Iterator::is_sorted_by)
 - #82204 (Update books)
 - #82207 (rustdoc: treat edition 2021 as unstable)
 - #82231 (Add long explanation for E0543)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-17 19:39:58 +00:00
Guillaume Gomez
13730e90bd
Rollup merge of #82136 - edward-shen:mismatched-subst-and-hir, r=lcnr
Fix ICE: Use delay_span_bug for mismatched subst/hir arg

Fixes #82126.
2021-02-17 20:37:58 +01:00
est31
6460205031 Remove redundant rustc_data_structures path component 2021-02-17 09:30:08 +01:00
Tomasz Miąsko
e190f0d974 Reduce size of InterpErrorInfo to 8 bytes 2021-02-17 08:57:06 +01:00
bors
8fe989dd76 Auto merge of #81611 - cjgillot:meowner, r=estebank
Only store a LocalDefId in some HIR nodes

Some HIR nodes are guaranteed to be HIR owners: Item, TraitItem, ImplItem, ForeignItem and MacroDef.
As a consequence, we do not need to store the `HirId`'s `local_id`, and we can directly store a `LocalDefId`.

This allows to avoid a bit of the dance with `tcx.hir().local_def_id` and `tcx.hir().local_def_id_to_hir_id` mappings.
2021-02-16 22:14:32 +00:00
Ralf Jung
897cb61076 validation: fix invalid-fn-ptr error message 2021-02-16 09:58:35 +01:00
Camille GILLOT
786a80e9ea Only store a LocalDefId in hir::ImplItem. 2021-02-15 19:32:29 +01:00
Camille GILLOT
cebbba081e Only store a LocalDefId in hir::Item.
Items are guaranteed to be HIR owner.
2021-02-15 19:32:10 +01:00
Camille GILLOT
bd3cd5dbed Use an ItemId inside mir::GlobalAsm. 2021-02-15 19:24:58 +01:00
Camille GILLOT
c676e358a5 Use ItemId as a strongly typed index. 2021-02-15 19:24:58 +01:00
Jonas Schievink
665bf9e35f
Rollup merge of #82067 - BoxyUwU:hahaicantthinkofabadpun, r=oli-obk
const_generics: Fix incorrect ty::ParamEnv::empty() usage

Fixes #80561

Not sure if I should keep the `debug!(..)`s or not but its the second time I've needed them so they sure seem useful lol

cc ``@lcnr``
r? ``@oli-obk``
2021-02-15 16:06:59 +01:00
Jonas Schievink
5e8435abe0
Rollup merge of #82061 - RalfJung:ctfe-read-pointer-as-bytes, r=oli-obk
CTFE validation: catch ReadPointerAsBytes and better error

r? ``@oli-obk``
Fixes https://github.com/rust-lang/rust/issues/79690
Cc https://github.com/rust-lang/miri/issues/1706
2021-02-15 16:06:57 +01:00
Jonas Schievink
6fde3c5438
Rollup merge of #82009 - BoxyUwU:idontknooow, r=varkor
const_generics: Dont evaluate array length const when handling errors

Fixes #79518
Fixes #78246

cc ````@lcnr````

This was ICE'ing because we dont pass in the correct ``ParamEnv`` which meant that there was no ``Self: Foo`` predicate to make ``Self::Assoc`` well formed which caused an ICE when trying to normalize ``Self::Assoc`` in the mir interpreter

r? ````@varkor````
2021-02-15 16:06:55 +01:00
Jonas Schievink
f02f7b05b2
Rollup merge of #81503 - henryboisdequin:fix-const-fn-arr-err-msg, r=estebank
Suggest to create a new `const` item if the `fn` in the array is a `const fn`

Fixes #73734. If the `fn` in the array repeat expression is a `const fn`, suggest creating a new `const` item. On nightly, suggest creating an inline `const` block. This PR also removes the `suggest_const_in_array_repeat_expressions` as it is no longer necessary.

Example:

```rust
fn main() {
    // Should not compile but hint to create a new const item (stable) or an inline const block (nightly)
    let strings: [String; 5] = [String::new(); 5];
    println!("{:?}", strings);
}

```

Gives this error:

```
error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not satisfied
 --> $DIR/const-fn-in-vec.rs:3:32
  |
2 |     let strings: [String; 5] = [String::new(); 5];
  |                             ^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `String`
  |
  = note: the `Copy` trait is required because the repeated element will be copied
```

With this change, this is the error message:

```
error[E0277]: the trait bound `String: Copy` is not satisfied
  --> $DIR/const-fn-in-vec.rs:3:32
   |
LL |     let strings: [String; 5] = [String::new(); 5];
   |                                ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
   |
   = help: moving the function call to a new `const` item will resolve the error
```
2021-02-15 16:06:47 +01:00
Edward Shen
a4b2fafcc1
Revise HIR lowering comment 2021-02-15 00:28:58 -05:00
Edward Shen
a491f51218
Use delay_span_bug for mismatched subst/hir arg 2021-02-14 23:59:45 -05:00
Dylan DPC
bcb14035e9
Rollup merge of #82056 - b-naber:mut_for_loop_bug, r=oli-obk
fix ice (#82032)

Fixes https://github.com/rust-lang/rust/issues/82032
2021-02-14 16:54:53 +01:00
Dylan DPC
c8dacf95ae
Rollup merge of #82029 - tmiasko:debug, r=matthewjasper
Use debug log level for developer oriented logs

The information logged here is of limited general interest, while at the
same times makes it impractical to simply enable logging and share the
resulting logs due to the amount of the output produced.

Reduce log level from info to debug for developer oriented information.

For example, when building cargo, this reduces the amount of logs
generated by `RUSTC_LOG=info cargo build` from 265 MB to 79 MB.

Continuation of changes from 81350.
2021-02-14 16:54:52 +01:00
Dylan DPC
2efde8c795
Rollup merge of #81965 - osa1:issue81200, r=oli-obk
Fix MIR pretty printer for non-local DefIds

Tries to fix #81200 -- the reproducer in the issue is not fixed yet.
Submitting PR to get feedback.

r? oli-obk
2021-02-14 16:54:51 +01:00
klensy
93c8ebe022 bumped smallvec deps 2021-02-14 18:03:11 +03:00
Ellen
b6144e7a20 yeet ya fixme into the void 2021-02-13 19:10:08 +00:00
Ömer Sinan Ağacan
fe82365630 Fix MIR pretty printer for non-local DefIds 2021-02-13 20:23:27 +03:00
Ellen
a3e079534d Heat up the ICE-y error reporting
rest in peace match bool <3
2021-02-13 14:42:30 +00:00
Ralf Jung
d6dcb3de54 CTFE validation: catch ReadPointerAsBytes and better error 2021-02-13 14:58:31 +01:00
b-naber
77dfd71b95 fix 82032 2021-02-13 11:47:44 +01:00
Tomasz Miąsko
361dcd5ca7 Use debug log level for developer oriented logs
The information logged here is of limited general interest, while at the
same times makes it impractical to simply enable logging and share the
resulting logs due to the amount of the output produced.

Reduce log level from info to debug for developer oriented information.

For example, when building cargo, this reduces the amount of logs
generated by `RUSTC_LOG=info cargo build` from 265 MB to 79 MB.

Continuation of changes from 81350.
2021-02-13 00:00:00 +00:00
Dylan DPC
fc93e260e9
Rollup merge of #81479 - osa1:issue24151, r=lcnr
Allow casting mut array ref to mut ptr

Allow casting mut array ref to mut ptr

We now allow two new casts:

- mut array reference to mut ptr. Example:

      let mut x: [usize; 2] = [0, 0];
      let p = &mut x as *mut usize;

  We allow casting const array references to const pointers so not
  allowing mut references to mut pointers was inconsistent.

- mut array reference to const ptr. Example:

      let mut x: [usize; 2] = [0, 0];
      let p = &mut x as *const usize;

  This was similarly inconsistent as we allow casting mut references to
  const pointers.

Existing test 'vector-cast-weirdness' updated to test both cases.

Fixes #24151
2021-02-12 22:53:29 +01:00
Yuki Okushi
0b7fc80e45
Rollup merge of #81959 - therealprof:fix-typo, r=oli-obk
Fix assosiated typo

Introduced in d3c4dbd85d, noticed only
after the fact, sorry. 😅

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2021-02-12 19:32:12 +09:00
bors
26e5bcd220 Auto merge of #81350 - tmiasko:instrument-debug, r=lcnr
Reduce log level used by tracing instrumentation from info to debug

Restore log level to debug to avoid make info log level overly verbose (the uses of instrument attribute modified there, were for the most part a replacement for `debug!`;  one use was novel).
2021-02-11 13:44:00 +00:00
Ömer Sinan Ağacan
d64b749f2c Allow casting mut array ref to mut ptr
We now allow two new casts:

- mut array reference to mut ptr. Example:

      let mut x: [usize; 2] = [0, 0];
      let p = &mut x as *mut usize;

  We allow casting const array references to const pointers so not
  allowing mut references to mut pointers was inconsistent.

- mut array reference to const ptr. Example:

      let mut x: [usize; 2] = [0, 0];
      let p = &mut x as *const usize;

  This was similarly inconsistent as we allow casting mut references to
  const pointers.

Existing test 'vector-cast-weirdness' updated to test both cases.

Fixes #24151
2021-02-10 15:44:41 +03:00
Daniel Egger
a6d413715c Fix assosiated typo
Introduced in d3c4dbd85d, noticed only
after the fact, sorry. 😅

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2021-02-10 09:36:26 +01:00
Dániel Buga
3c1d792f49 Only initialize what is used 2021-02-10 09:20:41 +01:00
Yuki Okushi
3f09418cbe
Rollup merge of #81466 - sasurau4:fix/enhance-sugget-mut-method-for-loop, r=oli-obk
Add suggest mut method for loop

Part of #49839

This PR focus on [the comment case](https://github.com/rust-lang/rust/issues/49839#issuecomment-761930746)
2021-02-10 12:24:21 +09:00
bors
87bacf22ec Auto merge of #81132 - bugadani:map-prealloc, r=matthewjasper
Borrowck: refactor visited map to a bitset

This PR refactors `Borrows`  and the `precompute_borrows_out_of_scope` function so that this initial phase has a much reduced memory pressure. This is achieved by reducing what is stored on the heap, and also reusing heap memory as much as possible.
2021-02-09 21:28:58 +00:00
Dániel Buga
5271c628be Remove RCs from Borrows 2021-02-08 20:37:16 +01:00
Mara Bos
b263981fd7
Rollup merge of #81779 - geogriff:const-ptr-to-int-error, r=lcnr
improve error message for disallowed ptr-to-int casts in const eval

Improves an error message as [suggested](https://github.com/rust-lang/rust/issues/80875#issuecomment-762754580) in #80875.

Does the wording make enough sense? I tried to follow precedent for error message style while maintaining brevity.

It seems like the rest of the `ConstEvalErrKind::NeedsRfc` error messages could be improved as well. I could give that a go if this approach works.

Closes #80875
2021-02-08 19:28:17 +01:00
Dániel Buga
46f30455f4 Optimize Borrows
Reuse as much memory as possible, reduce number of allocations.
Use BitSet instead of a HashMap, since only a single bit of
information was used as the map's value.
2021-02-07 22:26:21 +01:00
Daiki Ihara
d3c4dbd85d Add suggest mu method for loop 2021-02-05 22:12:31 +09:00
Jeffrey Griffin
ff315e34e8 improve error message for disallowed ptr-to-int casts in const eval 2021-02-05 00:52:19 -08:00
Tomasz Miąsko
eb5e2d08c7 Never MIR inline functions with a different instruction set 2021-02-05 00:00:00 +00:00
Aaron Hill
bc84e21107
Fix panic when emitting diagnostic for closure mutable binding error
Fixes #81700

The upvar borrow kind may be `ty::BorrowKind::UniqueImmBorrow`, which is
still a mutable borrow for the purposes of this diagnostic code.
2021-02-03 12:36:24 -05:00
Henry Boisdequin
c2e849c022 added a suggestion to create a const item if the fn in the array repeat expression is a const fn 2021-02-03 10:18:08 +05:30
Jonas Schievink
9e8753e2bb
Rollup merge of #81463 - matsujika:nll-ensure-c-case, r=varkor
Rename NLL* to Nll* accordingly to C-CASE

Given [C-CASE](https://rust-lang.github.io/api-guidelines/naming.html#casing-conforms-to-rfc-430-c-case), `NLLRegionVariableOrigin` and `NLL` are encouraged to be `NllRegionVariableOrigin` and `Nll` respectively.
2021-02-01 14:29:35 +01:00
Jonas Schievink
99f2f5a830
Rollup merge of #80404 - JulianKnodt:arr_ref, r=oli-obk
Remove const_in_array_repeat

Fixes #80371. Fixes #81315. Fixes #80767. Fixes #75682.

I thought there might be some issue with `Repeats(_, 0)`, but if you increase the items in the array it still ICEs. I'm not sure if this is the best fix but it does fix the given issue.
2021-01-31 16:36:42 +01:00
Jonas Schievink
7e3a8ec688
Rollup merge of #80092 - sexxi-goose:restrict_precision, r=nikomatsakis
2229: Fix issues with move closures and mutability

This PR fixes two issues when feature `capture_disjoint_fields` is used.

1. Can't mutate using a mutable reference
2. Move closures try to move value out through a reference.

To do so, we
1. Compute the mutability of the capture and store it as part of the `CapturedPlace`  that is written in TypeckResults
2. Restrict capture precision. Note this is temporary for now, to allow the feature to be used with move closures and ByValue captures and might change depending on discussions with the lang team.
    - No Derefs are captured for ByValue captures, since that will result in value behind a reference getting moved.
    - No projections are applied to raw pointers since these require unsafe blocks. We capture
    them completely.

r? `````@nikomatsakis`````
2021-01-31 16:36:41 +01:00
bors
9b32429822 Auto merge of #81327 - RalfJung:codegen-no-const-fail, r=oli-obk
codegen: assume constants cannot fail to evaluate

https://github.com/rust-lang/rust/pull/80579 landed, so we can finally remove this old hack from codegen and instead assume that consts never fail to evaluate. :)

r? `@oli-obk`
2021-01-31 07:03:09 +00:00