Commit Graph

328 Commits

Author SHA1 Message Date
bors
91b8f34ac2 Auto merge of #104799 - pcc:linkage-fn, r=tmiasko
Support Option and similar enums as type of static variable with linkage attribute

Compiler MCP:
rust-lang/compiler-team#565
2022-12-07 10:24:59 +00:00
Matthias Krüger
ddb98e0aac
Rollup merge of #105254 - cjgillot:issue-105251, r=oli-obk
Recurse into nested impl-trait when computing variance.

Fixes https://github.com/rust-lang/rust/issues/105251
2022-12-06 13:27:42 +01:00
Matthias Krüger
be3ad5d6b0
Rollup merge of #105005 - estebank:where-clause-lts, r=compiler-errors
On E0195 point at where clause lifetime bounds

Fix #104733
2022-12-06 13:27:41 +01:00
Esteban Küber
e802165dfe On E0195 point at where clause lifetime bounds
Fix #104733
2022-12-05 20:43:41 -08:00
Peter Collingbourne
f44a0153bc Support Option and similar enums as type of static variable with linkage attribute.
Compiler MCP:
https://github.com/rust-lang/compiler-team/issues/565
2022-12-05 15:05:43 -08:00
Peter Collingbourne
5873ebeef3 Move linkage type check to HIR analysis and fix semantics issues.
This ensures that the error is printed even for unused variables,
as well as unifying the handling between the LLVM and GCC backends.

This also fixes unusual behavior around exported Rust-defined variables
with linkage attributes. With the previous behavior, it appears to be
impossible to define such a variable such that it can actually be imported
and used by another crate. This is because on the importing side, the
variable is required to be a pointer, but on the exporting side, the
type checker rejects static variables of pointer type because they do
not implement `Sync`. Even if it were possible to import such a type, it
appears that code generation on the importing side would add an unexpected
additional level of pointer indirection, which would break type safety.

This highlighted that the semantics of linkage on Rust-defined variables
is different to linkage on foreign items. As such, we now model the
difference with two different codegen attributes: linkage for Rust-defined
variables, and import_linkage for foreign items.

This change gives semantics to the test
src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs which was
previously expected to fail to compile. Therefore, convert it into a
test that is expected to successfully compile.

The update to the GCC backend is speculative and untested.
2022-12-05 15:05:43 -08:00
León Orell Valerian Liehr
d5cb5fb185
normalize inherent associated types after substitution 2022-12-05 18:02:47 +01:00
bors
b9341bfdb1 Auto merge of #104920 - compiler-errors:avoid-infcx-build, r=jackh726
Avoid some `InferCtxt::build` calls

Either because we're inside of an `InferCtxt` already, or because we're not in a place where we'd ever see inference vars.

r? types
2022-12-05 02:51:06 +00:00
Michael Goulet
a68eae2f70 Avoid InferCtxt::build in generic_arg_mismatch_err 2022-12-04 20:54:30 +00:00
bors
0f0d5d716a Auto merge of #105261 - matthiaskrgr:rollup-9ghhc9c, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #101975 (Suggest to use . instead of :: when accessing a method of an object)
 - #105141 (Fix ICE on invalid variable declarations in macro calls)
 - #105224 (Properly substitute inherent associated types.)
 - #105236 (Add regression test for #47814)
 - #105247 (Use parent function WfCheckingContext to check RPITIT.)
 - #105253 (Update a couple of rustbuild deps)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-04 16:32:21 +00:00
Matthias Krüger
d055d6ad5e
Rollup merge of #105247 - cjgillot:issue-102682, r=compiler-errors
Use parent function WfCheckingContext to check RPITIT.

WF-check for RPITIT was done in the opaque type's param-env, so it could not benefit from assumed wf types from the function's parameters.

cc `@compiler-errors` since you chose that param-env in fd2766e7fd

Fixes https://github.com/rust-lang/rust/issues/102682
Fixes https://github.com/rust-lang/rust/issues/104908
Fixes https://github.com/rust-lang/rust/issues/102552
Fixes https://github.com/rust-lang/rust/issues/104529
2022-12-04 16:25:34 +01:00
Matthias Krüger
f2e223c576
Rollup merge of #105224 - cjgillot:issue-104240, r=compiler-errors
Properly substitute inherent associated types.

Fixes https://github.com/rust-lang/rust/issues/104240
2022-12-04 16:25:33 +01:00
bors
19c250aa12 Auto merge of #103293 - est31:untwist_and_drop_order, r=nagisa
Remove drop order twist of && and || and make them associative

Previously a short circuiting binop chain (chain of && or ||s) would drop the temporaries created by the first element after all the other elements, and otherwise follow evaluation order. So `f(1).g() && f(2).g() && f(3).g() && f(4).g()` would drop the temporaries in the order `2,3,4,1`. This made `&&` and `||` non-associative regarding drop order. In other words, adding ()'s to the expression would change drop order: `f(1).g() && (f(2).g() && f(3).g()) && f(4).g()` for example would drop in the order `3,2,4,1`.

