Commit graph

4736 commits

Author SHA1 Message Date
Oli Scherer
c6676db7ae Some more fine-grained forced inlining 2021-04-01 10:40:50 +00:00
Oli Scherer
d81f5ab100 Inline some functions that suddenly show up more in traces 2021-04-01 09:22:12 +00:00
Oli Scherer
d139968d19 bail out early when substituting mir constants that don't need substituting 2021-03-31 10:40:45 +00:00
Oli Scherer
4e8edfb5c2 Forward some layouts to prevent recomputation 2021-03-31 10:40:45 +00:00
Oli Scherer
dbacfbc368 Add a new normalization query just for mir constants 2021-03-31 10:40:42 +00:00
Oli Scherer
c7c39ce6d0 We should never see unevaluated type-level constants after monomorphization unless errors occurred 2021-03-31 09:13:45 +00:00
Oli Scherer
1d56b8a2bc Make unevaluated DefId rendering deterministic 2021-03-31 09:13:45 +00:00
Oli Scherer
5582b19559 Only emit a discrimiant tag for enums 2021-03-29 12:30:55 +00:00
Oli Scherer
c0e1191807 Don't build a ty::Const just to take it apart again 2021-03-29 12:30:55 +00:00
Oli Scherer
5b6ddd5026 Convert a closure into a method 2021-03-29 12:30:55 +00:00
bors
cc4103089f Auto merge of #83605 - RalfJung:unaligned, r=petrochenkov
unaligned_references: align(N) fields in packed(N) structs are fine

This removes some false positives from the unaligned_references lint: in a `repr(packed(2))` struct, fields of alignment 2 (and less) are guaranteed to be properly aligned, so we do not have to consider them "disaligned".
2021-03-29 00:17:23 +00:00
Vadim Petrochenkov
cc5392e76b linker: Use data execution prevention options by default when linker supports them 2021-03-28 23:44:40 +03:00
Ralf Jung
ee1caae33c unaligned_references: align(N) fields in packed(N) structs are fine 2021-03-28 12:54:19 +02:00
bors
505ed7fb1b Auto merge of #83593 - petrochenkov:nounwrap, r=nagisa
rustc_target: Avoid unwraps when adding linker flags

These `unwrap`s assume that some linker flags were already added by `*_base::opts()` methods, but that's doesn't necessarily remain the case when we are reducing the number of flags hardcoded in targets, as https://github.com/rust-lang/rust/pull/83587 shows.

r? `@nagisa`
2021-03-28 08:53:51 +00:00
bors
3bfc85149e Auto merge of #83587 - petrochenkov:asneeded, r=nagisa
linker: Use `--as-needed` by default when linker supports it

Do it in a centralized way in `link.rs` instead of individual target specs.
Majority of relevant target specs were already passing it.
2021-03-28 01:00:25 +00:00
Vadim Petrochenkov
049a49b911 rustc_target: Avoid unwraps when adding linker flags 2021-03-28 02:28:48 +03:00
Vadim Petrochenkov
6615ee89be linker: Use --as-needed by default when linker supports it 2021-03-28 01:49:15 +03:00
bors
8cd7d86ce2 Auto merge of #83103 - petrochenkov:unilex, r=Aaron1011
resolve: Partially unify early and late scope-relative identifier resolution

Reuse `early_resolve_ident_in_lexical_scope` instead of a chunk of code in `resolve_ident_in_lexical_scope` doing the same job.

`early_resolve_ident_in_lexical_scope`/`visit_scopes` had to be slightly extended to be able to 1) start from a specific module instead of the current parent scope and 2) report one deprecation lint.
`early_resolve_ident_in_lexical_scope` still doesn't support walking through "ribs", that part is left in `resolve_ident_in_lexical_scope` (moreover, I'm pretty sure it's buggy, but that's a separate issue, cc https://github.com/rust-lang/rust/issues/52389 at least).
2021-03-27 22:19:17 +00:00
Vadim Petrochenkov
ee0357af3b resolve: Partially unify early and late scope-relative ident resolution 2021-03-27 23:38:17 +03:00
Dylan DPC
1115accccc
Rollup merge of #83548 - Aaron1011:capture-none-delims, r=petrochenkov
Always preserve `None`-delimited groups in a captured `TokenStream`

Previously, we would silently remove any `None`-delimiters when
capturing a `TokenStream`, 'flattenting' them to their inner tokens.
This was not normally visible, since we usually have
`TokenKind::Interpolated` (which gets converted to a `None`-delimited
group during macro invocation) instead of an actual `None`-delimited
group.

