Expression with ill-formed type

Open Beginner friendly
#158 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
94/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
cli

Research direction

Open parser/src/lib.rs around lines 90–100 and read the self.parse_top match described in the issue. Remove the extra reference operator as specified, then run the parser crate’s tests or compile check. Done when the crate compiles with the Rust lifetime fix.

Written by the indexing model from the issue text.

Description

In some cases, the compiler has accidentally allowed types' lifetime constraints to be bypassed (e.g., &'a T requires that T: 'a), which causes... problems. The parser crate here somehow managed to be affected, and this bug fix would cause it to no longer compile: https://github.com/rust-lang/rust/pull/164277

Thankfully, AFAICT, a one-character fix is enough.

Problem and explanation

The problem lies here: https://github.com/uutils/awk/blob/c7a7cd64d68507d61b125f02713850cf1973a06d/parser/src/lib.rs#L90-L100

Let's say that the lifetime of the outer reference type of &mut self is 'b and the lifetime of the outer reference type of &self.parse_top(&mut lex, true) is 'c.

Then, &self.parse_top(&mut lex, true) has type &'c Result<&'b Ast<'a>>, and in the error branch, error has type &'c ParsingError. self is mutably (exclusively) borrowed until 'b expires, error cannot outlive 'c, and self is borrowed again before the last usage of error. This could only occur if 'b is strictly shorter than 'c, which makes type &'c Result<&'b Ast<'a>> ill-formed (we have a &'c T without T: 'c). So, with a bug fix, this would be rejected.

Fix

Match self.parse_top(&mut lex, true) instead of &self.parse_top(&mut lex, true). Just remove one ampersand.

Dominant language
Rust
Stars
30
Forks
10
Avg merge
1d 8h
Merged PRs (30d)
17

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from uutils/awk

All issues in uutils/awk

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.