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

22 files changed

+413
-117
lines changed

src/liballoc/string.rs

+7-1
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

+31-5
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

+6-3
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

+1-1
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

+2-2
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

+4-1
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

+6-4
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

+1-1
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

+2-4
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

+2-2
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.

src/librustc_typeck/check/mod.rs

-19
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ use std::slice;
154154

155155
use crate::require_c_abi_if_c_variadic;
156156
use crate::util::common::indenter;
157-
use crate::TypeAndSubsts;
158157

159158
use self::autoderef::Autoderef;
160159
use self::callee::DeferredCallResolution;
@@ -4251,24 +4250,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
42514250
}
42524251
}
42534252

4254-
// Determine the `Self` type, using fresh variables for all variables
4255-
// declared on the impl declaration e.g., `impl<A,B> for Vec<(A,B)>`
4256-
// would return `($0, $1)` where `$0` and `$1` are freshly instantiated type
4257-
// variables.
4258-
pub fn impl_self_ty(
4259-
&self,
4260-
span: Span, // (potential) receiver for this impl
4261-
did: DefId,
4262-
) -> TypeAndSubsts<'tcx> {
4263-
let ity = self.tcx.type_of(did);
4264-
debug!("impl_self_ty: ity={:?}", ity);
4265-
4266-
let substs = self.fresh_substs_for_item(span, did);
4267-
let substd_ty = self.instantiate_type_scheme(span, &substs, &ity);
4268-
4269-
TypeAndSubsts { substs, ty: substd_ty }
4270-
}
4271-
42724253
/// Unifies the output type with the expected type early, for more coercions
42734254
/// and forward type information on the input expressions.
42744255
fn expected_inputs_for_expected_output(

src/librustc_typeck/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ use rustc_infer::infer::{InferOk, TyCtxtInferExt};
9797
use rustc_infer::traits::TraitEngineExt as _;
9898
use rustc_middle::middle;
9999
use rustc_middle::ty::query::Providers;
100-
use rustc_middle::ty::subst::SubstsRef;
101100
use rustc_middle::ty::{self, Ty, TyCtxt};
102101
use rustc_middle::util;
103102
use rustc_session::config::EntryFnType;
@@ -111,10 +110,6 @@ use rustc_trait_selection::traits::{
111110
use std::iter;
112111

113112
use astconv::{AstConv, Bounds};
114-
pub struct TypeAndSubsts<'tcx> {
115-
substs: SubstsRef<'tcx>,
116-
ty: Ty<'tcx>,
117-
}
118113

119114
fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi, span: Span) {
120115
if decl.c_variadic && !(abi == Abi::C || abi == Abi::Cdecl) {

src/librustdoc/html/static/rustdoc.css

+19
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,25 @@ nav.sub {
184184
overflow: auto;
185185
}
186186

187+
/* Improve the scrollbar display on firefox */
188+
* {
189+
scrollbar-width: initial;
190+
}
191+
.sidebar {
192+
scrollbar-width: thin;
193+
}
194+
195+
/* Improve the scrollbar display on webkit-based browsers */
196+
::-webkit-scrollbar {
197+
width: 12px;
198+
}
199+
.sidebar::-webkit-scrollbar {
200+
width: 8px;
201+
}
202+
::-webkit-scrollbar-track {
203+
-webkit-box-shadow: inset 0;
204+
}
205+
187206
.sidebar .block > ul > li {
188207
margin-right: -10px;
189208
}

src/librustdoc/html/static/themes/dark.css

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ pre {
3232
background-color: #505050;
3333
}
3434

35+
/* Improve the scrollbar display on firefox */
36+
* {
37+
scrollbar-color: rgb(64, 65, 67) #717171;
38+
}
39+
.sidebar {
40+
scrollbar-color: rgba(32,34,37,.6) transparent;
41+
}
42+
43+
/* Improve the scrollbar display on webkit-based browsers */
44+
::-webkit-scrollbar-track {
45+
background-color: #717171;
46+
}
47+
::-webkit-scrollbar-thumb {
48+
background-color: rgba(32, 34, 37, .6);
49+
}
50+
.sidebar::-webkit-scrollbar-track {
51+
background-color: #717171;
52+
}
53+
.sidebar::-webkit-scrollbar-thumb {
54+
background-color: rgba(32, 34, 37, .6);
55+
}
56+
3557
.sidebar .current {
3658
background-color: #333;
3759
}

src/librustdoc/html/static/themes/light.css

+23
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ pre {
3434
background-color: #F1F1F1;
3535
}
3636

37+
/* Improve the scrollbar display on firefox */
38+
* {
39+
scrollbar-color: rgba(36, 37, 39, 0.6) #e6e6e6;
40+
}
41+
42+
.sidebar {
43+
scrollbar-color: rgba(36, 37, 39, 0.6) #d9d9d9;
44+
}
45+
46+
/* Improve the scrollbar display on webkit-based browsers */
47+
::-webkit-scrollbar-track {
48+
background-color: #ecebeb;
49+
}
50+
::-webkit-scrollbar-thumb {
51+
background-color: rgba(36, 37, 39, 0.6);
52+
}
53+
.sidebar::-webkit-scrollbar-track {
54+
background-color: #dcdcdc;
55+
}
56+
.sidebar::-webkit-scrollbar-thumb {
57+
background-color: rgba(36, 37, 39, 0.6);
58+
}
59+
3760
.sidebar .current {
3861
background-color: #fff;
3962
}

0 commit comments

Comments
 (0)