(a) RASHI (DH Mi she'Hechshich) says that he must give the wallet to the
gentile *while it is still day*, before it becomes Shabbos.
(b) The ROSH says that one may give his wallet to a gentile after Shabbos
has already entered. This is evident from the Gemara which asks why it is
permitted to give one's wallet to a gentile. According to Rashi's
explanation, there is no reason why it should not be permitted, since he is
giving it to the gentile before Shabbos!
The Rosh proposes another two proofs from the Gemara that Rashi's
explanation cannot be correct. (1) First, the Gemara says that this
Halachah applies only to one's wallet (or any other object that he owns),
but not to an object which he *finds*, since he has not yet acquired
ownership of the object. If the Mishnah is referring to a point before
Shabbos has entered, then the person should simply acquire the object
before Shabbos by lifting it, and the Gemara's discussion of an object
which he found is not relevant. (2) Second, when the Gemara says that if
there is no gentile one may place his wallet on his donkey, the Gemara
counters that by doing so he is doing the Melachah of Mechamer. The Mishnah
must be referring to *after* Shabbos has already entered, because otherwise
one is not doing the Melachah of Mechamer, since it was not yet Shabbos
when he placed his wallet on the donkey.
The BACH and the KORBAN NESANEL explain that Rashi was merely explaining
what one must do *l'Chatchilah* -- he must give his wallet to a gentile
before Shabbos enters. But b'Di'eved, if he did not give his wallet to a
gentile until after it became dark, he may still give his wallet to a
gentile to watch and he does not have to abandon it there.
The Bach explains that the reason Rashi understood that the Mishnah is
teaching what one should do l'Chat'chilah is because the Mishnah says, "If
it became dark while one was traveling, *he should give* his wallet to a
gentile." This implies that the Mishnah is instructing what one *should* do
to avoid any problem (such as carrying on Shabbos, or holding Muktzah). If
the Mishnah was discussing what to do when Shabbos has already entered, it
should have said, "If it became dark while one was traveling, *it is
permitted for him* to give his wallet to a gentile," teaching a Halachah of
what one *may* or may not do on Shabbos.
The Shulchan Aruch (266:8) adds that if one intentionally embarked on a
trip close to Shabbos, and he should have known that it might well become
Shabbos while he is traveling, he may *not* give his wallet to a gentile,
but he must abandon it on the road.