Commit graph

199 commits

Author SHA1 Message Date
Aaron Hill
d5a04a9927
Collect tokens when handling :literal matcher
An `NtLiteral` just wraps an `Expr`, so we don't need to add a new `tokens`
field to an AST struct.
2020-09-10 17:33:06 -04:00
Aaron Hill
1823dea7df
Attach TokenStream to ast::Ty
A `Ty` does not have outer attributes, so we only capture tokens
when parsing a `macro_rules!` matcher
2020-09-10 17:33:05 -04:00
Aaron Hill
de4bd9f0f8
Attach TokenStream to ast::Block
A `Block` does not have outer attributes, so we only capture tokens when
parsing a `macro_rules!` matcher
2020-09-10 17:33:05 -04:00
Tyler Mandry
c8f9c728c2
Rollup merge of #76567 - matthiaskrgr:clone_on_copy, r=varkor
use push(char) to add chars (single-char &strs) to strings instead of push_str(&str)
2020-09-10 12:20:12 -07:00
Tyler Mandry
94ae5d1866
Rollup merge of #76565 - matthiaskrgr:box_place, r=oli-obk
take reference to Place directly instead of taking reference to Box<Place>

clippy::borrowed_box
2020-09-10 12:20:11 -07:00
Tyler Mandry
ae46b9e483
Rollup merge of #76563 - yokodake:patch-1, r=jonas-schievink
small typo fix in rustc_parse docs

small typo in rustc_parse::new_parser_from_file's documentation

I'm not sure a PR is the way to do this though.
2020-09-10 12:20:09 -07:00
Tyler Mandry
ac85a4d71e
Rollup merge of #76559 - lcnr:const-evaluatable, r=oli-obk
add the `const_evaluatable_checked` feature

Implements a rather small subset of https://github.com/rust-lang/compiler-team/issues/340

Unlike the MCP, this does not try to compare different constant, but instead only adds the constants found in where clauses
to the predicates of a function. This PR adds the feature gate `const_evaluatable_checked`, without which nothing should change.

r? @oli-obk @eddyb
2020-09-10 12:20:07 -07:00
Tyler Mandry
2df1487fc9
Rollup merge of #76548 - tmiasko:validate, r=davidtwco
Validate removal of AscribeUserType, FakeRead, and Shallow borrow

Those statements are removed by CleanupNonCodegenStatements pass
in drop lowering phase, and should not occur afterwards.
2020-09-10 12:20:04 -07:00
Tyler Mandry
9f8a7827a1
Rollup merge of #76524 - davidtwco:issue-76077-inaccessible-private-fields, r=estebank
typeck: don't suggest inaccessible private fields

Fixes #76077.

This PR adjusts the missing field diagnostic logic in typeck so that when none of the missing fields in a struct expr are accessible then the error is less confusing.

r? @estebank
2020-09-10 12:20:02 -07:00
David Wood
409c141973
typeck/pat: inaccessible private fields
This commit adjusts the missing field diagnostic logic for struct
patterns in typeck to improve the diagnostic when the missing fields are
inaccessible.

Signed-off-by: David Wood <david@davidtw.co>
2020-09-10 18:52:00 +01:00
David Wood
c0894e7232
typeck/expr: inaccessible private fields
This commit adjusts the missing field diagnostic logic for struct
expressions in typeck to improve the diagnostic when the missing
fields are inaccessible.

Signed-off-by: David Wood <david@davidtw.co>
2020-09-10 18:51:56 +01:00
David Tolnay
fd4dd00dde
Syntactically permit unsafety on mods 2020-09-10 06:56:33 -07:00
Matthias Krüger
9bb10cc907 use push(char) instead of push_str(&str) to add single chars to strings
clippy::single-char-push-str
2020-09-10 13:58:41 +02:00
Matthias Krüger
e11c667e4a don't clone types that are copy (clippy::clone_on_copy) 2020-09-10 13:26:36 +02:00
Matthias Krüger
e2a511fe20 use String::from instead of format!() macro to craft string clippy::useless_format 2020-09-10 13:22:51 +02:00
Matthias Krüger
6bfe132067 take reference to Place directly instead of taking reference to Box<Place>
clippy::borrowed_box
2020-09-10 13:08:28 +02:00
Nanami
8b059980d7
small typo fix in rustc_parse docs 2020-09-10 11:56:11 +02:00
bors
a18b34d979 Auto merge of #76291 - matklad:spacing, r=petrochenkov
Rename IsJoint -> Spacing

