Commit graph

435 commits

Author SHA1 Message Date
lcnr
0c28e028b6 feature(const_generics) -> feature(const_param_types) 2021-08-30 11:00:21 +02:00
Ellen
fcc2badf9b rename const_evaluatable_checked to generic_const_exprs
2021-08-30 11:00:21 +02:00
Aaron Hill
c9157efad6
Don't use guess_head_span in predicates_of for foreign span
Previously, the result of `predicates_of` for a foreign trait
would depend on the *current* state of the corresponding source
file in the foreign crate. This could lead to ICEs during incremental
compilation, since the on-disk contents of the upstream source file
could potentially change without the upstream crate being recompiled.

Additionally, this ensure that that the metadata we produce for a crate
only depends on its *compiled* upstream dependencies (e.g an rlib or
rmeta file), *not* the current on-disk state of the upstream crate
source files.
2021-08-27 23:19:49 -05:00
Michael Woerister
af1b65cb18 Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix. 2021-08-27 11:50:44 +02:00
Jacob Lifshay
5802f60355 add support for clobbering xer, cr, and cr[0-7] for asm! on OpenPower/PowerPC
Fixes #88315
2021-08-25 22:08:27 -07:00
Léo Lanteri Thauvin
fde1b76b4b Use if-let guards in the codebase 2021-08-25 20:24:35 +02:00
Frank Steffahn
2f9ddf3bc7 Fix typos “an”→“a” and a few different ones that appeared in the same search 2021-08-22 18:15:49 +02:00
Guillaume Gomez
09d56a749c
Rollup merge of #88050 - Aaron1011:filename-hash-stable, r=michaelwoerister
Remove `HashStable` impls for `FileName` and `RealFileName`

These impls were unused, and incorrectly hashed the local
(non-remapped) path for `RealFileName::Remapped` (which would
break reproducible builds if these impls were used).
2021-08-19 19:30:07 +02:00
bors
0035d9dcec Auto merge of #87050 - jyn514:no-doc-primitive, r=manishearth
Add future-incompat lint for `doc(primitive)`

## What is `doc(primitive)`?

`doc(primitive)` is an attribute recognized by rustdoc which adds documentation for the built-in primitive types, such as `usize` and `()`. It has been stable since Rust 1.0.

## Why change anything?

`doc(primitive)` is useless for anyone outside the standard library. Since rustdoc provides no way to combine the documentation on two different primitive items, you can only replace the docs, and since the standard library already provides extensive documentation there is no reason to do so.

While fixing rustdoc's handling of primitive items (https://github.com/rust-lang/rust/pull/87073) I discovered that even rustdoc's existing handling of primitive items was broken if you had more than two crates using it (it would pick randomly between them). That meant both:
- Keeping rustdoc's existing treatment was nigh-impossible, because it was random.
- doc(primitive) was even more useless than it would otherwise be.

