@@ -291,6 +291,17 @@ private Type inferAnnotatedType(AstNode n, TypePath path) {
291291 result = n .( ShorthandSelfParameterMention ) .resolveTypeAt ( path )
292292}
293293
294+ /**
295+ * Holds if `me` is a call to the `panic!` macro.
296+ *
297+ * `panic!` needs special treatment, because it expands to a block expression
298+ * that looks like it should have type `()` instead of the correct `!` type.
299+ */
300+ pragma [ nomagic]
301+ private predicate isPanicMacroCall ( MacroExpr me ) {
302+ me .getMacroCall ( ) .resolveMacro ( ) .( MacroRules ) .getName ( ) .getText ( ) = "panic"
303+ }
304+
294305/** Module for inferring certain type information. */
295306module CertainTypeInference {
296307 pragma [ nomagic]
@@ -443,6 +454,14 @@ module CertainTypeInference {
443454 or
444455 result = inferCastExprType ( n , path )
445456 or
457+ exprHasUnitType ( n ) and
458+ path .isEmpty ( ) and
459+ result instanceof UnitType
460+ or
461+ isPanicMacroCall ( n ) and
462+ path .isEmpty ( ) and
463+ result instanceof NeverType
464+ or
446465 infersCertainTypeAt ( n , path , result .getATypeParameter ( ) )
447466 }
448467
@@ -579,7 +598,8 @@ private predicate typeEquality(AstNode n1, TypePath prefix1, AstNode n2, TypePat
579598 n2 = be .getRhs ( )
580599 )
581600 or
582- n1 = n2 .( MacroExpr ) .getMacroCall ( ) .getMacroCallExpansion ( )
601+ n1 = n2 .( MacroExpr ) .getMacroCall ( ) .getMacroCallExpansion ( ) and
602+ not isPanicMacroCall ( n2 )
583603 or
584604 n1 = n2 .( MacroPat ) .getMacroCall ( ) .getMacroCallExpansion ( )
585605 or
@@ -931,14 +951,17 @@ private predicate functionInfoBlanketLike(
931951 */
932952bindingset [ path, type]
933953private predicate isComplexRootStripped ( TypePath path , Type type ) {
934- path .isEmpty ( ) and
935- not validSelfType ( type )
936- or
937- exists ( TypeParameter tp |
938- complexSelfRoot ( _, tp ) and
939- path = TypePath:: singleton ( tp ) and
940- exists ( type )
941- )
954+ (
955+ path .isEmpty ( ) and
956+ not validSelfType ( type )
957+ or
958+ exists ( TypeParameter tp |
959+ complexSelfRoot ( _, tp ) and
960+ path = TypePath:: singleton ( tp ) and
961+ exists ( type )
962+ )
963+ ) and
964+ type != TNeverType ( )
942965}
943966
944967/**
@@ -1540,7 +1563,8 @@ private module MethodResolution {
15401563 MethodCall getMethodCall ( ) { result = mc_ }
15411564
15421565 Type getTypeAt ( TypePath path ) {
1543- result = mc_ .getACandidateReceiverTypeAtSubstituteLookupTraits ( derefChain , borrow , path )
1566+ result = mc_ .getACandidateReceiverTypeAtSubstituteLookupTraits ( derefChain , borrow , path ) and
1567+ not result = TNeverType ( )
15441568 }
15451569
15461570 pragma [ nomagic]
@@ -2810,7 +2834,8 @@ private predicate isReturnExprCfgAncestor(AstNode n) {
28102834pragma [ nomagic]
28112835predicate isUnitBlockExpr ( BlockExpr be ) {
28122836 not be .getStmtList ( ) .hasTailExpr ( ) and
2813- not isReturnExprCfgAncestor ( be )
2837+ not isReturnExprCfgAncestor ( be ) and
2838+ not be .hasLabel ( )
28142839}
28152840
28162841pragma [ nomagic]
@@ -2831,6 +2856,15 @@ private Type inferBlockExprType(BlockExpr be, TypePath path) {
28312856 )
28322857}
28332858
2859+ pragma [ nomagic]
2860+ private predicate exprHasUnitType ( Expr e ) {
2861+ e = any ( IfExpr ie | not ie .hasElse ( ) )
2862+ or
2863+ e instanceof WhileExpr
2864+ or
2865+ e instanceof ForExpr
2866+ }
2867+
28342868final private class AwaitTarget extends Expr {
28352869 AwaitTarget ( ) { this = any ( AwaitExpr ae ) .getExpr ( ) }
28362870
0 commit comments