Commit graph

5203 commits

Author SHA1 Message Date
Smitty
e4ce655cbf Handle pretty printing of else if let clauses
Closes #84434. Closes #82329.
2021-04-23 13:29:18 -04:00
Alex Crichton
35ae752231 Disable LLVM's new fptoint intrinsics on riscv64
Looks like this platform still isn't quite working yet due to
https://bugs.llvm.org/show_bug.cgi?id=50083
2021-04-23 07:45:23 -07:00
Santiago Pastorino
83767d97f0
Add pub_macro_rules to the list of removed features 2021-04-23 10:58:07 -03:00
Santiago Pastorino
0e4d2fd447
Revert "Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakis"
This reverts commit e2561c58a4, reversing
changes made to 2982ba50fc.
2021-04-23 10:40:32 -03:00
bors
236580bc5b Auto merge of #83425 - durin42:llvm-update, r=nagisa
RustWrapper: work around unification of diagnostic handlers

This lets me build against llvm/main as of March 23rd, 2021. I'm not
entirely sure this is _correct_, but it appears to be functionally
identical to what was done in LLVM: existing callsites of
setInlineAsmDiagnosticHandler were moved to SetDiagnosticHandler() on
the context object, which we already set up in both places that we
called setInlineAsmDiagnosticHandler().
2021-04-23 05:29:12 +00:00
Joshua Nelson
2b026782d8 Update comment on PrimTy::name_str 2021-04-22 23:32:48 -04:00
Rich Kadel
a07bf2e174 Fix ICE if original_span(fn_sig) returns a span not in body sourcefile
Fixes: #84421
2021-04-22 15:49:13 -07:00
bors
7f4afdf025 Auto merge of #84420 - workingjubilee:microvec, r=Mark-Simulacrum
Use arrayvec 0.7, drop smallvec 0.6

With the arrival of min const generics, many alt-vec libraries have
updated to use it in some way and arrayvec is no exception. Use the
latest with minor refactoring.

Also, rustc_workspace_hack is the only user of smallvec 0.6 in the
entire tree, so drop it.
2021-04-22 21:01:24 +00:00
Augie Fackler
fc2a74c640 RustWrapper: work around unification of diagnostic handlers
This lets me build against llvm/main as of March 23rd, 2021. I'm not
entirely sure this is _correct_, but it appears to be functionally
identical to what was done in LLVM: existing callsites of
setInlineAsmDiagnosticHandler were moved to SetDiagnosticHandler() on
the context object, which we already set up in both places that we
called setInlineAsmDiagnosticHandler().
2021-04-22 15:46:47 -04:00
Dylan DPC
f180c1e05d
Rollup merge of #84404 - tmiasko:intrinsics-in-coercion-lub, r=Mark-Simulacrum
Check for intrinsics before coercing to a function pointer

Return an error if coercing function items / non-capturing closures
to a common function pointer type would require reifying an intrinsic.

Turns ICE reported in #84297 into a proper error.
2021-04-22 18:14:42 +02:00
Dylan DPC
9b432e0234
Rollup merge of #84377 - jackh726:binder-refactor-fix, r=nikomatsakis
Followup to #83944

Some cleanups requested by ``@nikomatsakis``

r? ``@nikomatsakis``
2021-04-22 18:14:39 +02:00
Dylan DPC
2f438e31f5
Rollup merge of #84343 - camsteffen:closure-tree, r=varkor
Remove `ScopeTree::closure_tree`

Seems to be dead code since #50649.
2021-04-22 18:14:32 +02:00
Joshua Nelson
1a46b26422 Make a few functions private
These were made public in 3105bcfdc1. This
is so long ago I doubt anyone remembers why they're public. No one uses
them, including in-tree tools.
2021-04-22 09:22:30 -04:00
bors
25c15cdbe0 Auto merge of #71511 - hi-rustin:rustin-patch-rename-assoc, r=eddyb,varkor
Rename AssociatedItems to AssocItems

Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>

Part of https://github.com/rust-lang/rust/issues/60163#issuecomment-605308641
2021-04-22 11:32:50 +00:00
Jubilee Young
e8eb691c1f Use arrayvec 0.7, drop smallvec 0.6
With the arrival of min const generics, many alt-vec libraries have
updated to use it in some way and arrayvec is no exception. Use the
latest with minor refactoring.

Also, rustc_workspace_hack is the only user of smallvec 0.6 in the
entire tree, so drop it.
2021-04-21 22:39:08 -07:00
bors
71965ab4d0 Auto merge of #84411 - m-ou-se:rollup-9btsp2t, r=m-ou-se
Rollup of 12 pull requests

Successful merges:

 - #84013 (Replace all `fmt.pad` with `debug_struct`)
 - #84119 (Move `sys::vxworks` code to `sys::unix`)
 - #84212 (Replace `Void` in `sys` with never type)
 - #84251 (fix 'const-stable since' for NonZeroU*::new_unchecked)
 - #84301 (Document that `index` and `index_mut` can panic)
 - #84365 (Improve the docstrings of the `Lto` struct.)
 - #84378 (Fix broken doc link)
 - #84379 (Add GAT related tests)
 - #84380 (Write Rustdoc titles like "x in crate::mod - Rust")
 - #84390 (Format `Struct { .. }` on one line even with `{:#?}`.)
 - #84393 (Support `x.py doc std --open`)
 - #84406 (Remove `delete` alias from `mem::drop`.)

Failed merges:

 - #84387 (Move `sys_common::poison` to `sync::poison`)

r? `@ghost`
`@rustbot` modify labels: rollup
2021-04-22 05:01:30 +00:00
Mara Bos
6967b68667
Rollup merge of #84365 - vext01:improve-lto-docstrings, r=petrochenkov
Improve the docstrings of the `Lto` struct.

This change is the result of [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Making.20sense.20of.20LTO.20modes.20in.20rustc).

