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`
},
hir::ItemKind::Const(..)
| hir::ItemKind::Enum(..)
+ | hir::ItemKind::Macro(..)
| hir::ItemKind::Mod(..)
| hir::ItemKind::Static(..)
| hir::ItemKind::Struct(..)
},
hir::ItemKind::Const(..)
| hir::ItemKind::Enum(..)
+ | hir::ItemKind::Macro(..)
| hir::ItemKind::Mod(..)
| hir::ItemKind::Static(..)
| hir::ItemKind::Struct(..)
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
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),
(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),
}
}
+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))
-#![feature(const_generics)]
-#![allow(incomplete_features)]
-
pub struct ArrayWrapper<const N: usize>([usize; N]);
impl<const N: usize> ArrayWrapper<{ N }> {
// 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> {
#![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)
/// __|_ _|__||_|
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()],
// 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;
#![warn(clippy::missing_const_for_fn)]
#![allow(incomplete_features, clippy::let_and_return)]
-#![feature(const_generics)]
#![feature(custom_inner_attributes)]
use std::mem::transmute;
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 }
= 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
| |_____^
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
| |_^
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;
| |_^
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()
| |_^
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
| |_^
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
| |_^
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
| |_________^
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();