Commit Graph

13050 Commits

Author SHA1 Message Date
Jack Huey
e14eae6226 Remove subst_spanned 2022-05-08 21:53:25 -04:00
Guillaume Gomez
27a2bae89c
Rollup merge of #96788 - JakobDegen:checked-binop, r=oli-obk
Improve validator around field projections and checked bin ops

The two commits are unrelated. In both cases, these rules were already documented in MIR docs.
2022-05-07 15:23:47 +02:00
Guillaume Gomez
a644197391
Rollup merge of #96760 - davidtwco:diagnostic-translation-vec, r=oli-obk
diagnostics: port more diagnostics to derive + add support for `Vec` fields

- Port "unconstrained opaque type" diagnostic to using the derive.
- Allow `Vec` fields in diagnostic derive - enables support for diagnostics that have multiple primary spans, or have subdiagnostics repeated at multiple locations. `Vec<..>` fields in the diagnostic derive become loops in the generated code.
- Add `create_{err,warning}` - there wasn't a way to create a diagnostic from a struct and not emit it straight away.
- Port "explicit generic args w/ impl trait" diagnostic to using the derive.

r? `````@oli-obk`````
cc `````@pvdrz`````
2022-05-07 15:23:46 +02:00
Guillaume Gomez
c29f8575ac
Rollup merge of #96581 - RalfJung:debug-size-align, r=oli-obk
make Size and Align debug-printing a bit more compact

In particular in `{:#?}`-mode, these take up a lot of space, so I think this is the better alternative (even though it is a bit longer in `{:?}` mode, I think it is still more readable).

We could make it even smaller by deviating further from what the actual code looks like, e.g. via something like `Size(4 bytes)`. Not sure what people would think about that?

Cc `````@oli-obk`````
2022-05-07 15:23:44 +02:00
bors
574830f573 Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errors
Begin fixing all the broken doctests in `compiler/`

Begins to fix #95994.
All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are.
There are also a few that I marked `ignore` that could maybe be made to work but seem less important.
Each `ignore` has a rough "reason" for ignoring after it parentheses, with

- `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax"
- `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy.
- `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR.
- `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup.

Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful.

I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-07 06:30:29 +00:00
bors
36aa7c1436 Auto merge of #96804 - compiler-errors:rollup-1mc6aw3, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #96660 ([bootstrap] Give a better error when trying to run a path with no registered step)
 - #96701 (update `jemallocator` example to use 2018 edition import syntax)
 - #96746 (Fix an ICE on #96738)
 - #96758 (bootstrap: bsd platform flags for split debuginfo)
 - #96778 (Remove closures on `expect_local` to apply `#[track_caller]`)
 - #96781 (Fix an incorrect link in The Unstable Book)
 - #96783 (Link to correct issue in issue-95034 known-bug)
 - #96801 (Add regression test for #96319)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-07 04:15:52 +00:00
Michael Goulet
f799c5d897
Rollup merge of #96778 - JohnTitor:expect-local-track-caller-take-2, r=petrochenkov
Remove closures on `expect_local` to apply `#[track_caller]`

Pointed out in https://github.com/rust-lang/rust/pull/96747#discussion_r866576196
Didn't change `expect_non_local` as I'm not sure if it's also the case.
r? ``@petrochenkov``
2022-05-06 20:49:35 -07:00
Michael Goulet
825dc80d1a
Rollup merge of #96746 - JohnTitor:issue-96738, r=petrochenkov
Fix an ICE on #96738

In the block we don't know if the method actually exists thus `expect_local` panics.
Fixes #96738
Fixes #96583
2022-05-06 20:49:32 -07:00
bors
f6e5570460 Auto merge of #96531 - kckeiks:remove-item-like-visitor-from-rustc-typeck, r=cjgillot
Remove ItemLikeVisitor impls from rustc_typeck

Issue #95004
cc `@cjgillot`
2022-05-07 01:59:11 +00:00
bors
4799baa70d Auto merge of #96458 - Aaron1011:no-cycle-caching, r=jackh726,cjgillot
Don't cache results of coinductive cycle
2022-05-06 22:41:16 +00:00
Jakob Degen
c4168fdb50 Check that field projections have the correct type 2022-05-06 16:43:09 -04:00
bors
77652b9ef3 Auto merge of #96785 - GuillaumeGomez:rollup-rgiwa57, r=GuillaumeGomez
Rollup of 10 pull requests