However, there are a couple of cases where this becomes visible to
proc-macros:
1. A cross-crate `macro_rules!` macro has a `None`-delimited group
   stored in its body (as a result of being produced by another
   `macro_rules!` macro). The cross-crate `macro_rules!` invocation
   can then expand to an attribute macro invocation, which needs
   to be able to see the `None`-delimited group.
2. A proc-macro can invoke an attribute proc-macro with its re-collected
   input. If there are any nonterminals present in the input, they will
   get re-collected to `None`-delimited groups, which will then get
   captured as part of the attribute macro invocation.

Both of these cases are incredibly obscure, so there hopefully won't be
any breakage. This change will allow more agressive 'flattenting' of
nonterminals in #82608 without losing `None`-delimited groups.
2021-03-27 20:37:12 +01:00
Dylan DPC
b2e254318d
Rollup merge of #82917 - cuviper:iter-zip, r=m-ou-se
Add function core::iter::zip

This makes it a little easier to `zip` iterators:

```rust
for (x, y) in zip(xs, ys) {}
// vs.
for (x, y) in xs.into_iter().zip(ys) {}
```

You can `zip(&mut xs, &ys)` for the conventional `iter_mut()` and
`iter()`, respectively. This can also support arbitrary nesting, where
it's easier to see the item layout than with arbitrary `zip` chains:

```rust
for ((x, y), z) in zip(zip(xs, ys), zs) {}
for (x, (y, z)) in zip(xs, zip(ys, zs)) {}
// vs.
for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {}
for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {}
```

It may also format more nicely, especially when the first iterator is a
longer chain of methods -- for example:

```rust
    iter::zip(
        trait_ref.substs.types().skip(1),
        impl_trait_ref.substs.types().skip(1),
    )
    // vs.
    trait_ref
        .substs
        .types()
        .skip(1)
        .zip(impl_trait_ref.substs.types().skip(1))
```

This replaces the tuple-pair `IntoIterator` in #78204.
There is prior art for the utility of this in [`itertools::zip`].

