Commit Graph

216 Commits

Author SHA1 Message Date
Mazdak Farrokhzad 2c3e5d3de0 - remove syntax::{span_warn!, span_err!, span_fatal!. struct_err!}
- remove syntax::{help!, span_help!, span_note!}
- remove unused syntax::{struct_span_fatal, struct_span_err_or_warn!, span_err_or_warn!}
- lintify check_for_bindings_named_same_as_variants + conflicting_repr_hints
- inline syntax::{struct_span_warn!, diagnostic_used!}
- stringify_error_code! -> error_code! & use it more.
- find_plugin_registrar: de-fatalize an error
- de-fatalize metadata errors
- move type_error_struct! to rustc_typeck
- struct_span_err! -> rustc_errors
2020-01-08 04:25:33 +01:00
Mazdak Farrokhzad ebfd8673a7 Remove rustc_hir reexports in rustc::hir. 2020-01-05 12:49:22 +01:00
Mazdak Farrokhzad 62ac10ffde simplify reexports in rustc::hir 2020-01-05 12:47:11 +01:00
Vadim Petrochenkov 70f1d57048 Rename `syntax_pos` to `rustc_span` in source code 2020-01-01 09:15:18 +03:00
bors 214548b8af Auto merge of #67631 - oli-obk:polymorphic_promotion, r=wesleywiser
Work around a resolve bug in const prop

r? @wesleywiser @anp

This isn't exposed right now, but further changes to rustc may start causing bugs without this.
2019-12-30 02:05:24 +00:00
Camille GILLOT 36f95ab3fa Fallout in other crates. 2019-12-27 19:20:28 +01:00
Wesley Wiser 25a8b5d58e Fix `Instance::resolve()` incorrectly returning specialized instances
We only want to return specializations when `Reveal::All` is passed, not
when `Reveal::UserFacing` is. Resolving this fixes several issues with
the `ConstProp`, `SimplifyBranches`, and `Inline` MIR optimization
passes.

Fixes #66901
2019-12-27 13:04:32 -05:00
bors 8f5f8f916f Auto merge of #67192 - oli-obk:const_zst_addr, r=RalfJung,varkor
Various const eval and pattern matching ICE fixes

r? @RalfJung
cc @spastorino

This PR does not change existing behaviour anymore and just fixes a bunch of ICEs reachable from user code (sometimes even on stable via obscure union transmutes).
2019-12-27 07:38:52 +00:00
Camille GILLOT 8284035372 Fallout in other crates. 2019-12-26 23:38:46 +01:00
Oliver Scherer 1e40681f50 Don't ICE on the use of integer addresses for ZST constants in pattern matching 2019-12-26 22:46:22 +01:00
Mark Rousskov a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Mazdak Farrokhzad 97bee3a793
Rollup merge of #66877 - skinny121:const-eval-entry-points, r=oli-obk
Add simpler entry points to const eval for common usages.

I found the `tcx.const_eval` API to be complex/awkward to work with, because of the inherent complexity from all of the different situations it is called from. Though it mainly used in one of the following ways:
- Evaluates the value of a constant without any substitutions, e.g. evaluating a static, discriminant, etc.
- Evaluates the value of a resolved instance of a constant. this happens when evaluating unevaluated constants or normalising trait constants.
- Evaluates a promoted constant.

This PR adds three new functions `const_eval_mono`, `const_eval_resolve`, and `const_eval_promoted` to `TyCtxt`, which each cater to one of the three ways `tcx.const_eval`
 is normally used.
2019-12-22 19:46:07 +01:00
Mazdak Farrokhzad 877dc9daa8
Rollup merge of #67439 - Centril:clean-hair-slice, r=matthewjasper
Cleanup `lower_pattern_unadjusted` & Improve slice pat typeck

Following up on https://github.com/rust-lang/rust/pull/67318, in this PR, the HAIR lowering of patterns (`lower_pattern_unadjusted`) is cleaned up with a focus on slice patterns (in particular, some dead code is removed). Moreover, `check_pat_slice` is refactored some more.

