migrate lib_features.rs to translateable diagnostics
This commit is contained in:
parent
40d5f00e16
commit
c457abee2e
3 changed files with 40 additions and 20 deletions
|
@ -420,3 +420,9 @@ passes_unrecognized_field =
|
|||
|
||||
passes_layout =
|
||||
layout error: {$layout_error}
|
||||
|
||||
passes_feature_stable_twice =
|
||||
feature `{$feature}` is declared stable since {$since}, but was previously declared stable since {$prev_since}
|
||||
|
||||
passes_feature_previously_declared =
|
||||
feature `{$feature}` is declared {$declared}, but was previously declared {$prev_declared}
|
||||
|
|
|
@ -832,3 +832,23 @@ pub struct Layout {
|
|||
pub span: Span,
|
||||
pub layout_error: String,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes::feature_stable_twice, code = "E0711")]
|
||||
pub struct FeatureStableTwice {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub feature: Symbol,
|
||||
pub since: Symbol,
|
||||
pub prev_since: Symbol,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes::feature_previously_declared, code = "E0711")]
|
||||
pub struct FeaturePreviouslyDeclared<'a, 'b> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub feature: Symbol,
|
||||
pub declared: &'a str,
|
||||
pub prev_declared: &'b str,
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
use rustc_ast::{Attribute, MetaItemKind};
|
||||
use rustc_attr::{rust_version_symbol, VERSION_PLACEHOLDER};
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::middle::lib_features::LibFeatures;
|
||||
|
@ -15,6 +14,8 @@ use rustc_middle::ty::TyCtxt;
|
|||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{sym, Span};
|
||||
|
||||
use crate::errors::{FeaturePreviouslyDeclared, FeatureStableTwice};
|
||||
|
||||
fn new_lib_features() -> LibFeatures {
|
||||
LibFeatures { stable: Default::default(), unstable: Default::default() }
|
||||
}
|
||||
|
@ -92,14 +93,12 @@ impl<'tcx> LibFeatureCollector<'tcx> {
|
|||
(Some(since), _, false) => {
|
||||
if let Some((prev_since, _)) = self.lib_features.stable.get(&feature) {
|
||||
if *prev_since != since {
|
||||
self.span_feature_error(
|
||||
self.tcx.sess.emit_err(FeatureStableTwice {
|
||||
span,
|
||||
&format!(
|
||||
"feature `{}` is declared stable since {}, \
|
||||
but was previously declared stable since {}",
|
||||
feature, since, prev_since,
|
||||
),
|
||||
);
|
||||
feature,
|
||||
since,
|
||||
prev_since: *prev_since,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -110,22 +109,17 @@ impl<'tcx> LibFeatureCollector<'tcx> {
|
|||
self.lib_features.unstable.insert(feature, span);
|
||||
}
|
||||
(Some(_), _, true) | (None, true, _) => {
|
||||
self.span_feature_error(
|
||||
let declared = if since.is_some() { "stable" } else { "unstable" };
|
||||
let prev_declared = if since.is_none() { "stable" } else { "unstable" };
|
||||
self.tcx.sess.emit_err(FeaturePreviouslyDeclared {
|
||||
span,
|
||||
&format!(
|
||||
"feature `{}` is declared {}, but was previously declared {}",
|
||||
feature,
|
||||
if since.is_some() { "stable" } else { "unstable" },
|
||||
if since.is_none() { "stable" } else { "unstable" },
|
||||
),
|
||||
);
|
||||
declared,
|
||||
prev_declared,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn span_feature_error(&self, span: Span, msg: &str) {
|
||||
struct_span_err!(self.tcx.sess, span, E0711, "{}", &msg).emit();
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for LibFeatureCollector<'tcx> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue