Commit Graph

9767 Commits

Author SHA1 Message Date
Esteban Kuber
8bee2b88c0 Remove some unnecessarily verbose code 2021-12-03 18:41:39 +00:00
Esteban Kuber
fa3eebb26e Modify bounds_span to ignore bounds coming from a derive macro 2021-12-03 18:41:39 +00:00
Esteban Kuber
e70105f971 Keep spans for generics in #[derive(_)] desugaring
Keep the spans for generics coming from a `derive`d Item, so that errors
and suggestions have better detail.

Fix #84003.
2021-12-03 18:41:39 +00:00
Tom Farmer
3827b6451c Update invalid crate attributes, add help message
tidy run

update invalid crate attributes, improve error

update test outputs

de-capitalise error

update tests

Update invalid crate attributes, add help message

Update - generate span without using BytePos

Add correct dependancies

Update - generate suggestion without BytePos

Tidy run

update tests

Generate Suggestion without BytePos

Add all builtin attributes

add err builtin inner attr at top of crate

fix tests

add err builtin inner attr at top of crate

tidy fix

add err builtin inner attr at top of crate
2021-12-03 18:38:32 +00:00
Tobias Kortkamp
e24045e587
Explain why libatomic is not needed on FreeBSD riscv64
From Jessica Clarke (jrtc27@)
2021-12-03 18:49:42 +01:00
Wesley Wiser
d5f6b9c8c2 code-cov: generate dead functions with private/default linkage
As discovered in #85461, the MSVC linker treats weak symbols slightly
differently than unix-y linkers do. This causes link.exe to fail with
LNK1227 "conflicting weak extern definition" where as other targets are
able to link successfully.

This changes the dead functions from being generated as weak/hidden to
private/default which, as the LLVM reference says:

> Global values with “private” linkage are only directly accessible by
objects in the current module. In particular, linking code into a module
with a private global value may cause the private to be renamed as
necessary to avoid collisions. Because the symbol is private to the
module, all references can be updated. This doesn’t show up in any
symbol table in the object file.

This fixes the conflicting weak symbols but doesn't address the reason
*why* we have conflicting symbols for these dead functions. The test
cases added in this commit contain a minimal repro of the fundamental
issue which is that the logic used to decide what dead code functions
should be codegen'd in the current CGU doesn't take into account that
functions can be duplicated across multiple CGUs (for instance, in the
case of `#[inline(always)]` functions).

Fixing that is likely to be a more complex change (see
https://github.com/rust-lang/rust/issues/85461#issuecomment-985005805).

Fixes #85461
2021-12-03 12:00:12 -05:00
bors
ff2439b7b9 Auto merge of #91491 - spastorino:revert-91354, r=oli-obk
Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"

This reverts commit 18bb8c61a9, reversing
changes made to d9baa36190.

Reverts #91354 in order to address #91489. We would need to place this changes in a more granular way and would also be nice to address the small perf regression that was also introduced.

r? `@oli-obk`
cc `@fee1-dead`
2021-12-03 16:26:01 +00:00
Oli Scherer
9e5939ad92 Remove a code path that is neither documented nor can I see the reason it existed.
Also, no tests fail when turning that arm into an ICE
2021-12-03 15:23:43 +00:00
bors
2a9e0831d6 Auto merge of #91393 - Julian-Wollersberger:lexer_optimization, r=petrochenkov
Optimize `rustc_lexer`

The `cursor.first()` method in `rustc_lexer` now calls the `chars.next()` method instead of `chars.nth_char(0)`.

This allows LLVM to optimize the code better. The biggest win is that `eat_while()` is now fully inlined and generates better assembly. This improves the lexer's performance by 35% in a micro-benchmark I made (Lexing all 18MB of code in the compiler directory). But lexing is only a small part of the overall compilation time, so I don't know how significant it is.

Big thanks to criterion and `cargo asm`.
2021-12-03 13:20:14 +00:00
Santiago Pastorino
85b723c4e6
Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"
This reverts commit 18bb8c61a9, reversing
changes made to d9baa36190.
2021-12-03 10:11:21 -03:00
Michael Goulet
7c108ababc Fix ICE when yielding in fn returning impl Trait 2021-12-02 22:36:05 -08:00
Matthias Krüger
f056f0d1b4
Rollup merge of #91462 - b-naber:use-try-normalize-erasing-regions, r=jackh726
Use try_normalize_erasing_regions in needs_drop

Fixes https://github.com/rust-lang/rust/issues/81199

r? ``@jackh726``
2021-12-03 06:24:17 +01:00
Matthias Krüger
a5ee722f1e
Rollup merge of #91273 - Badel2:ice-index-str, r=estebank
Fix ICE #91268 by checking that the snippet ends with a `)`

Fix #91268

Previously it was assumed that the last character of `snippet` will be a `)`, so using `snippet.len() - 1` as an index should be safe. However as we see in the test, it is possible to enter that branch without a closing `)`, and it will trigger the panic if the last character happens to be multibyte.

The fix is to ensure that the snippet ends with `)`, and skip the suggestion otherwise.
2021-12-03 06:24:14 +01:00
Matthias Krüger
570dc70a2b
Rollup merge of #90854 - sanxiyn:unsized-and-uninhabited, r=estebank
Type can be unsized and uninhabited

Fix #88150.
2021-12-03 06:24:12 +01:00
Matthias Krüger
31003a3089
Rollup merge of #88906 - Kixunil:box-maybe-uninit-write, r=dtolnay
Implement write() method for Box<MaybeUninit<T>>

This adds method similar to `MaybeUninit::write` main difference being
it returns owned `Box`. This can be used to elide copy from stack
safely, however it's not currently tested that the optimization actually
occurs.

Analogous methods are not provided for `Rc` and `Arc` as those need to
handle the possibility of sharing. Some version of them may be added in
the future.

This was discussed in #63291 which this change extends.
2021-12-03 06:24:11 +01:00
est31
bdc4b46221 Use let_else in some more places in rustc_lint 2021-12-03 03:51:47 +01:00
Dylan MacKenzie
dc5feeb1fa Don't "simplify" during optimizations if optimizations are disabled 2021-12-02 17:31:38 -08:00
Dylan MacKenzie
42e31fffc4 Skip shim passes if they've already been run
Looks like Generator drop shims already have `post_borrowck_cleanup` run
on them. That's a bit surprising, since it means they're getting const-
and maybe borrow-checked? This merits further investigation, but for now
just preserve the status quo.
2021-12-02 17:31:38 -08:00
Dylan MacKenzie
71dd5422ac Use new MIR pass manager 2021-12-02 17:31:38 -08:00
Dylan MacKenzie
fca642c1c3 Add pass for simple phase change 2021-12-02 17:31:38 -08:00
Dylan MacKenzie
fd18b45e11 Update passes with new interface 2021-12-02 17:31:38 -08:00
Dylan MacKenzie
c1a501b131 Implement a pass manager 2021-12-02 17:31:38 -08:00
Dylan MacKenzie
a0de6346de Move instrument coverage config getters to Options 2021-12-02 17:12:59 -08:00
Dylan MacKenzie
386b1c5f57 Move mir_opt_level getter into Options 2021-12-02 17:12:58 -08:00
Esteban Kuber
5b5df0fa17 Remove incorrect newline from float cast suggestion 2021-12-03 01:00:09 +00:00
Mara Bos
41b1bcb40d Improve 'cannot contain emoji' error. 2021-12-03 01:20:25 +01:00
b-naber
a11994e423 use try_normalize_erasing_regions in needs_drop 2021-12-02 23:27:08 +01:00
bors
ff23ad3179 Auto merge of #91469 - matthiaskrgr:rollup-xom3j55, r=matthiaskrgr
Rollup of 12 pull requests

Successful merges:

 - #89954 (Fix legacy_const_generic doc arguments display)
 - #91321 (Handle placeholder regions in NLL type outlive constraints)
 - #91329 (Fix incorrect usage of `EvaluatedToOk` when evaluating `TypeOutlives`)
 - #91364 (Improve error message for incorrect field accesses through raw pointers)
 - #91387 (Clarify and tidy up explanation of E0038)
 - #91410 (Move `#![feature(const_precise_live_drops)]` checks earlier in the pipeline)
 - #91435 (Improve diagnostic for missing half of binary operator in `if` condition)
 - #91444 (disable tests in Miri that take too long)
 - #91457 (Add additional test from rust issue number 91068)
 - #91460 (Document how `last_os_error` should be used)
 - #91464 (Document file path case sensitivity)
 - #91466 (Improve the comments in `Symbol::interner`.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-02 21:58:48 +00:00
Matthias Krüger
f7afd461c7
Rollup merge of #91466 - nnethercote:Symbol-interner-comments, r=Mark-Simulacrum
Improve the comments in `Symbol::interner`.

r? `@Mark-Simulacrum`
2021-12-02 22:16:19 +01:00
Matthias Krüger
dbb9e224af
Rollup merge of #91435 - FabianWolff:issue-91421-if-then, r=lcnr
Improve diagnostic for missing half of binary operator in `if` condition

Fixes #91421. I've also changed it so that it doesn't consume the `else` token in the error case, because it will try to consume it again afterwards, leading to this incorrect error message (where the `else` reported as missing is actually there):
```
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{`
 --> src/main.rs:4:12
  |
4 |     } else { 4 };
  |            ^ expected one of `.`, `;`, `?`, `else`, or an operator
```

r? `@lcnr`
2021-12-02 22:16:13 +01:00
Matthias Krüger
39641319ad
Rollup merge of #91410 - ecstatic-morse:const-precise-live-drops-take-2, r=oli-obk
Move `#![feature(const_precise_live_drops)]` checks earlier in the pipeline