r? @matthewjasper
2019-12-22 02:40:03 +01:00
Ben Lewis c010d843aa Add simpler entry points to const eval for common usages. 2019-12-22 11:15:16 +13:00
Mazdak Farrokhzad a7aec3f207 1. ast::Mutability::{Mutable -> Mut, Immutable -> Not}.
2. mir::Mutability -> ast::Mutability.
2019-12-20 22:22:44 +01:00
Mazdak Farrokhzad 6286a1d7eb `slice_or_array_pattern`: remove dead code.
After #62550, it is no longer possible for `slice`
to be other than `None | Some(Binding(..) | Wild)`.
In particular, `lower_pat_slice` may never generate
`Some(Array(..) | Slice(..))` and so there is nothing
to flatten into `slice`.
2019-12-19 23:31:27 +01:00
Mazdak Farrokhzad cc3160bbbf `lower_pattern_unadjusted`: simplify `Or(..)` branch. 2019-12-19 23:14:52 +01:00
Mazdak Farrokhzad d63c324a15 `lower_pattern_unadjusted`: extract `lower_tuple_subpats`. 2019-12-19 23:09:33 +01:00
Mazdak Farrokhzad eb020bc245 `lower_pattern_unadjusted`: simplify `Binding(..)` branch.
Avoid calling `.node_type(...)` again.
2019-12-19 22:58:20 +01:00
Mazdak Farrokhzad be6381e9e0 `lower_pattern_unadjusted`: cleanup `Tuple(..)` branch. 2019-12-19 22:51:32 +01:00
Mazdak Farrokhzad 3b0af1d87d `lower_pattern_unadjusted`: cleanup `Slice(..)` branch. 2019-12-19 22:45:42 +01:00
Mazdak Farrokhzad 2a9f1f8c02 `lower_pattern_unadjusted`: extract common `ty::Error` code. 2019-12-19 22:41:34 +01:00
Mazdak Farrokhzad 13b71018c1 `lower_pattern_unadjusted`: remove dead code.
The code is dead because `check_pat_slice` will never have
`expected = ty::Ref(...)` due to default-binding-modes
(see `is_non_ref_pat`, `peel_off_references`).

Moreover, if the type is not `ty::Array(_) | ty::Slice(_)`
then `check_pat_slice` enters an error branch.
2019-12-19 19:43:07 +01:00
Mazdak Farrokhzad 3a93a0e860 HAIR lowering: improve code quality for slices 2019-12-19 18:19:14 +01:00
varkor 9f1269f23c Rename to `then_some` and `then` 2019-12-06 12:24:54 +00:00
varkor e3a8ea4e18 Use `to_option` in various places 2019-12-06 12:23:23 +00:00
Guillaume Gomez 798e389e57 Update to use new librustc_error_codes library 2019-11-14 13:05:42 +01:00
Camille GILLOT 7378c25f25 Rename in librustc_mir. 2019-11-12 20:50:45 +01:00
bors e3d998492a Auto merge of #66129 - Nadrieril:refactor-slice-pat-usefulness, r=varkor
Refactor slice pattern usefulness checking

As a follow up to https://github.com/rust-lang/rust/pull/65874, this PR changes how variable-length slice patterns are handled in usefulness checking. The objectives are: cleaning up that code to make it easier to understand, and paving the way to handling fixed-length slices more cleverly too, for https://github.com/rust-lang/rust/issues/53820.

Before this, variable-length slice patterns were eagerly expanded into a union of fixed-length slices. Now they have their own special constructor, which allows expanding them a bit more lazily.
As a nice side-effect, this improves diagnostics.

This PR shows a slight performance improvement, mostly due to 149792b608. This will probably have to be reverted in some way when we implement or-patterns.
2019-11-12 04:44:30 +00:00
Camille GILLOT ed640c6a27 Merge hir::Mutability into ast::Mutability. 2019-11-10 12:21:05 +01:00
Esteban Küber a12a32ab65 review comments 2019-11-06 10:04:23 -08:00
Nadrieril 7514c48917 Factor out constructing a new wildcard pattern 2019-11-06 15:09:03 +00:00
Felix S. Klock II 98f5b11b6b Migrate from `#[structural_match]` attribute a lang-item trait.
(Or more precisely, a pair of such traits: one for `derive(PartialEq)` and one
for `derive(Eq)`.)