[`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
2021-03-27 20:37:07 +01:00
Dylan DPC
ebea9d948f
Rollup merge of #82626 - lcnr:encode_with_shorthandb, r=estebank
update array missing `IntoIterator` msg

fixes #82602

r? ```@estebank``` do you know whether we can use the expr span in `rustc_on_unimplemented`? The label isn't too great rn
2021-03-27 20:37:06 +01:00
Dylan DPC
a900677eb9
Rollup merge of #82525 - RalfJung:unaligned-ref-warn, r=petrochenkov
make unaligned_references future-incompat lint warn-by-default

and also remove the safe_packed_borrows lint that it replaces.

`std::ptr::addr_of!` has hit beta now and will hit stable in a month, so I propose we start fixing https://github.com/rust-lang/rust/issues/27060 for real: creating a reference to a field of a packed struct needs to eventually become a hard error; this PR makes it a warn-by-default future-incompat lint. (The lint already existed, this just raises its default level.) At the same time I removed the corresponding code from unsafety checking; really there's no reason an `unsafe` block should make any difference here.

For references to packed fields outside `unsafe` blocks, this means `unaligned_refereces` replaces the previous `safe_packed_borrows` warning with a link to https://github.com/rust-lang/rust/issues/82523 (and no more talk about unsafe blocks making any difference). So behavior barely changes, the warning is just worded differently. For references to packed fields inside `unsafe` blocks, this PR shows a new future-incompat warning.

Closes https://github.com/rust-lang/rust/issues/46043 because that lint no longer exists.
2021-03-27 20:37:05 +01:00
Dylan DPC
520c9a25df
Rollup merge of #81351 - lcnr:big-money-big-prices, r=oli-obk
combine: stop eagerly evaluating consts

`super_relate_consts` eagerly evaluates constants which doesn't seem too great.

I now also finally understand why all of the unused substs test passed. The reason being
that we just evaluated the constants in `super_relate_consts` 😆

While this change isn't strictly necessary as evaluating consts here doesn't hurt, it still feels a lot cleaner to do it this way

r? `@oli-obk` `@nikomatsakis`
2021-03-27 20:37:04 +01:00
Yuki Okushi
fa70398d6d
Rollup merge of #83526 - klensy:lazy-too, r=petrochenkov
lazily calls some fns

Replaced some fn's with it's lazy variants.
2021-03-28 01:33:16 +09:00
Yuki Okushi
973fb4b77f
Rollup merge of #83348 - osa1:issue83344, r=jackh726
format macro argument parsing fix

When the character next to `{}` is "shifted" (when mapping a byte index
in the format string to span) we should avoid shifting the span end
index, so first map the index of `}` to span, then bump the span,
instead of first mapping the next byte index to a span (which causes
bumping the end span too much).

Regression test added.

Fixes #83344

---

r? ```@estebank```
2021-03-28 01:33:13 +09:00
Ralf Jung
fb4f48e032 make unaligned_refereces future-incompat lint warn-by-default, and remove the safe_packed_borrows lint that it replaces 2021-03-27 16:59:37 +01:00
lcnr
e461dddf58 update tests 2021-03-27 16:38:23 +01:00
Bastian Kauschke
42150fb8a1 combine: stop eagerly evaluating consts 2021-03-27 16:38:23 +01:00
Ömer Sinan Ağacan
5b9bac2ab6 format macro argument parsing fix
When the character next to `{}` is "shifted" (when mapping a byte index
in the format string to span) we should avoid shifting the span end
index, so first map the index of `}` to span, then bump the span,
instead of first mapping the next byte index to a span (which causes
bumping the end span too much).

Regression test added.

Fixes #83344
2021-03-27 13:06:36 +03:00
klensy
229d199994 lazily calls some fns 2021-03-27 10:20:32 +03:00
Yuki Okushi
1b01e0d36a
Rollup merge of #83525 - rust-lang:lcnr-doc-patch, r=jonas-schievink
fix doc comment for `ty::Dynamic`
2021-03-27 12:37:25 +09:00
Yuki Okushi
d7216bae23
Rollup merge of #83343 - osa1:issue83340, r=jackh726
Simplify and fix byte skipping in format! string parser

Fixes '\\' handling in format strings.

Fixes #83340
2021-03-27 12:37:19 +09:00
Aaron Hill
f94360fd83
Always preserve None-delimited groups in a captured TokenStream
Previously, we would silently remove any `None`-delimiters when
capturing a `TokenStream`, 'flattenting' them to their inner tokens.
This was not normally visible, since we usually have
`TokenKind::Interpolated` (which gets converted to a `None`-delimited
group during macro invocation) instead of an actual `None`-delimited
group.

However, there are a couple of cases where this becomes visible to
proc-macros:
1. A cross-crate `macro_rules!` macro has a `None`-delimited group
   stored in its body (as a result of being produced by another
   `macro_rules!` macro). The cross-crate `macro_rules!` invocation
   can then expand to an attribute macro invocation, which needs
   to be able to see the `None`-delimited group.
2. A proc-macro can invoke an attribute proc-macro with its re-collected
   input. If there are any nonterminals present in the input, they will
   get re-collected to `None`-delimited groups, which will then get
   captured as part of the attribute macro invocation.

Both of these cases are incredibly obscure, so there hopefully won't be
any breakage. This change will allow more agressive 'flattenting' of
nonterminals in #82608 without losing `None`-delimited groups.
2021-03-26 23:32:18 -04:00
lcnr
5ac917dbb2 fix rustc_on_implemented _Self paths 2021-03-26 21:22:03 +01:00
lcnr
7ca2c981b2
fix doc comment for `ty::Dynamic 2021-03-26 19:52:09 +01:00
bors
5e65467eff Auto merge of #83488 - Aaron1011:ban-expr-inner-attrs, r=petrochenkov
Ban custom inner attributes in expressions and statements

Split out from https://github.com/rust-lang/rust/pull/82608

Custom inner attributes are unstable, so this won't break any stable users.
This allows us to speed up token collection, and avoid a redundant call to `collect_tokens_no_attrs` when parsing an `Expr` that has outer attributes.

r? `@petrochenkov`
2021-03-26 17:26:18 +00:00
Josh Stone
72ebebe474 Use iter::zip in compiler/ 2021-03-26 09:32:31 -07:00
bors
b8719c51e0 Auto merge of #83404 - michaelwoerister:issue83045, r=eddyb
Fix #83045 by moving some crate loading verification code to a better place

r? `@eddyb`
2021-03-26 14:39:02 +00:00
bors
e423058751 Auto merge of #82980 - tmiasko:import-cold-multiplier, r=michaelwoerister
Import small cold functions

The Rust code is often written under an assumption that for generic
methods inline attribute is mostly unnecessary, since for optimized
builds using ThinLTO, a method will be code generated in at least one
CGU and available for import.

For example, deref implementations for Box, Vec, MutexGuard, and
MutexGuard are not currently marked as inline, neither is identity
implementation of From trait.

