Skip to content

Commit a66e334

Browse files
committed
Auto merge of rust-lang#116260 - matthiaskrgr:rollup-q3sge0i, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#116133 (ref(bootstrap.py): add `eprint` function) - rust-lang#116201 (Fix `noop_method_call` detection) - rust-lang#116231 (Remove `rustc_lint_defs::lint_array`) - rust-lang#116234 (Miri subtree update) - rust-lang#116239 (Only visit reachable nodes in SsaLocals.) - rust-lang#116245 (Clippy backport: Move needless_raw_string_hashes to pedantic) - rust-lang#116253 (Make `adt_const_params` feature suggestion consistent with other features and improve when it is emitted) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b8536c1 + 95262e4 commit a66e334

File tree

173 files changed

+615
-263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+615
-263
lines changed

Cargo.lock

+11-6
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,7 @@ dependencies = [
24192419
"rustc_version",
24202420
"serde",
24212421
"smallvec",
2422-
"ui_test 0.11.7",
2422+
"ui_test 0.21.2",
24232423
]
24242424

24252425
[[package]]
@@ -5621,18 +5621,23 @@ checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81"
56215621

56225622
[[package]]
56235623
name = "ui_test"
5624-
version = "0.11.7"
5624+
version = "0.20.0"
56255625
source = "registry+https://github.com/rust-lang/crates.io-index"
5626-
checksum = "c21899b59f53717dfad29e4f46e5b21a200a1b6888ab86532a07cfc8b48dd78c"
5626+
checksum = "bfd8fb9b15c8332cf51bfc2dc4830063b2446a9c9d732421b56f2478024a3971"
56275627
dependencies = [
5628+
"annotate-snippets",
5629+
"anyhow",
56285630
"bstr",
56295631
"cargo-platform",
56305632
"cargo_metadata",
56315633
"color-eyre",
56325634
"colored",
5635+
"comma",
56335636
"crossbeam-channel",
5634-
"diff",
5637+
"indicatif",
56355638
"lazy_static",
5639+
"levenshtein",
5640+
"prettydiff",
56365641
"regex",
56375642
"rustc_version",
56385643
"rustfix",
@@ -5643,9 +5648,9 @@ dependencies = [
56435648

56445649
[[package]]
56455650
name = "ui_test"
5646-
version = "0.20.0"
5651+
version = "0.21.2"
56475652
source = "registry+https://github.com/rust-lang/crates.io-index"
5648-
checksum = "bfd8fb9b15c8332cf51bfc2dc4830063b2446a9c9d732421b56f2478024a3971"
5653+
checksum = "aaf4bf7c184b8dfc7a4d3b90df789b1eb992ee42811cd115f32a7a1eb781058d"
56495654
dependencies = [
56505655
"annotate-snippets",
56515656
"anyhow",

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+57-32
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ use rustc_span::symbol::{sym, Ident, Symbol};
2424
use rustc_span::{Span, DUMMY_SP};
2525
use rustc_target::spec::abi::Abi;
2626
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
27+
use rustc_trait_selection::traits::misc::{
28+
type_allowed_to_implement_const_param_ty, ConstParamTyImplementationError,
29+
};
2730
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
2831
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
2932
use rustc_trait_selection::traits::{
@@ -865,43 +868,65 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
865868
);
866869
});
867870
} else {
868-
let err_ty_str;
869-
let mut is_ptr = true;
870-
871-
let err = match ty.kind() {
871+
let diag = match ty.kind() {
872872
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Error(_) => None,
873-
ty::FnPtr(_) => Some("function pointers"),
874-
ty::RawPtr(_) => Some("raw pointers"),
875-
_ => {
876-
is_ptr = false;
877-
err_ty_str = format!("`{ty}`");
878-
Some(err_ty_str.as_str())
879-
}
873+
ty::FnPtr(_) => Some(tcx.sess.struct_span_err(
874+
hir_ty.span,
875+
"using function pointers as const generic parameters is forbidden",
876+
)),
877+
ty::RawPtr(_) => Some(tcx.sess.struct_span_err(
878+
hir_ty.span,
879+
"using raw pointers as const generic parameters is forbidden",
880+
)),
881+
_ => Some(tcx.sess.struct_span_err(
882+
hir_ty.span,
883+
format!("`{}` is forbidden as the type of a const generic parameter", ty),
884+
)),
880885
};
881886

882-
if let Some(unsupported_type) = err {
883-
if is_ptr {
884-
tcx.sess.span_err(
885-
hir_ty.span,
886-
format!(
887-
"using {unsupported_type} as const generic parameters is forbidden",
888-
),
889-
);
890-
} else {
891-
let mut err = tcx.sess.struct_span_err(
892-
hir_ty.span,
893-
format!(
894-
"{unsupported_type} is forbidden as the type of a const generic parameter",
895-
),
896-
);
897-
err.note("the only supported types are integers, `bool` and `char`");
898-
if tcx.sess.is_nightly_build() {
899-
err.help(
900-
"more complex types are supported with `#![feature(adt_const_params)]`",
901-
);
887+
if let Some(mut diag) = diag {
888+
diag.note("the only supported types are integers, `bool` and `char`");
889+
890+
let cause = ObligationCause::misc(hir_ty.span, param.def_id);
891+
let may_suggest_feature = match type_allowed_to_implement_const_param_ty(
892+
tcx,
893+
tcx.param_env(param.def_id),
894+
ty,
895+
cause,
896+
) {
897+
// Can never implement `ConstParamTy`, don't suggest anything.
898+
Err(ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed) => false,
899+
// May be able to implement `ConstParamTy`. Only emit the feature help
900+
// if the type is local, since the user may be able to fix the local type.
901+
Err(ConstParamTyImplementationError::InfrigingFields(..)) => {
902+
fn ty_is_local(ty: Ty<'_>) -> bool {
903+
match ty.kind() {
904+
ty::Adt(adt_def, ..) => adt_def.did().is_local(),
905+
// Arrays and slices use the inner type's `ConstParamTy`.
906+
ty::Array(ty, ..) => ty_is_local(*ty),
907+
ty::Slice(ty) => ty_is_local(*ty),
908+
// `&` references use the inner type's `ConstParamTy`.
909+
// `&mut` are not supported.
910+
ty::Ref(_, ty, ast::Mutability::Not) => ty_is_local(*ty),
911+
// Say that a tuple is local if any of its components are local.
912+
// This is not strictly correct, but it's likely that the user can fix the local component.
913+
ty::Tuple(tys) => tys.iter().any(|ty| ty_is_local(ty)),
914+
_ => false,
915+
}
916+
}
917+
918+
ty_is_local(ty)
902919
}
903-
err.emit();
920+
// Implments `ConstParamTy`, suggest adding the feature to enable.
921+
Ok(..) => true,
922+
};
923+
if may_suggest_feature && tcx.sess.is_nightly_build() {
924+
diag.help(
925+
"add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types",
926+
);
904927
}
928+
929+
diag.emit();
905930
}
906931
}
907932
}

compiler/rustc_lint/src/foreign_modules.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ use rustc_hir::def::DefKind;
55
use rustc_middle::query::Providers;
66
use rustc_middle::ty::layout::LayoutError;
77
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
8-
use rustc_session::lint::{lint_array, LintArray};
98
use rustc_span::{sym, Span, Symbol};
109
use rustc_target::abi::FIRST_VARIANT;
1110

1211
use crate::lints::{BuiltinClashingExtern, BuiltinClashingExternSub};
13-
use crate::types;
12+
use crate::{types, LintVec};
1413

1514
pub(crate) fn provide(providers: &mut Providers) {
1615
*providers = Providers { clashing_extern_declarations, ..*providers };
1716
}
1817

19-
pub(crate) fn get_lints() -> LintArray {
20-
lint_array!(CLASHING_EXTERN_DECLARATIONS)
18+
pub(crate) fn get_lints() -> LintVec {
19+
vec![CLASHING_EXTERN_DECLARATIONS]
2120
}
2221

2322
fn clashing_extern_declarations(tcx: TyCtxt<'_>, (): ()) {

compiler/rustc_lint/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub use late::{check_crate, late_lint_mod, unerased_lint_store};
130130
pub use passes::{EarlyLintPass, LateLintPass};
131131
pub use rustc_session::lint::Level::{self, *};
132132
pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Lint, LintId};
133-
pub use rustc_session::lint::{LintArray, LintPass};
133+
pub use rustc_session::lint::{LintPass, LintVec};
134134

135135
fluent_messages! { "../messages.ftl" }
136136

compiler/rustc_lint/src/noop_method_call.rs

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
9898
let Ok(Some(i)) = ty::Instance::resolve(cx.tcx, cx.param_env, did, args) else { return };
9999
// (Re)check that it implements the noop diagnostic.
100100
let Some(name) = cx.tcx.get_diagnostic_name(i.def_id()) else { return };
101+
if !matches!(
102+
name,
103+
sym::noop_method_borrow | sym::noop_method_clone | sym::noop_method_deref
104+
) {
105+
return;
106+
}
101107

102108
let receiver_ty = cx.typeck_results().expr_ty(receiver);
103109
let expr_ty = cx.typeck_results().expr_ty_adjusted(expr);

compiler/rustc_lint/src/passes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ macro_rules! declare_combined_late_lint_pass {
111111
}
112112
}
113113

114-
$v fn get_lints() -> $crate::LintArray {
114+
$v fn get_lints() -> $crate::LintVec {
115115
let mut lints = Vec::new();
116116
$(lints.extend_from_slice(&$pass::get_lints());)*
117117
lints
@@ -226,7 +226,7 @@ macro_rules! declare_combined_early_lint_pass {
226226
}
227227
}
228228

229-
$v fn get_lints() -> $crate::LintArray {
229+
$v fn get_lints() -> $crate::LintVec {
230230
let mut lints = Vec::new();
231231
$(lints.extend_from_slice(&$pass::get_lints());)*
232232
lints

compiler/rustc_lint_defs/src/lib.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -785,16 +785,7 @@ macro_rules! declare_tool_lint {
785785
);
786786
}
787787

788-
/// Declares a static `LintArray` and return it as an expression.
789-
#[macro_export]
790-
macro_rules! lint_array {
791-
($( $lint:expr ),* ,) => { lint_array!( $($lint),* ) };
792-
($( $lint:expr ),*) => {{
793-
vec![$($lint),*]
794-
}}
795-
}
796-
797-
pub type LintArray = Vec<&'static Lint>;
788+
pub type LintVec = Vec<&'static Lint>;
798789

799790
pub trait LintPass {
800791
fn name(&self) -> &'static str;
@@ -808,7 +799,7 @@ macro_rules! impl_lint_pass {
808799
fn name(&self) -> &'static str { stringify!($ty) }
809800
}
810801
impl $ty {
811-
pub fn get_lints() -> $crate::LintArray { $crate::lint_array!($($lint),*) }
802+
pub fn get_lints() -> $crate::LintVec { vec![$($lint),*] }
812803
}
813804
};
814805
}

compiler/rustc_mir_transform/src/ssa.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,10 @@ impl SsaLocals {
7878
visitor.assignments[local] = Set1::One(LocationExtended::Arg);
7979
}
8080

81-
if body.basic_blocks.len() > 2 {
82-
for (bb, data) in traversal::reverse_postorder(body) {
83-
visitor.visit_basic_block_data(bb, data);
84-
}
85-
} else {
86-
for (bb, data) in body.basic_blocks.iter_enumerated() {
87-
visitor.visit_basic_block_data(bb, data);
88-
}
81+
// For SSA assignments, a RPO visit will see the assignment before it sees any use.
82+
// We only visit reachable nodes: computing `dominates` on an unreachable node ICEs.
83+
for (bb, data) in traversal::reverse_postorder(body) {
84+
visitor.visit_basic_block_data(bb, data);
8985
}
9086

9187
for var_debug_info in &body.var_debug_info {

0 commit comments

Comments
 (0)