The relevant rule:
Elision of alveolar plosives /t/ /d/
In rapid, casual speech the
alveolar plosives are commonly elided when preceded by the following
In the case of /t/ preceded by /s, f, ʃ, n, l, p, k, tʃ/ ...
In the case of /d/ preceded by /z, ð, n, l, b, g, dʒ/
Working with Words: An Introduction to English Linguistics, edited by Miguel Fuster Márquez.
In other words, when the clusters /st, ft, ʃt, nt, lt, pt, kt, tʃt/ are followed by any other consonant sound, they are often simplified by dropping the /t/. This is a feature of “rapid” and “casual” speech; it is by no means a requirement, and considering that it will be very confusing if somebody mishears your "can't" as a "can", I would not advise aiming for this pronunciation in this case.
However, it’s true that this elision can also apply to this pair of words. When speakers do drop the /t/, “can’t” and “can” can generally still be distinguished due to one main factor: the rhythm/stress pattern of the phrase. A neutral pronunciation of “I can complain” puts the main stress of the sentence on the last syllable of complain. A neutral pronunciation of “I can’t complain” puts the main stress of the sentence on “can’t”, with a secondary stress on the last syllable of "complain". This is only the neutral pronunciation; emphatic pronunciation of the first will put the stress on "can".
As an effect of the previous factor, “can” when unstressed has the vowel schwa /kən/ or a syllabic nasal /kn̩/ while “can’t” has a full vowel: phonemically /kænt/, but in many varieties of American speech the vowel is raised as a result of nasalization, so is realized as [kẽənt]. A stressed “can” will also be realized with a nasalized and raised vowel, as [kẽən], so there is no way to use the vowel to distinguish between a stressed “can” and a “can’t” that has the consonant dropped.
The only other way to tell the difference is by context. Since "I can't complain" is a fairly common phrase, while "I can complain" is much rarer, it's usually possible to guess which one is meant even if there is no audible difference. However, in any context where confusion is possible, there is the possibility of real ambiguity. For this reason, an emphatic "can't" will probably have the "t" pronounced in some manner (not necessarily as IPA [t]; it could also be a glottal stop [ʔ]), and in contexts where clarity is important, a normal "can't" may be pronounced with the /t/ to distinguish it from an emphatic "can" [kẽən].