Skip to content

Commit a3d7a5e

Browse files
committed
Auto merge of rust-lang#78528 - jonas-schievink:rollup-e70g9zk, r=jonas-schievink
Rollup of 11 pull requests Successful merges: - rust-lang#75078 (Improve documentation for slice strip_* functions) - rust-lang#76138 (Explain fully qualified syntax for `Rc` and `Arc`) - rust-lang#78244 (Dogfood {exclusive,half-open} ranges in compiler (nfc)) - rust-lang#78422 (Do not ICE on invalid input) - rust-lang#78423 (rustc_span: improve bounds checks in byte_pos_to_line_and_col) - rust-lang#78431 (Prefer new associated numeric consts in float error messages) - rust-lang#78462 (Use unwrapDIPtr because the Scope may be null.) - rust-lang#78493 (Update cargo) - rust-lang#78499 (Prevent String::retain from creating non-utf8 strings when abusing panic) - rust-lang#78505 (Update Clippy - temporary_cstring_as_ptr deprecation) - rust-lang#78527 (Fix some more typos) Failed merges: r? `@ghost`
2 parents 6bdae9e + e656e60 commit a3d7a5e

File tree

110 files changed

+3070
-747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+3070
-747
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ struct LoweringContext<'a, 'hir: 'a> {
148148
is_collecting_in_band_lifetimes: bool,
149149

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

260-
/// All other posiitons.
260+
/// All other positions.
261261
Other,
262262
}
263263