Hopefully it makes things a little clearer. What do you think?
2021-04-21 23:06:17 +02:00
Josh Stone
2a97c690bc Note array.into_iter() specifically in method probing 2021-04-21 13:04:59 -07:00
The8472
7f45cdb090 bump jobserver dependency
the newest jobserver version should slightly reduce context switches
in highly parallel build environments on linux kernels >= 5.6
2021-04-21 22:02:54 +02:00
Jack Huey
c78724f869 More review changes 2021-04-21 12:26:19 -04:00
Jack Huey
b78c0d8a4d Review comments 2021-04-21 11:49:59 -04:00
Alex Crichton
de2a4601ab rustc: Use LLVM's new saturating float-to-int intrinsics
This commit updates rustc, with an applicable LLVM version, to use
LLVM's new `llvm.fpto{u,s}i.sat.*.*` intrinsics to implement saturating
floating-point-to-int conversions. This results in a little bit tighter
codegen for x86/x86_64, but the main purpose of this is to prepare for
upcoming changes to the WebAssembly backend in LLVM where wasm's
saturating float-to-int instructions will now be implemented with these
intrinsics.

This change allows simplifying a good deal of surrounding code, namely
removing a lot of wasm-specific behavior. WebAssembly no longer has any
special-casing of saturating arithmetic instructions and the need for
`fptoint_may_trap` is gone and all handling code for that is now
removed. This means that the only wasm-specific logic is in the
`fpto{s,u}i` instructions which only get used for "out of bounds is
undefined behavior". This does mean that for the WebAssembly target
specifically the Rust compiler will no longer be 100% compatible with
pre-LLVM 12 versions, but it seems like that's unlikely to be relied on
by too many folks.

Note that this change does immediately regress the codegen of saturating
float-to-int casts on WebAssembly due to the specialization of the LLVM
intrinsic not being present in our LLVM fork just yet. I'll be following
up with an LLVM update to pull in those patches, but affects a few other
SIMD things in flight for WebAssembly so I wanted to separate this change.

Eventually the entire `cast_float_to_int` function can be removed when
LLVM 12 is the minimum version, but that will require sinking the
complexity of it into other backends such as Cranelfit.
2021-04-21 07:15:53 -07:00
lcnr
d3e0d2f53d supply substs to anon consts in defaults 2021-04-21 15:25:58 +02:00
lcnr
312b4fdfd2 improve wf check for const param defaults 2021-04-21 15:25:58 +02:00
lcnr
7cb1dcd488 loosen ordering restricts for const_generics_defaults 2021-04-21 15:25:58 +02:00
lcnr
259a368e9e fix name resolution for param defaults 2021-04-21 15:25:32 +02:00
Jack Huey
4568e7d62e Move nested quantification check to ast_validation 2021-04-21 03:12:04 -04:00
Tomasz Miąsko
75732dd00e Check for intrinsics before coercing to a function pointer
Return an error if coercing function items / non-capturing closures
to a common function pointer type would require reifying an intrinsic.
2021-04-21 00:00:00 +00:00
Jack Huey
9891582897 Remove TraitRefHackInner and use the concatenating functionality instead of trait_ref_hack 2021-04-20 16:43:04 -04:00
Jack Huey
457c4c133a Add BinderScopeType to replace binder_depth and from_poly_trait_ref 2021-04-20 16:42:46 -04:00
Jack Huey
32942ab807 A non-minimal set of TraitRefBoundarys to work on removing from_poly_trait_ref 2021-04-20 16:41:54 -04:00
Jack Huey
ba3d22ed66 Precompute inverse binder depth 2021-04-20 16:41:54 -04:00
bors
6df26f897c Auto merge of #84353 - estebank:as-ref-mir, r=davidtwco
Suggest `.as_ref()` on borrow error involving `Option`/`Result`

When encountering a E0382 borrow error involving an `Option` or `Result`
provide a suggestion to use `.as_ref()` on the prior move location to
avoid the move.

Fix #84165.
2021-04-20 14:05:12 +00:00
Oli Scherer
6e988c0613 Typo 2021-04-20 09:30:28 -04:00
Oli Scherer
a46bc5664a Tidy 2021-04-20 09:30:28 -04:00
Oli Scherer
a2f2179026 Add an attribute to be able to configure the limit 2021-04-20 09:30:28 -04:00
Oli Scherer
e9696c8b62 Implement a lint that highlights all moves larger than 1000 bytes 2021-04-20 09:30:21 -04:00
Edd Barrett
8cc918a3dc Improve the docstrings of the Lto struct. 2021-04-20 10:28:17 +01:00
bors
6af1e632a9 Auto merge of #84323 - richkadel:uncovered-functions, r=tmandry
coverage of async function bodies should match non-async

This fixes some missing coverage within async function bodies.

Commit 1 demonstrates the problem in the fixed issue, and commit 2 corrects it.

Fixes: #83985
2021-04-20 08:33:51 +00:00
bors
b2c20b51ed Auto merge of #84295 - richkadel:continue-coverage, r=tmandry
Add coverage to continue statements

`continue` statements were missing coverage. This was particularly
noticeable in a match pattern that contained only a `continue`
statement, leaving the branch appear uncounted. This PR addresses the
problem and adds tests to prove it.

r? `@tmandry`
cc: `@wesleywiser`
2021-04-20 03:08:24 +00:00
bors
e888a57da8 Auto merge of #84334 - klensy:typo-compiler, r=jyn514
fix few typos in comments
2021-04-20 00:16:45 +00:00
Esteban Küber
2763a0541c Suggest .as_ref() on borrow error involving Option/Result
When encountering a E0382 borrow error involving an `Option` or `Result`
provide a suggestion to use `.as_ref()` on the prior move location to
avoid the move.

Fix #84165.
2021-04-19 17:14:37 -07:00
bors
9d9c2c92b8 Auto merge of #84342 - Dylan-DPC:rollup-5b40142, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #84123 (Introduce CompileMonoItem DepNode)
 - #84126 (Enable sanitizers for x86_64-unknown-linux-musl)
 - #84168 (Lower async fn in traits.)
 - #84256 (doc: use U+2212 for minus sign in floating-point -0.0 remarks)
 - #84291 (fix aliasing violations in thread_local_const_init)
 - #84313 (fix suggestion for unsized function parameters)
 - #84330 (Remove unused footer section)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-04-19 20:49:27 +00:00
