Commit Graph

215144 Commits

Author SHA1 Message Date
Cassaundra Smith
80fcd7c40e
Fix invalid float literal suggestions when recovering an integer
Only suggest adding a zero to integers with a preceding dot when the change will
result in a valid floating point literal.

For example, `.0x0` should not be turned into `0.0x0`.
2023-01-30 13:39:25 -08:00
bors
481725984b Auto merge of #106853 - TimNN:undo-remap, r=oli-obk
Heuristically undo path prefix mappings.

Because the compiler produces better diagnostics if it can find the source of (potentially remapped) dependencies.

The new test fails without the other changes in this PR. Let me know if you have better suggestions for the test directory. I moved the existing remapping test to be in the same location as the new one.

Some more context: I'm exploring running UI tests with remapped paths by default in https://github.com/rust-lang/rust/pull/105924 and this was one of the issues discovered.

This may also be useful in the context of https://github.com/rust-lang/rfcs/pull/3127 ("New rustc and Cargo options to allow path sanitisation by default").
2023-01-16 15:11:28 +00:00
bors
af669c2684 Auto merge of #106850 - cjgillot:issue-106141, r=oli-obk
Make the inlining destination a Local.

Fixes https://github.com/rust-lang/rust/issues/106141
2023-01-16 12:30:49 +00:00
bors
a5bfc25c93 Auto merge of #106872 - dtolnay:nbsp, r=fee1-dead
Emit only one nbsp error per file

Fixes #106101.

See https://github.com/rust-lang/rust/issues/106098 for an explanation of how someone would end up with a large number of these nbsp characters in their source code, which is why I think rustc needs to handle this specific case in a friendlier way.
2023-01-16 09:37:08 +00:00
bors
d12412c90f Auto merge of #106395 - compiler-errors:rework-predicates, r=eholk
Rework some `predicates_of`/`{Generic,Instantiated}Predicates` code

1. Make `instantiate_own` return an iterator, since it's a bit more efficient and easier to work with
2. Remove `bound_{explicit,}_predicates_of` -- these `bound_` methods in particular were a bit awkward to work with since `ty::GenericPredicates` *already* acts kinda like an `EarlyBinder` with its own `instantiate_*` methods, and had only a few call sites anyways.
3. Implement `IntoIterator` for `InstantiatedPredicates`, since it's *very* commonly being `zip`'d together.
2023-01-16 05:55:59 +00:00
bors
41edaac716 Auto merge of #106907 - matthiaskrgr:rustdoc_ref, r=GuillaumeGomez
rustdoc: simplify some & ref erences
2023-01-16 02:43:25 +00:00
bors
9a19e76044 Auto merge of #106914 - matthiaskrgr:rollup-yh0x4gq, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #106888 (Add tidy check to ensure that rustdoc GUI tests start with a small description)
 - #106896 (suggest `is_empty` for collections when casting to `bool`)
 - #106900 (Fix regression in `unused_braces` with macros)
 - #106906 (remove redundant clones)
 - #106909 (Only suggest adding type param if path being resolved was a type)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-15 21:35:50 +00:00
Matthias Krüger
fc78b1e7f9
Rollup merge of #106909 - compiler-errors:only-types-can-be, r=estebank
Only suggest adding type param if path being resolved was a type
2023-01-15 21:17:36 +01:00
Matthias Krüger
8bd67dd12d
Rollup merge of #106906 - matthiaskrgr:clone, r=Nilstrieb
remove redundant clones
2023-01-15 21:17:35 +01:00
Matthias Krüger
5321ad574d
Rollup merge of #106900 - clubby789:unused-braces-regression, r=estebank
Fix regression in `unused_braces` with macros

Fixes #106899
2023-01-15 21:17:35 +01:00
Matthias Krüger
5610231454
Rollup merge of #106896 - Ezrashaw:str-cast-bool-emptyness, r=compiler-errors
suggest `is_empty` for collections when casting to `bool`

Fixes #106883

Matches on slices, `String` and `str`. It would be nice to do this with something like `Deref<Target=str>` as well, but AFAIK it's not possible in this part of the compiler.
2023-01-15 21:17:34 +01:00
Matthias Krüger
72180b348b
Rollup merge of #106888 - GuillaumeGomez:tidy-gui-test, r=notriddle
Add tidy check to ensure that rustdoc GUI tests start with a small description

