Commit Graph

758 Commits

Author SHA1 Message Date
Matthias Krüger
4d9effc65c
Rollup merge of #108176 - compiler-errors:bad-lexical-region-resolve-bug, r=oli-obk
Don't delay `ReError` bug during lexical region resolve

Lexical region resolution returns a list of `RegionResolutionError` which don't necessarily correspond to diagnostics being emitted. The compiler may, validly, throw away these resolution errors and do something else. Therefore it's not valid to use `ReError` during lifetime resolution, since we may actually be on a totally fine compilation path.

For example, the `implied_bounds_entailment` lint runs region resolution twice, and only emits an error if it fails both times. If we delay a bug and create a `ReError` during this first run, then we will ICE.

Fixes #108170

----

Side-note: this is conceptually equivalent to how we can't necessarily delay bugs or create `ty::Error` during trait solving/fulfillment, since the compiler is allowed to throw away these fulfillment errors to do other things. It's only once we actually emit an error (`report_region_errors` / `report_fulfillment_errors`)
2023-02-22 20:05:58 +01:00
Jeremy Fitzhardinge
fc5db2cd4f Implement -Zlink-directives=yes/no
`-Zlink-directives=no` will ignored `#[link]` directives while compiling a
crate, so nothing is emitted into the crate's metadata.  The assumption is
that the build system already knows about the crate's native dependencies
and can provide them at link time without these directives.

