Skip to content

Commit d78329b

Browse files
committed
Auto merge of #119088 - George-lewis:glewis/suggest-upgrading-compiler, r=Nilstrieb
Suggest Upgrading Compiler for Gated Features This PR addresses #117318 I have a few questions: 1. Do we want to specify the current version and release date of the compiler? I have added this in via environment variables, which I found in the code for the rustc cli where it handles the `--version` flag a. How can I handle the changing message in the tests? 3. Do we want to only show this message when the compiler is old? a. How can we determine when the compiler is old? I'll wait until we figure out the message to bless the tests
2 parents 23148b1 + d56cdd4 commit d78329b

File tree

451 files changed

+1569
-545
lines changed

Some content is hidden

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

451 files changed

+1569
-545
lines changed

Diff for: compiler/rustc_ast_lowering/src/asm.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4848
);
4949
if !is_stable && !self.tcx.features().asm_experimental_arch {
5050
feature_err(
51-
&self.tcx.sess.parse_sess,
51+
&self.tcx.sess,
5252
sym::asm_experimental_arch,
5353
sp,
5454
"inline assembly is not stable yet on this architecture",
@@ -63,13 +63,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6363
self.dcx().emit_err(AttSyntaxOnlyX86 { span: sp });
6464
}
6565
if asm.options.contains(InlineAsmOptions::MAY_UNWIND) && !self.tcx.features().asm_unwind {
66-
feature_err(
67-
&self.tcx.sess.parse_sess,
68-
sym::asm_unwind,
69-
sp,
70-
"the `may_unwind` option is unstable",
71-
)
72-
.emit();
66+
feature_err(&self.tcx.sess, sym::asm_unwind, sp, "the `may_unwind` option is unstable")
67+
.emit();
7368
}
7469

7570
let mut clobber_abis = FxIndexMap::default();
@@ -183,7 +178,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
183178
InlineAsmOperand::Const { anon_const } => {
184179
if !self.tcx.features().asm_const {
185180
feature_err(
186-
&sess.parse_sess,
181+
sess,
187182
sym::asm_const,
188183
*op_sp,
189184
"const operands for inline assembly are unstable",

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15121512
Some(hir::CoroutineKind::Coroutine(_)) => {
15131513
if !self.tcx.features().coroutines {
15141514
rustc_session::parse::feature_err(
1515-
&self.tcx.sess.parse_sess,
1515+
&self.tcx.sess,
15161516
sym::coroutines,
15171517
span,
15181518
"yield syntax is experimental",
@@ -1524,7 +1524,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15241524
None => {
15251525
if !self.tcx.features().coroutines {
15261526
rustc_session::parse::feature_err(
1527-
&self.tcx.sess.parse_sess,
1527+
&self.tcx.sess,
15281528
sym::coroutines,
15291529
span,
15301530
"yield syntax is experimental",

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10431043
{
10441044
add_feature_diagnostics(
10451045
&mut err,
1046-
&self.tcx.sess.parse_sess,
1046+
&self.tcx.sess,
10471047
sym::return_type_notation,
10481048
);
10491049
}
@@ -2310,7 +2310,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23102310
hir::ArrayLen::Infer(self.lower_node_id(c.id), self.lower_span(c.value.span))
23112311
} else {
23122312
feature_err(
2313-
&self.tcx.sess.parse_sess,
2313+
&self.tcx.sess,
23142314
sym::generic_arg_infer,
23152315
c.value.span,
23162316
"using `_` for array lengths is unstable",

Diff for: compiler/rustc_ast_passes/src/feature_gate.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ use crate::errors;
1717
macro_rules! gate {
1818
($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {{
1919
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
20-
feature_err(&$visitor.sess.parse_sess, sym::$feature, $span, $explain).emit();
20+
feature_err(&$visitor.sess, sym::$feature, $span, $explain).emit();
2121
}
2222
}};
2323
($visitor:expr, $feature:ident, $span:expr, $explain:expr, $help:expr) => {{
2424
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
25-
feature_err(&$visitor.sess.parse_sess, sym::$feature, $span, $explain)
26-
.with_help($help)
27-
.emit();
25+
feature_err(&$visitor.sess, sym::$feature, $span, $explain).with_help($help).emit();
2826
}
2927
}};
3028
}
@@ -33,7 +31,7 @@ macro_rules! gate {
3331
macro_rules! gate_alt {
3432
($visitor:expr, $has_feature:expr, $name:expr, $span:expr, $explain:expr) => {{
3533
if !$has_feature && !$span.allows_unstable($name) {
36-
feature_err(&$visitor.sess.parse_sess, $name, $span, $explain).emit();
34+
feature_err(&$visitor.sess, $name, $span, $explain).emit();
3735
}
3836
}};
3937
}
@@ -45,7 +43,7 @@ macro_rules! gate_multi {
4543
let spans: Vec<_> =
4644
$spans.filter(|span| !span.allows_unstable(sym::$feature)).collect();
4745
if !spans.is_empty() {
48-
feature_err(&$visitor.sess.parse_sess, sym::$feature, spans, $explain).emit();
46+
feature_err(&$visitor.sess, sym::$feature, spans, $explain).emit();
4947
}
5048
}
5149
}};
@@ -55,7 +53,7 @@ macro_rules! gate_multi {
5553
macro_rules! gate_legacy {
5654
($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {{
5755
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
58-
feature_warn(&$visitor.sess.parse_sess, sym::$feature, $span, $explain);
56+
feature_warn(&$visitor.sess, sym::$feature, $span, $explain);
5957
}
6058
}};
6159
}
@@ -91,14 +89,7 @@ impl<'a> PostExpansionVisitor<'a> {
9189
match abi::is_enabled(self.features, span, symbol_unescaped.as_str()) {
9290
Ok(()) => (),
9391
Err(abi::AbiDisabled::Unstable { feature, explain }) => {
94-
feature_err_issue(
95-
&self.sess.parse_sess,
96-
feature,
97-
span,
98-
GateIssue::Language,
99-
explain,
100-
)
101-
.emit();
92+
feature_err_issue(&self.sess, feature, span, GateIssue::Language, explain).emit();
10293
}
10394
Err(abi::AbiDisabled::Unrecognized) => {
10495
if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) {
@@ -571,13 +562,8 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
571562
if let Ok(snippet) = sm.span_to_snippet(span)
572563
&& snippet == "!"
573564
{
574-
feature_err(
575-
&sess.parse_sess,
576-
sym::never_patterns,
577-
span,
578-
"`!` patterns are experimental",
579-
)
580-
.emit();
565+
feature_err(sess, sym::never_patterns, span, "`!` patterns are experimental")
566+
.emit();
581567
} else {
582568
let suggestion = span.shrink_to_hi();
583569
sess.dcx().emit_err(errors::MatchArmWithNoBody { span, suggestion });

Diff for: compiler/rustc_attr/src/builtin.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_macros::HashStable_Generic;
99
use rustc_session::config::ExpectedValues;
1010
use rustc_session::lint::builtin::UNEXPECTED_CFGS;
1111
use rustc_session::lint::BuiltinLintDiagnostics;
12-
use rustc_session::parse::{feature_err, ParseSess};
12+
use rustc_session::parse::feature_err;
1313
use rustc_session::{RustcVersion, Session};
1414
use rustc_span::hygiene::Transparency;
1515
use rustc_span::{symbol::sym, symbol::Symbol, Span};
@@ -518,15 +518,15 @@ pub struct Condition {
518518
/// Tests if a cfg-pattern matches the cfg set
519519
pub fn cfg_matches(
520520
cfg: &ast::MetaItem,
521-
sess: &ParseSess,
521+
sess: &Session,
522522
lint_node_id: NodeId,
523523
features: Option<&Features>,
524524
) -> bool {
525525
eval_condition(cfg, sess, features, &mut |cfg| {
526526
try_gate_cfg(cfg.name, cfg.span, sess, features);
527-
match sess.check_config.expecteds.get(&cfg.name) {
527+
match sess.parse_sess.check_config.expecteds.get(&cfg.name) {
528528
Some(ExpectedValues::Some(values)) if !values.contains(&cfg.value) => {
529-
sess.buffer_lint_with_diagnostic(
529+
sess.parse_sess.buffer_lint_with_diagnostic(
530530
UNEXPECTED_CFGS,
531531
cfg.span,
532532
lint_node_id,
@@ -541,8 +541,8 @@ pub fn cfg_matches(
541541
),
542542
);
543543
}
544-
None if sess.check_config.exhaustive_names => {
545-
sess.buffer_lint_with_diagnostic(
544+
None if sess.parse_sess.check_config.exhaustive_names => {
545+
sess.parse_sess.buffer_lint_with_diagnostic(
546546
UNEXPECTED_CFGS,
547547
cfg.span,
548548
lint_node_id,
@@ -555,18 +555,18 @@ pub fn cfg_matches(
555555
}
556556
_ => { /* not unexpected */ }
557557
}
558-
sess.config.contains(&(cfg.name, cfg.value))
558+
sess.parse_sess.config.contains(&(cfg.name, cfg.value))
559559
})
560560
}
561561

562-
fn try_gate_cfg(name: Symbol, span: Span, sess: &ParseSess, features: Option<&Features>) {
562+
fn try_gate_cfg(name: Symbol, span: Span, sess: &Session, features: Option<&Features>) {
563563
let gate = find_gated_cfg(|sym| sym == name);
564564
if let (Some(feats), Some(gated_cfg)) = (features, gate) {
565565
gate_cfg(gated_cfg, span, sess, feats);
566566
}
567567
}
568568

569-
fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &ParseSess, features: &Features) {
569+
fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &Session, features: &Features) {
570570
let (cfg, feature, has_feature) = gated_cfg;
571571
if !has_feature(features) && !cfg_span.allows_unstable(*feature) {
572572
let explain = format!("`cfg({cfg})` is experimental and subject to change");
@@ -594,11 +594,11 @@ fn parse_version(s: Symbol) -> Option<RustcVersion> {
594594
/// evaluate individual items.
595595
pub fn eval_condition(
596596
cfg: &ast::MetaItem,
597-
sess: &ParseSess,
597+
sess: &Session,
598598
features: Option<&Features>,
599599
eval: &mut impl FnMut(Condition) -> bool,
600600
) -> bool {
601-
let dcx = &sess.dcx;
601+
let dcx = &sess.parse_sess.dcx;
602602
match &cfg.kind {
603603
ast::MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
604604
try_gate_cfg(sym::version, cfg.span, sess, features);
@@ -626,7 +626,7 @@ pub fn eval_condition(
626626
};
627627

628628
// See https://github.com/rust-lang/rust/issues/64796#issuecomment-640851454 for details
629-
if sess.assume_incomplete_release {
629+
if sess.parse_sess.assume_incomplete_release {
630630
RustcVersion::CURRENT > min_version
631631
} else {
632632
RustcVersion::CURRENT >= min_version

Diff for: compiler/rustc_builtin_macros/src/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn expand_cfg(
2222
Ok(cfg) => {
2323
let matches_cfg = attr::cfg_matches(
2424
&cfg,
25-
&cx.sess.parse_sess,
25+
&cx.sess,
2626
cx.current_expansion.lint_node_id,
2727
Some(cx.ecfg.features),
2828
);

Diff for: compiler/rustc_builtin_macros/src/source_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn expand_include<'cx>(
107107
return DummyResult::any(sp);
108108
};
109109
// The file will be added to the code map by the parser
110-
let file = match resolve_path(&cx.sess.parse_sess, file.as_str(), sp) {
110+
let file = match resolve_path(&cx.sess, file.as_str(), sp) {
111111
Ok(f) => f,
112112
Err(err) => {
113113
err.emit();
@@ -179,7 +179,7 @@ pub fn expand_include_str(
179179
let Some(file) = get_single_str_from_tts(cx, sp, tts, "include_str!") else {
180180
return DummyResult::any(sp);
181181
};
182-
let file = match resolve_path(&cx.sess.parse_sess, file.as_str(), sp) {
182+
let file = match resolve_path(&cx.sess, file.as_str(), sp) {
183183
Ok(f) => f,
184184
Err(err) => {
185185
err.emit();
@@ -213,7 +213,7 @@ pub fn expand_include_bytes(
213213
let Some(file) = get_single_str_from_tts(cx, sp, tts, "include_bytes!") else {
214214
return DummyResult::any(sp);
215215
};
216-
let file = match resolve_path(&cx.sess.parse_sess, file.as_str(), sp) {
216+
let file = match resolve_path(&cx.sess, file.as_str(), sp) {
217217
Ok(f) => f,
218218
Err(err) => {
219219
err.emit();

Diff for: compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2870,7 +2870,7 @@ fn add_dynamic_crate(cmd: &mut dyn Linker, sess: &Session, cratepath: &Path) {
28702870

28712871
fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool {
28722872
match lib.cfg {
2873-
Some(ref cfg) => rustc_attr::cfg_matches(cfg, &sess.parse_sess, CRATE_NODE_ID, None),
2873+
Some(ref cfg) => rustc_attr::cfg_matches(cfg, sess, CRATE_NODE_ID, None),
28742874
None => true,
28752875
}
28762876
}

Diff for: compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
155155
Some([item]) if item.has_name(sym::linker) => {
156156
if !tcx.features().used_with_arg {
157157
feature_err(
158-
&tcx.sess.parse_sess,
158+
&tcx.sess,
159159
sym::used_with_arg,
160160
attr.span,
161161
"`#[used(linker)]` is currently unstable",
@@ -167,7 +167,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
167167
Some([item]) if item.has_name(sym::compiler) => {
168168
if !tcx.features().used_with_arg {
169169
feature_err(
170-
&tcx.sess.parse_sess,
170+
&tcx.sess,
171171
sym::used_with_arg,
172172
attr.span,
173173
"`#[used(compiler)]` is currently unstable",
@@ -251,7 +251,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
251251
&& !attr.span.allows_unstable(sym::closure_track_caller)
252252
{
253253
feature_err(
254-
&tcx.sess.parse_sess,
254+
&tcx.sess,
255255
sym::closure_track_caller,
256256
attr.span,
257257
"`#[track_caller]` on closures is currently unstable",
@@ -304,7 +304,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
304304
// `#[target_feature]` on `main` and `start`.
305305
} else if !tcx.features().target_feature_11 {
306306
feature_err(
307-
&tcx.sess.parse_sess,
307+
&tcx.sess,
308308
sym::target_feature_11,
309309
attr.span,
310310
"`#[target_feature(..)]` can only be applied to `unsafe` functions",

Diff for: compiler/rustc_codegen_ssa/src/target_features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn from_target_feature(
8282
};
8383
if !allowed {
8484
feature_err(
85-
&tcx.sess.parse_sess,
85+
&tcx.sess,
8686
feature_gate.unwrap(),
8787
item.span(),
8888
format!("the target feature `{feature}` is currently unstable"),

Diff for: compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'tcx> NonConstOp<'tcx> for FloatingPointOp {
6464

6565
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
6666
feature_err(
67-
&ccx.tcx.sess.parse_sess,
67+
&ccx.tcx.sess,
6868
sym::const_fn_floating_point_arithmetic,
6969
span,
7070
format!("floating point arithmetic is not allowed in {}s", ccx.const_kind()),
@@ -553,7 +553,7 @@ impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
553553

554554
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
555555
feature_err(
556-
&ccx.tcx.sess.parse_sess,
556+
&ccx.tcx.sess,
557557
sym::const_mut_refs,
558558
span,
559559
format!("dereferencing raw mutable pointers in {}s is unstable", ccx.const_kind(),),
@@ -624,7 +624,7 @@ pub mod ty {
624624

625625
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
626626
feature_err(
627-
&ccx.tcx.sess.parse_sess,
627+
&ccx.tcx.sess,
628628
sym::const_mut_refs,
629629
span,
630630
format!("mutable references are not allowed in {}s", ccx.const_kind()),

0 commit comments

Comments
 (0)