@@ -84,7 +84,7 @@ impl<'s> LintLevelsBuilder<'s> {
8484 }
8585
8686 fn process_command_line ( & mut self , sess : & Session , store : & LintStore ) {
87- let mut specs = FxHashMap :: default ( ) ;
87+ self . sets . list . push ( LintSet :: CommandLine { specs : FxHashMap :: default ( ) } ) ;
8888 self . sets . lint_cap = sess. opts . lint_cap . unwrap_or ( Level :: Forbid ) ;
8989
9090 for & ( ref lint_name, level) in & sess. opts . lint_opts {
@@ -105,7 +105,17 @@ impl<'s> LintLevelsBuilder<'s> {
105105 for id in ids {
106106 self . check_gated_lint ( id, DUMMY_SP ) ;
107107 let src = LintLevelSource :: CommandLine ( lint_flag_val, orig_level) ;
108- specs. insert ( id, ( level, src) ) ;
108+ let specs = match self . sets . list . last ( ) . unwrap ( ) {
109+ LintSet :: CommandLine { ref specs } => specs,
110+ _ => unreachable ! ( ) ,
111+ } ;
112+ if self . check_before_insert_spec ( specs, id, ( level, src) ) {
113+ let specs = match self . sets . list . last_mut ( ) . unwrap ( ) {
114+ LintSet :: CommandLine { ref mut specs } => specs,
115+ _ => unreachable ! ( ) ,
116+ } ;
117+ specs. insert ( id, ( level, src) ) ;
118+ }
109119 }
110120 }
111121
@@ -122,15 +132,12 @@ impl<'s> LintLevelsBuilder<'s> {
122132 self . sets . list . push ( LintSet :: CommandLine { specs } ) ;
123133 }
124134
125- /// Attempts to insert the `id` to `level_src` map entry. If unsuccessful
126- /// (e.g. if a forbid was already inserted on the same scope), then emits a
127- /// diagnostic with no change to `specs`.
128- fn insert_spec (
129- & mut self ,
130- specs : & mut FxHashMap < LintId , LevelAndSource > ,
135+ fn check_before_insert_spec (
136+ & self ,
137+ specs : & FxHashMap < LintId , LevelAndSource > ,
131138 id : LintId ,
132139 ( level, src) : LevelAndSource ,
133- ) {
140+ ) -> bool {
134141 // Setting to a non-forbid level is an error if the lint previously had
135142 // a forbid level. Note that this is not necessarily true even with a
136143 // `#[forbid(..)]` attribute present, as that is overriden by `--cap-lints`.
@@ -212,11 +219,25 @@ impl<'s> LintLevelsBuilder<'s> {
212219 // issuing a FCW. In the FCW case, we want to
213220 // respect the new setting.
214221 if !fcw_warning {
215- return ;
222+ return false ;
216223 }
217224 }
218225 }
219- specs. insert ( id, ( level, src) ) ;
226+ true
227+ }
228+
229+ /// Attempts to insert the `id` to `level_src` map entry. If unsuccessful
230+ /// (e.g. if a forbid was already inserted on the same scope), then emits a
231+ /// diagnostic with no change to `specs`.
232+ fn insert_spec (
233+ & mut self ,
234+ specs : & mut FxHashMap < LintId , LevelAndSource > ,
235+ id : LintId ,
236+ ( level, src) : LevelAndSource ,
237+ ) {
238+ if self . check_before_insert_spec ( specs, id, ( level, src) ) {
239+ specs. insert ( id, ( level, src) ) ;
240+ }
220241 }
221242
222243 /// Pushes a list of AST lint attributes onto this context.
0 commit comments