Skip to content

Rollup of 6 pull requests #103696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
328f817
Make `CStr::from_ptr` `const`.
reitermarkus Oct 12, 2022
36dbb07
Update docs for `CStr::from_ptr`.
reitermarkus Oct 12, 2022
4accf83
Note scope of TAIT more accurately
compiler-errors Oct 22, 2022
e521a8d
Prevent foreign Rust exceptions from being caught
nbdd0121 Oct 5, 2022
86c65d2
Implement Rust foreign exception protection for EMCC and SEH
nbdd0121 Oct 5, 2022
daf3063
Add test case for foreign Rust exceptions
nbdd0121 Oct 5, 2022
979d1a2
Apply suggestion
nbdd0121 Oct 11, 2022
4e6d60c
Fix alloc size
nbdd0121 Oct 12, 2022
c9cca33
Fix windows compilation
nbdd0121 Oct 23, 2022
8b494f4
Allow `impl Fn() -> impl Trait` in return position
WaffleLapkin Feb 2, 2022
7a4ba2f
Add more tests for `impl Fn() -> impl Trait`
WaffleLapkin Jun 23, 2022
00f2277
Add even more tests for `impl Fn() -> impl Trait`
WaffleLapkin Jun 23, 2022
cc752f5
Feature gate `impl_trait_in_fn_trait_return`
WaffleLapkin Jul 24, 2022
d116859
--bless
WaffleLapkin Jul 28, 2022
690e037
add a test for gate `impl_trait_in_fn_trait_return`
WaffleLapkin Jul 28, 2022
e93982a
adopt to compiler changes
WaffleLapkin Oct 25, 2022
bfac2da
Ignore test on mingw32
nbdd0121 Oct 26, 2022
92b314b
add test for issue 98634
Rageking8 Oct 21, 2022
ae0232e
improve `filesearch::get_or_default_sysroot` r=ozkanonur
onur-ozkan Oct 28, 2022
b3f9277
Remove unneeded attribute.
reitermarkus Oct 28, 2022
0e8f28d
Rollup merge of #93582 - WaffleLapkin:rpitirpit, r=compiler-errors
Dylan-DPC Oct 28, 2022
cfe440e
Rollup merge of #102721 - nbdd0121:panic, r=Amanieu
Dylan-DPC Oct 28, 2022
db43536
Rollup merge of #102961 - reitermarkus:const-cstr-from-ptr, r=oli-obk
Dylan-DPC Oct 28, 2022
a0a9ade
Rollup merge of #103342 - Rageking8:add-test-for-issue-98634, r=compi…
Dylan-DPC Oct 28, 2022
ebd8e5c
Rollup merge of #103383 - compiler-errors:tait-scope, r=oli-obk
Dylan-DPC Oct 28, 2022
9aa9a53
Rollup merge of #103660 - ozkanonur:master, r=jyn514
Dylan-DPC Oct 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.lower_angle_bracketed_parameter_data(data, param_mode, itctx)
}
GenericArgs::Parenthesized(ref data) => match parenthesized_generic_args {
ParenthesizedGenericArgs::Ok => self.lower_parenthesized_parameter_data(data),
ParenthesizedGenericArgs::Ok => {
self.lower_parenthesized_parameter_data(data, itctx)
}
ParenthesizedGenericArgs::Err => {
// Suggest replacing parentheses with angle brackets `Trait(params...)` to `Trait<params...>`
let sub = if !data.inputs.is_empty() {
Expand Down Expand Up @@ -344,6 +346,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_parenthesized_parameter_data(
&mut self,
data: &ParenthesizedArgs,
itctx: &ImplTraitContext,
) -> (GenericArgsCtor<'hir>, bool) {
// Switch to `PassThrough` mode for anonymous lifetimes; this
// means that we permit things like `&Ref<T>`, where `Ref` has
Expand All @@ -355,6 +358,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.lower_ty_direct(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitParam))
}));
let output_ty = match output {
// Only allow `impl Trait` in return position. i.e.:
// ```rust
// fn f(_: impl Fn() -> impl Debug) -> impl Fn() -> impl Debug
// // disallowed --^^^^^^^^^^ allowed --^^^^^^^^^^
// ```
FnRetTy::Ty(ty)
if matches!(itctx, ImplTraitContext::ReturnPositionOpaqueTy { .. })
&& self.tcx.features().impl_trait_in_fn_trait_return =>
{
self.lower_ty(&ty, itctx)
}
FnRetTy::Ty(ty) => {
self.lower_ty(&ty, &ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn))
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ declare_features! (
(active, half_open_range_patterns_in_slices, "CURRENT_RUSTC_VERSION", Some(67264), None),
/// Allows `if let` guard in match arms.
(active, if_let_guard, "1.47.0", Some(51114), None),
/// Allows `impl Trait` as output type in `Fn` traits in return position of functions.
(active, impl_trait_in_fn_trait_return, "1.64.0", Some(99697), None),
/// Allows using imported `main` function
(active, imported_main, "1.53.0", Some(28937), None),
/// Allows associated types in inherent impls.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ symbols! {
impl_lint_pass,
impl_macros,
impl_trait_in_bindings,
impl_trait_in_fn_trait_return,
implied_by,
import,
import_name_type,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn f() -> impl Fn() -> impl Sized { || () }
//~^ ERROR `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return
fn g() -> &'static dyn Fn() -> impl Sized { &|| () }
//~^ ERROR `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return
--> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:1:24
|
LL | fn f() -> impl Fn() -> impl Sized { || () }
| ^^^^^^^^^^

error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return
--> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:3:32
|
LL | fn g() -> &'static dyn Fn() -> impl Sized { &|| () }
| ^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0562`.
8 changes: 8 additions & 0 deletions src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(impl_trait_in_fn_trait_return)]
use std::fmt::Debug;

fn a() -> impl Fn(&u8) -> impl Debug {
|x| x //~ ERROR hidden type for `impl Debug` captures lifetime that does not appear in bounds
}

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/impl-trait/impl-fn-hrtb-bounds-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0700]: hidden type for `impl Debug` captures lifetime that does not appear in bounds
--> $DIR/impl-fn-hrtb-bounds-2.rs:5:9
|
LL | |x| x
| --- ^
| |
| hidden type `&u8` captures the anonymous lifetime #1 defined here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0700`.
24 changes: 24 additions & 0 deletions src/test/ui/impl-trait/impl-fn-hrtb-bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![feature(impl_trait_in_fn_trait_return)]
use std::fmt::Debug;

fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|x| x
}

fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|x| x
}

fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|x| x
}

fn d() -> impl Fn() -> (impl Debug + '_) {
//~^ ERROR missing lifetime specifier
|| ()
}

fn main() {}
51 changes: 51 additions & 0 deletions src/test/ui/impl-trait/impl-fn-hrtb-bounds.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
error[E0106]: missing lifetime specifier
--> $DIR/impl-fn-hrtb-bounds.rs:19:38
|
LL | fn d() -> impl Fn() -> (impl Debug + '_) {
| ^^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime
|
LL | fn d() -> impl Fn() -> (impl Debug + 'static) {
| ~~~~~~~

error: higher kinded lifetime bounds on nested opaque types are not supported yet
--> $DIR/impl-fn-hrtb-bounds.rs:4:41
|
LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
| ^^
|
note: lifetime declared here
--> $DIR/impl-fn-hrtb-bounds.rs:4:19
|
LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
| ^

error: higher kinded lifetime bounds on nested opaque types are not supported yet
--> $DIR/impl-fn-hrtb-bounds.rs:9:52
|
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
| ^^
|
note: lifetime declared here
--> $DIR/impl-fn-hrtb-bounds.rs:9:20
|
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
| ^^

error: higher kinded lifetime bounds on nested opaque types are not supported yet
--> $DIR/impl-fn-hrtb-bounds.rs:14:52
|
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
| ^^
|
note: lifetime declared here
--> $DIR/impl-fn-hrtb-bounds.rs:14:20
|
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
| ^^

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0106`.
15 changes: 15 additions & 0 deletions src/test/ui/impl-trait/impl-fn-parsing-ambiguities.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![feature(impl_trait_in_fn_trait_return)]
use std::fmt::Debug;

fn a() -> impl Fn(&u8) -> impl Debug + '_ {
//~^ ERROR ambiguous `+` in a type
//~^^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|x| x
}

fn b() -> impl Fn() -> impl Debug + Send {
//~^ ERROR ambiguous `+` in a type
|| ()
}

fn main() {}
26 changes: 26 additions & 0 deletions src/test/ui/impl-trait/impl-fn-parsing-ambiguities.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: ambiguous `+` in a type
--> $DIR/impl-fn-parsing-ambiguities.rs:4:27
|
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
| ^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + '_)`

error: ambiguous `+` in a type
--> $DIR/impl-fn-parsing-ambiguities.rs:10:24
|
LL | fn b() -> impl Fn() -> impl Debug + Send {
| ^^^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + Send)`

error: higher kinded lifetime bounds on nested opaque types are not supported yet
--> $DIR/impl-fn-parsing-ambiguities.rs:4:40
|
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
| ^^
|
note: lifetime declared here
--> $DIR/impl-fn-parsing-ambiguities.rs:4:19
|
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
| ^

error: aborting due to 3 previous errors

15 changes: 15 additions & 0 deletions src/test/ui/impl-trait/impl-fn-predefined-lifetimes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![feature(impl_trait_in_fn_trait_return)]
use std::fmt::Debug;

fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
//~^ ERROR cannot resolve opaque type

|x| x
//~^ ERROR concrete type differs from previous defining opaque type use
}

fn _b<'a>() -> impl Fn(&'a u8) -> (impl Debug + 'a) {
a()
}

fn main() {}
24 changes: 24 additions & 0 deletions src/test/ui/impl-trait/impl-fn-predefined-lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error: concrete type differs from previous defining opaque type use
--> $DIR/impl-fn-predefined-lifetimes.rs:7:9
|
LL | |x| x
| ^ expected `impl Debug + '_`, got `&u8`
|
note: previous use here
--> $DIR/impl-fn-predefined-lifetimes.rs:7:5
|
LL | |x| x
| ^^^^^

error[E0720]: cannot resolve opaque type
--> $DIR/impl-fn-predefined-lifetimes.rs:4:35
|
LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
| ^^^^^^^^^^^^^^^ recursive opaque type
...
LL | |x| x
| ----- returning here with type `[closure@$DIR/impl-fn-predefined-lifetimes.rs:7:5: 7:8]`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0720`.
26 changes: 26 additions & 0 deletions src/test/ui/impl-trait/impl_fn_associativity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// run-pass
#![feature(impl_trait_in_fn_trait_return)]
use std::fmt::Debug;

fn f_debug() -> impl Fn() -> impl Debug {
|| ()
}

fn ff_debug() -> impl Fn() -> impl Fn() -> impl Debug {
|| f_debug()
}

fn multi() -> impl Fn() -> (impl Debug + Send) {
|| ()
}

fn main() {
// Check that `ff_debug` is `() -> (() -> Debug)` and not `(() -> ()) -> Debug`
let debug = ff_debug()()();
assert_eq!(format!("{:?}", debug), "()");

let x = multi()();
assert_eq!(format!("{:?}", x), "()");
fn assert_send(_: &impl Send) {}
assert_send(&x);
}
4 changes: 2 additions & 2 deletions src/test/ui/impl-trait/nested_impl_trait.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(impl_trait_in_fn_trait_return)]
use std::fmt::Debug;

fn fine(x: impl Into<u32>) -> impl Into<u32> { x }
Expand Down Expand Up @@ -25,8 +26,7 @@ fn allowed_in_assoc_type() -> impl Iterator<Item=impl Fn()> {
}

fn allowed_in_ret_type() -> impl Fn() -> impl Into<u32> {
//~^ `impl Trait` only allowed in function and inherent method return types
|| 5
|| 5u8
}

fn main() {}
22 changes: 8 additions & 14 deletions src/test/ui/impl-trait/nested_impl_trait.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0666]: nested `impl Trait` is not allowed
--> $DIR/nested_impl_trait.rs:5:56
--> $DIR/nested_impl_trait.rs:6:56
|
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| ----------^^^^^^^^^^-
Expand All @@ -8,7 +8,7 @@ LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| outer `impl Trait`

error[E0666]: nested `impl Trait` is not allowed
--> $DIR/nested_impl_trait.rs:9:42
--> $DIR/nested_impl_trait.rs:10:42
|
LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
| ----------^^^^^^^^^^-
Expand All @@ -17,7 +17,7 @@ LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
| outer `impl Trait`

error[E0666]: nested `impl Trait` is not allowed
--> $DIR/nested_impl_trait.rs:13:37
--> $DIR/nested_impl_trait.rs:14:37
|
LL | fn bad_in_arg_position(_: impl Into<impl Debug>) { }
| ----------^^^^^^^^^^-
Expand All @@ -26,7 +26,7 @@ LL | fn bad_in_arg_position(_: impl Into<impl Debug>) { }
| outer `impl Trait`

error[E0666]: nested `impl Trait` is not allowed
--> $DIR/nested_impl_trait.rs:18:44
--> $DIR/nested_impl_trait.rs:19:44
|
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| ----------^^^^^^^^^^-
Expand All @@ -35,19 +35,13 @@ LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| outer `impl Trait`

error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `fn` pointer return
--> $DIR/nested_impl_trait.rs:9:32
--> $DIR/nested_impl_trait.rs:10:32
|
LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
| ^^^^^^^^^^^^^^^^^^^^^

error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return
--> $DIR/nested_impl_trait.rs:27:42
|
LL | fn allowed_in_ret_type() -> impl Fn() -> impl Into<u32> {
| ^^^^^^^^^^^^^^

error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
--> $DIR/nested_impl_trait.rs:5:46
--> $DIR/nested_impl_trait.rs:6:46
|
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Debug`
Expand All @@ -56,15 +50,15 @@ LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`

error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
--> $DIR/nested_impl_trait.rs:18:34
--> $DIR/nested_impl_trait.rs:19:34
|
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Debug`
|
= help: the trait `Into<U>` is implemented for `T`
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`

error: aborting due to 8 previous errors
error: aborting due to 7 previous errors

Some errors have detailed explanations: E0277, E0562, E0666.
For more information about an error, try `rustc --explain E0277`.
Loading