Opened 12 months ago

Last modified 5 months ago

#27207 new defect

Examples in CodingStandardsRust.md are wrong

Reported by: cyberpunks Owned by:
Priority: Medium Milestone: Tor: unspecified
Component: Core Tor/Tor Version:
Severity: Normal Keywords: rust, doc, 035-deferred-20190115, 041-proposed, easy
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

The section on CString is incorrect:

  • CString::new("bl\x00ah").unwrap().into_raw() will panic in the 'unwrap' call, it will never return a pointer of any kind, dangling or otherwise.

Also, 12cf04646c571646b726e697d66ecafad7886cf2 seems to be the result of some miscommunication with withoutboats:

  • .expect() is literally '.unwrap(), but with a custom panic message,' it doesn't return an Option and is no safer than unwrap, but it is self-documenting.

Child Tickets

TicketStatusOwnerSummaryComponent
#29979closedDon't recommend expect() in CodingStandardsRust, because it panicsCore Tor/Tor

Change History (8)

comment:1 Changed 12 months ago by nickm

Milestone: Tor: 0.3.5.x-final

comment:2 Changed 12 months ago by teor

Maybe we should make CodingStandardsRust.md into a doctest, so we actually run the code.

comment:3 in reply to:  description Changed 11 months ago by Killer2514

Replying to cyberpunks:

The section on CString is incorrect:

  • CString::new("bl\x00ah").unwrap().into_raw() will panic in the 'unwrap' call, it will never return a pointer of any kind, dangling or otherwise.

Also, 12cf04646c571646b726e697d66ecafad7886cf2 seems to be the result of some miscommunication with withoutboats:

  • .expect() is literally '.unwrap(), but with a custom panic message,' it doesn't return an Option and is no safer than unwrap, but it is self-documenting.

comment:4 Changed 11 months ago by nickm

Summary: CodingStandardsRust.md is wrongExamples in CodingStandardsRust.md are wrong

comment:5 in reply to:  4 Changed 11 months ago by cyberpunks

Replying to nickm:

Summary: CodingStandardsRust.md is wrong → Examples in CodingStandardsRust.md are wrong

The problem isn't just rust code examples that don't compile, the words in English are wrong, too.

comment:6 Changed 7 months ago by nickm

Keywords: 035-deferred-20190115 041-proposed added
Milestone: Tor: 0.3.5.x-finalTor: unspecified

Marking a number of 0.3.5 tickets as possible, maybe even a good idea, for later. Possibly backportable, some of them. But not currently things to do as part of 0.3.5 stabilization.

comment:7 Changed 6 months ago by chelseakomlo

Keywords: easy added

comment:8 Changed 5 months ago by teor

#29979 fixes the expect(), but not the code examples.

Note: See TracTickets for help on using tickets.