Commit Graph

209503 Commits

Author SHA1 Message Date
Manish Goregaokar
7dfe1e1664
Rollup merge of #103559 - AndyJado:var_span_label, r=davidtwco
first move on a nested span_label

trying not to be smart this time.
2022-11-08 21:03:53 -05:00
Manish Goregaokar
75c239402c
Rollup merge of #103521 - chenyukang:yukang/fix-103451-avoid-hang, r=jackh726,wesleywiser
Avoid possible infinite  loop when next_point reaching the end of file

Fixes #103451
If we return a span with `lo` = `hi`, `span_to_snippet` will always get `Ok("")`, which may introduce infinite loop if we don't care.

This PR make `find_width_of_character_at_span` return `width` with 1, so that `span_to_snippet` will get an `Err`.
2022-11-08 21:03:53 -05:00
Manish Goregaokar
7521a974d3
Rollup merge of #103353 - wesleywiser:fix_lld_thinlto_msvc, r=michaelwoerister
Fix Access Violation when using lld & ThinLTO on windows-msvc

Users report an AV at runtime of the compiled binary when using lld and ThinLTO on windows-msvc. The AV occurs when accessing a static value which is defined in one crate but used in another. Based on the disassembly of the cross-crate use, it appears that the use is not correctly linked with the definition and is instead assigned a garbage pointer value.

If we look at the symbol tables for each crates' obj file, we can see what is happening:

*lib.obj*:

```
COFF SYMBOL TABLE
...
00E 00000000 SECT2  notype       External     | _ZN10reproducer7memrchr2FN17h612b61ca0e168901E
...
```

*bin.obj*:

```
COFF SYMBOL TABLE
...
010 00000000 UNDEF  notype       External     | __imp__ZN10reproducer7memrchr2FN17h612b61ca0e168901E
...
```

The use of the symbol has the "import" style symbol name but the declaration doesn't generate any symbol with the same name. As a result, linking the files generates a warning from lld:

> rust-lld: warning: bin.obj: locally defined symbol imported: reproducer::memrchr::FN::h612b61ca0e168901 (defined in lib.obj) [LNK4217]

and the symbol reference remains undefined at runtime leading to the AV.

To fix this, we just need to detect that we are performing ThinLTO (and thus, static linking) and omit the `dllimport` attribute on the extern item in LLVM IR.

Fixes #81408
2022-11-08 21:03:52 -05:00
Manish Goregaokar
bd4e608f7b
Rollup merge of #101381 - Urgau:target-mixup-homogenous-floats, r=Amanieu
Test that target feature mix up with homogeneous floats is sound

This pull-request adds a test in `src/test/abi/` that test that target feature mix up with homogeneous floats is sound.

This is basically is ripoff of [src/test/ui/simd/target-feature-mixup.rs](47d1cdb0bc/src/test/ui/simd/target-feature-mixup.rs) but for floats and without `#[repr(simd)]`.

*Extracted from https://github.com/rust-lang/rust/pull/97559 since I don't yet know what to do with that PR.*
2022-11-08 21:03:52 -05:00
Manish Goregaokar
f162e3a1b1
Rollup merge of #100508 - BoxyUwU:make_less_things_late_bound, r=nikomatsakis
avoid making substs of type aliases late bound when used as fn args

fixes #47511
fixes #85533
(although I did not know theses issues existed when i was working on this 🙃)

currently `Alias<...>` is treated the same as `Struct<...>` when deciding if generics should be late bound or early bound but this is not correct as `Alias` might normalize to a projection which does not constrain the generics.

