Commit Graph

338 Commits

Author SHA1 Message Date
Boxy
90c8d6bbe4 add predicate evaluation logic 2023-02-17 09:32:39 +00:00
bors
9556b56dbd Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwU
Switch to `EarlyBinder` for `type_of` query

Part of the work to finish #105779 and implement https://github.com/rust-lang/types-team/issues/78.

Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This adds `EarlyBinder` to the return type of the `type_of` query and removes `bound_type_of`.

r? `@lcnr`
2023-02-17 04:45:15 +00:00
Kyle Matsuda
c183110cc2 remove bound_type_of query; make type_of return EarlyBinder; change type_of in metadata 2023-02-16 17:05:56 -07:00
Kyle Matsuda
d822b97a27 change usages of type_of to bound_type_of 2023-02-16 17:01:52 -07:00
Michael Goulet
95f35fe443 Deny some late-bound ty/ct in some positions, add tests 2023-02-16 03:39:59 +00:00
Camille GILLOT
03dff82d59 Add of_trait to DefKind::Impl. 2023-02-14 19:55:44 +00:00
Alan Egerton
dea342d861
Make visiting traits generic over the Interner 2023-02-13 10:24:49 +00:00
Alan Egerton
ba55a453eb
Alias folding/visiting traits instead of re-export 2023-02-13 10:24:46 +00:00
klensy
4f5f9f0a13 remove unused imports 2023-02-06 17:40:18 +03:00
Camille GILLOT
15d6325747 Remove HirId -> LocalDefId map from HIR. 2023-01-28 09:55:26 +00:00
Camille GILLOT
1974b6b68d Introduce GeneratorWitnessMIR. 2023-01-27 18:58:44 +00:00
Kyle Matsuda
a969c194d8 fix up subst_identity vs skip_binder; add some FIXMEs as identified in review 2023-01-26 20:28:31 -07:00
Kyle Matsuda
c2414dfaa4 change fn_sig query to use EarlyBinder; remove bound_fn_sig query; add EarlyBinder to fn_sig in metadata 2023-01-26 20:28:25 -07:00
Kyle Matsuda
e982971ff2 replace usages of fn_sig query with bound_fn_sig 2023-01-26 20:15:36 -07:00
Scott McMurray
7d57685682 Also remove #![feature(control_flow_enum)] where possible 2023-01-18 10:22:21 -08:00
Scott McMurray
925dc37313 Stop using BREAK & CONTINUE in compiler
Switching them to `Break(())` and `Continue(())` instead.

libs-api would like to remove these constants, so stop using them in compiler to make the removal PR later smaller.
2023-01-17 23:17:51 -08:00
Kyle Matsuda
f29a334c90 change impl_trait_ref query to return EarlyBinder; remove bound_impl_trait_ref query; add EarlyBinder to impl_trait_ref in metadata 2023-01-14 00:29:56 -07:00
Kyle Matsuda
be130b57d4 change usages of impl_trait_ref to bound_impl_trait_ref 2023-01-14 00:23:32 -07:00
Kyle Matsuda
ef58baf8b8 change const_param_default query to return EarlyBinder; remove bound_const_param_default query; add EarlyBinder to const_param_default in metadata 2023-01-14 00:13:07 -07:00
Kyle Matsuda
bd6c63597b change usages of const_param_default query to bound_const_param_default 2023-01-14 00:13:07 -07:00
Albert Larsan
40ba0e84d5
Change src/test to tests in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00
bors
fa51fc01ca Auto merge of #106235 - compiler-errors:rework-bounds-collection, r=davidtwco
Rework `Bounds` collection

I think it's weird for the `Bounds` struct in astconv to store its predicates *almost* converted into real predicates... so we do this eagerly, instead of lazily.
2023-01-08 14:40:52 +00:00
nils
fd7a159710 Fix uninlined_format_args for some compiler crates
Convert all the crates that have had their diagnostic migration
completed (except save_analysis because that will be deleted soon and
apfloat because of the licensing problem).
2023-01-05 19:01:12 +01:00
Michael Goulet
a313ef05a7 rename get_parent_node to parent_id 2023-01-04 00:43:13 +00:00
Michael Goulet
520b5fac10 Rework hir Bounds collection 2022-12-28 23:40:09 +00:00
Oli Scherer
6af3638709 Prevent the creation of TraitRef without dedicated methods 2022-12-14 15:36:39 +00:00
Oli Scherer
a5cd3bde95 Ensure no one constructs AliasTys themselves 2022-12-14 15:36:39 +00:00
bors
918d0ac38e Auto merge of #104986 - compiler-errors:opaques, r=oli-obk
Combine `ty::Projection` and `ty::Opaque` into `ty::Alias`

Implements https://github.com/rust-lang/types-team/issues/79.

This PR consolidates `ty::Projection` and `ty::Opaque` into a single `ty::Alias`, with an `AliasKind` and `AliasTy` type (renamed from `ty::ProjectionTy`, which is the inner data of `ty::Projection`) defined as so:

```
enum AliasKind {
  Projection,
  Opaque,
}

struct AliasTy<'tcx> {
  def_id: DefId,
  substs: SubstsRef<'tcx>,
}
```

Since we don't have access to `TyCtxt` in type flags computation, and because repeatedly calling `DefKind` on the def-id is expensive, these two types are distinguished with `ty::AliasKind`, conveniently glob-imported into `ty::{Projection, Opaque}`. For example:

```diff
  match ty.kind() {
-   ty::Opaque(..) =>
+   ty::Alias(ty::Opaque, ..) => {}
    _ => {}
  }
```

This PR also consolidates match arms that treated `ty::Opaque` and `ty::Projection` identically.

r? `@ghost`
2022-12-14 01:19:24 +00:00
Michael Goulet
61adaf8187 Combine projection and opaque into alias 2022-12-13 17:48:55 +00:00
Michael Goulet
c13bd83528 squash OpaqueTy and ProjectionTy into AliasTy 2022-12-13 17:40:27 +00:00
Michael Goulet
5c6afb850c ProjectionTy.item_def_id -> ProjectionTy.def_id 2022-12-13 17:34:44 +00:00
Michael Goulet
7f3af72606 Use ty::OpaqueTy everywhere 2022-12-13 17:29:26 +00:00
Oli Scherer
cb26b35b12 Make some diagnostics not depend on the source of what they reference being available 2022-12-13 09:48:22 +00:00
Michael Goulet
26b24cd755 drive-by: move field_index to typeck results 2022-12-04 17:59:21 +00:00
bors
aff003becd Auto merge of #99798 - JulianKnodt:ac1, r=BoxyUwU
Add `ConstKind::Expr`

Starting to implement `ty::ConstKind::Abstract`, most of the match cases are stubbed out, some I was unsure what to add, others I didn't want to add until a more complete implementation was ready.

r? `@lcnr`
2022-11-25 22:56:59 +00:00
Boxy
2ac5d91d63 Make expand_abstract_consts infallible 2022-11-25 09:28:44 +00:00
Boxy
4833ce8673 fmt 2022-11-25 09:28:43 +00:00
kadmin
5bb1a9febc Add expand_abstract_const
Adds the ability to directly expand a const to an expr without having to deal with intermediate
steps.
2022-11-25 09:28:43 +00:00
kadmin
f9750c1554 Add empty ConstKind::Abstract
Initial pass at expr/abstract const/s

Address comments

Switch to using a list instead of &[ty::Const], rm `AbstractConst`

Remove try_unify_abstract_consts

Update comments

Add edits

Recurse more

More edits

Prevent equating associated consts

Move failing test to ui

Changes this test from incremental to ui, and mark it as failing and a known bug.
Does not cause the compiler to ICE, so should be ok.
2022-11-25 09:28:43 +00:00
Santiago Pastorino
974e2837bb
Introduce PredicateKind::Clause 2022-11-25 00:04:54 -03:00
Camille GILLOT
9d20aca983 Store a LocalDefId in hir::Variant & hir::Field. 2022-11-13 14:06:51 +00:00
Vadim Petrochenkov
448261a78a privacy: Check effective visibility invariants 2022-11-05 16:25:41 +04:00
Vadim Petrochenkov
bb401bd04d privacy: Print effective visibilities of constructors 2022-11-05 16:22:23 +04:00
Nicholas Nethercote
c8c25ce5a1 Rename some OwnerId fields.
spastorino noticed some silly expressions like `item_id.def_id.def_id`.

