@@ -4,6 +4,7 @@ use std::path::PathBuf;
44use rustc_ast:: { LitKind , MetaItem , MetaItemInner , MetaItemKind , MetaItemLit } ;
55use rustc_errors:: codes:: * ;
66use rustc_errors:: { ErrorGuaranteed , struct_span_code_err} ;
7+ use rustc_hir as hir;
78use rustc_hir:: def_id:: { DefId , LocalDefId } ;
89use rustc_hir:: { AttrArgs , Attribute } ;
910use rustc_macros:: LintDiagnostic ;
@@ -13,17 +14,16 @@ use rustc_middle::ty::{self, GenericArgsRef, GenericParamDef, GenericParamDefKin
1314use rustc_session:: lint:: builtin:: UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ;
1415use rustc_span:: { Span , Symbol , sym} ;
1516use tracing:: { debug, info} ;
16- use { rustc_attr_parsing as attr, rustc_hir as hir} ;
1717
1818use super :: { ObligationCauseCode , PredicateObligation } ;
1919use crate :: error_reporting:: TypeErrCtxt ;
20- use crate :: error_reporting:: traits:: on_unimplemented_condition:: { Condition , ConditionOptions } ;
20+ use crate :: error_reporting:: traits:: on_unimplemented_condition:: {
21+ ConditionOptions , OnUnimplementedCondition ,
22+ } ;
2123use crate :: error_reporting:: traits:: on_unimplemented_format:: {
2224 Ctx , FormatArgs , FormatString , FormatWarning ,
2325} ;
24- use crate :: errors:: {
25- EmptyOnClauseInOnUnimplemented , InvalidOnClauseInOnUnimplemented , NoValueInOnUnimplemented ,
26- } ;
26+ use crate :: errors:: { InvalidOnClause , NoValueInOnUnimplemented } ;
2727use crate :: infer:: InferCtxtExt ;
2828
2929impl < ' tcx > TypeErrCtxt < ' _ , ' tcx > {
@@ -306,21 +306,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
306306#[ derive( Clone , Debug ) ]
307307pub struct OnUnimplementedFormatString {
308308 /// Symbol of the format string, i.e. `"content"`
309- pub symbol : Symbol ,
309+ symbol : Symbol ,
310310 ///The span of the format string, i.e. `"content"`
311- pub span : Span ,
312- pub is_diagnostic_namespace_variant : bool ,
311+ span : Span ,
312+ is_diagnostic_namespace_variant : bool ,
313313}
314314
315315#[ derive( Debug ) ]
316316pub struct OnUnimplementedDirective {
317- pub condition : Option < Condition > ,
318- pub subcommands : Vec < OnUnimplementedDirective > ,
319- pub message : Option < ( Span , OnUnimplementedFormatString ) > ,
320- pub label : Option < ( Span , OnUnimplementedFormatString ) > ,
321- pub notes : Vec < OnUnimplementedFormatString > ,
322- pub parent_label : Option < OnUnimplementedFormatString > ,
323- pub append_const_msg : Option < AppendConstMessage > ,
317+ condition : Option < OnUnimplementedCondition > ,
318+ subcommands : Vec < OnUnimplementedDirective > ,
319+ message : Option < ( Span , OnUnimplementedFormatString ) > ,
320+ label : Option < ( Span , OnUnimplementedFormatString ) > ,
321+ notes : Vec < OnUnimplementedFormatString > ,
322+ parent_label : Option < OnUnimplementedFormatString > ,
323+ append_const_msg : Option < AppendConstMessage > ,
324324}
325325
326326/// For the `#[rustc_on_unimplemented]` attribute
@@ -427,18 +427,12 @@ impl<'tcx> OnUnimplementedDirective {
427427 } else {
428428 let cond = item_iter
429429 . next ( )
430- . ok_or_else ( || tcx. dcx ( ) . emit_err ( EmptyOnClauseInOnUnimplemented { span } ) ) ?
431- . meta_item_or_bool ( )
432- . ok_or_else ( || tcx. dcx ( ) . emit_err ( InvalidOnClauseInOnUnimplemented { span } ) ) ?;
433- attr:: eval_condition ( cond, & tcx. sess , Some ( tcx. features ( ) ) , & mut |cfg| {
434- if let Some ( value) = cfg. value
435- && let Err ( guar) = parse_value ( value, cfg. span )
436- {
437- errored = Some ( guar) ;
438- }
439- true
440- } ) ;
441- Some ( Condition { inner : cond. clone ( ) } )
430+ . ok_or_else ( || tcx. dcx ( ) . emit_err ( InvalidOnClause :: Empty { span } ) ) ?;
431+
432+ match OnUnimplementedCondition :: parse ( cond) {
433+ Ok ( condition) => Some ( condition) ,
434+ Err ( e) => return Err ( tcx. dcx ( ) . emit_err ( e) ) ,
435+ }
442436 } ;
443437
444438 let mut message = None ;
@@ -724,7 +718,7 @@ impl<'tcx> OnUnimplementedDirective {
724718 result
725719 }
726720
727- pub fn evaluate (
721+ pub ( crate ) fn evaluate (
728722 & self ,
729723 tcx : TyCtxt < ' tcx > ,
730724 trait_ref : ty:: TraitRef < ' tcx > ,
@@ -744,7 +738,7 @@ impl<'tcx> OnUnimplementedDirective {
744738 for command in self . subcommands . iter ( ) . chain ( Some ( self ) ) . rev ( ) {
745739 debug ! ( ?command) ;
746740 if let Some ( ref condition) = command. condition
747- && !condition. matches_predicate ( tcx , condition_options)
741+ && !condition. matches_predicate ( condition_options)
748742 {
749743 debug ! ( "evaluate: skipping {:?} due to condition" , command) ;
750744 continue ;
0 commit comments