Should mitigate the issues found during MCP on #73255.

Once this is done, we should clean up the queries a bit, since I think `mir_drops_elaborated_and_const_checked` can be merged back into `mir_promoted`.

Fixes #90770.

cc ``@rust-lang/wg-const-eval``
r? ``@nikomatsakis`` (since they reviewed #71824)
2021-12-02 22:16:13 +01:00
Matthias Krüger
b269213b35
Rollup merge of #91387 - graydon:E0038-clarification, r=wesleywiser
Clarify and tidy up explanation of E0038

I ran into E0038 (specifically the `Self:Sized` constraint on object-safety) the other day and it seemed to me that the explanations I found floating around the internet were a bit .. wrong. Like they didn't make sense. And then I went and checked the official explanation here and it didn't make sense either.

As far as I can tell (reading through the history of the RFCs), two totally different aspects of object-safety have got tangled up in much of the writing on the subject:
  - Object-safety related to "not even theoretically possible" issues. This includes things like "methods that take or return Self by value", which obviously will never work for an unsized type in a world with fixed-size stack frames (and it'd be an opaque type anyways, which, ugh). This sort of thing was originally decided method-by-method, with non-object-safe methods stripped from objects; but in [RFC 0255](https://rust-lang.github.io/rfcs/0255-object-safety.html) this sort of per-impossible-method reasoning was made into a per-trait safety property (with the escape hatch left in where users could mark methods `where Self:Sized` to have them stripped before the trait's object safety is considered).
  - Object-safety related to "totally possible but ergonomically a little awkward" issues. Specifically in a trait with `Trait:Sized`, there's no a priori reason why this constraint makes the trait impossible to make into an object -- imagine it had nothing but harmless `&self`-taking methods. No problem! Who cares if the Trait requires its implementing types to be sized? As far as I can tell reading the history here, in both RFC 0255 and then later in [RFC 0546](https://rust-lang.github.io/rfcs/0546-Self-not-sized-by-default.html) it seems that the motivation for making `Trait:Sized` be non-object-safe has _nothing to do_ with the impossibility of making objects out of such types, and everything to do with enabling "[a trait object SomeTrait to implement the trait SomeTrait](https://rust-lang.github.io/rfcs/0546-Self-not-sized-by-default.html#motivation)". That is, since `dyn Trait` is unsized, if `Trait:Sized` then you can never have the automatic (and reasonable) ergonomic implicit `impl Trait for dyn Trait`. And the authors of that RFC really wanted that automatic implicit implementation of `Trait` for `dyn Trait`. So they just defined `Trait:Sized` as non-object safe -- no `dyn Trait` can ever exist that the compiler can't synthesize such an impl for. Well enough!

However, I noticed in my reading-and-reconstruction that lots of documentation on the internet, including forum and Q&A site answers and (most worrying) the compiler explanation all kinda grasp at something like the first ("not theoretically possible") explanation, and fail to mention the second ("just an ergonomic constraint") explanation. So I figured I'd clean up the docs to clarify, maybe confuse the next person less (unless of course I'm misreading the history here and misunderstanding motives -- please let me know if so!)

While here I also did some cleanups:

  - Rewrote the preamble, trying to help the user get a little better oriented (I found the existing preamble a bit scattered).
  - Modernized notation (using `dyn Trait`)
  - Changed the section headings to all be written with the same logical sense: to all be written as "conditions that violate object safety" rather than a mix of that and the negated form "conditions that must not happen in order to ensure object safety".

I think there's a fair bit more to clean up in this doc -- the later sections get a bit rambly and I suspect there should be a completely separated-out section covering the `where Self:Sized` escape hatch for instructing the compiler to "do the old thing" and strip methods off traits when turning them into objects (it's a bit buried as a digression in the individual sub-error sections). But I did what I had time for now.
2021-12-02 22:16:12 +01:00
Matthias Krüger
7483211ed5
Rollup merge of #91364 - FabianWolff:issue-91210-ptr-field, r=oli-obk
Improve error message for incorrect field accesses through raw pointers

Fixes #91210.
2021-12-02 22:16:11 +01:00
Matthias Krüger
fd6e66f423
Rollup merge of #91329 - Aaron1011:modulo-regions-test, r=jackh726
Fix incorrect usage of `EvaluatedToOk` when evaluating `TypeOutlives`

A global predicate is not guarnatenteed to outlive all regions.
If the predicate involves late-bound regions, then it may fail
to outlive other regions (e.g. `for<'b> &'b bool: 'static` does not
hold)

We now only produce `EvaluatedToOk` when a global predicate has no
late-bound regions - in that case, the ony region that can be present
in the type is 'static
2021-12-02 22:16:10 +01:00
Matthias Krüger
b56e3d955a
Rollup merge of #91321 - matthewjasper:constaint-placeholders, r=jackh726
Handle placeholder regions in NLL type outlive constraints

Closes #76168
2021-12-02 22:16:09 +01:00
Nicholas Nethercote
66153d76e2 Improve the comments in Symbol::interner. 2021-12-03 07:12:31 +11:00
bors
acbe4443cc Auto merge of #91318 - eggyal:reduce-boilerplate-around-infallible-folders, r=jackh726
Reduce boilerplate around infallible folders

Further to https://github.com/rust-lang/rust/pull/91230#issuecomment-981059666

r? `@jackh726`
2021-12-02 19:12:00 +00:00
Martin Habovstiak
41e21aa1c2 Implement write() method for Box<MaybeUninit<T>>
This adds method similar to `MaybeUninit::write` main difference being
it returns owned `Box`. This can be used to elide copy from stack
safely, however it's not currently tested that the optimization actually
occurs.

Analogous methods are not provided for `Rc` and `Arc` as those need to
handle the possibility of sharing. Some version of them may be added in
the future.

This was discussed in #63291 which this change extends.
2021-12-02 17:18:34 +01:00
Alan Egerton
cf683e644f
Rename TypeFolderFallible to FallibleTypeFolder 2021-12-02 16:14:18 +00:00
eggyal
d79e17daf0
Update compiler/rustc_middle/src/ty/fold.rs
Co-authored-by: lcnr <rust@lcnr.de>
2021-12-02 16:14:16 +00:00
Alan Egerton
bfc434b6d0
Reduce boilerplate around infallible folders 2021-12-02 16:14:16 +00:00
Alan Egerton
db7295fa96
Remove no-longer used IdFunctor::map_id 2021-12-02 15:45:40 +00:00
bors
e5038e2099 Auto merge of #91455 - matthiaskrgr:rollup-gix2hy6, r=matthiaskrgr
Rollup of 4 iffy pull requests

Successful merges:

 - #89234 (Disallow non-c-like but "fieldless" ADTs from being casted to integer if they use arbitrary enum discriminant)
 - #91045 (Issue 90702 fix: Stop treating some crate loading failures as fatal errors)
 - #91394 (Bump stage0 compiler)
 - #91411 (Enable svh tests on msvc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-02 14:53:20 +00:00
Matthias Krüger
d96ce3ea8e
Rollup merge of #91394 - Mark-Simulacrum:bump-stage0, r=pietroalbini
Bump stage0 compiler

r? `@pietroalbini` (or anyone else)
2021-12-02 15:52:03 +01:00
Matthias Krüger
87ca333210
Rollup merge of #91045 - mjptree:issue-90702-fix, r=petrochenkov
Issue 90702 fix: Stop treating some crate loading failures as fatal errors

Surface mulitple `extern crate` resolution errors at a time.

This is achieved by creating a dummy crate, instead of aborting directly after the resolution error. The `ExternCrateError` has been added to allow propagating the resolution error from `rustc_metadata` crate to the `rustc_resolve` with a minimal public surface. The `import_extern_crate` function is a block that was factored out from `build_reduced_graph_for_item` for better organization. The only added functionality made to it where the added error handling in the `process_extern_crate` call. The remaining bits in this function are the same as before.

Resolves #90702

r? `@petrochenkov`
2021-12-02 15:52:01 +01:00
Matthias Krüger
0666a33a6b
Rollup merge of #89234 - nbdd0121:discr, r=jackh726
Disallow non-c-like but "fieldless" ADTs from being casted to integer if they use arbitrary enum discriminant

Code like

```rust
#[repr(u8)]
enum Enum {
    Foo /* = 0 */,
    Bar(),
    Baz{}
}

let x = Enum::Bar() as u8;
```

seems to be unintentionally allowed so we couldn't disallow them now ~~, but we could disallow them if arbitrary enum discriminant is used before 1.56 hits stable~~ (stabilization was reverted).

Related: #88621

`@rustbot` label +T-lang
2021-12-02 15:52:00 +01:00
bors
18bb8c61a9 Auto merge of #91354 - fee1-dead:const_env, r=spastorino
Cleanup: Eliminate ConstnessAnd

This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable `~const` feature.

We most definitely need to review all `without_const` and at some point should probably get rid of many of them by using `TraitPredicate` instead of `TraitRef`.

This is a continuation of https://github.com/rust-lang/rust/pull/90274.

r? `@oli-obk`

cc `@spastorino` `@ecstatic-morse`
2021-12-02 11:48:58 +00:00
bors
a2b7b7891e Auto merge of #91003 - psumbera:sparc64-abi, r=nagisa
fix sparc64 ABI for aggregates with floating point members

Fixes #86163
2021-12-02 02:59:44 +00:00
bors
76938d64a4 Auto merge of #90446 - cjgillot:late-elided, r=jackh726
Lint elided lifetimes in path during lifetime resolution.

The lifetime elision lint is known to be brittle and can be redundant with later lifetime resolution errors. This PR aims to remove the redundancy by performing the lint after lifetime resolution.