This commit renames several `def_id: OwnerId` fields as `owner_id`, so
those expressions become `item_id.owner_id.def_id`.

`item_id.owner_id.local_def_id` would be even clearer, but the use of
`def_id` for values of type `LocalDefId` is *very* widespread, so I left
that alone.
2022-10-29 20:28:38 +11:00
Vadim Petrochenkov
34eb73c72d privacy: Rename "accessibility levels" to "effective visibilities"
And a couple of other naming tweaks

Related to https://github.com/rust-lang/rust/issues/48054
2022-10-26 16:34:53 +04:00
Bryanskiy
a9447bb9d0 Perf improvements for effective visibility calculating 2022-10-25 15:15:18 +03:00
Nilstrieb
c65ebae221
Migrate all diagnostics 2022-10-23 10:09:44 +02:00
lcnr
b93713fb99 manually inline and rm visit_abstract_const_expr 2022-10-19 10:15:46 +02:00
lcnr
660ca48041 change ConstEvaluatable to use ty::Const 2022-10-18 16:09:04 +02:00
bors
b8b5caee04 Auto merge of #102026 - Bryanskiy:resolve_update, r=petrochenkov
Populate effective visibilities in 'rustc_resolve'

Next part of RFC https://github.com/rust-lang/rust/issues/48054.
previous: https://github.com/rust-lang/rust/pull/101713

`@rustbot` author
r? `@petrochenkov`
2022-10-16 20:34:38 +00:00
Bryanskiy
496ccd982c Populate effective visibilities in 'rustc_resolve' 2022-10-16 21:47:14 +03:00
bors
0938e1680d Auto merge of #101679 - compiler-errors:rpitit-default-body, r=nikomatsakis
Support default-body trait functions with return-position `impl Trait` in traits

Introduce a new `Trait` candidate kind for the `ImplTraitInTrait` projection candidate, which just projects an RPITIT down to its opaque type form.

This is a hack until we lower RPITITs to regular associated types, after which we will need to rework how these default bodies are type-checked, so comments are left in a few places for us to clean up later.

Fixes #101665
2022-10-12 21:03:47 +00:00
Michael Goulet
70f3c79c50 ImplItemKind::TyAlias => ImplItemKind::Type 2022-10-09 07:09:57 +00:00
Michael Goulet
79450360d2 Fix test for default body with impl 2022-10-05 04:16:05 +00:00
Nicholas Nethercote
f07d4efc45 Shrink hir::def::Res.
`Res::SelfTy` currently has two `Option`s. When the second one is `Some`
the first one is never consulted. So we can split it into two variants,
`Res::SelfTyParam` and `Res::SelfTyAlias`, reducing the size of `Res`
from 24 bytes to 12. This then shrinks `hir::Path` and
`hir::PathSegment`, which are the HIR types that take up the most space.
2022-09-29 08:44:52 +10:00
lcnr
1fc86a63f4 rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00
Pietro Albini
3975d55d98
remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Takayuki Maeda
8fe936099a separate definitions and HIR owners
fix a ui test

use `into`

fix clippy ui test

fix a run-make-fulldeps test

implement `IntoQueryParam<DefId>` for `OwnerId`

use `OwnerId` for more queries

change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
2022-09-24 23:21:19 +09:00
Jhonny Bill Mena
5f91719f75 UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic
Also renames:
- sym::AddSubdiagnostic to sym:: Subdiagnostic
- rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
a3396b2070 UPDATE - rename DiagnosticHandler macro to Diagnostic 2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
19b348fed4 UPDATE - rename DiagnosticHandler trait to IntoDiagnostic 2022-09-21 11:39:52 -04:00
Matthias Krüger
a6b34cd928
Rollup merge of #101713 - Bryanskiy:AccessLevels, r=petrochenkov
change AccessLevels representation