Builds on #76286 and might conflict with #76285

r? `@petrochenkov`
2020-09-10 08:07:48 +00:00
Bastian Kauschke
300b0acb85 fix tidy, small cleanup 2020-09-10 09:48:02 +02:00
Bastian Kauschke
8667f93040 implement const_evaluatable_checked feature MVP 2020-09-10 08:52:02 +02:00
bors
88197214b8 Auto merge of #75573 - Aaron1011:feature/const-mutation-lint, r=oli-obk
Add CONST_ITEM_MUTATION lint

Fixes #74053
Fixes #55721

This PR adds a new lint `CONST_ITEM_MUTATION`.
Given an item `const FOO: SomeType = ..`, this lint fires on:

* Attempting to write directly to a field (`FOO.field = some_val`) or
  array entry (`FOO.array_field[0] = val`)
* Taking a mutable reference to the `const` item (`&mut FOO`), including
  through an autoderef `FOO.some_mut_self_method()`

The lint message explains that since each use of a constant creates a
new temporary, the original `const` item will not be modified.
2020-09-10 05:54:26 +00:00
Tyler Mandry
193503eb62
Rollup merge of #76556 - tmandry:revert-76285, r=tmandry
Revert #76285

Fixes #76399. Reverting because the issue is P-critical and there are no PRs up to fix it.

r? @Mark-Simulacrum
cc @matklad @dtolnay
2020-09-09 21:02:38 -07:00
Tyler Mandry
ba6e2b3a31
Rollup merge of #76500 - richkadel:mir-graphviz-dark, r=tmandry
Add -Zgraphviz_dark_mode and monospace font fix

Many developers use a dark theme with editors and IDEs, but this
typically doesn't extend to graphviz output.

When I bring up a MIR graphviz document, the white background is
strikingly bright. This new option changes the colors used for graphviz
output to work better in dark-themed UIs.

<img width="1305" alt="Screen Shot 2020-09-09 at 3 00 31 PM" src="https://user-images.githubusercontent.com/3827298/92659478-4b9bff00-f2ad-11ea-8894-b40d3a873cb9.png">

Also fixed the monospace font for common graphviz renders (e.g., VS Code extensions), as described in https://github.com/rust-lang/rust/pull/76500#issuecomment-689837948

**Before:**
<img width="943" alt="Screen Shot 2020-09-09 at 2 48 44 PM" src="https://user-images.githubusercontent.com/3827298/92658939-47231680-f2ac-11ea-97ac-96727e4dd622.png">

**Now with fix:**
<img width="943" alt="Screen Shot 2020-09-09 at 2 49 02 PM" src="https://user-images.githubusercontent.com/3827298/92658959-51451500-f2ac-11ea-9aae-de982d466d6a.png">
2020-09-09 21:02:35 -07:00
Tyler Mandry
f09372ab60
Rollup merge of #74787 - petrochenkov:rustllvm, r=cuviper
Move `rustllvm` into `compiler/rustc_llvm`

The `rustllvm` directory is not self-contained, it contains C++ code built by a build script of the `rustc_llvm` crate which is then linked into that crate.
So it makes sense to make `rustllvm` a part of `rustc_llvm` and move it into its directory.
I replaced `rustllvm` with more obvious `llvm-wrapper` as the subdirectory name, but something like `llvm-adapter` would work as well, other suggestions are welcome.

To make things more confusing, the Rust side of FFI functions defined in `rustllvm` can be found in `rustc_codegen_llvm` rather than in `rustc_llvm`. Perhaps they need to be moved as well, but this PR doesn't do that.

