]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #88363 - michaelwoerister:remapped-diagnostics, r=estebank
authorbors <bors@rust-lang.org>
Fri, 3 Sep 2021 00:23:10 +0000 (00:23 +0000)
committerbors <bors@rust-lang.org>
Fri, 3 Sep 2021 00:23:10 +0000 (00:23 +0000)
Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix.

This PR fixes a regression (#87745) with `--remap-path-prefix` where the flag stopped causing diagnostic messages to be remapped as well. The regression was introduced in https://github.com/rust-lang/rust/pull/83813 where we erroneously assumed that remapping of diagnostic messages was not desired anymore (because #70642 partially undid that functionality with nobody objecting).

The issue is fixed by making `--remap-path-prefix` remap diagnostic messages again, including for paths that have been remapped in upstream crates (e.g. the standard library). This means that "sysroot-localization" (implemented in #70642) is also disabled if `rustc` is invoked with `--remap-path-prefix`. The assumption is that once someone starts explicitly remapping paths they also don't want paths to their local Rust installation in their build output.

In the future we might want to give more fine-grained control over this behavior via compiler flags (see https://github.com/rust-lang/rfcs/pull/3127 for a related RFC). For now this PR is intended as a regression fix.

This PR is an alternative to https://github.com/rust-lang/rust/pull/88191, which makes diagnostic messages be remapped unconditionally. That approach, however, would effectively revert #70642.

Fixes https://github.com/rust-lang/rust/issues/87745.

cc `@cbeuw`
r? `@ghost`

clippy_lints/src/missing_doc.rs
clippy_lints/src/missing_inline.rs
clippy_lints/src/non_expressive_names.rs
clippy_lints/src/utils/inspector.rs
clippy_utils/src/ast_utils.rs
tests/ui/crashes/ice-4775.rs
tests/ui/crashes/ice-5223.rs
tests/ui/doc/doc.rs
tests/ui/missing_const_for_fn/cant_be_const.rs
tests/ui/missing_const_for_fn/could_be_const.rs
tests/ui/missing_const_for_fn/could_be_const.stderr

index d358e9fb876a78e1a16c7b73bf29889e028143c9..940eee7a78897131d0ced058361e5dd3a87454e3 100644 (file)
@@ -122,6 +122,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
             },
             hir::ItemKind::Const(..)
             | hir::ItemKind::Enum(..)
+            | hir::ItemKind::Macro(..)
             | hir::ItemKind::Mod(..)
             | hir::ItemKind::Static(..)
             | hir::ItemKind::Struct(..)
index 977e6d966e873779cd4d72e909278e2cbced50ea..667cdd8302528caec005ef878d7a8f2087d50e70 100644 (file)
@@ -118,6 +118,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
             },
             hir::ItemKind::Const(..)
             | hir::ItemKind::Enum(..)
+            | hir::ItemKind::Macro(..)
             | hir::ItemKind::Mod(..)
             | hir::ItemKind::Static(..)
             | hir::ItemKind::Struct(..)
index ac21eb5275f0f8bc443e0a88a903d0ac70e7e089..2ffc00b449d08b7e9c25282579618b98ee233912 100644 (file)
@@ -316,8 +316,11 @@ fn apply<F: for<'c> Fn(&'c mut Self)>(&mut self, f: F) {
 
 impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
     fn visit_local(&mut self, local: &'tcx Local) {
-        if let Some(ref init) = local.init {
-            self.apply(|this| walk_expr(this, &**init));
+        if let Some((init, els)) = &local.kind.init_else_opt() {
+            self.apply(|this| walk_expr(this, init));
+            if let Some(els) = els {
+                self.apply(|this| walk_block(this, els));
+            }
         }
         // add the pattern after the expression because the bindings aren't available
         // yet in the init
index 6bf216cec1670f1011e1806d653dfd48cd5af4ca..e97983a2e1451d373e77609e8f13f456f7dbbfde 100644 (file)
@@ -381,6 +381,13 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) {
             let item_ty = cx.tcx.type_of(did);
             println!("function of type {:#?}", item_ty);
         },
+        hir::ItemKind::Macro(ref macro_def) => {
+            if macro_def.macro_rules {
+                println!("macro introduced by `macro_rules!`");
+            } else {
+                println!("macro introduced by `macro`");
+            }
+        },
         hir::ItemKind::Mod(..) => println!("module"),
         hir::ItemKind::ForeignMod { abi, .. } => println!("foreign module with abi: {}", abi),
         hir::ItemKind::GlobalAsm(asm) => println!("global asm: {:?}", asm),
index 7ea07a15aea51874457cee13b0319f4a8c9452db..133f6c29f7d2162d6300eca8c3d96d9f61af97d4 100644 (file)
@@ -221,7 +221,7 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
         (Local(l), Local(r)) => {
             eq_pat(&l.pat, &r.pat)
                 && both(&l.ty, &r.ty, |l, r| eq_ty(l, r))
-                && eq_expr_opt(&l.init, &r.init)
+                && eq_local_kind(&l.kind, &r.kind)
                 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
         },
         (Item(l), Item(r)) => eq_item(l, r, eq_item_kind),
@@ -234,6 +234,16 @@ pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
     }
 }
 
