Commit Graph

636 Commits

Author SHA1 Message Date
Bastian Kauschke 236689d6eb split SyntheticTyParamKind 2020-10-07 10:19:04 +02:00
Matthew Jasper 022c148fcd Fix tests from rebase 2020-10-06 11:19:33 +01:00
Matthew Jasper 1db284ecb0 Avoid creating useless projection predicate 2020-10-06 11:19:33 +01:00
Matthew Jasper 27534b3932 Fix rebase 2020-10-06 11:19:33 +01:00
Matthew Jasper d08ab945de Fix rebase 2020-10-06 11:19:32 +01:00
Matthew Jasper 0dfa6ff3be Avoid cycles from projection bounds
Only check the own predicates of associated types when confirming
projection candidates.
Also consider implied bounds when comparing trait and impl methods.
2020-10-06 11:19:32 +01:00
Matthew Jasper bc08b791bc Fix bugs in evaluating WellFormed predicates
- List the nestsed obligations in an order that works with the
  single pass used by evaluation
- Propagate recursion depth correctly
2020-10-06 11:19:31 +01:00
Matthew Jasper 582ccec1c5 Remove predicates on associated types from traits
These need to only be bounds to avoid cycle errors in trait checking.
2020-10-06 11:19:31 +01:00
Matthew Jasper 8787090964 Address review comments 2020-10-06 11:19:31 +01:00
Matthew Jasper 042464f75a Fix tests and bootstrap 2020-10-06 11:19:30 +01:00
Matthew Jasper 5b279c8016 Check opaque types satisfy their bounds 2020-10-06 11:19:30 +01:00
Matthew Jasper b3057f4d5f Check projections are well-formed when using projection candidates 2020-10-06 11:19:29 +01:00
Matthew Jasper f958e6c246 Separate bounds and predicates for associated/opaque types 2020-10-06 11:19:29 +01:00
Matthew Jasper d297147e62 Split bounds from predicates 2020-10-06 11:19:22 +01:00
Matthew Jasper a7ead3bd53 Move item_bounds to typeck::collect 2020-10-06 11:18:45 +01:00
Matthew Jasper 0eb87ed55f Rename projection_predicates to item_bounds 2020-10-06 11:18:45 +01:00
Yuki Okushi 2970af8e28
Rollup merge of #77559 - camelid:fix-rustdoc-warnings-invalid-rust-syntax, r=lcnr
Fix rustdoc warnings about invalid Rust syntax
2020-10-06 16:26:09 +09:00
Camelid c877ff3664 Fix rustdoc warnings about invalid Rust syntax 2020-10-04 19:35:44 -07:00
Dylan DPC 9dbc9ed870
Rollup merge of #77514 - scottmcm:less-once-chain-once, r=estebank
Replace some once(x).chain(once(y)) with [x, y] IntoIter

Now that we have by-value array iterators that are [already used](25c8c53dd9/compiler/rustc_hir/src/def.rs (L305-L307))...

For example,
```diff
-        once(self.type_ns).chain(once(self.value_ns)).chain(once(self.macro_ns)).filter_map(|it| it)
+        IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it)
```
2020-10-05 02:29:42 +02:00
Scott McMurray d74b8e0505 Replace some once(x).chain(once(y)) with [x, y] IntoIter
Now that we have by-value array iterators...
2020-10-03 16:51:43 -07:00
varkor 96eb68b121 Add `FIXME` for const generic defaults 2020-10-03 14:28:55 +01:00
varkor 0801263279 Fix missing diagnostic span for `impl Trait` with const generics 2020-10-02 01:39:04 +01:00
bors ef663a8a48 Auto merge of #77372 - jonas-schievink:rollup-e5bdzga, r=jonas-schievink
Rollup of 12 pull requests