This is another way to address issue # #70093, which is currently addressed
by `-Zlink-native-libraries` (implemented in #70095). The latter is
implemented at link time, which has the effect of ignoring `#[link]`
in *every* crate. This makes it a very large hammer as it requires all
native dependencies to be known to the build system to be at all usable,
including those in sysroot libraries. I think this means its effectively
unused, and definitely under-used.

Being able to control this on a crate-by-crate basis should make it much
easier to apply when needed.

I'm not sure if we need both mechanisms, but we can decide that later.
2023-02-22 10:18:01 -08:00
Alan Egerton
a9b2354a1d
Normalize line+col in normalize-tait-in-const test 2023-02-22 17:05:04 +00:00
Alan Egerton
695072daa6
Remove type-traversal trait aliases 2023-02-22 17:04:58 +00:00
Michael Howell
3f374128ee diagnostics: update test cases to refer to assoc fn with self as method 2023-02-22 08:40:47 -07:00
clubby789
c7a4f387fd Lint dead code in closures 2023-02-22 15:27:19 +00:00
Alex Macleod
4fba0c0449 Fix test filename for #105700 2023-02-22 13:08:13 +00:00
Guillaume Gomez
437f210af5
Rollup merge of #108239 - clubby789:overlapping-spans, r=compiler-errors
Fix overlapping spans in removing extra arguments

Fixes #108225

Each span is already extended to include the previous comma, so extending to the *next* comma is unecessary and causes an ICE with assertions on.

``@rustbot`` label +A-diagnostics
2023-02-22 10:35:08 +01:00
Guillaume Gomez
a32c500400
Rollup merge of #108230 - LittleFall:enhance/warning, r=estebank
Convert a hard-warning about named static lifetimes into lint "unused_lifetimes"

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

Some changes are ported from https://github.com/rust-lang/rust/pull/98079, thanks to jeremydavis519.

r? `@estebank` `@petrochenkov`

Any feedback is appreciated!

## Actions
- [x] resolve conflicts
- [x] fix build
- [x] address review comments in last pr
- [x] update tests
2023-02-22 10:35:08 +01:00
Guillaume Gomez
89c201e3be
Rollup merge of #108168 - clubby789:recursive-type-alias, r=compiler-errors
Fix ICE on type alias in recursion

Fixes #108160
2023-02-22 10:35:07 +01:00
Zhi Qi
ce2ae62d68 Convert a hard-warning about named static lifetimes into lint "unused_lifetimes"
Define the `named_static_lifetimes` lint

This lint will replace the existing hard-warning.

Replace the named static lifetime hard-warning with the new lint

Update the UI tests for the `named_static_lifetimes` lint

Remove the direct dependency on `rustc_lint_defs`

fix build

Signed-off-by: Zhi Qi <qizhi@pingcap.com>

use "UNUSED_LIFETIMES" instead

Signed-off-by: Zhi Qi <qizhi@pingcap.com>

update 1 test and fix typo

Signed-off-by: Zhi Qi <qizhi@pingcap.com>

update tests

Signed-off-by: Zhi Qi <qizhi@pingcap.com>

fix tests: add extra blank line

Signed-off-by: Zhi Qi <qizhi@pingcap.com>
2023-02-22 09:44:26 +08:00
Matthias Krüger
ae01430078
Rollup merge of #108295 - compiler-errors:wtf-is-this, r=cjgillot
Use DefKind to give more item kind information during BindingObligation note

The current label says "required by a bound in this". When I see that label, my immediate impression is "this... **what**?". It feels like it was cut short.

Alternative to this would be saying "in this item", but adding the item kind is strictly more informational and adds very little overhead to the existing error presentation.
2023-02-21 23:02:00 +01:00
Matthias Krüger
8a5843f07f
Rollup merge of #108202 - compiler-errors:non_lifetime_binders-type-match-ice, r=davidtwco
Make sure `test_type_match` doesn't ICE with late-bound types

Fixes #108190 (in a kind of hacky way, anyways doesn't really matter)
2023-02-21 23:01:59 +01:00
bors
f4c7596ac3 Auto merge of #108311 - oli-obk:invert_defines, r=lcnr
Make hidden type registration opt-in, so that each site can be reviewed on its own and we have the right defaults for trait solvers

r? `@lcnr`

pulled out of https://github.com/rust-lang/rust/pull/107891 as it is the uncontroversial part
2023-02-21 15:48:40 +00:00
Oli Scherer
88a7b6803b Make hidden type registration opt-in, so that each site can be reviewed on its own and we have the right defaults for trait solvers 2023-02-21 14:50:51 +00:00
clubby789
0b9a3e29d4 Fix overlapping spans in removing extra arguments 2023-02-21 13:13:09 +00:00
bors
3200982b76 Auto merge of #108138 - compiler-errors:malformed-fn-trait, r=TaKO8Ki
Move `Fn*` traits malformedness protections to typeck

I found it strange that we were doing a custom well-formedness check just for the `Fn*` traits' `call_*` fn items. My understanding from the git history is that this is just to avoid ICEs later on in typeck.

Well, that well-formedness check isn't even implemented correctly for `FnOnce::call_once`, or `FnMut::call_mut` for that matter. Instead, this PR just makes the typeck checks more robust, and leaves it up to the call-site to report errors when lang items are implemented in funny ways.

This coincidentally fixes another ICE where a the `Add` lang item is implemented with a `add` item that's a const instead of a method.
2023-02-21 12:59:11 +00:00
bors
bda32a4023 Auto merge of #108301 - Dylan-DPC:rollup-70zpkt0, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #108000 (lint: don't suggest MaybeUninit::assume_init for uninhabited types)
 - #108105 (Explain the default panic hook better)
 - #108141 (Add rpitit queries)
 - #108272 (docs: wrong naming convention in struct keyword doc)
 - #108285 (remove unstable `pick_stable_methods_before_any_unstable` flag)
 - #108289 (Name placeholder in some region errors)
 - #108290 (Add a test for default trait method with RPITITs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-21 09:51:03 +00:00
Dylan DPC
60c0972af7
Rollup merge of #108290 - compiler-errors:rpitit-trait-default-constraint, r=oli-obk
Add a test for default trait method with RPITITs

This didn't work in #107013, but now that #108203 has landed, let's make sure we don't regress it.

r? types
2023-02-21 14:20:01 +05:30
Dylan DPC
270f45e172
Rollup merge of #108289 - compiler-errors:name-placeholder, r=petrochenkov
Name placeholder in some region errors

Also don't print `ReVar` or `ReLateBound` as debug... these error messages are super uncommon anyways, but in the case they do trigger, let's be slightly more helpful.
2023-02-21 14:20:01 +05:30
Dylan DPC
4dea3a295f
Rollup merge of #108000 - y21:no-zero-init-for-uninhabited, r=jackh726
lint: don't suggest MaybeUninit::assume_init for uninhabited types

Creating a zeroed uninhabited type such as `!` or an empty enum with `mem::zeroed()` (or transmuting `()` to `!`) currently triggers this lint:
```rs
warning: the type `!` does not permit zero-initialization
 --> test.rs:5:23
  |
5 |         let _val: ! = mem::zeroed();
  |                       ^^^^^^^^^^^^^
  |                       |
  |                       this code causes undefined behavior when executed
  |                       help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
  |
  = note: the `!` type has no valid value
```
The `MaybeUninit` suggestion in the help message seems confusing/useless for uninhabited types, as such a type cannot be fully initialized in the first place (as the note implies).
This PR limits this help message to inhabited types which can be initialized
2023-02-21 14:19:58 +05:30
bors
3fee48c161 Auto merge of #104754 - nnethercote:more-ThinVec-in-ast, r=the8472
Use `ThinVec` more in the AST

r? `@ghost`
2023-02-21 07:02:57 +00:00
Michael Goulet
a58682d7cc Specify what 'this' actually is 2023-02-21 05:21:07 +00:00
bors
f715e430aa Auto merge of #107728 - RalfJung:miri-dyn-star, r=RalfJung,oli-obk
Miri: basic dyn* support

As usual I am very unsure about the dynamic dispatch stuff, but it passes even the `Pin<&mut dyn* Trait>` test so that is something.

TBH I think it was a mistake to make `dyn Trait` and `dyn* Trait` part of the same `TyKind` variant. Almost everywhere in Miri this lead to the wrong default behavior, resulting in strange ICEs instead of nice "unimplemented" messages. The two types describe pretty different runtime data layout after all.

Strangely I did not need to do the equivalent of [this diff](https://github.com/rust-lang/rust/pull/106532#discussion_r1087095963) in Miri. Maybe that is because the unsizing logic matches on `ty::Dynamic(.., ty::Dyn)` already? In `unsized_info` I don't think the `target_dyn_kind` can be `DynStar`, since then it wouldn't be unsized!

r? `@oli-obk` Cc `@eholk` (dyn-star) https://github.com/rust-lang/rust/issues/102425
2023-02-21 04:22:23 +00:00
Michael Goulet
dfc4a580f2 Add a test for default trait method with RPITITs 2023-02-21 02:01:26 +00:00
bors
2deff71719 Auto merge of #105462 - oli-obk:feeding_full, r=cjgillot,petrochenkov
give the resolver access to TyCtxt

The resolver is now created after TyCtxt is created. Then macro expansion and name resolution are run and the results fed into queries just like before this PR.

Since the resolver had (before this PR) mutable access to the `CStore` and the source span table, these two datastructures are now behind a `RwLock`. To ensure that these are not mutated anymore after the resolver is done, a read lock to them is leaked right after the resolver finishes.

### PRs split out of this one and leading up to it:

* https://github.com/rust-lang/rust/pull/105423
* https://github.com/rust-lang/rust/pull/105357
* https://github.com/rust-lang/rust/pull/105603
* https://github.com/rust-lang/rust/pull/106776
* https://github.com/rust-lang/rust/pull/106810
* https://github.com/rust-lang/rust/pull/106812
* https://github.com/rust-lang/rust/pull/108032
2023-02-21 01:19:25 +00:00
Nicholas Nethercote
7e855d5f31 Use ThinVec in a few more AST types. 2023-02-21 11:51:56 +11:00
Nicholas Nethercote
912b825002 Use ThinVec in ast::PatKind::Struct. 2023-02-21 11:51:56 +11:00
Nicholas Nethercote
b14b7ba5dd Use ThinVec in ast::Block. 2023-02-21 11:51:56 +11:00
Nicholas Nethercote
4143b101f9 Use ThinVec in various AST types.
This commit changes the sequence parsers to produce `ThinVec`, which
triggers numerous conversions.
2023-02-21 11:51:56 +11:00
Nicholas Nethercote
068db466e8 Use ThinVec in ast::WhereClause. 2023-02-21 11:51:55 +11:00
Nicholas Nethercote
dd7aff5cc5 Use ThinVec in ast::Generics and related types. 2023-02-21 11:51:55 +11:00
Michael Goulet
eb1f9babec Add test for bad cast with deferred projection equality 2023-02-21 00:07:06 +00:00
Michael Goulet
2895731e5e Name placeholder in some region errors 2023-02-21 00:00:49 +00:00
Matthias Krüger
194d52cc18
Rollup merge of #108254 - Nathan-Fenner:nathanf/error-span-ref-trait-refine, r=WaffleLapkin
Refine error span for trait error into borrowed expression

Extends the error span refinement in #106477 to drill into borrowed expressions just like tuples/struct/enum literals. For example,

```rs
trait Fancy {}
trait Good {}
impl <'a, T> Fancy for &'a T where T: Good {}
impl <S> Good for Option<S> where S: Iterator {}

fn want_fancy<F>(f: F) where F: Fancy {}

fn example() {
    want_fancy(&Some(5));
//  (BEFORE)   ^^^^^^^^ `{integer}` is not an iterator
//  (AFTER)          ^  `{integer}` is not an iterator
}
```

Existing heuristics try to find the right part of the expression to "point at"; current heuristics look at e.g. struct constructors and tuples. This PR adds a new check for borrowed expressions when looking into a borrowed type.
2023-02-20 22:12:18 +01:00
bors
8973049549 Auto merge of #108268 - matthiaskrgr:rollup-4tdvnx6, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #108124 (Document that CStr::as_ptr returns a type alias)
 - #108171 (Improve building compiler artifacts output)
 - #108200 (Use restricted Damerau-Levenshtein distance for diagnostics)
 - #108259 (remove FIXME that doesn't require fixing)
 - #108265 ("`const` generic" -> "const parameter")

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-20 16:19:06 +00:00
Oli Scherer
c3522d0637 Move the resolver into a query 2023-02-20 15:28:59 +00:00
Ralf Jung
57056d7f8f slightly beef up dyn-star-to-dyn test 2023-02-20 15:08:05 +01:00
Ralf Jung
b2f58146b9 basic dyn* support for Miri 2023-02-20 15:08:05 +01:00
Matthias Krüger
e4dadd6416
Rollup merge of #108265 - lcnr:cg-error-msg, r=BoxyUwU
"`const` generic" -> "const parameter"
2023-02-20 14:32:56 +01:00
Matthias Krüger
226ce31edd
Rollup merge of #108200 - jhpratt:restricted-damerau-levenshtein-distance, r=tmiasko
Use restricted Damerau-Levenshtein distance for diagnostics

This replaces the existing Levenshtein algorithm with the Damerau-Levenshtein algorithm. This means that "ab" to "ba" is one change (a transposition) instead of two (a deletion and insertion). More specifically, this is a _restricted_ implementation, in that "ca" to "abc" cannot be performed as "ca" → "ac" → "abc", as there is an insertion in the middle of a transposition. I believe that errors like that are sufficiently rare that it's not worth taking into account.

This was first brought up [on IRLO](https://internals.rust-lang.org/t/18227) when it was noticed that the diagnostic for `prinltn!` (transposed L and T) was `print!` and not `println!`. Only a single existing UI test was effected, with the result being an objective improvement.

~~I have left the method name and various other references to the Levenshtein algorithm untouched, as the exact manner in which the edit distance is calculated should not be relevant to the caller.~~

r? ``@estebank``

``@rustbot`` label +A-diagnostics +C-enhancement
2023-02-20 14:32:55 +01:00
bors
267cd1d2c5 Auto merge of #107721 - megakorre:issue_105700, r=petrochenkov
create dummy placeholder crate to prevent compiler from panicing

This PR is to address the panic found in https://github.com/rust-lang/rust/issues/105700.

There are 2 separate things going on with this panic.
First the code could not generate a dummy response for crate fragment types when it hits the recursion limit.
This PR adds the method to the trait implementation for `DymmyResult` to be able to create a dummy crate node.
This stops the panic from happening.

The second thing that is not addressed (and maybe does not need addressing? 🤷🏻)
is that when you have multiple attributes it ends up treating attributes that follow another as being the result of expanding the former (maybe there is a better way to say that). So you end up hitting the recursion limit. Even though you would think there is no expansion happening here.

If you did not hit the recursion limit the compiler would output that `invalid_attribute` does not exists. But it currently exits before the resolution step when the recursion limit is reached here.
2023-02-20 13:23:47 +00:00
lcnr
2cbe583593 const generic -> const parameter in err msg 2023-02-20 12:58:11 +01:00
bors
e7eaed21d5 Auto merge of #107969 - b-naber:proj-relate-variance, r=lcnr
Use covariance on type relations of field projection types if possible

It's fine to use covariance here unless we're in a mutating context.

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

Supersedes https://github.com/rust-lang/rust/pull/105958

r? `@lcnr`
2023-02-20 09:25:51 +00:00
Patrik Kårlin
0fd2a70b90
create dummy placeholder crate to prevent compiler 2023-02-20 10:20:57 +01:00
Nathan Fenner
fbcca2aaf0 Refine error span for trait error into borrowed expression 2023-02-19 21:27:04 -08:00
bors
7b552967b8 Auto merge of #105961 - fmease:iat-type-directed-probing, r=jackh726
Type-directed probing for inherent associated types

When probing for inherent associated types (IATs), equate the Self-type found in the projection with the Self-type of the relevant inherent impl blocks and check if all predicates are satisfied.
Previously, we didn't look at the Self-type or at the bounds and just picked the first inherent impl block containing an associated type with the name we were searching for which is obviously incorrect.

Regarding the implementation, I basically copied what we do during method probing (`assemble_inherent_impl_probe`, `consider_probe`). Unfortunately, I had to duplicate a lot of the diagnostic code found in `rustc_hir_typeck::method::suggest` which we don't have access to in `rustc_hir_analysis`. Not sure if there is a simple way to unify the error handling. Note that in the future, `rustc_hir_analysis::astconv` might not actually be the place where we resolve inherent associated types (see https://github.com/rust-lang/rust/pull/103621#issuecomment-1304309565) but `rustc_hir_typeck` (?) in which case the duplication may naturally just disappear. While inherent associated *constants* are currently resolved during "method" probing, I did not find a straightforward way to incorporate IAT lookup into it as types and values (functions & constants) are two separate entities for which distinct code paths are taken.

Fixes #104251 (incl. https://github.com/rust-lang/rust/issues/104251#issuecomment-1338501171).
Fixes #105305.
Fixes #107468.

`@rustbot` label T-types F-inherent_associated_types
r? types
2023-02-20 00:37:20 +00:00
León Orell Valerian Liehr
00b976a138
Collect fulfillment errors across impls 2023-02-19 22:54:08 +01:00
bors
21e5b941e0 Auto merge of #108128 - clubby789:builtin-derived-attr, r=jackh726
Properly check for builtin derived code

Fixes #108122
2023-02-19 21:18:07 +00:00
León Orell Valerian Liehr
6eb6455c46
Add a test and several known bugs 2023-02-19 18:35:36 +01:00
León Orell Valerian Liehr
77ea90ec71
Fix substitution bug 2023-02-19 18:35:35 +01:00
León Orell Valerian Liehr
6065867a7e
Use InferCtxt::probe to properly detect ambiguous candidates 2023-02-19 18:35:35 +01:00
León Orell Valerian Liehr
aa7edf7073
Use the correct ParamEnv 2023-02-19 18:35:34 +01:00
León Orell Valerian Liehr
488d0c9efd
Type-directed probing for inherent associated types 2023-02-19 18:35:28 +01:00
Guillaume Gomez
d2aef58eb5
Rollup merge of #108203 - compiler-errors:rpitit-fix-defaults-2, r=jackh726
Fix RPITITs in default trait methods (by assuming projection predicates in param-env)

Instead of having special projection logic that allows us to turn `ProjectionTy(RPITIT, [Self#0, ...])` into `OpaqueTy(RPITIT, [Self#0, ...])`, we can instead augment the param-env of default trait method bodies to assume these as projection predicates. This should allow us to only project where we're allowed to!

In order to make this work without introducing a bunch of cycle errors, we additionally tweak the `OpaqueTypeExpander` used by `ParamEnv::with_reveal_all_normalized` to not normalize the right-hand side of projection predicates. This should be fine, because if we use the projection predicate to normalize some other projection type, we'll continue to normalize the opaque that it gets projected to.

This also makes it possible to support default trait methods with RPITITs in an associated-type based RPITIT lowering strategy without too much extra effort.

Fixes #107002
Alternative to #108142
2023-02-19 14:47:56 +01:00
bors
eebdfb55fc Auto merge of #108228 - Dylan-DPC:rollup-i9t13qu, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #104659 (reflow the stack size story)
 - #106933 (Update documentation of select_nth_unstable and select_nth_unstable_by to state O(n^2) complexity)
 - #107783 (rustdoc: simplify DOM for `.item-table`)
 - #107951 (resolve: Fix doc links referring to other crates when documenting proc macro crates directly)
 - #108130 ("Basic usage" is redundant for there is just one example)
 - #108146 (rustdoc: hide `reference` methods in search index)
 - #108189 (Fix some more `non_lifetime_binders` stuff with higher-ranked trait bounds)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-19 08:15:40 +00:00
Dylan DPC
c5d5c57666
Rollup merge of #108189 - compiler-errors:non_lifetime_binders-bound-stuff, r=jackh726
Fix some more `non_lifetime_binders` stuff with higher-ranked trait bounds

1. When assembling candidates for `for<T> T: Sized`, we can't ICE because the self-type is a bound type.
2. Fix an issue where, when canonicalizing in non-universe preserving mode, we don't actually set the universe for placeholders to the root even though we do the same for region vars.
3. Make `Placeholder("T")` format like `T` in error messages.

Fixes #108180
Fixes #108182

r? types
2023-02-19 13:03:42 +05:30
bors
73f40197ec Auto merge of #107772 - compiler-errors:dyn-star-backend-is-ptr, r=eholk
Make `dyn*`'s value backend type a pointer

One tweak on top of Ralf's commit should fix using `usize` as a `dyn*`-coercible type, and should fix when we're using various other pointer types when LLVM opaque pointers is disabled.

r? `@eholk` but feel free to reassign
cc https://github.com/rust-lang/rust/pull/107728#issuecomment-1421231823 `@RalfJung`
2023-02-19 05:35:03 +00:00
Jacob Pratt
c2f2a3cff2
Add test for println! typo 2023-02-19 03:46:03 +00:00
Jacob Pratt
ff052eec80
Use restricted Damerau-Levenshtein algorithm 2023-02-19 03:46:03 +00:00
Michael Goulet
3e57b20391 Add test 2023-02-18 20:36:39 +00:00
Michael Goulet
c13d5f1aeb Make sure test_type_match doesn't ICE with late-bound types 2023-02-18 20:16:51 +00:00
Michael Goulet
6f3706ea71 Pretty placeholders using their names 2023-02-18 19:49:40 +00:00
Michael Goulet
ec40b1a393 Collapse placeholders to root universe in canonicalizer if not preserving universes 2023-02-18 19:49:40 +00:00
Michael Goulet
f4a4a31479 Don't ICE on bound types in sized conditions 2023-02-18 19:49:40 +00:00
Michael Goulet
df52e2037a Use inttoptr to support usize as dyn* value, use pointercast to make sure pointers are compatible 2023-02-18 19:47:33 +00:00
Michael Goulet
82b52056fe Check that built-in callable types validate their output type is Sized (in new solver) 2023-02-18 19:32:58 +00:00
y21
0610df9314 lint: don't suggest assume_init for uninhabited types 2023-02-18 19:05:44 +01:00
Matthias Krüger
d3d5163921
Rollup merge of #108186 - compiler-errors:closures-with-late-bound-types-r-bad, r=cjgillot
Deny non-lifetime bound vars in `for<..> ||` closure binders

Moves the check for illegal bound var types from astconv to resolve_bound_vars. If a binder is defined to have a type or const late-bound var that's not allowed, we'll resolve any usages to ty error or const error values, so we shouldn't ever see late-bound types or consts in places they aren't expected.

Fixes #108184
Fixes #108181
Fixes #108192
2023-02-18 13:26:47 +01:00
Matthias Krüger
7f9d9de82d
Rollup merge of #108162 - clubby789:issue-108155, r=Nilstrieb
Don't eagerly convert principal to string

Fixes #108155

~~I haven't yet been able to reproduce the ICE in a minimal example unfortunately.~~ Added a test
2023-02-18 13:26:47 +01:00
Matthias Krüger
3035ccbcb9
Rollup merge of #108031 - jieyouxu:issue-108019, r=estebank
Don't recover lifetimes/labels containing emojis as character literals

Fixes #108019.

Note that at the time of this commit, `unic-emoji-char` seems to have data tables only up to Unicode 5.0, but Unicode is already newer than this.

A newer emoji such as `🥺` will not be recognized as an emoji but older emojis such as `🐱` will.

This PR leaves a couple of FIXMEs where `unic_emoji_char::is_emoji` is used.
2023-02-18 13:26:46 +01:00
Michael Goulet
5ec812ddfd Add addl test 2023-02-18 03:34:27 +00:00
Michael Goulet
cec7835d7a Move late-bound arg type checks to resolve_bound_vars 2023-02-18 03:28:54 +00:00
bors
fabfd1fd93 Auto merge of #99679 - repnop:kernel-address-sanitizer, r=cuviper
Add `kernel-address` sanitizer support for freestanding targets

This PR adds support for KASan (kernel address sanitizer) instrumentation in freestanding targets. I included the minimal set of `x86_64-unknown-none`, `riscv64{imac, gc}-unknown-none-elf`, and `aarch64-unknown-none` but there's likely other targets it can be added to. (`linux_kernel_base.rs`?) KASan uses the address sanitizer attributes but has the `CompileKernel` parameter set to `true` in the pass creation.
2023-02-18 03:05:11 +00:00
Michael Goulet
fded2e95ab Adjust tracking issue for non_lifetime_binders 2023-02-18 02:42:43 +00:00
Michael Goulet
90cf0cc6c2 Don't delay ReError bug during lexical region resolve 2023-02-17 18:26:22 +00:00
clubby789
21bcd2ee9c Fix ICE on type alias in recursion 2023-02-17 16:20:38 +00:00
clubby789
eebd31c187 Don't eagerly convert principal to string 2023-02-17 14:44:58 +00:00
bors
f722b24eb9 Auto merge of #108159 - matthiaskrgr:rollup-5k2j7cx, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #107592 (Default `repr(C)` enums to `c_int` size)
 - #107956 (Copy `bin/*` and `lib/*.dylib` files to `stage0-sysroot`)
 - #108126 (fix a line, and do a consistency fix)
 - #108144 (Add compiler-errors to a few more triagebot groups)
 - #108149 (typo)
 - #108154 (`BasicBlock::new(0)` -> `START_BLOCK` [no functional changes])

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-17 14:27:28 +00:00
Matthias Krüger
e0aa5613d8
Rollup merge of #107592 - workingjubilee:use-16-bit-enum-on-16-bit-targets, r=WaffleLapkin
Default `repr(C)` enums to `c_int` size

This is what ISO C strongly implies this is correct, and
many processor-specific ABIs imply or mandate this size, so
"everyone" (LLVM, gcc...) defaults to emitting enums this way.
However, this is by no means guaranteed by ISO C,
and the bare-metal Arm targets show it can be overridden,
which rustc supports via `c-enum-min-bits` in a target.json.

The override is a flag named `-fshort-enums` in clang and gcc,
but introducing a CLI flag is probably unnecessary for rustc.
This flag can be used by non-Arm microcontroller targets,
like AVR and MSP430, but it is not enabled for them by default.
Rust programmers who know the size of a target's enums
can use explicit reprs, which also lets them match C23 code.

This change is most relevant to 16-bit targets: AVR and MSP430.
Most of rustc's targets use 32-bit ints, but ILP64 does exist.
Regardless, rustc should now correctly handle enums for
both very small and very large targets.

Thanks to William for confirming MSP430 behavior,
and to Waffle for better style and no-core `size_of` asserts.

Fixes rust-lang/rust#107361
Fixes rust-lang/rust#77806
2023-02-17 12:39:05 +01:00
Boxy
90c8d6bbe4 add predicate evaluation logic 2023-02-17 09:32:39 +00:00
Matthias Krüger
ecdb7bcee8
Rollup merge of #108136 - eggyal:unmet_trait_alias_bound_on_generic_impl, r=compiler-errors
Do not ICE on unmet trait alias impl bounds

Fixes #108132

I've also added some documentation to the `impl_def_id` field of `DerivedObligationCause` to try and minimise the risk of such errors in future.

r? `@compiler-errors`
2023-02-17 00:19:37 +01:00
Matthias Krüger
ee07df9c50
Rollup merge of #108009 - c410-f3r:moar-tests, r=petrochenkov
Move some tests

r? `@petrochenkov`
2023-02-17 00:19:35 +01:00
Matthias Krüger
089e8c03bc
Rollup merge of #107489 - compiler-errors:non_lifetime_binders, r=cjgillot
Implement partial support for non-lifetime binders

This implements support for non-lifetime binders. It's pretty useless currently, but I wanted to put this up so the implementation can be discussed.

Specifically, this piggybacks off of the late-bound lifetime collection code in `rustc_hir_typeck::collect::lifetimes`. This seems like a necessary step given the fact we don't resolve late-bound regions until this point, and binders are sometimes merged.

Q: I'm not sure if I should go along this route, or try to modify the earlier nameres code to compute the right bound var indices for type and const binders eagerly... If so, I'll need to rename all these queries to something more appropriate (I've done this for `resolve_lifetime::Region` -> `resolve_lifetime::ResolvedArg`)

cc rust-lang/types-team#81

r? `@ghost`
2023-02-17 00:19:34 +01:00
Jubilee Young
2edf6c8784 Default repr(C) enums to c_int size
This is what ISO C strongly implies this is correct, and
many processor-specific ABIs imply or mandate this size, so
"everyone" (LLVM, gcc...) defaults to emitting enums this way.
However, this is by no means guaranteed by ISO C,
and the bare-metal Arm targets show it can be overridden,
which rustc supports via `c-enum-min-bits` in a target.json.

The override is a flag named `-fshort-enums` in clang and gcc,
but introducing a CLI flag is probably unnecessary for rustc.
This flag can be used by non-Arm microcontroller targets,
like AVR and MSP430, but it is not enabled for them by default.
Rust programmers who know the size of a target's enums
can use explicit reprs, which also lets them match C23 code.

This change is most relevant to 16-bit targets: AVR and MSP430.
Most of rustc's targets use 32-bit ints, but ILP64 does exist.
Regardless, rustc should now correctly handle enums for
both very small and very large targets.

Thanks to William for confirming MSP430 behavior,
and to Waffle for better style and no-core size_of asserts.

Co-authored-by: William D. Jones <thor0505@comcast.net>
Co-authored-by: Waffle Maybe <waffle.lapkin@gmail.com>
2023-02-16 15:06:17 -08:00
Alan Egerton
a1468ae00d
Do not ICE on unmet trait alias impl bounds 2023-02-16 22:10:29 +00:00
Michael Goulet
2a700d47f5 Add ICE test for bad Add::add impl item type 2023-02-16 20:58:48 +00:00
Michael Goulet
ff9c5db03c Tweak wording 2023-02-16 20:52:29 +00:00
Michael Goulet
3dd638fe6c Move call trait lang item malformed check to typeck 2023-02-16 20:37:33 +00:00
clubby789
90f642bb3d Properly check for builtin derives 2023-02-16 19:44:03 +00:00
Matthias Krüger
d77b0221f8
Rollup merge of #108115 - eggyal:unmet_trait_alias_bound, r=compiler-errors
Do not ICE on unmet trait alias bounds

Rework of #108093 following feedback on that PR.

Fixes #108072

r? `@compiler-errors`
2023-02-16 17:51:26 +01:00
Matthias Krüger
f65c6e416c
Rollup merge of #106347 - estebank:removal-suggestion, r=TaKO8Ki
More accurate spans for arg removal suggestion

Partially address #106304.
2023-02-16 17:51:24 +01:00
Caio
d75e43c371 Move tests 2023-02-16 11:42:35 -03:00
Alan Egerton
540bd986aa
Do not ICE on unmet trait alias bounds 2023-02-16 11:18:08 +00:00
bors
af3c8b2726 Auto merge of #101841 - nnethercote:rm-save-analysis, r=Mark-Simulacrum
Remove save-analysis.

Most tests involving save-analysis were removed, but I kept a few where the `-Zsave-analysis` was an add-on to the main thing being tested, rather than the main thing being tested.

Closes https://github.com/rust-lang/rust/issues/43606
2023-02-16 10:35:44 +00:00
Dylan DPC
5fac20f87c
Rollup merge of #108050 - martingms:issue-108042-fix, r=compiler-errors
Fix index out of bounds ICE in `point_at_expr_source_of_inferred_type`

There might be more type params than args to a method call, which leads to an index out of bounds panic.
I'm not familiar with this code at all, so unsure whether this is the right fix, but at least this patch fixes #108042 for me (I hit the same issue with similar code)
2023-02-16 11:40:20 +05:30
Nicholas Nethercote
22a5125a36 Remove save-analysis.
Most tests involving save-analysis were removed, but I kept a few where
the `-Zsave-analysis` was an add-on to the main thing being tested,
rather than the main thing being tested.

For `x.py install`, the `rust-analysis` target has been removed.

For `x.py dist`, the `rust-analysis` target has been kept in a
degenerate form: it just produces a single file `reduced.json`
indicating that save-analysis has been removed. This is necessary for
rustup to keep working.

Closes #43606.
2023-02-16 15:14:45 +11:00
Michael Goulet
95f35fe443 Deny some late-bound ty/ct in some positions, add tests 2023-02-16 03:39:59 +00:00
Michael Goulet
262a344d72 Add feature gate for non_lifetime_binders 2023-02-16 03:39:58 +00:00
bors
dc7a676778 Auto merge of #108096 - matthiaskrgr:rollup-ncexzf6, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #107034 (Migrating rustc_infer to session diagnostics (part 4))
 - #107972 (Fix unintentional UB in ui tests)
 - #108010 (Make `InferCtxt::can_eq` and `InferCtxt::can_sub` return booleans)
 - #108021 (make x look for x.py if shell script does not exist)
 - #108047 (Use `target` instead of `machine` for mir interpreter integer handling.)
 - #108049 (Don't suggest `#[doc(hidden)]` trait methods with matching return type)
 - #108066 (Better names for illegal impl trait positions)
 - #108076 (rustdoc: Use more let chain)
 - #108088 (clarify correctness of `black_box`)
 - #108094 (Demonstrate I/O in File examples)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-16 00:12:54 +00:00
bors
c5283576ec Auto merge of #108012 - compiler-errors:issue-107999, r=oli-obk
Don't ICE in `might_permit_raw_init` if reference is polymorphic

Emitting optimized MIR for a polymorphic function may require computing layout of a type that isn't (yet) known. This happens in the instcombine pass, for example. Let's fail gracefully in that condition.

cc `@saethlin`
fixes #107999
2023-02-15 20:56:07 +00:00
Matthias Krüger
8259755069
Rollup merge of #108066 - compiler-errors:better-labels-for-bad-impl-trait, r=petrochenkov
Better names for illegal impl trait positions

Just some wording tweaks, no behavior changes.
2023-02-15 21:30:58 +01:00
Matthias Krüger
897f56ed28
Rollup merge of #108049 - clubby789:dont-suggest-unstable, r=compiler-errors
Don't suggest `#[doc(hidden)]` trait methods with matching return type

Fixes #107983, addressing the bad suggestion.
The test can probably be made more specific to this  case, but I'm unsure how.

`@rustbot` label +A-diagnostics
2023-02-15 21:30:58 +01:00
Matthias Krüger
d40c13ae02
Rollup merge of #107972 - saethlin:fix-test-ub, r=michaelwoerister
Fix unintentional UB in ui tests

`@matthiaskrgr` found UB in a bunch of the ui tests. This PR fixes a batch of miscellaneous tests I didn't think needed reviewers from a particular part of the project.
2023-02-15 21:30:56 +01:00
Martin Gammelsæter
e159c1e0ec Skip method calls with arity mismatch 2023-02-15 18:52:23 +01:00
Martin Gammelsæter
08cc628e73 Add point-at-inference ui test for wrong arity case 2023-02-15 18:44:03 +01:00
bors
2d14db321b Auto merge of #108006 - cjgillot:def-impl, r=oli-obk
Avoid accessing HIR when it can be avoided

Experiment to see if it helps some incremental cases.

Will be rebased once https://github.com/rust-lang/rust/pull/107942 gets merged.

r? `@ghost`
2023-02-15 16:14:10 +00:00
Ben Kimock
de01ea26c9 Fix unintentional UB in ui tests 2023-02-15 09:05:05 -05:00
clubby789
f4de121951 Don't suggest #[doc(hidden)] methods 2023-02-15 12:31:38 +00:00
bors
999ac5f777 Auto merge of #108070 - Dylan-DPC:rollup-v6xw7vk, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #105300 (rework min_choice algorithm of member constraints)
 - #107163 (Remove some superfluous type parameters from layout.rs.)
 - #107173 (Suggest the correct array length on mismatch)
 - #107411 (Handle discriminant in DataflowConstProp)
 - #107968 (Enable `#[thread_local]` on armv6k-nintendo-3ds)
 - #108032 (Un📦ing the Resolver)
 - #108060 (Revert to using `RtlGenRandom` as a fallback)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-15 08:48:44 +00:00
Dylan DPC
a110cf5d16
Rollup merge of #107173 - clubby789:suggest-array-length, r=compiler-errors
Suggest the correct array length on mismatch

Fixes #107156

I wasn't able to find a way to get the `Span` for the actual array size unfortunately, so this suggestion can't be applied automatically.

``@rustbot`` label +A-diagnostics
2023-02-15 12:24:54 +05:30
Dylan DPC
83f10ea5b7
Rollup merge of #105300 - aliemjay:member-lower, r=oli-obk
rework min_choice algorithm of member constraints

See [this comment](https://github.com/rust-lang/rust/pull/105300#issuecomment-1384312743) for the description of the new algorithm.

Fixes #63033
Fixes #104639

This uses a more general algorithm than #89056 that doesn't treat `'static` as a special case. It thus accepts more code. For example:
```rust
async fn test2<'s>(_: &'s u8, _: &'_ &'s u8, _: &'_ &'s u8) {}
```
I claim it's more correct as well because it fixes #104639.

cc ``@nikomatsakis`` ``@lqd`` ``@tmandry`` ``@eholk`` ``@chenyukang`` ``@oli-obk``

r? types
2023-02-15 12:24:53 +05:30
bors
068161ea48 Auto merge of #107940 - BoxyUwU:const_ty_assertion_use_semantic_equality, r=compiler-errors
use semantic equality for const param type equality assertion

Fixes #107898

See added test for what caused this ICE

---

The current in assertion in `relate.rs` is rather inadequate when keeping in mind future expansions to const generics:
- it will ICE when there are infer vars in a projection in a const param ty
- it will spurriously return false when either ty has infer vars because of using `==` instead of `infcx.at(..).eq`
- i am also unsure if it would be possible with `adt_const_params` to craft a situation where the const param type is not wf causing `normalize_erasing_regions` to `bug!` when we would have emitted a diagnostic.

This impl feels pretty Not Great to me  although i am not sure what a better idea would be.

- We have to have the logic behind a query because neither `relate.rs` or `combine.rs` have access to trait solving machinery (without evaluating nested obligations this assert will become _far_ less useful under lazy norm, which consts are already doing)
- `relate.rs` does not have access to canonicalization machinery which is necessary in order to have types potentially containing infer vars in query arguments.

We could possible add a method to `TypeRelation` to do this assertion rather than a query but to avoid implementing the same logic over and over we'd probably end up with the logic in a free function somewhere in `rustc_trait_selection` _anyway_ so I don't think that would be much better.

We could also just remove this assertion, it should not actually be necessary for it to be present. It has caught some bugs in the past though so if possible I would like to keep it.

r? `@compiler-errors`
2023-02-15 05:17:58 +00:00
Wesley Norris
19714385e0 Add kernel-address sanitizer support for freestanding targets 2023-02-14 20:54:25 -05:00
Michael Goulet
3f80017f03 Better label for illegal impl trait types 2023-02-14 23:12:27 +00:00
bors
0416b1a6f6 Auto merge of #108056 - matthiaskrgr:rollup-oa6bxvh, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #107573 (Update the minimum external LLVM to 14)
 - #107626 (Fix `x fix` on the standard library itself)
 - #107673 (update ICU4X to 1.1.0)
 - #107733 (Store metrics from `metrics.json` to CI PGO timer)
 - #108007 (Use `is_str` instead of string kind comparison)
 - #108033 (add an unstable `#[rustc_coinductive]` attribute)
 - #108039 (Refactor refcounted structural_impls via functors)
 - #108040 (Use derive attributes for uninteresting traversals)
 - #108044 (interpret: rename Pointer::from_addr → from_addr_invalid)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-14 21:07:04 +00:00
Camille GILLOT
facecf6e1b Fetch less HIR in signature check. 2023-02-14 20:26:03 +00:00
Esteban Küber
dff10d0668 Re-add replacement logic and add comment explaining it 2023-02-14 20:22:10 +00:00
Esteban Küber
755252bf51 Show the effects of weird code commented out 2023-02-14 20:22:10 +00:00
Esteban Küber
bd176ee591 Make removal suggestion not verbose 2023-02-14 20:22:10 +00:00
Esteban Küber
5d63e10318 rebase and review comments 2023-02-14 20:22:10 +00:00
Esteban Küber
287cd5974c Avoid trailing commas 2023-02-14 20:22:10 +00:00
Esteban Küber
f02d8ec15e More accurate spans for arg removal suggestion 2023-02-14 20:22:09 +00:00
Matthias Krüger
edcdab08a4
Rollup merge of #108033 - lcnr:coinductive-attr, r=compiler-errors
add an unstable `#[rustc_coinductive]` attribute

useful to test coinduction, especially in the new solver.

as this attribute should remain permanently unstable I don't think this needs any official approval. cc ``@rust-lang/types``

had to weaken the check for stable query results in the solver to prevent an ICE if there's a coinductive cycle with constraints.

r? ``@compiler-errors``
2023-02-14 18:24:42 +01:00
Matthias Krüger
a1ba861190
Rollup merge of #107573 - cuviper:drop-llvm-13, r=nagisa
Update the minimum external LLVM to 14

With this change, we'll have stable support for LLVM 14 through 16 (pending release).
For reference, the previous increase to LLVM 13 was #100460.
2023-02-14 18:24:40 +01:00
Matthias Krüger
1f486f0a9b
Rollup merge of #108003 - chenyukang:yukang/fix-107998, r=compiler-errors
Avoid ICE when the generic_span is empty

Fixes #107998
r? ```@TaKO8Ki```
2023-02-14 18:02:51 +01:00
Matthias Krüger
202c70666f
Rollup merge of #103478 - SpanishPear:spanishpear/issue_103366_fix, r=TaKO8Ki
Suggest fix for misplaced generic params on fn item #103366

fixes #103366

This still has some work to go, but works for 2/3 of the initial base cases described in #1033366

simple fn:
```
error: expected identifier, found `<`
 --> shreys/test_1.rs:1:3
  |
1 | fn<T> id(x: T) -> T { x }
  |   ^ expected identifier
  |
help: help: place the generic parameter list after the function name:
  |
1 | fn id<T>(x: T) -> T { x }
  |    ~~~~

```

Complicated bounds
```
error: expected identifier, found `<`
 --> spanishpear/test_2.rs:1:3
  |
1 | fn<'a, B: 'a + std::ops::Add<Output = u32>> f(_x: B) { }
  |   ^ expected identifier
  |
help: help: place the generic parameter list after the function name:
  |
1 | fn f<'a, B: 'a + std::ops::Add<Output = u32>>(_x: B) { }
  |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

Opening a draft PR for comments on approach, particularly I have the following questions:
 -  [x]  Is it okay to be using `err.span_suggestion` over struct derives? I struggled to get the initial implementation (particularly the correct suggestion message) on struct derives, although I think given what I've learned since starting, I could attempt re-doing it with that approach.
  -  [x] in the case where the snippet cannot be obtained from a span, is the `help` but no suggestion okay? I think yes (also, when does this case occur?)
  -  [x] are there any red flags for the generalisation of this work for relevant item kinds (i.e. `struct`, `enum`, `trait`, and `union`). My basic testing indicates it does work for those types except the help tip is currently hardcoded to `after the function name` - which should change dependent on the item.
  - [x] I am planning to not show the suggestion if there is already a `<` after the item identifier, (i.e. if there are already generics, as after a function name per the original issue). Any major objections?
  - [x] Is the style of error okay? I wasn't sure if there was a way to make it display nicer, or if thats handled by span_suggestion

These aren't blocking questions, and I will keep working on:
  - check if there is a `<` after the ident (and if so, not showing the suggestion)
  - generalize the help message
  - figuring out how to write/run/etc ui tests (including reading the docs for them)
  - logic cleanups
2023-02-14 18:02:50 +01:00
lcnr
51671cd435 add test for coinduction in new solver 2023-02-14 12:18:33 +01:00
许杰友 Jieyou Xu (Joe)
98b82aedba
Update numeric lifetime test 2023-02-14 18:17:59 +08:00
bors
9bb6e60d1f Auto merge of #103695 - LYF1999:yf/103563, r=lcnr
fix: Unexpected trait bound not satisfied in HRTB and Associated Type

fix https://github.com/rust-lang/rust/issues/103563
2023-02-14 10:01:19 +00:00
许杰友 Jieyou Xu (Joe)
380fa26413
Don't recover lifetimes/labels containing emojis as character literals
Note that at the time of this commit, `unic-emoji-char` seems to have
data tables only up to Unicode 5.0, but Unicode is already newer than
this.

A newer emoji such as `🥺` will not be recognized as an emoji
but older emojis such as `🐱` will.
2023-02-14 17:31:58 +08:00
yukang
3180f1c828 Fix #107998, avoid ICE when the generic_span is empty 2023-02-14 03:46:43 +00:00
Michael Goulet
087a0136d0 Don't ICE in might_permit_raw_init if reference is polymorphic 2023-02-14 01:03:06 +00:00
Matthias Krüger
5f3d360844
Rollup merge of #107942 - compiler-errors:tighter-inherent-impl-bad-spans, r=Nilstrieb
Tighter spans for bad inherent `impl` self types

Self-explanatory
2023-02-13 23:25:12 +01:00
Matthias Krüger
73b022b8e1
Rollup merge of #107902 - vincenzopalazzo:macros/async_fn_suggestion, r=compiler-errors
fix: improve the suggestion on future not awaited

Considering the following code

```rust
fn foo() -> u8 {
    async fn async_fn() -> u8 {  22 }

    async_fn()
}

fn main() {}
```

the error generated before this commit from the compiler is

```
➜  rust git:(macros/async_fn_suggestion) ✗ rustc test.rs --edition 2021
error[E0308]: mismatched types
 --> test.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
...
4 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, found opaque type
  |
  = note:     expected type `u8`
          found opaque type `impl Future<Output = u8>`
help: consider `await`ing on the `Future`
  |
4 |     async_fn().await
  |               ++++++

error: aborting due to previous error
```

In this case the error is nor perfect, and can confuse the user that do not know that the opaque type is the future.

So this commit will propose (and conclude the work start in https://github.com/rust-lang/rust/issues/80658)
to change the string `opaque type` to `future` when applicable and also remove the Expected vs Received note by adding a more specific one regarding the async function that return a future type.

So the new error emitted by the compiler is

```
error[E0308]: mismatched types
 --> test.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
...
4 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, found future
  |
note: calling an async function returns a future
 --> test.rs:4:5
  |
4 |     async_fn()
  |     ^^^^^^^^^^
help: consider `await`ing on the `Future`
  |
4 |     async_fn().await
  |               ++++++

error: aborting due to previous error
```

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

It remains to rework the case described in the following issue https://github.com/rust-lang/rust/issues/107899 but I think this deserves its own PR after we discuss a little bit how to handle these kinds of cases.

r? `@eholk`

`@rustbot` label +I-async-nominated

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-02-13 23:25:11 +01:00
Michael Goulet
e20f6ff1dc Tighter spans for bad inherent impl types 2023-02-13 18:41:18 +00:00
bors
a3c9eede5d Auto merge of #107924 - eggyal:move_fold_visit_traits_to_type_lib_with_trait_alias, r=oli-obk
Move folding & visiting traits into type library

This is a rework of #107712, following feedback on that PR.

In particular, this version uses trait aliases to reduce the API churn for trait consumers.  Doing so requires a workaround for #107747 until its fix in #107803 is merged into the stage0 compiler; this workaround, which uses conditional compilation based on the `bootstrap` configuration predicate, sits in dedicated commit b409329c for ease of reversion.

The possibility of the `rustc_middle` crate retaining its own distinct versions of each folding/visiting trait, blanket-implemented on all types that implement the respective trait in the type library, was also explored: however since this would necessitate making each `rustc_middle` trait a subtrait of the respective type library trait (so that such blanket implementations can delegate their generic methods), no benefit would be gained.

r? types
2023-02-13 16:50:33 +00:00
Vincenzo Palazzo
2bdc9a046a
fix: improve the suggestion on future not awaited
Considering the following code

```rust
fn foo() -> u8 {
    async fn async_fn() -> u8 {  22 }

    async_fn()
}

fn main() {}
```

the error generated before this commit from the compiler is

```
➜  rust git:(macros/async_fn_suggestion) ✗ rustc test.rs --edition 2021
error[E0308]: mismatched types
 --> test.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
...
4 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, found opaque type
  |
  = note:     expected type `u8`
          found opaque type `impl Future<Output = u8>`
help: consider `await`ing on the `Future`
  |
4 |     async_fn().await
  |               ++++++

error: aborting due to previous error
```

In this case the error is nor perfect, and can confuse the user
that do not know that the opaque type is the future.

So this commit will propose (and conclude the work start in
https://github.com/rust-lang/rust/issues/80658)
to change the string `opaque type` to `future` when applicable
and also remove the Expected vs Received note by adding a more
specific one regarding the async function that return a future type.

So the new error emitted by the compiler is

```
error[E0308]: mismatched types
 --> test.rs:4:5
  |
1 | fn foo() -> u8 {
  |             -- expected `u8` because of return type
...
4 |     async_fn()
  |     ^^^^^^^^^^ expected `u8`, found future
  |
note: calling an async function returns a future
 --> test.rs:4:5
  |
4 |     async_fn()
  |     ^^^^^^^^^^
help: consider `await`ing on the `Future`
  |
4 |     async_fn().await
  |               ++++++

error: aborting due to previous error
```

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-02-13 16:23:23 +01:00
yifei
d164448038 fix: Unexpected trait bound not satisfied in HRTB 2023-02-13 19:39:44 +08:00
Matthias Krüger
3e5c11b855
Rollup merge of #107931 - cjgillot:issue-107353, r=WaffleLapkin
Intern span when length is MAX_LEN with parent.

Fixes https://github.com/rust-lang/rust/issues/107353
2023-02-13 11:34:58 +01:00
Matthias Krüger
780beae7bd
Rollup merge of #107838 - estebank:terminal_hyperlinks, r=nagisa
Introduce `-Zterminal-urls` to use OSC8 for error codes

Terminals supporting the OSC8 Hyperlink Extension can support inline anchors where the text is user defineable but clicking on it opens a browser to a specified URLs, just like `<a href="URL">` does in HTML.

https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
2023-02-13 11:34:57 +01:00
Alan Egerton
ba55a453eb
Alias folding/visiting traits instead of re-export 2023-02-13 10:24:46 +00:00
Dylan DPC
4bf58083ac
Rollup merge of #107973 - saethlin:fix-simd-test-ub, r=workingjubilee
Fix unintentional UB in SIMD tests

r? `@workingjubilee`
2023-02-13 11:12:52 +05:30
Ben Kimock
9c4696b940 Fix unintentional UB in SIMD tests 2023-02-12 20:18:48 -05:00
b-naber
6e1d228285 only require sub type relation on field projection types 2023-02-12 23:18:15 +01:00
Ralf Jung
0ea0c90d58 fix UB in ancient test 2023-02-12 16:30:37 +01:00
bors
51cb5614dd Auto merge of #105601 - BelovDV:change-rlib-with-not-stable, r=petrochenkov
Enable new rlib in non stable cases

If bundled static library uses cfg (unstable) or whole-archive (wasn't supported) bundled libs are packed even without packed_bundled_libs.

r? `@petrochenkov`
2023-02-12 07:15:27 +00:00
clubby789
903ca873f7 Suggest the correct array length on mismatch 2023-02-12 02:15:41 +00:00
Boxy
a85b0101e6 make relate's const ty assertion use semantic equality 2023-02-11 23:05:16 +00:00
Camille GILLOT
84bb373b2a Pacify tidy. 2023-02-11 18:07:06 +00:00