This PR proposes to carry the information that an elision should be linted against by using a special `LifetimeName`. I am not certain this is the best solution, but it is certainly the easiest.

Fixes https://github.com/rust-lang/rust/issues/60199
Fixes https://github.com/rust-lang/rust/issues/55768
Fixes https://github.com/rust-lang/rust/issues/63110
Fixes https://github.com/rust-lang/rust/issues/71957
2021-12-01 23:22:43 +00:00
Michael
2ca9333011 Improve suggestion for extern crate self error message 2021-12-01 21:59:54 +00:00
David Tolnay
b516a8c5cb
Pretty print empty blocks as {} 2021-12-01 13:50:13 -08:00
Fabian Wolff
ba7374e517 Improve diagnostic for missing half of binary operator in if condition 2021-12-01 22:36:50 +01:00
Michael
62f4ce993e Stop treating extern crate loading failures as fatal errors 2021-12-01 21:04:13 +00:00
Michael
10b3a571d2 Factor out build reduced graph for extern crate 2021-12-01 21:04:12 +00:00
Gary Guo
f7ef1c9f41 Disallow non-c-like but "fieldless" ADTs from being casted to integer...
... if they use arbitrary enum discriminant. Code like

```rust
enum Enum {
    Foo = 1,
    Bar(),
    Baz{}
}
```

seems to be unintentionally allowed so we couldn't disallow them now,
but we could disallow them if arbitrary enum discriminant is used before
1.56 hits stable.
2021-12-01 19:59:15 +00:00
Matthias Krüger
4a6e8a9c93
Rollup merge of #91425 - jyn514:treat-lint-err-as-bug, r=oli-obk
Include lint errors in error count for `-Ztreat-err-as-bug`

This was a regression from https://github.com/rust-lang/rust/pull/87337;
the `panic_if_treat_err_as_bug` function only checked the number of hard
errors, not the number of lint errors.

r? `@oli-obk`
2021-12-01 20:57:47 +01:00
Matthias Krüger
519a842c50
Rollup merge of #91313 - petrochenkov:cratexp, r=Aaron1011
expand: Turn `ast::Crate` into a first class expansion target

And stop creating a fake `mod` item for the crate root when expanding a crate, thus addressing FIXMEs left in https://github.com/rust-lang/rust/pull/82238, and making a step towards a proper support for crate-level macro attributes (cc #54726).

