Skip to content

Commit

Permalink
Auto merge of #78528 - jonas-schievink:rollup-e70g9zk, r=jonas-schievink
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

Successful merges:

 - #75078 (Improve documentation for slice strip_* functions)
 - #76138 (Explain fully qualified syntax for `Rc` and `Arc`)
 - #78244 (Dogfood {exclusive,half-open} ranges in compiler (nfc))
 - #78422 (Do not ICE on invalid input)
 - #78423 (rustc_span: improve bounds checks in byte_pos_to_line_and_col)
 - #78431 (Prefer new associated numeric consts in float error messages)
 - #78462 (Use unwrapDIPtr because the Scope may be null.)
 - #78493 (Update cargo)
 - #78499 (Prevent String::retain from creating non-utf8 strings when abusing panic)
 - #78505 (Update Clippy - temporary_cstring_as_ptr deprecation)
 - #78527 (Fix some more typos)

Failed merges:

r? `@ghost`
  • Loading branch information
bors committed Oct 29, 2020
2 parents 6bdae9e + e656e60 commit a3d7a5e
Show file tree
Hide file tree
Showing 110 changed files with 3,070 additions and 747 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct LoweringContext<'a, 'hir: 'a> {
is_collecting_in_band_lifetimes: bool,

/// Currently in-scope lifetimes defined in impl headers, fn headers, or HRTB.
/// When `is_collectin_in_band_lifetimes` is true, each lifetime is checked
/// When `is_collecting_in_band_lifetimes` is true, each lifetime is checked
/// against this list to see if it is already in-scope, or if a definition
/// needs to be created for it.
///
Expand Down Expand Up @@ -257,7 +257,7 @@ enum ImplTraitPosition {
/// Disallowed in `let` / `const` / `static` bindings.
Binding,

/// All other posiitons.
/// All other positions.
Other,
}

