Skip to content

Commit 164f6ae

Browse files
acozzettecopybara-github
authored andcommitted
Fix mismatched_lifetime_syntaxes errors
Fixes #23057. PiperOrigin-RevId: 792657577
1 parent 75afd7f commit 164f6ae

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

.github/workflows/test_rust.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ jobs:
3030

3131
# Override cases with custom images
3232
- config: { name: Cargo }
33-
image: "us-docker.pkg.dev/protobuf-build/containers/release/linux/rust:8.0.1-1.79.0-d271543f317955b5732ce19b2be672a195e96508"
33+
# We currently need to be on nightly to have access to the
34+
# multi-package publishing feature. This will be stabilized in
35+
# 1.90, so we should switch to that as soon as it is released.
36+
image: "us-docker.pkg.dev/protobuf-build/containers/release/linux/rust:8.0.1-nightly-2025-08-07-f0d1e209ed9369f69d93ce418990ecff3aa08d6f"
3437
bazel_cmd: "run"
3538
targets: "//rust/release_crates:cargo_test"
3639

MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ register_toolchains(
180180
dev_dependency = True,
181181
)
182182

183+
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust", dev_dependency = True)
184+
rust.toolchain(
185+
edition = "2021",
186+
versions = [ "1.79.0" ],
187+
)
188+
183189
crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate", dev_dependency = True)
184190
crate.spec(
185191
package = "googletest",

rust/map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct MapMut<'msg, K: ?Sized, V: ?Sized> {
4444
}
4545

4646
impl<'msg, K: ?Sized, V: ?Sized> MapMut<'msg, K, V> {
47-
pub fn inner(&self, _private: Private) -> InnerMapMut {
47+
pub fn inner(&self, _private: Private) -> InnerMapMut<'_> {
4848
self.inner
4949
}
5050
}
@@ -346,14 +346,14 @@ where
346346
V::map_clear(self.as_mut())
347347
}
348348

349-
pub fn get<'a>(&self, key: impl Into<View<'a, K>>) -> Option<View<V>>
349+
pub fn get<'a>(&self, key: impl Into<View<'a, K>>) -> Option<View<'_, V>>
350350
where
351351
K: 'a,
352352
{
353353
V::map_get(self.as_view(), key.into())
354354
}
355355

356-
pub fn get_mut<'a>(&mut self, key: impl Into<View<'a, K>>) -> Option<Mut<V>>
356+
pub fn get_mut<'a>(&mut self, key: impl Into<View<'a, K>>) -> Option<Mut<'_, V>>
357357
where
358358
K: 'a,
359359
V: Message,
@@ -377,7 +377,7 @@ where
377377
/// Returns an iterator visiting all key-value pairs in arbitrary order.
378378
///
379379
/// The iterator element type is `(View<K>, View<V>)`.
380-
pub fn iter(&self) -> MapIter<K, V> {
380+
pub fn iter(&self) -> MapIter<'_, K, V> {
381381
self.into_iter()
382382
}
383383

rust/release_crates/cargo_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ tar -xvf $WELL_KNOWN_TYPES_TAR -C $WELL_KNOWN_TYPES_ROOT
7777
# Put the Bazel-built protoc at the beginning of $PATH
7878
PATH=$(dirname $(rlocation com_google_protobuf/protoc)):$PATH
7979

80+
export RUSTFLAGS="-Dmismatched-lifetime-syntaxes"
81+
8082
cd $CRATE_ROOT
8183
CARGO_HOME=$CARGO_HOME cargo test
8284
CARGO_HOME=$CARGO_HOME cargo publish --dry-run

rust/repeated.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ where
159159
///
160160
/// Returns `None` if `index >= len`.
161161
#[inline]
162-
pub fn get(&self, index: usize) -> Option<View<T>> {
162+
pub fn get(&self, index: usize) -> Option<View<'_, T>> {
163163
self.as_view().get(index)
164164
}
165165

@@ -198,7 +198,7 @@ where
198198
/// # Safety
199199
/// Undefined behavior if `index >= len`.
200200
#[inline]
201-
pub unsafe fn get_unchecked(&self, index: usize) -> View<T> {
201+
pub unsafe fn get_unchecked(&self, index: usize) -> View<'_, T> {
202202
// SAFETY: in-bounds as promised
203203
unsafe { self.as_view().get_unchecked(index) }
204204
}
@@ -232,7 +232,7 @@ where
232232
}
233233

234234
/// Iterates over the values in the repeated field.
235-
pub fn iter(&self) -> RepeatedIter<T> {
235+
pub fn iter(&self) -> RepeatedIter<'_, T> {
236236
self.as_view().into_iter()
237237
}
238238

@@ -251,7 +251,7 @@ impl<T> Repeated<T>
251251
where
252252
T: ProxiedInRepeated,
253253
{
254-
pub fn as_view(&self) -> View<Repeated<T>> {
254+
pub fn as_view(&self) -> View<'_, Repeated<T>> {
255255
RepeatedView { raw: self.inner.raw(), _phantom: PhantomData }
256256
}
257257

src/google/protobuf/compiler/rust/message.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,13 +1009,13 @@ void GenerateRs(Context& ctx, const Descriptor& msg, const upb::DefPool& pool) {
10091009
$pb$::ClearAndParse::clear_and_parse_dont_enforce_required(&mut msg, data).map(|_| msg)
10101010
}
10111011
1012-
pub fn as_view(&self) -> $Msg$View {
1012+
pub fn as_view(&self) -> $Msg$View<'_> {
10131013
$Msg$View::new(
10141014
$pbi$::Private,
10151015
$pbr$::MessageViewInner::view_of_owned(&self.inner))
10161016
}
10171017
1018-
pub fn as_mut(&mut self) -> $Msg$Mut {
1018+
pub fn as_mut(&mut self) -> $Msg$Mut<'_> {
10191019
let inner = $pbr$::MessageMutInner::mut_of_owned(&mut self.inner);
10201020
$Msg$Mut::new($pbi$::Private, inner)
10211021
}
@@ -1039,14 +1039,14 @@ void GenerateRs(Context& ctx, const Descriptor& msg, const upb::DefPool& pool) {
10391039
10401040
impl $pb$::AsView for $Msg$ {
10411041
type Proxied = Self;
1042-
fn as_view(&self) -> $Msg$View {
1042+
fn as_view(&self) -> $Msg$View<'_> {
10431043
self.as_view()
10441044
}
10451045
}
10461046
10471047
impl $pb$::AsMut for $Msg$ {
10481048
type MutProxied = Self;
1049-
fn as_mut(&mut self) -> $Msg$Mut {
1049+
fn as_mut(&mut self) -> $Msg$Mut<'_> {
10501050
self.as_mut()
10511051
}
10521052
}

0 commit comments

Comments
 (0)