Commit Graph

2519 Commits

Author SHA1 Message Date
Michael Goulet
137c207d20 FIXME for diagnostic variable name 2022-04-10 11:11:25 -07:00
bors
559c01931b Auto merge of #95435 - cjgillot:one-name, r=oli-obk
Make def names and HIR names consistent.

The name in the `DefKey` is interned to create the `DefId`, so it does not
require any query to access.  This can be leveraged to avoid a few useless
HIR accesses for names.

~In order to achieve that, generic parameters created from universal
impl-trait are given the pretty-printed ast as a name, instead of
`{{opaque}}`.~

~Drive-by: the `TyCtxt::opt_item_name` used a dummy span for non-local
definitions.  We have access to `def_ident_span`, so we use it.~
2022-04-09 22:48:00 +00:00
bors
8c1fb2eb23 Auto merge of #95697 - klensy:no-strings, r=petrochenkov
refactor: simplify few string related interactions

Few small optimizations:

check_doc_keyword: don't alloc string for emptiness check
check_doc_alias_value: get argument as Symbol to prevent needless string convertions
check_doc_attrs: don't alloc vec, iterate over slice.
replace as_str() check with symbol check
get_single_str_from_tts: don't prealloc string
trivial string to str replace
LifetimeScopeForPath::NonElided use Vec<Symbol> instead of Vec<String>
AssertModuleSource use FxHashSet<Symbol> instead of BTreeSet<String>
CrateInfo.crate_name replace FxHashMap<CrateNum, String> with FxHashMap<CrateNum, Symbol>
2022-04-09 13:15:26 +00:00
Dylan DPC
dfb4194e3b
Rollup merge of #95785 - RalfJung:interpret-size-mismatch, r=oli-obk
interpret: err instead of ICE on size mismatches in to_bits_or_ptr_internal

We did this a while ago already for `to_i32()` and friends, but missed this one. That became quite annoying when I was debugging an ICE caused by `read_pointer` in a Miri shim where the code was passing an argument at the wrong type.

Having `scalar_to_ptr` be fallible is consistent with all the other `Scalar::to_*` methods being fallible. I added `unwrap` only in code outside the interpreter, which is no worse off than before now in terms of panics.

r? ````@oli-obk````
2022-04-09 12:52:05 +02:00
Camille GILLOT
f89d64d7aa Use def_key in tcx.item_name when possible. 2022-04-09 10:54:43 +02:00
bors
e980c62955 Auto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercote
Cached stable hash cleanups

r? `@nnethercote`

Add a sanity assertion in debug mode to check that the cached hashes are actually the ones we get if we compute the hash each time.

Add a new data structure that bundles all the hash-caching work to make it easier to re-use it for different interned data structures
2022-04-09 02:31:24 +00:00
Oli Scherer
25d6f8e0f6 Avoid looking at the internals of Interned directly 2022-04-08 15:57:44 +00:00
klensy
d0cc98689e check_doc_keyword: don't alloc string for emptiness check
check_doc_alias_value: get argument as Symbol to prevent needless string convertions

check_doc_attrs: don't alloc vec, iterate over slice. Vec introduced in #83149, but no perf run posted on merge

replace as_str() check with symbol check

get_single_str_from_tts: don't prealloc string

trivial string to str replace

LifetimeScopeForPath::NonElided use Vec<Symbol> instead of Vec<String>

AssertModuleSource use BTreeSet<Symbol> instead of BTreeSet<String>

CrateInfo.crate_name replace FxHashMap<CrateNum, String> with FxHashMap<CrateNum, Symbol>
2022-04-08 11:45:57 +03:00
Camille GILLOT
b5dfa6a78d Compute ty_param_owner using DefIdTree. 2022-04-07 22:30:16 +02:00
Ralf Jung
38004b72bc interpret: err instead of ICE on size mismatches in to_bits_or_ptr_internal 2022-04-07 16:24:48 -04:00
Oli Scherer
7d2cad68d2 Deduplicate the error printing code for hidden type mismatches 2022-04-07 13:52:59 +00:00
Oli Scherer
25876b3541 Report opaque type mismatches directly during borrowck of the function instead of within the type_of query.
This allows us to only store a single hidden type per opaque type instead of having to store one per set of substitutions.
2022-04-07 13:39:52 +00:00
Oli Scherer
2e0ef701c2 Document and rename the new wrapper type 2022-04-07 13:01:48 +00:00
Pietro Albini
181d28bb61
trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
bors
f262ca12aa Auto merge of #94527 - oli-obk:undef_scalars, r=nagisa,erikdesjardin
Let CTFE to handle partially uninitialized unions without marking the entire value as uninitialized.

