From 5669209d8ed026e14d92a9af127c8004bd7e31b5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 1 Jul 2018 00:27:44 +0200 Subject: [PATCH 1/6] Fix rustdoc run failures by shutting down definitely some lints --- src/librustc/lint/levels.rs | 5 +++++ src/librustc/session/mod.rs | 6 +++++- src/librustdoc/core.rs | 9 ++++++++- src/test/rustdoc-ui/unused.rs | 24 ++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/test/rustdoc-ui/unused.rs diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index 3393a2bf89d4b..f8676a3e7a113 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -118,6 +118,11 @@ impl LintLevelSets { // Ensure that we never exceed the `--cap-lints` argument. level = cmp::min(level, self.lint_cap); + if let Some(driver_level) = sess.driver_lint_caps.get(&LintId::of(lint)) { + // Ensure that we never exceed driver level. + level = cmp::min(*driver_level, level); + } + return (level, src) } diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 076d56fb80842..180c5867e93d8 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -22,7 +22,7 @@ use middle::dependency_format; use session::search_paths::PathKind; use session::config::{OutputType}; use ty::tls; -use util::nodemap::{FxHashSet}; +use util::nodemap::{FxHashMap, FxHashSet}; use util::common::{duration_to_secs_str, ErrorReported}; use util::common::ProfileQueriesMsg; @@ -160,6 +160,9 @@ pub struct Session { /// Metadata about the allocators for the current crate being compiled pub has_global_allocator: Once, + + /// Cap lint level specified by a driver specifically. + pub driver_lint_caps: FxHashMap, } pub struct PerfStats { @@ -1164,6 +1167,7 @@ pub fn build_session_( (*GLOBAL_JOBSERVER).clone() }, has_global_allocator: Once::new(), + driver_lint_caps: FxHashMap(), }; sess diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index e858f10860b41..c8c23bce66510 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -235,6 +235,14 @@ pub fn run_core(search_paths: SearchPaths, let mut sess = session::build_session_( sessopts, cpath, diagnostic_handler, codemap, ); + + let shutdown_lints = [lint::builtin::UNUSED_IMPORTS, + lint::builtin::UNUSED_EXTERN_CRATES]; + + for l in &shutdown_lints { + sess.driver_lint_caps.insert(lint::LintId::of(l), lint::Allow); + } + let codegen_backend = rustc_driver::get_codegen_backend(&sess); let cstore = Rc::new(CStore::new(codegen_backend.metadata_loader())); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); @@ -299,7 +307,6 @@ pub fn run_core(search_paths: SearchPaths, &sess); let resolver = RefCell::new(resolver); - abort_on_err(driver::phase_3_run_analysis_passes(&*codegen_backend, control, &sess, diff --git a/src/test/rustdoc-ui/unused.rs b/src/test/rustdoc-ui/unused.rs new file mode 100644 index 0000000000000..8b53098639232 --- /dev/null +++ b/src/test/rustdoc-ui/unused.rs @@ -0,0 +1,24 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-pass + +// This test purpose is to check that unused_imports lint isn't fired +// by rustdoc. Why would it? Because when rustdoc is running, it uses +// "everybody-loops" which replaces parts of code with "loop {}" to get +// huge performance improvements. + +#![deny(unused_imports)] + +use std::fs::File; + +pub fn f() { + let _: File; +} From c09617d36969c8167b5b8719e96d72977010c958 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 5 Jul 2018 20:06:33 +0200 Subject: [PATCH 2/6] Whitelist lints --- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/lib.rs | 2 +- src/librustdoc/core.rs | 23 +++++++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 79796d788719a..ec8cd0e5c1ef9 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -283,7 +283,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode { } declare_lint! { - MISSING_DOCS, + pub MISSING_DOCS, Allow, "detects missing documentation for public members" } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 9ac22f8dceb05..4daab0ac7b4c2 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -51,7 +51,7 @@ use lint::LintId; use lint::FutureIncompatibleInfo; mod bad_style; -mod builtin; +pub mod builtin; mod types; mod unused; diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index c8c23bce66510..f50113e80a7b9 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -189,6 +189,7 @@ pub fn run_core(search_paths: SearchPaths, let intra_link_resolution_failure_name = lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE.name; let warnings_lint_name = lint::builtin::WARNINGS.name; + let missing_docs = rustc_lint::builtin::MISSING_DOCS.name; let lints = lint::builtin::HardwiredLints.get_lints() .iter() .chain(rustc_lint::SoftLints.get_lints()) @@ -236,12 +237,22 @@ pub fn run_core(search_paths: SearchPaths, sessopts, cpath, diagnostic_handler, codemap, ); - let shutdown_lints = [lint::builtin::UNUSED_IMPORTS, - lint::builtin::UNUSED_EXTERN_CRATES]; - - for l in &shutdown_lints { - sess.driver_lint_caps.insert(lint::LintId::of(l), lint::Allow); - } + lint::builtin::HardwiredLints.get_lints() + .into_iter() + .chain(rustc_lint::SoftLints.get_lints().into_iter()) + .filter_map(|lint| { + if lint.name == warnings_lint_name || + lint.name == intra_link_resolution_failure_name || + lint.name == missing_docs { + None + } else { + Some(lint) + } + }) + .for_each(|l| { + sess.driver_lint_caps.insert(lint::LintId::of(l), + lint::Allow); + }); let codegen_backend = rustc_driver::get_codegen_backend(&sess); let cstore = Rc::new(CStore::new(codegen_backend.metadata_loader())); From 47f4d15ca886e4d2559ea28bcbeab6218962748c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 9 Jul 2018 18:10:08 +0200 Subject: [PATCH 3/6] add comment about lints whitelisting --- src/librustdoc/core.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index f50113e80a7b9..e516192769fec 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -241,6 +241,8 @@ pub fn run_core(search_paths: SearchPaths, .into_iter() .chain(rustc_lint::SoftLints.get_lints().into_iter()) .filter_map(|lint| { + // We don't want to whitelist *all* lints so let's + // ignore those ones. if lint.name == warnings_lint_name || lint.name == intra_link_resolution_failure_name || lint.name == missing_docs { From 52d15f6589ad0826584b4f10c48eba90f38cfd4a Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 11 Jul 2018 01:08:15 +0300 Subject: [PATCH 4/6] use the adjusted type for cat_pattern in tuple patterns This looks like a typo introduced in #51686. Fixes #52213. --- src/librustc/middle/mem_categorization.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 597872ef45de0..569bbdfbb7627 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -1342,7 +1342,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { ref ty => span_bug!(pat.span, "tuple pattern unexpected type {:?}", ty), }; for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) { - let subpat_ty = self.pat_ty_unadjusted(&subpat)?; // see (*2) + let subpat_ty = self.pat_ty_adjusted(&subpat)?; // see (*2) let interior = InteriorField(FieldIndex(i, Name::intern(&i.to_string()))); let subcmt = Rc::new(self.cat_imm_interior(pat, cmt.clone(), subpat_ty, interior)); self.cat_pattern_(subcmt, &subpat, op)?; From 6aa901a5b9739291936c07d31053ff17614d5906 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 11 Jul 2018 01:09:48 +0300 Subject: [PATCH 5/6] add a debug log for more MC failures I don't see why MC should fail on well-formed code, so it might be a better idea to just add a `delay_span_bug` there (anyone remember the `cat_expr Errd` bug from the 1.0 days?). However, I don't think this is a good idea to backport a new delay_span_bug into stable and this code is going away soon-ish anyway. --- src/librustc_typeck/check/regionck.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index f6fcf2fcd4825..b6b26b7d05223 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -105,7 +105,10 @@ use rustc::hir::{self, PatKind}; // a variation on try that just returns unit macro_rules! ignore_err { - ($e:expr) => (match $e { Ok(e) => e, Err(_) => return () }) + ($e:expr) => (match $e { Ok(e) => e, Err(_) => { + debug!("ignoring mem-categorization error!"); + return () + }}) } /////////////////////////////////////////////////////////////////////////// @@ -1034,7 +1037,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { debug!("link_pattern(discr_cmt={:?}, root_pat={:?})", discr_cmt, root_pat); - let _ = self.with_mc(|mc| { + ignore_err!(self.with_mc(|mc| { mc.cat_pattern(discr_cmt, root_pat, |sub_cmt, sub_pat| { match sub_pat.node { // `ref x` pattern @@ -1049,7 +1052,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { _ => {} } }) - }); + })); } /// Link lifetime of borrowed pointer resulting from autoref to lifetimes in the value being From e0e046c902c8aa933ff0bc50c6566df3cdde17c0 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 11 Jul 2018 01:11:59 +0300 Subject: [PATCH 6/6] add test for #52213 --- src/test/compile-fail/issue-52213.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/test/compile-fail/issue-52213.rs diff --git a/src/test/compile-fail/issue-52213.rs b/src/test/compile-fail/issue-52213.rs new file mode 100644 index 0000000000000..810379c63d3e1 --- /dev/null +++ b/src/test/compile-fail/issue-52213.rs @@ -0,0 +1,24 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T { + match (&t,) { //~ ERROR cannot infer an appropriate lifetime + ((u,),) => u, + } +} + +fn main() { + let x = { + let y = Box::new((42,)); + transmute_lifetime(&y) + }; + + println!("{}", x); +}