Expand Down Expand Up @@ -363,7 +363,7 @@ enum ParenthesizedGenericArgs {
/// elided bounds follow special rules. Note that this only covers
/// cases where *nothing* is written; the `'_` in `Box<dyn Foo +
/// '_>` is a case of "modern" elision.
/// - **Deprecated** -- this coverse cases like `Ref<T>`, where the lifetime
/// - **Deprecated** -- this covers cases like `Ref<T>`, where the lifetime
/// parameter to ref is completely elided. `Ref<'_, T>` would be the modern,
/// non-deprecated equivalent.
///
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl<'a> AstValidator<'a> {
self.session.source_map().guess_head_span(self.extern_mod.unwrap().span)
}

/// An `fn` in `extern { ... }` cannot have qualfiers, e.g. `async fn`.
/// An `fn` in `extern { ... }` cannot have qualifiers, e.g. `async fn`.
fn check_foreign_fn_headerless(&self, ident: Ident, span: Span, header: FnHeader) {
if header.has_qualifiers() {
self.err_handler()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/tagged_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod drop;
pub use copy::CopyTaggedPtr;
pub use drop::TaggedPtr;

/// This describes the pointer type encaspulated by TaggedPtr.
/// This describes the pointer type encapsulated by TaggedPtr.
///
/// # Safety
///
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/transitive_relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct TransitiveRelation<T: Eq + Hash> {
edges: Vec<Edge>,

// This is a cached transitive closure derived from the edges.
// Currently, we build it lazilly and just throw out any existing
// Currently, we build it lazily and just throw out any existing
// copy whenever a new edge is added. (The Lock is to permit
// the lazy computation.) This is kind of silly, except for the
// fact its size is tied to `self.elements.len()`, so I wanted to
Expand Down Expand Up @@ -255,7 +255,7 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
// argument is that, after step 2, we know that no element
// can reach its successors (in the vector, not the graph).
// After step 3, we know that no element can reach any of
// its predecesssors (because of step 2) nor successors
// its predecessors (because of step 2) nor successors
// (because we just called `pare_down`)
//
// This same algorithm is used in `parents` below.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ impl Emitter for SilentEmitter {
/// Maximum number of lines we will print for a multiline suggestion; arbitrary.
///
/// This should be replaced with a more involved mechanism to output multiline suggestions that
/// more closely mimmics the regular diagnostic output, where irrelevant code lines are elided.
/// more closely mimics the regular diagnostic output, where irrelevant code lines are elided.
pub const MAX_SUGGESTION_HIGHLIGHT_LINES: usize = 6;
/// Maximum number of suggestions to be shown
///
Expand Down Expand Up @@ -887,7 +887,7 @@ impl EmitterWriter {
// or the next are vertical line placeholders.
|| (annotation.takes_space() // If either this or the next annotation is
&& next.has_label()) // multiline start/end, move it to a new line
|| (annotation.has_label() // so as not to overlap the orizontal lines.
|| (annotation.has_label() // so as not to overlap the horizontal lines.
&& next.takes_space())
|| (annotation.takes_space() && next.takes_space())
|| (overlaps(next, annotation, l)
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#![feature(never_type)]
#![feature(nll)]
#![feature(or_patterns)]
#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
#![recursion_limit = "256"]

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ fn lint_literal<'tcx>(
cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
lint.build(&format!("literal out of range for `{}`", t.name_str()))
.note(&format!(
"the literal `{}` does not fit into the type `{}` and will be converted to `std::{}::INFINITY`",
"the literal `{}` does not fit into the type `{}` and will be converted to `{}::INFINITY`",
cx.sess()
.source_map()
.span_to_snippet(lit.span)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
has_emitted
}
ty::Array(ty, len) => match len.try_eval_usize(cx.tcx, cx.param_env) {
// If the array is empty we don't lint, to avoid false positives
Some(0) | None => false,
// If the array is definitely non-empty, we can do `#[must_use]` checking.
Some(n) if n != 0 => {
Some(n) => {
let descr_pre = &format!("{}array{} of ", descr_pre, plural_suffix,);
check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, n as usize + 1)
}
// Otherwise, we don't lint, to avoid false positives.
_ => false,
},
ty::Closure(..) => {
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTypedef(
LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope) {
return wrap(Builder->createTypedef(
unwrap<DIType>(Type), StringRef(Name, NameLen), unwrap<DIFile>(File),
LineNo, unwrap<DIScope>(Scope)));
LineNo, unwrapDIPtr<DIScope>(Scope)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType(
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#![feature(associated_type_bounds)]
#![feature(rustc_attrs)]
#![feature(int_error_matching)]
#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
#![recursion_limit = "512"]

#[macro_use]
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/inhabitedness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ impl<'tcx> TyS<'tcx> {
),

Array(ty, len) => match len.try_eval_usize(tcx, param_env) {
Some(0) | None => DefIdForest::empty(),
// If the array is definitely non-empty, it's uninhabited if
// the type of its elements is uninhabited.
Some(n) if n != 0 => ty.uninhabited_from(tcx, param_env),
_ => DefIdForest::empty(),
Some(1..) => ty.uninhabited_from(tcx, param_env),
},

// References to uninitialised memory is valid for any type, including
// References to uninitialised memory are valid for any type, including
// uninhabited types, in unsafe code, so we treat all references as
// inhabited.
// The precise semantics of inhabitedness with respect to references is currently
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1834,10 +1834,10 @@ impl<'tcx> TyS<'tcx> {
}
ty::Array(ty, len) => {
match len.try_eval_usize(tcx, ParamEnv::empty()) {
Some(0) | None => false,
// If the array is definitely non-empty, it's uninhabited if
// the type of its elements is uninhabited.
Some(n) if n != 0 => ty.conservative_is_privately_uninhabited(tcx),
_ => false,
Some(1..) => ty.conservative_is_privately_uninhabited(tcx),
}
}
ty::Ref(..) => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
const SECONDARY_LIB_DIR: &str = "lib";

match option_env!("CFG_LIBDIR_RELATIVE") {
Some(libdir) if libdir != "lib" => libdir.into(),
_ => {
None | Some("lib") => {
if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
PRIMARY_LIB_DIR.into()
} else {
SECONDARY_LIB_DIR.into()
}
}
Some(libdir) => libdir.into(),
}
}

Expand Down
42 changes: 31 additions & 11 deletions compiler/rustc_span/src/caching_source_map_view.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
use crate::source_map::SourceMap;
use crate::{BytePos, SourceFile};
use rustc_data_structures::sync::Lrc;
use std::ops::Range;

#[derive(Clone)]
struct CacheEntry {
time_stamp: usize,
line_number: usize,
line_start: BytePos,
line_end: BytePos,
// The line's byte position range in the `SourceMap`. This range will fail to contain a valid
// position in certain edge cases. Spans often start/end one past something, and when that
// something is the last character of a file (this can happen when a file doesn't end in a
// newline, for example), we'd still like for the position to be considered within the last
// line. However, it isn't according to the exclusive upper bound of this range. We cannot
// change the upper bound to be inclusive, because for most lines, the upper bound is the same
// as the lower bound of the next line, so there would be an ambiguity.
//
// Since the containment aspect of this range is only used to see whether or not the cache
// entry contains a position, the only ramification of the above is that we will get cache
// misses for these rare positions. A line lookup for the position via `SourceMap::lookup_line`
// after a cache miss will produce the last line number, as desired.
line: Range<BytePos>,
file: Lrc<SourceFile>,
file_index: usize,
}
Expand All @@ -26,8 +38,7 @@ impl<'sm> CachingSourceMapView<'sm> {
let entry = CacheEntry {
time_stamp: 0,
line_number: 0,
line_start: BytePos(0),
line_end: BytePos(0),
line: BytePos(0)..BytePos(0),
file: first_file,
file_index: 0,
};
Expand All @@ -47,13 +58,13 @@ impl<'sm> CachingSourceMapView<'sm> {

// Check if the position is in one of the cached lines
for cache_entry in self.line_cache.iter_mut() {
if pos >= cache_entry.line_start && pos < cache_entry.line_end {
if cache_entry.line.contains(&pos) {
cache_entry.time_stamp = self.time_stamp;

return Some((
cache_entry.file.clone(),
cache_entry.line_number,
pos - cache_entry.line_start,
pos - cache_entry.line.start,
));
}
}
Expand All @@ -69,13 +80,13 @@ impl<'sm> CachingSourceMapView<'sm> {
let cache_entry = &mut self.line_cache[oldest];

// If the entry doesn't point to the correct file, fix it up
if pos < cache_entry.file.start_pos || pos >= cache_entry.file.end_pos {
if !file_contains(&cache_entry.file, pos) {
let file_valid;
if self.source_map.files().len() > 0 {
let file_index = self.source_map.lookup_source_file_idx(pos);
let file = self.source_map.files()[file_index].clone();

if pos >= file.start_pos && pos < file.end_pos {
if file_contains(&file, pos) {
cache_entry.file = file;
cache_entry.file_index = file_index;
file_valid = true;
Expand All @@ -95,10 +106,19 @@ impl<'sm> CachingSourceMapView<'sm> {
let line_bounds = cache_entry.file.line_bounds(line_index);

cache_entry.line_number = line_index + 1;
cache_entry.line_start = line_bounds.0;
cache_entry.line_end = line_bounds.1;
cache_entry.line = line_bounds;
cache_entry.time_stamp = self.time_stamp;

Some((cache_entry.file.clone(), cache_entry.line_number, pos - cache_entry.line_start))
Some((cache_entry.file.clone(), cache_entry.line_number, pos - cache_entry.line.start))
}
}

#[inline]
fn file_contains(file: &SourceFile, pos: BytePos) -> bool {
// `SourceMap::lookup_source_file_idx` and `SourceFile::contains` both consider the position
// one past the end of a file to belong to it. Normally, that's what we want. But for the
// purposes of converting a byte position to a line and column number, we can't come up with a
// line and column number if the file is empty, because an empty file doesn't contain any
// lines. So for our purposes, we don't consider empty files to contain any byte position.
file.contains(pos) && !file.is_empty()
}
21 changes: 15 additions & 6 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use std::cell::RefCell;
use std::cmp::{self, Ordering};
use std::fmt;
use std::hash::Hash;
use std::ops::{Add, Sub};
use std::ops::{Add, Range, Sub};
use std::path::{Path, PathBuf};
use std::str::FromStr;

Expand Down Expand Up @@ -1426,24 +1426,33 @@ impl SourceFile {
if line_index >= 0 { Some(line_index as usize) } else { None }
}

pub fn line_bounds(&self, line_index: usize) -> (BytePos, BytePos) {
if self.start_pos == self.end_pos {
return (self.start_pos, self.end_pos);
pub fn line_bounds(&self, line_index: usize) -> Range<BytePos> {
if self.is_empty() {
return self.start_pos..self.end_pos;
}

assert!(line_index < self.lines.len());
if line_index == (self.lines.len() - 1) {
(self.lines[line_index], self.end_pos)
self.lines[line_index]..self.end_pos
} else {
(self.lines[line_index], self.lines[line_index + 1])
self.lines[line_index]..self.lines[line_index + 1]
}
}

/// Returns whether or not the file contains the given `SourceMap` byte
/// position. The position one past the end of the file is considered to be
/// contained by the file. This implies that files for which `is_empty`
/// returns true still contain one byte position according to this function.
#[inline]
pub fn contains(&self, byte_pos: BytePos) -> bool {
byte_pos >= self.start_pos && byte_pos <= self.end_pos
}

#[inline]
pub fn is_empty(&self) -> bool {
self.start_pos == self.end_pos
}

/// Calculates the original byte position relative to the start of the file
/// based on the given byte position.
pub fn original_relative_byte_pos(&self, pos: BytePos) -> BytePos {
Expand Down
20 changes: 13 additions & 7 deletions compiler/rustc_trait_selection/src/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,17 @@ fn virtual_call_violation_for_method<'tcx>(

let param_env = tcx.param_env(method.def_id);

let abi_of_ty = |ty: Ty<'tcx>| -> &Abi {
let abi_of_ty = |ty: Ty<'tcx>| -> Option<&Abi> {
match tcx.layout_of(param_env.and(ty)) {
Ok(layout) => &layout.abi,
Err(err) => bug!("error: {}\n while computing layout for type {:?}", err, ty),
Ok(layout) => Some(&layout.abi),
Err(err) => {
// #78372
tcx.sess.delay_span_bug(
tcx.def_span(method.def_id),
&format!("error: {}\n while computing layout for type {:?}", err, ty),
);
None
}
}
};

Expand All @@ -473,7 +480,7 @@ fn virtual_call_violation_for_method<'tcx>(
receiver_for_self_ty(tcx, receiver_ty, tcx.mk_unit(), method.def_id);

match abi_of_ty(unit_receiver_ty) {
&Abi::Scalar(..) => (),
Some(Abi::Scalar(..)) => (),
abi => {
tcx.sess.delay_span_bug(
tcx.def_span(method.def_id),
Expand All @@ -493,13 +500,12 @@ fn virtual_call_violation_for_method<'tcx>(
receiver_for_self_ty(tcx, receiver_ty, trait_object_ty, method.def_id);

match abi_of_ty(trait_object_receiver) {
&Abi::ScalarPair(..) => (),
Some(Abi::ScalarPair(..)) => (),
abi => {
tcx.sess.delay_span_bug(
tcx.def_span(method.def_id),
&format!(
"receiver when `Self = {}` should have a ScalarPair ABI; \
found {:?}",
"receiver when `Self = {}` should have a ScalarPair ABI; found {:?}",
trait_object_ty, abi
),
);
Expand Down
Loading

0 comments on commit a3d7a5e

Please sign in to comment.