I think this needs more tests before merging
more explanation of PR [here](https://hackmd.io/v44a-QVjTIqqhK9uretyQg?view)

Hackmd inline for future readers:
---

This assumes reader is familiar with the concept of early/late bound lifetimes. There's a section on rustc-dev-guide if not (although i think some details are a bit out of date)

## problem & background

Not all lifetimes on a fn can be late bound:
```rust
fn foo<'a>() -> &'a ();
impl<'a> Fn<()> for FooFnDef {
    type Output = &'a (); // uh oh unconstrained lifetime
}
```
so we make make them early bound
```rust
fn foo<'a>() -> &'a ();
impl<'a> Fn<()> for FooFnDef<'a> {// wow look at all that lifetimey
     type Output = &'a ();
}
```
(Closures have the same constraint however it is not enforced leading to soundness bugs, [#84385](https://github.com/rust-lang/rust/pull/84385) implements this "downgrading late bound to early bound" for closures)

lifetimes on fn items are only late bound when they are "constrained" by the fn args:
```rust
fn foo<'a>(_: &'a ()) -> &'a ();
//               late bound, not present on `FooFnItem`
//               vv
impl<'a> Trait<(&'a (),)> for FooFnItem {
    type Output = &'a ();
}

// projections do not constrain inputs
fn bar<'a, T: Trait>(_: <T as Trait<'a>>::Assoc) -> &'a (); //  early bound
                                                            //  vv
impl<'a, T: Trait> Fn<(<T as Trait<'a>>::Assoc,)> for BarFnItem<'a, T> {
    type Output = &'a ();
}
```

current logic for determining if inputs "constrain" a lifetime works off of HIR so does not normalize aliases. It also assumes that any path with no self type constrains all its substs (i.e. `Foo<'a, u32>` has no self type but `T::Assoc` does). This falls apart for top level type aliases (see linked issues):

```rust
type Alias<'a, T> = <T as Trait<'a>>::Assoc;
//                      wow look its a path with no self type uwu
//                      i bet that constrains `'a` so it should be latebound
//                      vvvvvvvvvvv
fn foo<'a, T: Trait>(_: Alias<'a, T>) -> &'a ();
//                     `Alias` normalized to make things clearer
//                     vvvvvvvvvvvvvvvvvvvvvvv
impl<'a, T: Trait> Fn<(<T as Trait<'a>>::Assoc,)> for FooFnDef<T> {
    type Output = &'a ();
    // oh no `'a` isnt constrained wah wah waaaah *trumbone noises*
    // i think, idk what musical instrument that is
}
```

## solution

The PR solves this by having the hir visitor that checks for lifetimes in constraining uses check if the path is a `DefKind::Alias`. If it is we ""normalize"" it by calling `type_of` and walking the returned type. This is a bit hacky as it requires a mapping between the substs on the path in hir, and the generics of the `type Alias<...>` which is on the ty layer.

Alternative solutions may involve calculating the "late boundness" of lifetimes after/during astconv rather than relying on hir at all. We already have code to determine whether a lifetime SHOULD be late bound or not as this is currently how the error for `fn foo<'a, T: Trait>(_: Alias<'a, T>) -> &'a ();` gets emitted.