@@ -363,7 +363,7 @@ enum ParenthesizedGenericArgs {
363363
/// elided bounds follow special rules. Note that this only covers
364364
/// cases where *nothing* is written; the `'_` in `Box<dyn Foo +
365365
/// '_>` is a case of "modern" elision.
366-
/// - **Deprecated** -- this coverse cases like `Ref<T>`, where the lifetime
366+
/// - **Deprecated** -- this covers cases like `Ref<T>`, where the lifetime
367367
/// parameter to ref is completely elided. `Ref<'_, T>` would be the modern,
368368
/// non-deprecated equivalent.
369369
///

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ impl<'a> AstValidator<'a> {
516516
self.session.source_map().guess_head_span(self.extern_mod.unwrap().span)
517517
}
518518

519-
/// An `fn` in `extern { ... }` cannot have qualfiers, e.g. `async fn`.
519+
/// An `fn` in `extern { ... }` cannot have qualifiers, e.g. `async fn`.
520520
fn check_foreign_fn_headerless(&self, ident: Ident, span: Span, header: FnHeader) {
521521
if header.has_qualifiers() {
522522
self.err_handler()

compiler/rustc_data_structures/src/tagged_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod drop;
2424
pub use copy::CopyTaggedPtr;
2525
pub use drop::TaggedPtr;
2626

27-
/// This describes the pointer type encaspulated by TaggedPtr.
27+
/// This describes the pointer type encapsulated by TaggedPtr.
2828
///
2929
/// # Safety
3030
///

compiler/rustc_data_structures/src/transitive_relation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct TransitiveRelation<T: Eq + Hash> {
1818
edges: Vec<Edge>,
1919

2020
// This is a cached transitive closure derived from the edges.
21-
// Currently, we build it lazilly and just throw out any existing
21+
// Currently, we build it lazily and just throw out any existing
2222
// copy whenever a new edge is added. (The Lock is to permit
2323
// the lazy computation.) This is kind of silly, except for the
2424
// fact its size is tied to `self.elements.len()`, so I wanted to
@@ -255,7 +255,7 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
255255
// argument is that, after step 2, we know that no element
256256
// can reach its successors (in the vector, not the graph).
257257
// After step 3, we know that no element can reach any of
258-
// its predecesssors (because of step 2) nor successors
258+
// its predecessors (because of step 2) nor successors
259259
// (because we just called `pare_down`)
260260
//
261261
// This same algorithm is used in `parents` below.

compiler/rustc_errors/src/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ impl Emitter for SilentEmitter {
513513
/// Maximum number of lines we will print for a multiline suggestion; arbitrary.
514514
///
515515
/// This should be replaced with a more involved mechanism to output multiline suggestions that
516-
/// more closely mimmics the regular diagnostic output, where irrelevant code lines are elided.
516+
/// more closely mimics the regular diagnostic output, where irrelevant code lines are elided.
517517
pub const MAX_SUGGESTION_HIGHLIGHT_LINES: usize = 6;
518518
/// Maximum number of suggestions to be shown
519519
///
@@ -887,7 +887,7 @@ impl EmitterWriter {
887887
// or the next are vertical line placeholders.
888888
|| (annotation.takes_space() // If either this or the next annotation is
889889
&& next.has_label()) // multiline start/end, move it to a new line
890-
|| (annotation.has_label() // so as not to overlap the orizontal lines.
890+
|| (annotation.has_label() // so as not to overlap the horizontal lines.
891891
&& next.takes_space())
892892
|| (annotation.takes_space() && next.takes_space())
893893
|| (overlaps(next, annotation, l)

compiler/rustc_lint/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#![feature(never_type)]
3636
#![feature(nll)]
3737
#![feature(or_patterns)]
38+
#![feature(half_open_range_patterns)]
39+
#![feature(exclusive_range_pattern)]
3840
#![recursion_limit = "256"]
3941

4042
#[macro_use]

compiler/rustc_lint/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ fn lint_literal<'tcx>(
439439
cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
440440
lint.build(&format!("literal out of range for `{}`", t.name_str()))
441441
.note(&format!(
442-
"the literal `{}` does not fit into the type `{}` and will be converted to `std::{}::INFINITY`",
442+
"the literal `{}` does not fit into the type `{}` and will be converted to `{}::INFINITY`",
443443
cx.sess()
444444
.source_map()
445445
.span_to_snippet(lit.span)

compiler/rustc_lint/src/unused.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
250250
has_emitted
251251
}
252252
ty::Array(ty, len) => match len.try_eval_usize(cx.tcx, cx.param_env) {
253+
// If the array is empty we don't lint, to avoid false positives
254+
Some(0) | None => false,
253255
// If the array is definitely non-empty, we can do `#[must_use]` checking.
254-
Some(n) if n != 0 => {
256+
Some(n) => {
255257
let descr_pre = &format!("{}array{} of ", descr_pre, plural_suffix,);
256258
check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, n as usize + 1)
257259
}
258-
// Otherwise, we don't lint, to avoid false positives.
259-
_ => false,
260260
},
261261
ty::Closure(..) => {
262262
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTypedef(
766766
LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope) {
767767
return wrap(Builder->createTypedef(
768768
unwrap<DIType>(Type), StringRef(Name, NameLen), unwrap<DIFile>(File),
769-
LineNo, unwrap<DIScope>(Scope)));
769+
LineNo, unwrapDIPtr<DIScope>(Scope)));
770770
}
771771

772772
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType(

compiler/rustc_middle/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#![feature(associated_type_bounds)]
4848
#![feature(rustc_attrs)]
4949
#![feature(int_error_matching)]
50+
#![feature(half_open_range_patterns)]
51+
#![feature(exclusive_range_pattern)]
5052
#![recursion_limit = "512"]
5153

5254
#[macro_use]

compiler/rustc_middle/src/ty/inhabitedness/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ impl<'tcx> TyS<'tcx> {
201201
),
202202

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

210-
// References to uninitialised memory is valid for any type, including
210+
// References to uninitialised memory are valid for any type, including
211211
// uninhabited types, in unsafe code, so we treat all references as
212212
// inhabited.
213213
// The precise semantics of inhabitedness with respect to references is currently

compiler/rustc_middle/src/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1834,10 +1834,10 @@ impl<'tcx> TyS<'tcx> {
18341834
}
18351835
ty::Array(ty, len) => {
18361836
match len.try_eval_usize(tcx, ParamEnv::empty()) {
1837+
Some(0) | None => false,
18371838
// If the array is definitely non-empty, it's uninhabited if
18381839
// the type of its elements is uninhabited.
1839-
Some(n) if n != 0 => ty.conservative_is_privately_uninhabited(tcx),
1840-
_ => false,
1840+
Some(1..) => ty.conservative_is_privately_uninhabited(tcx),
18411841
}
18421842
}
18431843
ty::Ref(..) => {

compiler/rustc_session/src/filesearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
153153
const SECONDARY_LIB_DIR: &str = "lib";
154154

155155
match option_env!("CFG_LIBDIR_RELATIVE") {
156-
Some(libdir) if libdir != "lib" => libdir.into(),
157-
_ => {
156+
None | Some("lib") => {
158157
if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
159158
PRIMARY_LIB_DIR.into()
160159
} else {
161160
SECONDARY_LIB_DIR.into()
162161
}
163162
}
163+
Some(libdir) => libdir.into(),
164164
}
165165
}
166166

compiler/rustc_span/src/caching_source_map_view.rs

+31-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
use crate::source_map::SourceMap;
22
use crate::{BytePos, SourceFile};
33
use rustc_data_structures::sync::Lrc;
4+
use std::ops::Range;
45

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

4859
// Check if the position is in one of the cached lines
4960
for cache_entry in self.line_cache.iter_mut() {
50-
if pos >= cache_entry.line_start && pos < cache_entry.line_end {
61+
if cache_entry.line.contains(&pos) {
5162
cache_entry.time_stamp = self.time_stamp;
5263

5364
return Some((
5465
cache_entry.file.clone(),
5566
cache_entry.line_number,
56-
pos - cache_entry.line_start,
67+
pos - cache_entry.line.start,
5768
));
5869
}
5970
}
@@ -69,13 +80,13 @@ impl<'sm> CachingSourceMapView<'sm> {
6980
let cache_entry = &mut self.line_cache[oldest];
7081

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

78-
if pos >= file.start_pos && pos < file.end_pos {
89+
if file_contains(&file, pos) {
7990
cache_entry.file = file;
8091
cache_entry.file_index = file_index;
8192
file_valid = true;
@@ -95,10 +106,19 @@ impl<'sm> CachingSourceMapView<'sm> {
95106
let line_bounds = cache_entry.file.line_bounds(line_index);
96107

97108
cache_entry.line_number = line_index + 1;
98-
cache_entry.line_start = line_bounds.0;
99-
cache_entry.line_end = line_bounds.1;
109+
cache_entry.line = line_bounds;
100110
cache_entry.time_stamp = self.time_stamp;
101111

102-
Some((cache_entry.file.clone(), cache_entry.line_number, pos - cache_entry.line_start))
112+
Some((cache_entry.file.clone(), cache_entry.line_number, pos - cache_entry.line.start))
103113
}
104114
}
115+
116+
#[inline]
117+
fn file_contains(file: &SourceFile, pos: BytePos) -> bool {
118+
// `SourceMap::lookup_source_file_idx` and `SourceFile::contains` both consider the position
119+
// one past the end of a file to belong to it. Normally, that's what we want. But for the
120+
// purposes of converting a byte position to a line and column number, we can't come up with a
121+
// line and column number if the file is empty, because an empty file doesn't contain any
122+
// lines. So for our purposes, we don't consider empty files to contain any byte position.
123+
file.contains(pos) && !file.is_empty()
124+
}

compiler/rustc_span/src/lib.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use std::cell::RefCell;
5252
use std::cmp::{self, Ordering};
5353
use std::fmt;
5454
use std::hash::Hash;
55-
use std::ops::{Add, Sub};
55+
use std::ops::{Add, Range, Sub};
5656
use std::path::{Path, PathBuf};
5757
use std::str::FromStr;
5858

@@ -1426,24 +1426,33 @@ impl SourceFile {
14261426
if line_index >= 0 { Some(line_index as usize) } else { None }
14271427
}
14281428

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

14341434
assert!(line_index < self.lines.len());
14351435
if line_index == (self.lines.len() - 1) {
1436-
(self.lines[line_index], self.end_pos)
1436+
self.lines[line_index]..self.end_pos
14371437
} else {
1438-
(self.lines[line_index], self.lines[line_index + 1])
1438+
self.lines[line_index]..self.lines[line_index + 1]
14391439
}
14401440
}
14411441

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

1451+
#[inline]
1452+
pub fn is_empty(&self) -> bool {
1453+
self.start_pos == self.end_pos
1454+
}
1455+
14471456
/// Calculates the original byte position relative to the start of the file
14481457
/// based on the given byte position.
14491458
pub fn original_relative_byte_pos(&self, pos: BytePos) -> BytePos {

compiler/rustc_trait_selection/src/traits/object_safety.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,17 @@ fn virtual_call_violation_for_method<'tcx>(
461461

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

464-
let abi_of_ty = |ty: Ty<'tcx>| -> &Abi {
464+
let abi_of_ty = |ty: Ty<'tcx>| -> Option<&Abi> {
465465
match tcx.layout_of(param_env.and(ty)) {
466-
Ok(layout) => &layout.abi,
467-
Err(err) => bug!("error: {}\n while computing layout for type {:?}", err, ty),
466+
Ok(layout) => Some(&layout.abi),
467+
Err(err) => {
468+
// #78372
469+
tcx.sess.delay_span_bug(
470+
tcx.def_span(method.def_id),
471+
&format!("error: {}\n while computing layout for type {:?}", err, ty),
472+
);
473+
None
474+
}
468475
}
469476
};
470477

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

475482
match abi_of_ty(unit_receiver_ty) {
476-
&Abi::Scalar(..) => (),
483+
Some(Abi::Scalar(..)) => (),
477484
abi => {
478485
tcx.sess.delay_span_bug(
479486
tcx.def_span(method.def_id),
@@ -493,13 +500,12 @@ fn virtual_call_violation_for_method<'tcx>(
493500
receiver_for_self_ty(tcx, receiver_ty, trait_object_ty, method.def_id);
494501

495502
match abi_of_ty(trait_object_receiver) {
496-
&Abi::ScalarPair(..) => (),
503+
Some(Abi::ScalarPair(..)) => (),
497504
abi => {
498505
tcx.sess.delay_span_bug(
499506
tcx.def_span(method.def_id),
500507
&format!(
501-
"receiver when `Self = {}` should have a ScalarPair ABI; \
502-
found {:?}",
508+
"receiver when `Self = {}` should have a ScalarPair ABI; found {:?}",
503509
trait_object_ty, abi
504510
),
505511
);

0 commit comments

Comments
 (0)