@@ -54,6 +54,8 @@ pub struct Session {
5454 /// The maximum recursion limit for potentially infinitely recursive
5555 /// operations such as auto-dereference and monomorphization.
5656 pub recursion_limit : Cell < uint > ,
57+
58+ pub can_print_warnings : bool
5759}
5860
5961impl Session {
@@ -82,13 +84,19 @@ impl Session {
8284 self . diagnostic ( ) . handler ( ) . abort_if_errors ( )
8385 }
8486 pub fn span_warn ( & self , sp : Span , msg : & str ) {
85- self . diagnostic ( ) . span_warn ( sp, msg)
87+ if self . can_print_warnings {
88+ self . diagnostic ( ) . span_warn ( sp, msg)
89+ }
8690 }
8791 pub fn span_warn_with_code ( & self , sp : Span , msg : & str , code : & str ) {
88- self . diagnostic ( ) . span_warn_with_code ( sp, msg, code)
92+ if self . can_print_warnings {
93+ self . diagnostic ( ) . span_warn_with_code ( sp, msg, code)
94+ }
8995 }
9096 pub fn warn ( & self , msg : & str ) {
91- self . diagnostic ( ) . handler ( ) . warn ( msg)
97+ if self . can_print_warnings {
98+ self . diagnostic ( ) . handler ( ) . warn ( msg)
99+ }
92100 }
93101 pub fn opt_span_warn ( & self , opt_sp : Option < Span > , msg : & str ) {
94102 match opt_sp {
@@ -247,6 +255,13 @@ pub fn build_session_(sopts: config::Options,
247255 }
248256 ) ;
249257
258+ let can_print_warnings = sopts. lint_opts
259+ . iter ( )
260+ . filter ( |& & ( ref key, _) | key. as_slice ( ) == "warnings" )
261+ . map ( |& ( _, ref level) | * level != lint:: Allow )
262+ . last ( )
263+ . unwrap_or ( true ) ;
264+
250265 let sess = Session {
251266 target : target_cfg,
252267 opts : sopts,
@@ -265,6 +280,7 @@ pub fn build_session_(sopts: config::Options,
265280 crate_metadata : RefCell :: new ( Vec :: new ( ) ) ,
266281 features : RefCell :: new ( feature_gate:: Features :: new ( ) ) ,
267282 recursion_limit : Cell :: new ( 64 ) ,
283+ can_print_warnings : can_print_warnings
268284 } ;
269285
270286 sess. lint_store . borrow_mut ( ) . register_builtin ( Some ( & sess) ) ;
0 commit comments