@@ -232,9 +232,14 @@ import M2
232232module Consistency {
233233 import M2:: Consistency
234234
235+ private Type inferCertainTypeAdj ( AstNode n , TypePath path ) {
236+ result = CertainTypeInference:: inferCertainType ( n , path ) and
237+ not result = TNeverType ( )
238+ }
239+
235240 predicate nonUniqueCertainType ( AstNode n , TypePath path , Type t ) {
236- strictcount ( CertainTypeInference :: inferCertainType ( n , path ) ) > 1 and
237- t = CertainTypeInference :: inferCertainType ( n , path ) and
241+ strictcount ( inferCertainTypeAdj ( n , path ) ) > 1 and
242+ t = inferCertainTypeAdj ( n , path ) and
238243 // Suppress the inconsistency if `n` is a self parameter and the type
239244 // mention for the self type has multiple types for a path.
240245 not exists ( ImplItemNode impl , TypePath selfTypePath |
@@ -291,6 +296,17 @@ private Type inferAnnotatedType(AstNode n, TypePath path) {
291296 result = n .( ShorthandSelfParameterMention ) .resolveTypeAt ( path )
292297}
293298
299+ /**
300+ * Holds if `me` is a call to the `panic!` macro.
301+ *
302+ * `panic!` needs special treatment, because it expands to a block expression
303+ * that looks like it should have type `()` instead of the correct `!` type.
304+ */
305+ pragma [ nomagic]
306+ private predicate isPanicMacroCall ( MacroExpr me ) {
307+ me .getMacroCall ( ) .resolveMacro ( ) .( MacroRules ) .getName ( ) .getText ( ) = "panic"
308+ }
309+
294310/** Module for inferring certain type information. */
295311module CertainTypeInference {
296312 pragma [ nomagic]
@@ -443,6 +459,14 @@ module CertainTypeInference {
443459 or
444460 result = inferCastExprType ( n , path )
445461 or
462+ exprHasUnitType ( n ) and
463+ path .isEmpty ( ) and
464+ result instanceof UnitType
465+ or
466+ isPanicMacroCall ( n ) and
467+ path .isEmpty ( ) and
468+ result instanceof NeverType
469+ or
446470 infersCertainTypeAt ( n , path , result .getATypeParameter ( ) )
447471 }
448472
@@ -579,7 +603,8 @@ private predicate typeEquality(AstNode n1, TypePath prefix1, AstNode n2, TypePat
579603 n2 = be .getRhs ( )
580604 )
581605 or
582- n1 = n2 .( MacroExpr ) .getMacroCall ( ) .getMacroCallExpansion ( )
606+ n1 = n2 .( MacroExpr ) .getMacroCall ( ) .getMacroCallExpansion ( ) and
607+ not isPanicMacroCall ( n2 )
583608 or
584609 n1 = n2 .( MacroPat ) .getMacroCall ( ) .getMacroCallExpansion ( )
585610 or
@@ -931,14 +956,17 @@ private predicate functionInfoBlanketLike(
931956 */
932957bindingset [ path, type]
933958private 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- )
959+ (
960+ path .isEmpty ( ) and
961+ not validSelfType ( type )
962+ or
963+ exists ( TypeParameter tp |
964+ complexSelfRoot ( _, tp ) and
965+ path = TypePath:: singleton ( tp ) and
966+ exists ( type )
967+ )
968+ ) and
969+ type != TNeverType ( )
942970}
943971
944972/**
@@ -1540,7 +1568,8 @@ private module MethodResolution {
15401568 MethodCall getMethodCall ( ) { result = mc_ }
15411569
15421570 Type getTypeAt ( TypePath path ) {
1543- result = mc_ .getACandidateReceiverTypeAtSubstituteLookupTraits ( derefChain , borrow , path )
1571+ result = mc_ .getACandidateReceiverTypeAtSubstituteLookupTraits ( derefChain , borrow , path ) and
1572+ not result = TNeverType ( )
15441573 }
15451574
15461575 pragma [ nomagic]
@@ -2810,7 +2839,8 @@ private predicate isReturnExprCfgAncestor(AstNode n) {
28102839pragma [ nomagic]
28112840predicate isUnitBlockExpr ( BlockExpr be ) {
28122841 not be .getStmtList ( ) .hasTailExpr ( ) and
2813- not isReturnExprCfgAncestor ( be )
2842+ not isReturnExprCfgAncestor ( be ) and
2843+ not be .hasLabel ( )
28142844}
28152845
28162846pragma [ nomagic]
@@ -2831,6 +2861,15 @@ private Type inferBlockExprType(BlockExpr be, TypePath path) {
28312861 )
28322862}
28332863
2864+ pragma [ nomagic]
2865+ private predicate exprHasUnitType ( Expr e ) {
2866+ e = any ( IfExpr ie | not ie .hasElse ( ) )
2867+ or
2868+ e instanceof WhileExpr
2869+ or
2870+ e instanceof ForExpr
2871+ }
2872+
28342873final private class AwaitTarget extends Expr {
28352874 AwaitTarget ( ) { this = any ( AwaitExpr ae ) .getExpr ( ) }
28362875
0 commit comments