follow up to #94411

To fix https://github.com/rust-lang/rust/issues/69488 and by extension fix https://github.com/rust-lang/rust/issues/94371, we should stop treating types like `MaybeUninit<usize>` as something that the `Scalar` type in the interpreter engine can represent. So we add a new field to `abi::Primitive` that records whether the primitive is nested in a union

cc `@RalfJung`

r? `@ghost`
2022-04-05 16:46:13 +00:00
Oli Scherer
d57b755909 Use WrappingRange::full instead of hand-rolling it 2022-04-05 13:18:22 +00:00
Oli Scherer
d32ce37a17 Mark scalar layout unions so that backends that do not support partially initialized scalars can special case them. 2022-04-05 13:18:21 +00:00
David Wood
9956d4f99d macros: add args for non-subdiagnostic fields
Non-subdiagnostic fields (i.e. those that don't have `#[label]`
attributes or similar and are just additional context) have to be added
as arguments for Fluent messages to refer them. This commit extends the
`SessionDiagnostic` derive to do this for all fields that do not have
attributes and introduces an `IntoDiagnosticArg` trait that is
implemented on all types that can be converted to a argument for Fluent.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:02 +01:00
David Wood
c45f29595d span: move MultiSpan
`MultiSpan` contains labels, which are more complicated with the
introduction of diagnostic translation and will use types from
`rustc_errors` - however, `rustc_errors` depends on `rustc_span` so
`rustc_span` cannot use types like `DiagnosticMessage` without
dependency cycles. Introduce a new `rustc_error_messages` crate that can
contain `DiagnosticMessage` and `MultiSpan`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:00 +01:00
Esteban Kuber
3aac307ca6 Mention implementers of unsatisfied trait
When encountering an unsatisfied trait bound, if there are no other
suggestions, mention all the types that *do* implement that trait:

```
error[E0277]: the trait bound `f32: Foo` is not satisfied
  --> $DIR/impl_wf.rs:22:6
   |
LL | impl Baz<f32> for f32 { }
   |      ^^^^^^^^ the trait `Foo` is not implemented for `f32`
   |
   = help: the following other types implement trait `Foo`:
             Option<T>
             i32
             str
note: required by a bound in `Baz`
  --> $DIR/impl_wf.rs:18:31
   |
LL | trait Baz<U: ?Sized> where U: Foo { }
   |                               ^^^ required by this bound in `Baz`
```

Mention implementers of traits in `ImplObligation`s.

Do not mention other `impl`s for closures, ranges and `?`.
2022-04-04 21:01:42 +00:00
bors
ec667fbcfc Auto merge of #95031 - compiler-errors:param-env-cache, r=Aaron1011
Do not use `ParamEnv::and` when building a cache key from a param-env and trait eval candidate

Do not use `ParamEnv::and` to cache a param-env with a selection/evaluation candidate.

This is because if the param-env is `RevealAll` mode, and the candidate looks global (i.e. it has erased regions, which can show up when we normalize a projection type under a binder<sup>1</sup>), then when we use `ParamEnv::and` to pair the candidate and the param-env for use as a cache key, we will throw away the param-env's caller bounds, and we'll end up caching a candidate that we inferred from the param-env with a empty param-env, which may cause cache-hit later when we have an empty param-env, and possibly mess with normalization like we see in the referenced issue during codegen.

Not sure how to trigger this with a more structured test, but changing `check-pass` to `build-pass` triggers the case that https://github.com/rust-lang/rust/issues/94903 detected.

