Commit Graph

9421 Commits

Author SHA1 Message Date
Yuki Okushi
6d9913d51b Rollup merge of #67880 - lbonn:fix/multi-substs, r=petrochenkov
Handle multiple error fix suggestions carefuly

The existing code seems to assume that substitutions spans are disjoint,
which is not always the case.

In the example:

    pub trait AAAA {}
    pub trait B {}
    pub trait C {}
    pub type T<P: AAAA + B + C> = P;

, we get three substituions starting from ':' and ending respectively at
the end of each trait token.

With the former offset calculation, this would cause `underline_start` to
eventually become negative before being converted to `usize`...

The new version may report erroneous results for non perfectly overlapping
substitutions but I don't know if such examples exist. Alternatively, we
could detect these cases and trim out overlapping substitutions.

Fixes #67690
2020-01-07 13:46:04 +09:00
Yuki Okushi
3cce950743 Rollup merge of #67671 - estebank:type-impl-trait, r=davidtwco
Account for `type X = impl Trait;` in lifetime suggestion

Fix #67619.
2020-01-07 13:45:59 +09:00
varkor
3ab95ceb12 Detail transitive containment in E0588 diagnostic 2020-01-07 02:16:57 +00:00
Esteban Küber
2905f14b67 Account for type X = impl Trait; in lifetime suggestion 2020-01-06 13:36:06 -08:00
Andy Russell
a7727c59ac fire "non_camel_case_types" for associated types 2020-01-06 09:51:23 -05:00
Dylan DPC
34716a31db Rollup merge of #67915 - lzutao:Self, r=Centril
Use Self instead of $type

r? @Dylan-DPC
2020-01-06 12:00:23 +05:30
Dylan DPC
c79034ed47 Rollup merge of #67906 - varkor:silence-toogeneric, r=nagisa
Silence `TooGeneric` error

This error may be produced during intermediate failed attempts at evaluation of a generic const, which may nevertheless succeed later.

Fixes https://github.com/rust-lang/rust/issues/66962.

r? @eddyb
2020-01-06 12:00:20 +05:30
Dylan DPC
3692075049 Rollup merge of #67800 - Aaron1011:fix/mir-generic-instance, r=oli-obk
Fix ICE involving calling `Instance.ty` during const evaluation

Fixes #67639

`Instance.ty` assumes that we are in a fully monomorphic context (e.g.
codegen), and can therefore use an empty `ParamEnv` when performing
normalization. Howver, the MIR constant evaluator code ends up calling
`Instance.ty` as a result of us attemptign to 'speculatively'
const-evaluate generic functions during const propagation.

As a result,
we may end up with projections involving type parameters
(e.g. <T as MyTrait>::Bar>) in the type we are trying to normalize.
Normalization expects us to have proper predicates in the `ParamEnv` for
such projections, and will ICE if we don't.

This commit adds a new method `Instance.ty_env`, which takes a
`ParamEnv` for use during normalization. The MIR const-evaluator code is
changed to use this method, passing in the proper `ParamEnv` for the
context at hand.
2020-01-06 12:00:16 +05:30
Lzu Tao
c7dbf5ad54 Use Self instead of $type 2020-01-06 04:33:31 +00:00
varkor
adb46fd0a4 Silence TooGeneric error
This error may be produced during intermediate failed attempts at evaluation of a generic const, which may nevertheless succeed later.
2020-01-05 23:00:47 +00:00
Aaron Hill
ee922d47f2 Fix ICE involving calling Instance.ty during const evaluation
Fixes #67639

`Instance.ty` assumes that we are in a fully monomorphic context (e.g.
codegen), and can therefore use an empty `ParamEnv` when performing
normalization. Howver, the MIR constant evaluator code ends up calling
`Instance.ty` as a result of us attemptign to 'speculatively'
const-evaluate generic functions during const propagation.

As a result,
we may end up with projections involving type parameters
(e.g. <T as MyTrait>::Bar>) in the type we are trying to normalize.
Normalization expects us to have proper predicates in the `ParamEnv` for
such projections, and will ICE if we don't.

This commit adds a new method `Instance.ty_env`, which takes a
`ParamEnv` for use during normalization. The MIR const-evaluator code is
changed to use this method, passing in the proper `ParamEnv` for the
context at hand.
2020-01-05 14:37:59 -05:00
Matthew Jasper
5e92625004 Correctly check for opaque types in assoc_ty_def 2020-01-05 18:13:01 +00:00
Laurent Bonnans
12545c75ff Handle multiple error fix suggestions carefuly
The existing code seems to assume that substitutions spans are disjoint,
which is not always the case.

In the example:

    pub trait AAAA {}
    pub trait B {}
    pub trait C {}
    pub type T<P: AAAA + B + C> = P;

, we get three substituions starting from ':' and ending respectively at
the end of each trait token.

With the former offset calculation, this would cause `underline_start` to
eventually become negative before being converted to `usize`...

