Commit graph

126537 commits

Author SHA1 Message Date
bors
36b0d7e257 Auto merge of #75779 - scileo:fix-issue-75492, r=petrochenkov
Improve error message when typo is made in format!

The expansion of the format! built-in macro is roughly done in two steps:
  - the format expression is parsed, the arguments are parsed,
  - the format expression is checked to be a string literal, code is expanded.

The problem is that the expression parser can eat too much tokens, which invalidates the parsing of the next format arguments. As the format expression check happens next, the error emitted concerns the format arguments, whereas the problem is about the format expression.

This PR contains two commits. The first one actually checks that the formatting expression is a string literal before raising any error about the formatting arguments, and the second one contains some simple heuristics which allow to suggest, when the format expression is followed by a dot instead of a comma, to suggest to replace the dot with a comma.

This pull request should fix #75492.

Note: this is my first non-doc contribution to the rust ecosystem. Feel free to make any comment about my code, or whatever. I'll be very happy to fix it :)
2020-08-30 21:03:06 +00:00
Sebastian Dröge
8d3cf9237d Improve documentation of slice::get_unchecked() / split_at_unchecked()
Thanks to Ivan Tham, who gave the majority of these suggestions during
their review.
2020-08-30 23:13:47 +03:00
Sebastian Dröge
d08996ac54 Get rid of bounds check in slice::chunks_exact() and related functions during construction
LLVM can't figure out in

    let rem = self.len() % chunk_size;
    let len = self.len() - rem;
    let (fst, snd) = self.split_at(len);

and

    let rem = self.len() % chunk_size;
    let (fst, snd) = self.split_at(rem);

that the index passed to split_at() is smaller than the slice length and
adds a bounds check plus panic for it.

Apart from removing the overhead of the bounds check this also allows
LLVM to optimize code around the ChunksExact iterator better.
2020-08-30 23:13:47 +03:00
Sebastian Dröge
30dc32b10e Add (non-public) slice::split_at_unchecked() and split_at_mut_unchecked()
These are unsafe variants of the non-unchecked functions and don't do
any bounds checking.

For the time being these are not public and only a preparation for the
following commit. Making it public and stabilization can follow later
and be discussed in https://github.com/rust-lang/rust/issues/76014 .
2020-08-30 23:13:46 +03:00
Sasha
f6d18db402 Use string literal directly when available in format
Previous implementation used the `Parser::parse_expr` function in order
to extract the format expression. If the first comma following the
format expression was mistakenly replaced with a dot, then the next
format expression was eaten by the function, because it looked as a
syntactically valid expression, which resulted in incorrectly spanned
error messages.

The way the format expression is exctracted is changed: we first look at
the first available token in the first argument supplied to the
`format!` macro call. If it is a string literal, then it is promoted as
a format expression immediatly, otherwise we fall back to the original
`parse_expr`-related method.

This allows us to ensure that the parser won't consume too much tokens
when a typo is made.

A test has been created so that it is ensured that the issue is properly
fixed.
2020-08-30 22:09:58 +02:00
Vadim Petrochenkov
7dfbf59f10 cleanup: Remove duplicate library names from Cargo.tomls 2020-08-30 22:57:54 +03:00
Lukas Kalbertodt
d7afe2a223
Fix tests using FixedSizeArray methods (which are now shadowed) 2020-08-30 21:08:18 +02:00
Lukas Kalbertodt
104a02301c
Add [T; N]::as_[mut_]slice
These methods are like the ones on `std::array::FixedSizeArray`
and in the crate `arraytools`.
2020-08-30 21:08:17 +02:00
marmeladema
68500ffacb datastructures: replace once_cell crate with an impl from std 2020-08-30 20:06:14 +01:00
Camelid
37ea97cc10
Explain why the 0 is a u32 2020-08-30 11:43:16 -07:00
Who? Me?!
0175c437e2
Update README.md 2020-08-30 13:40:11 -05:00
Camelid
7e2548fe69
Import Debug instead of redefining it 2020-08-30 11:39:45 -07:00
Caleb Cartwright
883b1e7592 parser: restore some fn visibility for rustfmt 2020-08-30 13:04:36 -05:00
David Wood
6ff471b1cf
ty: remove obsolete printer
This commit removes the obsolete printer and replaces all uses of it
with `FmtPrinter`. Of the replaced uses, all but one use was in `debug!`
logging, two cases were notable:

- `MonoItem::to_string` is used in `-Z print-mono-items` and therefore
  affects the output of all codegen-units tests.
- `DefPathBasedNames` was used in `librustc_codegen_llvm/type_of.rs`
  with `LLVMStructCreateNamed` and that'll now get different values, but
  this should result in no functional change.

Signed-off-by: David Wood <david@davidtw.co>
2020-08-30 18:59:07 +01:00
Aleksey Kladov
518cac9190 Remove unused function 2020-08-30 19:54:45 +02:00
Aleksey Kladov
ccffea5b6b Move lexer unit tests to rustc_lexer
StringReader is an intornal abstraction which at the moment changes a
lot, so these unit tests cause quite a bit of friction.

Moving them to rustc_lexer and more ingerated-testing style should
make them much less annoying, hopefully without decreasing their
usefulness much.

Note that coloncolon tests are removed (it's unclear what those are
testing).

\r\n tests are removed as well, as we normalize line endings even
before lexing.
2020-08-30 19:53:36 +02:00
Aaron Hill
a97dcfa375
Run cfg-stripping on generic parameters before invoking derive macros
Fixes #75930

This changes the tokens seen by a proc-macro. However, ising a `#[cfg]` attribute
on a generic paramter is unusual, and combining it with a proc-macro
derive is probably even more unusual. I don't expect this to cause any
breakage.
2020-08-30 13:46:19 -04:00
CDirkx
5fac991bf6 Add unstable const_ordering feature, and some tests. 2020-08-30 19:40:00 +02:00
bors
85fbf49ce0 Auto merge of #74862 - mark-i-m:mv-compiler, r=petrochenkov
Move almost all compiler crates to compiler/

This PR implements https://github.com/rust-lang/compiler-team/issues/336 and moves all `rustc_*` crates from `src` to the new `compiler` directory.

`librustc_foo` directories are renamed to `rustc_foo`.
`src` directories are introduced inside `rustc_*` directories to mirror the scheme already use for `library` crates.
2020-08-30 15:57:57 +00:00
mark
9e5f7d5631 mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
Prabakaran Kumaresshan
523fea4d14 revert Some(Item) link 2020-08-30 19:19:20 +05:30
Ivan Tham
1d017eb6a4
Fix env doc vars_os broken link 2020-08-30 21:19:21 +08:00
bors
db534b3ac2 Auto merge of #75176 - jyn514:impl-link, r=GuillaumeGomez,petrochenkov
Fix intra-doc links for cross-crate re-exports of default trait methods

The original fix for this was very simple: https://github.com/rust-lang/rust/pull/58972 ignored `extern_traits` because before https://github.com/rust-lang/rust/issues/65983 was fixed, they would always fail to resolve, giving spurious warnings. So the first commit just undoes that change, so extern traits are now seen by the `collect_intra_doc_links` pass. There are also some minor changes in `librustdoc/fold.rs` to avoid borrowing the `extern_traits` RefCell more than once at a time.