I haven't added token collection support for the whole crate in this PR, maybe later.
r? `@Aaron1011`
2021-12-01 20:57:43 +01:00
Julian Wollersberger
1f147a2ed7 Replace nth_char(0) with next() in cursor.first()
and optimize the iterator returned by `tokenize().

This improves lexer performance by 35%
2021-12-01 19:14:10 +01:00
Joshua Nelson
9de8a4a6fa Include lint errors in error count for -Ztreat-err-as-bug
This was a regression from https://github.com/rust-lang/rust/pull/87337;
the `panic_if_treat_err_as_bug` function only checked the number of hard
errors, not the number of lint errors.
2021-12-01 16:39:55 +00:00
Deadbeef
5ebc99e5b2
Format 2021-12-01 23:33:37 +08:00
Deadbeef
b64c40bc6f
TODO => FIXME 2021-12-01 23:32:36 +08:00
Deadbeef
6b07cec05c
Cache with consistent env and bound 2021-12-01 23:22:42 +08:00
bors
f04a2f4b8e Auto merge of #91255 - b-naber:normalization-ice, r=jackh276
Implement version of normalize_erasing_regions that allows for normalization failure

Fixes https://github.com/rust-lang/rust/issues/59324
Fixes https://github.com/rust-lang/rust/issues/67684
Fixes https://github.com/rust-lang/rust/issues/69398
Fixes https://github.com/rust-lang/rust/issues/71113
Fixes https://github.com/rust-lang/rust/issues/82079
Fixes #85103
Fixes https://github.com/rust-lang/rust/issues/88856
Fixes #91231
Fixes https://github.com/rust-lang/rust/issues/91234

Previously we called `normalize_erasing_regions` inside `layout_of`. `normalize_erasing_regions` assumes that the normalization succeeds. Since some `layout_of` calls happen before typecheck has finished, we introduce a new variant that allows for returning an error.
2021-12-01 13:33:33 +00:00
b-naber
6952470095 rebase 2021-12-01 13:15:59 +01:00
b-naber
4d9a0bf21b address review 2021-12-01 12:12:40 +01:00
b-naber
84bcd40927 fix query description 2021-12-01 12:12:40 +01:00
b-naber
0b32cf3a8d remove static_assert_size on InterpError 2021-12-01 12:12:39 +01:00
b-naber
ff448cfcee implement version of normalize_erasing_regions that doesn't assume value is normalizable 2021-12-01 12:12:38 +01:00
Matthias Krüger
4f252f1a91
Rollup merge of #91404 - nnethercote:fix-bad-NodeId-limit-checking, r=dtolnay
Fix bad `NodeId` limit checking.

`Resolver::next_node_id` converts a `u32` to a `usize` (which is
possibly bigger), does a checked add, and then converts the result back
to a `u32`. The `usize` conversion completely subverts the checked add!

This commit removes the conversion to/from `usize`.
2021-12-01 10:50:23 +01:00
Matthias Krüger
c09c16c0df
Rollup merge of #91298 - FabianWolff:issue-91028-source-avail, r=cjgillot
Improve error message for `E0659` if the source is not available

Fixes #91028. The fix is similar to those in #89233 and #87088. With this change, instead of the dangling
```
note: `Option` could also refer to the enum defined here
```
I get
```
note: `Option` could also refer to an enum from prelude
```
If the standard library source code _is_ available, the output does not change.
2021-12-01 10:50:21 +01:00
Matthias Krüger
d93df5775c
Rollup merge of #91207 - richkadel:rk-bump-coverage-version, r=tmandry
Add support for LLVM coverage mapping format versions 5 and 6

This PR cherry-pick's Swatinem's initial commit in unsubmitted PR #90047.

My additional commit augments Swatinem's great starting point, but adds full support for LLVM
Coverage Mapping Format version 6, conditionally, if compiling with LLVM 13.

Version 6 requires adding the compilation directory when file paths are
relative, and since Rustc coverage maps use relative paths, we should
add the expected compilation directory entry.

Note, however, that with the compilation directory, coverage reports
from `llvm-cov show` can now report file names (when the report includes
more than one file) with the full absolute path to the file.

This would be a problem for test results, but the workaround (for the
rust coverage tests) is to include an additional `llvm-cov show`
parameter: `--compilation-dir=.`
2021-12-01 10:50:20 +01:00
Matthias Krüger
a4f46742c2
Rollup merge of #90985 - camsteffen:diag-name-usage, r=jackh726
Use `get_diagnostic_name` more
2021-12-01 10:50:18 +01:00
Matthias Krüger
e68e5d2391
Rollup merge of #87160 - estebank:colon-recovery, r=nagisa
When recovering from a `:` in a pattern, use adequate AST pattern

If the suggestion to use `::` instead of `:` in the pattern isn't correct, a second resolution error will be emitted.
2021-12-01 10:50:18 +01:00
Petr Sumbera
128ceec92d fix sparc64 ABI for aggregates with floating point members 2021-12-01 10:03:45 +01:00
bors
2446a21595 Auto merge of #91324 - eggyal:avoid-uneccesary-clone-of-annotatable, r=Aaron1011
Avoid uneccessary clone of Annotatable

Addresses FIXME comment created in #82608

r? `@Aaron1011`
2021-12-01 06:18:39 +00:00
Nicholas Nethercote
e7ee8230ce Fix bad NodeId limit checking.
`Resolver::next_node_id` converts a `u32` to a `usize` (which is
possibly bigger), does a checked add, and then converts the result back
to a `u32`. The `usize` conversion completely subverts the checked add!

This commit removes the conversion to/from `usize`.
2021-12-01 15:08:37 +11:00
Dylan MacKenzie
58c996c3a7 Move post-elaboration const-checking earlier in the pipeline
Instead we run `RemoveFalseEdges` and `RemoveUninitDrops` at the
appropriate time. The extra `SimplifyCfg` avoids visiting unreachable
blocks during `RemoveUninitDrops`.
2021-11-30 17:25:30 -08:00
Dylan MacKenzie
3e0e8be037 Handle DropAndReplace in const-checking
It runs before the real drop elaboration pass.
2021-11-30 17:25:30 -08:00
Dylan MacKenzie
ce2959da97 Add rationale for RemoveUnneededDrops
...since its name is very close to `RemoveUninitDrops`.
2021-11-30 17:25:30 -08:00
Dylan MacKenzie
4f7605b6fd Add RemoveUninitDrops MIR pass 2021-11-30 17:25:30 -08:00
Dylan MacKenzie
d707707364 Add "is" methods for projections to a given index 2021-11-30 17:17:14 -08:00
Dylan MacKenzie
bb27b05104 Separate RemoveFalseEdges from SimplifyBranches
Otherwise dataflow state will propagate along false edges and cause
things to be marked as maybe init unnecessarily. These should be
separate, since `SimplifyBranches` also makes `if true {} else {}` into
a `goto`, which means we wouldn't lint anything in the `else` block.
2021-11-30 17:14:48 -08:00
Matthias Krüger
7baafb1f5e
Rollup merge of #91397 - jyn514:generic-param-docs, r=wesleywiser
Emit a warning on generic parameters with doc comments

Fixes https://github.com/rust-lang/rust/issues/90610
2021-11-30 23:43:33 +01:00
Matthias Krüger
dc78cd4c61
Rollup merge of #91294 - cjgillot:process-elem, r=jackh726
Visit type in process_projection_elem.

Instead of reimplementing it for each visitor.
2021-11-30 23:43:31 +01:00
Camille GILLOT
aa2450f41b Merge Implicit and ImplicitMissing. 2021-11-30 22:56:47 +01:00
Camille GILLOT
72dc29c260 Handle allow(elided_lifetimes_in_paths). 2021-11-30 22:55:07 +01:00
Camille GILLOT
b621133200 Simplify lowering. 2021-11-30 22:55:07 +01:00
Camille GILLOT
5ea7ea8a57 Lint elided lifetimes in path during lifetime resolution. 2021-11-30 22:55:07 +01:00
Camille GILLOT
ac03470c3b Flatten match. 2021-11-30 22:55:06 +01:00
Camille GILLOT
c44e93086d Move report_elision_failure in diagnostics.rs. 2021-11-30 22:55:06 +01:00
Rich Kadel
0c57fab5fc Add conditional support for coverage map version 6
This commit augments Swatinem's initial commit in uncommitted PR #90047,
which was a great starting point, but did not fully support LLVM
Coverage Mapping Format version 6.

Version 6 requires adding the compilation directory when file paths are
relative, and since Rustc coverage maps use relative paths, we should
add the expected compilation directory entry.

Note, however, that with the compilation directory, coverage reports
from `llvm-cov show` can now report file names (when the report includes
more than one file) with the full absolute path to the file.

This would be a problem for test results, but the workaround (for the
rust coverage tests) is to include an additional `llvm-cov show`
parameter: `--compilation-dir=.`
2021-11-30 13:54:53 -08:00
Joshua Nelson
bd894a0877 Emit a warning on generic parameters with doc comments 2021-11-30 18:49:55 +00:00
Mark Rousskov
971c549ca3 re-format with new rustfmt 2021-11-30 13:08:41 -05:00
Graydon Hoare
7907fa8ec4
Clarify and tidy up explanation of E0038 2021-11-30 09:25:17 -08:00
Mark Rousskov
b221c877e8 Apply cfg-bootstrap switch 2021-11-30 10:51:42 -05:00
bors
1c0287830e Auto merge of #91388 - JohnTitor:rollup-640o1e5, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #91243 (Don't treat unnormalized function arguments as well-formed)
 - #91250 (Refactor EmitterWriter::emit_suggestion_default )
 - #91317 (tests: Ignore `test/debuginfo/rc_arc.rs` on windows-gnu)
 - #91323 (CTFE: support assert_zero_valid and assert_uninit_valid)
 - #91358 (Fix small typo)
 - #91360 (⬆️ rust-analyzer)
 - #91368 (Don't re-export `MirPass`)
 - #91383 (Add `drop_while` as doc alias to `Iterator::skip_while`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-30 10:45:22 +00:00
Yuki Okushi
898f1e4717
Rollup merge of #91368 - ecstatic-morse:mir-pass-reexport, r=cjgillot
Don't re-export `MirPass`

`rust-analyzer` wants to use the `rustc_const_eval` one by default, which is weird.

r? ``@cjgillot``
2021-11-30 17:29:12 +09:00
Yuki Okushi
56c838cdc7
Rollup merge of #91358 - kd-collective:fix_typo, r=cjgillot
Fix small typo

Fix a typo in code commenting!
`accross` -> `across`
2021-11-30 17:29:10 +09:00
Yuki Okushi
a940c68035
Rollup merge of #91323 - RalfJung:assert-type, r=oli-obk
CTFE: support assert_zero_valid and assert_uninit_valid

This ensures the implementation of all three type-based assert_ intrinsics remains consistent in Miri.

`assert_inhabited` recently got stabilized in https://github.com/rust-lang/rust/pull/90896 (meaning stable `const fn` can call it), so do the same with these other intrinsics.

Cc ```@rust-lang/wg-const-eval```
2021-11-30 17:29:09 +09:00
Yuki Okushi
626afa18b3
Rollup merge of #91250 - rukai:remove_trailing_whitespace, r=wesleywiser
Refactor EmitterWriter::emit_suggestion_default

Makes progress towards https://github.com/rust-lang/rust/issues/89979

Split into 2 commits:
* the first commit is purely a refactor and I verified that `./x.py test src/test/ui --stage 1` and  `./x.py test src/test/rustdoc-ui --stage 1` continue to pass on this commit.
* ~~the second commit removes the empty trailing line from diff style suggestions.~~ - I discovered an issue with this so its just the refactor now.

r? diagnostics
2021-11-30 17:29:07 +09:00
Yuki Okushi
6e7cf2e88b
Rollup merge of #91243 - jackh726:issue-91068, r=nikomatsakis
Don't treat unnormalized function arguments as well-formed

Partial revert of #88312

r? ``@pnkfelix``
cc ``@nikomatsakis``
2021-11-30 17:29:06 +09:00
bors
90912e68ab Auto merge of #91330 - cjgillot:no-ee-features, r=Aaron1011
Remove eval_always for lib_features.

r? `@Aaron1011`
2021-11-30 07:40:08 +00:00
Dylan MacKenzie
f6b499da16 Suggest the pat_param specifier before | on 2021 edition
We have a migration warning but no lint for users who have enabled the
new edition.
2021-11-29 22:20:34 -08:00
Dylan MacKenzie
188d670125 Don't re-export MirPass 2021-11-29 12:58:15 -08:00
Esteban Kuber
c02710530c review comments: clean up 2021-11-29 18:39:08 +00:00
Fabian Wolff
821b92b102 Improve error message for incorrect field accesses through raw pointers 2021-11-29 19:31:17 +01:00
Ralf Jung
6c3c3e0952 CTFE: support assert_zero_valid and assert_uninit_valid 2021-11-29 11:49:31 -05:00
kijima
3c42a11895 Fix small typo 2021-11-30 01:31:10 +09:00
Alex Crichton
a0c959750a std: Stabilize the thread_local_const_init feature
This commit is intended to follow the stabilization disposition of the
FCP that has now finished in #84223. This stabilizes the ability to flag
thread local initializers as `const` expressions which enables the macro
to generate more efficient code for accessing it, notably removing
runtime checks for initialization.

More information can also be found in #84223 as well as the tests where
the feature usage was removed in this PR.

Closes #84223
2021-11-29 07:23:46 -08:00
bors
6db0a0e9a4 Auto merge of #91299 - cjgillot:expect-ldid, r=petrochenkov
Take a LocalDefId in expect_*item.

Items and item-likes are always HIR owners.
When trying to find such nodes, there is no ambiguity, the `LocalDefId` and the `HirId::owner` always match.
In such cases, `local_def_id_to_hir_id` does not carry any meaningful information, so we can just skip calling it altogether.
2021-11-29 15:02:01 +00:00
Deadbeef
87cd1ce6c1
ParamEnv should be const when ImplItem is within a const impl. 2021-11-29 22:21:38 +08:00
Deadbeef
8710a2e169
Reformat everything 2021-11-29 21:19:51 +08:00
Deadbeef
fdf5322169
Fix tools 2021-11-29 21:19:50 +08:00
Oli Scherer
f394bb57bb
Always use const param envs for const eval.
Nothing else makes sense, and there is no "danger" in doing so, as it only does something if there are const bounds, which are unstable. This used to happen implicitly via the inferctxt before, which was much more fragile.
2021-11-29 21:19:50 +08:00
Oli Scherer
a9a79f657c
Completely remove ConstnessAnd 2021-11-29 21:19:49 +08:00
Oli Scherer
a848c4ba3f
Avoid storing the ImplPolarity and Constness next to a TraitRef and use TraitPredicate instead 2021-11-29 21:19:49 +08:00
Oli Scherer
d161cc2071
Replace ConstnessAnd<TraitRef> with TraitPredicate which conveys the same information 2021-11-29 21:19:48 +08:00
Oli Scherer
b16c811f1c
Prefer TraitPredicate over ConstnessAnd<TraitRef> 2021-11-29 21:19:48 +08:00
Oli Scherer
d51068ca28
Use the constness from the param env instead of having a separate dimension for it
This breaks a ~const test that will be fixed in a follow up commit of this PR
2021-11-29 21:19:47 +08:00
Oli Scherer
e37947f097
Re-use constness_for_typeck instead of rolling it ourselves 2021-11-29 21:19:46 +08:00
Oli Scherer
1761d88f4a
Static items are also const 2021-11-29 21:19:46 +08:00
Oli Scherer
721ffd14c3
Add constness to ParamEnv
This now causes a lot of queries to be executed twice, as reveal_all forces NotConst
2021-11-29 21:19:46 +08:00
Oli Scherer
22eeff700e
Prepare for more ParamEnv flags 2021-11-29 21:19:42 +08:00
bors
8b954910c5 Auto merge of #91350 - matthiaskrgr:rollup-nleabdj, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #91049 (Add a caveat to std::os::windows::fs::symlink_file)
 - #91281 (Add demonstration test for #91161)
 - #91327 (Delete an unreachable codepath from format_args implementation)
 - #91336 (Remove unused root_parent.)
 - #91349 (Accumulate all values of `-C remark` option)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-29 10:34:52 +00:00
Matthias Krüger
e15e0ba45c
Rollup merge of #91349 - tmiasko:accumulate-remark-args, r=nikic
Accumulate all values of `-C remark` option

When `-C remark=...` option is specified multiple times,
accumulate all values instead of using only the last one.

r? `@nikic`
2021-11-29 10:41:38 +01:00
Matthias Krüger
b8a4a4c232
Rollup merge of #91336 - cjgillot:root_parent, r=matthewjasper
Remove unused root_parent.
2021-11-29 10:41:37 +01:00
Matthias Krüger
7df49eff10
Rollup merge of #91327 - dtolnay:exact, r=michaelwoerister
Delete an unreachable codepath from format_args implementation
2021-11-29 10:41:36 +01:00
Tomasz Miąsko
e74e39a699 Accumulate all values of -C remark option
When `-C remark=...` option is specified multiple times,
accumulate all values instead of using only the last one.
2021-11-29 09:12:01 +01:00
bors
44723c5d59 Auto merge of #91043 - camsteffen:descendant-eq, r=petrochenkov
Add fast path to `is_descendant_of`
2021-11-29 07:46:36 +00:00
Matthias Krüger
67762ffe35
Rollup merge of #90833 - tmiasko:optimization-remarks, r=nikic
Emit LLVM optimization remarks when enabled with `-Cremark`

The default diagnostic handler considers all remarks to be disabled by
default unless configured otherwise through LLVM internal flags:
`-pass-remarks`, `-pass-remarks-missed`, and `-pass-remarks-analysis`.
This behaviour makes `-Cremark` ineffective on its own.

Fix this by configuring a custom diagnostic handler that enables
optimization remarks based on the value of `-Cremark` option. With
`-Cremark=all` enabling all remarks.

Fixes #90924.

r? `@nikic`
2021-11-28 23:45:17 +01:00
Matthias Krüger
9715724006
Rollup merge of #90131 - camsteffen:fmt-args-span-fix, r=cjgillot
Fix a format_args span to be expansion

I found this while exploring solutions for rust-lang/rust-clippy#7843.

r? `@m-ou-se`
2021-11-28 23:45:15 +01:00
Cameron Steffen
ac8d514376 Add parent crate assert to register_expn_id 2021-11-28 16:35:54 -06:00
Cameron Steffen
768cfac705 Add fast path to is_descendant_of 2021-11-28 16:35:54 -06:00
Fabian Wolff
b9b4f549a4 Add a suggestion if macro_rules is misspelled 2021-11-28 23:10:37 +01:00
cameron
37ca2eb8c2 suggest cast char -> int 2021-11-28 21:46:53 +00:00
Camille GILLOT
06b2e659d3 Remove unused root_parent. 2021-11-28 21:48:28 +01:00
Camille GILLOT
877b2d79d9 Remove eval_always for lib_features. 2021-11-28 21:13:36 +01:00
Camille GILLOT
5fb4648757 Take a LocalDefId in expect_*item. 2021-11-28 21:09:45 +01:00
Aaron Hill
4910fe6889
Fix incorrect usage of EvaluatedToOk when evaluating TypeOutlives
A global predicate is not guarnatenteed to outlive all regions.
If the predicate involves late-bound regions, then it may fail
to outlive other regions (e.g. `for<'b> &'b bool: 'static` does not
hold)