Successful merges:

 - #77037 (more tiny clippy cleanups)
 - #77233 (BTreeMap: keep an eye out on the size of the main components)
 - #77280 (Ensure that all LLVM components requested by tests are available on CI)
 - #77284 (library: Forward compiler-builtins "mem" feature)
 - #77296 (liveness: Use Option::None to represent absent live nodes)
 - #77322 (Add unstable book docs for `-Zunsound-mir-opts`)
 - #77328 (Use `rtassert!` instead of `assert!` from the child process after fork() in std::sys::unix::process::Command::spawn())
 - #77331 (Add test for async/await combined with const-generics.)
 - #77338 (Fix typo in alloc vec comment)
 - #77340 (Alloc vec use imported path)
 - #77345 (Add test for issue #74761)
 - #77348 (Update books)

Failed merges:

r? `@ghost`
2020-09-30 20:49:27 +00:00
Jonas Schievink 248d6bf1e2
Rollup merge of #77037 - matthiaskrgr:cl42ppy, r=Dylan-DPC
more tiny clippy cleanups

commits stand alone and can be reviewed one by one
2020-09-30 20:56:05 +02:00
Hugues de Valon 2588287def Add more tests and check for ABI
Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
2020-09-30 18:10:17 +01:00
Hugues de Valon 1aaafac6ff Add support for cmse_nonsecure_entry attribute
This patch adds support for the LLVM cmse_nonsecure_entry attribute.
This is a target-dependent attribute that only has sense for the
thumbv8m Rust targets.
You can find more information about this attribute here:
https://developer.arm.com/documentation/ecm0359818/latest/

Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
2020-09-30 15:48:59 +01:00
Camelid 8a6831a7fd Say "doesn't" instead of "wouldn't" in convert message 2020-09-29 19:27:58 -07:00
Camelid 094f14c554 Add article after "to"
Also added missing backtick in "you can cast" message.
2020-09-29 10:30:42 -07:00
bors 4d52dc4790 Auto merge of #76754 - varkor:diagnostic-cleanup-ii, r=ecstatic-morse
Clean up diagnostics for arithmetic operation errors

Plus a small tweak to a range pattern error message.
2020-09-29 14:28:58 +00:00
Ralf Jung 88ae20d8aa
Rollup merge of #76711 - davidtwco:issue-51154-param-closure, r=estebank
diag: improve closure/generic parameter mismatch

Fixes #51154.

This PR improves the diagnostic when a type parameter is expected and a closure is found, noting that each closure has a distinct type and therefore could not always match the caller-chosen type of the parameter.

r? @estebank
2020-09-28 18:39:42 +02:00
bors 535d27ac9a Auto merge of #77236 - matthewjasper:defer-typeof-impl-trait, r=davidtwco
Compute underlying type of impl trait types later in compilation

Also change a `bug!` to `delay_span_bug`
Closes #74018
2020-09-28 12:47:23 +00:00
Camelid 549f861f7d Use correct article in help message for conversion or cast
Before it always used `an`; now it uses the correct article for the type.
2020-09-27 13:51:08 -07:00
bors d902752866 Auto merge of #77118 - exrook:stability-generic-parameters-2, r=varkor
Stability annotations on generic parameters (take 2.5)

Rebase of #72314 + more tests

Implements rust-lang/wg-allocators#2.
2020-09-27 12:51:21 +00:00
Matthew Jasper 3a81adeca2 Call `type_of` for opaque types later in compilation
This ensures that various wf checks have already been done before we
typeck item bodies.
2020-09-26 17:56:03 +01:00
varkor 94c789b275 `char` not char 2020-09-26 13:34:49 +01:00
Ralf Jung 9e02642fb3
Rollup merge of #77211 - est31:remove_unused_allow, r=oli-obk
Remove unused #[allow(...)] statements from compiler/
2020-09-26 12:58:34 +02:00
Ralf Jung ac8169dc10
Rollup merge of #77093 - lcnr:const-generics-infer-warning, r=varkor
merge `need_type_info_err(_const)`

I hoped that this would automatically solve #76737 but it doesn't quite seem like it

fixes #77092

r? @varkor
2020-09-26 12:58:17 +02:00
Bastian Kauschke 32195ac8f4 rename functions 2020-09-26 10:28:15 +02:00
est31 12187b7f86 Remove unused #[allow(...)] statements from compiler/ 2020-09-26 01:25:55 +02:00
Jonas Schievink e739468f97
Rollup merge of #77155 - lcnr:ImplSource, r=ecstatic-morse
remove enum name from ImplSource variants

