Commit Graph

22085 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
aa7edf7073
Use the correct ParamEnv 2023-02-19 18:35:34 +01:00
León Orell Valerian Liehr
488d0c9efd
Type-directed probing for inherent associated types 2023-02-19 18:35:28 +01:00
bors
eebdfb55fc Auto merge of #108228 - Dylan-DPC:rollup-i9t13qu, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #104659 (reflow the stack size story)
 - #106933 (Update documentation of select_nth_unstable and select_nth_unstable_by to state O(n^2) complexity)
 - #107783 (rustdoc: simplify DOM for `.item-table`)
 - #107951 (resolve: Fix doc links referring to other crates when documenting proc macro crates directly)
 - #108130 ("Basic usage" is redundant for there is just one example)
 - #108146 (rustdoc: hide `reference` methods in search index)
 - #108189 (Fix some more `non_lifetime_binders` stuff with higher-ranked trait bounds)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-19 08:15:40 +00:00
Dylan DPC
c5d5c57666
Rollup merge of #108189 - compiler-errors:non_lifetime_binders-bound-stuff, r=jackh726
Fix some more `non_lifetime_binders` stuff with higher-ranked trait bounds

1. When assembling candidates for `for<T> T: Sized`, we can't ICE because the self-type is a bound type.
2. Fix an issue where, when canonicalizing in non-universe preserving mode, we don't actually set the universe for placeholders to the root even though we do the same for region vars.
3. Make `Placeholder("T")` format like `T` in error messages.

Fixes #108180
Fixes #108182

r? types
2023-02-19 13:03:42 +05:30
Dylan DPC
4a0f088f7c
Rollup merge of #107951 - petrochenkov:procmacdoc, r=jackh726
resolve: Fix doc links referring to other crates when documenting proc macro crates directly

Fixes https://github.com/rust-lang/rust/issues/107950
2023-02-19 13:03:41 +05:30
bors
73f40197ec Auto merge of #107772 - compiler-errors:dyn-star-backend-is-ptr, r=eholk
Make `dyn*`'s value backend type a pointer

One tweak on top of Ralf's commit should fix using `usize` as a `dyn*`-coercible type, and should fix when we're using various other pointer types when LLVM opaque pointers is disabled.

r? `@eholk` but feel free to reassign
cc https://github.com/rust-lang/rust/pull/107728#issuecomment-1421231823 `@RalfJung`
2023-02-19 05:35:03 +00:00
bors
fcdbd1c07f Auto merge of #107867 - compiler-errors:new-solver-fn-trait-safety, r=lcnr
Check that built-in callable types validate their output type is `Sized` (in new solver)

Working on parity with old solver. Putting this up for consideration, it's not *really* needed or anything just yet. Maybe it's better to approach this from another direction (like always checking the item bounds when calling `consider_assumption`? we may need that for coinduction to be sound though?)

This basically implements #100096 for the new solver.
2023-02-19 02:42:10 +00:00
bors
f77f4d55bd Auto merge of #107542 - compiler-errors:param-envs-with-inference-vars-are-cursed, r=jackh726
Don't call `with_reveal_all_normalized` in const-eval when `param_env` has inference vars in it

**what:** This slightly shifts the order of operations from an existing hack:

5b6ed253c4/compiler/rustc_middle/src/ty/consts/kind.rs (L225-L230)

in order to avoid calling a tcx query (`TyCtxt::reveal_opaque_types_in_bounds`, via `ParamEnv::with_reveal_all_normalized`) when a param-env has inference variables in it.

**why:** This allows us to enable fingerprinting of query keys/values outside of incr-comp in deubg mode, to make sure we catch other places where we're passing infer vars and other bad things into query keys. Currently that (bbf33836b9) crashes because we introduce inference vars into a param-env in the blanket-impl finder in rustdoc 😓

5b6ed253c4/src/librustdoc/clean/blanket_impl.rs (L43)