As, except for the bool result, there is no data returned by the sub-expressions of the short circuiting binops, we can safely discard of any temporaries created by the sub-expr. Previously, code was already putting the rhs's into terminating scopes, but missed it for the lhs's.

This commit addresses this "twist". We now also put the lhs into a terminating scope. The drop order of the above expressions becomes `1,2,3,4`.

There might be code relying on the current order, and therefore I'd recommend doing a crater run to gauge the impact. I'd argue that such code is already quite wonky as it is one `foo() &&` addition away from breaking. ~~For the impact, I don't expect any *build* failures, as the compiler gets strictly more tolerant: shortening the lifetime of temporaries only expands the list of programs the compiler accepts as valid. There might be *runtime* failures caused by this change however.~~ Edit: both build and runtime failures are possible, e.g. see the example provided by dtolnay [below](https://github.com/rust-lang/rust/pull/103293#issuecomment-1285341113). Edit2: the crater run has finished and [results](https://github.com/rust-lang/rust/pull/103293#issuecomment-1292275203) are that there is only one build failure which is easy to fix with a +/- 1 line diff.

I've included a testcase that now compiles thanks to this patch.

The breakage is also limited to drop order relative to conditionals in the && chain: that is, in code like this:

```Rust
let hello = foo().hi() && bar().world();
println!("hi");
```

we already drop the temporaries of `foo().hi()` before we reach "hi".

I'd ideally have this PR merged before let chains are stabilized. If this PR is taking too long, I'd love to have a more restricted version of this change limited to `&&`'s in let chains: the `&&`'s of such chains are quite special anyways as they accept `let` bindings, in there the `&&` is therefore more a part of the "if let chain" construct than a construct of its own.

Fixes #103107

