Skip to content

Commit 8e18e26

Browse files
committed
Auto merge of #71105 - Dylan-DPC:rollup-nezezxr, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #70656 (Improve scrollbar display in rustdoc) - #71051 (Suggest .into() over try_into() when it would work) - #71087 (Remove `FnCtxt::impl_self_ty`) - #71097 (Pattern docs) - #71101 (Miri: let machine hook dynamically decide about alignment checks) Failed merges: r? @ghost
2 parents c58c532 + 73e56de commit 8e18e26

File tree

22 files changed

+413
-117
lines changed

22 files changed

+413
-117
lines changed

src/liballoc/string.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,13 @@ impl<'a> Extend<Cow<'a, str>> for String {
18271827
}
18281828
}
18291829

1830-
/// A convenience impl that delegates to the impl for `&str`
1830+
/// A convenience impl that delegates to the impl for `&str`.
1831+
///
1832+
/// # Examples
1833+
///
1834+
/// ```
1835+
/// assert_eq!(String::from("Hello world").find("world"), Some(6));
1836+
/// ```
18311837
#[unstable(
18321838
feature = "pattern",
18331839
reason = "API not fully fleshed out and ready to be stabilized",

src/libcore/str/pattern.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,13 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
451451

452452
impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {}
453453

454-
/// Searches for chars that are equal to a given char
454+
/// Searches for chars that are equal to a given `char`.
455+
///
456+
/// # Examples
457+
///
458+
/// ```
459+
/// assert_eq!("Hello world".find('o'), Some(4));
460+
/// ```
455461
impl<'a> Pattern<'a> for char {
456462
type Searcher = CharSearcher<'a>;
457463

@@ -696,7 +702,14 @@ unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> {
696702

697703
impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {}
698704

699-
/// Searches for chars that are equal to any of the chars in the array
705+
/// Searches for chars that are equal to any of the chars in the array.
706+
///
707+
/// # Examples
708+
///
709+
/// ```
710+
/// assert_eq!("Hello world".find(&['l', 'l'] as &[_]), Some(2));
711+
/// assert_eq!("Hello world".find(&['l', 'l'][..]), Some(2));
712+
/// ```
700713
impl<'a, 'b> Pattern<'a> for &'b [char] {
701714
pattern_methods!(CharSliceSearcher<'a, 'b>, MultiCharEqPattern, CharSliceSearcher);
702715
}
@@ -738,7 +751,14 @@ where
738751

739752
impl<'a, F> DoubleEndedSearcher<'a> for CharPredicateSearcher<'a, F> where F: FnMut(char) -> bool {}
740753

741-
/// Searches for chars that match the given predicate
754+
/// Searches for chars that match the given predicate.
755+
///
756+
/// # Examples
757+
///
758+
/// ```
759+
/// assert_eq!("Hello world".find(char::is_uppercase), Some(0));
760+
/// assert_eq!("Hello world".find(|c| "aeiou".contains(c)), Some(1));
761+
/// ```
742762
impl<'a, F> Pattern<'a> for F
743763
where
744764
F: FnMut(char) -> bool,
@@ -763,6 +783,12 @@ impl<'a, 'b, 'c> Pattern<'a> for &'c &'b str {
763783
///
764784
/// Will handle the pattern `""` as returning empty matches at each character
765785
/// boundary.
786+
///
787+
/// # Examples
788+
///
789+
/// ```
790+
/// assert_eq!("Hello world".find("world"), Some(6));
791+
/// ```
766792
impl<'a, 'b> Pattern<'a> for &'b str {
767793
type Searcher = StrSearcher<'a, 'b>;
768794

@@ -771,7 +797,7 @@ impl<'a, 'b> Pattern<'a> for &'b str {
771797
StrSearcher::new(haystack, self)
772798
}
773799

774-
/// Checks whether the pattern matches at the front of the haystack
800+
/// Checks whether the pattern matches at the front of the haystack.
775801
#[inline]
776802
fn is_prefix_of(self, haystack: &'a str) -> bool {
777803
haystack.as_bytes().starts_with(self.as_bytes())
@@ -788,7 +814,7 @@ impl<'a, 'b> Pattern<'a> for &'b str {
788814
}
789815
}
790816

791-
/// Checks whether the pattern matches at the back of the haystack
817+
/// Checks whether the pattern matches at the back of the haystack.
792818
#[inline]
793819
fn is_suffix_of(self, haystack: &'a str) -> bool {
794820
haystack.as_bytes().ends_with(self.as_bytes())

src/librustc_mir/const_eval/machine.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,12 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter {
179179

180180
const GLOBAL_KIND: Option<!> = None; // no copying of globals from `tcx` to machine memory
181181

182-
// We do not check for alignment to avoid having to carry an `Align`
183-
// in `ConstValue::ByRef`.
184-
const CHECK_ALIGN: bool = false;
182+
#[inline(always)]
183+
fn enforce_alignment(_memory_extra: &Self::MemoryExtra) -> bool {
184+
// We do not check for alignment to avoid having to carry an `Align`
185+
// in `ConstValue::ByRef`.
186+
false
187+
}
185188

186189
#[inline(always)]
187190
fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {

src/librustc_mir/interpret/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
118118
const GLOBAL_KIND: Option<Self::MemoryKind>;
119119

120120
/// Whether memory accesses should be alignment-checked.
121-
const CHECK_ALIGN: bool;
121+
fn enforce_alignment(memory_extra: &Self::MemoryExtra) -> bool;
122122

123123
/// Whether to enforce the validity invariant
124124
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;

src/librustc_mir/interpret/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
323323
size: Size,
324324
align: Align,
325325
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
326-
let align = M::CHECK_ALIGN.then_some(align);
326+
let align = M::enforce_alignment(&self.extra).then_some(align);
327327
self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest)
328328
}
329329

330330
/// Like `check_ptr_access`, but *definitely* checks alignment when `align`
331-
/// is `Some` (overriding `M::CHECK_ALIGN`). Also lets the caller control
331+
/// is `Some` (overriding `M::enforce_alignment`). Also lets the caller control
332332
/// the error message for the out-of-bounds case.
333333
pub fn check_ptr_access_align(
334334
&self,

src/librustc_mir/transform/const_prop.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
173173

174174
const GLOBAL_KIND: Option<!> = None; // no copying of globals from `tcx` to machine memory
175175

176-
const CHECK_ALIGN: bool = false;
176+
#[inline(always)]
177+
fn enforce_alignment(_memory_extra: &Self::MemoryExtra) -> bool {
178+
false
179+
}
177180

178181
#[inline(always)]
179182
fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {

src/librustc_typeck/check/demand.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,17 +753,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
753753

754754
match (&expected_ty.kind, &checked_ty.kind) {
755755
(&ty::Int(ref exp), &ty::Int(ref found)) => {
756-
let is_fallible = match (found.bit_width(), exp.bit_width()) {
757-
(Some(found), Some(exp)) if found > exp => true,
756+
let is_fallible = match (exp.bit_width(), found.bit_width()) {
757+
(Some(exp), Some(found)) if exp < found => true,
758+
(None, Some(8 | 16)) => false,
758759
(None, _) | (_, None) => true,
759760
_ => false,
760761
};
761762
suggest_to_change_suffix_or_into(err, is_fallible);
762763
true
763764
}
764765
(&ty::Uint(ref exp), &ty::Uint(ref found)) => {
765-
let is_fallible = match (found.bit_width(), exp.bit_width()) {
766-
(Some(found), Some(exp)) if found > exp => true,
766+
let is_fallible = match (exp.bit_width(), found.bit_width()) {
767+
(Some(exp), Some(found)) if exp < found => true,
768+
(None, Some(8 | 16)) => false,
767769
(None, _) | (_, None) => true,
768770
_ => false,
769771
};

src/librustc_typeck/check/method/confirm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
209209
"impl {:?} is not an inherent impl",
210210
impl_def_id
211211
);
212-
self.impl_self_ty(self.span, impl_def_id).substs
212+
self.fresh_substs_for_item(self.span, impl_def_id)
213213
}
214214

215215
probe::ObjectPick => {

src/librustc_typeck/check/method/probe.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,8 +1128,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11281128
) -> Option<PickResult<'tcx>> {
11291129
let tcx = self.tcx;
11301130

1131-
// In general, during probing we erase regions. See
1132-
// `impl_self_ty()` for an explanation.
1131+
// In general, during probing we erase regions.
11331132
let region = tcx.lifetimes.re_erased;
11341133

11351134
let autoref_ty = tcx.mk_ref(region, ty::TypeAndMut { ty: self_ty, mutbl });
@@ -1614,8 +1613,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16141613
} else {
16151614
match param.kind {
16161615
GenericParamDefKind::Lifetime => {
1617-
// In general, during probe we erase regions. See
1618-
// `impl_self_ty()` for an explanation.
1616+
// In general, during probe we erase regions.
16191617
self.tcx.lifetimes.re_erased.into()
16201618
}
16211619
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => {

src/librustc_typeck/check/method/suggest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
117117
.span_if_local(item.def_id)
118118
.or_else(|| self.tcx.hir().span_if_local(impl_did));
119119

120-
let impl_ty = self.impl_self_ty(span, impl_did).ty;
120+
let impl_ty = self.tcx.at(span).type_of(impl_did);
121121

122122
let insertion = match self.tcx.impl_trait_ref(impl_did) {
123123
None => String::new(),
@@ -537,7 +537,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
537537
// When the "method" is resolved through dereferencing, we really want the
538538
// original type that has the associated function for accurate suggestions.
539539
// (#61411)
540-
let ty = self.impl_self_ty(span, *impl_did).ty;
540+
let ty = tcx.at(span).type_of(*impl_did);
541541
match (&ty.peel_refs().kind, &actual.peel_refs().kind) {
542542
(ty::Adt(def, _), ty::Adt(def_actual, _)) if def == def_actual => {
543543
// Use `actual` as it will have more `substs` filled in.

0 commit comments

Comments
 (0)