See the CI failure here: https://github.com/rust-lang/rust/actions/runs/4058194838/jobs/6984834619
2023-02-18 23:43:42 +00:00
Michael Goulet
6f3706ea71 Pretty placeholders using their names 2023-02-18 19:49:40 +00:00
Michael Goulet
ec40b1a393 Collapse placeholders to root universe in canonicalizer if not preserving universes 2023-02-18 19:49:40 +00:00
Michael Goulet
f4a4a31479 Don't ICE on bound types in sized conditions 2023-02-18 19:49:40 +00:00
Michael Goulet
7f798c2b21 Emit the right types for vtable pointers when dropping dyn* 2023-02-18 19:47:34 +00:00
Michael Goulet
e82cc656c8 Make dyn* have the same scalar pair ABI as corresponding fat pointer 2023-02-18 19:47:34 +00:00
Michael Goulet
df52e2037a Use inttoptr to support usize as dyn* value, use pointercast to make sure pointers are compatible 2023-02-18 19:47:33 +00:00
Michael Goulet
6402c98621 Add consider_implied_clause 2023-02-18 19:45:02 +00:00
Michael Goulet
82b52056fe Check that built-in callable types validate their output type is Sized (in new solver) 2023-02-18 19:32:58 +00:00
Ralf Jung
88e39ee314 make first component of dyn* use pointer layout+type, and adjust DynStar comment 2023-02-18 19:24:55 +00:00
bors
53709aedba Auto merge of #108209 - petrochenkov:doclean, r=notriddle
rustdoc: Cleanup doc link extraction
2023-02-18 16:41:55 +00:00
Matthias Krüger
6c91efd6d7
Rollup merge of #108205 - tshepang:why-special-case, r=cjgillot
link to llvm changes that prompted the special cases
2023-02-18 13:26:48 +01:00
Matthias Krüger
d3d5163921
Rollup merge of #108186 - compiler-errors:closures-with-late-bound-types-r-bad, r=cjgillot
Deny non-lifetime bound vars in `for<..> ||` closure binders

Moves the check for illegal bound var types from astconv to resolve_bound_vars. If a binder is defined to have a type or const late-bound var that's not allowed, we'll resolve any usages to ty error or const error values, so we shouldn't ever see late-bound types or consts in places they aren't expected.

Fixes #108184
Fixes #108181
Fixes #108192
2023-02-18 13:26:47 +01:00
Matthias Krüger
7f9d9de82d
Rollup merge of #108162 - clubby789:issue-108155, r=Nilstrieb
Don't eagerly convert principal to string

Fixes #108155

~~I haven't yet been able to reproduce the ICE in a minimal example unfortunately.~~ Added a test
2023-02-18 13:26:47 +01:00
Matthias Krüger
d9c9040290
Rollup merge of #108046 - oli-obk:no_evaluating_fed_queries, r=cjgillot
Don't allow evaluating queries that were fed in a previous compiler run

r? `@cjgillot`

this code was already unreachable. Also we removed the no_hash + feeding restriction in https://github.com/rust-lang/rust/pull/105220.
2023-02-18 13:26:46 +01:00
Matthias Krüger
3035ccbcb9
Rollup merge of #108031 - jieyouxu:issue-108019, r=estebank
Don't recover lifetimes/labels containing emojis as character literals

Fixes #108019.

Note that at the time of this commit, `unic-emoji-char` seems to have data tables only up to Unicode 5.0, but Unicode is already newer than this.

A newer emoji such as `🥺` will not be recognized as an emoji but older emojis such as `🐱` will.

This PR leaves a couple of FIXMEs where `unic_emoji_char::is_emoji` is used.
2023-02-18 13:26:46 +01:00
Vadim Petrochenkov
97e73eea84 doc links: Filter away autolinks in both rustc and rustdoc 2023-02-18 15:15:57 +04:00
Vadim Petrochenkov
ccdb598d1b rustdoc: Cleanup broken link callbacks 2023-02-18 14:45:01 +04:00
Tshepang Mbambo
8ab795ef08 add a summary, in addition to the link 2023-02-18 11:09:40 +02:00
Tshepang Mbambo
225e01ee79 link to llvm changes that prompted the special cases 2023-02-18 09:59:41 +02:00
bors
6d819a4b8f Auto merge of #106476 - keith:ks/add-sanitizer-support-for-modern-ios-platforms, r=badboy
Add sanitizer support for modern iOS platforms

asan and tsan generally support iOS, but that previously wasn't configured in rust. This only adds support for the simulator architectures, and arm64 device architecture, not the older 32 bit architectures.
2023-02-18 05:58:41 +00:00
Michael Goulet
cec7835d7a Move late-bound arg type checks to resolve_bound_vars 2023-02-18 03:28:54 +00:00
bors
fabfd1fd93 Auto merge of #99679 - repnop:kernel-address-sanitizer, r=cuviper
Add `kernel-address` sanitizer support for freestanding targets

This PR adds support for KASan (kernel address sanitizer) instrumentation in freestanding targets. I included the minimal set of `x86_64-unknown-none`, `riscv64{imac, gc}-unknown-none-elf`, and `aarch64-unknown-none` but there's likely other targets it can be added to. (`linux_kernel_base.rs`?) KASan uses the address sanitizer attributes but has the `CompileKernel` parameter set to `true` in the pass creation.
2023-02-18 03:05:11 +00:00
Michael Goulet
fded2e95ab Adjust tracking issue for non_lifetime_binders 2023-02-18 02:42:43 +00:00
bors
a9842c73bc Auto merge of #108112 - nnethercote:clarify-iterator-interners, r=oli-obk,compiler-errors
Clarify iterator interners