Status: waiting on [this accepted FCP](https://github.com/rust-lang/rust/pull/103293#issuecomment-1293411354) finishing.
2022-12-04 14:03:12 +00:00
Camille GILLOT
44948d1fdc Recurse into nested impl-trait when computing variance. 2022-12-04 13:54:56 +00:00
Camille GILLOT
12473d3f36 Use parent function WfCheckingContext to check RPITIT. 2022-12-04 10:33:07 +00:00
est31
a59a2d3f6a Also avoid creating a terminating scope in mixed chains
This avoids creation of a terminating scope in
chains that contain both && and ||, because
also there we know that a terminating scope is
not neccessary: all the chain members are already
in such terminating scopes.

Also add a mixed && / || test.
2022-12-04 04:09:40 +01:00
est31
a2076dc0a6 Improve comments 2022-12-04 04:09:40 +01:00
est31
8cf521d80e Remove drop order twist of && and || and make them associative
Previously a short circuiting && chain would drop the
first element after all the other elements, and otherwise
follow evaluation order, so code like:

f(1).g() && f(2).g() && f(3).g() && f(4).g()

would drop the temporaries in the order 2,3,4,1. This made
&& and || non-associative regarding drop order, so
adding ()'s to the expression would change drop order:

f(1).g() && (f(2).g() && f(3).g()) && f(4).g()

for example would drop in the order 3,2,4,1.

As, except for the bool result, there is no data returned
by the sub-expressions of the short circuiting binops,
we can safely discard of any temporaries created by the
sub-expr. Previously, code was already putting the rhs's
into terminating scopes, but missed it for the lhs's.

This commit addresses this "twist". In the expression,
we now also put the lhs into a terminating scope.
The drop order for the above expressions is 1,2,3,4
now.
2022-12-03 23:32:08 +01:00
Camille GILLOT
8a7ae23f75 Properly substitute inherent associated types. 2022-12-03 19:08:00 +00:00
Matthias Krüger
b1e680650e
Rollup merge of #105200 - cjgillot:issue-104562, r=compiler-errors
Remove useless filter in unused extern crate check.

Fixes https://github.com/rust-lang/rust/issues/104562
2022-12-03 17:37:44 +01:00
Matthias Krüger
ed9a21eb0c
Rollup merge of #105193 - tmiasko:naked-nocoverage, r=wesleywiser
Disable coverage instrumentation for naked functions

Fixes #105170.
2022-12-03 17:37:44 +01:00
Camille GILLOT
59cc6cd4ac Remove useless filter in unused extern crate check. 2022-12-03 09:23:03 +00:00
Tomasz Miąsko
b740cdcf43 Mark naked functions as never inline in codegen_fn_attrs
Use code generation attributes to ensure that naked functions are never
inline, replacing separate checks in MIR inliner and LLVM code
generation.
2022-12-03 01:04:42 +01:00
Tomasz Miąsko
c955add18c Disable coverage instrumentation for naked functions 2022-12-03 01:03:28 +01:00
Matthias Krüger
09e2d0f289
Rollup merge of #105163 - compiler-errors:afit-lt-arity, r=jackh726
Check lifetime param count in `collect_trait_impl_trait_tys`

We checked the type and const generics count, but not the lifetimes, which were handled in a different function.

Fixes #105154
2022-12-02 21:22:50 +01:00
Michael Goulet
bd7ee07d02 Check lifetime param count in collect_trait_impl_trait_tys 2022-12-02 04:05:39 +00:00
Vadim Petrochenkov
6cd4dd3091 rustc_hir: Relax lifetime requirements on Visitor::visit_path 2022-12-01 17:04:02 +03:00
bors
24606deaf4 Auto merge of #104905 - compiler-errors:normalization-changes, r=spastorino
Some initial normalization method changes

1. Rename `AtExt::normalize` to `QueryNormalizeExt::query_normalize` (using the `QueryNormalizer`)
2. Introduce `NormalizeExt::normalize` to replace `partially_normalize_associated_types_in` (using the `AssocTypeNormalizer`)
3. Rename `FnCtxt::normalize_associated_types_in` to `FnCtxt::normalize`
4. Remove some unused other normalization fns in `Inherited` and `FnCtxt`

Also includes one drive-by where we're no longer creating a `FnCtxt` inside of `check_fn`, but passing it in. This means we don't need such weird `FnCtxt` construction logic.

Stacked on top of #104835 for convenience.

r? types
2022-11-30 11:13:09 +00:00
Santiago Pastorino
537488efd6
Make inferred_outlives_crate return Clause 2022-11-29 12:01:58 -03:00
Michael Goulet
1e236acd05 Make ObligationCtxt::normalize take cause by borrow 2022-11-28 17:35:40 +00:00
Michael Goulet
06786227fd Simplify more FnCtxt normalization 2022-11-28 17:35:39 +00:00
Michael Goulet
52cd342696 FnCtxt normalization stuff 2022-11-28 17:35:39 +00:00
Nicholas Nethercote
a60e337c88 Rename NestedMetaItem::[Ll]iteral as NestedMetaItem::[Ll]it.
We already use a mix of `Literal` and `Lit`. The latter is better
because it is shorter without causing any ambiguity.
2022-11-28 15:18:53 +11:00
Nicholas Nethercote
e4a9150872 Rename ast::Lit as ast::MetaItemLit. 2022-11-28 15:18:49 +11:00
Matthias Krüger
86304f5149
Rollup merge of #104976 - WaffleLapkin:move_comments, r=cjgillot
Prefer doc comments over `//`-comments in compiler

Doc comments are generally nicer: they show up in the documentation, they are shown in IDEs when you hover other mentions of items, etc. Thus it makes sense to use them instead of `//`-comments.
2022-11-27 22:14:08 +01:00
bors
454784afba Auto merge of #104048 - cjgillot:split-lifetime, r=compiler-errors
Separate lifetime ident from lifetime resolution in HIR

Drive-by: change how suggested generic args are computed.
Fixes https://github.com/rust-lang/rust/issues/103815

I recommend reviewing commit-by-commit.
2022-11-27 14:30:19 +00:00
Maybe Waffle
1d42936b18 Prefer doc comments over //-comments in compiler 2022-11-27 11:19:04 +00:00
Guillaume Gomez
a2e485c25c
Rollup merge of #104786 - WaffleLapkin:amp-mut-help, r=compiler-errors
Use the power of adding helper function to simplify code w/ `Mutability`

r? `@compiler-errors`
2022-11-26 17:47:23 +01:00
Santiago Pastorino
974e2837bb
Introduce PredicateKind::Clause 2022-11-25 00:04:54 -03:00
Oli Scherer
42cc8e8f4e
Simplify a bunch of trait ref obligation creations 2022-11-25 00:04:54 -03:00
Camille GILLOT
1c737d6997 Use kw::Empty for elided lifetimes in path. 2022-11-24 17:48:59 +00:00
Camille GILLOT
41090346d8 Change how suggested lifetime args are computed. 2022-11-24 17:48:42 +00:00
hkalbasi
390a637e29 move things from rustc_target::abi to rustc_abi 2022-11-24 16:26:13 +03:30
hkalbasi
27fb904d68 move some layout logic to rustc_target::abi::layout 2022-11-24 16:26:12 +03:30
Matthias Krüger
2190b163a3
Rollup merge of #104775 - spastorino:use-obligation-ctxt-normalize, r=lcnr
Use ObligationCtxt::normalize

r? ```@lcnr```
2022-11-24 08:42:37 +01:00
bors
872631d0f0 Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiser
Use `as_deref` in compiler (but only where it makes sense)

This simplifies some code :3

(there are some changes that are not exacly `as_deref`, but more like "clever `Option`/`Result` method use")
2022-11-24 00:17:35 +00:00
Maybe Waffle
da40965300 Add Mutability::{is_mut,is_not} 2022-11-23 20:26:31 +00:00
Maybe Waffle
9b9c7d0ecc Depend on Mutability ordering 2022-11-23 20:26:31 +00:00
Camille GILLOT
fb7d25e978 Separate lifetime ident from resolution in HIR. 2022-11-23 19:33:06 +00:00
Santiago Pastorino
409203a315
Use ObligationCtxt::normalize 2022-11-23 11:32:49 -03:00