Commit graph

158270 commits

Author SHA1 Message Date
Matthias Krüger
81f3ae8997
Rollup merge of #90628 - ken-matsui:clarify-error-messages-caused-by-reexporting-pub-crate-visibility-to-outside, r=oli-obk
Clarify error messages caused by re-exporting `pub(crate)` visibility to outside

This PR clarifies error messages and suggestions caused by re-exporting pub(crate) visibility outside the crate.

Here is a small example ([Rust Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e2cd0bd4422d4f20e6522dcbad167d3b)):

```rust
mod m {
    pub(crate) enum E {}
}
pub use m::E;

fn main() {}
```

This code is compiled to:

```
error[E0365]: `E` is private, and cannot be re-exported
 --> prog.rs:4:9
  |
4 | pub use m::E;
  |         ^^^^ re-export of private `E`
  |
  = note: consider declaring type or module `E` with `pub`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0365`.
```

However, enum `E` is actually public to the crate, not private totally—nevertheless, rustc treats `pub(crate)` and private visibility as the same on the error messages. They are not clear and should be segmented distinctly.

By applying changes in this PR, the error message below will be the following message that would be clearer:

```
error[E0365]: `E` is only public to inside of the crate, and cannot be re-exported outside
 --> prog.rs:4:9
  |
4 | pub use m::E;
  |         ^^^^ re-export of crate public `E`
  |
  = note: consider declaring type or module `E` with `pub`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0365`.
```
2021-11-20 10:21:13 +01:00
Matthias Krüger
7354bb331e
Rollup merge of #90575 - m-ou-se:compatible-variant-improvements, r=estebank
Improve suggestions for compatible variants on type mismatch.

Fixes #90553.