The new version may report erroneous results for non perfectly overlapping
substitutions but I don't know if such examples exist. Alternatively, we
could detect these cases and trim out overlapping substitutions.
2020-01-05 12:51:57 +01:00
Adam Perry
b97ee0f07a Fix typo
Co-Authored-By: lzutao <taolzu@gmail.com>
2020-01-04 22:54:09 -08:00
Adam Perry
7a6af7eb0e Result's panics have #[track_caller]. 2020-01-04 19:52:37 -08:00
Adam Perry
2e9d573d3f Option's panics are all #[track_caller].
Also includes a simple test with a custom panic hook to ensure we don't regress.
2020-01-04 19:52:37 -08:00
varkor
0c2cf07d6e Add backticks to various diagnostics 2020-01-05 00:17:46 +00:00
cjkenn
e01e8b9256 add ui test 2020-01-04 10:58:04 -08:00
Dylan DPC
5dabc3b339 Rollup merge of #67775 - mental32:master, r=Dylan-DPC
Make "use $crate" a hard error

Closes #37390
2020-01-04 23:52:50 +05:30
Dylan DPC
3c87772a8a Rollup merge of #67709 - petrochenkov:nodedup2, r=Centril
Introduce an option for disabling deduplication of diagnostics

With the intent of using it in UI tests (https://github.com/rust-lang/rust/pull/67122).

The option is boolean (`-Z deduplicate-diagnostics=yes/no`) and can be specified multiple times with later values overriding earlier values (`-Z deduplicate-diagnostics=no -Z deduplicate-diagnostics=yes` == `-Z deduplicate-diagnostics=yes`), so it can be set in a hierarchical way, e.g. UI testing infra may disable the deduplication by default with specific tests being able to enable it back.
2020-01-04 23:52:48 +05:30
Dylan DPC
cce055daef Rollup merge of #67137 - anp:tracked-panic-internals, r=eddyb
libstd uses `core::panic::Location` where possible.

cc @eddyb
2020-01-04 23:52:44 +05:30
Adam Perry
e218da4251 Test cleanups to match #[track_caller] in panic!.
* Removes unnecessary feature flag from track_caller test.
* Tests of panic internals no longer need to explicitly construct Location.
* Add #![warn(const_err)] to retain-never-const per @oli-obk.
* Add track_caller test with diverging function.
2020-01-04 10:02:17 -08:00
Guillaume Gomez
1140ceebcc Rollup merge of #67823 - euclio:drop-improvements, r=petrochenkov
improve some `Drop`-related error messages
2020-01-04 13:17:29 +01:00
Guillaume Gomez
a469b1785d Rollup merge of #67822 - wesleywiser:revert_67676, r=oli-obk
Revert `const_err` lint checking of casts

Reverts part of #67676

r? @oli-obk

cc @SimonSapin
2020-01-04 13:17:27 +01:00
Yuki Okushi
c818f4c88e try to fix ui errors 2020-01-04 14:27:29 +05:30
Mazdak Farrokhzad
689e29f0f5 Rollup merge of #67835 - euclio:delimiter-wording, r=Centril
tweak wording of mismatched delimiter errors

This PR improves the wording of the "incorrect delimiter" error messages. Here's a quick rationale:

- *"un-closed" -> "unclosed"*: "unclosed" is valid English, so there's no need to hyphenate the prefix. This should be pretty uncontroversial, I think.
- *"close delimiter" -> "closing delimiter"*: In my anecdotal experience, I've always heard "closing delimiter" or "closing parenthesis". In addition, the codebase already uses this terminology in comments and function names more than "close delimiter", which could indicate that it's more intuitive.
- "incorrect delimiter" -> "mismatched delimiter": "Incorrect delimiter" is vague; why is it incorrect? "mismatched" clearly indicates why the delimiter is causing the error.

r? @estebank
2020-01-04 02:19:54 +01:00
Mazdak Farrokhzad
b32dc91372 Rollup merge of #67810 - crlf0710:uncommon_codepoints_lint, r=Manishearth
Implement uncommon_codepoints lint.

Part of #55467 .  The checks of `$crate` and `{{root}}` are very unfortunate. But i'm not sure where they belongs to.
2020-01-04 02:19:52 +01:00
Mazdak Farrokhzad
a436293994 Rollup merge of #66913 - VirrageS:help-self, r=varkor,Centril
Suggest calling method when first argument is `self`

Closes: #66782

I've explored different approaches for this MR but I think the most straightforward is the best one.

I've tried to find out if the methods for given type exist (to maybe have a better suggestion), but we don't collect them anywhere and collecting them is quite problematic. Moreover, collecting all the methods would require rewriting big part of the code and also could potentially include performance degradation, which I don't think is necessary for this simple case.
2020-01-04 02:19:44 +01:00
Andy Russell
e9990bc65f clarify that Drop can be implemented for enums and unions too 2020-01-03 17:57:24 -05:00
Andy Russell
e589358210 improve generic Drop error messages
- Use the span of the predicate
- Use the def's description instead of "struct/enum" (notably incorrect
  for unions)