This is quite a lot cleaner in my opinion.
2020-09-25 19:42:48 +02:00
Jonas Schievink 1b8c939a8d
Rollup merge of #76973 - lzutao:unstably-const-assume, r=oli-obk
Unstably allow assume intrinsic in const contexts

Not sure much about this usage because there are concerns
about [blocking  optimization][1] and [slowing down LLVM][2] when using `assme` intrinsic
in inline functions.
But since Oli suggested in https://github.com/rust-lang/rust/issues/76960#issuecomment-695772221,
here we are.

[1]: https://github.com/rust-lang/rust/pull/54995#issuecomment-429302709
[2]: https://github.com/rust-lang/rust/issues/49572#issuecomment-589615423
2020-09-25 19:42:29 +02:00
Jonas Schievink 6f3da3d53f
Rollup merge of #77121 - duckymirror:html-root-url, r=jyn514
Updated html_root_url for compiler crates

Closes #77103

r? @jyn514
2020-09-25 02:29:45 +02:00
Bastian Kauschke 1857184cd1 remove enum name from ImplSource variants 2020-09-24 19:22:36 +02:00
Matthias Krüger d7a5c574b1 use std::mem::take(x) instead of std::mem::replace(x, Default::default()) (clippy::mem_replace_with_default) 2020-09-24 13:38:08 +02:00
Bastian Kauschke 3f9015b22d visit impl self ty + trait 2020-09-24 09:04:26 +02:00
Bastian Kauschke f8d3f401df walk hir to get const evaluatable predicates 2020-09-24 09:03:50 +02:00
Bastian Kauschke ac1d0d8b28 fmt, use IndexSet directly instead of UniquePredicates 2020-09-24 09:03:14 +02:00
Bastian Kauschke e1f408e6c8 const_evaluatable_checked: collect predicates from fn_sig 2020-09-24 09:03:07 +02:00
Erik Hofmayer 138a2e5eaa /nightly/nightly-rustc 2020-09-23 21:51:56 +02:00
Erik Hofmayer dd66ea2d3d Updated html_root_url for compiler crates 2020-09-23 21:14:43 +02:00
Dylan DPC bcdbe79f0c
Rollup merge of #76994 - yuk1ty:fix-small-typo, r=estebank
fix small typo in docs and comments

Fixed `the the` to `the`, as far as I found.
2020-09-23 14:54:07 +02:00
Bastian Kauschke 45d92b43e3 merge `need_type_info_err(_const)` 2020-09-23 09:24:58 +02:00
Avi Dessauer 9eb595705e Update src/librustc_typeck/astconv.rs
Co-authored-by: varkor <github@varkor.com>
2020-09-22 21:55:32 -04:00
Avi Dessauer 19e90843a4 Add documentation 2020-09-22 21:55:23 -04:00
Avi Dessauer 3947591ee8 Remove now unneeded check_stability argument 2020-09-22 21:54:16 -04:00
Avi Dessauer a7a2086053 Stability annotations on generic trait parameters 2020-09-22 21:53:48 -04:00
bors c113030f6b Auto merge of #76906 - Nicholas-Baron:shorten_typeck_check, r=oli-obk
Split rustc_typeck::check into separate files

Contributing to #60302.
2020-09-22 08:11:07 +00:00
Nicholas-Baron ccd218d04c Added back the '// ignore-file-length' with an explanation 2020-09-21 09:16:55 -07:00
Ralf Jung 982c4a9c25
Rollup merge of #76835 - matthiaskrgr:replace_prefix, r=lcnr
make replace_prefix only take &str as arguments

included the clippy::manual strip commit to not run into merge conflicts later.

