Skip to content

Commit

Permalink
Fix all 'assigned but unused variable' warnings
Browse files Browse the repository at this point in the history
- The variables in content_location_parser appear to have been copied
  from content_disposition_parser but are unused
- Ragel seems to always generate a useless testEof variable. The `if
  false` trick is also used in whitequark/parser@21581a2 to suppress the
  warning. As mentioned in the parser commit, `if false` will not
  actually generate instructions and so it has no runtime cost.

Co-authored-by: Guilherme Quirino <[email protected]>
  • Loading branch information
2 people authored and eval committed Jun 3, 2024
1 parent 80065af commit d629660
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/mail/parsers/address_lists_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33228,6 +33228,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 2461
raise Mail::Field::IncompleteParseError.new(Mail::AddressList, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/address_lists_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::AddressList, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/content_disposition_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 40
raise Mail::Field::IncompleteParseError.new(Mail::ContentDispositionElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/content_disposition_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::ContentDispositionElement, data, p)
end
Expand Down
6 changes: 5 additions & 1 deletion lib/mail/parsers/content_location_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def self.parse(data)
return content_location if Mail::Utilities.blank?(data)

# Parser state
disp_type_s = param_attr_s = param_attr = qstr_s = qstr = param_val_s = nil
qstr_s = qstr = param_val_s = nil

# 5.1 Variables Used by Ragel
p = 0
Expand Down Expand Up @@ -808,6 +808,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 32
raise Mail::Field::IncompleteParseError.new(Mail::ContentLocationElement, data, p)
end
Expand Down
6 changes: 5 additions & 1 deletion lib/mail/parsers/content_location_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Mail::Parsers
return content_location if Mail::Utilities.blank?(data)

# Parser state
disp_type_s = param_attr_s = param_attr = qstr_s = qstr = param_val_s = nil
qstr_s = qstr = param_val_s = nil

# 5.1 Variables Used by Ragel
p = 0
Expand All @@ -64,6 +64,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::ContentLocationElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/content_transfer_encoding_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 21
raise Mail::Field::IncompleteParseError.new(Mail::ContentTransferEncodingElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/content_transfer_encoding_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::ContentTransferEncodingElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/content_type_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 47
raise Mail::Field::IncompleteParseError.new(Mail::ContentTypeElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/content_type_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::ContentTypeElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/date_time_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 103
raise Mail::Field::IncompleteParseError.new(Mail::DateTimeElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/date_time_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::DateTimeElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/envelope_from_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3661,6 +3661,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 257
raise Mail::Field::IncompleteParseError.new(Mail::EnvelopeFromElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/envelope_from_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::EnvelopeFromElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/message_ids_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5147,6 +5147,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 318
raise Mail::Field::IncompleteParseError.new(Mail::MessageIdsElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/message_ids_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::MessageIdsElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/mime_version_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 23
raise Mail::Field::IncompleteParseError.new(Mail::MimeVersionElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/mime_version_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::MimeVersionElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/phrase_lists_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 42
raise Mail::Field::IncompleteParseError.new(Mail::PhraseList, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/phrase_lists_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::PhraseList, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/received_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8768,6 +8768,10 @@ def self.parse(data)
end
end

if false
testEof
end

if p != eof || cs < 648
raise Mail::Field::IncompleteParseError.new(Mail::ReceivedElement, data, p)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mail/parsers/received_parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ module Mail::Parsers
%%write init;
%%write exec;

if false
testEof
end

if p != eof || cs < %%{ write first_final; }%%
raise Mail::Field::IncompleteParseError.new(Mail::ReceivedElement, data, p)
end
Expand Down
2 changes: 0 additions & 2 deletions spec/mail/network/delivery_methods/smtp_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
end

it "should not dot-stuff unterminated last line with no leading dot" do
body = "this is a test\n.\nonly a test"

Mail.deliver do
from '[email protected]'
to '[email protected]'
Expand Down

0 comments on commit d629660

Please sign in to comment.