Skip to content

Commit 47604e5

Browse files
committed
rename "condition" to "filter"
1 parent fb55baf commit 47604e5

3 files changed

Lines changed: 31 additions & 40 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::ops::Range;
33
use rustc_errors::{Diagnostic, E0232};
44
use rustc_hir::AttrPath;
55
use rustc_hir::attrs::diagnostic::{
6-
Directive, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name, NameValue,
7-
OnUnimplementedCondition, Piece, Predicate,
6+
Directive, Filter, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name,
7+
NameValue, Piece, Predicate,
88
};
99
use rustc_macros::Diagnostic;
1010
use rustc_parse_format::{
@@ -347,19 +347,19 @@ fn parse_directive_items<'p, S: Stage>(
347347
if is_root {
348348
let items = or_malformed!(item.args().as_list()?);
349349
let mut iter = items.mixed();
350-
let condition: &MetaItemOrLitParser = match iter.next() {
350+
let filter: &MetaItemOrLitParser = match iter.next() {
351351
Some(c) => c,
352352
None => {
353353
cx.emit_err(InvalidOnClause::Empty { span });
354354
continue;
355355
}
356356
};
357357

358-
let filter = parse_condition(condition);
358+
let filter = parse_filter(filter);
359359

360360
if items.len() < 2 {
361361
// Something like `#[rustc_on_unimplemented(on(.., /* nothing */))]`
362-
// There's a condition but no directive behind it, this is a mistake.
362+
// There's a filter but no directive behind it, this is a mistake.
363363
malformed!();
364364
}
365365

@@ -527,12 +527,10 @@ fn slice_span(input: Span, Range { start, end }: Range<usize>, is_source_literal
527527
if is_source_literal { input.from_inner(InnerSpan { start, end }) } else { input }
528528
}
529529

530-
pub(crate) fn parse_condition(
531-
input: &MetaItemOrLitParser,
532-
) -> Result<OnUnimplementedCondition, InvalidOnClause> {
530+
pub(crate) fn parse_filter(input: &MetaItemOrLitParser) -> Result<Filter, InvalidOnClause> {
533531
let span = input.span();
534532
let pred = parse_predicate(input)?;
535-
Ok(OnUnimplementedCondition { span, pred })
533+
Ok(Filter { span, pred })
536534
}
537535

538536
fn parse_predicate(input: &MetaItemOrLitParser) -> Result<Predicate, InvalidOnClause> {
@@ -567,7 +565,7 @@ fn parse_predicate(input: &MetaItemOrLitParser) -> Result<Predicate, InvalidOnCl
567565
return Err(InvalidOnClause::UnsupportedLiteral { span: p.args_span() });
568566
};
569567
let name = parse_name(predicate.name);
570-
let value = parse_filter(value.name);
568+
let value = parse_filter_format(value.name);
571569
let kv = NameValue { name, value };
572570
Ok(Predicate::Match(kv))
573571
}
@@ -602,7 +600,7 @@ fn parse_name(name: Symbol) -> Name {
602600
}
603601
}
604602

605-
fn parse_filter(input: Symbol) -> FilterFormatString {
603+
fn parse_filter_format(input: Symbol) -> FilterFormatString {
606604
let pieces = Parser::new(input.as_str(), None, None, false, ParseMode::Diagnostic)
607605
.map(|p| match p {
608606
RpfPiece::Lit(s) => LitOrArg::Lit(Symbol::intern(s)),

compiler/rustc_hir/src/attrs/diagnostic.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct Directive {
1414
pub is_rustc_attr: bool,
1515
/// This is never nested more than once, i.e. the directives in this
1616
/// thinvec have no filters of their own.
17-
pub filters: ThinVec<(OnUnimplementedCondition, Directive)>,
17+
pub filters: ThinVec<(Filter, Directive)>,
1818
pub message: Option<(Span, FormatString)>,
1919
pub label: Option<(Span, FormatString)>,
2020
pub notes: ThinVec<FormatString>,
@@ -51,29 +51,29 @@ impl Directive {
5151

5252
pub fn eval(
5353
&self,
54-
condition_options: Option<&ConditionOptions>,
54+
filter_options: Option<&FilterOptions>,
5555
args: &FormatArgs,
5656
) -> CustomDiagnostic {
5757
let this = &args.this;
5858
debug!(
59-
"Directive::eval({self:?}, this={this}, options={condition_options:?}, args ={args:?})"
59+
"Directive::eval({self:?}, this={this}, options={filter_options:?}, args ={args:?})"
6060
);
6161

6262
let mut ret = CustomDiagnostic::default();
6363

64-
if let Some(condition_options) = condition_options {
64+
if let Some(filter_options) = filter_options {
6565
for (filter, directive) in &self.filters {
66-
if filter.matches_predicate(condition_options) {
66+
if filter.matches_predicate(filter_options) {
6767
debug!("eval: {filter:?} succeeded");
6868
ret.update(directive, args);
6969
} else {
70-
debug!("eval: skipping {filter:?} due to condition");
70+
debug!("eval: skipping {filter:?} due to {filter_options:?}");
7171
}
7272
}
7373
} else {
7474
debug_assert!(
7575
!self.is_rustc_attr,
76-
"Directive::eval called for `rustc_on_unimplemented` without `condition_options`"
76+
"Directive::eval called for `rustc_on_unimplemented` without `filter_options`"
7777
);
7878
};
7979
ret.update(self, args);
@@ -237,12 +237,12 @@ pub enum FormatArg {
237237

238238
/// Represents the `on` filter in `#[rustc_on_unimplemented]`.
239239
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
240-
pub struct OnUnimplementedCondition {
240+
pub struct Filter {
241241
pub span: Span,
242242
pub pred: Predicate,
243243
}
244-
impl OnUnimplementedCondition {
245-
pub fn matches_predicate(self: &OnUnimplementedCondition, options: &ConditionOptions) -> bool {
244+
impl Filter {
245+
pub fn matches_predicate(&self, options: &FilterOptions) -> bool {
246246
self.pred.eval(&mut |p| match p {
247247
FlagOrNv::Flag(b) => options.has_flag(*b),
248248
FlagOrNv::NameValue(NameValue { name, value }) => {
@@ -257,7 +257,7 @@ impl OnUnimplementedCondition {
257257
}
258258
}
259259

260-
/// Predicate(s) in `#[rustc_on_unimplemented]`'s `on` filter. See [`OnUnimplementedCondition`].
260+
/// Predicate(s) in `#[rustc_on_unimplemented]`'s `on` filter. See [`Filter`].
261261
///
262262
/// It is similar to the predicate in the `cfg` attribute,
263263
/// and may contain nested predicates.
@@ -391,8 +391,7 @@ pub enum LitOrArg {
391391
Arg(Symbol),
392392
}
393393

394-
/// Used with `OnUnimplementedCondition::matches_predicate` to evaluate the
395-
/// [`OnUnimplementedCondition`].
394+
/// Used with `Filter::matches_predicate` to evaluate the [`Filter`].
396395
///
397396
/// For example, given a
398397
/// ```rust,ignore (just an example)
@@ -418,7 +417,7 @@ pub enum LitOrArg {
418417
/// it will look like this:
419418
///
420419
/// ```rust,ignore (just an example)
421-
/// ConditionOptions {
420+
/// FilterOptions {
422421
/// self_types: ["u32", "{integral}"],
423422
/// from_desugaring: Some("QuestionMark"),
424423
/// cause: None,
@@ -431,7 +430,7 @@ pub enum LitOrArg {
431430
/// }
432431
/// ```
433432
#[derive(Debug)]
434-
pub struct ConditionOptions {
433+
pub struct FilterOptions {
435434
/// All the self types that may apply.
436435
pub self_types: Vec<String>,
437436
// The kind of compiler desugaring.
@@ -445,7 +444,7 @@ pub struct ConditionOptions {
445444
pub generic_args: Vec<(Symbol, String)>,
446445
}
447446

448-
impl ConditionOptions {
447+
impl FilterOptions {
449448
pub fn has_flag(&self, name: Flag) -> bool {
450449
match name {
451450
Flag::CrateLocal => self.crate_local,

compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
use rustc_hir as hir;
4-
use rustc_hir::attrs::diagnostic::{ConditionOptions, CustomDiagnostic, FormatArgs};
4+
use rustc_hir::attrs::diagnostic::{CustomDiagnostic, FilterOptions, FormatArgs};
55
use rustc_hir::def_id::LocalDefId;
66
use rustc_hir::find_attr;
77
use rustc_middle::ty::print::PrintTraitRefExt;
@@ -40,11 +40,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
4040
if trait_pred.polarity() != ty::PredicatePolarity::Positive {
4141
return CustomDiagnostic::default();
4242
}
43-
let (condition_options, format_args) =
43+
let (filter_options, format_args) =
4444
self.on_unimplemented_components(trait_pred, obligation, long_ty_path);
4545
if let Some(command) = find_attr!(self.tcx, trait_pred.def_id(), OnUnimplemented {directive, ..} => directive.as_deref()).flatten() {
4646
command.eval(
47-
Some(&condition_options),
47+
Some(&filter_options),
4848
&format_args,
4949
)
5050
} else {
@@ -57,7 +57,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
5757
trait_pred: ty::PolyTraitPredicate<'tcx>,
5858
obligation: &PredicateObligation<'tcx>,
5959
long_ty_path: &mut Option<PathBuf>,
60-
) -> (ConditionOptions, FormatArgs) {
60+
) -> (FilterOptions, FormatArgs) {
6161
let (def_id, args) = (trait_pred.def_id(), trait_pred.skip_binder().trait_ref.args);
6262
let trait_pred = trait_pred.skip_binder();
6363

@@ -219,14 +219,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
219219
let this = self.tcx.def_path_str(trait_pred.trait_ref.def_id);
220220
let this_sugared = trait_pred.trait_ref.print_trait_sugared().to_string();
221221

222-
let condition_options = ConditionOptions {
223-
self_types,
224-
from_desugaring,
225-
cause,
226-
crate_local,
227-
direct,
228-
generic_args,
229-
};
222+
let filter_options =
223+
FilterOptions { self_types, from_desugaring, cause, crate_local, direct, generic_args };
230224

231225
// Unlike the generic_args earlier,
232226
// this one is *not* collected under `with_no_trimmed_paths!`
@@ -256,6 +250,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
256250
.collect();
257251

258252
let format_args = FormatArgs { this, this_sugared, generic_args, item_context };
259-
(condition_options, format_args)
253+
(filter_options, format_args)
260254
}
261255
}

0 commit comments

Comments
 (0)