However, that brought up a much more thorny problem. `rustc_resolve` started giving 'error: cannot find a built-in macro with name `cfg`' when documenting `libproc_macro` (I still haven't been able to reproduce on anything smaller than the full standard library). The chain of events looked like this (thanks @eddyb for the help debugging!):

0. `x.py build --stage 1` builds the standard library and creates a sysroot
1. `cargo doc` does something like `cargo check` to create `rmeta`s for all the crates (unrelated to what was built above)
2. the `cargo check`-like `libcore-*.rmeta` is loaded as a transitive dependency *and claims ownership* of builtin macros
3. `rustdoc` later tries to resolve some path in a doc link
4. suggestion logic fires and loads "extern prelude" crates by name
5. the sysroot `libcore-*.rlib` is loaded and *fails to claim ownership* of builtin macros

`rustc_resolve` gives the error after step 5. However, `rustdoc` doesn't need suggestions at all - `resolve_str_path_error` completely discards the `ResolutionError`! The fix implemented in this PR is to skip the suggestion logic for `resolve_ast_path`: pass `record_used: false` and skip `lookup_import_candidates` when `record_used` isn't set.

It's possible that if/when https://github.com/rust-lang/rust/issues/74207 is implemented this will need a more in-depth fix which returns a `ResolutionError` from `compile_macro`, to allow rustdoc to reuse the suggestions from rustc_resolve. However, that's a much larger change and there's no need for it yet, so I haven't implemented it here.

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

r? @GuillaumeGomez
2020-08-30 13:16:38 +00:00
DPC
b3d7b7bdcb update fixmes 2020-08-30 14:43:52 +02:00
Joshua Nelson
9131d23cc0 resolve: Don't speculatively load crates if this is a speculative resolution
This avoids a rare rustdoc bug where loading `core` twice caused a
'cannot find a built-in macro' error:

1. `x.py build --stage 1` builds the standard library and creates a sysroot
2. `cargo doc` does something like `cargo check` to create `rmeta`s for all the crates (unrelated to what was built above)
3. the `cargo check`-like `libcore-*.rmeta` is loaded as a transitive dependency *and claims ownership* of builtin macros
4. `rustdoc` later tries to resolve some path in a doc link
5. suggestion logic fires and loads "extern prelude" crates by name
6. the sysroot `libcore-*.rlib` is loaded and *fails to claim ownership* of builtin macros

This fixes step 5. by not running suggestion logic if this is a
speculative resolution. Additionally, it marks `resolve_ast_path` as a
speculative resolution.
2020-08-30 08:15:08 -04:00
Joshua Nelson
a1c71a1709 rustdoc,metadata: Debugging 2020-08-30 08:14:55 -04:00
khyperia
1663bfba02 Fix matching on field.abi instead of self.layout.abi 2020-08-30 13:38:47 +02:00
Prabakaran Kumaresshan
7ea4c28af2 add i32::MAX link 2020-08-30 17:07:50 +05:30
bors
b1d092c159 Auto merge of #75867 - estebank:async-lt-sugg-fix, r=matthewjasper
Account for async functions when suggesting new named lifetime

Fix #75850.
2020-08-30 11:25:52 +00:00
Amjad Alsharafi
300a0072a2 Fix intra-doc path resolution problem in library/alloc/src/slice.rs
`alloc::slice` uses `core::slice` functions, documentation are copied
from there and the links as well without resolution. `crate::ptr...`
cannot be resolved in `alloc::slice`, but `ptr` itself is imported in
both `alloc::slice` and `core::slice`, so we used that instead.
2020-08-30 15:22:27 +08:00
bors
360eb349ae Auto merge of #75919 - rust-lang:jonas-schievink-patch-1, r=ehuss
Fix typo (`thumbv8m.main-none-eabihf` is Mainline)
2020-08-30 06:32:12 +00:00
bors
99b4a01776 Auto merge of #75901 - GuillaumeGomez:ayu-theme-button-hover-background-color, r=pickfire
Improve theme button hover background color

Fixes #75880.

![Screenshot from 2020-08-25 13-44-01](https://user-images.githubusercontent.com/3050060/91170922-e60b1880-e6d9-11ea-9eb1-61a44cdc28d9.png)
![Screenshot from 2020-08-25 13-43-43](https://user-images.githubusercontent.com/3050060/91170924-e73c4580-e6d9-11ea-969e-616bf4130975.png)

r? @pickfire
2020-08-30 04:43:09 +00:00
Camelid
bd3196282b
other branch -> else branch 2020-08-29 20:53:40 -07:00
Camelid
80dcad9e5b
Be more specific about polymorphic return types
I no longer say "polymorphic" since it's a bit ambiguous here.
2020-08-29 20:52:09 -07:00
Camelid
26eab6a0d5
Specify 0 of type u32 2020-08-29 20:48:53 -07:00
Camelid
0d9a2abe69
It's only an issue without an impl Trait for ! 2020-08-29 20:41:36 -07:00
Camelid
fd985e29dd
cannot have divergence -> cannot diverge 2020-08-29 20:35:58 -07:00
Ivan Tham
00cf550c2b Env use shorter intra-doc links in path
vars() rather than vars function

Co-authored-by: Joshua Nelson <joshua@yottadb.com>

Use [xxx()] rather than the [xxx] function

Co-authored-by: Joshua Nelson <joshua@yottadb.com>

Env text representation of function intra-doc link

Suggested by @jyn514

Link join_paths in env doc for parity

Change xxx to env::xxx for lib env doc

Add link requsted by @jyn514

Fix doc build with same link

Co-authored-by: Joshua Nelson <joshua@yottadb.com>

Fix missing intra-doc link

Fix added whitespace in doc

Co-authored-by: Joshua Nelson <joshua@yottadb.com>

Add brackets for `join_paths`

Co-authored-by: Joshua Nelson <joshua@yottadb.com>

Use unused link join_paths

Removed same link for join_paths

Co-authored-by: Joshua Nelson <joshua@yottadb.com>

Remove unsed link join_paths
2020-08-30 11:16:06 +08:00
Camelid
4aae781407 Add info about ! and impl Trait 2020-08-29 19:59:22 -07:00
bors
f6d910c852 Auto merge of #76093 - jyn514:prim-assoc-items, r=Manishearth
Fix intra-doc links for associated constants

Previously, only associated functions would be resolved. Fixes the issues in https://github.com/rust-lang/rust/pull/75969#discussion_r477898003.

I'm a little uncomfortable hard-coding the string constants, but it looks like that's how it's done elsewhere. I might make a follow-up PR at some point putting it in one place.

Not sure how to test associated types, since AFAIK there aren't any on primitives.

r? @Manishearth
2020-08-30 02:36:48 +00:00
Joshua Nelson
1404784992 Fix intra-doc links for associated constants
Previously, only associated functions would be resolved.
2020-08-29 21:37:08 -04:00
bors
62850d882b Auto merge of #76090 - Dylan-DPC:rollup-eksndcr, r=Dylan-DPC
Rollup of 14 pull requests

Successful merges:

 - #75832 (Move to intra-doc links for wasi/ext/fs.rs, os_str_bytes.rs…)
 - #75852 (Switch to intra-doc links in `core::hash`)
 - #75874 (Shorten liballoc doc intra link while readable)
 - #75881 (Expand rustdoc theme chooser x padding)
 - #75885 (Fix another clashing_extern_declarations false positive.)
 - #75892 (Fix typo in TLS Model in Unstable Book)
 - #75910 (Add test for issue #27130)
 - #75917 (Move to intra doc links for core::ptr::non_null)
 - #75975 (Allow --bess ing expect-tests in tools)
 - #75990 (Add __fastfail for Windows on arm/aarch64)
 - #76015 (Fix loading pretty-printers in rust-lldb script)
 - #76022 (Clean up rustdoc front-end source code)
 - #76029 (Move to intra-doc links for library/core/src/sync/atomic.rs)
 - #76057 (Move retokenize hack to save_analysis)

Failed merges:

r? @ghost
2020-08-30 00:47:37 +00:00
Prabakaran Kumaresshan
01d95f241b resolve comments 2020-08-30 05:40:47 +05:30
Prabakaran Kumaresshan
8a92718b64 Switch to intra-doc links in core/src/{convert,iter}/mod.rs 2020-08-30 05:40:47 +05:30
Dylan DPC
9d7d24d516
Rollup merge of #76057 - matklad:remove-retokenize, r=petrochenkov
Move retokenize hack to save_analysis

closes #76046
2020-08-30 01:44:01 +02:00
Dylan DPC
11193ca202
Rollup merge of #76029 - denisvasilik:intra-doc-links-core-atomic, r=kennytm
Move to intra-doc links for library/core/src/sync/atomic.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links, T-rustdoc

Known issues:

* Link from core to std:

    [`Arc`]
	[`std:🧵:yield_now`]
	[`std:🧵:sleep`]
	[`std::sync::Mutex`]
2020-08-30 01:43:59 +02:00
Dylan DPC
b1f983a582
Rollup merge of #76022 - GuillaumeGomez:cleanup-rustdoc-front, r=jyn514
Clean up rustdoc front-end source code

r? @jyn514
2020-08-30 01:43:57 +02:00
Dylan DPC
063313bca6
Rollup merge of #76015 - ortem:fix-lldb-script, r=Mark-Simulacrum
Fix loading pretty-printers in rust-lldb script

Pretty-printers loading in `rust-lldb` script was broken in https://github.com/rust-lang/rust/pull/72357

This fixes https://github.com/rust-lang/rust/issues/76006
2020-08-30 01:43:55 +02:00
Dylan DPC
96e0bc7b6b
Rollup merge of #75990 - rylev:arm-fastfail, r=alexcrichton
Add __fastfail for Windows on arm/aarch64

Fixes #73215
2020-08-30 01:43:54 +02:00
Dylan DPC
3b9ca2cb52
Rollup merge of #75975 - matklad:snapshot-tests, r=Mark-Simulacrum
Allow --bess ing expect-tests in tools

I haven't tried this, but I think this should do the trick, as `RustdocCrate` is a special step in bootstrap, which uses `tool_caro`

r? @ghost
2020-08-30 01:43:52 +02:00