2121//! `late_lint_methods!` invocation in `lib.rs`.
2222
2323use crate :: fluent_generated as fluent;
24+ use crate :: r#unsafe:: { UNSAFE_OBLIGATION_DEFINE , UNSAFE_OBLIGATION_DISCHARGE } ;
2425use crate :: {
2526 errors:: BuiltinEllpisisInclusiveRangePatterns ,
2627 lints:: {
@@ -36,22 +37,21 @@ use crate::{
3637 BuiltinTypeAliasGenericBoundsSuggestion , BuiltinTypeAliasWhereClause ,
3738 BuiltinUnexpectedCliConfigName , BuiltinUnexpectedCliConfigValue ,
3839 BuiltinUngatedAsyncFnTrackCaller , BuiltinUnnameableTestItems , BuiltinUnpermittedTypeInit ,
39- BuiltinUnpermittedTypeInitSub , BuiltinUnreachablePub , BuiltinUnsafe ,
40- BuiltinUnstableFeatures , BuiltinUnusedDocComment , BuiltinUnusedDocCommentSub ,
41- BuiltinWhileTrue , SuggestChangingAssocTypes ,
40+ BuiltinUnpermittedTypeInitSub , BuiltinUnreachablePub , BuiltinUnstableFeatures ,
41+ BuiltinUnusedDocComment , BuiltinUnusedDocCommentSub , BuiltinWhileTrue ,
42+ SuggestChangingAssocTypes ,
4243 } ,
4344 types:: { transparent_newtype_field, CItemKind } ,
4445 EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext ,
4546} ;
4647use hir:: IsAsync ;
4748use rustc_ast:: attr;
4849use rustc_ast:: tokenstream:: { TokenStream , TokenTree } ;
49- use rustc_ast:: visit:: { FnCtxt , FnKind } ;
5050use rustc_ast:: { self as ast, * } ;
5151use rustc_ast_pretty:: pprust:: { self , expr_to_string} ;
5252use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
5353use rustc_data_structures:: stack:: ensure_sufficient_stack;
54- use rustc_errors:: { Applicability , DecorateLint , MultiSpan } ;
54+ use rustc_errors:: { Applicability , MultiSpan } ;
5555use rustc_feature:: { deprecated_attributes, AttributeGate , BuiltinAttribute , GateIssue , Stability } ;
5656use rustc_hir as hir;
5757use rustc_hir:: def:: { DefKind , Res } ;
@@ -287,140 +287,6 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
287287 }
288288}
289289
290- declare_lint ! {
291- /// The `unsafe_code` lint catches usage of `unsafe` code.
292- ///
293- /// ### Example
294- ///
295- /// ```rust,compile_fail
296- /// #![deny(unsafe_code)]
297- /// fn main() {
298- /// unsafe {
299- ///
300- /// }
301- /// }
302- /// ```
303- ///
304- /// {{produces}}
305- ///
306- /// ### Explanation
307- ///
308- /// This lint is intended to restrict the usage of `unsafe`, which can be
309- /// difficult to use correctly.
310- UNSAFE_CODE ,
311- Allow ,
312- "usage of `unsafe` code"
313- }
314-
315- declare_lint_pass ! ( UnsafeCode => [ UNSAFE_CODE ] ) ;
316-
317- impl UnsafeCode {
318- fn report_unsafe (
319- & self ,
320- cx : & EarlyContext < ' _ > ,
321- span : Span ,
322- decorate : impl for < ' a > DecorateLint < ' a , ( ) > ,
323- ) {
324- // This comes from a macro that has `#[allow_internal_unsafe]`.
325- if span. allows_unsafe ( ) {
326- return ;
327- }
328-
329- cx. emit_spanned_lint ( UNSAFE_CODE , span, decorate) ;
330- }
331- }
332-
333- impl EarlyLintPass for UnsafeCode {
334- fn check_attribute ( & mut self , cx : & EarlyContext < ' _ > , attr : & ast:: Attribute ) {
335- if attr. has_name ( sym:: allow_internal_unsafe) {
336- self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: AllowInternalUnsafe ) ;
337- }
338- }
339-
340- #[ inline]
341- fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , e : & ast:: Expr ) {
342- if let ast:: ExprKind :: Block ( ref blk, _) = e. kind {
343- // Don't warn about generated blocks; that'll just pollute the output.
344- if blk. rules == ast:: BlockCheckMode :: Unsafe ( ast:: UserProvided ) {
345- self . report_unsafe ( cx, blk. span , BuiltinUnsafe :: UnsafeBlock ) ;
346- }
347- }
348- }
349-
350- fn check_item ( & mut self , cx : & EarlyContext < ' _ > , it : & ast:: Item ) {
351- match it. kind {
352- ast:: ItemKind :: Trait ( box ast:: Trait { unsafety : ast:: Unsafe :: Yes ( _) , .. } ) => {
353- self . report_unsafe ( cx, it. span , BuiltinUnsafe :: UnsafeTrait ) ;
354- }
355-
356- ast:: ItemKind :: Impl ( box ast:: Impl { unsafety : ast:: Unsafe :: Yes ( _) , .. } ) => {
357- self . report_unsafe ( cx, it. span , BuiltinUnsafe :: UnsafeImpl ) ;
358- }
359-
360- ast:: ItemKind :: Fn ( ..) => {
361- if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: no_mangle) {
362- self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: NoMangleFn ) ;
363- }
364-
365- if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: export_name) {
366- self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: ExportNameFn ) ;
367- }
368-
369- if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: link_section) {
370- self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: LinkSectionFn ) ;
371- }
372- }
373-
374- ast:: ItemKind :: Static ( ..) => {
375- if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: no_mangle) {
376- self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: NoMangleStatic ) ;
377- }
378-
379- if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: export_name) {
380- self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: ExportNameStatic ) ;
381- }
382-
383- if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: link_section) {
384- self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: LinkSectionStatic ) ;
385- }
386- }
387-
388- _ => { }
389- }
390- }
391-
392- fn check_impl_item ( & mut self , cx : & EarlyContext < ' _ > , it : & ast:: AssocItem ) {
393- if let ast:: AssocItemKind :: Fn ( ..) = it. kind {
394- if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: no_mangle) {
395- self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: NoMangleMethod ) ;
396- }
397- if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: export_name) {
398- self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: ExportNameMethod ) ;
399- }
400- }
401- }
402-
403- fn check_fn ( & mut self , cx : & EarlyContext < ' _ > , fk : FnKind < ' _ > , span : Span , _: ast:: NodeId ) {
404- if let FnKind :: Fn (
405- ctxt,
406- _,
407- ast:: FnSig { header : ast:: FnHeader { unsafety : ast:: Unsafe :: Yes ( _) , .. } , .. } ,
408- _,
409- _,
410- body,
411- ) = fk
412- {
413- let decorator = match ctxt {
414- FnCtxt :: Foreign => return ,
415- FnCtxt :: Free => BuiltinUnsafe :: DeclUnsafeFn ,
416- FnCtxt :: Assoc ( _) if body. is_none ( ) => BuiltinUnsafe :: DeclUnsafeMethod ,
417- FnCtxt :: Assoc ( _) => BuiltinUnsafe :: ImplUnsafeMethod ,
418- } ;
419- self . report_unsafe ( cx, span, decorator) ;
420- }
421- }
422- }
423-
424290declare_lint ! {
425291 /// The `missing_docs` lint detects missing documentation for public items.
426292 ///
@@ -1633,7 +1499,8 @@ declare_lint_pass!(
16331499 WHILE_TRUE ,
16341500 BOX_POINTERS ,
16351501 NON_SHORTHAND_FIELD_PATTERNS ,
1636- UNSAFE_CODE ,
1502+ UNSAFE_OBLIGATION_DEFINE ,
1503+ UNSAFE_OBLIGATION_DISCHARGE ,
16371504 MISSING_DOCS ,
16381505 MISSING_COPY_IMPLEMENTATIONS ,
16391506 MISSING_DEBUG_IMPLEMENTATIONS ,
0 commit comments