Before:
![image](https://user-images.githubusercontent.com/783247/140385675-6ff41090-eca2-41bc-b161-99c5dabfec61.png)

After:
![image](https://user-images.githubusercontent.com/783247/140385748-20cf26b5-ea96-4e56-8af2-5fe1ab16fd3b.png)

r? `````@estebank`````
2021-11-20 10:21:12 +01:00
bors
50f2c29200 Auto merge of #90535 - tmiasko:clone-from, r=oli-obk
Implement `clone_from` for `State`

Data flow engine uses `clone_from` for domain values.  Providing an
implementation of `clone_from` will avoid some intermediate memory
allocations.

Extracted from #90413.

r? `@oli-obk`
2021-11-20 04:12:03 +00:00
Ken Matsui
33ab5123e2
Clarify error messages caused by re-exporting pub(crate) visibility to outside 2021-11-20 10:47:33 +09:00
bors
3b65165ab7 Auto merge of #91064 - matthiaskrgr:rollup-2ijidpt, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #88361 (Makes docs for references a little less confusing)
 - #90089 (Improve display of enum variants)
 - #90956 (Add a regression test for #87573)
 - #90999 (fix CTFE/Miri simd_insert/extract on array-style repr(simd) types)
 - #91026 (rustdoc doctest: detect `fn main` after an unexpected semicolon)
 - #91035 (Put back removed empty line)
 - #91044 (Turn all 0x1b_u8 into '\x1b' or b'\x1b')
 - #91054 (rustdoc: Fix some unescaped HTML tags in docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-20 01:06:27 +00:00
Matthias Krüger
54bc33367c
Rollup merge of #91054 - camelid:fix-tags, r=GuillaumeGomez
rustdoc: Fix some unescaped HTML tags in docs

They were being interpreted literally.
2021-11-20 01:09:45 +01:00
Matthias Krüger
62b259cd88
Rollup merge of #91044 - r00ster91:x1b, r=joshtriplett
Turn all 0x1b_u8 into '\x1b' or b'\x1b'

Supersedes #91040
2021-11-20 01:09:44 +01:00
Matthias Krüger
98540c6805
Rollup merge of #91035 - GuillaumeGomez:put-back-removed-empty-line, r=camelid
Put back removed empty line

Fixes comment from https://github.com/rust-lang/rust/pull/90438#r752813630.

r? ````@camelid````
2021-11-20 01:09:43 +01:00
Matthias Krüger
a9858ce78f
Rollup merge of #91026 - notriddle:notriddle/rustdoc-doctest-semicolon, r=jyn514
rustdoc doctest: detect `fn main` after an unexpected semicolon

Fixes #91014

The basic problem with this is that rustdoc, when hunting for `fn main`, will stop parsing after it reaches a fatal error. This unexpected semicolon was a fatal error, so in `src/test/rustdoc-ui/failed-doctest-extra-semicolon-on-item.rs`, it would wrap the doctest in an implied main function, turning it into this:

    fn main() {
        struct S {};
        fn main() {
            assert_eq!(0, 1);
        }
    }

This, as it turns out, is totally valid, and it executes no assertions, so *it passes,* even though the user wanted it to execute the assertion.

The Rust parser already has the ability to recover from these unexpected semicolons, but to do so, it needs to use the `parse_mod` function, so this PR changes it to do that.
2021-11-20 01:09:42 +01:00
Matthias Krüger
cf69f9e220
Rollup merge of #90999 - RalfJung:miri_simd, r=oli-obk
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types

The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do.

The new helper methods will also be needed for https://github.com/rust-lang/miri/issues/1912.

r? ``````@oli-obk``````
2021-11-20 01:09:41 +01:00
Matthias Krüger
5c98cf145d
Rollup merge of #90956 - JohnTitor:issue-87573, r=Mark-Simulacrum
Add a regression test for #87573

Closes #87573
2021-11-20 01:09:40 +01:00
Matthias Krüger
c0695bbf60
Rollup merge of #90089 - jsha:enum-fields-headings, r=camelid,GuillaumeGomez
Improve display of enum variants

Use h3 and h4 for the variant name and the "Fields" subheading.
Remove the "of T" part of the "Fields" subheading.
Remove border-bottom from "Fields" subheading.
Move docblock below "Fields" listing.

Fixes #90061

Demo:

https://jacob.hoffman-andrews.com/rust/xmlparser-updated/xmlparser/enum.Token.html#variants
https://jacob.hoffman-andrews.com/rust/fix-enum-variants/std/io/enum.ErrorKind.html#variants
https://jacob.hoffman-andrews.com/rust/fix-enum-variants/std/result/enum.Result.html#variants

r? ``@camelid``
2021-11-20 01:09:38 +01:00
Matthias Krüger
97bd45b373
Rollup merge of #88361 - WaffleLapkin:patch-2, r=jyn514
Makes docs for references a little less confusing

- Make clear that the `Pointer` trait is related to formatting
- Make clear that the `Pointer` trait is implemented for references (previously it was confusing to first see that it's implemented and then see it in "expect")
- Make clear that `&T` (shared reference) implements `Send` (if `T: Send + Sync`)
2021-11-20 01:09:37 +01:00
Noah Lev
0ae053a481 rustdoc: Fix some unescaped HTML tags in docs
They were being interpreted literally.
2021-11-19 15:54:05 -05:00
bors
a77da2d454 Auto merge of #91034 - camelid:docfragment, r=jyn514
rustdoc: Cleanup `DocFragment`

- Remove unused `DocFragment.line` field
- Avoid using `Iterator::count()` where possible
2021-11-19 18:04:14 +00:00
r00ster91
a2d78573d3 Turn all 0x1b_u8 into '\x1b' or b'\x1b' 2021-11-19 18:14:18 +01:00
Noah Lev
7a4e2ceb92 Use fast comparison against kw::Empty
We think `.as_str().lines().next().is_none()` should be equivalent to
`== kw::Empty`.

Co-authored-by: Joshua Nelson <github@jyn.dev>
2021-11-19 11:34:41 -05:00
Maybe Waffle
cdb0c29a9c Remove unnecessary doc links 2021-11-19 19:13:53 +03:00
bors
18fa4342fc Auto merge of #90996 - the8472:obligation-hashes2, r=matthewjasper
Optimize `impl Hash for ObligationCauseData` by not hashing `ObligationCauseCode` variant fields

Split out from #90913 since it's a [clear performance win](https://perf.rust-lang.org/compare.html?start=ad442399756573dccacb314b6bf8079964bcc72a&end=223f5e877fe93b5f437c2d703f883797913cd2b7) and should be easier to review.

It speeds up hashing for `Obligation` [deduplication](c9c4b5d727/compiler/rustc_trait_selection/src/traits/select/mod.rs (L2355-L2356)) by only hashing the discriminant of the `ObligationCauseCode` enum instead of its contents. That shouldn't affect hash quality much since there are several other fields in `Obligation` which should be unique enough, especially the predicate itself which is hashed as an interned pointer.
2021-11-19 11:50:51 +00:00
Guillaume Gomez
592178cfcf Put back removed empty line 2021-11-19 10:20:49 +01:00
bors
e8423e6c44 Auto merge of #91033 - JohnTitor:rollup-sr9zg6o, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #89258 (Make char conversion functions unstably const)
 - #90578 (add const generics test)
 - #90633 (Refactor single variant `Candidate` enum into a struct)
 - #90800 (bootstap: create .cargo/config only if not present)
 - #90942 (windows: Return the "Not Found" error when a path is empty)
 - #90947 (Move some tests to more reasonable directories - 9.5)
 - #90961 (Suggest removal of arguments for unit variant, not replacement)
 - #90990 (Arenas cleanup)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-19 06:13:29 +00:00
Yuki Okushi
1576a7cc81
Rollup merge of #90990 - nnethercote:arenas-cleanup, r=oli-obk
Arenas cleanup

I was looking closely at the arenas code and here are some small improvement to readability.
2021-11-19 13:06:38 +09:00
Yuki Okushi
c74ff8b563
Rollup merge of #90961 - estebank:suggest-removal-of-call, r=nagisa
Suggest removal of arguments for unit variant, not replacement
2021-11-19 13:06:37 +09:00
Yuki Okushi
022709f479
Rollup merge of #90947 - c410-f3r:testsssssss, r=petrochenkov
Move some tests to more reasonable directories - 9.5

cc #73494
r? `@petrochenkov`
2021-11-19 13:06:36 +09:00
Yuki Okushi
f62984fca9
Rollup merge of #90942 - JohnTitor:should-os-error-3, r=m-ou-se
windows: Return the "Not Found" error when a path is empty

Fixes #90940
2021-11-19 13:06:35 +09:00
Yuki Okushi
b542224fa5
Rollup merge of #90800 - aplanas:fix_cargo_config, r=Mark-Simulacrum
bootstap: create .cargo/config only if not present

In some situations we should want on influence into the .cargo/config
when we use vendored source.  One example is #90764, when we want to
workaround some references to crates forked and living in git, that are
missing in the vendor/ directory.

This commit will create the .cargo/config file only when the .cargo/
directory needs to be created.
2021-11-19 13:06:35 +09:00
Yuki Okushi
48947eafda
Rollup merge of #90633 - tmiasko:candidate-struct, r=nagisa
Refactor single variant `Candidate` enum into a struct

`Candidate` enum has only a single `Ref` variant.  Refactor it into a
struct and reduce overall indentation of the code by two levels.

No functional changes.
2021-11-19 13:06:34 +09:00
Yuki Okushi
81fd016848
Rollup merge of #90578 - lcnr:add-test, r=Mark-Simulacrum
add const generics test

cc https://github.com/rust-lang/rust/pull/89829#issuecomment-948921310

r? rust-lang/project-const-generics
2021-11-19 13:06:32 +09:00
Yuki Okushi
7432588e5d
Rollup merge of #89258 - est31:const_char_convert, r=oli-obk
Make char conversion functions unstably const

The char conversion functions like `char::from_u32` do trivial computations and can easily be converted into const fns. Only smaller tricks are needed to avoid non-const standard library functions like `Result::ok` or `bool::then_some`.

Tracking issue: https://github.com/rust-lang/rust/issues/89259
2021-11-19 13:06:31 +09:00
Noah Lev
a792234388 rustdoc: Avoid using Iterator::count() where possible
`count()` iterates over the whole collection. Using `len()` instead, or
`.next().is_none()` when comparing to zero, should be faster.
2021-11-18 23:04:51 -05:00
Noah Lev
f4687d5381 rustdoc: Remove unused DocFragment.line field 2021-11-18 22:57:09 -05:00
bors
ce3f3a5ffa Auto merge of #90329 - nbdd0121:typeck, r=nagisa
Try all stable method candidates first before trying unstable ones

Currently we try methods in this order in each step:
* Stable by value
* Unstable by value
* Stable autoref
* Unstable autoref
* ...

This PR changes it to first try pick methods without any unstable candidates, and if none is found, try again to pick unstable ones.

Fix #90320
CC #88971, hopefully would allow us to rename the "unstable_*" methods for integer impls back.

`@rustbot` label T-compiler T-libs-api
2021-11-19 03:00:46 +00:00
bors
548c1088ef Auto merge of #90774 - alexcrichton:tweak-const, r=m-ou-se
std: Tweak expansion of thread-local const

This commit tweaks the expansion of `thread_local!` when combined with a
`const { ... }` value to help ensure that the rules which apply to
`const { ... }` blocks will be the same as when they're stabilized.
Previously with this invocation:

    thread_local!(static NAME: Type = const { init_expr });

this would generate (on supporting platforms):

    #[thread_local]
    static NAME: Type = init_expr;

instead the macro now expands to:

    const INIT_EXPR: Type = init_expr;
    #[thread_local]
    static NAME: Type = INIT_EXPR;

with the hope that because `init_expr` is defined as a `const` item then
it's not accidentally allowing more behavior than if it were put into a
`static`. For example on the stabilization issue [this example][ex] now
gives the same error both ways.

[ex]: https://github.com/rust-lang/rust/issues/84223#issuecomment-953384298
2021-11-18 23:54:14 +00:00
Michael Howell
214ad2f5b5 rustdoc doctest: detect fn main after an unexpected semicolon
The basic problem with this is that rustdoc, when hunting for `fn main`, will stop
parsing after it reaches a fatal error. This unexpected semicolon was a fatal error,
so in `src/test/rustdoc-ui/failed-doctest-extra-semicolon-on-item.rs`, it would wrap
the doctest in an implied main function, turning it into this:

    fn main() {
        struct S {};
        fn main() {
            assert_eq!(0, 1);
        }
    }

This, as it turns out, is totally valid, and it executes no assertions, so *it passes,*
even though the user wanted it to execute the assertion.

The Rust parser already has the ability to recover from these unexpected semicolons,
but to do so, it needs to use the `parse_mod` function, so this commit changes it to do that.
2021-11-18 16:23:18 -07:00
Nicholas Nethercote
0a89598dbd Add some comments.
Also use `Default::default()` in one `TypedArena::default()`, for
consistency with `DroplessArena::default()`.
2021-11-19 07:52:59 +11:00
bors
cc946fcd32 Auto merge of #91019 - JohnTitor:rollup-q95ra7r, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #90386 (Add `-Zassert-incr-state` to assert state of incremental cache)
 - #90438 (Clean up mess for --show-coverage documentation)
 - #90480 (Mention `Vec::remove` in `Vec::swap_remove`'s docs)
 - #90607 (Make slice->str conversion and related functions `const`)
 - #90750 (rustdoc: Replace where-bounded Clean impl with simple function)
 - #90895 (require full validity when determining the discriminant of a value)
 - #90989 (Avoid suggesting literal formatting that turns into member access)
 - #91002 (rustc: Remove `#[rustc_synthetic]`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-18 20:23:26 +00:00
lcnr
8ace192988 bless nll 2021-11-18 18:44:14 +01:00
Yuki Okushi
08c1639fd9
Rollup merge of #91002 - petrochenkov:nosynth, r=davidtwco
rustc: Remove `#[rustc_synthetic]`

This function parameter attribute was introduced in https://github.com/rust-lang/rust/pull/44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself.

Noticed while reviewing https://github.com/rust-lang/rust/pull/90947.
2021-11-19 02:22:59 +09:00
Yuki Okushi
dfbbb3b900
Rollup merge of #90989 - notriddle:notriddle/rustc-suggest-float-ending-in-dot, r=sanxiyn
Avoid suggesting literal formatting that turns into member access

Fixes #90974
2021-11-19 02:22:59 +09:00
Yuki Okushi
0a2b7d71d9
Rollup merge of #90895 - RalfJung:read-discriminant-valid, r=oli-obk
require full validity when determining the discriminant of a value

This resolves (for now) the semantic question that came up in https://github.com/rust-lang/rust/pull/89764: arguably, reading the discriminant of a value is 'using' that value, so we are in our right to demand full validity. Reading a discriminant is somewhat special in that it works for values of *arbitrary* type; all the other primitive MIR operations work on specific types (e.g. `bool` or an integer) and basically implicitly require validity as part of just "doing their job".

The alternative would be to just require that the discriminant itself is valid, if any -- but then what do we do for types that do not have a discriminant, which kind of validity do we check? [This code](81117ff930/compiler/rustc_codegen_ssa/src/mir/place.rs (L206-L215)) means we have to at least reject uninhabited types, but I would rather not special case that.

I don't think this can be tested in CTFE (since validity is not enforced there), I will add a compile-fail test to Miri:
```rust
#[allow(enum_intrinsics_non_enums)]
fn main() {
    let i = 2u8;
    std::mem::discriminant(unsafe { &*(&i as *const _ as *const bool) }); // UB
}
```

(I tried running the check even on the CTFE machines, but then it runs during ConstProp and that causes all sorts of problems. We could run it for ConstEval but not ConstProp, but that simply does not seem worth the effort currently.)

r? ``@oli-obk``
2021-11-19 02:22:58 +09:00
Yuki Okushi
47c1bd1bcc
Rollup merge of #90750 - camelid:rm-tuple-impls-1, r=jyn514
rustdoc: Replace where-bounded Clean impl with simple function

This is the first step in removing the Clean impls for tuples. Either way, this
significantly simplifies the code since it reduces the amount of "trait magic".

(To clarify, I'm referring to impls like `impl Clean for (A, B)`, not Clean impls
that work on tuples in the user's program.)

cc ``@jyn514``
2021-11-19 02:22:57 +09:00
Yuki Okushi
77c985f765
Rollup merge of #90607 - WaffleLapkin:const_str_from_utf8, r=oli-obk
Make slice->str conversion and related functions `const`

This PR marks the following APIs as `const`:
```rust
// core::str
pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>;
pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error>;
pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str;

impl Utf8Error {
    pub const fn valid_up_to(&self) -> usize;
    pub const fn error_len(&self) -> Option<usize>;
}
```

Everything but `from_utf8_unchecked_mut` uses `const_str_from_utf8` feature gate, `from_utf8_unchecked_mut` uses `const_str_from_utf8_unchecked_mut` feature gate.

---

I'm not sure why `from_utf8_unchecked_mut` was left out being  non-`const`, considering that `from_utf8_unchecked` is not only `const`, but **`const` stable**.

---

r? ```@oli-obk``` (performance-only `const_eval_select` use)
2021-11-19 02:22:57 +09:00
Yuki Okushi
3e97d9bd97
Rollup merge of #90480 - r00ster91:remove, r=kennytm
Mention `Vec::remove` in `Vec::swap_remove`'s docs

Thought this was a nice addition.
2021-11-19 02:22:56 +09:00
Yuki Okushi
153e4dc38a
Rollup merge of #90438 - GuillaumeGomez:doc-show-coverage, r=camelid
Clean up mess for --show-coverage documentation

It was somewhat duplicated for some reasons... Anyway, this remove this duplication and clean up a bit.

r? ```@camelid```
2021-11-19 02:22:55 +09:00
Yuki Okushi
728b3f2356
Rollup merge of #90386 - pierwill:assert-incr-state-85864, r=Aaron1011
Add `-Zassert-incr-state` to assert state of incremental cache

Closes #85864.
2021-11-19 02:22:54 +09:00
bors
b6f580acc0 Auto merge of #90382 - alexcrichton:wasm64-libstd, r=joshtriplett
std: Get the standard library compiling for wasm64

This commit goes through and updates various `#[cfg]` as appropriate to
get the wasm64-unknown-unknown target behaving similarly to the
wasm32-unknown-unknown target. Most of this is just updating various
conditions for `target_arch = "wasm32"` to also account for `target_arch
= "wasm64"` where appropriate. This commit also lists `wasm64` as an
allow-listed architecture to not have the `restricted_std` feature
enabled, enabling experimentation with `-Z build-std` externally.

The main goal of this commit is to enable playing around with
`wasm64-unknown-unknown` externally via `-Z build-std` in a way that's
similar to the `wasm32-unknown-unknown` target. These targets are
effectively the same and only differ in their pointer size, but wasm64
is much newer and has much less ecosystem/library support so it'll still
take time to get wasm64 fully-fledged.
2021-11-18 17:19:27 +00:00
Ralf Jung
0304e16f3b CTFE SIMD: also test 1-element array 2021-11-18 11:05:30 -05:00
Caio
41d9abd76c Move some tests to more reasonable directories 2021-11-18 12:09:34 -03:00
Ralf Jung
2f1a1f530b fix CTFE/Miri simd_insert/extract on array-style repr(simd) types 2021-11-18 09:10:35 -05:00
Maybe Waffle
573a00e3f9 Fill in tracking issues for const_str_from_utf8 and const_str_from_utf8_unchecked_mut features 2021-11-18 14:04:01 +03:00