@@ -140,6 +140,7 @@ pub struct MessageInfo {
140140 pub stdout_needs_erase : bool ,
141141 pub stderr_needs_erase : bool ,
142142 pub cross_debug : bool ,
143+ pub has_warned : bool ,
143144}
144145
145146impl MessageInfo {
@@ -153,6 +154,7 @@ impl MessageInfo {
153154 . as_deref ( )
154155 . map ( bool_from_envvar)
155156 . unwrap_or_default ( ) ,
157+ has_warned : false ,
156158 }
157159 }
158160
@@ -231,13 +233,15 @@ impl MessageInfo {
231233 /// prints a red 'error' message.
232234 #[ track_caller]
233235 pub fn error < T : fmt:: Display > ( & mut self , message : T ) -> Result < ( ) > {
236+ self . has_warned = true ;
234237 self . stderr_check_erase ( ) ?;
235238 status ! ( @stderr cross_prefix!( "error" ) , Some ( & message) , red, self )
236239 }
237240
238241 /// prints an amber 'warning' message.
239242 #[ track_caller]
240243 pub fn warn < T : fmt:: Display > ( & mut self , message : T ) -> Result < ( ) > {
244+ self . has_warned = true ;
241245 match self . verbosity {
242246 Verbosity :: Quiet => Ok ( ( ) ) ,
243247 _ => status ! ( @stderr
@@ -371,6 +375,15 @@ impl MessageInfo {
371375
372376 Ok ( ( ) )
373377 }
378+
379+ /// Returns true if we've previously warned or errored, and we're in CI or `CROSS_NO_WARNINGS` has been set.
380+ ///
381+ /// This is used so that unexpected warnings and errors cause ci to fail.
382+ pub fn should_fail ( & self ) -> bool {
383+ // FIXME: store env var
384+ env:: var ( "CROSS_NO_WARNINGS" ) . map_or_else ( |_| is_ci:: cached ( ) , |env| bool_from_envvar ( & env) )
385+ && self . has_warned
386+ }
374387}
375388
376389impl Default for MessageInfo {
0 commit comments