I found the iterator interners very confusing. This PR clarifies things.

r? `@compiler-errors`
2023-02-18 00:20:52 +00:00
bors
231bcd131d Auto merge of #105274 - saethlin:instcombine-mut-ref, r=cjgillot
Enable instcombine for mutable reborrows

`instcombine` used to contain this comment, which is no longer accurate because there it is fine to copy `&mut _` in MIR:
```rust
// The dereferenced place must have type `&_`, so that we don't copy `&mut _`.
```
So let's try replacing that check with something much more permissive...
2023-02-17 20:50:11 +00:00
bors
9aa5c24b7d Auto merge of #108075 - WaffleLapkin:de-arena-allocates-you-OwO, r=Nilstrieb
Remove `arena_cache` modifier from `associated_item` query & copy `ty::AssocItem` instead of passing by ref

r? `@ghost`
2023-02-17 17:42:51 +00:00
Oli Scherer
b4182d240a Don't allow evaluating queries that were fed in a previous compiler run 2023-02-17 16:16:01 +00:00
clubby789
eebd31c187 Don't eagerly convert principal to string 2023-02-17 14:44:58 +00:00
bors
f722b24eb9 Auto merge of #108159 - matthiaskrgr:rollup-5k2j7cx, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #107592 (Default `repr(C)` enums to `c_int` size)
 - #107956 (Copy `bin/*` and `lib/*.dylib` files to `stage0-sysroot`)
 - #108126 (fix a line, and do a consistency fix)
 - #108144 (Add compiler-errors to a few more triagebot groups)
 - #108149 (typo)
 - #108154 (`BasicBlock::new(0)` -> `START_BLOCK` [no functional changes])

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-17 14:27:28 +00:00
Matthias Krüger
ae5473c969
Rollup merge of #108154 - scottmcm:start-block-cleanup, r=compiler-errors
`BasicBlock::new(0)` -> `START_BLOCK` [no functional changes]
2023-02-17 12:39:07 +01:00
Matthias Krüger
392b150011
Rollup merge of #108149 - tshepang:typo, r=Dylan-DPC
typo
2023-02-17 12:39:07 +01:00
Matthias Krüger
e53bd4c282
Rollup merge of #108126 - tshepang:nits, r=lcnr
fix a line, and do a consistency fix
2023-02-17 12:39:06 +01:00
Matthias Krüger
e0aa5613d8
Rollup merge of #107592 - workingjubilee:use-16-bit-enum-on-16-bit-targets, r=WaffleLapkin
Default `repr(C)` enums to `c_int` size

This is what ISO C strongly implies this is correct, and
many processor-specific ABIs imply or mandate this size, so
"everyone" (LLVM, gcc...) defaults to emitting enums this way.
However, this is by no means guaranteed by ISO C,
and the bare-metal Arm targets show it can be overridden,
which rustc supports via `c-enum-min-bits` in a target.json.

The override is a flag named `-fshort-enums` in clang and gcc,
but introducing a CLI flag is probably unnecessary for rustc.
This flag can be used by non-Arm microcontroller targets,
like AVR and MSP430, but it is not enabled for them by default.
Rust programmers who know the size of a target's enums
can use explicit reprs, which also lets them match C23 code.

This change is most relevant to 16-bit targets: AVR and MSP430.
Most of rustc's targets use 32-bit ints, but ILP64 does exist.
Regardless, rustc should now correctly handle enums for
both very small and very large targets.

Thanks to William for confirming MSP430 behavior,
and to Waffle for better style and no-core `size_of` asserts.

Fixes rust-lang/rust#107361
Fixes rust-lang/rust#77806
2023-02-17 12:39:05 +01:00
bors
f4f5fc3e5c Auto merge of #107965 - BoxyUwU:add_const_arg_has_type_predicate, r=compiler-errors
Add `Clause::ConstArgHasType`

Currently the way that we check that a const arg has the correct type for the const param it is an argument for is by setting the expected type of `typeck` on the anon const of the argument to be the const param's type.

In the future for a potential `min_generic_const_exprs` we will allow providing const arguments that do not have an associated anon const that can be typeck'd which will require us to actually check that  the const argument has the correct type. While it would potentially be possible to just call `eq` when creating substs this would not work if we support generics of the form `const N: T, T` (the const parameters type referencing generics declared after itself).