The presence of multiple LLVM-related directories in `src` (`llvm-project`, `rustllvm`, `librustc_llvm`, `librustc_codegen_llvm` and their predecessors) historically confused me and made me wonder about their purpose.
With this PR we will have LLVM itself (`llvm-project`), a FFI crate (`rustc_llvm`, kind of `llvm-sys`) and a codegen backend crate using LLVM through the FFI crate (`rustc_codegen_llvm`).
2020-09-09 21:02:24 -07:00
Tyler Mandry
fdff7defc9 Revert "Rollup merge of #76285 - matklad:censor-spacing, r=petrochenkov"
This reverts commit 85cee57fd7, reversing
changes made to b4d3873024.
2020-09-10 02:18:46 +00:00
Tomasz Miąsko
00e64ba476 Validate removal of AscribeUserType, FakeRead, and Shallow borrow
Those statements are removed by CleanupNonCodegenStatements pass
in drop lowering phase, and should not occur afterwards.
2020-09-10 00:00:00 +00:00
Tyler Mandry
32714eb6bc
Rollup merge of #76523 - tmiasko:non-use-context-coverage, r=wesleywiser
Remove unused PlaceContext::NonUse(NonUseContext::Coverage)

r? @richkadel / @wesleywiser
2020-09-09 15:06:07 -07:00
Tyler Mandry
09c614948f
Rollup merge of #76522 - matthiaskrgr:redundant_clone, r=jonas-schievink
remove redundant clones

(clippy::redundant_clone)
2020-09-09 15:06:05 -07:00
Tyler Mandry
98f59bc2aa
Rollup merge of #76515 - jumbatm:issue76496-reproducibility-regression, r=oli-obk
SessionDiagnostic: Fix non-determinism in generated format string.

Fixes #76496.

r? @oli-obk
2020-09-09 15:06:02 -07:00
Tyler Mandry
c18fa460a4
Rollup merge of #76504 - Flying-Toast:master, r=lcnr
Capitalize safety comments
2020-09-09 15:06:00 -07:00
Tyler Mandry
bab09684b4
Rollup merge of #76313 - richkadel:mir-spanview-2, r=wesleywiser
Improved the MIR spanview output

* Adds missing "tail" spans (spans that continue beyond the end of
overlapping spans)
* Adds a caret to highlight empty spans associated with MIR elements
that have a position, but otherwise would not be visible.
* Adds visual pointing brackets at the beginning and end of each span

<img width="590" alt="Screen Shot 2020-09-03 at 8 38 08 PM" src="https://user-images.githubusercontent.com/3827298/92202571-25510c00-ee34-11ea-89bc-89eea939476d.png">
<img width="1061" alt="Screen Shot 2020-09-03 at 8 41 04 PM" src="https://user-images.githubusercontent.com/3827298/92202629-49145200-ee34-11ea-8fda-fc6e62c80736.png">
<img width="1113" alt="Screen Shot 2020-09-06 at 5 42 57 PM" src="https://user-images.githubusercontent.com/3827298/92339198-ca085f00-f069-11ea-96d1-c01ced50e2ba.png">
<img width="1692" alt="Screen Shot 2020-09-06 at 5 45 54 PM" src="https://user-images.githubusercontent.com/3827298/92339209-d4c2f400-f069-11ea-94c0-b4d36c200878.png">

r? @tmandry
FYI: @wesleywiser
2020-09-09 15:05:49 -07:00
Tyler Mandry
5ea55518bc
Rollup merge of #75984 - kornelski:typeormodule, r=matthewjasper
Improve unresolved use error message

"use of undeclared type or module `foo`" doesn't mention that it could be a crate.

This error can happen when users forget to add a dependency to `Cargo.toml`, so I think it's important to mention that it could be a missing crate.

I've used a heuristic based on Rust's naming conventions. It complains about an unknown type if the ident starts with an upper-case letter, and crate or module otherwise. It seems to work very well. The expanded error help covers both an unknown type and a missing crate case.
2020-09-09 15:05:45 -07:00
Tyler Mandry
07dbe49ce9
Rollup merge of #75094 - 0dvictor:cgu, r=oli-obk
Add `-Z combine_cgu` flag

Introduce a compiler option to let rustc combines all regular CGUs into a single one at the end of compilation.

Part of Issue #64191
2020-09-09 15:05:43 -07:00
Rich Kadel
f7aee330c7 Also fixed monospace font for d3-graphviz engine
VS code graphviz extensions use d3-graphviz, which supports `Courier`
fontname but does not support `monospace`. This caused graphs to render
poorly because the text sizes were wrong.
2020-09-09 14:49:32 -07:00
Vadim Petrochenkov
10d3f8a484 Move rustllvm into rustc_llvm 2020-09-09 23:05:43 +03:00
bors
e2be5f568d Auto merge of #74595 - lcnr:ConstEvaluatable-fut-compat, r=oli-obk
make `ConstEvaluatable` more strict