r? @lcnr
2020-09-21 15:30:39 +02:00
yuk1ty 16047d46a1 fix typo in docs and comments 2020-09-21 12:14:28 +09:00
Nicholas-Baron 99e2e7075c Moved all functions prefixed with 'check' to a separate file 2020-09-20 19:00:31 -07:00
Nicholas-Baron f896ddfc73 Moved the Expectation enum to its own file 2020-09-20 18:58:32 -07:00
Nicholas-Baron 428a8c6eae Moved the Diverges struct to its own file 2020-09-20 18:58:32 -07:00
Nicholas-Baron b1e9379679 Formatted use statements for fewer lines 2020-09-20 18:58:32 -07:00
Nicholas-Baron 7995d5cda4 Moved Inherited struct to own file 2020-09-20 18:58:30 -07:00
Nicholas-Baron 45fdf97d11 Removed util.rs
Per suggestion of @oli-obk.
This file was rather short and joining it did not cause mod.rs to become
significantly bigger.
2020-09-20 18:56:09 -07:00
Nicholas-Baron c8162c22eb Moved the FnCtxt struct to its own file 2020-09-20 18:56:01 -07:00
Nicholas-Baron c190f66060 Moved GatherLocalsVisitor to its own file 2020-09-20 18:48:31 -07:00
Nicholas-Baron 3e770645aa Moved a struct only need by util into util 2020-09-20 18:48:31 -07:00
Nicholas-Baron 6fd80e35e0 Moved another struct and used pub(super) to be explicit 2020-09-20 18:48:31 -07:00
Nicholas-Baron bfe5bc9cb9 Formatter moved one use statement 2020-09-20 18:48:31 -07:00
Nicholas-Baron 63dbfb3c30 Start of moving some functionality to separate files 2020-09-20 18:48:31 -07:00
bors 0f9f0b384a Auto merge of #76295 - mati865:remove-mmx, r=Amanieu,oli-obk
Remove MMX from Rust

Follow-up to https://github.com/rust-lang/stdarch/pull/890
This removes most of MMX from Rust (tests pass with small changes), keeping stable `is_x86_feature_detected!("mmx")` working.
2020-09-21 00:43:26 +00:00
Ralf Jung fc58224b79
Rollup merge of #76940 - Aaron1011:fix/trait-on-tait, r=oli-obk
Don't allow implementing trait directly on type-alias-impl-trait

This is specifically disallowed by the RFC, but we never added a check
for it.

Fixes #76202
2020-09-20 15:52:09 +02:00
Ralf Jung 8405d50e12
Rollup merge of #76890 - matthiaskrgr:matches_simpl, r=lcnr
use matches!() macro for simple if let conditions
2020-09-20 15:52:01 +02:00
Lzu Tao 3e08354fb0 Correct file path after some restructures in compiler 2020-09-20 13:48:16 +00:00
Mateusz Mikuła 5de2c95e6e Remove MMX from Rust 2020-09-20 15:13:11 +02:00
bors 41507ed0d5 Auto merge of #76964 - RalfJung:rollup-ybn06fs, r=RalfJung
Rollup of 15 pull requests

Successful merges:

 - #76722 (Test and fix Send and Sync traits of BTreeMap artefacts)
 - #76766 (Extract some intrinsics out of rustc_codegen_llvm)
 - #76800 (Don't generate bootstrap usage unless it's needed)
 - #76809 (simplfy condition in ItemLowerer::with_trait_impl_ref())
 - #76815 (Fix wording in mir doc)
 - #76818 (Don't compile regex at every function call.)
 - #76821 (Remove redundant nightly features)
 - #76823 (black_box: silence unused_mut warning when building with cfg(miri))
 - #76825 (use `array_windows` instead of `windows` in the compiler)
 - #76827 (fix array_windows docs)
 - #76828 (use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip))
 - #76840 (Move to intra doc links in core/src/future)
 - #76845 (Use intra docs links in core::{ascii, option, str, pattern, hash::map})
 - #76853 (Use intra-doc links in library/core/src/task/wake.rs)
 - #76871 (support panic=abort in Miri)

Failed merges:

r? `@ghost`
2020-09-20 11:02:36 +00:00
Ralf Jung bfa1904765
Rollup merge of #76828 - matthiaskrgr:clippy_manual_strip, r=lcnr
use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip)
2020-09-20 12:08:29 +02:00
bors 5e449b9adf Auto merge of #74949 - oli-obk:validate_const_eval_raw, r=RalfJung
Validate constants during `const_eval_raw`

This PR implements the groundwork for https://github.com/rust-lang/rust/issues/72396

* constants are now validated during `const_eval_raw`
* to prevent cycle errors, we do not validate references to statics anymore beyond the fact that they are not dangling
* the `const_eval` query ICEs if used on `static` items
* as a side effect promoteds are now evaluated to `ConstValue::Scalar` again (since they are just a reference to the actual promoted allocation in most cases).
2020-09-20 08:58:32 +00:00
Aaron Hill 367efa86d5
Don't allow implementing trait directly on type-alias-impl-trait
This is specifically disallowed by the RFC, but we never added a check
for it.

Fixes #76202
2020-09-19 17:10:54 -04:00
Ralf Jung 5631b5d684
Rollup merge of #76749 - guswynn:hir_ranges, r=estebank
give *even better* suggestion when matching a const range

notice that the err already has "constant defined here"
so this is now *exceedingly clear*

extension to #76222

r? @estebank
2020-09-19 11:47:50 +02:00
Oliver Scherer 2d7ac728e4 Stop using the `const_eval` query for initializers of statics
As a side effect, we now represent most promoteds as `ConstValue::Scalar` again. This is useful because all implict promoteds are just references anyway and most explicit promoteds are numeric arguments to `asm!` or SIMD instructions.
2020-09-19 10:36:36 +02:00
Matthias Krüger 40dddd3305 use matches!() macro for simple if let conditions 2020-09-18 20:28:35 +02:00
Bastian Kauschke 82ebbd7d6b add test for let-bindings 2020-09-18 17:11:34 +02:00
Matthias Krüger 026922ad60 make replace_prefix only take &str as arguments
https://github.com/rust-lang/rust/pull/76828#issuecomment-694078200
2020-09-17 13:12:04 +02:00
Matthias Krüger 012974da7a use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip) 2020-09-17 10:13:16 +02:00
bors 95386b656e Auto merge of #76028 - aticu:improve_e0118, r=estebank,jyn514,GuillaumeGomez
Improve E0118