Part of RFC (https://github.com/rust-lang/rust/issues/48054). This patch implements effective visibility table with basic methods and change AccessLevels table representation according to it.

r? ``@petrochenkov``
2022-09-17 23:30:49 +02:00
est31
173eb6f407 Only enable the let_else feature on bootstrap
On later stages, the feature is already stable.

Result of running:

rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-15 21:06:45 +02:00
Bryanskiy
d7b9221405 change AccessLevels representation 2022-09-14 18:11:00 +03:00
bors
a0d1df4a5d Auto merge of #101709 - nnethercote:simplify-visitors-more, r=cjgillot
Simplify visitors more

A successor to #100392.

r? `@cjgillot`
2022-09-14 05:21:14 +00:00
Nicholas Nethercote
6568ef338e Remove path_span argument to the visit_path_segment methods.
The `visit_path_segment` method of both the AST and HIR visitors has a
`path_span` argument that isn't necessary. This commit removes it.

There are two very small and inconsequential functional changes.

- One call to `NodeCollector::insert` now is passed a path segment
  identifier span instead of a full path span. This span is only used in
a panic message printed in the case of an internal compiler bug.

- Likewise, one call to `LifetimeCollectVisitor::record_elided_anchor`
  now uses a path segment identifier span instead of a full path span.
  This span is used to make some `'_` lifetimes.
2022-09-12 13:24:25 +10:00
Niklas Jonsson
8d3c30c004 rustc_error, rustc_private, rustc_ast: Switch to stable hash containers 2022-09-10 11:49:12 +02:00
Camille GILLOT
05812df603 Handle generic parameters. 2022-09-09 01:31:46 +00:00
Michael Goulet
4265ef8cb2 Implement projection for ImplTraitPlaceholder 2022-09-09 01:31:44 +00:00
Michael Goulet
78b962a4f3 RPITIT placeholder items 2022-09-09 01:31:44 +00:00
Vadim Petrochenkov
d8d3b83e3a rustc: Parameterize ty::Visibility over used ID
It allows using `LocalDefId` instead of `DefId` when possible, and also encode cheaper `Visibility<DefIndex>` into metadata.
2022-09-07 13:35:41 +04:00
Guillaume Gomez
1aaf9aec95
Rollup merge of #100147 - Bryanskiy:private-in-public, r=petrochenkov
optimization of access level table construction

Refactoring which was mentioned in #87487
2022-09-02 11:34:48 +02:00
Oli Scherer
ee3c835018 Always import all tracing macros for the entire crate instead of piecemeal by module 2022-09-01 14:54:27 +00:00
Bryanskiy
0111fb00da add TestReachabilityVisitor 2022-08-31 14:23:07 +03:00
Vadim Petrochenkov
fc3f3c304b rustc_middle: Remove Visibility::Invisible 2022-08-27 22:34:18 +03:00
Xiretza
7f3a6fd7f6 Replace #[lint/warning/error] with #[diag] 2022-08-21 09:17:43 +02:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Nicholas Nethercote
8c5303898e Simplify rustc_hir::intravisit::Visitor::visit_variant_data.
It has four arguments that are never used. This avoids lots of argument
passing in functions that feed into `visit_variant_data`.
2022-08-11 10:54:01 +10:00
Michael Goulet
694a010a5c move DiagnosticArgFromDisplay into rustc_errors 2022-08-05 16:44:01 +00:00
Michael Goulet
0ad57d8502 Delay formatting trimmed path until lint/error is emitted 2022-08-05 16:44:01 +00:00
Camille GILLOT
d7ea161b7e Remove DefId from AssocItemContainer. 2022-08-01 21:38:45 +02:00
Camille GILLOT
110f0656cb Store associated item defaultness in impl_defaultness. 2022-08-01 21:38:16 +02:00
Camille GILLOT
6733bc3066 Remove guess_head_span. 2022-07-28 23:14:04 +02:00
Matthias Krüger
611bbcb044 clippy::perf fixes 2022-07-20 11:48:11 +02:00
David Wood
c3fdf74885 errors: lint on LintDiagnosticBuilder::build
Apply the `#[rustc_lint_diagnostics]` attribute to
`LintDiagnosticBuilder::build` so that diagnostic migration lints will
trigger for it.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-15 16:13:47 +01:00
Michael Goulet
27b6ab9129 Remove some more usages of guess_head_span 2022-07-15 03:17:20 +00:00
kadmin
e612e2603c Move abstract const to rustc_middle::ty 2022-07-12 02:21:31 +00:00
Dylan DPC
707c0d9a2d
Rollup merge of #98881 - cjgillot:q-def-kind, r=fee1-dead
Only compute DefKind through the query.
2022-07-06 14:49:08 +05:30
Alan Egerton
4f0a64736b
Update TypeVisitor paths 2022-07-06 06:41:53 +01:00
Alan Egerton
e9e5d0685b
Relax constrained generics to TypeVisitable 2022-07-05 22:25:43 +01:00
Camille GILLOT
e3d63203a3 Only compute DefKind through the query. 2022-07-04 10:42:23 +02:00
bors
116edb6800 Auto merge of #98542 - jackh726:coinductive-wf, r=oli-obk
Make empty bounds lower to `WellFormed` and make `WellFormed` coinductive

r? rust-lang/types
2022-06-29 03:22:47 +00:00
Jack Huey
e16dbb5076 Make empty bounds lower to WellFormed and make WellFormed coinductive 2022-06-28 00:17:40 -04:00
David Wood
15d61d711d privacy: deny diagnostic migration lints
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27 08:53:42 +01:00
David Wood
74f3a965f4 privacy: port "in public interface" diag
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27 08:53:42 +01:00
David Wood
0557d02a9d privacy: port unnamed "item is private" diag
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27 08:53:42 +01:00
David Wood
cb90a4f30c privacy: port "item is private" diag
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27 08:53:42 +01:00
David Wood
be9ebfdbce privacy: port "field is private" diag
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27 08:53:42 +01:00
Camille GILLOT
3039cfeb6a Make ExprKind::Closure a struct variant. 2022-06-12 00:16:27 +02:00
Nicholas Nethercote
90db033955 Folding revamp.
This commit makes type folding more like the way chalk does it.

Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods.
- `fold_with` is the standard entry point, and defaults to calling
  `super_fold_with`.
- `super_fold_with` does the actual work of traversing a type.
- For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead
  calls into a `TypeFolder`, which can then call back into
  `super_fold_with`.

With the new approach, `TypeFoldable` has `fold_with` and
`TypeSuperFoldable` has `super_fold_with`.
- `fold_with` is still the standard entry point, *and* it does the
  actual work of traversing a type, for all types except types of
  interest.
- `super_fold_with` is only implemented for the types of interest.

Benefits of the new model.
- I find it easier to understand. The distinction between types of
  interest and other types is clearer, and `super_fold_with` doesn't
  exist for most types.
- With the current model is easy to get confused and implement a
  `super_fold_with` method that should be left defaulted. (Some of the
  precursor commits fixed such cases.)
- With the current model it's easy to call `super_fold_with` within
  `TypeFolder` impls where `fold_with` should be called. The new
  approach makes this mistake impossible, and this commit fixes a number
  of such cases.
- It's potentially faster, because it avoids the `fold_with` ->
  `super_fold_with` call in all cases except types of interest. A lot of
  the time the compile would inline those away, but not necessarily
  always.
2022-06-08 09:24:03 +10:00
Jack Huey
410dcc9674 Fully stabilize NLL 2022-06-03 17:16:41 -04:00
Yuki Okushi
f597846826
Rollup merge of #97096 - tmiasko:reachable-constructor, r=petrochenkov
Types with reachable constructors are reachable

Fixes #96934.

r? `@petrochenkov`
2022-05-18 07:40:58 +09:00
Tomasz Miąsko
17f2893455 Types with reachable constructors are reachable 2022-05-17 00:00:00 +00:00
Miguel Guarniz
f1c256d168 remove redundant branch
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13 11:46:06 -04:00
Miguel Guarniz
e166409f0d remove Visitor impl for PrivateItemsInPublicInterfacesChecker
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13 11:46:06 -04:00
Vadim Petrochenkov
5b5964f569 rustc: Panic by default in DefIdTree::parent
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.
2022-05-02 01:56:50 +03:00
Camille GILLOT
94449e6101 Store all generic bounds as where predicates. 2022-04-30 13:55:13 +02:00
Camille GILLOT
05b29f9a92 Inline WhereClause into Generics. 2022-04-30 13:51:49 +02:00
Camille GILLOT
9861bc8d52 Compute has_pub_restricted in the resolver. 2022-04-23 23:03:18 +02:00
Camille GILLOT
423a712a16 Fix lints. 2022-04-23 23:01:19 +02:00
Camille GILLOT
4bbe078d92 Drop vis in Item. 2022-04-23 09:59:24 +02:00
Camille GILLOT
a6e3124d2c Drop vis in ImplItem. 2022-04-23 09:57:00 +02:00
Camille GILLOT
a62680d108 Drop vis in FieldDef. 2022-04-23 09:56:15 +02:00
Camille GILLOT
10d10efb21 Stop visiting visibility. 2022-04-23 09:53:45 +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
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
Camille GILLOT
21a554caf6 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-29 18:50:52 +02:00
mark
bb8d4307eb rustc_error: make ErrorReported impossible to construct
There are a few places were we have to construct it, though, and a few
places that are more invasive to change. To do this, we create a
constructor with a long obvious name.
2022-03-16 10:35:24 -05:00
Nicholas Nethercote
ca5525d564 Improve AdtDef interning.
This commit makes `AdtDef` use `Interned`. Much the commit is tedious
changes to introduce getter functions. The interesting changes are in
`compiler/rustc_middle/src/ty/adt.rs`.
2022-03-11 13:31:24 +11:00
Takayuki Maeda
51a53bf4df remove unnecessary .. patterns 2022-03-07 02:18:36 +09:00
Mark Rousskov
22c3a71de1 Switch bootstrap cfgs 2022-02-25 08:00:52 -05:00
Vadim Petrochenkov
17b1afdbb2 resolve: Fix incorrect results of opt_def_kind query for some built-in macros
Previously it always returned `MacroKind::Bang` while some of those macros are actually attributes and derives
2022-02-24 22:54:36 +03:00
Nicholas Nethercote
a95fb8b150 Overhaul Const.
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as
this:
```
pub struct Const<'tcx>(&'tcx Interned<ConstS>);
```
This now matches `Ty` and `Predicate` more closely, including using
pointer-based `eq` and `hash`.

Notable changes:
- `mk_const` now takes a `ConstS`.
- `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a
  we need separate arena for it, because we can't use the `Dropless` one any
  more.
- Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes
- Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes.
- Lots of tedious sigil fiddling.
2022-02-15 16:19:59 +11:00
Ellen
e81e09a24e change to a struct variant 2022-02-12 11:23:53 +00:00
lcnr
a1a30f7548 add a rustc::query_stability lint 2022-02-01 10:15:59 +01:00
Cameron Steffen
b11733534d Remove a span from hir::ExprKind::MethodCall 2022-01-21 07:48:10 -06:00
Matthias Krüger
db1253f1d2
Rollup merge of #92582 - lcnr:generic-arg-infer, r=BoxyUwU
improve `_` constants in item signature handling

removing the "type" from the error messages does slightly worsen the error messages for types, but figuring out whether the placeholder is for a type or a constant and correctly dealing with that seemed fairly difficult to me so I took the easy way out  Imo the error message is still clear enough.

r? `@BoxyUwU` cc `@estebank`
2022-01-20 17:10:35 +01:00
lcnr
cbc6d35a57 privacy: update visit_infer 2022-01-18 12:23:43 +01:00
bors
7bc7be860f Auto merge of #87648 - JulianKnodt:const_eq_constrain, r=oli-obk
allow eq constraints on associated constants

Updates #70256

(cc `@varkor,` `@Centril)`
2022-01-18 09:58:39 +00:00
kadmin
f396888c4d Update w/ comments
Removes uses of ty() where a method is implemented on TypeFoldable, and also directly formats
a Term.
2022-01-17 20:01:21 +00:00
kadmin
e7529d6a38 Update term for use in more places
Replace use of `ty()` on term and use it in more places. This will allow more flexibility in the
future, but slightly worried it allows items which are consts which only accept types.
2022-01-17 19:59:40 +00:00
kadmin
67f56671d0 Use Term in ProjectionPredicate
ProjectionPredicate should be able to handle both associated types and consts so this adds the
first step of that. It mainly just pipes types all the way down, not entirely sure how to handle
consts, but hopefully that'll come with time.
2022-01-17 17:44:56 +00:00
Cameron Steffen
45db716902 Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
bors
7be8693984 Auto merge of #92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnr
partially revertish `lazily "compute" anon const default substs`

reverts #87280 except for some of the changes around `ty::Unevaluated` having a visitor and a generic for promoted
why revert: <https://github.com/rust-lang/rust/pull/92805#issuecomment-1010736049>

r? `@lcnr`
2022-01-16 11:19:21 +00:00
Camille GILLOT
60064726ae Return a LocalDefId in get_parent_item. 2022-01-15 21:26:20 +01:00
Ellen
dec8ed438c attempt to re-add ty::Unevaluated visitor and friends 2022-01-15 01:16:55 +00:00
Ellen
71bbb603f4 initial revert 2022-01-15 01:16:55 +00:00
Lamb
1b2c64d223 fix: set struct/union/enum fields/variants as reachable when item is 2022-01-14 02:59:16 +00:00
Aaron Hill
450ef8613c
Store a Symbol instead of an Ident in VariantDef/FieldDef
The field is also renamed from `ident` to `name. In most cases,
we don't actually need the `Span`. A new `ident` method is added
to `VariantDef` and `FieldDef`, which constructs the full `Ident`
using `tcx.def_ident_span()`. This method is used in the cases
where we actually need an `Ident`.