relevant zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60ConstEvaluatable.60.20generic.20functions/near/204125452

Let's see how much this impacts. Depending on how this goes this should probably be a future compat warning.

Short explanation: we currently forbid anonymous constants which depend on generic types, e.g. `[0; std::mem::size_of::<T>]` currently errors.

We previously checked this by evaluating the constant and returned an error if that failed. This however allows things like
```rust
const fn foo<T>() -> usize {
    if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
        std::mem::size_of::<T>()
    } else {
        8
    }
}

fn test<T>() {
    let _ = [0; foo::<T>()];
}
```
which is a backwards compatibility hazard. This also has worrying interactions with mir optimizations (https://github.com/rust-lang/rust/pull/74491#issuecomment-661890421) and intrinsics (#74538).

r? `@oli-obk` `@eddyb`
2020-09-09 20:04:04 +00:00
Tomasz Miąsko
0016405073 Remove unused PlaceContext::NonUse(NonUseContext::Coverage) 2020-09-09 17:02:19 +02:00
Matthias Krüger
be28b6235e remove redundant clones
(clippy::redundant_clone)
2020-09-09 16:32:55 +02:00
jumbatm
8b392505ae Fix non-determinism in generated format string. 2020-09-09 21:23:25 +10:00
bors
3f5e617e36 Auto merge of #76406 - GuillaumeGomez:create-e0774, r=pickfire,jyn514
Create E0774
2020-09-09 08:23:33 +00:00
Victor Ding
c81b43d8ac Add -Z combine_cgu flag
Introduce a compiler option to let rustc combines all regular CGUs into
a single one at the end of compilation.

Part of Issue #64191
2020-09-09 17:32:23 +10:00
bors
0855263dcd Auto merge of #76463 - camelid:improve-E0607-explanation, r=jyn514
Improve wording of E0607 explanation

`@rustbot` modify labels: A-diagnostics C-enhancement
2020-09-09 06:33:03 +00:00
Flying-Toast
2799aec6ab Capitalize safety comments 2020-09-08 22:37:18 -04:00
Rich Kadel
c19b2370e4 Add -Zgraphviz_dark_mode
Many developers use a dark theme with editors and IDEs, but this
typically doesn't extend to graphviz output.

When I bring up a MIR graphviz document, the white background is
strikingly bright. This new option changes the colors used for graphviz
output to work better in dark-themed UIs.
2020-09-08 17:19:38 -07:00
Dylan DPC
12707346cf
Rollup merge of #76403 - scileo:doc-all-impls, r=lcnr
Fix documentation for TyCtxt::all_impls

`TyCtxt::all_impls` documentation was wrong about the return type.
2020-09-09 01:35:23 +02:00
Dylan DPC
1083833b3e
Rollup merge of #76401 - JulianKnodt:i68366, r=lcnr
Add help note to unconstrained const parameter

Resolves #68366, since it is currently intended behaviour.
If demonstrating `T -> U` is injective, there should be an additional word that it is not **yet** supported.

r? @lcnr
2020-09-09 01:35:20 +02:00
Dylan DPC
4ac88c01c3
Rollup merge of #76355 - calebcartwright:reduce-rustfmt-visibility, r=nikomatsakis
remove public visibility previously needed for rustfmt

`submod_path_from_attr` in rustc_expand::module was previously public because it was also consumed by rustfmt. However, we've done a bit of refactoring in rustfmt and no longer need to use this function.

This changes the visibility to the parent mod as was originally going to be done before the rustfmt dependency was realized (c189565edc (diff-cd1b379893bae95f7991d5a3f3c6d337R201))
2020-09-09 01:35:11 +02:00
Guillaume Gomez
e0df2f87b6 Create new E0774 code error 2020-09-08 21:32:03 +02:00
Bastian Kauschke
1dd00e60b9 add tracking issue, fix rebase 2020-09-08 16:39:12 +02:00
Bastian Kauschke
c10ad0d888 review 2020-09-08 16:39:12 +02:00