Skip to content

Commit

Permalink
Auto merge of #71105 - Dylan-DPC:rollup-nezezxr, r=Dylan-DPC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Apr 13, 2020
2 parents c58c532 + 73e56de commit 8e18e26
Show file tree
Hide file tree
Showing 22 changed files with 413 additions and 117 deletions.
8 changes: 7 additions & 1 deletion src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,13 @@ impl<'a> Extend<Cow<'a, str>> for String {
}
}

/// A convenience impl that delegates to the impl for `&str`
/// A convenience impl that delegates to the impl for `&str`.
///
/// # Examples
///
/// ```
/// assert_eq!(String::from("Hello world").find("world"), Some(6));
/// ```
#[unstable(
feature = "pattern",
reason = "API not fully fleshed out and ready to be stabilized",
Expand Down
36 changes: 31 additions & 5 deletions src/libcore/str/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,13 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {

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

/// Searches for chars that are equal to a given char
/// Searches for chars that are equal to a given `char`.
///
/// # Examples
///
/// ```
/// assert_eq!("Hello world".find('o'), Some(4));
/// ```
impl<'a> Pattern<'a> for char {
type Searcher = CharSearcher<'a>;

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

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

/// Searches for chars that are equal to any of the chars in the array
/// Searches for chars that are equal to any of the chars in the array.
///
/// # Examples
///
/// ```
/// assert_eq!("Hello world".find(&['l', 'l'] as &[_]), Some(2));
/// assert_eq!("Hello world".find(&['l', 'l'][..]), Some(2));
/// ```
impl<'a, 'b> Pattern<'a> for &'b [char] {
pattern_methods!(CharSliceSearcher<'a, 'b>, MultiCharEqPattern, CharSliceSearcher);
}
Expand Down Expand Up @@ -738,7 +751,14 @@ where

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

/// Searches for chars that match the given predicate
/// Searches for chars that match the given predicate.
///
/// # Examples
///
/// ```
/// assert_eq!("Hello world".find(char::is_uppercase), Some(0));
/// assert_eq!("Hello world".find(|c| "aeiou".contains(c)), Some(1));
/// ```
impl<'a, F> Pattern<'a> for F
where
F: FnMut(char) -> bool,
Expand All @@ -763,6 +783,12 @@ impl<'a, 'b, 'c> Pattern<'a> for &'c &'b str {
///
/// Will handle the pattern `""` as returning empty matches at each character
/// boundary.
///
/// # Examples
///
/// ```
/// assert_eq!("Hello world".find("world"), Some(6));
/// ```
impl<'a, 'b> Pattern<'a> for &'b str {
type Searcher = StrSearcher<'a, 'b>;

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

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

/// Checks whether the pattern matches at the back of the haystack
/// Checks whether the pattern matches at the back of the haystack.
#[inline]
fn is_suffix_of(self, haystack: &'a str) -> bool {
haystack.as_bytes().ends_with(self.as_bytes())
Expand Down
9 changes: 6 additions & 3 deletions src/librustc_mir/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,12 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter {

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

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

#[inline(always)]
fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
const GLOBAL_KIND: Option<Self::MemoryKind>;

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

/// Whether to enforce the validity invariant
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
size: Size,
align: Align,
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
let align = M::CHECK_ALIGN.then_some(align);
let align = M::enforce_alignment(&self.extra).then_some(align);
self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest)
}

/// Like `check_ptr_access`, but *definitely* checks alignment when `align`
/// is `Some` (overriding `M::CHECK_ALIGN`). Also lets the caller control
/// is `Some` (overriding `M::enforce_alignment`). Also lets the caller control
/// the error message for the out-of-bounds case.
pub fn check_ptr_access_align(
&self,
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {

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

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

#[inline(always)]
fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
Expand Down
10 changes: 6 additions & 4 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,17 +753,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

match (&expected_ty.kind, &checked_ty.kind) {
(&ty::Int(ref exp), &ty::Int(ref found)) => {
let is_fallible = match (found.bit_width(), exp.bit_width()) {
(Some(found), Some(exp)) if found > exp => true,
let is_fallible = match (exp.bit_width(), found.bit_width()) {
(Some(exp), Some(found)) if exp < found => true,
(None, Some(8 | 16)) => false,
(None, _) | (_, None) => true,
_ => false,
};
suggest_to_change_suffix_or_into(err, is_fallible);
true
}
(&ty::Uint(ref exp), &ty::Uint(ref found)) => {
let is_fallible = match (found.bit_width(), exp.bit_width()) {
(Some(found), Some(exp)) if found > exp => true,
let is_fallible = match (exp.bit_width(), found.bit_width()) {
(Some(exp), Some(found)) if exp < found => true,
(None, Some(8 | 16)) => false,
(None, _) | (_, None) => true,
_ => false,
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
"impl {:?} is not an inherent impl",
impl_def_id
);
self.impl_self_ty(self.span, impl_def_id).substs
self.fresh_substs_for_item(self.span, impl_def_id)
}

probe::ObjectPick => {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
) -> Option<PickResult<'tcx>> {
let tcx = self.tcx;

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

let autoref_ty = tcx.mk_ref(region, ty::TypeAndMut { ty: self_ty, mutbl });
Expand Down Expand Up @@ -1614,8 +1613,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
} else {
match param.kind {
GenericParamDefKind::Lifetime => {
// In general, during probe we erase regions. See
// `impl_self_ty()` for an explanation.
// In general, during probe we erase regions.
self.tcx.lifetimes.re_erased.into()
}
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.span_if_local(item.def_id)
.or_else(|| self.tcx.hir().span_if_local(impl_did));

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

let insertion = match self.tcx.impl_trait_ref(impl_did) {
None => String::new(),
Expand Down Expand Up @@ -537,7 +537,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// When the "method" is resolved through dereferencing, we really want the
// original type that has the associated function for accurate suggestions.
// (#61411)
let ty = self.impl_self_ty(span, *impl_did).ty;
let ty = tcx.at(span).type_of(*impl_did);
match (&ty.peel_refs().kind, &actual.peel_refs().kind) {
(ty::Adt(def, _), ty::Adt(def_actual, _)) if def == def_actual => {
// Use `actual` as it will have more `substs` filled in.
Expand Down
19 changes: 0 additions & 19 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ use std::slice;

use crate::require_c_abi_if_c_variadic;
use crate::util::common::indenter;
use crate::TypeAndSubsts;

use self::autoderef::Autoderef;
use self::callee::DeferredCallResolution;
Expand Down Expand Up @@ -4251,24 +4250,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

// Determine the `Self` type, using fresh variables for all variables
// declared on the impl declaration e.g., `impl<A,B> for Vec<(A,B)>`
// would return `($0, $1)` where `$0` and `$1` are freshly instantiated type
// variables.
pub fn impl_self_ty(
&self,
span: Span, // (potential) receiver for this impl
did: DefId,
) -> TypeAndSubsts<'tcx> {
let ity = self.tcx.type_of(did);
debug!("impl_self_ty: ity={:?}", ity);

let substs = self.fresh_substs_for_item(span, did);
let substd_ty = self.instantiate_type_scheme(span, &substs, &ity);

TypeAndSubsts { substs, ty: substd_ty }
}

/// Unifies the output type with the expected type early, for more coercions
/// and forward type information on the input expressions.
fn expected_inputs_for_expected_output(
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ use rustc_infer::infer::{InferOk, TyCtxtInferExt};
use rustc_infer::traits::TraitEngineExt as _;
use rustc_middle::middle;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::util;
use rustc_session::config::EntryFnType;
Expand All @@ -111,10 +110,6 @@ use rustc_trait_selection::traits::{
use std::iter;

use astconv::{AstConv, Bounds};
pub struct TypeAndSubsts<'tcx> {
substs: SubstsRef<'tcx>,
ty: Ty<'tcx>,
}

fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi, span: Span) {
if decl.c_variadic && !(abi == Abi::C || abi == Abi::Cdecl) {
Expand Down
19 changes: 19 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,25 @@ nav.sub {
overflow: auto;
}

/* Improve the scrollbar display on firefox */
* {
scrollbar-width: initial;
}
.sidebar {
scrollbar-width: thin;
}

/* Improve the scrollbar display on webkit-based browsers */
::-webkit-scrollbar {
width: 12px;
}
.sidebar::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0;
}

.sidebar .block > ul > li {
margin-right: -10px;
}
Expand Down
22 changes: 22 additions & 0 deletions src/librustdoc/html/static/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ pre {
background-color: #505050;
}

/* Improve the scrollbar display on firefox */
* {
scrollbar-color: rgb(64, 65, 67) #717171;
}
.sidebar {
scrollbar-color: rgba(32,34,37,.6) transparent;
}

/* Improve the scrollbar display on webkit-based browsers */
::-webkit-scrollbar-track {
background-color: #717171;
}
::-webkit-scrollbar-thumb {
background-color: rgba(32, 34, 37, .6);
}
.sidebar::-webkit-scrollbar-track {
background-color: #717171;
}
.sidebar::-webkit-scrollbar-thumb {
background-color: rgba(32, 34, 37, .6);
}

.sidebar .current {
background-color: #333;
}
Expand Down
23 changes: 23 additions & 0 deletions src/librustdoc/html/static/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ pre {
background-color: #F1F1F1;
}

/* Improve the scrollbar display on firefox */
* {
scrollbar-color: rgba(36, 37, 39, 0.6) #e6e6e6;
}

.sidebar {
scrollbar-color: rgba(36, 37, 39, 0.6) #d9d9d9;
}

/* Improve the scrollbar display on webkit-based browsers */
::-webkit-scrollbar-track {
background-color: #ecebeb;
}
::-webkit-scrollbar-thumb {
background-color: rgba(36, 37, 39, 0.6);
}
.sidebar::-webkit-scrollbar-track {
background-color: #dcdcdc;
}
.sidebar::-webkit-scrollbar-thumb {
background-color: rgba(36, 37, 39, 0.6);
}

.sidebar .current {
background-color: #fff;
}
Expand Down
Loading

0 comments on commit 8e18e26

Please sign in to comment.