<sup>1.</sup> That is, we will replace the late-bound region with a placeholder, which gets canonicalized and turned into an infererence variable, which gets erased during region freshening right before we cache the result. Sorry, it's quite a few steps.

Fixes #94903
r? `@Aaron1011` (or reassign as you see fit)
2022-04-04 04:48:36 +00:00
bors
fbc45b650a Auto merge of #95537 - GuillaumeGomez:type_of-doc, r=Dylan-DPC
Improve TyCtxt::type_of documentation

r? `@oli-obk`
2022-04-02 12:13:11 +00:00
Guillaume Gomez
6fdeee4be3 Improve TyCtxt::type_of documentation 2022-04-02 13:57:27 +02:00
Dylan DPC
1c82fac3f7
Rollup merge of #95560 - lcnr:obligation-cause, r=oli-obk
convert more `DefId`s to `LocalDefId`
2022-04-02 03:34:27 +02:00
Dylan DPC
1e43cf46bd
Rollup merge of #95559 - lcnr:inferctxt-typeck, r=oli-obk
small type system refactoring
2022-04-02 03:34:26 +02:00
bors
eb82facb16 Auto merge of #94883 - cjgillot:flat-metadata, r=oli-obk
Encode even more metadata through tables instead of EntryKind

This should move us closer to getting rid of `EntryKind`.
2022-04-01 21:16:41 +00:00
lcnr
8eacf6078f update comment 2022-04-01 13:47:01 +02:00
lcnr
796b828371 convert more DefIds to LocalDefId 2022-04-01 13:38:43 +02:00
lcnr
389c83b474 remove unused incorrect EqUnifyValue impl 2022-04-01 12:57:24 +02:00
lcnr
c2b5a7ea52 remove unify_key::replace_if_possible 2022-04-01 12:41:46 +02:00
Matthias Krüger
cdf178f776
Rollup merge of #95388 - RalfJung:rust-val-limit, r=oli-obk
interpret: make isize::MAX the limit for dynamic value sizes

We are currently enforcing `data_layout.obj_size_bound()` as the maximal dynamic size of a Rust value (including for `size_of_val_raw`), but that does not match the docs.

In particular, Miri currently falsely says that this code has UB:
```rust
#![feature(layout_for_ptr)]
fn main() {
    let size = isize::MAX as usize;
    // Creating a raw slice of size isize::MAX and asking for its size is okay.
    let s = std::ptr::slice_from_raw_parts(1usize as *const u8, size);
    assert_eq!(size, unsafe { std::mem::size_of_val_raw(s) });
}
```
2022-04-01 06:59:44 +02:00
Matthias Krüger
94b1960535
Rollup merge of #95260 - compiler-errors:fn, r=davidtwco
Better suggestions for `Fn`-family trait selection errors

1. Suppress suggestions to add `std::ops::Fn{,Mut,Once}` bounds when a type already implements `Fn{,Mut,Once}`
2. Add a note that points out that a type does in fact implement `Fn{,Mut,Once}`, but the arguments vary (either by number or by actual arguments)
3. Add a note that points out that a type does in fact implement `Fn{,Mut,Once}`, but not the right one (e.g. implements `FnMut`, but `Fn` is required).

Fixes #95147
2022-04-01 06:59:41 +02:00
Camille GILLOT
15b2d1a97c Merge impl_constness and is_const_fn_raw. 2022-03-31 18:33:46 +02:00
Camille GILLOT
e62f483842 Create trait_def table. 2022-03-31 18:14:54 +02:00
Oli Scherer
33d0ce95a9 inline a trivial function 2022-03-31 14:54:04 +00:00
Oli Scherer
00c24dd8ce Move stable hash from TyS into a datastructure that can be shared with other interned types. 2022-03-31 14:54:04 +00:00
Ralf Jung
a421cbbead interpret: make isize::MAX the limit for dynamic value sizes 2022-03-31 08:57:45 -04:00
lcnr
d7cada1767 obligation cause: RepeatVec -> RepeatValueCopy 2022-03-31 12:51:46 +02:00
Dylan DPC
1b7d6dbd30
Rollup merge of #95497 - nyurik:compiler-spell-comments, r=compiler-errors
Spellchecking compiler comments