It is probably not possible to do this right now, late boundness is used by `generics_of` and `gather_explicit_predicates_of` as we currently do not put late bound lifetimes in `Generics`. Although this seems sus to me as the long term goal is to make all generics late bound which would result in `generics_of(function)` being empty? [#103448](https://github.com/rust-lang/rust/pull/103448) places all lifetimes in `Generics` regardless of late boundness so that may be a good step towards making this possible.
2022-11-08 21:03:51 -05:00
bors
8d36948b15 Auto merge of #104168 - GuillaumeGomez:rollup-tf4edqc, r=GuillaumeGomez
Rollup of 12 pull requests

Successful merges:

 - #103928 (Add 'ty_error_with_guaranteed' and 'const_error_with_guaranteed')
 - #104027 (Place config.toml in current working directory if config not found)
 - #104093 (disable btree size tests on Miri)
 - #104097 (run alloc benchmarks in Miri and fix UB)
 - #104104 (Add split-debuginfo print option)
 - #104109 (rustdoc: Add mutable to the description)
 - #104113 (Fix `const_fn_trait_ref_impl`, add test for it)
 - #104114 (Fix invalid background-image file name)
 - #104132 (fix: lint against lint functions)
 - #104139 (Clarify licensing situation of MPSC and SPSC queue)
 - #104147 (Remove an address comparison from the parser)
 - #104165 (Add llvm-main to triagebot.toml)

Failed merges:

 - #104115 (Migrate crate-search element to CSS variables)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-08 22:50:12 +00:00
Boxy
983a90d716 tests 2022-11-08 22:15:40 +00:00
Boxy
49be827dca comment 2022-11-08 21:59:58 +00:00
Guillaume Gomez
c46cc1dabe
Rollup merge of #104165 - Manishearth:triagebot-llvm, r=Mark-Simulacrum
Add llvm-main to triagebot.toml
2022-11-08 20:40:54 +01:00
Guillaume Gomez
e3c98a88bf
Rollup merge of #104147 - WaffleLapkin:don't-compare-ptr-addresses-in-parser-, r=compiler-errors
Remove an address comparison from the parser

Originally this check was added in #68985, as suggested by 940f65782c (r376850175). I don't think that this address check is a robust way of making parser more robust.

This code is also extensively tested by [`ui/parser/issues/issue-35813-postfix-after-cast.rs`](57d3c58ed6/src/test/ui/parser/issues/issue-35813-postfix-after-cast.rs).

_Replaces #103700_

r? `@compiler-errors`
2022-11-08 20:40:53 +01:00
Guillaume Gomez
ed38562d76
Rollup merge of #104139 - ferrocene:pa-channel-licensing, r=pnkfelix
Clarify licensing situation of MPSC and SPSC queue

Originally, these two files were licensed under the `BSD-2-Clause` license, as they were based off sample code on a blog licensing those snippets under that license:

* `library/std/src/sync/mpsc/mpsc_queue.rs`
* `library/std/src/sync/mpsc/spsc_queue.rs`

In 2017 though, the author of that blog agreed to relicense their code under the standard `MIT OR Apache-2.0` license in https://github.com/rust-lang/rust/pull/42149. This PR clarifies the situation in the files by expanding the comment at the top of the file.

r? ``@pnkfelix``
2022-11-08 20:40:53 +01:00
Guillaume Gomez
a92d83a4ac
Rollup merge of #104132 - Rejyr:rustc_lint-function-lints, r=davidtwco
fix: lint against lint functions

Add `#[rustc_lint_diagnostics]` to lint functions missing them. From [this discussion](https://github.com/rust-lang/rust/pull/101138#issuecomment-1306379999).

r? ```@davidtwco```
2022-11-08 20:40:52 +01:00
Guillaume Gomez
3d20047f40
Rollup merge of #104114 - GuillaumeGomez:background-image-path, r=notriddle
Fix invalid background-image file name

This is a follow-up of https://github.com/rust-lang/rust/pull/101702.

Apparently the image hash was the wrong one. You can see the error in https://doc.rust-lang.org/nightly/core/primitive.u16.html?search=hello too.

I really need to check if I can adds check for resources load errors in `browser-ui-test`.

cc ``````@jsha``````
r? ``````@notriddle``````
2022-11-08 20:40:52 +01:00
Guillaume Gomez
02db37a18a
Rollup merge of #104113 - ink-feather-org:fix_const_fn_ref_impls, r=compiler-errors
Fix `const_fn_trait_ref_impl`, add test for it

#99943 broke `#[feature(const_fn_trait_ref_impl)]`, this PR fixes this and adds a test for it.

r? ````@fee1-dead````
2022-11-08 20:40:51 +01:00
Guillaume Gomez
c39cf7acaa
Rollup merge of #104109 - yancyribbens:add-mutable-to-comment-for-align-to-mut, r=thomcc
rustdoc: Add mutable to the description

`mutable` is missing from the description.  Currently the description for [align_to](https://github.com/rust-lang/rust/blob/master/library/core/src/slice/mod.rs#L3498) is the same as [align_to_mut](https://github.com/rust-lang/rust/blob/master/library/core/src/slice/mod.rs#L3559)
2022-11-08 20:40:51 +01:00
Guillaume Gomez
92f1c6f884
Rollup merge of #104104 - kamirr:master, r=lcnr
Add split-debuginfo print option

This option prints all supported values for `-Csplit-debuginfo=..`, i.e. only stable ones on stable/beta and all of them on nightly/dev.

Motivated by 1.65.0 regression causing builds with the following entry in `Cargo.toml` to fail on Windows:
```toml
[profile.dev]
split-debuginfo = "unpacked"
```

See https://github.com/rust-lang/cargo/pull/11347 for details.

This will lead to closing https://github.com/rust-lang/rust/issues/103976.
2022-11-08 20:40:50 +01:00
Guillaume Gomez
53b6a894ca
Rollup merge of #104097 - RalfJung:miri-alloc-benches, r=thomcc
run alloc benchmarks in Miri and fix UB

Miri since recently has a "fake monotonic clock" that works even with isolation. Its measurements are not very meaningful but it means we can run these benches and check them for UB.

And that's a good thing since there was UB here: fixes https://github.com/rust-lang/rust/issues/104096.

r? ``@thomcc``
2022-11-08 20:40:50 +01:00
Guillaume Gomez
afaba1997d
Rollup merge of #104093 - RalfJung:test-sizes, r=thomcc
disable btree size tests on Miri

Seems fine not to run these in Miri, they can't have UB anyway. And this lets us do layout randomization in Miri.

r? ``@thomcc``
2022-11-08 20:40:49 +01:00
Guillaume Gomez
3abf329040
Rollup merge of #104027 - ted-tanner:issue-103697-fix, r=jyn514
Place config.toml in current working directory if config not found

Fixes an issue where bootsrapping a Rust build would place `config.toml` in `{src_root}` rather than the current working directory

#103697
2022-11-08 20:40:49 +01:00
Guillaume Gomez
3a78320f5c
Rollup merge of #103928 - chenyukang:yukang/fix-103874-add-ty_error_with_guaranteed, r=lcnr
Add 'ty_error_with_guaranteed' and 'const_error_with_guaranteed'

Part of #103874
2022-11-08 20:40:48 +01:00
bors
85f4f41deb Auto merge of #103252 - lcnr:recompute_applicable_impls, r=jackh726
selection failure: recompute applicable impls

The way we currently skip errors for ambiguous trait obligations seems pretty fragile so we get some duplicate errors because of this.

Removing this info from selection errors changes this system to be closer to my image of our new trait solver and is also making it far easier to change overflow errors to be non-fatal 

r? types cc `@estebank`
2022-11-08 19:35:08 +00:00
Manish Goregaokar
9eb977bec4 Add llvm-main to triagebot.toml 2022-11-08 11:30:15 -08:00
Waffle Maybe
268ea3528d
Fix outdated comment
Co-authored-by: clubby789 <jamie@hill-daniel.co.uk>
2022-11-08 21:49:58 +04:00
bors
c5842b0be7 Auto merge of #103965 - petrochenkov:effvisperf3, r=oli-obk
resolve: More detailed effective visibility tracking for imports

Per-`DefId` tracking is not enough, due to glob imports in particular, which have a single `DefId` for the whole glob import item.
We need to track this stuff per every introduced name (`NameBinding`).

Also drop `extern` blocks from the effective visibility table, they are nominally private and it doesn't make sense to keep them there.

Later commits add some debug-only invariant checking and optimiaztions to mitigate regressions in https://github.com/rust-lang/rust/pull/103965#issuecomment-1304256445.

This is a bugfix and continuation of https://github.com/rust-lang/rust/pull/102026.
2022-11-08 14:37:40 +00:00
lcnr
91d5a32bc5 ignore wasm in test 2022-11-08 14:48:07 +01:00
lcnr
003ed76e41 delay errors as bug 2022-11-08 14:48:07 +01:00
lcnr
f1551bfc02 selection failure: recompute applicable impls 2022-11-08 14:48:07 +01:00
Maybe Waffle
e5d01dcc78 Remove an address comparison from the parser 2022-11-08 11:51:10 +00:00
bors
ddfe1e87f7 Auto merge of #104063 - compiler-errors:ct-norm-unless, r=jackh726
Don't normalize constants unless they need normalization

Maybe makes normalization a bit faster when we have many constants in a type

r? `@ghost`
2022-11-08 10:02:11 +00:00
Pietro Albini
807a7bfcee
clarify licensing situation of mpsc and spsc queue 2022-11-08 09:36:08 +01:00
bors
57d3c58ed6 Auto merge of #104138 - Dylan-DPC:rollup-m3ojpjg, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #103446 (Specialize `iter::ArrayChunks::fold` for TrustedRandomAccess iterators)
 - #103651 (Fix `rustc_parse_format` spans following escaped utf-8 multibyte chars)
 - #103865 (Move `fallback_has_occurred` state tracking to `FnCtxt`)
 - #103955 (Update linker-plugin-lto.md to contain up to Rust 1.65)
 - #103987 (Remove `in_tail_expr` from FnCtxt)
 - #104067 (fix debuginfo for windows_gnullvm_base.rs)
 - #104094 (fully move `on_unimplemented` to `error_reporting`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-08 06:49:52 +00:00
Dylan DPC
c23068c8c6
Rollup merge of #104094 - lcnr:on_unimplemented-move, r=wesleywiser
fully move `on_unimplemented` to `error_reporting`

the `traits` module has a few too many submodules in my opinion.
2022-11-08 11:23:53 +05:30
Dylan DPC
2b9e099a83
Rollup merge of #104067 - jeremyd2019:patch-1, r=davidtwco
fix debuginfo for windows_gnullvm_base.rs

These lines (including the FIXME comment) were added to windows_gnu_base.rs in cf2c492ef8 but windows_gnullvm_base.rs was not updated.  This resulted in an error `LLVM ERROR: dwo only supported with ELF and Wasm` attempting to build on aarch64-pc-windows-gnullvm.

See also https://github.com/msys2/MINGW-packages/pull/13921#issuecomment-1304391707

/cc ```@mati865``` ```@davidtwco```

r? ```@davidtwco```
2022-11-08 11:23:53 +05:30
Dylan DPC
58c13e095e
Rollup merge of #103987 - compiler-errors:no-in_tail_expr, r=eholk
Remove `in_tail_expr` from FnCtxt

Cleans up yet another unneeded member from `FnCtxt`. The `in_tail_expr` condition wasn't even correct -- it was set for true while typechecking the whole fn body.
2022-11-08 11:23:52 +05:30
Dylan DPC
799648a61f
Rollup merge of #103955 - str4d:update-lto-doc-1.65, r=ehuss
Update linker-plugin-lto.md to contain up to Rust 1.65

The table rows were obtained via the script embedded in the page.
2022-11-08 11:23:52 +05:30
Dylan DPC
77a44ab568
Rollup merge of #103865 - compiler-errors:fallback-has-occurred-tracking, r=eholk
Move `fallback_has_occurred` state tracking to `FnCtxt`

Removes a ton of callsites that defaulted to `false`
2022-11-08 11:23:51 +05:30
Dylan DPC
4946ee7c8f
Rollup merge of #103651 - Alexendoo:parse-format-unicode-escapes, r=wesleywiser
Fix `rustc_parse_format` spans following escaped utf-8 multibyte chars

Currently too many skips are created for char escapes that are larger than 1 byte when encoded in UTF-8, [playground:](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c77a9dc669b69b167271b59ed2c8d88c)

```rust
fn main() {
    format!("\u{df}{a}");
    format!("\u{211d}{a}");
    format!("\u{1f4a3}{a}");
}
```
```
error[[E0425]](https://doc.rust-lang.org/stable/error-index.html#E0425): cannot find value `a` in this scope
 --> src/main.rs:2:22
  |
2 |     format!("\u{df}{a}");
  |                      ^ not found in this scope

error[[E0425]](https://doc.rust-lang.org/stable/error-index.html#E0425): cannot find value `a` in this scope
 --> src/main.rs:3:25
  |
3 |     format!("\u{211d}{a}");
  |                         ^ not found in this scope

error[[E0425]](https://doc.rust-lang.org/stable/error-index.html#E0425): cannot find value `a` in this scope
 --> src/main.rs:4:27
  |
4 |     format!("\u{1f4a3}{a}");
  |                           ^ not found in this scope
```

This reduces the number of skips to account for that

Fixes https://github.com/rust-lang/rust-clippy/issues/9727
2022-11-08 11:23:51 +05:30
Dylan DPC
b695ed3f20
Rollup merge of #103446 - the8472:tra-array-chunks, r=Mark-Simulacrum
Specialize `iter::ArrayChunks::fold` for TrustedRandomAccess iterators

```
OLD:
test iter::bench_trusted_random_access_chunks                      ... bench:         368 ns/iter (+/- 4)
NEW:
test iter::bench_trusted_random_access_chunks                      ... bench:          30 ns/iter (+/- 0)
```

The resulting assembly is similar to #103166 but the specialization kicks in under different (partially overlapping) conditions compared to that PR. They're complementary.

In principle a TRA-based specialization could be applied to all `ArrayChunks` methods, including `next()` as we do for `Zip` but that would have all the same hazards as the Zip specialization. Only doing it for `fold` is far less hazardous. The downside is that it only helps with internal, exhaustive iteration. I.e. `for _ in` or `try_fold` will not benefit.

Note that the regular, `try_fold`-based and the specialized `fold()` impl have observably slightly different behavior. Namely the specialized variant does not fetch the remainder elements from the underlying iterator. We do have a few other places in the standard library where beyond-the-end-of-iteration side-effects are being elided under some circumstances but not others.

Inspired by https://old.reddit.com/r/rust/comments/yaft60/zerocost_iterator_abstractionsnot_so_zerocost/
2022-11-08 11:23:50 +05:30
yukang
3320879f40 code cleanup with err.emit_unless 2022-11-08 11:17:57 +08:00
yukang
465ac26405 deprecate unchecked_claim_error_was_emitted in error_reported 2022-11-08 11:17:57 +08:00
yukang
1f21b96dce add 'ty_error_with_guaranteed' and 'const_error_with_guaranteed' 2022-11-08 11:17:46 +08:00
bors
6b23a7e87f Auto merge of #104023 - Nilstrieb:cleanup-query, r=cjgillot
Several query cleanups

A few cleanups, mostly about naming in `rustc_query_system`.

r? `@cjgillot`
2022-11-08 03:03:38 +00:00
Rejyr
ae5cc9c56e fix: lint against lint functions
fix: lint against the functions `LintContext::{lookup_with_diagnostics,lookup,struct_span_lint,lint}`, `TyCtxt::struct_lint_node`, `LintLevelsBuilder::struct_lint`.
2022-11-07 19:23:29 -05:00
bors
6184a963f7 Auto merge of #104013 - notriddle:notriddle/rustdoc-sizeof, r=GuillaumeGomez
rustdoc: use `ThinVec` and `Box<str>` to shrink `clean::ItemKind`
2022-11-08 00:02:45 +00:00
The 8472
3925fc0c8e document and improve array Guard type
The type is unsafe and now exposed to the whole crate.
Document it properly and add an unsafe method so the
caller can make it visible that something unsafe is happening.
2022-11-08 00:13:26 +01:00
Tanner Davies
66e8a29640 Only set config.config to None when using default path 2022-11-07 15:27:42 -07:00
The 8472
43c353fff7 simplification: do not process the ArrayChunks remainder in fold() 2022-11-07 21:44:25 +01:00
The 8472
cfcce8e684 specialize iter::ArrayChunks::fold for TrustedRandomAccess iters
This is fairly safe use of TRA since it consumes the iterator so
no struct in an unsafe state will be left exposed to user code
2022-11-07 21:44:25 +01:00
The 8472
eb3f001d37 make the array initialization guard available to other modules 2022-11-07 21:44:25 +01:00
The 8472
b00666ed09 add benchmark for iter::ArrayChunks::fold specialization
This also updates the existing iter::Copied::next_chunk benchmark so
that the thing it benches doesn't get masked by the ArrayChunks specialization
2022-11-07 21:44:24 +01:00