Skip to content

Commit

Permalink
Unrolled build for rust-lang#115624
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#115624 - compiler-errors:rtn-path, r=WaffleLapkin

Print the path of a return-position impl trait in trait when `return_type_notation` is enabled

When we're printing a return-position impl trait in trait, we usually just print it like an opaque. This is *usually* fine, but can be confusing when using `return_type_notation`. Print the path of the method from where the RPITIT originates when this feature gate is enabled.
  • Loading branch information
rust-timer authored Sep 8, 2023
2 parents 3d24970 + 748476d commit 026013a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
11 changes: 11 additions & 0 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,17 @@ pub trait PrettyPrinter<'tcx>:
}
}

if self.tcx().features().return_type_notation
&& let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = self.tcx().opt_rpitit_info(def_id)
&& let ty::Alias(_, alias_ty) = self.tcx().fn_sig(fn_def_id).skip_binder().output().skip_binder().kind()
&& alias_ty.def_id == def_id
{
let num_args = self.tcx().generics_of(fn_def_id).count();
write!(self, " {{ ")?;
self = self.print_def_path(fn_def_id, &args[..num_args])?;
write!(self, "() }}")?;
}

Ok(self)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ error: future cannot be sent between threads safely
LL | is_send(foo::<T>());
| ^^^^^^^^^^ future returned by `foo` is not `Send`
|
= help: within `impl Future<Output = Result<(), ()>>`, the trait `Send` is not implemented for `impl Future<Output = Result<(), ()>>`
= help: within `impl Future<Output = Result<(), ()>>`, the trait `Send` is not implemented for `impl Future<Output = Result<(), ()>> { <T as Foo>::method() }`
note: future is not `Send` as it awaits another future which is not `Send`
--> $DIR/basic.rs:13:5
|
LL | T::method().await?;
| ^^^^^^^^^^^ await occurs here on type `impl Future<Output = Result<(), ()>>`, which is not `Send`
| ^^^^^^^^^^^ await occurs here on type `impl Future<Output = Result<(), ()>> { <T as Foo>::method() }`, which is not `Send`
note: required by a bound in `is_send`
--> $DIR/basic.rs:17:20
|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/normalizing-self-auto-trait-issue-109924.rs:8:12
|
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
= note: `#[warn(incomplete_features)]` on by default

error[E0277]: `impl Future<Output = ()> { <_ as Foo>::bar() }` cannot be sent between threads safely
--> $DIR/normalizing-self-auto-trait-issue-109924.rs:23:11
|
LL | build(Bar);
| ----- ^^^ `impl Future<Output = ()> { <_ as Foo>::bar() }` cannot be sent between threads safely
| |
| required by a bound introduced by this call
|
= help: the trait `for<'a> Send` is not implemented for `impl Future<Output = ()> { <_ as Foo>::bar() }`
note: required by a bound in `build`
--> $DIR/normalizing-self-auto-trait-issue-109924.rs:20:39
|
LL | fn build<T>(_: T) where T: Foo<bar(): Send> {}
| ^^^^ required by this bound in `build`

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/normalizing-self-auto-trait-issue-109924.rs:8:12
|
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// revisions: current next
//[current] known-bug: #109924
//[next] check-pass
//[next] compile-flags: -Ztrait-solver=next
// edition:2021

#![feature(async_fn_in_trait)]
#![feature(return_type_notation)]
//[next]~^ WARN the feature `return_type_notation` is incomplete

trait Foo {
async fn bar(&self);
}

struct Bar;
impl Foo for Bar {
async fn bar(&self) {}
}

fn build<T>(_: T) where T: Foo<bar(): Send> {}

fn main() {
build(Bar);
}

0 comments on commit 026013a

Please sign in to comment.