Cameron Steffen
c9c14d0c1f Small refactor 2021-04-19 15:40:21 -05:00
Cameron Steffen
98a11e01e5 Remove closure_tree 2021-04-19 15:40:20 -05:00
Dylan DPC
349fae3a32
Rollup merge of #84313 - lcnr:sized-err-msg, r=petrochenkov
fix suggestion for unsized function parameters

taken from `@fasterthanlime's` article https://fasterthanli.me/articles/whats-in-the-box
2021-04-19 22:00:10 +02:00
Dylan DPC
e5b5745db1
Rollup merge of #84168 - cjgillot:asi, r=davidtwco
Lower async fn in traits.

An error is already created by AST validation.

Fixes #84149
2021-04-19 22:00:06 +02:00
Dylan DPC
3b81ea86fb
Rollup merge of #84126 - 12101111:musl-sanitizer, r=davidtwco
Enable sanitizers for x86_64-unknown-linux-musl

Those 4 sanitizers get musl target support in LLVM 12 release.
2021-04-19 22:00:04 +02:00
Dylan DPC
817b7e0c11
Rollup merge of #84123 - bjorn3:compile_mono_item_dep_node, r=wesleywiser
Introduce CompileMonoItem DepNode

This is likely required for allowing efficient hot code swap support in cg_clif's jit mode. My prototype currently requires re-compiling all functions, which is both slow and uses a lot of memory as there is not support for freeing the memory used by replaced functions yet.

cc https://github.com/bjorn3/rustc_codegen_cranelift/issues/1087
2021-04-19 22:00:01 +02:00
Rich Kadel
5d8d67f746 compute fn_sig span from body call_site, and use body ctxt, not root 2021-04-19 12:30:55 -07:00
lcnr
a8193ca4c3 fix suggestion for unsized function parameters 2021-04-19 20:06:19 +02:00
bors
1a6c98e4d6 Auto merge of #84091 - tmiasko:check-attrs-sym, r=davidtwco
Match against attribute name when validating attributes

Extract attribute name once and match it against symbols that are being
validated, instead of using `Session::check_name` for each symbol
individually.

Assume that all validated attributes are used, instead of marking them
as such, since the attribute check should be exhaustive.
2021-04-19 18:05:44 +00:00
Ralf Jung
46d09f7a4b remove E0723 error code 2021-04-19 14:58:11 +02:00
klensy
f43ee8ebf6 fix few typos 2021-04-19 15:57:08 +03:00
Ralf Jung
04db4abbfc add gate tests and pacify tidy 2021-04-19 10:25:31 +02:00
bors
532609b01c Auto merge of #84316 - teymour-aldridge:improve-defaulted-never-note, r=petrochenkov
Improve an error message.
2021-04-19 04:51:48 +00:00
bors
c4ba8e3e5f Auto merge of #83799 - crlf0710:stablize_non_ascii_idents, r=Manishearth
Stablize `non-ascii-idents`