The only use-case for this outside the standard library is for no-std libraries which want to link to primitives (https://github.com/rust-lang/rust/issues/73423) which is being fixed in https://github.com/rust-lang/rust/pull/87073.

https://github.com/rust-lang/rust/pull/87073 makes various breaking changes to `doc(primitive)` (breaking in the sense that they change the semantics, not in that they cause code to fail to compile). It's not possible to avoid these and still fix rustdoc's issues.

## What can we do about it?

As shown by the crater run (https://github.com/rust-lang/rust/pull/87050#issuecomment-886166706), no one is actually using doc(primitive), there wasn't a single true regression in the whole run. We can either:
1. Feature gate it completely, breaking anyone who crater missed. They can easily fix the breakage just by removing the attribute.
2. add it to the `INVALID_DOC_ATTRIBUTES` future-incompat lint, and at the same time make it a no-op unless you add a feature gate. That would mean rustdoc has to look at the features of dependent crates, because it needs to know where primitives are defined in order to link to them.
3. add it to `INVALID_DOC_ATTRIBUTES`, but still use it to determine where primitives come from
4. do nothing; the behavior will silently change in https://github.com/rust-lang/rust/pull/87073.

My preference is for 2, but I would also be happy with 1 or 3. I don't think we should silently change the behavior.

This PR currently implements 3.
2021-08-16 15:36:44 +00:00
bors
92f3753b07 Auto merge of #84039 - jyn514:uplift-atomic-ordering, r=wesleywiser
Uplift the invalid_atomic_ordering lint from clippy to rustc

This is mostly just a rebase of https://github.com/rust-lang/rust/pull/79654; I've copy/pasted the text from that PR below.

r? `@lcnr` since you reviewed the last one, but feel free to reassign.

---

This is an implementation of https://github.com/rust-lang/compiler-team/issues/390.

As mentioned, in general this turns an unconditional runtime panic into a (compile time) lint failure. It has no false positives, and the only false negatives I'm aware of are if `Ordering` isn't specified directly and is comes from an argument/constant/whatever.

As a result of it having no false positives, and the alternative always being strictly wrong, it's on as deny by default. This seems right.

In the [zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Uplift.20the.20.60invalid_atomic_ordering.60.20lint.20from.20clippy/near/218483957) `@joshtriplett` suggested that lang team should FCP this before landing it. Perhaps libs team cares too?

---

Some notes on the code for reviewers / others below

## Changes from clippy

The code is changed from [the implementation in clippy](68cf94f6a6/clippy_lints/src/atomic_ordering.rs) in the following ways:

1. Uses `Symbols` and `rustc_diagnostic_item`s instead of string literals.
    - It's possible I should have just invoked Symbol::intern for some of these instead? Seems better to use symbol, but it did require adding several.
2. The functions are moved to static methods inside the lint struct, as a way to namespace them.
    - There's a lot of other code in that file — which I picked as the location for this lint because `@jyn514` told me that seemed reasonable.
3. Supports unstable AtomicU128/AtomicI128.
    - I did this because it was almost easier to support them than not — not supporting them would have (ideally) required finding a way not to give them a `rustc_diagnostic_item`, which would have complicated an already big macro.
    - These don't have tests since I wasn't sure if/how I should make tests conditional on whether or not the target has the atomic... This is to a certain extent an issue of 64bit atomics too, but 128-bit atomics are much less common. Regardless, the existing tests should be *more* than thorough enough here.
4. Minor changes like:
    - grammar tweaks ("loads cannot have `Release` **and** `AcqRel` ordering" => "loads cannot have `Release` **or** `AcqRel` ordering")
    - function renames (`match_ordering_def_path` => `matches_ordering_def_path`),
    - avoiding clippy-specific helper methods that don't exist in rustc_lint and didn't seem worth adding for this case (for example `cx.struct_span_lint` vs clippy's `span_lint_and_help` helper).

## Potential issues

(This is just about the code in this PR, not conceptual issues with the lint or anything)

1. I'm not sure if I should have used a diagnostic item for `Ordering` and its variants (I couldn't figure out how really, so if I should do this some pointers would be appreciated).
    - It seems possible that failing to do this might possibly mean there are more cases this lint would miss, but I don't really know how `match_def_path` works and if it has any pitfalls like that, so maybe not.

2. I *think* I deprecated the lint in clippy (CC `@flip1995` who asked to be notified about clippy changes in the future in [this comment](https://github.com/rust-lang/rust/pull/75671#issuecomment-718731659)) but I'm not sure if I need to do anything else there.
    - I'm kind of hoping CI will catch if I missed anything, since `x.py test src/tools/clippy` fails with a lot of errors with and without my changes (and is probably a nonsense command regardless). Running `cargo test` from src/tools/clippy also fails with unrelated errors that seem like refactorings that didnt update clippy? So, honestly no clue.

3. I wasn't sure if the description/example I gave good. Hopefully it is. The example is less thorough than the one from clippy here: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering. Let me know if/how I should change it if it needs changing.

4. It pulls in the `if_chain` crate. This crate was already used in clippy, and seems like it's used elsewhere in rustc, but I'm willing to rewrite it to not use this if needed (I'd prefer not to, all things being equal).
2021-08-16 06:36:13 +00:00
Joshua Nelson
03df65497e feature gate doc(primitive) 2021-08-16 05:41:16 +00:00
Thom Chiovoloni
402a9c9f5e Uplift the invalid_atomic_ordering lint from clippy to rustc
- Deprecate clippy::invalid_atomic_ordering
- Use rustc_diagnostic_item for the orderings in the invalid_atomic_ordering lint
- Reduce code duplication
- Give up on making enum variants diagnostic items and just look for
`Ordering` instead

  I ran into tons of trouble with this because apparently the change to
  store HIR attrs in a side table also gave the DefIds of the
  constructor instead of the variant itself. So I had to change
  `matches_ordering` to also check the grandparent of the defid as well.

- Rename `atomic_ordering_x` symbols to just the name of the variant
- Fix typos in checks - there were a few places that said "may not be
  Release" in the diagnostic but actually checked for SeqCst in the lint.
- Make constant items const
- Use fewer diagnostic items
- Only look at arguments after making sure the method matches

  This prevents an ICE when there aren't enough arguments.

- Ignore trait methods
- Only check Ctors instead of going through `qpath_res`

  The functions take values, so this couldn't ever be anything else.

- Add if_chain to allowed dependencies
- Fix grammar
- Remove unnecessary allow
2021-08-16 03:55:27 +00:00
Aaron Hill
d8c3a649a6
Remove HashStable impls for FileName and RealFileName
These impls were unused, and incorrectly hashed the local
(non-remapped) path for `RealFileName::Remapped` (which would
break reproducible builds if these impls were used).
2021-08-15 10:48:53 -05:00
bors
85109e257a Auto merge of #87581 - Amanieu:asm_clobber_abi, r=nagisa
Add support for clobber_abi to asm!

This PR adds the `clobber_abi` feature that was proposed in #81092.

Fixes #81092

cc `@rust-lang/wg-inline-asm`

r? `@nagisa`
2021-08-14 22:29:27 +00:00
Gary Guo
1fb1643129 Implement black_box using intrinsic
The new implementation allows some `memcpy`s to be optimized away,
so the uninit value in ui/sanitize/memory.rs is constructed directly
onto the return place. Therefore the sanitizer now says that the
value is allocated by `main` rather than `random`.
2021-08-12 16:16:57 +01:00
Amanieu d'Antras
3fd463a5ca Add support for clobber_abi to asm! 2021-08-12 12:43:11 +01:00
bors
e91405b9d5 Auto merge of #87262 - dtolnay:negative, r=Aaron1011
Support negative numbers in Literal::from_str

proc_macro::Literal has allowed negative numbers in a single literal token ever since Rust 1.29, using https://doc.rust-lang.org/stable/proc_macro/struct.Literal.html#method.isize_unsuffixed and similar constructors.

```rust
let lit = proc_macro::Literal::isize_unsuffixed(-10);
```

However, the suite of constructors on Literal is not sufficient for all use cases, for example arbitrary precision floats, or custom suffixes in FFI macros.

```rust
let lit = proc_macro::Literal::f64_unsuffixed(0.101001000100001000001000000100000001); // :(
let lit = proc_macro::Literal::i???_suffixed(10ulong); // :(
```

For those, macros construct the literal using from_str instead, which preserves arbitrary precision, custom suffixes, base, and digit grouping.

```rust
let lit = "0.101001000100001000001000000100000001".parse::<Literal>().unwrap();
let lit = "10ulong".parse::<Literal>().unwrap();
let lit = "0b1000_0100_0010_0001".parse::<Literal>().unwrap();
```

However, until this PR it was not possible to construct a literal token that is **both** negative **and** preserving of arbitrary precision etc.

This PR fixes `Literal::from_str` to recognize negative integer and float literals.
2021-08-03 04:50:28 +00:00
Cameron Steffen
14f3418f79
Rollup merge of #86176 - nbdd0121:explicit-generic-args, r=jackh726
Implement a `explicit_generic_args_with_impl_trait` feature gate

Implements #83701

When this gate is enabled, explicit generic arguments can be specified even if `impl Trait` is used in argument position. Generic arguments can only be specified for explicit generic parameters but not for the synthetic type parameters from  `impl Trait`

So code like this will be accepted:
```rust
#![feature(explicit_generic_args_with_impl_trait)]

fn foo<T: ?Sized>(_f: impl AsRef<T>) {}
fn main() {
    foo::<str>("".to_string());
}
```
2021-08-02 09:36:49 -05:00
bors
b53a93db2d Auto merge of #87535 - lf-:authors, r=Mark-Simulacrum
rfc3052 followup: Remove authors field from Cargo manifests

Since RFC 3052 soft deprecated the authors field, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information for contributors, we may as well
remove it from crates in this repo.
2021-08-02 05:49:17 +00:00
Gary Guo
9b90e7e980 Implement a explicit_generic_args_with_impl_trait feature gate
When this gate is enabled, explicit generic arguments can be specified even
if `impl Trait` is used in argument position. Generic arguments can only be
specified for explicit generic parameters but not for the synthetic type
parameters from  `impl Trait`
2021-08-02 04:17:01 +01:00
Alexander Regueiro
2dc86a6450 Added feature gate. 2021-07-31 00:51:38 +08:00
Jade
3cf820e17d rfc3052: Remove authors field from Cargo manifests
Since RFC 3052 soft deprecated the authors field anyway, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information, we should remove it from
crates in this repo.
2021-07-29 14:56:05 -07:00
Jonas Schievink
dbd126901a Add feature gates for for and ? in consts 2021-07-29 23:21:54 +02:00
Mara Bos
b64c4f9560 Add new const_format_args!() macro and use it in panics. 2021-07-28 16:12:25 +02:00
Mara Bos
f827d3e285 Make const panic!("..") work in Rust 2021.
During const eval, this replaces calls to core::panicking::panic_fmt and
std::panicking::being_panic_fmt with a call to a new const fn:
core::panicking::const_panic_fmt. That function uses
fmt::Arguments::as_str() to get the str and calls panic_str with that
instead.

panic!() invocations with formatting arguments are still not accepted,
as the creation of such a fmt::Arguments cannot be done in constant
functions right now.
2021-07-28 16:10:41 +02:00
Jacob Pratt
c70147fd66
Permit deriving default on enums with #[default] 2021-07-27 15:47:47 -04:00
kadmin
8759f00c73 Actually infer args in visitors 2021-07-26 21:15:18 +00:00
Charles Lew
ab171c5279 Add internal attribute and tests. 2021-07-20 22:14:43 +08:00
bors
d5af63480f Auto merge of #87225 - estebank:cleanup, r=oli-obk
Various diagnostics clean ups/tweaks

* Always point at macros, including derive macros
* Point at non-local items that introduce a trait requirement
* On private associated item, point at definition
2021-07-19 18:44:27 +00:00
Esteban Küber
ba052bd8de Various diagnostics clean ups/tweaks
* Always point at macros, including derive macros
* Point at non-local items that introduce a trait requirement
* On private associated item, point at definition
2021-07-19 08:43:35 -07:00
David Tolnay
55ff45a5c2
Support negative numbers in Literal::from_str 2021-07-18 14:08:34 -07:00
Yuki Okushi
07faa2e32c
Rollup merge of #87170 - xFrednet:clippy-5393-add-diagnostic-items, r=Manishearth,oli-obk
Add diagnostic items for Clippy

This adds a bunch of diagnostic items to `std`/`core`/`alloc` functions, structs and traits used in Clippy. The actual refactorings in Clippy to use these items will be done in a different PR in Clippy after the next sync.

This PR doesn't include all paths Clippy uses, I've only gone through the first 85 lines of Clippy's [`paths.rs`](ecf85f4bdc/clippy_utils/src/paths.rs) (after rust-lang/rust-clippy#7466) to get some feedback early on. I've also decided against adding diagnostic items to methods, as it would be nicer and more scalable to access them in a nicer fashion, like adding a `is_diagnostic_assoc_item(did, sym::Iterator, sym::map)` function or something similar (Suggested by `@camsteffen` [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Diagnostic.20Item.20Naming.20Convention.3F/near/225024603))

There seems to be some different naming conventions when it comes to diagnostic items, some use UpperCamelCase (`BinaryHeap`) and some snake_case (`hashmap_type`). This PR uses UpperCamelCase for structs and traits and snake_case with the module name as a prefix for functions. Any feedback on is this welcome.

cc: rust-lang/rust-clippy#5393

r? `@Manishearth`
2021-07-18 14:21:57 +09:00
Camille GILLOT
b35ceeeec7 Simplify Expn creation. 2021-07-17 19:41:14 +02:00
Camille GILLOT
dddaa6d068 Rename expn_info -> expn_data. 2021-07-17 19:41:13 +02:00
Camille GILLOT
0f8573e57b Pass ExpnData by reference. 2021-07-17 19:41:12 +02:00
Camille GILLOT
41c1f39fa8 Drop ExpnData::krate. 2021-07-17 19:41:10 +02:00
Camille GILLOT
dbd2d77641 Drop orig_id. 2021-07-17 19:41:09 +02:00
Camille GILLOT
37a13def48 Encode ExpnId using ExpnHash for incr. comp. 2021-07-17 19:41:08 +02:00
Camille GILLOT
2fe37c5bd1 Choose encoding format in caller code. 2021-07-17 19:41:07 +02:00
Camille GILLOT
078dd37f88 Use LocalExpnId where possible. 2021-07-17 19:41:02 +02:00
Camille GILLOT
6e78d6c9d6 Make the CrateNum part of the ExpnId. 2021-07-17 19:35:33 +02:00
xFrednet
67002db2cf Corrected symbol order after adding diagnostic items 2021-07-17 12:20:43 +02:00
xFrednet
d38f2b0cc1 Added diagnostic items to structs and traits for Clippy 2021-07-15 23:57:02 +02:00
xFrednet
1a900042ab Added diagnostic items to functions for Clippy 2021-07-15 23:47:03 +02:00
Camille GILLOT
c2d43e1329 Simplify metadata decoding. 2021-07-15 19:31:47 +02:00
Camille GILLOT
47ea2ae933 Separate encoding paths.
The two paths will be modified independently in the next few commits.
2021-07-15 19:31:46 +02:00
bors
2155386f31 Auto merge of #87106 - Mark-Simulacrum:edition-no-clone, r=petrochenkov
Avoid cloning ExpnData to access Span edition

ExpnData is a fairly hefty structure to clone; cloning it may not be cheap. In
some cases this may get optimized out, but it's not clear that will always be
the case. Try to avoid that cost.

r? `@ghost` -- opening for a perf run to start with
2021-07-14 01:41:12 +00:00
bors
c7d6bcc788 Auto merge of #87044 - cjgillot:expnhash, r=petrochenkov
Cache expansion hash globally

... instead of computing it multiple times.

Split from #86676
r? `@petrochenkov`
2021-07-13 22:32:58 +00:00
Camille GILLOT
616ce3c5c0 Cache expansion hash. 2021-07-13 23:10:56 +02:00
Camille GILLOT
cff0ea5f88 Move HashStable implementations. 2021-07-13 23:10:55 +02:00
Mark Rousskov
7d373c9c11 Avoid cloning ExpnData to access Span edition
ExpnData is a fairly hefty structure to clone; cloning it may not be cheap. In
some cases this may get optimized out, but it's not clear that will always be
the case. Try to avoid that cost.
2021-07-13 10:57:10 -04:00
bors
ca99e3eb3a Auto merge of #86922 - joshtriplett:target-abi, r=oli-obk
target abi

Implement cfg(target_abi) (RFC 2992)

Add an `abi` field to `TargetOptions`, defaulting to "". Support using
`cfg(target_abi = "...")` for conditional compilation on that field.

Gated by `feature(cfg_target_abi)`.

Add a test for `target_abi`, and a test for the feature gate.

Add `target_abi` to tidy as a platform-specific cfg.

Update targets to use `target_abi`

All eabi targets have `target_abi = "eabi".`
All eabihf targets have `target_abi = "eabihf"`.
`armv6_unknown_freebsd` and `armv7_unknown_freebsd` have `target_abi = "eabihf"`.
All abi64 targets have `target_abi = "abi64"`.
All ilp32 targets have `target_abi = "ilp32"`.
All softfloat targets have `target_abi = "softfloat"`.
All *-uwp-windows-* targets have `target_abi = "uwp"`.
All spe targets have `target_abi = "spe"`.
All macabi targets have `target_abi = "macabi"`.
aarch64-apple-ios-sim has `target_abi = "sim"`.
`x86_64-fortanix-unknown-sgx` has `target_abi = "fortanix"`.
`x86_64-unknown-linux-gnux32` has `target_abi = "x32"`.

Add FIXME entries for targets for which existing values need to change
once `cfg_target_abi` becomes stable. (All of them are tier 3 targets.)

Add a test for `target_abi` in `--print cfg`.
2021-07-13 12:25:10 +00:00
bors
394804bb23 Auto merge of #86857 - fee1-dead:add-attr, r=oli-obk
Add #[default_method_body_is_const]

`@rustbot` label F-const_trait_impl
2021-07-13 06:59:34 +00:00
bors
4581c4ef6f Auto merge of #87042 - petrochenkov:cleanquotspan, r=Aaron1011
Cleanup span quoting

I finally got to reviewing https://github.com/rust-lang/rust/pull/84278.
See the individual commit messages.
r? `@Aaron1011`
2021-07-11 08:46:43 +00:00
bors
99f8efec46 Auto merge of #86416 - Amanieu:asm_clobber_only, r=nagisa
Add clobber-only register classes for asm!

These are needed to properly express a function call ABI using a clobber
list, even though we don't support passing actual values into/out of
these registers.
2021-07-11 01:06:58 +00:00
Vadim Petrochenkov
4ba91a063d rustc_span: Reorder some ExpnData fields in accordance with comments
A drive-by change.
2021-07-11 00:40:25 +03:00
Vadim Petrochenkov
28f4dba438 rustc_span: Revert addition of proc_macro field to ExpnKind::Macro
The flag has a vague meaning and is used for a single diagnostic change that is low benefit and appears only under `-Z macro_backtrace`.
2021-07-10 23:03:35 +03:00
Amanieu d'Antras
e1c3f5e017 Add clobber-only register classes for asm!
These are needed to properly express a function call ABI using a clobber
list, even though we don't support passing actual values into/out of
these registers.
2021-07-10 17:29:00 +02:00
Deadbeef
2db927d8d8
Add #[default_method_body_is_const] 2021-07-10 20:54:44 +08:00
Mara Bos
ad10107600
Rollup merge of #86881 - tmiasko:lookup-line, r=nagisa
Inline implementation of lookup_line

to avoid unnecessary conversions from `Option<usize>` to `isize` and back.
2021-07-09 16:20:32 +02:00
bors
ee86f96ba1 Auto merge of #85828 - scottmcm:raw-eq, r=oli-obk
Stop generating `alloca`s & `memcmp` for simple short array equality

Example:
```rust
pub fn demo(x: [u16; 6], y: [u16; 6]) -> bool { x == y }
```

Before:
```llvm
define zeroext i1 `@_ZN10playground4demo17h48537f7eac23948fE(i96` %0, i96 %1) unnamed_addr #0 {
start:
  %y = alloca [6 x i16], align 8
  %x = alloca [6 x i16], align 8
  %.0..sroa_cast = bitcast [6 x i16]* %x to i96*
  store i96 %0, i96* %.0..sroa_cast, align 8
  %.0..sroa_cast3 = bitcast [6 x i16]* %y to i96*
  store i96 %1, i96* %.0..sroa_cast3, align 8
  %_11.i.i.i = bitcast [6 x i16]* %x to i8*
  %_14.i.i.i = bitcast [6 x i16]* %y to i8*
  %bcmp.i.i.i = call i32 `@bcmp(i8*` nonnull dereferenceable(12) %_11.i.i.i, i8* nonnull dereferenceable(12) %_14.i.i.i, i64 12) #2, !alias.scope !2
  %2 = icmp eq i32 %bcmp.i.i.i, 0
  ret i1 %2
}
```
```x86
playground::demo: # `@playground::demo`
	sub	rsp, 32
	mov	qword ptr [rsp], rdi
	mov	dword ptr [rsp + 8], esi
	mov	qword ptr [rsp + 16], rdx
	mov	dword ptr [rsp + 24], ecx
	xor	rdi, rdx
	xor	esi, ecx
	or	rsi, rdi
	sete	al
	add	rsp, 32
	ret
```

After:
```llvm
define zeroext i1 `@_ZN4mini4demo17h7a8994aaa314c981E(i96` %0, i96 %1) unnamed_addr #0 {
start:
  %2 = icmp eq i96 %0, %1
  ret i1 %2
}
```
```x86
_ZN4mini4demo17h7a8994aaa314c981E:
	xor	rcx, r8
	xor	edx, r9d
	or	rdx, rcx
	sete	al
	ret
```
2021-07-09 09:16:27 +00:00
bors
95fb131521 Auto merge of #86904 - m-ou-se:prelude-collision-check-trait, r=nikomatsakis
Check FromIterator trait impl in prelude collision check.

Fixes #86902.
2021-07-09 06:35:42 +00:00
Scott McMurray
2456495a26 Stop generating allocas+memcmp for simple array equality 2021-07-08 14:55:54 -07:00
Tomasz Miąsko
1719d45013 Inline implementation of lookup_line
to simplify the implementation and avoid unnecessary
conversions from `Option<usize>` to `isize` and back.
2021-07-08 23:30:53 +02:00
Guillaume Gomez
d12b16887b
Rollup merge of #86726 - sexxi-goose:use-diagnostic-item-for-rfc2229-migration, r=nikomatsakis
Use diagnostic items instead of lang items for rfc2229 migrations

This PR removes the `Send`, `UnwindSafe` and `RefUnwindSafe` lang items introduced in https://github.com/rust-lang/rust/pull/84730, and uses diagnostic items instead to check for `Send`, `UnwindSafe` and `RefUnwindSafe` traits for RFC2229 migrations.

r? ```@nikomatsakis```
2021-07-08 18:30:33 +02:00
Guillaume Gomez
a2654fb64c Rework SESSION_GLOBALS API to prevent overwriting it 2021-07-08 16:16:28 +02:00
Josh Triplett
84d6e8aed3 Implement cfg(target_abi) (RFC 2992)
Add an `abi` field to `TargetOptions`, defaulting to "". Support using
`cfg(target_abi = "...")` for conditional compilation on that field.

Gated by `feature(cfg_target_abi)`.

Add a test for `target_abi`, and a test for the feature gate.

Add `target_abi` to tidy as a platform-specific cfg.

This does not add an abi to any existing target.
2021-07-07 08:52:35 -07:00
Mara Bos
60535441c8 Check FromIterator trait impl in prelude collision check. 2021-07-07 13:26:38 +00:00
bors
d04ec47358 Auto merge of #86143 - bjorn3:revert_revert_merge_crate_disambiguator, r=michaelwoerister
Reland "Merge CrateDisambiguator into StableCrateId"

Reverts https://github.com/rust-lang/rust/pull/85891 as this revert of #85804 made perf even worse.

r? `@Mark-Simulacrum`
2021-07-06 11:31:59 +00:00
bjorn3
489ad8b8b5 Revert "Revert "Merge CrateDisambiguator into StableCrateId""
This reverts commit 8176ab8bc1.
2021-07-06 11:28:04 +02:00
Camille GILLOT
3162c37b59 Store macro parent module in ExpnData. 2021-07-06 08:07:06 +02:00
bors
96859dbaf6 Auto merge of #86778 - tmiasko:fast-multiline, r=davidtwco
Avoid byte to char position conversions in `is_multiline`

Converting a byte position into a char position is currently linear in
the number of multibyte characters in the source code. Avoid it when
checking if a range spans across lines.

This makes it feasible to compile source files with a large number of
multibyte characters.
2021-07-03 16:06:35 +00:00
Tomasz Miąsko
7a410763fa Avoid byte to char position conversions in is_multiline
Converting a byte position into a char position is currently linear in
the number of multibyte characters in the source code. Avoid it when
checking if a range spans across lines.

This makes it feasible to compile source files with a large number of
multibyte characters.
2021-07-01 13:30:00 +02:00
Roxane Fruytier
3e569dd2df Remove lang items Send, UnwindSafe and RefUnwindSafe 2021-06-29 17:47:57 -04:00
Josh Triplett
ab0f63ecdf rustc_span: Explicitly handle crates that differ from package names
The sha-1 and md-5 packages contain crates named sha1 and md5,
respectively. This discrepancy makes it somewhat more challenging to
automate detection of unused crates. Explicitly rename the packages to
the names of the crates they contain, to simplify such detection.
2021-06-24 23:48:53 -07:00
bors
8cb207ae69 Auto merge of #86386 - inquisitivecrystal:better-errors-for-display-traits-v3, r=estebank
Better errors for Debug and Display traits

Currently, if someone tries to pass value that does not implement `Debug` or `Display` to a formatting macro, they get a very verbose and confusing error message. This PR changes the error messages for missing `Debug` and `Display` impls to be less overwhelming in this case, as suggested by #85844. I was a little less aggressive in changing the error message than that issue proposed. Still, this implementation would be enough to reduce the number of messages to be much more manageable.

After this PR, information on the cause of an error involving a `Debug` or `Display` implementation would suppressed if the requirement originated within a standard library macro. My reasoning was that errors originating from within a macro are confusing when they mention details that the programmer can't see, and this is particularly problematic for `Debug` and `Display`, which are most often used via macros. It is possible that either a broader or a narrower criterion would be better. I'm quite open to any feedback.

Fixes #85844.
2021-06-23 03:16:04 +00:00
bors
80926fc409 Auto merge of #86368 - michaelwoerister:lexing-ice, r=davidtwco
Disambiguate between SourceFiles from different crates even if they have the same path

This PR fixes an ICE that can occur when the compiler encounters a source file that is part of both the local crate and an upstream crate:

1. While importing source files from an upstream crate the compiler creates a `SourceFile` entry for `foo.rs` in the `SourceMap`. Since this is an imported source file its `src` field is `None`.
2. At a later point the parser encounters `foo.rs` again. It tells the `SourceMap` to load the file but because we already have an entry for `foo.rs` the `SourceMap` will return the existing version with `src == None`.
3. The parser proceeds under the assumption that `src.is_some()` and panics when actually trying to use the file's contents.

This PR fixes the issue by adding the source file's associated `CrateNum` to the `SourceMap`'s interning key. As a consequence the two instances of the file will each have a separate entry in the `SourceMap`. They just happen to share the same file path. This approach seemed less problematic to me than trying to mutate the `SourceFile` after it had already been created.

Another, more involved, approach might be to merge the `src` and the `external_src` field.

Fixes #85955
2021-06-22 14:53:58 +00:00
bors
44f4a87d70 Auto merge of #85707 - jam1garner:future_prelude_collision_lint, r=nikomatsakis
Add `future_prelude_collision` lint

Implements #84594. (RFC rust-lang/rfcs#3114 ([rendered](https://github.com/rust-lang/rfcs/blob/master/text/3114-prelude-2021.md))) Not entirely complete but wanted to have my progress decently available while I finish off the last little bits.

Things left to implement:

* [x] UI tests for lints
* [x] Only emit lint for 2015 and 2018 editions
* [ ] Lint name/message bikeshedding
* [x] Implement for `FromIterator` (from best I can tell, the current approach as mentioned from [this comment](https://github.com/rust-lang/rust/issues/84594#issuecomment-847288288) won't work due to `FromIterator` instances not using dot-call syntax, but if I'm correct about this then that would also need to be fixed for `TryFrom`/`TryInto`)*
* [x] Add to `rust-2021-migration` group? (See #85512) (added to `rust-2021-compatibility` group)
* [ ] Link to edition guide in lint docs

*edit: looked into it, `lookup_method` will also not be hit for `TryFrom`/`TryInto` for non-dotcall syntax. If anyone who is more familiar with typecheck knows the equivalent for looking up associated functions, feel free to chime in.
2021-06-22 07:01:54 +00:00
bors
4573a4a879 Auto merge of #86383 - shamatar:slice_len_lowering, r=bjorn3
Add MIR pass to lower call to `core::slice::len` into `Len` operand

During some larger experiment with range analysis I've found that code like `let l = slice.len()` produces different MIR then one found in bound checks. This optimization pass replaces terminators that are calls to `core::slice::len` with just a MIR operand and Goto terminator.

It uses some heuristics to remove the outer borrow that is made to call `core::slice::len`, but I assume it can be eliminated, just didn't find how.

Would like to express my gratitude to `@oli-obk` who helped me a lot on Zullip
2021-06-21 22:24:13 +00:00
Michael Woerister
c3c4ab5ed2 Encode SourceFile source crate as StableCrateId in incr. comp. OnDiskCache. 2021-06-21 15:30:16 +02:00
Michael Woerister
47327145e3 Disambiguate between SourceFiles from different crates even if they have the same path. 2021-06-21 13:38:46 +02:00
Alex Vlasov
aa53928ed7 Squashed implementation of the pass 2021-06-20 16:09:42 +02:00
Yuki Okushi
34f38bf760
Make s pre-interned 2021-06-17 09:45:19 +09:00
Aris Merchant
f1f1c9b25b Improve errors for missing Debug and Display impls 2021-06-16 01:13:28 -07:00
Yuki Okushi
5936ecc24f
Rollup merge of #85608 - scottmcm:stabilize-control-flow-enum-basics, r=m-ou-se
Stabilize `ops::ControlFlow` (just the type)

Tracking issue: https://github.com/rust-lang/rust/issues/75744 (which also tracks items *not* closed by this PR).

With the new `?` desugar implemented, [it's no longer possible to mix `Result` and `ControlFlow`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=13feec97f5c96a9d791d97f7de2d49a6).  (At the time of making this PR, godbolt was still on the 2021-05-01 nightly, where you can see that [the mixing example compiled](https://rust.godbolt.org/z/13Ke54j16).)  That resolves the only blocker I know of, so I'd like to propose that `ControlFlow` be considered for stabilization.

Its basic existence was part of https://github.com/rust-lang/rfcs/pull/3058, where it got a bunch of positive comments (examples [1](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-758277325) [2](https://github.com/rust-lang/rfcs/pull/3058#pullrequestreview-592106494) [3](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-784444155) [4](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-797031584)).  Its use in the compiler has been well received (https://github.com/rust-lang/rust/pull/78182#issuecomment-713695594), and there are ecosystem updates interested in using it (https://github.com/rust-itertools/itertools/issues/469#issuecomment-677729589, https://github.com/jonhoo/rust-imap/issues/194).

As this will need an FCP, picking a libs member manually:
r? `@m-ou-se`

## Stabilized APIs

```rust
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ControlFlow<B, C = ()> {
    /// Exit the operation without running subsequent phases.
    Break(B),
    /// Move on to the next phase of the operation as normal.
    Continue(C),
}
```

As well as using `?` on a `ControlFlow<B, _>` in a function returning `ControlFlow<B, _>`.  (Note, in particular, that there's no `From::from`-conversion on the `Break` value, the way there is for `Err`s.)

## Existing APIs *not* stabilized here

All the associated methods and constants: `break_value`, `is_continue`, `map_break`, [`CONTINUE`](https://doc.rust-lang.org/nightly/std/ops/enum.ControlFlow.html#associatedconstant.CONTINUE), etc.

Some of the existing methods in nightly seem reasonable, some seem like they should be removed, and some need more discussion to decide.  But none of them are *essential*, so [as in the RFC](https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#methods-on-controlflow), they're all omitted from this PR.

They can be considered separately later, as further usage demonstrates which are important.
2021-06-15 17:40:08 +09:00
jam1garner
1626e1938a Add support for associated functions to future_prelude_collision lint 2021-06-14 13:27:24 -04:00
jam1garner
79388aa067 Add future_prelude_collision lint 2021-06-14 13:27:23 -04:00
bors
0f6ba39fd8 Auto merge of #86180 - cjgillot:defmv, r=petrochenkov
Hash DefId in rustc_span.

This is mostly just moving code around. Changes are simplifications of unneeded callbacks from rustc_span to rustc_middle.

r? `@petrochenkov`
2021-06-12 06:09:20 +00:00
Yuki Okushi
79c0559ce1
Rollup merge of #86153 - tmiasko:dummy-span, r=estebank
Print dummy spans as `no-location`

Fixes #58808.
2021-06-12 01:15:59 +09:00
Camille GILLOT
72e9589149 Make DummyHashStableContext dummier. 2021-06-11 16:54:34 +02:00
Camille GILLOT
d1931b6406 Sprinkle inline. 2021-06-11 16:48:24 +02:00
Camille GILLOT
a7a50b0c0a Hash DefId in rustc_span. 2021-06-11 12:25:02 +02:00
Ryan Levick
6936349233 Add support for using qualified paths with structs in expression and pattern
position.
2021-06-10 13:18:41 +02:00
Tomasz Miąsko
fab319be73 Print dummy spans as no-location 2021-06-09 00:33:46 +02:00
bors
e4a6032706 Auto merge of #85903 - bjorn3:rustc_serialize_cleanup, r=varkor
Remove unused functions and arguments from rustc_serialize
2021-06-07 14:40:26 +00:00
bjorn3
8176ab8bc1 Revert "Merge CrateDisambiguator into StableCrateId"
This reverts commit d0ec85d3fb.
2021-06-07 10:37:45 +02:00
bors
f434217aab Auto merge of #79608 - alessandrod:bpf, r=nagisa
BPF target support

This adds `bpfel-unknown-none` and `bpfeb-unknown-none`, two new no_std targets that generate little and big endian BPF. The approach taken is very similar to the cuda target, where `TargetOptions::obj_is_bitcode` is enabled and code generation is done by the linker.

I added the targets to `dist-various-2`. There are [some tests](https://github.com/alessandrod/bpf-linker/tree/main/tests/assembly) in bpf-linker and I'm planning to add more. Those are currently not ran as part of rust CI.
2021-06-06 01:02:32 +00:00
Yuki Okushi
36f1ed6de2
Rollup merge of #85850 - bjorn3:less_feature_gates, r=jyn514
Remove unused feature gates

The first commit removes a usage of a feature gate, but I don't expect it to be controversial as the feature gate was only used to workaround a limitation of rust in the past. (closures never being `Clone`)

The second commit uses `#[allow_internal_unstable]` to avoid leaking the `trusted_step` feature gate usage from inside the index newtype macro. It didn't work for the `min_specialization` feature gate though.

The third commit removes (almost) all feature gates from the compiler that weren't used anyway.
2021-06-04 13:42:54 +09:00
Tomasz Miąsko
c1f6495b8e Miscellaneous inlining improvements 2021-06-02 08:49:58 +02:00
bors
625d5a693e Auto merge of #85829 - bjorn3:simplify_crate_num, r=jackh726
Remove CrateNum::ReservedForIncrCompCache

It's only use is easily replaceable with `Option<CrateNum>`.
2021-06-01 20:09:03 +00:00