This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-31 04:57:28 +02:00
Dylan DPC
4ce6567daa
Rollup merge of #95263 - compiler-errors:async-block-pretty, r=jackh726
Restore `impl Future<Output = Type>` to async blocks

I was sad when I undid some of the code I wrote in #91096 in the PR #95225, so I fixed it here to not print `[async output]`.

This PR "manually" normalizes the associated type `<[generator] as Generator>::Return` type which appears very frequently in `impl Future` types that result from async block desugaring.
2022-03-31 04:57:25 +02:00
Michael Goulet
7b2eaa3d8f Restore impl Future<Output = Type> to async blocks 2022-03-30 19:26:35 -07:00
bors
a39ac5ae17 Auto merge of #95501 - Dylan-DPC:rollup-arx6sdc, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #93901 (Stabilize native library modifier syntax and the `whole-archive` modifier specifically)
 - #94806 (Fix `cargo run tidy`)
 - #94869 (Add the generic_associated_types_extended feature)
 - #95011 (async: Give predictable name to binding generated from .await expressions.)
 - #95251 (Reduce max hash in raw strings from u16 to u8)
 - #95298 (Fix double drop of allocator in IntoIter impl of Vec)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-31 00:29:54 +00:00
Dylan DPC
e08ab08a2e
Rollup merge of #94869 - jackh726:gats_extended, r=compiler-errors
Add the generic_associated_types_extended feature

Right now, this only ignore obligations that reference new placeholders in `poly_project_and_unify_type`. In the future, this might do other things, like allowing object-safe GATs.

**This feature is *incomplete* and quite likely unsound. This is mostly just for testing out potential future APIs using a "relaxed" set of rules until we figure out *proper* rules.**

Also drive by cleanup of adding a `ProjectAndUnifyResult` enum instead of using a `Result<Result<Option>>`.

r? `@nikomatsakis`
2022-03-31 00:26:29 +02:00
bors
a40c595695 Auto merge of #95436 - cjgillot:static-mut, r=oli-obk
Remember mutability in `DefKind::Static`.

This allows to compute the `BodyOwnerKind` from `DefKind` only, and
removes a direct dependency of some MIR queries onto HIR.

As a side effect, it also simplifies metadata, since we don't need 4
flavours of `EntryKind::*Static` any more.
2022-03-30 22:09:56 +00:00
Jack Huey
4e570a68a1 Add the generic_associated_types_extended feature 2022-03-30 17:41:11 -04:00
Yuri Astrakhan
8d7b124c1f a few mode feedback fixes per @bjorn3 2022-03-30 17:28:19 -04:00
Yuri Astrakhan
a6dd658254 Addressed comments by @compiler-errors and @bjorn3 2022-03-30 17:04:46 -04:00
Yuri Astrakhan
5160f8f843 Spellchecking compiler comments
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-30 15:14:15 -04:00
bors
3e7514670d Auto merge of #94963 - lcnr:inherent-impls-std, r=oli-obk,m-ou-se
allow arbitrary inherent impls for builtin types in core

Part of https://github.com/rust-lang/compiler-team/issues/487. Slightly adjusted after some talks with `@m-ou-se` about the requirements of `t-libs-api`.

This adds a crate attribute `#![rustc_coherence_is_core]` which allows arbitrary impls for builtin types in core.

For other library crates impls for builtin types should be avoided if possible. We do have to allow the existing stable impls however. To prevent us from accidentally adding more of these in the future, there is a second attribute `#[rustc_allow_incoherent_impl]` which has to be added to **all impl items**. This only supports impls for builtin types but can easily be extended to additional types in a future PR.

This implementation does not check for overlaps in these impls. Perfectly checking that requires us to check the coherence of these incoherent impls in every crate, as two distinct dependencies may add overlapping methods. It should be easy enough to detect if it goes wrong and the attribute is only intended for use inside of std.

The first two commits are mostly unrelated cleanups.
2022-03-30 12:28:50 +00:00
lcnr
a6153e8218 get clippy to compile again 2022-03-30 11:23:58 +02:00