The first commit comes from https://github.com/rust-lang/rust/pull/106865 to prevent CI to fail.

This PR adds a tidy check to enforce having a small description at the top of the GUI test. Although the format is made to be as easy as possible to read, it's not always obvious what a test is actually checking. I think enforcing this will make it easier for us to come back on these tests if needed.

r? `@notriddle`
2023-01-15 21:17:34 +01:00
bors
9e75dddf60 Auto merge of #106393 - the8472:use-ptr-sub, r=scottmcm
Simplify manual ptr arithmetic in slice::Iter with ptr_sub

The old code was introduced in #61885, which predates the ptr_sub method and underlying intrinsic. The codegen test still passes.

r? `@scottmcm`
2023-01-15 18:39:40 +00:00
The 8472
9db0134018 replace manual ptr arithmetic with ptr_sub 2023-01-15 17:38:05 +01:00
Michael Goulet
566202b975 Only suggest adding type param if path being resolved was a type 2023-01-15 16:33:08 +00:00
Michael Goulet
90df86f474 Remove bound_{explicit,}_item_bounds 2023-01-15 15:36:06 +00:00
Michael Goulet
e1533a26f7 drive-by: assert when iterating through InstantiatedPredicates 2023-01-15 15:36:06 +00:00
Michael Goulet
9b28edb6d7 Make InstantiatedPredicates impl IntoIterator 2023-01-15 15:36:06 +00:00
Michael Goulet
91fd862df0 instantiate_own doesn't need to return a pair of vectors 2023-01-15 15:29:53 +00:00
bors
ae4d89dfb5 Auto merge of #106742 - compiler-errors:new-solver-make-it-not-ice, r=lcnr
Implement some FIXME methods in the new trait solver

Implement just enough of the solver's response logic to make it not ICE.

Also, fix a bug with `no_bound_vars` call failing due to canonical bound vars.

r? `@lcnr`
2023-01-15 15:07:27 +00:00
Matthias Krüger
fdd6af14a1 rustdoc: simplify some & ref erences 2023-01-15 15:23:30 +01:00
Matthias Krüger
665d4ea98d remove redundant clones 2023-01-15 15:02:02 +01:00
bors
fc11ee02ee Auto merge of #106171 - compiler-errors:consolidate-extract_callable_info, r=estebank,lcnr
Consolidate two almost duplicated fn info extraction routines

Moves `extract_callable_info` up to trait selection, because it was being (almost) duplicated fully there for similar diagnostic purposes. This also generalizes the diagnostics we can give slightly (see UI test).
2023-01-15 12:10:36 +00:00
Guillaume Gomez
5376670323 Add small description to GUI test 2023-01-15 12:58:04 +01:00
Guillaume Gomez
98cfa68f16 Add tidy check to ensure that rustdoc GUI tests start with a small description 2023-01-15 12:58:04 +01:00
Ezra Shaw
92ced4a12e
suggest is_empty for collections when casting to bool 2023-01-15 22:17:54 +13:00
bors
bbb36fe545 Auto merge of #105851 - dtolnay:peekmutleak, r=Mark-Simulacrum
Leak amplification for peek_mut() to ensure BinaryHeap's invariant is always met

In the libs-api team's discussion around #104210, some of the team had hesitations around exposing malformed BinaryHeaps of an element type whose Ord and Drop impls are trusted, and which does not contain interior mutability.

For example in the context of this kind of code:

```rust
use std::collections::BinaryHeap;
use std::ops::Range;
use std::slice;

fn main() {
    let slice = &mut ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
    let cut_points = BinaryHeap::from(vec![4, 2, 7]);
    println!("{:?}", chop(slice, cut_points));
}

// This is a souped up slice::split_at_mut to split in arbitrary many places.
//
// usize's Ord impl is trusted, so 1 single bounds check guarantees all those
// output slices are non-overlapping and in-bounds
fn chop<T>(slice: &mut [T], mut cut_points: BinaryHeap<usize>) -> Vec<&mut [T]> {
    let mut vec = Vec::with_capacity(cut_points.len() + 1);
    let max = match cut_points.pop() {
        Some(max) => max,
        None => {
            vec.push(slice);
            return vec;
        }
    };

    assert!(max <= slice.len());

    let len = slice.len();
    let ptr: *mut T = slice.as_mut_ptr();
    let get_unchecked_mut = unsafe {
        |range: Range<usize>| &mut *slice::from_raw_parts_mut(ptr.add(range.start), range.len())
    };

    vec.push(get_unchecked_mut(max..len));
    let mut end = max;
    while let Some(start) = cut_points.pop() {
        vec.push(get_unchecked_mut(start..end));
        end = start;
    }
    vec.push(get_unchecked_mut(0..end));
    vec
}
```