This is the stablization PR for RFC 2457. Currently this is waiting on fcp in [tracking issue](https://github.com/rust-lang/rust/issues/55467).

r? `@Manishearth`
2021-04-18 23:28:43 +00:00
Rich Kadel
1893721ec4 Fixes the issue with uncovered source in async function bodies
The body_span was assumed to be in the Span root context, but this was
not the case for async function bodies.
2021-04-18 16:26:18 -07:00
Ralf Jung
bd9556956a fix feature use in rustc libs 2021-04-18 22:05:45 +02:00
teymour-aldridge
567de4a202 Improve an error message. 2021-04-18 20:38:23 +01:00
Rich Kadel
d1d7fb1ae5 Only generate dummy assign when instrumenting coverage
And make the LocalDecl internal, to avoid needing to declare storage.
(For multiple `continue` stateuemtns, it must also be mutable.)
2021-04-18 12:09:14 -07:00
Ralf Jung
fbfaab2cb7 separate feature flag for unsizing casts in const fn 2021-04-18 19:11:29 +02:00
Ralf Jung
fdad6ab3a3 move 'trait bounds on const fn' to separate feature gate 2021-04-18 18:36:41 +02:00
bors
ef88434286 Auto merge of #84274 - nagisa:fix-simd, r=nikic
Don't set fast-math for the SIMD operations we set it for previously

Instead of `fast-math`. `fast-math` implies things like functions not
being able to accept as an argument or return as a result, say, `inf`
which made these functions confusingly named or behaving incorrectly,
depending on how you interpret it. It seems that the intended behaviour
was to set a `afn` flag instead. In doing so we also renamed the
intrinsics to say `_approx` so that it is clear these are not precision
oriented and the users can act accordingly.

Fixes #84268
2021-04-18 14:39:34 +00:00
Rich Kadel
448e52d97c Add coverage to continue statements
`continue` statements were missing coverage. This was particularly
noticeable in a match pattern that contained only a `continue`
statement, leaving the branch appear uncounted. This PR addresses the
problem and adds tests to prove it.
2021-04-18 03:11:25 -07:00
bors
dc99219d3a Auto merge of #84064 - hyd-dev:unknown-lints, r=petrochenkov
Do not ignore path segments in the middle in `#[allow]`/`#[warn]`/`#[deny]`/`#[forbid]` attributes

Fixes #83477.
2021-04-18 02:12:13 +00:00
Simonas Kazlauskas
487e27350a Don't set fast(-math) for certain simd ops
`fast-math` implies things like functions not being able to accept as an
argument or return as a result, say, `inf` which made these functions
confusingly named or behaving incorrectly, depending on how you
interpret it. Since the time when these intrinsics have been implemented
the intrinsics user's (stdsimd) approach has changed significantly and
so now it is required that these intrinsics operate normally rather than
in "whatever" way.

Fixes #84268
2021-04-17 23:33:10 +03:00
bors
cd9b30527e Auto merge of #84260 - Aaron1011:global-alloc-eval-always, r=cjgillot
Mark `has_global_allocator` query as `eval_always`

Fixes #84252

This query reads from untracked global state in `CStore`.
2021-04-17 12:48:50 +00:00
hyd-dev
ac044e35aa
Do not ignore path segments in the middle in #[allow]/#[warn]/#[deny]/#[forbid] attributes 2021-04-17 18:11:07 +08:00
bors
080d30235f Auto merge of #84244 - ABouttefeux:closure-return-conflict-suggest, r=estebank
fix incomplete diagnostic notes when closure returns conflicting for genric type

fixes #84128
Correctly report the span on for conflicting return type in closures
2021-04-17 07:17:31 +00:00
bors
57e28ef86f Auto merge of #84243 - Soveu:fix-derive-macro-const-default, r=petrochenkov
Builtin derive macros: fix error with const generics default

This fixes a bug where builtin derive macros (like Clone, Debug) would basically copy-paste the default from a const generic, causing a compile error with very confusing message - it would say defaults are not allowed in impl blocks, while pointing at struct/enum/union definition.
2021-04-17 04:48:36 +00:00
bors
42e5621c53 Auto merge of #84113 - SNCPlay42:suggestion-extern-crate, r=petrochenkov
Detect when suggested paths enter extern crates more rigorously

When reporting resolution errors, the compiler tries to avoid suggesting importing inaccessible paths from other crates. However, the search for suggestions only recognized when it was entering a crate root directly, and so failed to recognize a path like `crate::module::private_item`, where `module` was imported from another crate with `use other_crate::module`, as entering another crate.

Fixes #80079
Fixes #84081
2021-04-17 02:23:10 +00:00
Aaron Hill
169a221618
Mark has_global_allocator query as eval_always
Fixes #84252

This query reads from untracked global state in `CStore`.
2021-04-16 16:28:54 -04:00
bjorn3
21f13afafe Add comment 2021-04-16 20:55:51 +02:00
Josh Stone
b79af2fcde Implement #[rustc_skip_array_during_method_dispatch] 2021-04-16 11:11:59 -07:00
Aliénore Bouttefeux
af90cac0e1 fix reporting return type in some cases 2021-04-16 17:06:19 +02:00
Soveu
9ecfae44d7 builtin derive macros: fix error with const generics default 2021-04-16 16:29:11 +02:00
Dylan DPC
c7c59d7c3b
Rollup merge of #84172 - jayaddison:compiler/E0384-reduce-assertiveness, r=petrochenkov
Compiler error messages: reduce assertiveness of message E0384

This message is emitted as guidance by the compiler when a developer attempts to reassign a value to an immutable variable.  Following the message will always currently work, but it may not always be the best course of action; following the 'consider ...' messaging pattern provides a hint to the developer that it could be wise to explore other alternatives.

Resolves #84144
2021-04-16 14:08:33 +02:00
Dylan DPC
8853aaeefc
Rollup merge of #83944 - jackh726:binder-refactor-fix2, r=lcnr
Fix a couple resolve bugs from binder refactor

Fixes #83753
Fixes #83907
2021-04-16 14:08:31 +02:00
bors
d4bc912c48 Auto merge of #84217 - crlf0710:remove_main_attr_pure, r=petrochenkov
Remove #[main] attribute.

This removes the #[main] attribute support from the compiler according to the decisions within #29634. For existing use cases within test harness generation, replaced it with a newly-introduced internal attribute `#[rustc_main]`.

This is first part extracted from #84062 .

Closes #29634.

r? `@petrochenkov`
2021-04-16 08:01:45 +00:00
bors
710da44e22 Auto merge of #84228 - SkiFire13:fix-84213, r=estebank
Suggest to borrow after failing to cast from T to *const/mut T

Fixes #84213
2021-04-16 05:13:43 +00:00
Charles Lew
fc357039f9 Remove #[main] attribute. 2021-04-16 13:04:02 +08:00
klensy
cb2d52282f rename StyledBuffer.text to lines 2021-04-16 05:38:32 +03:00
klensy
247d74f207 StyledBuffer::set_style: check overwrite first 2021-04-16 05:23:40 +03:00
klensy
7e9d3c6f6c StyledBuffer::prepend: if line is empty, insert content without inserting spaces 2021-04-16 05:11:45 +03:00
klensy
e97ddedac6 added some docs for StyledBuffer 2021-04-16 04:14:59 +03:00
klensy
f5229916e3 added default for StyledChar 2021-04-16 03:20:07 +03:00
klensy
756be4a052 refactored StyledBuffer parts into StyledChar 2021-04-16 03:14:05 +03:00
bors
e87c4dd334 Auto merge of #84226 - Aaron1011:track-link-dead-code, r=Mark-Simulacrum
Track `-C link-dead-code` during incremental compilation

This option influences monomorphization, which participates in
incremental compilation.
2021-04-16 00:01:49 +00:00
Giacomo Stevanato
2899b58832 Add suggestion to borrow when casting T to *const/mut T 2021-04-15 23:49:42 +02:00
bors
7af1f55ae3 Auto merge of #84205 - workingjubilee:more-simd-intrin, r=bjorn3
Add simd_{round,trunc} intrinsics

LLVM supports many functions from math.h in its IR. Many of these
have SIMD instructions on various platforms. So, let's add round and
trunc so std::arch can use them.

Yes, exact comparison is intentional: rounding must always return a
valid integer-equal value, except for inf/NAN.
2021-04-15 21:00:11 +00:00
Aaron Hill
1ce1cda02f
Track -C link-dead-code during incremental compilation
This option influences monomorphization, which participates in
incremental compilation.
2021-04-15 15:05:26 -04:00
mark
0566ccc72f rename pat2015 to pat_param 2021-04-15 13:52:09 -05:00
mark
ebc4acee91 stabilize :pat2015, leave :pat2021 gated 2021-04-15 13:52:09 -05:00
Aaron Hill
19c9d93ab5
Run buffered lints attached to anon consts
Fixes #84195
2021-04-15 11:11:44 -04:00
bors
0894d1e906 Auto merge of #84193 - ehuss:unsafe_op_in_unsafe_fn-docs, r=RalfJung
Update docs for unsafe_op_in_unsafe_fn stability.

The unsafe_op_in_unsafe_fn lint was stabilized in #79208, but the bottom of this documentation wasn't updated.

I'm just guessing at the reason here, hopefully it is close to correct. The only discussion I found is https://github.com/rust-lang/rust/issues/71668#issuecomment-730399862 which didn't really explain the thought process behind the decision.
2021-04-15 07:11:18 +00:00
Dylan DPC
fd105db772
Rollup merge of #84192 - vext01:backend-write-typos, r=wesleywiser
Fix typos in rustc_codegen_ssa/src/back/write.rs.

Just a couple of typos I spotted when reading this comment about the job server.
2021-04-15 01:27:56 +02:00
Jubilee Young
003b8eadd7 Add more SIMD math.h intrinsics
LLVM supports many functions from math.h in its IR. Many of these have
single-instruction variants on various platforms. So, let's add them so
std::arch can use them.

Yes, exact comparison is intentional: rounding must always return a
valid integer-equal value, except for inf/NAN.
2021-04-14 15:25:06 -07:00
bors
16bf626a31 Auto merge of #84130 - Aaron1011:fix/none-delim-lookahead, r=petrochenkov
Fix lookahead with None-delimited group

Fixes https://github.com/rust-lang/rust/issues/84162, a regression introduced by https://github.com/rust-lang/rust/pull/82608.
2021-04-14 20:45:23 +00:00
bors
7537b20626 Auto merge of #83948 - ABouttefeux:lint-nullprt-deref, r=RalfJung
add lint deref_nullptr detecting when a null ptr is dereferenced

fixes #83856
changelog: add lint that detect code like
```rust
unsafe {
      &*core::ptr::null::<i32>()
 };
unsafe {
     addr_of!(std::ptr::null::<i32>())
};
let x: i32 = unsafe {*core::ptr::null()};
let x: i32 = unsafe {*core::ptr::null_mut()};
unsafe {*(0 as *const i32)};
unsafe {*(core::ptr::null() as *const i32)};
```
```
warning: Dereferencing a null pointer causes undefined behavior
 --> src\main.rs:5:26
  |
5 |     let x: i32 = unsafe {*core::ptr::null()};
  |                          ^^^^^^^^^^^^^^^^^^
  |                          |
  |                          a null pointer is dereferenced
  |                          this code causes undefined behavior when executed
  |
  = note: `#[warn(deref_nullptr)]` on by default
```

Limitation:
It does not detect code like
```rust
const ZERO: usize = 0;
unsafe {*(ZERO as *const i32)};
```
or code where `0` is not directly a literal
2021-04-14 18:04:22 +00:00
bors
07ef259845 Auto merge of #84158 - cratelyn:patch-extern-c-unwind-behavior, r=nikomatsakis
move new c abi abort behavior behind feature gate

*Background*

In #76570, new ABI strings including `C-unwind` were introduced. Their
behavior is specified in RFC 2945 <sup>[1]</sup>.

However, it was reported in the #ffi-unwind stream of the Rust community Zulip
that this had altered the way that `extern "C"` functions behaved even when the
`c_unwind` feature gate was not active. <sup>[2]</sup>

*Overview*

This makes a small patch to `rustc_mir_build::build::should_abort_on_panic`, so
that the same behavior from before is in place when the `c_unwind` gate is not
active.

`rustc_middle::ty::layout::fn_can_unwind` is not touched, as the visible
behavior should not differ before/after #76570. <sup>[3]</sup>

---

1: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
2: https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/Is.20unwinding.20through.20extern.20C.20UB.3F/near/230112325
3: https://github.com/rust-lang/rust/pull/76570/files#diff-b0320c2b8868f325d83c027fc5d71732636e9763551e35895488f30fe057c6e9L2599-R2617

[1]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
[2]: https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/Is.20unwinding.20through.20extern.20C.20UB.3F/near/230112325
[3]: https://github.com/rust-lang/rust/pull/76570/files#diff-b0320c2b8868f325d83c027fc5d71732636e9763551e35895488f30fe057c6e9L2599-R2617
2021-04-14 15:35:33 +00:00
Eric Huss
e67f4439fe Update docs for unsafe_op_in_unsafe_fn stability. 2021-04-14 08:28:40 -07:00
Edd Barrett
26da4b4355 Fix typos in rustc_codegen_ssa/src/back/write.rs. 2021-04-14 16:27:01 +01:00
James Addison
ff47e97838 Merge branch 'master' into compiler/E0384-reduce-assertiveness 2021-04-14 12:52:06 +01:00
Camille GILLOT
22f6448bed Lower async fn in traits.
An error is already created by AST validation.
2021-04-13 20:57:44 +02:00
bors
132b4e5d16 Auto merge of #84164 - LingMan:option_option, r=estebank
Avoid an `Option<Option<_>>`

By simply swapping the calls to `map` and `and_then` around the complexity of
handling an `Option<Option<_>>` disappears.

`@rustbot` modify labels +C-cleanup +T-compiler
2021-04-13 18:04:20 +00:00
LingMan
28aed81f7d Avoid an Option<Option<_>>
By simply swapping the calls to `map` and `and_then` around the complexity of
handling an `Option<Option<_>>` disappears.
2021-04-13 18:42:19 +02:00
katelyn a. martin
3e16d233d8 move new c abi abort behavior behind feature gate
### Background

    In #76570, new ABI strings including `C-unwind` were introduced.
    Their behavior is specified in RFC 2945 [1].

    However, it was reported in the #ffi-unwind stream of the Rust
    community Zulip that this had altered the way that `extern "C"`
    functions behaved even when the `c_unwind` feature gate was not
    active. [2]

 ### Overview

    This makes a small patch to
    `rustc_mir_build::build::should_abort_on_panic`, so that the same
    behavior from before is in place when the `c_unwind` gate is not
    active.

    `rustc_middle::ty::layout::fn_can_unwind` is not touched, as the
    visible behavior should not differ before/after #76570. [3]

 ### Footnotes

 [1]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
 [2]: https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/Is.20unwinding.20through.20extern.20C.20UB.3F/near/230112325
 [3]: https://github.com/rust-lang/rust/pull/76570/files#diff-b0320c2b8868f325d83c027fc5d71732636e9763551e35895488f30fe057c6e9L2599-R2617
2021-04-13 09:55:21 -04:00
Dylan DPC
91c08288c4
Rollup merge of #84141 - camelid:fix-typo, r=Dylan-DPC
Fix typo in error message

Also tweaked the message a bit by

- removing the hyphen, because in my opinion the hyphen makes the
  message a bit harder to read, especially combined with the backticks;
- adding the word "be", because I think it's a bit clearer that way.
2021-04-13 11:10:44 +02:00
Dylan DPC
e40d7e6d84
Rollup merge of #84140 - b-naber:parser_past_eof, r=varkor
Don't call bump in check_mistyped_turbofish_with_multiple_type_params

Fixes https://github.com/rust-lang/rust/issues/84117
2021-04-13 11:10:43 +02:00
James Addison
0174dd6f92 Compiler error messages: reduce assertiveness of message E0384
This message is emitted as guidance by the compiler when a developer attempts to reassign a value to an immutable variable.  Following the message will always currently work, but it may not always be the best course of action; following the 'consider ...' messaging pattern provides a hint to the developer that it could be wise to explore other alternatives.
2021-04-12 23:29:09 +01:00
Aaron Hill
c6d67f8317
Add fast path when None delimiters are not involved 2021-04-12 17:26:26 -04:00
Camelid
1e2635815f Fix typo in error message
Also tweaked the message a bit by

- removing the hyphen, because in my opinion the hyphen makes the
  message a bit harder to read, especially combined with the backticks;
- adding the word "be", because I think it's a bit clearer that way.
2021-04-12 13:08:15 -07:00
b-naber
dd54459bfc don't bump in check_mistyped_turbofish_with_multiple_type_params 2021-04-12 21:09:04 +02:00
Manish Goregaokar
664c3e71b8 Turn old edition lints (anonymous-parameters, keyword-idents) into warn-by-default on 2015 2021-04-12 09:45:59 -07:00
Aaron Hill
eb7b1a150f
Fix lookahead with None-delimited group 2021-04-12 11:50:16 -04:00
bjorn3
15bfd9da85 Introduce CompileMonoItem DepNode 2021-04-12 13:58:12 +02:00
bors
c18c0ad2bc Auto merge of #84068 - Amanieu:fix_lint, r=lcnr
Add `bad_asm_style` to  HardwiredLints

This was missed when the lint was added, which prevents the lint from being ignored with `#[allow]`.
2021-04-12 10:49:39 +00:00
Dylan DPC
c905e9d0ca
Rollup merge of #84014 - estebank:cool-bears-hot-tip, r=varkor
Improve trait/impl method discrepancy errors

* Use more accurate spans
* Clean up some code by removing previous hack
* Provide structured suggestions

Structured suggestions are particularly useful for cases where arbitrary self types are used, like in custom `Future`s, because the way to write `self: Pin<&mut Self>` is not necessarily self-evident when first encountered.
2021-04-12 01:04:04 +02:00
Dylan DPC
b6780b3a20
Rollup merge of #83669 - kwj2104:issue-81508-fix, r=varkor
Issue 81508 fix

Fix #81508

**Problem**: When variable name is used incorrectly as path, error and warning point to undeclared/unused name, when in fact the name is used, just incorrectly (should be used as a variable, not part of a path).

**Summary for fix**: When path resolution errs, diagnostics checks for variables in ```ValueNS``` that have the same name (e.g., variable rather than path named Foo), and adds additional suggestion that user may actually intend to use the variable name rather than a path.

The fix does not suppress or otherwise change the *warning* that results. I did not find a straightforward way in the code to modify this, but would love to make changes here as well with any guidance.
2021-04-12 01:04:03 +02:00
SNCPlay42
a3ee0bb726 detect when suggested paths enter extern crates more rigorously 2021-04-11 23:44:54 +01:00
hyd-dev
2fd4dd20d7
Allow using -C force-unwind-tables=no when panic=unwind 2021-04-11 22:32:40 +08:00
Aaron Hill
a93c4f05de
Implement token-based handling of attributes during expansion
This PR modifies the macro expansion infrastructure to handle attributes
in a fully token-based manner. As a result:

* Derives macros no longer lose spans when their input is modified
  by eager cfg-expansion. This is accomplished by performing eager
  cfg-expansion on the token stream that we pass to the derive
  proc-macro
* Inner attributes now preserve spans in all cases, including when we
  have multiple inner attributes in a row.

This is accomplished through the following changes:

* New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced.
  These are very similar to a normal `TokenTree`, but they also track
  the position of attributes and attribute targets within the stream.
  They are built when we collect tokens during parsing.
  An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when
  we invoke a macro.
* Token capturing and `LazyTokenStream` are modified to work with
  `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which
  is created during the parsing of a nested AST node to make the 'outer'
  AST node aware of the attributes and attribute target stored deeper in the token stream.
* When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`),
we tokenize and reparse our target, capturing additional information about the locations of
`#[cfg]` and `#[cfg_attr]` attributes at any depth within the target.
This is a performance optimization, allowing us to perform less work
in the typical case where captured tokens never have eager cfg-expansion run.
2021-04-11 01:31:36 -04:00
Tomasz Miąsko
985ae0b55b Match against attribute name when validating attributes
Extract attribute name once and match it against symbols that are being
validated, instead of using `Session::check_name` for each symbol
individually.

