Skip to content

Commit 0610172

Browse files
committed
rename "condition" to "filter"
1 parent d6969da commit 0610172

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::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::{
@@ -329,19 +329,19 @@ fn parse_directive_items<'p>(
329329
if is_root {
330330
let items = or_malformed!(item.args().as_list()?);
331331
let mut iter = items.mixed();
332-
let condition: &MetaItemOrLitParser = match iter.next() {
332+
let filter: &MetaItemOrLitParser = match iter.next() {
333333
Some(c) => c,
334334
None => {
335335
cx.emit_err(InvalidOnClause::Empty { span });
336336
continue;
337337
}
338338
};
339339

340-
let filter = parse_condition(condition);
340+
let filter = parse_filter(filter);
341341

342342
if items.len() < 2 {
343343
// Something like `#[rustc_on_unimplemented(on(.., /* nothing */))]`
344-
// There's a condition but no directive behind it, this is a mistake.
344+
// There's a filter but no directive behind it, this is a mistake.
345345
malformed!();
346346
}
347347

@@ -509,12 +509,10 @@ fn slice_span(input: Span, Range { start, end }: Range<usize>, is_source_literal
509509
if is_source_literal { input.from_inner(InnerSpan { start, end }) } else { input }
510510
}
511511

512-
pub(crate) fn parse_condition(
513-
input: &MetaItemOrLitParser,
514-
) -> Result<OnUnimplementedCondition, InvalidOnClause> {
512+
pub(crate) fn parse_filter(input: &MetaItemOrLitParser) -> Result<Filter, InvalidOnClause> {
515513
let span = input.span();
516514
let pred = parse_predicate(input)?;
517-
Ok(OnUnimplementedCondition { span, pred })
515+
Ok(Filter { span, pred })
518516
}
519517

520518
fn parse_predicate(input: &MetaItemOrLitParser) -> Result<Predicate, InvalidOnClause> {
@@ -549,7 +547,7 @@ fn parse_predicate(input: &MetaItemOrLitParser) -> Result<Predicate, InvalidOnCl
549547
return Err(InvalidOnClause::UnsupportedLiteral { span: p.args_span() });
550548
};
551549
let name = parse_name(predicate.name);
552-
let value = parse_filter(value.name);
550+
let value = parse_filter_format(value.name);
553551
let kv = NameValue { name, value };
554552
Ok(Predicate::Match(kv))
555553
}
@@ -584,7 +582,7 @@ fn parse_name(name: Symbol) -> Name {
584582
}
585583
}
586584

587-
fn parse_filter(input: Symbol) -> FilterFormatString {
585+
fn parse_filter_format(input: Symbol) -> FilterFormatString {
588586
let pieces = Parser::new(input.as_str(), None, None, false, ParseMode::Diagnostic)
589587
.map(|p| match p {
590588
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
@@ -15,7 +15,7 @@ pub struct Directive {
1515
pub is_rustc_attr: bool,
1616
/// This is never nested more than once, i.e. the directives in this
1717
/// thinvec have no filters of their own.
18-
pub filters: ThinVec<(OnUnimplementedCondition, Directive)>,
18+
pub filters: ThinVec<(Filter, Directive)>,
1919
pub message: Option<(Span, FormatString)>,
2020
pub label: Option<(Span, FormatString)>,
2121
pub notes: ThinVec<FormatString>,
@@ -52,29 +52,29 @@ impl Directive {
5252

5353
pub fn eval(
5454
&self,
55-
condition_options: Option<&ConditionOptions>,
55+
filter_options: Option<&FilterOptions>,
5656
args: &FormatArgs,
5757
) -> CustomDiagnostic {
5858
let this = &args.this;
5959
debug!(
60-
"Directive::eval({self:?}, this={this}, options={condition_options:?}, args ={args:?})"
60+
"Directive::eval({self:?}, this={this}, options={filter_options:?}, args ={args:?})"
6161
);
6262

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

65-
if let Some(condition_options) = condition_options {
65+
if let Some(filter_options) = filter_options {
6666
for (filter, directive) in &self.filters {
67-
if filter.matches_predicate(condition_options) {
67+
if filter.matches_predicate(filter_options) {
6868
debug!("eval: {filter:?} succeeded");
6969
ret.update(directive, args);
7070
} else {
71-
debug!("eval: skipping {filter:?} due to condition");
71+
debug!("eval: skipping {filter:?} due to {filter_options:?}");
7272
}
7373
}
7474
} else {
7575
debug_assert!(
7676
!self.is_rustc_attr,
77-
"Directive::eval called for `rustc_on_unimplemented` without `condition_options`"
77+
"Directive::eval called for `rustc_on_unimplemented` without `filter_options`"
7878
);
7979
};
8080
ret.update(self, args);
@@ -238,12 +238,12 @@ pub enum FormatArg {
238238

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

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

395-
/// Used with `OnUnimplementedCondition::matches_predicate` to evaluate the
396-
/// [`OnUnimplementedCondition`].
395+
/// Used with `Filter::matches_predicate` to evaluate the [`Filter`].
397396
///
398397
/// For example, given a
399398
/// ```rust,ignore (just an example)
@@ -419,7 +418,7 @@ pub enum LitOrArg {
419418
/// it will look like this:
420419
///
421420
/// ```rust,ignore (just an example)
422-
/// ConditionOptions {
421+
/// FilterOptions {
423422
/// self_types: ["u32", "{integral}"],
424423
/// from_desugaring: Some("QuestionMark"),
425424
/// cause: None,
@@ -432,7 +431,7 @@ pub enum LitOrArg {
432431
/// }
433432
/// ```
434433
#[derive(Debug)]
435-
pub struct ConditionOptions {
434+
pub struct FilterOptions {
436435
/// All the self types that may apply.
437436
pub self_types: Vec<String>,
438437
// The kind of compiler desugaring.
@@ -446,7 +445,7 @@ pub struct ConditionOptions {
446445
pub generic_args: Vec<(Symbol, String)>,
447446
}
448447

449-
impl ConditionOptions {
448+
impl FilterOptions {
450449
pub fn has_flag(&self, name: Flag) -> bool {
451450
match name {
452451
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)