- Align formatting with other error messages
2020-01-03 17:57:23 -05:00
Vadim Petrochenkov
6bd6a20475 Add a test 2020-01-03 18:03:28 +04:00
Vadim Petrochenkov
4feeceecd1 Introduce an option for disabling deduplication of diagnostics 2020-01-03 18:03:28 +04:00
Andy Russell
7fd014d569 tweak wording of mismatched delimiter errors 2020-01-03 08:40:15 -05:00
mental
c0da63951a Thank you Dylan and JohnTitor for blessing me. 2020-01-03 11:50:12 +02:00
bors
30ddb5a8c1 Auto merge of #67828 - JohnTitor:rollup-qmswkkl, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #67450 (Allow for setting a ThinLTO import limit during bootstrap)
 - #67595 (Suggest adding a lifetime constraint for opaque type)
 - #67636 (allow rustfmt key in [build] section)
 - #67736 (Less-than is asymmetric, not antisymmetric)
 - #67762 (Add missing links for insecure_time)
 - #67783 (Warn for bindings named same as variants when matching against a borrow)
 - #67796 (Ensure that we process projections during MIR inlining)
 - #67807 (Use drop instead of the toilet closure `|_| ()`)
 - #67816 (Clean up err codes)
 - #67825 (Minor: change take() docs grammar to match other docs)

Failed merges:

r? @ghost
2020-01-03 09:07:05 +00:00
Yuki Okushi
b0649c0c5f Rollup merge of #67807 - lzutao:toilet-closure, r=Centril
Use drop instead of the toilet closure `|_| ()`
2020-01-03 17:56:30 +09:00
Yuki Okushi
09c7a9beb2 Rollup merge of #67796 - Aaron1011:fix/mir-inline-proj, r=wesleywiser
Ensure that we process projections during MIR inlining

Fixes #67710

Previously, we were not calling `super_place`, which resulted in us
failing to update any local references that occur in
ProjectionElem::Index. This caused the post-inlining MIR to contain a
reference to a local ID from the inlined callee, leading to an ICE
due to a type mismatch.
2020-01-03 17:56:29 +09:00
Yuki Okushi
7affcd5394 Rollup merge of #67783 - LeSeulArtichaut:pattern-ref-warning, r=Centril
Warn for bindings named same as variants when matching against a borrow

Fixes #67776
2020-01-03 17:56:27 +09:00
Yuki Okushi
76c1454d27 Rollup merge of #67595 - ohadravid:impl-trait-does-not-live-long-enough, r=estebank
Suggest adding a lifetime constraint for opaque type

Fixes #67577, where code like this:

```
struct List {
  data: Vec<String>,
}
impl List {
  fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> {
    self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref())
  }
}
```

will show this error:
```
   Compiling playground v0.0.1 (/playground)
error[E0597]: `prefix` does not live long enough
 --> src/lib.rs:6:47
  |
5 |   fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> {
  |                   -- lifetime `'a` defined here     --------------------------- opaque type requires that `prefix` is borrowed for `'a`
...
```

but without suggesting the lovely `help: you can add a constraint..`.

r? @estebank
2020-01-03 17:56:21 +09:00
bors
4877e164a1 Auto merge of #67768 - wesleywiser:dnm_test_perf_65244, r=Mark-Simulacrum
Revert #65244 for performance reasons

This reverts commit f35517ee86.

Revert #65244 so we can see if it is the cause of the performance issue in #67706

cc https://github.com/rust-lang/rust/issues/67644
2020-01-03 05:51:04 +00:00
Wesley Wiser
8e4886dd55 Revert const_err lint checking of casts
Reverts part of #67676
2020-01-02 21:21:02 -05:00
Charles Lew
485e98aae2 Implement uncommon_codepoints lint. 2020-01-03 08:20:12 +08:00
LeSeulArtichaut
5cc9f6b706 Reformulate test description
Co-authored-by: Centril <twingoow@gmail.com>
2020-01-02 21:11:43 +01:00
LeSeulArtichaut
dc19b4842a Enhance test
Co-authored-by: Centril <twingoow@gmail.com>
2020-01-02 21:08:25 +01:00
LeSeulArtichaut
318280519d Move test
Co-authored-by: Centril <twingoow@gmail.com>
2020-01-02 20:16:55 +01:00
mental
b97438333e Lets see if I can get these ui tests to run. 2020-01-02 12:08:20 +02:00
mental
56b3120bf4 Remove // check-pass for ui/import/import-crate-var.rs 2020-01-02 11:59:32 +02:00
Lzu Tao
dd8f072233 Use drop instead of the toilet closure |_| () 2020-01-02 08:56:12 +00:00
mental
3323f1e57d Update src/test/ui 2020-01-02 10:16:07 +02:00
Aaron Hill
e8e53b56df Ensure that we process projections during MIR inlining
Fixes #67710

Previously, we were not calling `super_place`, which resulted in us
failing to update any local references that occur in
ProjectionElem::Index. This caused the post-inlining MIR to contain a
reference to a local ID from the inlined callee, leading to an ICE
due to a type mismatch.
2020-01-01 20:10:55 -05:00