Assume that all validated attributes are used, instead of marking them
as such, since the attribute check should be exhaustive.
2021-04-11 00:00:00 +00:00
bors
25ea6be13e Auto merge of #84023 - Aaron1011:derive-invoc-order, r=petrochenkov
Expand derive invocations in left-to-right order

While derives were being collected in left-to-order order, the
corresponding `Invocation`s were being pushed in the wrong order.
2021-04-10 22:04:37 +00:00
Aaron Hill
21e6cc19fe
Expand derive invocations in left-to-right order
While derives were being collected in left-to-order order, the
corresponding `Invocation`s were being pushed in the wrong order.
2021-04-10 17:29:20 -04:00
Amanieu d'Antras
e9d3085cb6 Add bad_asm_style to HardwiredLints 2021-04-10 19:24:24 +01:00
Kornel
40af086ee4 Don't tell users to use a nightly flag on the stable channel
Hint upgrading to a newer Rust version instead
2021-04-10 13:35:35 +01:00
bors
481598b26d Auto merge of #84024 - estebank:unclosed-brace-use, r=jackh726
Avoid `;` -> `,` recovery and unclosed `}` recovery from being too verbose

Those two recovery attempts have a very bad interaction that causes too
unnecessary output. Add a simple gate to avoid interpreting a `;` as a
`,` when there are unclosed braces.