In PGO builds, when functions are determined to be cold, the default
multiplier of zero will stop the import, no matter how trivial the
implementation.

Increase slightly the default multiplier from 0 to 0.1.

r? `@ghost`
2021-03-26 11:57:44 +00:00
Michael Woerister
09bab38291 Fix #83045 by moving some crate loading verification code to a better place. 2021-03-26 09:59:10 +01:00
bors
7637fd588b Auto merge of #83503 - Dylan-DPC:rollup-mqvjfav, r=Dylan-DPC
Rollup of 8 pull requests

Successful merges:

 - #83055 ([rustdoc] Don't document stripped items in JSON renderer.)
 - #83437 (Refactor #82270 as lint instead of an error)
 - #83444 (Fix bootstrap tests on beta)
 - #83456 (Add docs for Vec::from functions)
 - #83463 (ExitStatusExt: Fix missing word in two docs messages)
 - #83470 (Fix patch note about #80653 not mentioning nested nor recursive)
 - #83485 (Mark asm tests as requiring LLVM 10.0.1)
 - #83486 (Don't ICE when using `#[global_alloc]` on a non-item statement)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-03-26 04:10:13 +00:00
Dylan DPC
b0bec95534
Rollup merge of #83486 - Aaron1011:fix/global-alloc-error, r=petrochenkov
Don't ICE when using `#[global_alloc]` on a non-item statement

Fixes #83469

We need to return an `Annotatable::Stmt` if we were passed an
`Annotatable::Stmt`
2021-03-26 02:34:45 +01:00
Dylan DPC
02b27cd79e
Rollup merge of #83437 - Amanieu:asm_syntax, r=petrochenkov
Refactor #82270 as lint instead of an error

This PR fixes several issues with #82270 which generated an error when `.intel_syntax` or `.att_syntax` was used in inline assembly:
- It is now a warn-by-default lint instead of an error.
- The lint only triggers on x86. `.intel_syntax` and `.att_syntax` are only valid on x86.
- The lint no longer provides machine-applicable suggestions for two reasons:
	- These changes should not be made automatically since changes to assembly code can be very subtle.
	- The template string is not always just a string: it can contain macro invocation (`concat!`), raw strings, escape characters, etc.

cc ``@asquared31415``
2021-03-26 02:34:39 +01:00
bors
0ced530534 Auto merge of #83465 - michaelwoerister:safe-read_raw_bytes, r=cjgillot
Allow for reading raw bytes from rustc_serialize::Decoder without unsafe code

The current `read_raw_bytes` method requires using `MaybeUninit` and `unsafe`. I don't think this is necessary. Let's see if a safe interface has any performance drawbacks.

This is a followup to #83273 and will make it easier to rebase #82183.

r? `@cjgillot`
2021-03-26 01:28:59 +00:00
Aaron Hill
7504b9bb96
Avoid double-collection for expression nonterminals 2021-03-25 18:05:49 -04:00
Aaron Hill
fe60f19f7e
Ban custom inner attributes in expressions and statements 2021-03-25 18:05:30 -04:00
Aaron Hill
8ecd931a8e
Don't ICE when using #[global_alloc] on a non-item statement
Fixes #83469

We need to return an `Annotatable::Stmt` if we were passed an
`Annotatable::Stmt`
2021-03-25 15:41:31 -04:00
bors
52e3dffa50 Auto merge of #82743 - jackh726:resolve-refactor, r=nikomatsakis
Refactor rustc_resolve::late::lifetimes to resolve per-item

There are some changes to tests that I'd like some feedback on; so this is still WIP.

The reason behind this change will (hopefully) allow us to (as part of #76814) be able to essentially use the lifetime resolve code to resolve *all* late bound vars (including those of super traits). Currently, it only resolves those that are *syntactically* in scope. In #76814, I'm essentially finding that I would essentially have to redo the passing of bound vars through scopes (i.e. when instantiating a poly trait ref), and that's what this code does anyways. However, to be able to do this (ask super traits what bound vars are in scope), we have to be able to resolve items separately.

The first commit is actually partially orthogonal. Essentially removing one use of late bound debruijn indices.

Not exactly sure who would be best to review here.
Let r? `@nikomatsakis`
2021-03-25 19:28:16 +00:00
bors
cb473c2c5b Auto merge of #83424 - cjgillot:noparam, r=lcnr
GenericParam does not need to be a HIR owner.

The special case is not required.

Universal impl traits design to regular generic parameters, and their content is owned by the enclosing item.

Existential (and opaque) impl traits generate their own enclosing item, and are collected through it.
2021-03-25 16:35:19 +00:00