```console
[['7', '8', '9'], ['4', '5', '6'], ['2', '3'], ['0', '1']]
```

In the current BinaryHeap API, `peek_mut()` is the only thing that makes the above function unsound.

```rust
let slice = &mut ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
let mut cut_points = BinaryHeap::from(vec![4, 2, 7]);
{
    let mut max = cut_points.peek_mut().unwrap();
    *max = 0;
    std::mem::forget(max);
}
println!("{:?}", chop(slice, cut_points));
```

```console
[['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], [], ['2', '3'], ['0', '1']]
```

Or worse:

```rust
let slice = &mut ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
let mut cut_points = BinaryHeap::from(vec![100, 100]);
{
    let mut max = cut_points.peek_mut().unwrap();
    *max = 0;
    std::mem::forget(max);
}
println!("{:?}", chop(slice, cut_points));
```

```console
[['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], [], ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\u{1}', '\0', '?', '翾', '?', '翾', '\0', '\0', '?', '翾', '?', '翾', '?', '啿', '?', '啿', '?', '啿', '?', '啿', '?', '啿', '?', '翾', '\0', '\0', '񤬐', '啿', '\u{5}', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\u{8}', '\0', '`@',` '\0', '\u{1}', '\0', '?', '翾', '?', '翾', '?', '翾', '
thread 'main' panicked at 'index out of bounds: the len is 33 but the index is 33', library/core/src/unicode/unicode_data.rs:319:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

---