Fix #83498.
2021-04-10 03:02:46 +00:00
bors
dae9d6ac3e Auto merge of #84004 - mattico:print-target-features-improvements, r=petrochenkov
Categorize and explain target features support

There are 3 different uses of the `-C target-feature` args passed to rustc:
1. All of the features are passed to LLVM, which uses them to configure code-generation. This is sort-of stabilized since 1.0 though LLVM does change/add/remove target features regularly.
2. Target features which are in [the compiler's allowlist](69e1d22ddb/compiler/rustc_codegen_ssa/src/target_features.rs (L12-L34)) can be used in `cfg!(target_feature)` etc. These may have different names than in LLVM and are renamed before passing them to LLVM.
3. Target features which are in the allowlist and which are stabilized or feature-gate-enabled can be used in `#[target_feature]`.

It can be confusing that `rustc --print target-features` just prints out the LLVM features without separating out the rustc features or even mentioning that the dichotomy exists.

This improves the situation by separating out the rustc and LLVM target features and adding a brief explanation about the difference.

Abbreviated Example Output:
```
$ rustc --print target-features
Features supported by rustc for this target:
    adx                         - Support ADX instructions.
    aes                         - Enable AES instructions.
...
    xsaves                      - Support xsaves instructions.
    crt-static                  - Enables libraries with C Run-time Libraries(CRT) to be statically linked.

Code-generation features supported by LLVM for this target:
    16bit-mode                  - 16-bit mode (i8086).
    32bit-mode                  - 32-bit mode (80386).
...
    x87                         - Enable X87 float instructions.
    xop                         - Enable XOP instructions.

Use +feature to enable a feature, or -feature to disable it.
For example, rustc -C target-cpu=mycpu -C target-feature=+feature1,-feature2

Code-generation features cannot be used in cfg or #[target_feature],
and may be renamed or removed in a future version of LLVM or rustc.

```

Motivated by #83975.
CC https://github.com/rust-lang/rust/issues/49653
2021-04-09 21:14:50 +00:00
Esteban Küber
0d7167698f Avoid ; -> , recovery and unclosed } recovery from being too verbose
Those two recovery attempts have a very bad interaction that causes too
unnecessary output. Add a simple gate to avoid interpreting a `;` as a
`,` when there are unclosed braces.
2021-04-09 10:22:41 -07:00
12101111
7cd0a4d352
Enable sanitizers for x86_64-unknown-linux-musl 2021-04-09 23:22:17 +08:00
Matt Ickstadt
e258a5ba6e Categorize and explain target features support 2021-04-09 10:16:04 -05:00
Aliénore Bouttefeux
79666c8857 changes based on review 2021-04-09 16:13:04 +02:00
bors
971608b54c Auto merge of #83956 - estebank:issue-83892, r=varkor
Use a more appropriate span for `;` suggestion

