Skip to content

Commit 80a9646

Browse files
committedNov 26, 2022
Auto merge of #104945 - GuillaumeGomez:rollup-ygzbpbe, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #104786 (Use the power of adding helper function to simplify code w/ `Mutability`) - #104788 (Do not record unresolved const vars in generator interior) - #104909 (Rename `normalize_opaque_types` to `reveal_opaque_types_in_bounds`) - #104921 (Remove unnecessary binder from `get_impl_future_output_ty`) - #104924 (jsondoclint: Accept trait alias is places where trait expected.) - #104928 (rustdoc: use flexbox CSS to align sidebar button instead of position) - #104943 (jsondoclint: Handle using enum variants and glob using enums.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c3a1c02 + 95e6356 commit 80a9646

File tree

45 files changed

+445
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+445
-318
lines changed
 

‎compiler/rustc_ast/src/ast.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,9 @@ pub enum PatKind {
775775
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
776776
#[derive(HashStable_Generic, Encodable, Decodable)]
777777
pub enum Mutability {
778-
Mut,
778+
// N.B. Order is deliberate, so that Not < Mut
779779
Not,
780+
Mut,
780781
}
781782

782783
impl Mutability {
@@ -787,12 +788,39 @@ impl Mutability {
787788
}
788789
}
789790

790-
pub fn prefix_str(&self) -> &'static str {
791+
/// Returns `""` (empty string) or `"mut "` depending on the mutability.
792+
pub fn prefix_str(self) -> &'static str {
791793
match self {
792794
Mutability::Mut => "mut ",
793795
Mutability::Not => "",
794796
}
795797
}
798+
799+
/// Returns `"&"` or `"&mut "` depending on the mutability.
800+
pub fn ref_prefix_str(self) -> &'static str {
801+
match self {
802+
Mutability::Not => "&",
803+
Mutability::Mut => "&mut ",
804+
}
805+
}
806+
807+
/// Returns `""` (empty string) or `"mutably "` depending on the mutability.
808+
pub fn mutably_str(self) -> &'static str {
809+
match self {
810+
Mutability::Not => "",
811+
Mutability::Mut => "mutably ",
812+
}
813+
}
814+
815+
/// Return `true` if self is mutable
816+
pub fn is_mut(self) -> bool {
817+
matches!(self, Self::Mut)
818+
}
819+
820+
/// Return `true` if self is **not** mutable
821+
pub fn is_not(self) -> bool {
822+
matches!(self, Self::Not)
823+
}
796824
}
797825

798826
/// The kind of borrow in an `AddrOf` expression,

‎compiler/rustc_ast_lowering/src/lib.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1781,14 +1781,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17811781
// Given we are only considering `ImplicitSelf` types, we needn't consider
17821782
// the case where we have a mutable pattern to a reference as that would
17831783
// no longer be an `ImplicitSelf`.
1784-
TyKind::Rptr(_, mt)
1785-
if mt.ty.kind.is_implicit_self() && mt.mutbl == ast::Mutability::Mut =>
1786-
{
1787-
hir::ImplicitSelfKind::MutRef
1788-
}
1789-
TyKind::Rptr(_, mt) if mt.ty.kind.is_implicit_self() => {
1790-
hir::ImplicitSelfKind::ImmRef
1791-
}
1784+
TyKind::Rptr(_, mt) if mt.ty.kind.is_implicit_self() => match mt.mutbl {
1785+
hir::Mutability::Not => hir::ImplicitSelfKind::ImmRef,
1786+
hir::Mutability::Mut => hir::ImplicitSelfKind::MutRef,
1787+
},
17921788
_ => hir::ImplicitSelfKind::None,
17931789
}
17941790
}),

0 commit comments

Comments
 (0)