We now only produce `EvaluatedToOk` when a global predicate has no
late-bound regions - in that case, the ony region that can be present
in the type is 'static
2021-11-28 15:03:58 -05:00
David Tolnay
cc53f1356d
Delete an unreachable codepath from format_args implementation 2021-11-28 11:52:38 -08:00
Alan Egerton
d05e4d2c9b
Avoid uneccessary clone of Annotatable 2021-11-28 18:41:04 +00:00
Matthias Krüger
67d175515f
Rollup merge of #91308 - BGR360:issue-88586, r=jackh726
Fix ICE when lowering `trait A where for<'a> Self: 'a`

Fixes #88586.

r? `@jackh726`

Jack, this fix is much smaller in scope than what I think you were proposing in the issue. Let me know if you had a vision for a larger refactor here.

cc `@JohnTitor`
2021-11-28 17:11:11 +01:00
Matthias Krüger
233c50e79e
Rollup merge of #91251 - oli-obk:wf_sync_statics, r=matthewjasper
Perform Sync check on static items in wf-check instead of during const checks

r? `@RalfJung`

This check is solely happening on the signature of the static item and not on its body, therefor it belongs into wf-checking instead of const checking.
2021-11-28 17:11:10 +01:00
Ben Reeves
6df2c78e1c Address PR feedback 2021-11-28 07:05:23 -06:00
bors
e6d2de9483 Auto merge of #91230 - eggyal:fallible-type-fold, r=jackh726
Make `TypeFolder::fold_*` return `Result`

Implements rust-lang/compiler-team#432.

Initially this is just a rebase of `@LeSeulArtichaut's` work in #85469 (abandoned; see https://github.com/rust-lang/rust/pull/85485#issuecomment-908781112).  At that time, it caused a regression in performance that required some further exploration... with this rebased PR bors can hopefully report some perf analysis from which we can investigate further (if the regression is indeed still present).

r? `@jackh726` cc `@nikomatsakis`
2021-11-28 13:04:27 +00:00
Matthias Krüger
7134ae0a8d
Rollup merge of #91303 - RalfJung:array-init-align, r=oli-obk
Miri: fix alignment check in array initialization

https://github.com/rust-lang/rust/pull/85376 introduced a regression in Miri, reported at https://github.com/rust-lang/miri/issues/1919 and https://github.com/rust-lang/miri/issues/1925. This PR fixes that. I will add tests to Miri once this lands.

r? `@oli-obk`
Fixes https://github.com/rust-lang/miri/issues/1919
Fixes https://github.com/rust-lang/miri/issues/1925
2021-11-28 10:42:40 +01:00
Matthias Krüger
9e8dfcffb7
Rollup merge of #91254 - Aaron1011:impl-candidate-err-ty, r=lcnr
Only check for errors in predicate when skipping impl assembly

Prior to PR #91205, checking for errors in the overall obligation
would check checking the `ParamEnv`, due to an incorrect
`super_visit_with` impl. With this bug fixed, we will now
bail out of impl candidate assembly if the `ParamEnv` contains
any error types.

In practice, this appears to be overly conservative - when an error
occurs early in compilation, we end up giving up early for some
predicates that we could have successfully evaluated without overflow.
By only checking for errors in the predicate itself, we avoid causing
additional spurious 'type annotations needed' errors after a 'real'
error has already occurred.

With this PR, the diagnostic changes caused by PR #91205 are reverted.
2021-11-28 10:42:39 +01:00
Vadim Petrochenkov
141c6cc78e expand: Turn ast::Crate into a first class expansion target
And stop creating a fake `mod` item for the crate root when expanding a crate.
2021-11-28 15:48:55 +08:00
Ben Reeves
9155f672bf typeck: Ensure proper bound vars passed to add_bounds.
Fixes the ICE in #88586.
2021-11-27 23:59:08 -06:00
Ralf Jung
f8e3b31858 Miri: fix alignment check in array initialization 2021-11-27 18:18:48 -05:00
Fabian Wolff
6dfed31c43 Improve error message for E0659 if the source is not available 2021-11-27 18:42:49 +01:00
Aaron Hill
d18065d997
Only check for errors in predicate when skipping impl assembly
Prior to PR #91205, checking for errors in the overall obligation
would check checking the `ParamEnv`, due to an incorrect
`super_visit_with` impl. With this bug fixed, we will now
bail out of impl candidate assembly if the `ParamEnv` contains
any error types.

In practice, this appears to be overly conservative - when an error
occurs early in compilation, we end up giving up early for some
predicates that we could have successfully evaluated without overflow.
By only checking for errors in the predicate itself, we avoid causing
additional spurious 'type annotations needed' errors after a 'real'
error has already occurred.

With this PR, the diagnostic changes caused by PR #91205 are reverted.
2021-11-27 11:33:55 -06:00
Alan Egerton
afa6f92c46
Use intrinsic pointer methods 2021-11-27 16:59:18 +00:00
Alan Egerton
9f714ef035
Delegate from map_id to try_map_id 2021-11-27 16:55:21 +00:00
Camille GILLOT
29b30a9bd2 Visit type in process_projection_elem. 2021-11-27 17:39:27 +01:00
Alan Egerton
04f1c09f90
Avoid UB when short-circuiting try_map_id for Vec 2021-11-27 15:06:06 +00:00
Alan Egerton
51e15ac709
Remove erroneous merge conflict 2021-11-27 11:53:00 +00:00
Matthias Krüger
7c5bcd548b
Rollup merge of #91208 - estebank:eq-constraint, r=cjgillot
Account for incorrect `where T::Assoc = Ty` bound

Provide suggestoin to constrain trait bound for associated type.
Revert incorrect changes to `missing-bounds` test.

Address part of #20041.
2021-11-27 11:46:44 +01:00
Tobias Kortkamp
47474f1055
Add riscv64gc-unknown-freebsd 2021-11-27 07:24:18 +01:00
Scott McMurray
b215a32af3 Small mir-opt refactor
Hopefully-non-controversial changes from some not-ready-yet work that I'd figured I'd submit on their own.
2021-11-26 18:18:14 -08:00
Badel2
0da3a0f56e Fix ICE #91268 by checking that the snippet ends with a ) 2021-11-26 23:57:21 +01:00
Fabian Wolff
b38a54049e Print a suggestion when comparing references to primitive types in constant functions 2021-11-26 23:10:46 +01:00
Matthew Jasper
2a83c11d4d Handle placeholder regions in NLL type outlive constraints 2021-11-26 22:06:08 +00:00
bors
6d246f0c8d Auto merge of #91253 - matthiaskrgr:rollup-dnlcjmr, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #91169 (Change cg_ssa's get_param to borrow the builder mutably)
 - #91176 (If the thread does not get the lock in the short term, yield the CPU)
 - #91212 (Fix ICE due to out-of-bounds statement index when reporting borrowck error)
 - #91225 (Fix invalid scrollbar display on source code page)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-26 16:30:42 +00:00
