]> git.lizzy.rs Git - rust.git/commitdiff
Fix the tests
authorest31 <MTest31@outlook.com>
Wed, 12 Aug 2020 01:45:16 +0000 (03:45 +0200)
committerest31 <MTest31@outlook.com>
Mon, 8 Mar 2021 07:18:50 +0000 (08:18 +0100)
compiler/rustc_metadata/src/creader.rs

index 9e3f121378cbafc6b4ed714e2dc3df11a8ac4d3a..5634467eeb7fbcbc3b59712ddcccd00c18a2534c 100644 (file)
@@ -195,10 +195,16 @@ fn crate_dependencies_in_reverse_postorder(&self, cnum: CrateNum) -> Vec<CrateNu
     }
 
     pub fn report_unused_deps(&self, tcx: TyCtxt<'_>) {
+        // We put the check for the option before the lint_level_at_node call
+        // because the call mutates internal state and introducing it
+        // leads to some ui tests failing.
+        if !tcx.sess.opts.json_unused_externs {
+            return;
+        }
         let level = tcx
             .lint_level_at_node(lint::builtin::UNUSED_CRATE_DEPENDENCIES, rustc_hir::CRATE_HIR_ID)
             .0;
-        if level != lint::Level::Allow && tcx.sess.opts.json_unused_externs {
+        if level != lint::Level::Allow {
             let unused_externs =
                 self.unused_externs.iter().map(|ident| ident.to_ident_string()).collect::<Vec<_>>();
             let unused_externs = unused_externs.iter().map(String::as_str).collect::<Vec<&str>>();