Ensure inherited reference is never set to &mut behind an &

This commit is contained in:
Jules Bertholet 2024-04-06 17:07:09 -04:00
parent b6c409723b
commit e3945bd3a8
No known key found for this signature in database
GPG key ID: 32034DAFC38C1BFC
6 changed files with 124 additions and 67 deletions

View file

@ -36,6 +36,7 @@ use rustc_macros::HashStable_Generic;
use rustc_span::source_map::{respan, Spanned};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
use std::cmp;
use std::fmt;
use std::mem;
use thin_vec::{thin_vec, ThinVec};
@ -731,6 +732,13 @@ impl BindingAnnotation {
Self::MUT_REF_MUT => "mut ref mut ",
}
}
pub fn cap_ref_mutability(mut self, mutbl: Mutability) -> Self {
if let ByRef::Yes(old_mutbl) = self.0 {
self.0 = ByRef::Yes(cmp::min(old_mutbl, mutbl));
}
self
}
}
#[derive(Clone, Encodable, Decodable, Debug)]