Matthias Krüger
13c60669cc
Rollup merge of #91212 - compiler-errors:issue91206, r=oli-obk
Fix ICE due to out-of-bounds statement index when reporting borrowck error

Replace an `[index]` with a `.get` when `statement_index` points to a basic-block terminator (and is therefore out-of-bounds in the statements list).

Fixes #91206
Cc ``@camsteffen``
r? ``@oli-obk``
2021-11-26 16:02:26 +01:00
Matthias Krüger
324b4bcb3c
Rollup merge of #91169 - RDambrosio016:master, r=bjorn3
Change cg_ssa's get_param to borrow the builder mutably

This is a small change to make `get_param` more flexible for codegens that may need to modify things when retrieving function parameters.

This will currently only be used by [rustc_codegen_nvvm](https://github.com/Rust-GPU/Rust-CUDA) (my own project), but may be useful to more codegens in the future.

This is needed because cg_nvvm needs to remap certain types to libnvvm-friendly types, such as `i128` -> `<2 x i64>`. Because cg_ssa does not give mutable access to the builder, i resorted to using a mutex:
```rs
    fn get_param(&self, index: usize) -> Self::Value {
        let val = llvm::get_param(self.llfn(), index as c_uint);
        trace!("Get param `{:?}`", val);
        unsafe {
            let llfnty = LLVMRustGetFunctionType(self.llfn());
            let map = self.remapped_integer_args.borrow();
            if let Some((_, key)) = map.get(llfnty) {
                if let Some((_, new_ty)) = key.iter().find(|t| t.0 == index) {
                    trace!("Casting irregular param {:?} to {:?}", val, new_ty);
                    return transmute_llval(
                        *self.llbuilder.lock().unwrap(),
                        &self.cx,
                        val,
                        *new_ty,
                    );
                }
            }
            val
        }
    }
```
However, i predict this is pretty bad for performance, considering how much builders are called during codegen, so i would greatly appreciate having a more flexible API for this.
2021-11-26 16:02:23 +01:00
Oli Scherer
18694126b1 Perform Sync check on static items in wf-check instead of during const checks 2021-11-26 14:22:45 +00:00
Lucas Kent
df3e7a28f7 Refactor EmitterWriter::emit_suggestion_default 2021-11-27 01:13:37 +11:00
bors
454cc5fb86 Auto merge of #91164 - Badel2:usefulness-stack-overflow, r=davidtwco
Fix stack overflow in `usefulness.rs`

Fix #88747

Applied the suggestion from `@nbdd0121,` not sure if this has any drawbacks. The first call to `ensure_sufficient_stack` is not needed to fix the test case, but I added it to be safe.
2021-11-26 13:42:35 +00:00
bors
1e79d79dac Auto merge of #91205 - Aaron1011:visit_param_env, r=lcnr
Visit `param_env` field in Obligation's `TypeFoldable` impl

This oversight appears to have gone unnoticed for a long time
without causing issues, but it should still be fixed.
2021-11-26 09:55:06 +00:00
LeSeulArtichaut
6db9605d85
Use TypeFolder::Error for FullTypeResolver and QueryNormalizer
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-26 07:40:43 +00:00
LeSeulArtichaut
30bf20a692
Unwrap the results of type folders
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-26 07:38:25 +00:00
LeSeulArtichaut
6dc3dae46f
Adapt TypeFolder implementors to return a Result
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-26 07:25:16 +00:00
LeSeulArtichaut
6e3fa20b00
Make TypeFoldable implementors short-circuit on error
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-26 07:17:59 +00:00
LeSeulArtichaut
c5f0d0ebb4
Make TypeFolder::fold_* return Result 2021-11-26 06:53:35 +00:00
bors
9adfd9db78 Auto merge of #85102 - estebank:point-at-assignment, r=oli-obk
Diagnostic tweaks

* On type mismatch caused by assignment, point at the source of the expectation
* Hide redundant errors
* Suggest `while let` when `let` is missing in some cases
2021-11-26 03:57:55 +00:00
jackh726
eeaa215f85 Don't treat unnormalized function arguments as well-formed 2021-11-25 21:16:27 -05:00
Aaron Hill
a7cc6bc4d0
Visit param_env field in Obligation's TypeFoldable impl
This oversight appears to have gone unnoticed for a long time
without causing issues, but it should still be fixed.
2021-11-25 15:33:37 -06:00
bors
dd549dcab4 Auto merge of #90580 - cjgillot:no-ee-upvar, r=Aaron1011
Remove eval_always from upvars.

Split off https://github.com/rust-lang/rust/pull/86056
r? `@ghost`
2021-11-25 19:43:56 +00:00
Esteban Küber
d6e34ad108 When recovering from a : in a pattern, use adequate AST pattern 2021-11-25 18:40:29 +00:00
Esteban Kuber
9cce7bb921 Account for type obligation coming from const and static 2021-11-25 18:04:33 +00:00
Esteban Küber
37a11a96a1 On type mismatch caused by assignment, point at assignee
* Do not emit unnecessary E0308 after E0070
* Show fewer errors on `while let` missing `let`
* Hide redundant E0308 on `while let` missing `let`
* Point at binding definition when possible on invalid assignment
* do not point at closure twice
* do not suggest `if let` for literals in lhs
* account for parameter types
2021-11-25 18:04:33 +00:00
Michael Goulet
718a3b1f2d Fix issue 91206 2021-11-25 16:34:30 +00:00
Matthias Krüger
984e644432
Rollup merge of #91185 - camelid:rm-force-overflow-checks, r=wesleywiser
Remove `-Z force-overflow-checks`

It was replaced several years ago by the stable option `-C overflow-checks`.
The goal was to delete the `-Z` flag once users had migrated [1].
Now that it's been several years, it makes sense to delete the old flag.

See also the discussion on Zulip [2].

[1]: https://github.com/rust-lang/rust/issues/33134#issuecomment-280484097
[2]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/overflow.20checks/near/262497224

r? ```@wesleywiser```
cc ```@RalfJung```
2021-11-25 15:05:40 +01:00
Matthias Krüger
5fff1d77e7
Rollup merge of #91162 - RalfJung:miri-shift-truncation, r=oli-obk
explain why CTFE/Miri perform truncation on shift offset

Closes https://github.com/rust-lang/miri/issues/1920
2021-11-25 15:05:39 +01:00
Matthias Krüger
5f6cb2c552
Rollup merge of #91111 - cjgillot:hir-no-lower-attrs, r=michaelwoerister
Do not visit attributes in `ItemLowerer`.

By default, AST visitors visit expressions that appear in key-value attributes.
Those expressions should not be lowered to HIR, as they do not correspond to actually compiled code.

Since an attribute cannot produce meaningful HIR, just skip them altogether.

Fixes https://github.com/rust-lang/rust/issues/81886
Fixes https://github.com/rust-lang/rust/issues/90873
r? `@michaelwoerister`
2021-11-25 15:05:38 +01:00
Matthias Krüger
6970cf5a23
Rollup merge of #91096 - compiler-errors:elaborate_opaque_trait, r=estebank
Print associated types on opaque `impl Trait` types

This PR generalizes #91021, printing associated types for all opaque `impl Trait` types instead of just special-casing for future.

before:
```
error[E0271]: type mismatch resolving `<impl Iterator as Iterator>::Item == u32`
```

after:
```
error[E0271]: type mismatch resolving `<impl Iterator<Item = usize> as Iterator>::Item == u32`
```

---

Questions:
1. I'm kinda lost in binders hell with this one. Is all of the `rebind`ing necessary?
2. Is there a map collection type that will give me a stable iteration order? Doesn't seem like TraitRef is Ord, so I can't just sort later..
3. I removed the logic that suppresses printing generator projection types. It creates outputs like this [gist](https://gist.github.com/compiler-errors/d6f12fb30079feb1ad1d5f1ab39a3a8d). Should I put that back?
4. I also added spaces between traits, `impl A+B` -> `impl A + B`. I quite like this change, but is there a good reason to keep it like that?

r? ````@estebank````
2021-11-25 15:05:37 +01:00
Matthias Krüger
0780889833
Rollup merge of #90499 - rusticstuff:macos-target-fixes, r=petrochenkov
Link with default MACOSX_DEPLOYMENT_TARGET if not otherwise specified.

This PR sets the MACOSX_DEPLOYMENT_TARGET environment variable during the linking stage to our default, if it is not specified. This way it matches the deployment target we pass to llvm. If not set the the linker uses Xcode or Xcode commandline tools default which varies by version.

Fixes #90342, #91082.

Drive-by fixes to make Rust behave more like clang:
* Default to 11.0 deployment target for ARM64 which is the earliest version that had support for it.
* Set the llvm target to `arm64-apple-macosx<deployment target>` instead of `aarch64-apple-macosx<deployment target>`.
2021-11-25 15:05:36 +01:00
Matthias Krüger
90dd7c03af
Rollup merge of #89359 - fee1-dead:const-it, r=oli-obk
Various fixes for const_trait_impl

A few problems I found while making `Iterator` easier to const-implement.

1. More generous `~const Drop` check.

We check for nested fields with caller bounds.

For example, an ADT type with fields of types `A`, `B`, `C`, check if all of them are either:
 - Bounded (`A: ~const Drop`, `B: Copy`)
 - Known to be able to destruct at compile time (`C = i32`, `struct C(i32)`, `C = some_fn`)

2. Don't treat trait functions marked with `#[default_method_body_is_const]` as stable const fns when checking `const_for` and `const_try` feature gates.

I think anyone can review this, so no r? this time.
2021-11-25 15:05:35 +01:00
bors
23a436606b Auto merge of #88781 - estebank:emoji-idents, r=oli-obk
Tokenize emoji as if they were valid identifiers

In the lexer, consider emojis to be valid identifiers and reject
them later to avoid knock down parse errors.

Partially address #86102.
2021-11-25 08:16:08 +00:00
Hans Kratz
b376f5621b Set MACOSX_DEPLOYMENT_TARGET env var to default for linking if not set. 2021-11-25 07:08:44 +01:00
Hans Kratz
8f4d88c4bf Set the default deployment target for Macos ARM64 to 11.0.
11.0 (Big Sur) is the first version which supports ARM64 so we use
that as default.
2021-11-25 07:08:37 +01:00
Hans Kratz
fa18030567 The correct LLVM target for aarch64-apple-darwin is arm64-... (as with ios) 2021-11-25 06:56:42 +01:00
bors
c6eda7d8a7 Auto merge of #85346 - estebank:issue-84946, r=nagisa,varkor
Account for incorrect `impl Foo<const N: ty> {}` syntax

Fix #84946
2021-11-25 05:09:51 +00:00
Esteban Kuber
4954389a9d Account for incorrect where T::Assoc = Ty bound
Provide suggestoin to constrain trait bound for associated type.
Revert incorrect changes to `missing-bounds` test.

Address part of #20041.
2021-11-25 01:49:48 +00:00
Camille GILLOT
7f5d3fff4f Do not visit attributes in LateResolutionVisitor. 2021-11-25 00:24:04 +01:00
Esteban Kuber
505b09e326 Tweak span and add more tests 2021-11-24 22:04:52 +00:00
Guillaume Gomez
a6a1d7ca29
Rollup merge of #90420 - GuillaumeGomez:rustdoc-internals-feature, r=camelid
Create rustdoc_internals feature gate

As suggested by ``@camelid`` [here](https://github.com/rust-lang/rust/pull/90398#issuecomment-955093851), since `doc_keyword` and `doc_primitive` aren't meant to be stabilized, we could put them behind a same feature flag.

This is pretty much what it would look like (needs to update the tests too).

The tracking issue is https://github.com/rust-lang/rust/issues/90418.

What do you think ``@rust-lang/rustdoc`` ?
2021-11-24 22:56:37 +01:00
Guillaume Gomez
cbe563a4d5
Rollup merge of #90044 - rusticstuff:disable_arm_outline_atomics_for_musl, r=workingjubilee
Restrict aarch64 outline atomics to glibc for now.

The introduced dependency on `getauxval` causes linking problems with musl, making compiling any binaries for `aarch64-unknown-linux-musl` impossible without workarounds such as using lld or adding liblibc.rlib again to the linker invocation, see #89626.

This is a workaround until libc>0.2.108 is merged.
2021-11-24 22:56:36 +01:00
Guillaume Gomez
3c77b56d94 Update error message for doc(keyword) 2021-11-24 21:57:18 +01:00
Guillaume Gomez
1e6ced3532 Create rustdoc_internals feature gate 2021-11-24 21:57:18 +01:00
Esteban Küber
7190bc3097 Account for incorrect impl Foo<const N: ty> {} syntax
Fix #84946
2021-11-24 20:02:09 +00:00
Noah Lev
f0b990a8f9 Remove -Z force-overflow-checks
It was replaced several years ago by the stable option `-C
overflow-checks`. The goal was to delete the `-Z` flag once users had
migrated [1]. Now that it's been several years, it makes sense to delete
the old flag.

See also the discussion on Zulip [2].

[1]: https://github.com/rust-lang/rust/issues/33134#issuecomment-280484097
[2]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/overflow.20checks/near/262497224
2021-11-24 10:19:23 -08:00
bors
8a48b376d5 Auto merge of #90491 - Mark-Simulacrum:push-pred-faster, r=matthewjasper
Optimize live point computation

This refactors the live-point computation to lower per-MIR-instruction costs by operating on a largely per-block level. This doesn't fundamentally change the number of operations necessary, but it greatly improves the practical performance by aggregating bit manipulation into ranges rather than single-bit; this scales much better with larger blocks.

On the benchmark provided in #90445, with 100,000 array elements, walltime for a check build is improved from 143 seconds to 15.

I consider the tiny losses here acceptable given the many small wins on real world benchmarks and large wins on stress tests. The new code scales much better, but on some subset of inputs the slightly higher constant overheads decrease performance somewhat. Overall though, this is expected to be a big win for pathological cases (as illustrated by the test case motivating this work) and largely not material for non-pathological cases. I consider the new code somewhat easier to follow, too.
2021-11-24 15:51:46 +00:00
bors
c6a7ca196a Auto merge of #90579 - cjgillot:no-ee-ii, r=Aaron1011
Remove eval_always for inherent_impls.

Split off https://github.com/rust-lang/rust/pull/86056
r? `@ghost`
2021-11-24 12:51:19 +00:00
Deadbeef
4f29f3cef8
Add impl polarity to fields 2021-11-24 16:31:47 +08:00
Deadbeef
b2005117bc
Allow features like const_try in d_m_b_i_c 2021-11-24 15:57:44 +08:00
Deadbeef
e0c2ff7ccc
Allow more cases to match ~const Drop. 2021-11-24 15:57:40 +08:00
Deadbeef
3b25e92a8f
Debug 2021-11-24 15:55:21 +08:00
woppopo
89b2e0c9d5 Make intrinsics::write_bytes const 2021-11-24 13:05:26 +09:00
rdambrosio
870b8311c1 Feat: make cg_ssa get_param borrow the builder mutable 2021-11-23 22:30:20 -05:00
Ralf Jung
5f6ccf6121 document BinOp behavior quirks in the corresponding enum 2021-11-23 20:30:26 -05:00
Arpad Borsos
566ad8da45 Update CoverageMappingFormat Support to Version6
Version 5 adds Branch Regions which are a prerequisite for branch coverage.
Version 6 can use the zeroth filename as prefix for other relative files.
2021-11-23 15:49:03 -08:00
bors
de4b242e1e Auto merge of #91149 - notriddle:notriddle/rustdoc-doctest-semicolon, r=jyn514
fix(doctest): detect extern crate items in statement doctests

This partially reverts #91026, because rustdoc needs to detect the extern statements, even when they appear inside implicit `main()`. It does not entirely revert it, so the old bug is still fixed, by duplicating some of the logic from `parse_mod` instead of trying to use it directly.

Fixes #91134
2021-11-23 23:48:55 +00:00
Badel2
6955afe8fd Fix stack overflow in usefulness.rs 2021-11-23 23:07:11 +01:00
Camille GILLOT
ae126ad282 Do not visit attributes in ItemLowerer.
By default, AST visitors visit expressions that appear in key-value attributes.
Those expressions should not be lowered to HIR, as they do not correspond to actually compiled code.

Since an attribute cannot produce meaningful HIR, just skip them altogether.
2021-11-23 22:06:22 +01:00
bors
65c55bf931 Auto merge of #91159 - matthiaskrgr:rollup-91mgg5v, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #90856 (Suggestion to wrap inner types using 'allocator_api' in tuple)
 - #91103 (Inhibit clicks on summary's children)
 - #91137 (Give people a single link they can click in the contributing guide)
 - #91140 (Split inline const to two feature gates and mark expression position inline const complete)
 - #91148 (Use `derive_default_enum` in the compiler)
 - #91153 (kernel_copy: avoid panic on unexpected OS error)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-23 20:44:33 +00:00
Esteban Kuber
5402e4833f Sort FxHashSet's contents before emitting errors for consistent output 2021-11-23 20:37:24 +00:00
Esteban Kuber
38979a3ba1 udpate comment to be more accurate 2021-11-23 20:37:23 +00:00
Esteban Kuber
143f784199 replace_tabs -> normalize_whitespace 2021-11-23 20:37:21 +00:00
Esteban Kuber
d68add9ecc review comment: plural of emoji is emoji 2021-11-23 20:36:19 +00:00
Esteban Kuber
21224e6ee0 Account for confusable codepoints when recovering emoji identifiers 2021-11-23 20:36:19 +00:00
Esteban Kuber
a96fe02f6c Replace ZWJ with nothing in terminal output 2021-11-23 20:36:14 +00:00
Esteban Kuber
5a68abb094 Tokenize emoji as if they were valid indentifiers
In the lexer, consider emojis to be valid identifiers and reject
them later to avoid knock down parse errors.
2021-11-23 20:35:07 +00:00
Ralf Jung
94c9c22b39 explain why CTFE/Miri perform truncation on shift offset 2021-11-23 14:12:14 -05:00
Michael Goulet
9cc117930b Fix printing unit return ty, don't elaborate FnOnce unless we see it 2021-11-23 11:05:07 -08:00
Michael Goulet
471334e996 Suppress noisy generator associated type 2021-11-23 10:34:16 -08:00
Michael Goulet
b84a52c95a Add generator lang-item 2021-11-23 10:34:16 -08:00
Michael Goulet
ce182d17f8 Elaborate trait generics and associated types 2021-11-23 10:34:16 -08:00
Michael Goulet
c969b1dea0 Add supertraits method to rustc_middle 2021-11-23 10:34:16 -08:00
Michael Goulet
8756d0701e Derive Ord and PartialOrd for TraitRef 2021-11-23 10:34:16 -08:00
Matthias Krüger
e52e3a4bb3
Rollup merge of #91148 - jhpratt:use-default-enum, r=petrochenkov
Use `derive_default_enum` in the compiler

Let's get this feature some real-world love.

``@rustbot`` label: +C-cleanup +S-waiting-on-review
2021-11-23 19:28:11 +01:00
Matthias Krüger
a26c2c7495
Rollup merge of #91140 - nbdd0121:const_typeck, r=oli-obk
Split inline const to two feature gates and mark expression position inline const complete

This PR splits inline const in pattern position into its own `#![feature(inline_const_pat)]` feature gate, and make the usage in expression position complete.

I think I have resolved most outstanding issues related to `inline_const` with #89561 and other PRs. The only thing left that I am aware of is #90150 and the lack of lifetime checks when inline const is used in pattern position (FIXME in #89561). Implementation-wise when used in pattern position it has to be lowered during MIR building while in expression position it's evaluated only when monomorphizing (just like normal consts), so it makes some sense to separate it into two feature gates so one can progress without being blocked by another.

``@rustbot`` label: T-compiler F-inline_const
2021-11-23 19:28:10 +01:00
Matthias Krüger
68a44c8228
Rollup merge of #90856 - ken-matsui:suggestion-to-wrap-vec-allocator-api-in-tuple, r=davidtwco
Suggestion to wrap inner types using 'allocator_api' in tuple

This PR provides a suggestion to wrap the inner types in tuple when being along with 'allocator_api'.

Closes https://github.com/rust-lang/rust/issues/83250

```rust
fn main() {
    let _vec: Vec<u8, _> = vec![]; //~ ERROR use of unstable library feature 'allocator_api'
}
```

```diff
 error[E0658]: use of unstable library feature 'allocator_api'
   --> $DIR/suggest-vec-allocator-api.rs:2:23
    |
 LL |     let _vec: Vec<u8, _> = vec![];
-   |                       ^
+   |                   ----^
+   |                   |
+   |                   help: consider wrapping the inner types in tuple: `(u8, _)`
    |
    = note: see issue #32838 <https://github.com/rust-lang/rust/issues/32838> for more information
    = help: add `#![feature(allocator_api)]` to the crate attributes to enable
```
2021-11-23 19:28:06 +01:00
bors
7b3cd075bb Auto merge of #90788 - ecstatic-morse:issue-90752, r=wesleywiser
Mark places as initialized when mutably borrowed

Fixes the example in #90752, but does not handle some corner cases involving raw pointers and unsafe. See [this comment](https://github.com/rust-lang/rust/issues/90752#issuecomment-965822895) for more information, or the second test.

Although I talked about both `MaybeUninitializedPlaces` and `MaybeInitializedPlaces` in #90752, this PR only changes the latter. That's because "maybe uninitialized" is the conservative choice, and marking them as definitely initialized (`!maybe_uninitialized`) when a mutable borrow is created could lead to problems if `addr_of_mut` to an uninitialized local is allowed. Additionally, places cannot become uninitialized via a mutable reference, so if a place is definitely initialized, taking a mutable reference to it should not change that.

I think it's correct to ignore interior mutability as nbdd0121 suggests below. Their analysis doesn't work inside of `core::cell`, which *does* have access to `UnsafeCell`'s field, but that won't be an issue unless we explicitly instantiate one with an `enum` within that module.

r? `@wesleywiser`
2021-11-23 17:44:33 +00:00
Ken Matsui
57494f7c75
Suggestion to wrap inner types using allocator_api in tuple 2021-11-24 00:24:13 +09:00
bors
311fa1f14d Auto merge of #89881 - Mark-Simulacrum:fieldless-fast, r=davidtwco
Avoid generating empty closures for fieldless enum variants

For many enums, this avoids generating lots of tiny stubs that need to be codegen'd and then inlined and removed by LLVM. perf shows this to be a fairly small, but significant, win on rustc bootstrap time -- with minimal impact on runtime performance (which is at times even positive).
2021-11-23 13:56:00 +00:00
bors
22c2d9ddbf Auto merge of #89883 - Mark-Simulacrum:incr-verify-outline, r=nnethercote
Manually outline error on incremental_verify_ich

This reduces codegen for rustc_query_impl by 169k lines of LLVM IR, representing
a 1.2% improvement. This code should be fairly cold, so hopefully this has minimal
performance impact.
2021-11-23 09:10:50 +00:00
Michael Howell
bff1645bdb fix(doctest): detect extern crate items in statement doctests
This partially reverts #91026, because rustdoc needs to detect the extern statements,
even when they appear inside implicit `main()`. It does not entirely revert it,
so the old bug is still fixed, by duplicating some of the logic from `parse_mod`
instead of trying to use it directly.

Fixes #91134
2021-11-22 19:47:58 -07:00
Mark Rousskov
dc65b22901 Manually outline error on incremental_verify_ich
This reduces codegen for rustc_query_impl by 169k lines of LLVM IR, representing
a 1.2% improvement.
2021-11-22 21:32:20 -05:00
Mark Rousskov
3228603cce Avoid generating empty closures for fieldless enums
For many enums, this avoids generating lots of tiny stubs that need to be
codegen'd and then inlined and removed by LLVM.
2021-11-22 21:22:35 -05:00
Jacob Pratt
7b103e7dd2
Use derive_default_enum in the compiler 2021-11-22 20:17:53 -05:00
Eric Holk
ca2057cedf Fix comments 2021-11-22 14:57:33 -08:00
Eric Holk
dfa0db5961 Reintroduce into_future in .await desugaring
This is a reintroduction of the remaining parts from
https://github.com/rust-lang/rust/pull/65244 that have not been relanded
yet.

Issues GH-67644, GH-67982
2021-11-22 14:57:27 -08:00
Gary Guo
6f38568dec #![feature(inline_const)] is no longer incomplete 2021-11-22 22:17:03 +00:00
Gary Guo
6d61d87b22 Split inline const to two feature gates 2021-11-22 22:17:03 +00:00
Benjamin A. Bjørnseth
bb9dee95ed add rustc option for using LLVM stack smash protection
LLVM has built-in heuristics for adding stack canaries to functions. These
heuristics can be selected with LLVM function attributes. This patch adds a
rustc option `-Z stack-protector={none,basic,strong,all}` which controls the use
of these attributes. This gives rustc the same stack smash protection support as
clang offers through options `-fno-stack-protector`, `-fstack-protector`,
`-fstack-protector-strong`, and `-fstack-protector-all`. The protection this can
offer is demonstrated in test/ui/abi/stack-protector.rs. This fills a gap in the
current list of rustc exploit
mitigations (https://doc.rust-lang.org/rustc/exploit-mitigations.html),
originally discussed in #15179.

Stack smash protection adds runtime overhead and is therefore still off by
default, but now users have the option to trade performance for security as they
see fit. An example use case is adding Rust code in an existing C/C++ code base
compiled with stack smash protection. Without the ability to add stack smash
protection to the Rust code, the code base artifacts could be exploitable in
ways not possible if the code base remained pure C/C++.

Stack smash protection support is present in LLVM for almost all the current
tier 1/tier 2 targets: see
test/assembly/stack-protector/stack-protector-target-support.rs. The one
exception is nvptx64-nvidia-cuda. This patch follows clang's example, and adds a
warning message printed if stack smash protection is used with this target (see
test/ui/stack-protector/warn-stack-protector-unsupported.rs). Support for tier 3
targets has not been checked.

Since the heuristics are applied at the LLVM level, the heuristics are expected
to add stack smash protection to a fraction of functions comparable to C/C++.
Some experiments demonstrating how Rust code is affected by the different
heuristics can be found in
test/assembly/stack-protector/stack-protector-heuristics-effect.rs. There is
potential for better heuristics using Rust-specific safety information. For
example it might be reasonable to skip stack smash protection in functions which
transitively only use safe Rust code, or which uses only a subset of functions
the user declares safe (such as anything under `std.*`). Such alternative
heuristics could be added at a later point.

LLVM also offers a "safestack" sanitizer as an alternative way to guard against
stack smashing (see #26612). This could possibly also be included as a
stack-protection heuristic. An alternative is to add it as a sanitizer (#39699).
This is what clang does: safestack is exposed with option
`-fsanitize=safe-stack`.

The options are only supported by the LLVM backend, but as with other codegen
options it is visible in the main codegen option help menu. The heuristic names
"basic", "strong", and "all" are hopefully sufficiently generic to be usable in
other backends as well.

Reviewed-by: Nikita Popov <nikic@php.net>

Extra commits during review:

- [address-review] make the stack-protector option unstable

- [address-review] reduce detail level of stack-protector option help text

- [address-review] correct grammar in comment

- [address-review] use compiler flag to avoid merging functions in test

- [address-review] specify min LLVM version in fortanix stack-protector test

  Only for Fortanix test, since this target specifically requests the
  `--x86-experimental-lvi-inline-asm-hardening` flag.

- [address-review] specify required LLVM components in stack-protector tests

- move stack protector option enum closer to other similar option enums

- rustc_interface/tests: sort debug option list in tracking hash test

- add an explicit `none` stack-protector option

Revert "set LLVM requirements for all stack protector support test revisions"

This reverts commit a49b74f92a4e7d701d6f6cf63d207a8aff2e0f68.
2021-11-22 20:06:22 +01:00
bors
f7c48297ce Auto merge of #88681 - ehuss:duplicate-attributes, r=petrochenkov
Check for duplicate attributes.

This adds some checks for duplicate attributes. In many cases, the duplicates were being ignored without error or warning. This adds several kinds of checks (see `AttributeDuplicates` enum).

The motivation here is to issue unused warnings with similar reasoning for any unused lint, and to error for cases where there are conflicts.

This also adds a check for empty attribute lists in a few attributes where this causes the attribute to be ignored.

Closes #55112.
2021-11-22 02:15:25 +00:00
Eric Huss
36dcd4cbd9 Update link_ordinal duplicate attribute handling.
This removes the duplicate check, as this is now handled in a
centralized location.
2021-11-21 08:02:00 -08:00
Cameron Steffen
9c83f8c4d1 Simplify for loop desugar 2021-11-21 08:15:21 -06:00