Add check for ui_testing via promoting parameters from ParseSess
to Session
This commit is contained in:
parent
b55faad314
commit
36a69e9d39
44 changed files with 188 additions and 233 deletions
|
@ -1,6 +1,5 @@
|
|||
use std::num::NonZeroU32;
|
||||
|
||||
use crate::parse::ParseSess;
|
||||
use rustc_ast::token;
|
||||
use rustc_ast::util::literal::LitError;
|
||||
use rustc_errors::{
|
||||
|
@ -10,6 +9,8 @@ use rustc_macros::Diagnostic;
|
|||
use rustc_span::{BytePos, Span, Symbol};
|
||||
use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple};
|
||||
|
||||
use crate::parse::ParseSess;
|
||||
|
||||
pub struct FeatureGateError {
|
||||
pub span: MultiSpan,
|
||||
pub explain: DiagnosticMessage,
|
||||
|
@ -33,16 +34,18 @@ pub struct FeatureDiagnosticForIssue {
|
|||
#[derive(Subdiagnostic)]
|
||||
#[note(session_feature_suggest_upgrade_compiler)]
|
||||
pub struct SuggestUpgradeCompiler {
|
||||
version: &'static str,
|
||||
date: &'static str,
|
||||
}
|
||||
|
||||
impl SuggestUpgradeCompiler {
|
||||
pub fn new() -> Self {
|
||||
let version = option_env!("CFG_VERSION").unwrap_or("unknown");
|
||||
let date = option_env!("CFG_VER_DATE").unwrap_or("unknown");
|
||||
pub fn ui_testing() -> Self {
|
||||
Self { date: "YYYY-MM-DD" }
|
||||
}
|
||||
|
||||
Self { version, date }
|
||||
pub fn new() -> Option<Self> {
|
||||
let date = option_env!("CFG_VER_DATE")?;
|
||||
|
||||
Some(Self { date })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use crate::errors::{
|
|||
use crate::lint::{
|
||||
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
|
||||
};
|
||||
use crate::Session;
|
||||
use rustc_ast::node_id::NodeId;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc};
|
||||
|
@ -80,7 +81,7 @@ impl SymbolGallery {
|
|||
/// The `feature`'s `Symbol` is the one you used in `unstable.rs` and `rustc_span::symbols`.
|
||||
#[track_caller]
|
||||
pub fn feature_err(
|
||||
sess: &ParseSess,
|
||||
sess: &Session,
|
||||
feature: Symbol,
|
||||
span: impl Into<MultiSpan>,
|
||||
explain: impl Into<DiagnosticMessage>,
|
||||
|
@ -94,7 +95,7 @@ pub fn feature_err(
|
|||
/// Almost always, you want to use this for a language feature. If so, prefer `feature_err`.
|
||||
#[track_caller]
|
||||
pub fn feature_err_issue(
|
||||
sess: &ParseSess,
|
||||
sess: &Session,
|
||||
feature: Symbol,
|
||||
span: impl Into<MultiSpan>,
|
||||
issue: GateIssue,
|
||||
|
@ -104,12 +105,14 @@ pub fn feature_err_issue(
|
|||
|
||||
// Cancel an earlier warning for this same error, if it exists.
|
||||
if let Some(span) = span.primary_span() {
|
||||
if let Some(err) = sess.dcx.steal_diagnostic(span, StashKey::EarlySyntaxWarning) {
|
||||
if let Some(err) = sess.parse_sess.dcx.steal_diagnostic(span, StashKey::EarlySyntaxWarning)
|
||||
{
|
||||
err.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
let mut err = sess.dcx.create_err(FeatureGateError { span, explain: explain.into() });
|
||||
let mut err =
|
||||
sess.parse_sess.dcx.create_err(FeatureGateError { span, explain: explain.into() });
|
||||
add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false);
|
||||
err
|
||||
}
|
||||
|
@ -118,7 +121,7 @@ pub fn feature_err_issue(
|
|||
///
|
||||
/// This diagnostic is only a warning and *does not cause compilation to fail*.
|
||||
#[track_caller]
|
||||
pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'static str) {
|
||||
pub fn feature_warn(sess: &Session, feature: Symbol, span: Span, explain: &'static str) {
|
||||
feature_warn_issue(sess, feature, span, GateIssue::Language, explain);
|
||||
}
|
||||
|
||||
|
@ -132,13 +135,13 @@ pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'st
|
|||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
#[track_caller]
|
||||
pub fn feature_warn_issue(
|
||||
sess: &ParseSess,
|
||||
sess: &Session,
|
||||
feature: Symbol,
|
||||
span: Span,
|
||||
issue: GateIssue,
|
||||
explain: &'static str,
|
||||
) {
|
||||
let mut err = sess.dcx.struct_span_warn(span, explain);
|
||||
let mut err = sess.parse_sess.dcx.struct_span_warn(span, explain);
|
||||
add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false);
|
||||
|
||||
// Decorate this as a future-incompatibility lint as in rustc_middle::lint::struct_lint_level
|
||||
|
@ -153,7 +156,7 @@ pub fn feature_warn_issue(
|
|||
}
|
||||
|
||||
/// Adds the diagnostics for a feature to an existing error.
|
||||
pub fn add_feature_diagnostics(err: &mut Diagnostic, sess: &ParseSess, feature: Symbol) {
|
||||
pub fn add_feature_diagnostics(err: &mut Diagnostic, sess: &Session, feature: Symbol) {
|
||||
add_feature_diagnostics_for_issue(err, sess, feature, GateIssue::Language, false);
|
||||
}
|
||||
|
||||
|
@ -164,7 +167,7 @@ pub fn add_feature_diagnostics(err: &mut Diagnostic, sess: &ParseSess, feature:
|
|||
/// `add_feature_diagnostics`.
|
||||
pub fn add_feature_diagnostics_for_issue(
|
||||
err: &mut Diagnostic,
|
||||
sess: &ParseSess,
|
||||
sess: &Session,
|
||||
feature: Symbol,
|
||||
issue: GateIssue,
|
||||
feature_from_cli: bool,
|
||||
|
@ -174,14 +177,18 @@ pub fn add_feature_diagnostics_for_issue(
|
|||
}
|
||||
|
||||
// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
|
||||
if sess.unstable_features.is_nightly_build() {
|
||||
if sess.parse_sess.unstable_features.is_nightly_build() {
|
||||
if feature_from_cli {
|
||||
err.subdiagnostic(CliFeatureDiagnosticHelp { feature });
|
||||
} else {
|
||||
err.subdiagnostic(FeatureDiagnosticHelp { feature });
|
||||
}
|
||||
|
||||
err.subdiagnostic(SuggestUpgradeCompiler::new());
|
||||
if sess.opts.unstable_opts.ui_testing {
|
||||
err.subdiagnostic(SuggestUpgradeCompiler::ui_testing());
|
||||
} else if let Some(suggestion) = SuggestUpgradeCompiler::new() {
|
||||
err.subdiagnostic(suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ impl Session {
|
|||
if err.code.is_none() {
|
||||
err.code(error_code!(E0658));
|
||||
}
|
||||
add_feature_diagnostics(&mut err, &self.parse_sess, feature);
|
||||
add_feature_diagnostics(&mut err, self, feature);
|
||||
err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue