@@ -54,6 +54,8 @@ pub struct Session {
54
54
/// The maximum recursion limit for potentially infinitely recursive
55
55
/// operations such as auto-dereference and monomorphization.
56
56
pub recursion_limit : Cell < uint > ,
57
+
58
+ pub can_print_warnings : bool
57
59
}
58
60
59
61
impl Session {
@@ -82,13 +84,19 @@ impl Session {
82
84
self . diagnostic ( ) . handler ( ) . abort_if_errors ( )
83
85
}
84
86
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
+ }
86
90
}
87
91
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
+ }
89
95
}
90
96
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
+ }
92
100
}
93
101
pub fn opt_span_warn ( & self , opt_sp : Option < Span > , msg : & str ) {
94
102
match opt_sp {
@@ -247,6 +255,13 @@ pub fn build_session_(sopts: config::Options,
247
255
}
248
256
) ;
249
257
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
+
250
265
let sess = Session {
251
266
target : target_cfg,
252
267
opts : sopts,
@@ -265,6 +280,7 @@ pub fn build_session_(sopts: config::Options,
265
280
crate_metadata : RefCell :: new ( Vec :: new ( ) ) ,
266
281
features : RefCell :: new ( feature_gate:: Features :: new ( ) ) ,
267
282
recursion_limit : Cell :: new ( 64 ) ,
283
+ can_print_warnings : can_print_warnings
268
284
} ;
269
285
270
286
sess. lint_store . borrow_mut ( ) . register_builtin ( Some ( & sess) ) ;
0 commit comments