Fix #83892.
2021-04-09 04:19:25 +00:00
bors
cd56e255c4 Auto merge of #83870 - jackh726:binder-refactor-fix, r=nikomatsakis
Don't concatenate binders across types

Partially addresses #83737

There's actually two issues that I uncovered in #83737. The first is that we are concatenating bound vars across types, i.e. in
```
F: Fn(&()) -> &mut (dyn Future<Output = ()> + Unpin)
```
the bound vars on `Future` get set as `for<anon>` since those are the binders on `Fn(&()`. This is obviously wrong, since we should only concatenate directly nested trait refs. This is solved here by introducing a new `TraitRefBoundary` scope, that we put around the "syntactical" trait refs and basically don't allow concatenation across.

Now, this alone *shouldn't* be a super terrible problem. At least not until you consider the other issue, which is a much more elusive and harder to design a "perfect" fix. A repro can be seen in:
```
use core::future::Future;

async fn handle<F>(slf: &F)
where
    F: Fn(&()) -> &mut (dyn for<'a> Future<Output = ()> + Unpin),
{
    (slf)(&()).await;
}
```
Notice the `for<'a>` around `Future`. Here, `'a` is unused, so the `for<'a>` Binder gets changed to a `for<>` Binder in the generator witness, but the "local decl" still has it. This has heavy intersections with region anonymization and erasing. Luckily, it's not *super* common to find this unique set of circumstances. It only became apparently because of the first issue mentioned here. However, this *is* still a problem, so I'm leaving #83737 open.

r? `@nikomatsakis`
2021-04-09 01:50:01 +00:00
bors
619d19c318 Auto merge of #83941 - wesleywiser:win_dbginfo_closures, r=nagisa
Improve debuginfo for closures and async functions on Windows MSVC

The issue was that the resulting debuginfo was too complex for LLVM to
translate into CodeView records correctly. As a result, it simply
ignored the debuginfo which meant Windows debuggers could not display
any closed over variables when stepping inside a closure or async fn.

This fixes that by creating additional allocas on the stack so that
the resulting debuginfo is simple (just `*my_variable.dbg.spill`) and
LLVM can generate the correct CV records.

I also updated some of our existing tests to run in CDB to cover this case.

Before (closure):

