Skip to content
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

Remove defaults from trait params when using them in function definition #123

Merged
merged 3 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ fn transform_block(
};

let mut outer_generics = generics.clone();
for p in &mut outer_generics.params {
match p {
GenericParam::Type(t) => {
let _ = t.default.take();
}
GenericParam::Const(c) => {
let _ = c.default.take();
}
GenericParam::Lifetime(_) => {}
}
}
if !has_self {
if let Some(mut where_clause) = outer_generics.where_clause {
where_clause.predicates = where_clause
Expand Down
26 changes: 22 additions & 4 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ pub mod issue92 {
}

// https://github.com/dtolnay/async-trait/issues/104
mod issue104 {
pub mod issue104 {
use async_trait::async_trait;

#[async_trait]
Expand All @@ -909,7 +909,7 @@ mod issue104 {
}

// https://github.com/dtolnay/async-trait/issues/106
mod issue106 {
pub mod issue106 {
use async_trait::async_trait;
use std::future::Future;

Expand Down Expand Up @@ -941,7 +941,7 @@ mod issue106 {
}

// https://github.com/dtolnay/async-trait/issues/110
mod issue110 {
pub mod issue110 {
#![deny(clippy::all)]

use async_trait::async_trait;
Expand All @@ -963,7 +963,7 @@ mod issue110 {
}

// https://github.com/dtolnay/async-trait/issues/120
mod issue120 {
pub mod issue120 {
#![deny(clippy::trivially_copy_pass_by_ref)]

use async_trait::async_trait;
Expand All @@ -978,3 +978,21 @@ mod issue120 {
async fn f(&self) {}
}
}

// https://github.com/dtolnay/async-trait/pulls/123
pub mod pull123 {
use async_trait::async_trait;

#[async_trait]
trait Trait<T = ()> {
async fn f(&self) -> &str
where
T: 'async_trait,
{
"default"
}
}

#[async_trait]
impl<T> Trait<T> for () {}
}