+pub fn eq_local_kind(l: &LocalKind, r: &LocalKind) -> bool {
+    use LocalKind::*;
+    match (l, r) {
+        (Decl, Decl) => true,
+        (Init(l), Init(r)) => eq_expr(l, r),
+        (InitElse(li, le), InitElse(ri, re)) => eq_expr(li, ri) && eq_block(le, re),
+        _ => false,
+    }
+}
+
 pub fn eq_item<K>(l: &Item<K>, r: &Item<K>, mut eq_kind: impl FnMut(&K, &K) -> bool) -> bool {
     eq_id(l.ident, r.ident)
         && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
index 31e53e846d54da5bdd0f1c29f92d4b1b6d34460e..405e3039e7d0c6f8487953b4296cb29ba075e4ac 100644 (file)
@@ -1,6 +1,3 @@
-#![feature(const_generics)]
-#![allow(incomplete_features)]
-
 pub struct ArrayWrapper<const N: usize>([usize; N]);
 
 impl<const N: usize> ArrayWrapper<{ N }> {
index 9bb2e227fc12e6ccbad119ac349f1f5af721fbcd..e3b3b27a6fc382c933c387a46ad43c98917e6ae5 100644 (file)
@@ -1,7 +1,4 @@
 // Regression test for #5233
-
-#![feature(const_generics)]
-#![allow(incomplete_features)]
 #![warn(clippy::indexing_slicing, clippy::iter_cloned_collect)]
 
 pub struct KotomineArray<T, const N: usize> {
index 8afef6b23d47653c27a9f2d2398ed411fd08667a..8b0c0f304fce0f8fc318e83f1e8d01dc90e77b1e 100644 (file)
@@ -2,7 +2,7 @@
 
 #![allow(dead_code, incomplete_features)]
 #![warn(clippy::doc_markdown)]
-#![feature(custom_inner_attributes, const_generics, const_evaluatable_checked, const_option)]
+#![feature(custom_inner_attributes, generic_const_exprs, const_option)]
 #![rustfmt::skip]
 
 /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there)
@@ -203,7 +203,7 @@ fn issue_2343() {}
 /// __|_ _|__||_|
 fn pulldown_cmark_crash() {}
 
-// issue #7033 - const_evaluatable_checked ICE
+// issue #7033 - generic_const_exprs ICE
 struct S<T, const N: usize>
 where [(); N.checked_next_power_of_two().unwrap()]: {
     arr: [T; N.checked_next_power_of_two().unwrap()],
index 6d2cbb6ad96fa865870159854b8e1d053d6f0b75..aa60d0504e5e60c1181351c9444736b62d740b5a 100644 (file)
@@ -5,8 +5,7 @@
 // aux-build:helper.rs
 
 #![warn(clippy::missing_const_for_fn)]
-#![allow(incomplete_features)]
-#![feature(start, const_generics)]
+#![feature(start)]
 #![feature(custom_inner_attributes)]
 
 extern crate helper;
index 0accb516f5f6b4a145e161c708cc726a72b221a8..baa7eec05462ebad8baea0762ed76b51ae7dfa2d 100644 (file)
@@ -1,6 +1,5 @@
 #![warn(clippy::missing_const_for_fn)]
 #![allow(incomplete_features, clippy::let_and_return)]
-#![feature(const_generics)]
 #![feature(custom_inner_attributes)]
 
 use std::mem::transmute;
index 63c211f39fa1e3530a1be0d041f69d6bae65ee63..b89cc6451bb592c5f3f6fbbab1daa194953d5101 100644 (file)
@@ -1,5 +1,5 @@
 error: this could be a `const fn`
-  --> $DIR/could_be_const.rs:14:5
+  --> $DIR/could_be_const.rs:13:5
    |
 LL | /     pub fn new() -> Self {
 LL | |         Self { guess: 42 }
@@ -9,7 +9,7 @@ LL | |     }
    = note: `-D clippy::missing-const-for-fn` implied by `-D warnings`
 
 error: this could be a `const fn`
-  --> $DIR/could_be_const.rs:18:5
+  --> $DIR/could_be_const.rs:17:5
    |
 LL | /     fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] {
 LL | |         b
@@ -17,7 +17,7 @@ LL | |     }
    | |_____^
 
 error: this could be a `const fn`
-  --> $DIR/could_be_const.rs:24:1
+  --> $DIR/could_be_const.rs:23:1
    |
 LL | / fn one() -> i32 {
 LL | |     1
@@ -25,7 +25,7 @@ LL | | }
    | |_^
 
 error: this could be a `const fn`
-  --> $DIR/could_be_const.rs:29:1
+  --> $DIR/could_be_const.rs:28:1
    |
 LL | / fn two() -> i32 {
 LL | |     let abc = 2;
@@ -34,7 +34,7 @@ LL | | }
    | |_^
 
 error: this could be a `const fn`
-  --> $DIR/could_be_const.rs:35:1
+  --> $DIR/could_be_const.rs:34:1
    |
 LL | / fn string() -> String {
 LL | |     String::new()
@@ -42,7 +42,7 @@ LL | | }
    | |_^
 
 error: this could be a `const fn`
-  --> $DIR/could_be_const.rs:40:1
+  --> $DIR/could_be_const.rs:39:1
    |
 LL | / unsafe fn four() -> i32 {
 LL | |     4
@@ -50,7 +50,7 @@ LL | | }
    | |_^
 
 error: this could be a `const fn`
-  --> $DIR/could_be_const.rs:45:1
+  --> $DIR/could_be_const.rs:44:1
    |
 LL | / fn generic<T>(t: T) -> T {
 LL | |     t
@@ -58,7 +58,7 @@ LL | | }
    | |_^
 
 error: this could be a `const fn`
-  --> $DIR/could_be_const.rs:68:9
+  --> $DIR/could_be_const.rs:67:9
    |
 LL | /         pub fn b(self, a: &A) -> B {
 LL | |             B
@@ -66,7 +66,7 @@ LL | |         }
    | |_________^
 
 error: this could be a `const fn`
-  --> $DIR/could_be_const.rs:78:5
+  --> $DIR/could_be_const.rs:77:5
    |
 LL | /     fn const_fn_stabilized_before_msrv(byte: u8) {
 LL | |         byte.is_ascii_digit();