- Changes the "base type" terminology to "nominal type" (according to the [reference](https://doc.rust-lang.org/stable/reference/items/implementations.html#inherent-implementations)).
- Suggests removing a reference, if one is present on the type.
- Clarify what is meant by a "nominal type".

closes #69392

This is my first not-entirely-trivial PR, so please let me know if I missed anything or if something could be improved. Though I probably won't be able to fix anything in the upcoming week.
2020-09-17 03:56:38 +00:00
Gus Wynn 230355f25f comments and factor to own method 2020-09-16 12:32:10 -07:00
Tyler Mandry a6c4d30c7b
Rollup merge of #76756 - matthiaskrgr:cl123ppy, r=Dylan-DPC
fix a couple of stylistic clippy warnings

namely:

clippy::redundant_pattern_matching
clippy::redundant_pattern
clippy::search_is_some
clippy::filter_next
clippy::into_iter_on_ref
clippy::clone_on_copy
clippy::needless_return
2020-09-16 12:24:17 -07:00
Gus Wynn 1d93048324 give better suggestion when matching a const range 2020-09-16 10:13:11 -07:00
Dylan DPC fa4cfeb597
Rollup merge of #75304 - Aaron1011:feature/diag-deref-move-out, r=estebank
Note when a a move/borrow error is caused by a deref coercion

Fixes #73268

When a deref coercion occurs, we may end up with a move error if the
base value has been partially moved out of. However, we do not indicate
anywhere that a deref coercion is occuring, resulting in an error
message with a confusing span.

This PR adds an explicit note to move errors when a deref coercion is
involved. We mention the name of the type that the deref-coercion
resolved to, as well as the `Deref::Target` associated type being used.
2020-09-16 01:30:32 +02:00
Matthias Krüger 73d4171ea6 fix a couple of stylistic clippy warnings
namely:

clippy::redundant_pattern_matching
clippy::redundant_pattern
clippy::search_is_some
clippy::filter_next
clippy::into_iter_on_ref
clippy::clone_on_copy
clippy::needless_return
2020-09-15 22:44:54 +02:00
bors 255ceeb5ff Auto merge of #76612 - estebank:pat-missing-fields-suggestion, r=davidtwco
Provide suggestion for missing fields in patterns
2020-09-15 00:17:13 +00:00
bors 9b4154193e Auto merge of #76541 - matthiaskrgr:unstable_sort, r=davidtwco
use sort_unstable to sort primitive types

It's not important to retain original order if we have &[1, 1, 2, 3] for example.

clippy::stable_sort_primitive
2020-09-14 21:43:17 +00:00
bors 41dc3942eb Auto merge of #75608 - estebank:suggest-boxed-match-exprs, r=lcnr,varkor
More structured suggestions for boxed trait objects instead of impl Trait on non-coerceable tail expressions

When encountering a `match` or `if` as a tail expression where the
different arms do not have the same type *and* the return type of that
`fn` is an `impl Trait`, check whether those arms can implement `Trait`
and if so, suggest using boxed trait objects.

Use structured suggestion for `impl T` to `Box<dyn T>`.

Fix https://github.com/rust-lang/rust/issues/69107
2020-09-14 19:57:57 +00:00
Esteban Küber c6f2ddf1cb Fix rebase and add comments 2020-09-14 12:51:25 -07:00
David Wood 01f65afa4a
diag: improve closure/generic parameter mismatch
This commit improves the diagnostic when a type parameter is expected
and a closure is found, noting that each closure has a distinct type and
therefore could not always match the caller-chosen type of the
parameter.

Signed-off-by: David Wood <david@davidtw.co>
2020-09-14 15:21:38 +01:00
Bastian Kauschke c552717e9d review, improve note span 2020-09-13 22:53:51 +02:00
Bastian Kauschke e5b82a56c5 allow concrete self types in consts 2020-09-13 22:53:51 +02:00
bors 7402a39447 Auto merge of #76244 - vandenheuvel:remove__paramenv__def_id, r=nikomatsakis
Removing the `def_id` field from hot `ParamEnv` to make it smaller

This PR addresses https://github.com/rust-lang/rust/issues/74865.
2020-09-13 16:28:22 +00:00
bors dbb73f8f79 Auto merge of #73461 - calebzulawski:validate-attribute-placement, r=matthewjasper
Validate built-in attribute placement

Closes #54584, closes #47725, closes #54044.

I've changed silently ignoring some incorrectly placed attributes to errors.  I'm not sure what the policy is since this can theoretically break code (should they be warnings instead? does it warrant a crater run?).
2020-09-12 22:04:37 +00:00
Esteban Küber dc53cfea7e Add test cases and address review comments 2020-09-11 17:05:18 -07:00
Esteban Küber 5d2a935e6c Make suggestion more complete 2020-09-11 17:05:18 -07:00
Esteban Küber ff297fafbf Make suggestion have a more targetted underline 2020-09-11 17:05:18 -07:00
Esteban Küber fd9133b9c3 Suggest boxed trait objects in tail `match` and `if` expressions
When encountering a `match` or `if` as a tail expression where the
different arms do not have the same type *and* the return type of that
`fn` is an `impl Trait`, check whether those arms can implement `Trait`
and if so, suggest using boxed trait objects.
2020-09-11 17:05:18 -07:00
Esteban Küber c8ee33714b Use structured suggestion for `impl T` to `Box<dyn T>` 2020-09-11 17:05:18 -07:00
Gus Wynn 5e126c944b better diag when const ranges are used in patterns 2020-09-11 15:02:15 -07:00
Esteban Küber 21f8326cec Provide suggestion for missing fields in patterns 2020-09-11 13:47:33 -07:00
aticu 1c1bb1309f Improve E0118 description 2020-09-11 19:48:43 +02:00
bors a7425476e8 Auto merge of #75611 - JulianKnodt:cg_enum_err, r=lcnr
Add help note when using type in place of const

This adds a small help note when it might be possible that wrapping a parameter in braces might resolve the issue of having a type where a const was expected.

Currently, I am displaying the `HirId`, and I'm not particularly sure where to get the currently displayed path(?).

r? `@lcnr`
2020-09-11 08:40:07 +00:00
Aaron Hill d18b4bb7a7
Note when a a move/borrow error is caused by a deref coercion
Fixes #73268

When a deref coercion occurs, we may end up with a move error if the
base value has been partially moved out of. However, we do not indicate
anywhere that a deref coercion is occuring, resulting in an error
message with a confusing span.

This PR adds an explicit note to move errors when a deref coercion is
involved. We mention the name of the type that the deref-coercion
resolved to, as well as the `Deref::Target` associated type being used.
2020-09-10 20:56:20 -04:00
Tyler Mandry ac85a4d71e
Rollup merge of #76559 - lcnr:const-evaluatable, r=oli-obk
add the `const_evaluatable_checked` feature

Implements a rather small subset of https://github.com/rust-lang/compiler-team/issues/340

Unlike the MCP, this does not try to compare different constant, but instead only adds the constants found in where clauses
to the predicates of a function. This PR adds the feature gate `const_evaluatable_checked`, without which nothing should change.

r? @oli-obk @eddyb
2020-09-10 12:20:07 -07:00
David Wood 409c141973
typeck/pat: inaccessible private fields
This commit adjusts the missing field diagnostic logic for struct
patterns in typeck to improve the diagnostic when the missing fields are
inaccessible.

Signed-off-by: David Wood <david@davidtw.co>
2020-09-10 18:52:00 +01:00
David Wood c0894e7232
typeck/expr: inaccessible private fields
This commit adjusts the missing field diagnostic logic for struct
expressions in typeck to improve the diagnostic when the missing
fields are inaccessible.

Signed-off-by: David Wood <david@davidtw.co>
2020-09-10 18:51:56 +01:00
Bastian Kauschke 300b0acb85 fix tidy, small cleanup 2020-09-10 09:48:02 +02:00
Bastian Kauschke 8667f93040 implement `const_evaluatable_checked` feature MVP 2020-09-10 08:52:02 +02:00
Matthias Krüger b4935e0726 use sort_unstable to sort primitive types
It's not important to retain original order if we have &[1, 1, 2, 3] for example.

clippy::stable_sort_primitive
2020-09-10 00:03:58 +02:00
Bram van den Heuvel 7dad29d686 Remove def_id field from ParamEnv 2020-09-09 10:14:31 +02:00
Dylan DPC 1083833b3e
Rollup merge of #76401 - JulianKnodt:i68366, r=lcnr
Add help note to unconstrained const parameter

Resolves #68366, since it is currently intended behaviour.
If demonstrating `T -> U` is injective, there should be an additional word that it is not **yet** supported.

r? @lcnr
2020-09-09 01:35:20 +02:00
bors 71569e4201 Auto merge of #75138 - jumbatm:session-diagnostic-derive, r=oli-obk
Add derive macro for specifying diagnostics using attributes.

Introduces `#[derive(SessionDiagnostic)]`, a derive macro for specifying structs that can be converted to Diagnostics using directions given by attributes on the struct and its fields. Currently, the following attributes have been implemented:
- `#[code = "..."]` -- this sets the Diagnostic's error code, and must be provided on the struct iself (ie, not on a field). Equivalent to calling `code`.
- `#[message = "..."]` -- this sets the Diagnostic's primary error message.
- `#[label = "..."]` -- this must be applied to fields of type `Span`, and is equivalent to `span_label`
- `#[suggestion(..)]` -- this allows a suggestion message to be supplied. This attribute must be applied to a field of type `Span` or `(Span, Applicability)`, and is equivalent to calling `span_suggestion`. Valid arguments are:
    - `message = "..."` -- this sets the suggestion message.
    - (Optional) `code = "..."` -- this suggests code for the suggestion. Defaults to empty.

`suggestion`also  comes with other variants: `#[suggestion_short(..)]`, `#[suggestion_hidden(..)]` and `#[suggestion_verbose(..)]` which all take the same keys.

Within the strings passed to each attribute, fields can be referenced without needing to be passed explicitly into the format string -- eg, `#[error = "{ident} already declared"] ` will set the error message to `format!("{} already declared", &self.ident)`. Any fields on the struct can be referenced in this way.

Additionally, for any of these attributes, Option fields can be used to only optionally apply the decoration -- for example:

```rust
#[derive(SessionDiagnostic)]
#[code = "E0123"]
struct SomeKindOfError {
    ...
    #[suggestion(message = "informative error message")]
    opt_sugg: Option<(Span, Applicability)>
    ...
}
```
will not emit a suggestion if `opt_sugg` is `None`.

We plan on iterating on this macro further; this PR is a start.

Closes #61132.

r? `@oli-obk`
2020-09-08 00:58:43 +00:00
kadmin ee55c1f1d2 Add regression test and help note 2020-09-07 20:12:02 +00:00
Caleb Zulawski 4efe97a3d9 Check placement of more attributes 2020-09-05 20:45:43 -04:00
bors 81a769f261 Auto merge of #75584 - RalfJung:union-no-deref, r=matthewjasper
do not apply DerefMut on union field

This implements the part of [RFC 2514](https://github.com/rust-lang/rfcs/blob/master/text/2514-union-initialization-and-drop.md) about `DerefMut`. Unlike described in the RFC, we only apply this warning specifically when doing `DerefMut` of a `ManuallyDrop` field; that is really the case we are worried about here.

@matthewjasper suggested I patch `convert_place_derefs_to_mutable` and `convert_place_op_to_mutable` for this, but I could not find anything to do in `convert_place_op_to_mutable` and this is sufficient to make the test pass. However, maybe there are some other cases this misses? I have no familiarity with this code.

This is a breaking change *in theory*, if someone used `ManuallyDrop<T>` in a union field and relied on automatic `DerefMut`. But on stable this means `T: Copy`, so the `ManuallyDrop` is rather pointless.

Cc https://github.com/rust-lang/rust/issues/55149
2020-09-05 11:47:01 +00:00
LeSeulArtichaut 3e14b684dd Change ty.kind to a method 2020-09-04 17:47:51 +02:00
kadmin 96bb2c86f2 Add further tests and liberalize type checking 2020-09-03 17:46:27 +00:00
kadmin 8d9187597a Update to use multipart suggestion
Nice.
2020-09-03 16:02:56 +00:00
kadmin 4b132eefb4 Initial commit 2020-09-03 16:02:56 +00:00
Dan Aloni 75a042e74b Fix some unwanted uses of Debug formatting on user-facing messages
While formatting for user diagnostics used `Display` for all most cases,
some small amount of cases used `Debug` instead.  Until now, `Display`
and `Debug` yielded the same output for many types. However, with path
trimming, we want to show a shorter path for the user, these cases need
fixing.
2020-09-02 10:40:10 +03:00
jumbatm 57edf88b40 Replace some trivial struct_span_err!s in typeck. 2020-09-01 23:05:56 +10:00
jumbatm 93eaf15646 Add SessionDiagnostic derive macro.
Co-authored-by: Oliver Scherer <github35764891676564198441@oli-obk.de>
2020-09-01 22:02:45 +10:00
Ralf Jung 97974e3cab only emit error for ManuallyDrop derefs 2020-08-31 10:14:31 +02:00
Ralf Jung 44defaea3a also detect DerefMut in nested union fields 2020-08-31 10:14:30 +02:00
Ralf Jung ec0924f964 do not apply DerefMut on union field 2020-08-31 10:14:29 +02:00
Esteban Küber 07112ca62d Suggest `if let x = y` when encountering `if x = y`
Detect potential cases where `if let` was meant but `let` was left out.

Fix #44990.
2020-08-30 15:01:06 -07:00
mark 9e5f7d5631 mv compiler to compiler/ 2020-08-30 18:45:07 +03:00