This makes incremental compilation properly track changes
to the `Span`, without all of the invalidations caused by storing
a `Span` directly via an `Ident`.
2022-01-11 10:16:22 -05:00
Lamb
3a77bb86ff Compute most of Public/Exported access level in rustc_resolve
Mak DefId to AccessLevel map in resolve for export

hir_id to accesslevel in resolve and applied in privacy
using local def id
removing tracing probes
making function not recursive and adding comments

Move most of Exported/Public res to rustc_resolve

moving public/export res to resolve

fix missing stability attributes in core, std and alloc

move code to access_levels.rs

return for some kinds instead of going through them

Export correctness, macro changes, comments

add comment for import binding

add comment for import binding

renmae to access level visitor, remove comments, move fn as closure, remove new_key

fmt

fix rebase

fix rebase

fmt

fmt

fix: move macro def to rustc_resolve

fix: reachable AccessLevel for enum variants

fmt

fix: missing stability attributes for other architectures

allow unreachable pub in rustfmt

fix: missing impl access level + renaming export to reexport

Missing impl access level was found thanks to a test in clippy
2022-01-09 21:33:14 +00:00
Vadim Petrochenkov
4b03fd910c rustc_middle: Rename Export to ModChild and add some comments
Also rename `module_exports`/`export_map` to `module_reexports`/`reexport_map` for clarity.
2022-01-09 09:22:07 +08:00
Matthias Krüger
b57a6b38c5
Rollup merge of #90586 - jswrenn:relax-privacy-lints, r=petrochenkov
Relax priv-in-pub lint on generic bounds and where clauses of trait impls.