Additionally having `ConstArgHasType` will allow us to potentially make progress on removing the `ty` field of `Const` which may be desirable. Once progress has been made on this, `ConstArgHasType` will also be helpful in ensuring we do not make mistakes in trait/impl checking by declaring functions with the wrong const parameter types as the checks that the param env is compatible would catch it. (We have messed this up in the past, and with generic const parameter types these checks will get more complex)

There is a [document](https://hackmd.io/wuCS6CJBQ9-fWbwaW7nQRw?view) about the types of const generics that may provide some general information on this subject

---

This PR shouldn't have any impact on whether code compiles or not on stable, it primarily exists to make progress on unstable const generics features that are desirable.
2023-02-17 11:27:21 +00:00
Nicholas Nethercote
af32411f20 Avoid double-interning some BoundVariableKinds.
This function has this line twice:
```
let bound_vars = tcx.intern_bound_variable_kinds(&bound_vars);
```
The second occurrence is effectively a no-op, because the first
occurrence interned any that needed it.
2023-02-17 22:24:34 +11:00
Nicholas Nethercote
107f14d2ca Replace more mk_foo calls with infer_foo. 2023-02-17 22:24:34 +11:00
Nicholas Nethercote
2017aeff88 Use IntoIterator for mk_fn_sig.
This makes a lot of call sites nicer.
2023-02-17 22:24:34 +11:00
Nicholas Nethercote
c8237db3ee Clarify iterator interners.
There are two traits, `InternAs` and `InternIteratorElement`. I found
them confusing to use, particularly this:
```
pub fn mk_tup<I: InternAs<Ty<'tcx>, Ty<'tcx>>>(self, iter: I) -> I::Output {
    iter.intern_with(|ts| self.intern_tup(ts))
}
```
where I thought there might have been two levels of interning going on
(there isn't) due to the `intern_with`/`InternAs` + `intern_tup` naming.

And then I found the actual traits and impls themselves *very*
confusing.
- `InternAs` has a single impl, for iterators, with four type variables.
- `InternAs` is only implemented for iterators because it wouldn't
  really make sense to implement for any other type. And you can't
  really understand the trait without seeing that single impl, which is
  suspicious.
- `InternAs` is basically just a wrapper for `InternIteratorElement`
  which does all the actual work.
- Neither trait actually does any interning. They just have `Intern` in
  their name because they are used *by* interning code.
- There are no comments.

So this commit improves things.
- It removes `InternAs` completely. This makes the `mk_*` function
  signatures slightly more verbose -- two trait bounds instead of one --
  but much easier to read, because you only need to understand one trait
  instead of two.
- It renames `InternIteratorElement` as `CollectAndApply`. Likewise, it
  renames its method `intern_with` as `collect_and_apply`. These names
  describe better what's going on: we collect the iterator elements into
  a slice and then apply a function to the slice.
- It adds comments, making clear that all this is all there just to
  provide an optimized version of `f(&iter.collect::<Vec<_>>())`.

It took me a couple of attempts to come up with this commit. My initial
attempt kept `InternAs` around, but renamed things and added comments,
and I wasn't happy with it. I think this version is much better. The
resulting code is shorter, despite the addition of the comments.
2023-02-17 22:24:34 +11:00
Nicholas Nethercote
9d5cf0f0bf Remove the InternIteratorElement impl for &'a T.
`InternIteratorElement` is a trait used to intern values produces by
iterators. There are three impls, corresponding to iterators that
produce different types:
- One for `T`, which operates straightforwardly.
- One for `Result<T, E>`, which is fallible, and will fail early with an
  error result if any of the iterator elements are errors.
- One for `&'a T`, which clones the items as it iterates.

That last one is bad: it's extremely easy to use it without realizing
that it clones, which goes against Rust's normal "explicit is better"
approach to cloning.

So this commit just removes it. In practice, there weren't many use
sites. For all but one of them `into_iter()` could be used, which avoids
the need for cloning. And for the one remaining case `copied()` is
used.
2023-02-17 22:24:34 +11:00
Nicholas Nethercote
28184e7491 Clarify mk_fn_sig signature.
Giving the item type a name `T` avoids duplication.
2023-02-17 22:24:34 +11:00
Nicholas Nethercote
bcf0ec0191 Replace mk_foo calls with infer_foo where possible.
There are several `mk_foo`/`intern_foo` pairs, where the former takes an
iterator and the latter takes a slice. (This naming convention is bad,
but that's a fix for another PR.)

This commit changes several `mk_foo` occurrences into `intern_foo`,
avoiding the need for some `.iter()`/`.into_iter()` calls. Affected
cases:
- mk_type_list
- mk_tup
- mk_substs
- mk_const_list
2023-02-17 22:24:31 +11:00
Boxy
90c8d6bbe4 add predicate evaluation logic 2023-02-17 09:32:39 +00:00