bors [Thu, 7 Nov 2019 00:10:52 +0000 (00:10 +0000)]
Auto merge of #65750 - nnethercote:cheaper-doc-comments, r=petrochenkov
Cheaper doc comments
This PR implements the idea from #60935: represent doc comments more cheaply, rather than converting them into `#[doc="..."]` attribute form. Unlike #60936 (which is about coalescing doc comments to reduce their number), this approach does not have any backwards compatibility concerns, and it eliminates about 80-90% of the current cost of doc comments (as estimated using the numbers in #60930, which eliminated the cost of doc comments entirely by treating them as normal comments).
bors [Wed, 6 Nov 2019 18:12:57 +0000 (18:12 +0000)]
Auto merge of #65728 - ecstatic-morse:promotion-const-proj, r=eddyb
Fix promotion in a `const` when projections are present
Resolves #65727.
This marks the entire local as "needs promotion" when only a projection of that local appears in a promotable context. This should only affect promotion in a `const` or `static`, not in a `fn` or `const fn`, which is handled in `promote_consts.rs`.
`AttrKind` is a new type with two variants, `Normal` and `DocComment`. It's a
big performance win (over 10% in some cases) because `DocComment` lets doc
comments (which are common) be represented very cheaply.
`Attribute` gets some new helper methods to ease the transition:
- `has_name()`: check if the attribute name matches a single `Symbol`; for
`DocComment` variants it succeeds if the symbol is `sym::doc`.
- `is_doc_comment()`: check if it has a `DocComment` kind.
- `{get,unwrap}_normal_item()`: extract the item from a `Normal` variant;
panic otherwise.
bors [Wed, 6 Nov 2019 09:35:27 +0000 (09:35 +0000)]
Auto merge of #65830 - Quantumplation:master, r=davidtwco,estebank
Use ident.span instead of def_span in dead-code pass
Hello! First time contributor! :)
This should fix #58729.
According to @estebank in the duplicate #63064, def_span scans forward on the line until it finds a {,
and if it can't find one, falls back to the span for the whole item. This
was apparently written before the identifier span was explicitly tracked on
each node.
This means that if an unused function signature spans multiple lines, the
entire function (potentially hundreds of lines) gets flagged as dead code.
This could, for example, cause IDEs to add error squiggly's to the whole
function.
By using the span from the ident instead, we narrow the scope of this in
most cases. In a wider sense, it's probably safe to use ident.span
instead of def_span in most locations throughout the whole code base,
but since this is my first contribution, I kept it small.
Some interesting points that came up while I was working on this:
- I reorganized the tests a bit to bring some of the dead code ones all
into the same location
- A few tests were for things unrelated to dead code (like the
path-lookahead for parens), so I added #![allow(dead_code)] and
cleaned up the stderr file to reduce noise in the future
- The same fix doesn't apply to const and static declarations. I tried
adding these cases to the match expression, but that created a much
wider change to tests and error messages, so I left it off until I
could get some code review to validate the approach.
bors [Wed, 6 Nov 2019 06:14:03 +0000 (06:14 +0000)]
Auto merge of #66143 - Centril:rollup-qmzuex0, r=Centril
Rollup of 9 pull requests
Successful merges:
- #65776 (Rename `LocalInternedString` and more)
- #65973 (caller_location: point to macro invocation sites, like file!/line!, and use in core::panic!.)
- #66015 (librustc_lexer: Refactor the module)
- #66062 (Configure LLVM module PIC level)
- #66086 (bump smallvec to 1.0)
- #66092 (Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.)
- #66103 (Add target thumbv7neon-unknown-linux-musleabihf)
- #66133 (Update the bundled `wasi-libc` repository)
- #66139 (use American spelling for `pluralize!`)
Rollup merge of #66133 - alexcrichton:update-wasi-libc, r=Mark-Simulacrum
Update the bundled `wasi-libc` repository
This updates the libc that the `wasm32-wasi` target links against to the
latest revision, mostly just bringing in minor bug fixes and minor wasm
size improvements.
Rollup merge of #66103 - smaeul:patch/thumb-musl, r=nagisa
Add target thumbv7neon-unknown-linux-musleabihf
This is a copy of thumbv7neon-unknown-linux-gnueabihf with musl changes
merged from armv7-unknown-linux-musleabihf. This appears to have been
missed when adding the other ARMv7-A thumb targets.
Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.
This system call is present on all supported NetBSD versions and provides an endless stream of non-blocking random data from the kernel's ChaCha20-based CSPRNG. It doesn't require a file like `/dev/urandom` to be opened.
The system call is documented here (under kern.arandom):
https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7+NetBSD-7.0
And defined here:
https://nxr.netbsd.org/xref/src/sys/sys/sysctl.h#273
The semantics are the same as FreeBSD so reading 256 bytes per call is fine.
Similar change for getrandom crate: rust-random/getrandom#115
Rollup merge of #66062 - smaeul:patch/pic-level, r=estebank
Configure LLVM module PIC level
As of LLVM 9, this is required for 32-bit PowerPC to properly generate
PLT references. Previously, only BigPIC was supported; now LLVM supports
both BigPIC and SmallPIC, and there is no default value provided.
Rollup merge of #66015 - popzxc:refactor-librustc_parser, r=matklad
librustc_lexer: Refactor the module
This PR introduces a refactoring of the `librustc_lexer` in order to improve readability.
All the changes performed are only cosmetic and do not introduce any changes the lexer logic or performance.
Newly introduced modules `literal`, `token` and `utils` are just copy-pasted from the `lib.rs` and do not contain even cosmetic changes (I decided to do so so it'll be easier to review changes looking only on diff).
Rollup merge of #65973 - eddyb:caller-location-panic, r=petrochenkov
caller_location: point to macro invocation sites, like file!/line!, and use in core::panic!.
The main change here is to `core::panic!`, trying to fix this remaining regression: https://github.com/rust-lang/rust/pull/65927#issuecomment-547625147
However, in order for `caller_location` to be usable from macros the same way `file!()`/`line!()` are, it needs to have the same behavior (of extracting the macro invocation site `Span` and using that).
Arguably we would've had to do this at some point anyway, if we want to use `#[track_caller]` to replace the `file!()`/`line!()` uses from macros, but I'm not sure the RFC mentions this at all.
bors [Wed, 6 Nov 2019 02:29:21 +0000 (02:29 +0000)]
Auto merge of #66141 - Centril:rollup-n2fcvp9, r=Centril
Rollup of 11 pull requests
Successful merges:
- #65892 (Remove `PartialEq` and `Eq` from the `SpecialDerives`.)
- #66014 (Show type parameter name and definition in type mismatch error messages )
- #66027 (Move has_panic_handler to query)
- #66054 (syntax: Avoid span arithmetic for delimiter tokens)
- #66068 (use silent emitter for rustdoc highlighting pass)
- #66081 (let caller of check_ptr_access_align control the error message)
- #66093 (Do not ICE with a precision flag in formatting str and no format arguments)
- #66098 (Detect `::` -> `:` typo when involving turbofish)
- #66101 (Tweak type mismatch caused by break on tail expr)
- #66106 (Fix typo in explanation of `E0080`)
- #66115 (rustc: remove "GlobalMetaData" dead code from hir::map::definitions.)
Rollup merge of #66101 - estebank:break-tail-e0308, r=Centril
Tweak type mismatch caused by break on tail expr
When `break;` has a type mismatch because the `Destination` points at a tail
expression with an obligation flowing from a return type, point at the
return type.
Rollup merge of #66054 - petrochenkov:delspan, r=estebank
syntax: Avoid span arithmetic for delimiter tokens
The +/-1 logic is from the time where the whole group had a single span and the delimiter spans had to be calculated from it.
Now the delimiters have their own spans which are constructed by lexer or proc macro API and can be used directly.
If those spans are not perfect, then it should be fixed by tweaking the corresponding lexer logic rather than by trying to add or substract `1` from the span boundaries.
Rollup merge of #66027 - Mark-Simulacrum:panic-handler-query, r=alexcrichton
Move has_panic_handler to query
Moves us off of a global Once instead re-querying the lang item each time. The conditions on when we set it to true change a little (previously we'd make sure a few more lang items were `Some`) but I think they in practice don't matter, we won't compile later on if we don't have them.
Esteban Küber [Tue, 5 Nov 2019 02:47:02 +0000 (18:47 -0800)]
Tweak type mismatch caused by break on tail expr
When `break;` has a type mismatch because the `Destination` points at a tail
expression with an obligation flowing from a return type, point at the
return type.
Alex Crichton [Tue, 5 Nov 2019 19:49:23 +0000 (11:49 -0800)]
Update the bundled `wasi-libc` repository
This updates the libc that the `wasm32-wasi` target links against to the
latest revision, mostly just bringing in minor bug fixes and minor wasm
size improvements.
Pi Lanningham [Tue, 5 Nov 2019 15:42:34 +0000 (15:42 +0000)]
Detect if item.span is in a macro, and fall back
If item.span is part of a macro invocation, this has several downstream
implications. To name two that were found while working on this:
- The dead-code error gets annotated with a "in this macro invocation"
- Some errors get canceled if they refer to remote crates
Ideally, we should annotate item.ident.span with the same macro info,
but this is a larger change (see: #66095), so for now we just fall
back to the old behavior if this item was generated by a macro.
I use span.macro_backtrace().len() to detect if it's part of a macro,
because that (among other things) is what is used by the code which
adds the "in this macro invocation" annotations mentioned above.
Pietro Albini [Tue, 5 Nov 2019 13:37:07 +0000 (14:37 +0100)]
Rollup merge of #66082 - GuillaumeGomez:cleanup-highlightsourcelines, r=kinnison
clean highlightSourceLines code
This is the first part of https://github.com/rust-lang/rust/issues/66046. Now that I've splitted the hashchange stuff and the source code lines highlighting, I'll be able to fix the whole issue once and for all.
The `#[rustc_args_required_const]` attribute was added to `simd_shuffle*` in rust-lang/stdarch#825. This caused `promote_consts` to double-count its second argument when recording promotion candidates, which caused the promotion candidate compatibility check to fail.
Once `stdarch` is updated in-tree to include rust-lang/stdarch#825, all special logic around `simd_shuffle` can and should be removed.
Pietro Albini [Tue, 5 Nov 2019 13:36:55 +0000 (14:36 +0100)]
Rollup merge of #65948 - danielhenrymantilla:doc/maybe_uninit_ref_mut, r=RalfJung
Improve MaybeUninit::get_{ref,mut} documentation
As mentioned in https://github.com/rust-lang/rust/issues/63568#issuecomment-544106668, `MaybeUninit`'s `get_{ref,mut}` documentation is lacking, so this PR attempts to fix that.
That being said, and as @RalfJung mentions in that thread,
> In particular, we should clarify that all the UB rules for these methods equally apply when calling the raw ptr methods and creating a reference manually.
these other docs also need to be improved, which I can do in this PR ~~(hence the `[WIP]`)~~.
Finally, since all these documentations are related to clearly establishing when dealing with uninitialized memory which patterns are known to be sound and which patterns are currently UB (that is, until, if ever, the rules around references to unintialized integers get relaxed, this documentation will treat them as UB, and advise against such patterns (_e.g._, it is not possible to use uninitialized buffers with the `Read` API)), I think that adding even more examples to the main documentation of `MaybeUninit` inherent definition wouldn't hurt either.
bors [Tue, 5 Nov 2019 09:31:36 +0000 (09:31 +0000)]
Auto merge of #66109 - pietroalbini:rollup-2npidna, r=pietroalbini
Rollup of 10 pull requests
Successful merges:
- #65136 (Update codegen option documentation.)
- #65574 (docs: improve disclaimer regarding LinkedList)
- #65720 (Add FFI bindings for LLVM's Module::getInstructionCount())
- #65905 ([doc] fixes for unix/vxworks `OpenOptionsExt::mode`)
- #65962 (Fix logic in example.)
- #66019 (Improved std::iter::Chain documentation)
- #66038 (doc(str): show example of chars().count() under len())
- #66042 (Suggest correct code when encountering an incorrect trait bound referencing the current trait)
- #66073 (Do not needlessly write-lock)
- #66096 (Add a failing UI test for multiple loops of all kinds in a `const`)
Pietro Albini [Tue, 5 Nov 2019 08:50:00 +0000 (09:50 +0100)]
Rollup merge of #66096 - ecstatic-morse:const-loop-test, r=Centril
Add a failing UI test for multiple loops of all kinds in a `const`
This simply demonstrates the current behavior and ensures we don't allow anything by accident.
The new const checker will be able to improve the diagnostics here. While working on it, I didn't see very many tests with non-`while` loops in a `const`, and there were no tests with multiple loops.
I wasn't sure which of the syntax versions is better (`<Self as ..>::` vs `Self::`), so I used the former simply because it was less change to the existing code.
Pietro Albini [Tue, 5 Nov 2019 08:49:50 +0000 (09:49 +0100)]
Rollup merge of #65720 - icefoxen:LLVMgetInstructionCount, r=rkruppe
Add FFI bindings for LLVM's Module::getInstructionCount()
Just to make it usable for profiling and such inside
rustc itself. It was vaguely useful in
https://wiki.alopex.li/WhereRustcSpendsItsTime and I figured
I might as well upstream it; I may or may not ever get around
to doing more with it (hopefully I will), but it may be useful
for others.
Pietro Albini [Tue, 5 Nov 2019 08:49:47 +0000 (09:49 +0100)]
Rollup merge of #65136 - ehuss:update-codegen-options, r=Dylan-DPC
Update codegen option documentation.
Some documentation updates:
- Add more detail to codegen options.
- Add missing options:
- `force-frame-pointers`
- `default-linker-libraries`
- `linker-plugin-lto`
- Add fragment anchors for all command-line-arguments.
- Add some cross links between options.
bors [Tue, 5 Nov 2019 05:47:31 +0000 (05:47 +0000)]
Auto merge of #65938 - eddyb:fn-abi-rename, r=oli-obk
rustc_target: rename {Fn,Arg}Type to {Fn,Arg}Abi.
I was trying to tweak the API of `FnType` (now `FnAbi`) and the name kept bothering me.
`FnAbi` is to a function signature a bit like a layout is to a type, so the name still isn't perfect yet, but at least it doesn't have the misleading `Type` in it anymore.
If this can't land I think I can continue my original refactor without it, so I'm not strongly attached to it.
bors [Mon, 4 Nov 2019 21:06:50 +0000 (21:06 +0000)]
Auto merge of #65874 - Nadrieril:clarify-usefulness, r=varkor
Clarify pattern-matching usefulness algorithm
This PR clarifies a bit the usefulness algorithm by emphasizing that each row of the matrix can be seen as a sort of stack from which we pop constructors. It also moves code around to increase separation of concerns.
This is part of my splitting of https://github.com/rust-lang/rust/pull/65160 into smaller PRs.
nia [Mon, 4 Nov 2019 17:16:11 +0000 (17:16 +0000)]
Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.
This system call is present on all supported NetBSD versions and
provides an endless stream of non-blocking random data from the
kernel's ChaCha20-based CSPRNG. It doesn't require a file descriptor
to be opened.
The system call is documented here (under kern.arandom):
https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7+NetBSD-7.0
And defined here:
https://nxr.netbsd.org/xref/src/sys/sys/sysctl.h#273
The semantics are the same as FreeBSD so reading 256 bytes per call
is fine.
Similar change for getrandom crate: rust-random/getrandom#115
bors [Mon, 4 Nov 2019 12:16:00 +0000 (12:16 +0000)]
Auto merge of #66078 - petrochenkov:gateout, r=Centril
expand: Feature gate out-of-line modules in proc macro input
Extracted from https://github.com/rust-lang/rust/pull/64273.
We are currently gating attributes applied directly to `mod` items because there are unresolved questions about out-of-line modules and their behavior is very likely to change.
However, you can sneak an out-of-line module into an attribute macro input using modules nested into other items like
```rust
#[my_attr]
fn m() {
#[path = "zzz.rs"]
mod n; // what tokens does the `my_attr` macro see?
}
```
This PR prevents that and emits a feature gate error for this case as well.
r? @Centril
It would be great to land this before beta.
bors [Mon, 4 Nov 2019 09:00:39 +0000 (09:00 +0000)]
Auto merge of #65835 - Mark-Simulacrum:lockless-lintbuffer, r=nikomatsakis
Remove LintBuffer from Session
This moves the `LintBuffer` from `Session` into the `Resolver`, where it is used until lowering is done and then consumed by early lint passes. This also happily removes the failure mode of buffering lints too late where it would have previously lead to ICEs; it is statically no longer possible to do so.
I suspect that with a bit more work a similar move could be done for the lint buffer inside `ParseSess`, but this PR doesn't touch it (in part to keep itself small).
The last commit is the "interesting" commit -- the ones before it don't work (though they compile) as they sort of prepare the various crates for the lint buffer to be passed in rather than accessed through Session.