The priv-in-pub lint is a legacy mechanism of the compiler, supplanted by a reachability-based [type privacy](https://github.com/rust-lang/rfcs/blob/master/text/2145-type-privacy.md) analysis. This PR does **not** relax type privacy; it only relaxes the lint (as proposed by the type privacy RFC) in the case of trait impls.

## Current Behavior
On public trait impls, it's currently an **error** to have a `where` bound constraining a private type with a trait:
```rust
pub trait Trait {}
pub struct Type {}

struct Priv {}
impl Trait for Priv {}

impl Trait for Type
where
    Priv: Trait // ERROR
{}
```

...and it's a **warning** to have have a public type constrained by a private trait:
```rust
pub trait Trait {}
pub struct Type {}

pub struct Pub {}
trait Priv {}
impl Priv for Pub {}

impl Trait for Type
where
    Pub: Priv // WARNING
{}
```

This lint applies to `where` clauses in other contexts, too; e.g. on free functions:
```rust
struct Priv<T>(T);
pub trait Pub {}
impl<T: Pub> Pub for Priv<T> {}

pub fn function<T>()
where
    Priv<T>: Pub // WARNING
{}
```

**These constraints could be relaxed without issue.**

## New Behavior
This lint is relaxed for `where` clauses on trait impls, such that it's okay to have a `where` bound constraining a private type with a trait:
```rust
pub trait Trait {}
pub struct Type {}

struct Priv {}
impl Trait for Priv {}

impl Trait for Type
where
    Priv: Trait // OK
{}
```

...and it's okay to have a public type constrained by a private trait:
```rust
pub trait Trait {}
pub struct Type {}

pub struct Pub {}
trait Priv {}
impl Priv for Pub {}

impl Trait for Type
where
    Pub: Priv // OK
{}
```

## Rationale
While the priv-in-pub lint is not essential for soundness, it *can* help programmers avoid pitfalls that would make their libraries difficult to use by others. For instance, such a lint *is* useful for free functions; e.g. if a downstream crate tries to call the `function` in the previous snippet in a generic context:
```rust
fn callsite<T>()
where
    Priv<T>: Pub // ERROR: omitting this bound is a compile error, but including it is too
{
    function::<T>()
}
```
...it cannot do so without repeating `function`'s `where` bound, which we cannot do because `Priv` is out-of-scope. A lint for this case is arguably helpful.

However, this same reasoning **doesn't** hold for trait impls. To call an unconstrained method on a public trait impl with private bounds, you don't need to forward those private bounds, you can forward the public trait:
```rust
mod upstream {
    pub trait Trait {
        fn method(&self) {}
    }
    pub struct Type<T>(T);

    pub struct Pub<T>(T);
    trait Priv {}
    impl<T: Priv> Priv for Pub<T> {}

    impl<T> Trait for Type<T>
    where
        Pub<T>: Priv // WARNING
    {}
}

mod downstream {
    use super::upstream::*;

    fn function<T>(value: Type<T>)
    where
        Type<T>: Trait // <- no private deets!
    {
        value.method();
    }
}
```

**This PR only eliminates the lint on trait impls.** It leaves it intact for all other contexts, including trait definitions, inherent impls, and function definitions. It doesn't need to exist in those cases either, but I figured I'd first target a case where it's mostly pointless.

## Other Notes
- See discussion [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/relax.20priv-in-pub.20lint.20for.20trait.20impl.20.60where.60.20bounds/near/222458397).
- This PR effectively reverts #79291.
2021-12-27 21:42:25 +01:00
Jack Wrenn
ebef8a8cee relax priv-in-pub lint on generic bounds and where clauses in trait impls 2021-12-27 00:22:09 +00:00
LegionMammal978
29c56fef27 Remove in_band_lifetimes from rustc_privacy
See #91867 for more information.
2021-12-14 12:38:06 -05:00
Camille GILLOT
5fb4648757 Take a LocalDefId in expect_*item. 2021-11-28 21:09:45 +01:00
inquisitivecrystal
9a987b0466 Add ty::Visibility::is_public() 2021-11-09 18:35:00 -08:00
Gary Guo
02c1774cd3 Give inline const separate DefKind 2021-11-07 03:59:06 +00:00
Mark Rousskov
3215eeb99f
Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
Matthias Krüger
87822b27ee
Rollup merge of #89558 - lcnr:query-stable-lint, r=estebank
Add rustc lint, warning when iterating over hashmaps

r? rust-lang/wg-incr-comp
2021-10-24 15:48:42 +02:00
bors
aa5740c715 Auto merge of #90104 - spastorino:coherence-for-negative-trait, r=nikomatsakis
Implement coherence checks for negative trait impls

The main purpose of this PR is to be able to [move Error trait to core](https://github.com/rust-lang/project-error-handling/issues/3).

This feature is necessary to handle the following from impl on box.

```rust
impl From<&str> for Box<dyn Error> { ... }
```

Without having negative traits affect coherence moving the error trait into `core` and moving that `From` impl to `alloc` will cause the from impl to no longer compiler because of a potential future incompatibility. The compiler indicates that `&str` _could_ introduce an `Error` impl in the future, and thus prevents the `From` impl in `alloc` that would cause overlap with `From<E: Error> for Box<dyn Error>`. Adding `impl !Error for &str {}` with the negative trait coherence feature will disable this error by encoding a stability guarantee that `&str` will never implement `Error`, making the `From` impl compile.

We would have this in `alloc`:

```rust
impl From<&str> for Box<dyn Error> {} // A
impl<E> From<E> for Box<dyn Error> where E: Error {} // B
```

and this in `core`:

```rust
trait Error {}
impl !Error for &str {}
```

r? `@nikomatsakis`

This PR was built on top of `@yaahc` PR #85764.

Language team proposal: to https://github.com/rust-lang/lang-team/issues/96
2021-10-23 12:51:15 +00:00