Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f69f6e0

Browse files
authoredMar 18, 2024··
Unrolled build for rust-lang#122158
Rollup merge of rust-lang#122158 - estebank:feature-sugg, r=WaffleLapkin Provide structured suggestion for `#![feature(foo)]` ``` error: `S2<'_>` is forbidden as the type of a const generic parameter --> $DIR/lifetime-in-const-param.rs:5:23 | LL | struct S<'a, const N: S2>(&'a ()); | ^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | LL + #![feature(adt_const_params)] | ``` Fix rust-lang#55941.
2 parents d31b6fb + 6c31f6c commit f69f6e0

File tree

98 files changed

+755
-253
lines changed

Some content is hidden

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

98 files changed

+755
-253
lines changed
 

‎compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
9999
#[allow(rustc::untranslatable_diagnostic)]
100100
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, _: Span) -> Diag<'tcx> {
101101
let FnCallNonConst { caller, callee, args, span, call_source, feature } = *self;
102-
let ConstCx { tcx, param_env, .. } = *ccx;
102+
let ConstCx { tcx, param_env, body, .. } = *ccx;
103103

104104
let diag_trait = |err, self_ty: Ty<'_>, trait_id| {
105105
let trait_ref = TraitRef::from_method(tcx, trait_id, args);
@@ -297,10 +297,12 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
297297
ccx.const_kind(),
298298
));
299299

300-
if let Some(feature) = feature
301-
&& ccx.tcx.sess.is_nightly_build()
302-
{
303-
err.help(format!("add `#![feature({feature})]` to the crate attributes to enable",));
300+
if let Some(feature) = feature {
301+
ccx.tcx.disabled_nightly_features(
302+
&mut err,
303+
body.source.def_id().as_local().map(|local| ccx.tcx.local_def_id_to_hir_id(local)),
304+
[(String::new(), feature)],
305+
);
304306
}
305307

306308
if let ConstContext::Static(_) = ccx.const_kind() {

‎compiler/rustc_hir_analysis/src/astconv/generics.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::ty::{
1616
self, GenericArgsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty, TyCtxt,
1717
};
1818
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
19-
use rustc_span::symbol::kw;
19+
use rustc_span::symbol::{kw, sym};
2020
use smallvec::SmallVec;
2121

2222
/// Report an error that a generic argument did not match the generic parameter that was
@@ -41,9 +41,11 @@ fn generic_arg_mismatch_err(
4141
if let GenericParamDefKind::Const { .. } = param.kind {
4242
if matches!(arg, GenericArg::Type(hir::Ty { kind: hir::TyKind::Infer, .. })) {
4343
err.help("const arguments cannot yet be inferred with `_`");
44-
if sess.is_nightly_build() {
45-
err.help("add `#![feature(generic_arg_infer)]` to the crate attributes to enable");
46-
}
44+
tcx.disabled_nightly_features(
45+
&mut err,
46+
param.def_id.as_local().map(|local| tcx.local_def_id_to_hir_id(local)),
47+
[(String::new(), sym::generic_arg_infer)],
48+
);
4749
}
4850
}
4951

0 commit comments

Comments
 (0)
Please sign in to comment.