((The addition of the second marker trait, `StructuralEq`, is largely a hack to
work-around `fn (&T)` not implementing `PartialEq` and `Eq`; see also issue
rust-lang/rust#46989; otherwise I would just check if `Eq` is implemented.))

Note: this does not use trait fulfillment error-reporting machinery; it just
uses the trait system to determine if the ADT was tagged or not. (Nonetheless, I
have kept an `on_unimplemented` message on the new trait for structural_match
check, even though it is currently not used.)

Note also: this does *not* resolve the ICE from rust-lang/rust#65466, as noted
in a comment added in this commit. Further work is necessary to resolve that and
other problems with the structural match checking, especially to do so without
breaking stable code (adapted from test fn-ptr-is-structurally-matchable.rs):

```rust
fn r_sm_to(_: &SM) {}

fn main() {
    const CFN6: Wrap<fn(&SM)> = Wrap(r_sm_to);
    let input: Wrap<fn(&SM)> = Wrap(r_sm_to);
    match Wrap(input) {
        Wrap(CFN6) => {}
        Wrap(_) => {}
    };
}
```

where we would hit a problem with the strategy of unconditionally checking for
`PartialEq` because the type `for <'a> fn(&'a SM)` does not currently even
*implement* `PartialEq`.

----

added review feedback:
* use an or-pattern
* eschew `return` when tail position will do.
* don't need fresh_expansion; just add `structural_match` to appropriate `allow_internal_unstable` attributes.

also fixed example in doc comment so that it actually compiles.
2019-10-25 14:52:07 +02:00
Felix S. Klock II 620083ad16 refactoring: move const_to_pat code into its own submodule. 2019-10-25 11:39:12 +02:00
varkor 133cd2cfaf Search for generic parameters when finding non-`structural_match` types 2019-10-22 12:26:32 +01:00
varkor 600607f45a Move `search_for_adt_without_structural_match` to `ty/mod` 2019-10-22 12:26:32 +01:00
Yuki Okushi 2518bbd5a3
Rollup merge of #65460 - sinkuu:contains_insert, r=varkor
Clean up `contains()` `insert()` chains on HashSet

They can be merged to a single `insert()` call, which may avoid double-hashing/lookup of the value.
2019-10-21 03:10:54 +09:00
Esteban Küber 1ec60730fe Deduplicate code for formatting `RangeEnd` 2019-10-16 11:57:19 -07:00
Shotaro Yamada d5ffd36a6c Change HashSet element type to `DefId` 2019-10-16 13:46:44 +09:00
bors 22bc9e1d9c Auto merge of #64778 - csmoe:index, r=eddyb
Introduce librustc_index crate

Closes #50592
2019-09-30 13:33:15 +00:00
csmoe 64f61c7888 remove indexed_vec re-export from rustc_data_structures 2019-09-29 16:48:31 +00:00
ben c94fea092e Move `get_slice_bytes` to `rustc::mir::interpret` so it can be reused. 2019-09-28 14:35:04 +12:00
varkor ff4ed8c2de Rename `hair::Pattern` to `hair::Pat` 2019-09-26 18:51:59 +01:00
varkor 79ff44873d Rename `PatternTypeProjection` to `PatTyProj` 2019-09-26 18:45:50 +01:00
varkor d556193646 Rename `PatternContext` to `PatCtxt` 2019-09-26 18:45:10 +01:00
varkor 5fbc211fbd Rename `hair::PatternRange` to `hair::PatRange` 2019-09-26 18:43:36 +01:00
varkor ff59620734 Rename `hair::PatternKind` to `hair::PatKind` 2019-09-26 18:42:24 +01:00
varkor 1ae3c36800 Rename `hair::FieldPattern` to `hair::FieldPat` 2019-09-26 18:29:53 +01:00
varkor 8bd0382134 Rename `Pat.node` to `Pat.kind` 2019-09-26 18:21:09 +01:00
varkor 95f6d72a60 Rename `Expr.node` to `Expr.kind`
For both `ast::Expr` and `hir::Expr`.
2019-09-26 18:21:09 +01:00