File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
compiler/rustc_passes/src Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,9 @@ impl CheckAttrVisitor<'tcx> {
9898 | sym:: rustc_if_this_changed
9999 | sym:: rustc_then_this_would_need => self . check_rustc_dirty_clean ( & attr) ,
100100 sym:: cmse_nonsecure_entry => self . check_cmse_nonsecure_entry ( attr, span, target) ,
101+ sym:: default_method_body_is_const => {
102+ self . check_default_method_body_is_const ( attr, span, target)
103+ }
101104 _ => true ,
102105 } ;
103106 // lint-only checks
@@ -1465,6 +1468,29 @@ impl CheckAttrVisitor<'tcx> {
14651468 }
14661469 }
14671470 }
1471+
1472+ /// default_method_body_is_const should only be applied to trait methods with default bodies.
1473+ fn check_default_method_body_is_const (
1474+ & self ,
1475+ attr : & Attribute ,
1476+ span : & Span ,
1477+ target : Target ,
1478+ ) -> bool {
1479+ match target {
1480+ Target :: Method ( MethodKind :: Trait { body : true } ) => true ,
1481+ _ => {
1482+ self . tcx
1483+ . sess
1484+ . struct_span_err (
1485+ attr. span ,
1486+ "attribute should be applied to a trait method with body" ,
1487+ )
1488+ . span_label ( * span, "not a trait method or missing a body" )
1489+ . emit ( ) ;
1490+ false
1491+ }
1492+ }
1493+ }
14681494}
14691495
14701496impl Visitor < ' tcx > for CheckAttrVisitor < ' tcx > {
You can’t perform that action at this time.
0 commit comments