Successful merges:

 - #96557 (Allow inline consts to reference generic params)
 - #96590 (rustdoc: when running a function-signature search, tweak the tab bar)
 - #96650 (Collect function instance used in `global_asm!` sym operand)
 - #96733 (turn `append_place_to_string` from recursion into iteration)
 - #96748 (Fixes reexports in search)
 - #96752 (Put the incompatible_closure_captures lint messages in alphabetical order)
 - #96754 (rustdoc: ensure HTML/JS side implementors don't have dups)
 - #96772 (Suggest fully qualified path with appropriate params)
 - #96776 (Fix two minor issues in hir.rs)
 - #96782 (a small `mirror_expr` cleanup)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-06 20:14:01 +00:00
Jakob Degen
5289bbece3 Expand validator to be more precise on checked binary ops 2022-05-06 15:40:32 -04:00
Guillaume Gomez
a0e2c7e8bb
Rollup merge of #96782 - lcnr:mirror-expr, r=compiler-errors
a small `mirror_expr` cleanup
2022-05-06 20:05:45 +02:00
Guillaume Gomez
a411a32cae
Rollup merge of #96776 - liuw:hir, r=oli-obk
Fix two minor issues in hir.rs

I found these two places in hir.rs which could use a bit of improvements while going through the code.

No functional change.
2022-05-06 20:05:45 +02:00
Guillaume Gomez
6db969ec95
Rollup merge of #96772 - TaKO8Ki:suggest-fully-qualified-path-with-appropriate-params, r=compiler-errors
Suggest fully qualified path with appropriate params

closes #96291
2022-05-06 20:05:44 +02:00
Guillaume Gomez
28d85ab8c4
Rollup merge of #96752 - scottmcm:error-sorting, r=compiler-errors
Put the incompatible_closure_captures lint messages in alphabetical order

Looks like they were in hash order before, which was causing me trouble in #94598, so this PR sorts the errors by trait name.
2022-05-06 20:05:42 +02:00
Guillaume Gomez
c3ddd59f5b
Rollup merge of #96733 - SparrowLii:place_to_string, r=davidtwco
turn `append_place_to_string` from recursion into iteration

This PR fixes the FIXME in the impl of `append_place_to_string` which turns `append_place_to_string` from recursion into iteration, meanwhile simplifying the code relatively.
2022-05-06 20:05:40 +02:00
Guillaume Gomez
c7af4e67c3
Rollup merge of #96650 - tmiasko:global-asm-sym-fn, r=Amanieu
Collect function instance used in `global_asm!` sym operand

The constants used in SymFn operands have FnDef type,
so the type of the constant identifies the function.

Fixes #96623.
2022-05-06 20:05:39 +02:00
Guillaume Gomez
66443a1852
Rollup merge of #96557 - nbdd0121:const, r=oli-obk
Allow inline consts to reference generic params

Tracking issue: #76001

The RFC says that inline consts cannot reference to generic parameters (for now), same as array length expressions. And expresses that it's desirable for it to reference in-scope generics, when array length expressions gain that feature as well.

However it is possible to implement this for inline consts before doing this for all anon consts, because inline consts are only used as values and they won't be used in the type system. So we can have:
```rust
fn foo<T>() {
    let x = [4i32; std::mem::size_of::<T>()];   // NOT ALLOWED (for now)
    let x = const { std::mem::size_of::<T>() }; // ALLOWED with this PR!
    let x = [4i32; const { std::mem::size_of::<T>() }];   // NOT ALLOWED (for now)
}
```

This would make inline consts super useful for compile-time checks and assertions:
```rust
fn assert_zst<T>() {
    const { assert!(std::mem::size_of::<T>() == 0) };
}
```

This would create an error during monomorphization when `assert_zst` is instantiated with non-ZST `T`s. A error during mono might sound scary, but this is exactly what a "desugared" inline const would do:
```rust
fn assert_zst<T>() {
    struct F<T>(T);
    impl<T> F<T> {
        const V: () = assert!(std::mem::size_of::<T>() == 0);
    }
    let _ = F::<T>::V;
}
```

It should also be noted that the current inline const implementation can already reference the type params via type inference, so this resolver-level restriction is not any useful either:
```rust
fn foo<T>() -> usize {
    let (_, size): (PhantomData<T>, usize) = const {
        const fn my_size_of<T>() -> (PhantomData<T>, usize) {
            (PhantomData, std::mem::size_of::<T>())
        }
        my_size_of()
    };
    size
}
```

```@rustbot``` label: F-inline_const
2022-05-06 20:05:37 +02:00
bors
d60b4f52c9 Auto merge of #95454 - randomicon00:fix95444, r=wesleywiser
Fixing #95444 by only displaying passes that take more than 5 millise…

As discussed in #95444, I have added the code to test and only display prints that are greater than 5 milliseconds.

r? `@jyn514`
2022-05-06 17:52:47 +00:00
lcnr
a87fa6314f mirror_expr cleanup 2022-05-06 19:00:37 +02:00
Yuki Okushi
7b773e890e
Remove closures on expect_local to apply #[track_caller] 2022-05-07 01:11:32 +09:00
Miguel Guarniz
91ef3ba71d remove all usages of hir().def_kind
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:11:05 -04:00
Miguel Guarniz
3afc5ea201 use def_span and def_kind queries instead of calling tcx.hir() methods
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:11:05 -04:00
Miguel Guarniz
ef1d112095 pass ItemId to check_item_type instead of Item
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:11:05 -04:00
Miguel Guarniz
1b07c4af81 remove ImplWfCheck
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:11:05 -04:00
Miguel Guarniz
dfe07461f4 remove CheckItemTypesVisitor
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:11:04 -04:00
Miguel Guarniz
d88dfd2522 use hir_module_items in check_mod_item_types query
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:11:04 -04:00
Miguel Guarniz
422dd3b8dc use hir_module_items instead of visit_all_item_likes in check_mod_impl_wf query
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:11:04 -04:00
Miguel Guarniz
f47f39b95f remove UnsafetyChecker
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:11:04 -04:00
Miguel Guarniz
7c3c588988 remove ItemLikeVisitor impl for InherentOverlapChecker
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:11:04 -04:00
Miguel Guarniz
63849b6ecf remove ItemLikeVisitor impl for InherentCollect
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 12:10:59 -04:00
Miguel Guarniz
c27f30835c remove OutlivesTest
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 11:55:15 -04:00
Miguel Guarniz
9c111dd209 remove VarianceTest
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 11:55:15 -04:00
Miguel Guarniz
03e955d812 use DefKind::Fn instead of DefKind::AsscFn for foreign items
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 11:55:15 -04:00
Miguel Guarniz
a7225275e5 remove ItemLikeVisitor impl for TermsContext
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 11:55:15 -04:00
Miguel Guarniz
7064033bf6 remove ItemLikeVisitor impl for ContraintContext
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-06 11:55:15 -04:00
Yuki Okushi
35d77c1710
Also suggest calling constructors for external DefIds 2022-05-07 00:43:50 +09:00
Wei Liu
fcb385cfb1 Use matches! for YieldSource::is_await 2022-05-06 15:00:48 +00:00
Wei Liu
85e688e4c3 Fix comment for async closure variant 2022-05-06 14:59:40 +00:00
Takayuki Maeda
857eb02abe suggest fully qualified path with appropriate params 2022-05-06 23:14:11 +09:00
bors
9a251644fa Auto merge of #96268 - jackh726:remove-mutable_borrow_reservation_conflict-lint, r=nikomatsakis
Remove mutable_borrow_reservation_conflict lint and allow the code pattern

This was the only breaking issue with the NLL stabilization PR. Lang team decided to go ahead and allow this.

r? `@nikomatsakis`
Closes #59159
Closes #56254
2022-05-06 12:32:44 +00:00
bors
8c4fc9d9a4 Auto merge of #94598 - scottmcm:prefix-free-hasher-methods, r=Amanieu
Add a dedicated length-prefixing method to `Hasher`

This accomplishes two main goals:
- Make it clear who is responsible for prefix-freedom, including how they should do it
- Make it feasible for a `Hasher` that *doesn't* care about Hash-DoS resistance to get better performance by not hashing lengths

This does not change rustc-hash, since that's in an external crate, but that could potentially use it in future.

Fixes #94026

r? rust-lang/libs

---

The core of this change is the following two new methods on `Hasher`:

```rust
pub trait Hasher {
    /// Writes a length prefix into this hasher, as part of being prefix-free.
    ///
    /// If you're implementing [`Hash`] for a custom collection, call this before
    /// writing its contents to this `Hasher`.  That way
    /// `(collection![1, 2, 3], collection![4, 5])` and
    /// `(collection![1, 2], collection![3, 4, 5])` will provide different
    /// sequences of values to the `Hasher`
    ///
    /// The `impl<T> Hash for [T]` includes a call to this method, so if you're
    /// hashing a slice (or array or vector) via its `Hash::hash` method,
    /// you should **not** call this yourself.
    ///
    /// This method is only for providing domain separation.  If you want to
    /// hash a `usize` that represents part of the *data*, then it's important
    /// that you pass it to [`Hasher::write_usize`] instead of to this method.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(hasher_prefixfree_extras)]
    /// # // Stubs to make the `impl` below pass the compiler
    /// # struct MyCollection<T>(Option<T>);
    /// # impl<T> MyCollection<T> {
    /// #     fn len(&self) -> usize { todo!() }
    /// # }
    /// # impl<'a, T> IntoIterator for &'a MyCollection<T> {
    /// #     type Item = T;
    /// #     type IntoIter = std::iter::Empty<T>;
    /// #     fn into_iter(self) -> Self::IntoIter { todo!() }
    /// # }
    ///
    /// use std:#️⃣:{Hash, Hasher};
    /// impl<T: Hash> Hash for MyCollection<T> {
    ///     fn hash<H: Hasher>(&self, state: &mut H) {
    ///         state.write_length_prefix(self.len());
    ///         for elt in self {
    ///             elt.hash(state);
    ///         }
    ///     }
    /// }
    /// ```
    ///
    /// # Note to Implementers
    ///
    /// If you've decided that your `Hasher` is willing to be susceptible to
    /// Hash-DoS attacks, then you might consider skipping hashing some or all
    /// of the `len` provided in the name of increased performance.
    #[inline]
    #[unstable(feature = "hasher_prefixfree_extras", issue = "88888888")]
    fn write_length_prefix(&mut self, len: usize) {
        self.write_usize(len);
    }

    /// Writes a single `str` into this hasher.
    ///
    /// If you're implementing [`Hash`], you generally do not need to call this,
    /// as the `impl Hash for str` does, so you can just use that.
    ///
    /// This includes the domain separator for prefix-freedom, so you should
    /// **not** call `Self::write_length_prefix` before calling this.
    ///
    /// # Note to Implementers
    ///
    /// The default implementation of this method includes a call to
    /// [`Self::write_length_prefix`], so if your implementation of `Hasher`
    /// doesn't care about prefix-freedom and you've thus overridden
    /// that method to do nothing, there's no need to override this one.
    ///
    /// This method is available to be overridden separately from the others
    /// as `str` being UTF-8 means that it never contains `0xFF` bytes, which
    /// can be used to provide prefix-freedom cheaper than hashing a length.
    ///
    /// For example, if your `Hasher` works byte-by-byte (perhaps by accumulating
    /// them into a buffer), then you can hash the bytes of the `str` followed
    /// by a single `0xFF` byte.
    ///
    /// If your `Hasher` works in chunks, you can also do this by being careful
    /// about how you pad partial chunks.  If the chunks are padded with `0x00`
    /// bytes then just hashing an extra `0xFF` byte doesn't necessarily
    /// provide prefix-freedom, as `"ab"` and `"ab\u{0}"` would likely hash
    /// the same sequence of chunks.  But if you pad with `0xFF` bytes instead,
    /// ensuring at least one padding byte, then it can often provide
    /// prefix-freedom cheaper than hashing the length would.
    #[inline]
    #[unstable(feature = "hasher_prefixfree_extras", issue = "88888888")]
    fn write_str(&mut self, s: &str) {
        self.write_length_prefix(s.len());
        self.write(s.as_bytes());
    }
}
```

With updates to the `Hash` implementations for slices and containers to call `write_length_prefix` instead of `write_usize`.

`write_str` defaults to using `write_length_prefix` since, as was pointed out in the issue, the `write_u8(0xFF)` approach is insufficient for hashers that work in chunks, as those would hash `"a\u{0}"` and `"a"` to the same thing.  But since `SipHash` works byte-wise (there's an internal buffer to accumulate bytes until a full chunk is available) it overrides `write_str` to continue to use the add-non-UTF-8-byte approach.

---

Compatibility:

Because the default implementation of `write_length_prefix` calls `write_usize`, the changed hash implementation for slices will do the same thing the old one did on existing `Hasher`s.
2022-05-06 09:43:57 +00:00
Ralf Jung
22cc6c3482 don't debug-print ConstValue in MIR pretty-printer 2022-05-06 10:57:03 +02:00
Ralf Jung
bd31ba045d make Size and Align debug-printing a bit more compact 2022-05-06 10:57:03 +02:00
Elliot Roberts
647d0b6dd3 fix unmatched braces 2022-05-06 00:17:02 -07:00
Scott McMurray
98054377ee Add a dedicated length-prefixing method to Hasher
This accomplishes two main goals:
- Make it clear who is responsible for prefix-freedom, including how they should do it
- Make it feasible for a `Hasher` that *doesn't* care about Hash-DoS resistance to get better performance by not hashing lengths

This does not change rustc-hash, since that's in an external crate, but that could potentially use it in future.
2022-05-06 00:03:38 -07:00
SparrowLii
8ff01894a0 turn append_place_to_string from recursion into iteration 2022-05-06 12:11:42 +08:00
David Wood
af47257c0d typeck: port "explicit generic args w/ impl trait"
Port the "explicit generic arguments with impl trait" diagnostic to
using the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-06 03:46:12 +01:00