![image](https://user-images.githubusercontent.com/831192/113756857-e6dc4200-96df-11eb-8d6d-b7ed7a84aad5.png)

After (closure):

![image](https://user-images.githubusercontent.com/831192/113757067-2e62ce00-96e0-11eb-89f7-7dc8ab89b1b8.png)

Before (async):

![image](https://user-images.githubusercontent.com/831192/114077916-4e2bfa80-9876-11eb-9f15-e302d1faa652.png)

After (async):

![image](https://user-images.githubusercontent.com/831192/114077677-0d33e600-9876-11eb-8ce3-cac20a9ea94a.png)

Fixes #83709
2021-04-08 23:09:06 +00:00
Esteban Küber
bb502c4889 Provide verbose suggestion for new output type 2021-04-08 15:54:26 -07:00
Esteban Küber
5af3dec59f Suggest return type 2021-04-08 15:27:43 -07:00
Esteban Küber
147649d4b9 Suggest changing impl parameter types to match trait
This is particularly useful for cases where arbitrary self types are
used, like in custom `Future`s.
2021-04-08 13:50:47 -07:00
bors
2e495d2e84 Auto merge of #84008 - Dylan-DPC:rollup-invxvg8, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #80733 (Improve links in inline code in `core::pin`.)
 - #81764 (Stabilize `rustdoc::bare_urls` lint)
 - #81938 (Stabilize `peekable_peek_mut`)
 - #83980 (Fix outdated crate names in compiler docs)
 - #83992 (Merge idents when generating source content)
 - #84001 (Update Clippy)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-04-08 19:38:54 +00:00
Dylan DPC
74b23f9d11
Rollup merge of #83980 - pierwill:fix-compiler-librustc-names, r=davidtwco
Fix outdated crate names in compiler docs

Changes `librustc_X` to `rustc_X`, only in documentation comments.
Plain code comments are left unchanged.
2021-04-08 20:29:58 +02:00
Dylan DPC
9aed9c1353
Rollup merge of #81764 - jyn514:lint-links, r=GuillaumeGomez
Stabilize `rustdoc::bare_urls` lint

Closes https://github.com/rust-lang/rust/issues/77501. Closes https://github.com/rust-lang/rust/issues/83598.
2021-04-08 20:29:56 +02:00
Wesley Wiser
533002d3a1 Fix closed over variables not available in debuginfo for Windows MSVC
The issue was that the resulting debuginfo was too complex for LLVM to
translate into CodeView records correctly. As a result, it simply
ignored the debuginfo which meant Windows debuggers could not display
any closed over variables when stepping inside a closure.

This fixes that by spilling additional variables to the stack so that
the resulting debuginfo is simple (just `*my_variable.dbg.spill`) and
LLVM can generate the correct CV records.
2021-04-08 14:08:56 -04:00
Esteban Küber
d43ede10e4 Use more accurate spans for trait/impl method arg divergence 2021-04-08 10:19:56 -07:00
pierwill
0019ca9141 Fix outdated crate names in compiler docs
Changes `librustc_X` to `rustc_X`, only in documentation comments.
Plain code comments are left unchanged.

Also fix incorrect file paths.
2021-04-08 11:12:14 -05:00
Alex Crichton
482a3d06c3 rustc: Add a new wasm ABI
This commit implements the idea of a new ABI for the WebAssembly target,
one called `"wasm"`. This ABI is entirely of my own invention
and has no current precedent, but I think that the addition of this ABI
might help solve a number of issues with the WebAssembly targets.

When `wasm32-unknown-unknown` was first added to Rust I naively
"implemented an abi" for the target. I then went to write `wasm-bindgen`
which accidentally relied on details of this ABI. Turns out the ABI
definition didn't match C, which is causing issues for C/Rust interop.
Currently the compiler has a "wasm32 bindgen compat" ABI which is the
original implementation I added, and it's purely there for, well,
`wasm-bindgen`.

Another issue with the WebAssembly target is that it's not clear to me
when and if the default C ABI will change to account for WebAssembly's
multi-value feature (a feature that allows functions to return multiple
values). Even if this does happen, though, it seems like the C ABI will
be guided based on the performance of WebAssembly code and will likely
not match even what the current wasm-bindgen-compat ABI is today. This
leaves a hole in Rust's expressivity in binding WebAssembly where given
a particular import type, Rust may not be able to import that signature
with an updated C ABI for multi-value.

To fix these issues I had the idea of a new ABI for WebAssembly, one
called `wasm`. The definition of this ABI is "what you write
maps straight to wasm". The goal here is that whatever you write down in
the parameter list or in the return values goes straight into the
function's signature in the WebAssembly file. This special ABI is for
intentionally matching the ABI of an imported function from the
environment or exporting a function with the right signature.

With the addition of a new ABI, this enables rustc to:

* Eventually remove the "wasm-bindgen compat hack". Once this
  ABI is stable wasm-bindgen can switch to using it everywhere.
  Afterwards the wasm32-unknown-unknown target can have its default ABI
  updated to match C.

* Expose the ability to precisely match an ABI signature for a
  WebAssembly function, regardless of what the C ABI that clang chooses
  turns out to be.

* Continue to evolve the definition of the default C ABI to match what
  clang does on all targets, since the purpose of that ABI will be
  explicitly matching C rather than generating particular function
  imports/exports.

Naturally this is implemented as an unstable feature initially, but it
would be nice for this to get stabilized (if it works) in the near-ish
future to remove the wasm32-unknown-unknown incompatibility with the C
ABI. Doing this, however, requires the feature to be on stable because
wasm-bindgen works with stable Rust.
2021-04-08 08:03:18 -07:00
Niko Matsakis
c1dc0b7bbc add comments 2021-04-08 10:56:03 -04:00
Aliénore Bouttefeux
0531ed0b62 fix lint doc 2021-04-08 12:09:32 +02:00
bors
69e1d22ddb Auto merge of #83981 - nagisa:nagisa/revert-cfg-wasm, r=Mark-Simulacrum
Remove the insta-stable `cfg(wasm)`

The addition of `cfg(wasm)` was an oversight on my end that turns out to have a number
of downsides:

* It was introduced as an insta-stable addition, forgoing the usual
  staging mechanism we use for potentially far-reaching changes;
* It is a breaking change for people who are using `--cfg wasm` either
  directly or via cargo for other purposes;
* It is not entirely clear if a bare `wasm` cfg is a right option or
  whether `wasm` family of targets are special enough to warrant
  special-casing these targets specifically.

As for the last point, there appears to be a fair amount of support for
reducing the boilerplate in specifying architectures from the same
family, while ignoring their pointer width. The suggested way forward
would be to propose such a change as a separate RFC as it is potentially
a quite contentious addition.

cc #83879 `@devsnek`
2021-04-08 07:23:04 +00:00