@@ -630,7 +630,7 @@ impl OwnedLocation {
630630/// are collected in this struct.
631631pub struct Spec < ' a , S , R > {
632632 subject : S ,
633- expression : Option < Expression < ' a > > ,
633+ expression : Expression < ' a > ,
634634 description : Option < Cow < ' a , str > > ,
635635 location : Option < Location < ' a > > ,
636636 failures : Vec < AssertFailure > ,
@@ -645,8 +645,8 @@ impl<S, R> Spec<'_, S, R> {
645645 }
646646
647647 /// Returns the expression (or subject name) if one has been set.
648- pub fn expression ( & self ) -> Option < & Expression < ' _ > > {
649- self . expression . as_ref ( )
648+ pub fn expression ( & self ) -> & Expression < ' _ > {
649+ & self . expression
650650 }
651651
652652 /// Returns the location in source code or test code if it has been set.
@@ -692,10 +692,10 @@ impl<'a, S, R> Spec<'a, S, R> {
692692 /// The diff format is set to "no highlighting". Failure messages will not
693693 /// highlight differences between the actual and the expected value.
694694 #[ must_use = "a spec does nothing unless an assertion method is called" ]
695- pub const fn new ( subject : S , failing_strategy : R ) -> Self {
695+ pub fn new ( subject : S , failing_strategy : R ) -> Self {
696696 Self {
697697 subject,
698- expression : None ,
698+ expression : Expression :: default ( ) ,
699699 description : None ,
700700 location : None ,
701701 failures : vec ! [ ] ,
@@ -707,7 +707,7 @@ impl<'a, S, R> Spec<'a, S, R> {
707707 /// Sets the subject name or expression for this assertion.
708708 #[ must_use = "a spec does nothing unless an assertion method is called" ]
709709 pub fn named ( mut self , subject_name : impl Into < Cow < ' a , str > > ) -> Self {
710- self . expression = Some ( Expression ( subject_name. into ( ) ) ) ;
710+ self . expression = Expression ( subject_name. into ( ) ) ;
711711 self
712712 }
713713
@@ -883,9 +883,8 @@ where
883883 #[ track_caller]
884884 pub fn expecting ( mut self , mut expectation : impl Expectation < S > ) -> Self {
885885 if !expectation. test ( & self . subject ) {
886- let default_expression = Expression :: default ( ) ;
887- let expression = self . expression . as_ref ( ) . unwrap_or ( & default_expression) ;
888- let message = expectation. message ( expression, & self . subject , false , & self . diff_format ) ;
886+ let message =
887+ expectation. message ( & self . expression , & self . subject , false , & self . diff_format ) ;
889888 self . do_fail_with_message ( message) ;
890889 }
891890 self
@@ -976,7 +975,7 @@ where
976975 /// Fails the assertion according the current failing strategy of this
977976 /// `Spec`.
978977 #[ track_caller]
979- fn do_fail_with_message ( & mut self , message : impl Into < String > ) {
978+ pub fn do_fail_with_message ( & mut self , message : impl Into < String > ) {
980979 let message = message. into ( ) ;
981980 let failure = AssertFailure {
982981 description : self . description . clone ( ) . map ( String :: from) ,
@@ -1105,14 +1104,13 @@ impl<'a, I, R> Spec<'a, I, R> {
11051104 I : IntoIterator < Item = T > ,
11061105 A : Fn ( Spec < ' a , T , CollectFailures > ) -> Spec < ' a , B , CollectFailures > ,
11071106 {
1108- let default_expression = & Expression :: default ( ) ;
1109- let root_expression = self . expression . as_ref ( ) . unwrap_or ( default_expression) ;
1107+ let root_expression = & self . expression ;
11101108 let mut position = -1 ;
11111109 for item in self . subject {
11121110 position += 1 ;
11131111 let element_spec = Spec {
11141112 subject : item,
1115- expression : Some ( format ! ( "{root_expression} [{position}]" ) . into ( ) ) ,
1113+ expression : format ! ( "{root_expression} [{position}]" ) . into ( ) ,
11161114 description : None ,
11171115 location : self . location ,
11181116 failures : vec ! [ ] ,
@@ -1185,15 +1183,14 @@ impl<'a, I, R> Spec<'a, I, R> {
11851183 I : IntoIterator < Item = T > ,
11861184 A : Fn ( Spec < ' a , T , CollectFailures > ) -> Spec < ' a , B , CollectFailures > ,
11871185 {
1188- let default_expression = & Expression :: default ( ) ;
1189- let root_expression = self . expression . as_ref ( ) . unwrap_or ( default_expression) ;
1186+ let root_expression = & self . expression ;
11901187 let mut any_success = false ;
11911188 let mut position = -1 ;
11921189 for item in self . subject {
11931190 position += 1 ;
11941191 let element_spec = Spec {
11951192 subject : item,
1196- expression : Some ( format ! ( "{root_expression} [{position}]" ) . into ( ) ) ,
1193+ expression : format ! ( "{root_expression} [{position}]" ) . into ( ) ,
11971194 description : None ,
11981195 location : self . location ,
11991196 failures : vec ! [ ] ,
0 commit comments