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

Fix missing parens around dyn Trait-behind-ref after having added the + 'usability bound #13

Merged
merged 6 commits into from
Jul 17, 2024
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
25 changes: 21 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
strategy:
matrix:
rust-toolchains:
- 1.39.0 # MSRV
- 1.65.0 # MSRV
- stable
features__proc-macros: ["", "--features proc-macros"]
features__showme: ["", "--features showme"]
exclude:
- rust-toolchains: 1.39.0
- rust-toolchains: 1.65.0
features__showme: "--features showme"
steps:
- name: Install Rust toolchain
Expand Down Expand Up @@ -54,13 +54,13 @@ jobs:
- macos-latest
- windows-latest
rust-toolchains:
- 1.39.0
- 1.65.0
- stable
- nightly
exclude:
# This setup very often fails with a memory allocation failure on GH.
- os: windows-latest
rust-toolchains: 1.39.0
rust-toolchains: 1.65.0
steps:
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -95,6 +95,23 @@ jobs:
--features proc-macros
-- --nocapture

required-jobs:
name: 'All the required jobs'
needs:
- check
- build-and-test
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: 'Check success of the required jobs'
run: |
RESULT=$(echo "${ join(needs.*.result, '') }" | sed -e "s/success//g")
if [ -n "$RESULT" ]; then
echo "❌"
false
fi
echo "✅"

# == MIRI == #
# miri:
# name: Test with miri
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/future-proof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ jobs:
- macos-latest
- windows-latest
rust-toolchains:
- 1.39.0
- 1.65.0
- stable
- beta
- nightly
latest-lockfile: [true, false]
exclude:
# This setup very often fails with a memory allocation failure on GH.
- os: windows-latest
rust-toolchains: 1.39.0
rust-toolchains: 1.65.0
steps:
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
Expand Down
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fix-hidden-lifetime-bug"
version = "0.2.5"
version = "0.2.6"
authors = [
"Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>",
]
Expand All @@ -14,7 +14,7 @@ keywords = ["impl", "lifetime", "bug", "hidden", "bound"]

[dependencies.proc-macros]
package = "fix-hidden-lifetime-bug-proc_macros"
version = "0.2.5"
version = "=0.2.6"
path = "src/proc_macros"
optional = true

Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ https://github.com/danielhenrymantilla/fix_hidden_lifetime_bug.rs)
https://crates.io/crates/fix-hidden-lifetime-bug)
[![Documentation](https://docs.rs/fix-hidden-lifetime-bug/badge.svg)](
https://docs.rs/fix-hidden-lifetime-bug)
[![MSRV](https://img.shields.io/badge/MSRV-1.39.0-white)](
[![MSRV](https://img.shields.io/badge/MSRV-1.65.0-white)](
https://gist.github.com/danielhenrymantilla/8e5b721b3929084562f8f65668920c33)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](
https://github.com/rust-secure-code/safety-dance/)
Expand Down Expand Up @@ -59,12 +59,14 @@ https://github.com/danielhenrymantilla/fix_hidden_lifetime_bug.rs/actions)

<details><summary>Problematic code</summary>

```rust,compile_fail
```rust ,ignore
async fn bar<'a> (_: &(), _: Box<dyn Send>) {
/* … */
}
```

EDIT: Fixed as of 1.69.0

</details>

<br/>
Expand All @@ -85,12 +87,14 @@ https://github.com/danielhenrymantilla/fix_hidden_lifetime_bug.rs/actions)

<details><summary>Problematic code</summary>

```rust,compile_fail
```rust ,ignore
async fn baz<'a>(a: &'static (), b: &(), c: &()) {
/* … */
}
```

EDIT: Fixed as of 1.69.0

</details>

<br/>
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.39.0
1.65.0
2 changes: 1 addition & 1 deletion src/proc_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ proc-macro = true

[package]
name = "fix-hidden-lifetime-bug-proc_macros"
version = "0.2.5"
version = "0.2.6"
authors = [
"Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>",
]
Expand Down
24 changes: 24 additions & 0 deletions src/proc_macros/collect_lifetime_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,28 @@ impl VisitMut for Visitor<'_> {
dyn_trait.bounds.push(TypeParamBound::Lifetime(lt));
}
}

fn visit_type_mut (
self: &'_ mut Self,
type_: &mut Type,
)
{
// Subrecurse.
visit_mut::visit_type_mut(self, type_);
// When adding the `+ 'lt` as in our `dyn_trait.bounds.push()` above,
// we may end up with `&dyn Trait` becoming `&dyn Trait + '…`, which is
// not valid Rust (disambiguating parentheses are then required),
// see https://github.com/danielhenrymantilla/fix_hidden_lifetime_bug.rs/issues/12
match type_ {
Type::Reference(ref_) => match &*ref_.elem {
Type::TraitObject(dyn_trait) if dyn_trait.bounds.len() > 1 => {
*ref_.elem = parse_quote_spanned!(dyn_trait.span()=>
( #dyn_trait )
);
},
_ => {},
},
_ => {},
}
}
}
4 changes: 4 additions & 0 deletions tests/regressions/_012.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[::fix_hidden_lifetime_bug::fix_hidden_lifetime_bug]
fn example(_a: &dyn Send) -> impl Sized {
()
}
Loading