about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2021-07-22Resolve nested inference variables.Oli Scherer-19/+7
I attempted that with the previous code, but I misunderstdood how `shallow_resolve` works.
2021-07-22Remove an unnecessary variableOli Scherer-2/+1
2021-07-22Use instrument debugging for more readable logsOli Scherer-13/+9
2021-07-22Make mir borrowck's use of opaque types independent of the typeck query's resultOli Scherer-87/+66
2021-07-22Fix VecMap::iter_mutOli Scherer-5/+6
It used to allow you to mutate the key, even though that can invalidate the map by creating duplicate keys.
2021-07-22Auto merge of #87265 - Aaron1011:hir-wf-fn, r=estebankbors-47/+172
Support HIR wf checking for function signatures During function type-checking, we normalize any associated types in the function signature (argument types + return type), and then create WF obligations for each of the normalized types. The HIR wf code does not currently support this case, so any errors that we get have imprecise spans. This commit extends `ObligationCauseCode::WellFormed` to support recording a function parameter, allowing us to get the corresponding HIR type if an error occurs. Function typechecking is modified to pass this information during signature normalization and WF checking. The resulting code is fairly verbose, due to the fact that we can no longer normalize the entire signature with a single function call. As part of the refactoring, we now perform HIR-based WF checking for several other 'typed items' (statics, consts, and inherent impls). As a result, WF and projection errors in a function signature now have a precise span, which points directly at the responsible type. If a function signature is constructed via a macro, this will allow the error message to point at the code 'most responsible' for the error (e.g. a user-supplied macro argument).
2021-07-22Auto merge of #87250 - robojumper:87199-sized-relaxation, r=nikomatsakisbors-0/+1
Fix implicit Sized relaxation when attempting to relax other, unsupported trait Fixes #87199. Do note that this bug fix causes code like the `ref_arg::<[i32]>(&[5]);` line in the test case in combination with an affected function to no longer compile.
2021-07-22Auto merge of #87246 - rust-lang:placeholder-pretty, r=nikomatsakisbors-36/+108
When pretty printing, name placeholders as bound regions Split from #85499 When we see a placeholder that we are going to print, treat it as a bound var (and add it to a `for<...>`
2021-07-21Improve caching during trait evaluationAaron Hill-28/+49
Previously, we would 'forget' that we had `'static` regions in some place during trait evaluation. This lead to us producing `EvaluatedToOkModuloRegions` when we could have produced `EvaluatedToOk`, causing us to perform unnecessary work. This PR preserves `'static` regions when we canonicalize a predicate for `evaluate_obligation`, and when we 'freshen' a predicate during trait evaluation. Thie ensures that evaluating a predicate containing `'static` regions can produce `EvaluatedToOk` (assuming that we don't end up introducing any region dependencies during evaluation). Building off of this improved caching, we use `predicate_must_hold_considering_regions` during fulfillment of projection predicates to see if we can skip performing additional work. We already do this for trait predicates, but doing this for projection predicates lead to mixed performance results without the above caching improvements.
2021-07-21Rollup merge of #87346 - rylev:rename-force-warn, r=nikomatsakisEric Huss-6/+6
Rename force-warns to force-warn The renames the `--force-warns` option to `--force-warn`. This mirrors other lint options like `--warn` and `--deny` which are in the singular. r? `@nikomatsakis` cc `@ehuss` - this option is being used by Cargo. How do we make sure the transition to using the new name is as smooth as possible?
2021-07-21Rollup merge of #87342 - midgleyc:add-E0757-long, r=GuillaumeGomezGuillaume Gomez-1/+34
Add long explanation for E0757 Helps with #61137
2021-07-21Rollup merge of #87321 - midgleyc:add-E0722-long, r=GuillaumeGomezGuillaume Gomez-1/+32
Add long explanation for E0722 Helps with #61137
2021-07-21Rollup merge of #87311 - oli-obk:nll_suggestion_span, r=estebankGuillaume Gomez-4/+6
Get back the more precise suggestion spans of old regionck I noticed that when you turn on nll, the structured suggestion replaces a snippet instead of appending a snippet. It seems clearer to the user to only highlight the newly added characters instead of the entire `impl Trait` (and old regionck already does it this way). r? ``@estebank``
2021-07-21Rollup merge of #87273 - fee1-dead:impl-const-impl-bounds, r=oli-obkGuillaume Gomez-22/+34
Recognize bounds on impls as const bounds r? ```@oli-obk```
2021-07-21Rollup merge of #87206 - matthiaskrgr:clippy_collect, r=davidtwcoGuillaume Gomez-9/+5
avoid temporary vectors/reuse iterators Avoid collecting an interator just to re-iterate immediately. Rather reuse the previous iterator. (clippy::needless_collect)
2021-07-21Rename force-warns to force-warnRyan Levick-6/+6
2021-07-21docs: normalise wording in line with docsChris Midgley-1/+1
2021-07-21docs: add additional links for ffi_pure / ffi_constChris Midgley-2/+10
2021-07-21Add long explanation for E0757Chris Midgley-1/+26
2021-07-21docs: add newline before exampleChris Midgley-0/+1
2021-07-21docs: remove spurious main functionsChris Midgley-4/+0
2021-07-21add working code exampleChris Midgley-0/+10
2021-07-20Add long explanation for E0722Chris Midgley-1/+25
2021-07-20Support HIR wf checking for function signaturesAaron Hill-47/+172
During function type-checking, we normalize any associated types in the function signature (argument types + return type), and then create WF obligations for each of the normalized types. The HIR wf code does not currently support this case, so any errors that we get have imprecise spans. This commit extends `ObligationCauseCode::WellFormed` to support recording a function parameter, allowing us to get the corresponding HIR type if an error occurs. Function typechecking is modified to pass this information during signature normalization and WF checking. The resulting code is fairly verbose, due to the fact that we can no longer normalize the entire signature with a single function call. As part of the refactoring, we now perform HIR-based WF checking for several other 'typed items' (statics, consts, and inherent impls). As a result, WF and projection errors in a function signature now have a precise span, which points directly at the responsible type. If a function signature is constructed via a macro, this will allow the error message to point at the code 'most responsible' for the error (e.g. a user-supplied macro argument).
2021-07-20Get back the more precise suggestion spans of old regionckOli Scherer-4/+6
2021-07-20Auto merge of #87244 - jackh726:issue-71883, r=estebankbors-31/+149
Better diagnostics with mismatched types due to implicit static lifetime Fixes #78113 I think this is my first diagnostics PR...definitely happy to hear thoughts on the direction/implementation here. I was originally just trying to solve the error above, where the lifetime on a GAT was causing a cryptic "mismatched types" error. But as I was writing this, I realized that this (unintentionally) also applied to a different case: `wf-in-foreign-fn-decls-issue-80468.rs`. I'm not sure if this diagnostic should get a new error code, or even reuse an existing one. And, there might be some ways to make this even more generalized. Also, the error is a bit more lengthy and verbose than probably needed. So thoughts there are welcome too. This PR essentially ended up adding a new nice region error pass that triggers if a type doesn't match the self type of an impl which is selected because of a predicate because of an implicit static bound on that self type. r? `@estebank`
2021-07-20Auto merge of #87224 - RalfJung:miri-ptr-oob, r=oli-obkbors-18/+40
miri: better ptr-out-of-bounds errors For offsets larger than `isize::MAX`, display them as negative offsets. r? `@oli-obk`
2021-07-20Auto merge of #87141 - spastorino:remove_impl_trait_in_bindings, r=oli-obkbors-313/+61
Remove impl trait in bindings Closes #86729 r? `@oli-obk`
2021-07-19Better errors when we don't have implicit statics in trait objectsjackh726-31/+53
2021-07-20Auto merge of #84959 - camsteffen:lint-suggest-group, r=estebankbors-7/+7
Suggest lint groups Fixes rust-lang/rust-clippy#6986
2021-07-19Auto merge of #87284 - Aaron1011:remove-paren-special, r=petrochenkovbors-6/+0
Remove special case for `ExprKind::Paren` in `MutVisitor` The special case breaks several useful invariants (`ExpnId`s are globally unique, and never change). This special case was added back in 2016 in https://github.com/rust-lang/rust/pull/34355 r? `@petrochenkov`
2021-07-19Remove special case for `ExprKind::Paren` in `MutVisitor`Aaron Hill-6/+0
The special case breaks several useful invariants (`ExpnId`s are globally unique, and never change). This special case was added back in 2016 in https://github.com/rust-lang/rust/pull/34355
2021-07-19Better diagnostics when mismatched types due to implict static lifetimejackh726-16/+112
2021-07-19Auto merge of #87153 - ↵bors-71/+140
michaelwoerister:debuginfo-names-dyn-trait-projection-bounds, r=wesleywiser [debuginfo] Emit associated type bindings in trait object type names. This PR updates debuginfo type name generation for trait objects to include associated type bindings and auto trait bounds -- so that, for example, the debuginfo type name of `&dyn Iterator<Item=Foo>` and `&dyn Iterator<Item=Bar>` don't both map to just `&dyn Iterator` anymore. The following table shows examples of debuginfo type names before and after the PR: | type | before | after | |------|---------|-------| | `&dyn Iterator<Item=u32>>` | `&dyn Iterator` | `&dyn Iterator<Item=u32>` | | `&(dyn Iterator<Item=u32>> + Sync)` | `&dyn Iterator` | `&(dyn Iterator<Item=u32> + Sync)` | | `&(dyn SomeTrait<bool, i8, Bar=u32>> + Send)` | `&dyn SomeTrait<bool, i8>` | `&(dyn SomeTrait<bool, i8, Bar=u32>> + Send)` | For targets that need C++-like type names, we use `assoc$<Item,u32>` instead of `Item=u32`: | type | before | after | |------|---------|-------| | `&dyn Iterator<Item=u32>>` | `ref$<dyn$<Iterator> >` | `ref$<dyn$<Iterator<assoc$<Item,u32> > > >` | | `&(dyn Iterator<Item=u32>> + Sync)` | `ref$<dyn$<Iterator> >` | `ref$<dyn$<Iterator<assoc$<Item,u32> >,Sync> >` | | `&(dyn SomeTrait<bool, i8, Bar=u32>> + Send)` | `ref$<dyn$<SomeTrait<bool, i8> > >` | `ref$<dyn$<SomeTrait<bool,i8,assoc$<Bar,u32> > >,Send> >` | The PR also adds self-profiling measurements for debuginfo type name generation (re. https://github.com/rust-lang/rust/issues/86431). It looks like the compiler spends up to 0.5% of its time in that task, so the potential for optimizing it via caching seems limited. However, the perf run also shows [the biggest regression](https://perf.rust-lang.org/detailed-query.html?commit=585e91c718b0b2c5319e1fffd0ff1e62aaf7ccc2&base_commit=b9197978a90be6f7570741eabe2da175fec75375&benchmark=tokio-webpush-simple-debug&run_name=incr-unchanged) in a test case that does not even invoke the code in question. This suggests that the length of the names we generate here can affect performance by influencing how much data the linker has to copy around. Fixes https://github.com/rust-lang/rust/issues/86134.
2021-07-19Auto merge of #87225 - estebank:cleanup, r=oli-obkbors-28/+52
Various diagnostics clean ups/tweaks * Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-19Various diagnostics clean ups/tweaksEsteban Küber-28/+52
* Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-19Improve impl trait disallowed context error textSantiago Pastorino-1/+1
2021-07-19Auto merge of #86970 - inquisitivecrystal:force-warn, r=davidtwcobors-46/+18
Make `--force-warns` a normal lint level option Now that `ForceWarn` is a lint level, there's no reason `--force-warns` should be treated differently from other options that set lint levels. This merges the `ForceWarn` handling in with the other lint level command line options. It also unifies all of the relevant selection logic in `compiler/rustc_lint/src/levels.rs`, rather than having some of it weirdly elsewhere. Fixes #86958, which arose from the special-cased handling of `ForceWarn` having had an error in it.
2021-07-19Improve impl_trait_in_bindings removed feature textSantiago Pastorino-1/+1
2021-07-19Recognize bounds on impls as const boundsDeadbeef-14/+23
2021-07-19Iterate through impls only when permittedDeadbeef-8/+11
2021-07-19Rollup merge of #87268 - SkiFire13:fix-uninit-ref-list, r=nagisaGuillaume Gomez-6/+6
Don't create references to uninitialized data in `List::from_arena` Previously `result` and `arena_slice` were references pointing to uninitialized data, which is technically UB. They may have been fine because the pointed data is `Copy` and and they were only written to, but the semantics of this aren't clearly defined yet, and since we have a sound way to do the same thing I don't think we should keep the possibly-unsound way.
2021-07-19Rollup merge of #87256 - Aaron1011:hir-wf-assoc-default, r=oli-obkGuillaume Gomez-1/+5
Extend HIR-based WF checking to associated type defaults Previously, we would only look at associated types in `impl` blocks.
2021-07-19Don't create references to uninitialized data in List::from_arenaGiacomo Stevanato-6/+6
2021-07-19Auto merge of #87146 - Aaron1011:better-macro-lint, r=petrochenkovbors-44/+119
Compute a better `lint_node_id` during expansion When we need to emit a lint at a macro invocation, we currently use the `NodeId` of its parent definition (e.g. the enclosing function). This means that any `#[allow]` / `#[deny]` attributes placed 'closer' to the macro (e.g. on an enclosing block or statement) will have no effect. This commit computes a better `lint_node_id` in `InvocationCollector`. When we visit/flat_map an AST node, we assign it a `NodeId` (earlier than we normally would), and store than `NodeId` in current `ExpansionData`. When we collect a macro invocation, the current `lint_node_id` gets cloned along with our `ExpansionData`, allowing it to be used if we need to emit a lint later on. This improves the handling of `#[allow]` / `#[deny]` for `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` and some `asm!`-related lints. The 'legacy derive helpers' lint retains its current behavior (I've inlined the now-removed `lint_node_id` function), since there isn't an `ExpansionData` readily available.
2021-07-19Auto merge of #86848 - notriddle:notriddle/drop-dyn, r=varkorbors-1/+62
feat(rustc_lint): add `dyn_drop` Based on the conversation in #86747. Explanation ----------- A trait object bound of the form `dyn Drop` is most likely misleading and not what the programmer intended. `Drop` bounds do not actually indicate whether a type can be trivially dropped or not, because a composite type containing `Drop` types does not necessarily implement `Drop` itself. Naïvely, one might be tempted to write a deferred drop system, to pull cleaning up memory out of a latency-sensitive code path, using `dyn Drop` trait objects. However, this breaks down e.g. when `T` is `String`, which does not implement `Drop`, but should probably be accepted. To write a trait object bound that accepts anything, use a placeholder trait with a blanket implementation. ```rust trait Placeholder {} impl<T> Placeholder for T {} fn foo(_x: Box<dyn Placeholder>) {} ```
2021-07-18Auto merge of #87004 - JamieCunliffe:pgo-gc-sections, r=Mark-Simulacrumbors-1/+6
Don't use gc-sections with profile-generate. When building with profile-generate don't call gc_sections as this can can sometimes strip out profile data. This missing information in the prof files can then result in missing functions when using the profile information. #78226 r? `@Mark-Simulacrum`
2021-07-18Auto merge of #86950 - tmiasko:personality, r=nagisabors-5/+14
Use existing declaration of rust_eh_personality If crate declares `rust_eh_personality`, re-use existing declaration as otherwise attempts to set function attributes that follow the declaration will fail (unless it happens to have exactly the same type signature as the one predefined in the compiler). Fixes #70117. Fixes https://github.com/rust-lang/rust/pull/81469#issuecomment-809428126; probably.
2021-07-18Extend HIR-based WF checking to associated type defaultsAaron Hill-1/+5
Previously, we would only look at associated types in `impl` blocks.
2021-07-18feat(rustc_lint): add `dyn_drop`Michael Howell-1/+62
Based on the conversation in #86747. Explanation ----------- A trait object bound of the form `dyn Drop` is most likely misleading and not what the programmer intended. `Drop` bounds do not actually indicate whether a type can be trivially dropped or not, because a composite type containing `Drop` types does not necessarily implement `Drop` itself. Naïvely, one might be tempted to write a deferred drop system, to pull cleaning up memory out of a latency-sensitive code path, using `dyn Drop` trait objects. However, this breaks down e.g. when `T` is `String`, which does not implement `Drop`, but should probably be accepted. To write a trait object bound that accepts anything, use a placeholder trait with a blanket implementation. ```rust trait Placeholder {} impl<T> Placeholder for T {} fn foo(_x: Box<dyn Placeholder>) {} ```