Skip to content

Commit 5f9de55

Browse files
committed
comments for deduce_param_attrs
1 parent e124355 commit 5f9de55

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

compiler/rustc_middle/src/middle/deduced_param_attrs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_macros::{Decodable, Encodable, HashStable};
33
use crate::ty::{Ty, TyCtxt, TypingEnv};
44

55
/// Flags that dictate how a parameter is mutated. If the flags are empty, the param is
6-
/// read-only. If non-empty, it is read-only with conditions.
6+
/// read-only. If non-empty, it is read-only if *all* flags' conditions are met.
77
#[derive(Clone, Copy, PartialEq, Debug, Decodable, Encodable, HashStable)]
88
pub struct DeducedReadOnlyParam(u8);
99

@@ -53,6 +53,7 @@ impl DeducedParamAttrs {
5353
ty: Ty<'tcx>,
5454
) -> bool {
5555
let read_only = self.read_only;
56+
// We have to check *all* set bits; only if all checks pass is this truly read-only.
5657
if read_only.contains(DeducedReadOnlyParam::MUTATED) {
5758
return false;
5859
}

compiler/rustc_mir_transform/src/deduce_param_attrs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
//! body of the function instead of just the signature. These can be useful for optimization
55
//! purposes on a best-effort basis. We compute them here and store them into the crate metadata so
66
//! dependent crates can use them.
7+
//!
8+
//! Note that this *crucially* relies on codegen *not* doing any more MIR-level transformations
9+
//! after `optimized_mir`! We check for things that are *not* guaranteed to be preserved by MIR
10+
//! transforms, such as which local variables happen to be mutated.
711
812
use rustc_hir::def_id::LocalDefId;
913
use rustc_index::IndexVec;

0 commit comments

Comments
 (0)