This PR makes `peek_mut()` use leak amplification (https://doc.rust-lang.org/1.66.0/nomicon/leaking.html#drain) to preserve the heap's invariant even in the situation that `PeekMut` gets leaked.

I'll also follow up in the tracking issue of unstable `drain_sorted()` (#59278) and `retain()` (#71503).
2023-01-15 08:59:55 +00:00
clubby789
295f5483fe Fix regression in unused_braces with macros 2023-01-15 05:08:30 +00:00
bors
754f6d4a8c Auto merge of #106892 - matthiaskrgr:rollup-ohneu8o, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #106072 (fix: misleading "add dyn keyword before derive macro" suggestion)
 - #106859 (Suggestion for type mismatch when we need a u8 but the programmer wrote a char literal)
 - #106863 (Remove various double spaces in compiler source comments.)
 - #106865 (Add explanation comment for GUI test)
 - #106867 (Fix the stability attributes for `std::os::fd`.)
 - #106878 (Add regression test for #92157)
 - #106879 (Add regression test for #42114)
 - #106880 (doc: fix typo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-15 00:16:09 +00:00
Matthias Krüger
cdf462275a
Rollup merge of #106880 - tspiteri:borrowing-sub-typo, r=cuviper
doc: fix typo
2023-01-15 01:01:39 +01:00
Matthias Krüger
30b963c05c
Rollup merge of #106879 - JohnTitor:issue-42114, r=compiler-errors
Add regression test for #42114

Closes #42114
r? compiler-errors
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-01-15 01:01:39 +01:00
Matthias Krüger
08ef0ce056
Rollup merge of #106878 - JohnTitor:issue-92157, r=compiler-errors
Add regression test for #92157

Closes #92157
r? compiler-errors
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-01-15 01:01:38 +01:00
Matthias Krüger
445e3841da
Rollup merge of #106867 - sunfishcode:sunfishcode/std-os-fd-stable-version, r=m-ou-se
Fix the stability attributes for `std::os::fd`.

As `@bjorn3` pointed out [here], I used the wrong stability attribute in #98368 when making `std::os::fd` public. I set it to Rust 1.63, which was when io-safety was stabilized, but it should be Rust 1.66, which was when `std::os::fd` was stabilized.

[here]: https://github.com/rust-lang/rust/pull/98368#discussion_r1063721420
2023-01-15 01:01:38 +01:00
Matthias Krüger
8843335451
Rollup merge of #106865 - GuillaumeGomez:add-gui-test-explanation, r=notriddle
Add explanation comment for GUI test

r? `@notriddle`
2023-01-15 01:01:37 +01:00
Matthias Krüger
cc02ecc010
Rollup merge of #106863 - anden3:compiler-double-spaces, r=Nilstrieb
Remove various double spaces in compiler source comments.

Was asked to do it by `@Nilstrieb`
2023-01-15 01:01:37 +01:00
Matthias Krüger
980bf1979e
Rollup merge of #106859 - tialaramex:master, r=Nilstrieb
Suggestion for type mismatch when we need a u8 but the programmer wrote a char literal

Today Rust just points out that we have a char and we need a u8, but if I wrote 'A' then I could fix this by just writing b'A' instead. This code should detect the case where we're about to report a type mismatch of this kind, and the programmer wrote a char literal, and the char they wrote is ASCII, so therefore just prefixing b to make a byte literal will do what they meant.

I have definitely written this mistake more than once, it's not difficult to figure out what to do, but the compiler might as well tell us anyway.

I provided a test with two simple examples where the suggestion is appropriate, and one where it is not because the char literal is not ASCII, showing that the suggestion is only triggered in the former cases.

I have contributed only a small typo doc fix before, so this is my first substantive rustc change.
2023-01-15 01:01:36 +01:00
Matthias Krüger
d7fcd01f67
Rollup merge of #106072 - eopb:dyn-derive, r=estebank
fix: misleading "add dyn keyword before derive macro" suggestion

Fixes #106071
2023-01-15 01:01:36 +01:00
David Tolnay
23501703fb
Document guarantees about BinaryHeap invariant 2023-01-14 13:28:30 -08:00
David Tolnay
aedb756020
Leak amplification for peek_mut() to ensure BinaryHeap's invariant is always met 2023-01-14 13:28:22 -08:00
David Tolnay
4fe167f83a
Add test of leaking a binary_heap PeekMut 2023-01-14 13:28:14 -08:00
Nick Lamb
130d02b62e Improve E0308: suggest user meant to use byte literal, w/ tests and fix
suggested by Nilstrieb

Co-authored-by: nils <48135649+Nilstrieb@users.noreply.github.com>
2023-01-14 21:27:14 +00:00
Trevor Spiteri
208b781bda doc: fix typo 2023-01-14 22:09:14 +01:00
bors
afaf3e07aa Auto merge of #106866 - matthiaskrgr:rollup-r063s44, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #105526 (libcore: make result of iter::from_generator Clone)
 - #106563 (Fix `unused_braces` on generic const expr macro call)
 - #106661 (Stop probing for statx unless necessary)
 - #106820 (Deprioritize fulfillment errors that come from expansions.)
 - #106828 (rustdoc: remove `docblock` class from notable trait popover)
 - #106849 (Allocate one less vec while parsing arrays)
 - #106855 (rustdoc: few small cleanups)
 - #106860 (Remove various double spaces in the libraries.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-14 20:53:37 +00:00
Yuki Okushi
cf5be0c3ac
Add regression test for #42114
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-01-15 05:52:22 +09:00
Yuki Okushi
aa51a0f19a
Add regression test for #92157
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-01-15 05:47:24 +09:00
David Tolnay
dab06ccdab
Emit only one nbsp error per file 2023-01-14 11:06:22 -08:00
David Tolnay
39edcfa84e
Add more nbsp to unicode-chars test 2023-01-14 11:04:36 -08:00
Dan Gohman
287c65838c Fix the stability attributes for std::os::fd.
As @bjorn3 pointed out [here], I used the wrong stability attribute in #98368
when making `std::os::fd` public. I set it to Rust 1.63, which was when
io-safety was stabilized, but it should be Rust 1.66, which was when
`std::os::fd` was stabilized.

[here]: https://github.com/rust-lang/rust/pull/98368#discussion_r1063721420
2023-01-14 09:47:34 -08:00
Matthias Krüger
e0eb63a73c
Rollup merge of #106860 - anden3:doc-double-spaces, r=Dylan-DPC
Remove various double spaces in the libraries.

I was just pretty bothered by this when reading the source for a function, and was suggested to check if this happened elsewhere.
2023-01-14 18:45:29 +01:00
Matthias Krüger
bc0c816410
Rollup merge of #106855 - klensy:rd-s, r=notriddle
rustdoc: few small cleanups
2023-01-14 18:45:28 +01:00