Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #78528

Merged
merged 111 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
dbb0583
docs: Reword `str::strip_prefix` and `strip_suffix` a bit
ijackson Aug 3, 2020
b7974bd
docs: Reword `slice::strip_prefix` and `strip_suffix` a bit
ijackson Aug 3, 2020
4549c77
docs: Rewrap `str::strip_prefix` and `strip_suffix` back to 100
ijackson Oct 12, 2020
6f5e96f
docs: Rewrap `slice::strip_prefix` and `strip_suffix` back to 100
ijackson Oct 12, 2020
22358c6
docs: `slice::strip_prefix` and `strip_suffix`, fold in sentence
ijackson Oct 12, 2020
bb0ce32
Lint unnecessary int-to-int and float-to-float casts
geoffreycopin Oct 15, 2020
915ce36
manual_unwrap_or / support Result::unwrap_or
tnielens Oct 17, 2020
114cb21
Remove an extra blank line in doc examples
giraffate Oct 19, 2020
ec23db9
Add linter for a single element for loop
patrickelectric Oct 3, 2020
ba1ca19
tests: if_same_then_else2: Ignore single_element_loop lint
patrickelectric Oct 3, 2020
65b52d8
needless-lifetime / multiple where clause predicates regression
tnielens Oct 19, 2020
57bf80f
Add lint for holding RefCell Ref across an await
Sep 10, 2020
8727169
fmt
Sep 10, 2020
070a751
update_lints
Sep 10, 2020
0f4abbf
Better naming post copy/paste
Sep 28, 2020
b3a427d
Add another test case
Sep 28, 2020
3ed69cd
Move existing lint into shared file
Oct 13, 2020
ee20eba
Move refcell lint into shared module
Oct 13, 2020
d8c6bce
Convert the await holding lints to correctness
Oct 13, 2020
86f2b29
Merge lints into one pass
Oct 19, 2020
4d33225
Separate tests for each lint
Oct 19, 2020
4a4f998
Add new lint for undropped ManuallyDrop values
cgm616 Oct 16, 2020
e70817e
Update tests and add known problems to docs
cgm616 Oct 16, 2020
c693de3
New lint: manual-range-contains
llogiq Oct 15, 2020
f2da0c7
manual-unwrap-or / pr remarks
tnielens Oct 22, 2020
6533d8b
manual-unwrap-or / pr remarks, round 2
tnielens Oct 22, 2020
e8f12d2
Address review comments
geoffreycopin Oct 22, 2020
02f0110
Add test case for negative literals
geoffreycopin Oct 22, 2020
30f80c3
Fix test file
geoffreycopin Oct 22, 2020
3807634
clippy_lints: Update empty_loop lint
josephlr Oct 11, 2020
cdb555f
Merge commit 'bf1c6f9871f430e284b17aa44059e0d0395e28a6' into clippyup
ebroto Oct 23, 2020
6caeed1
Remove duplicate import of `Target`
ebroto Oct 23, 2020
d46edd9
Keep sign in int-to-float casts
geoffreycopin Oct 23, 2020
62f60e1
No lint with `cfg!` and fix sugg for macro in `needless_bool` lint
ThibsG Oct 24, 2020
0d21ae0
manual-unwrap-or / pr remarks, round 3
tnielens Oct 24, 2020
71ac0c0
Keep separators in cast_size_32bits stderr
geoffreycopin Oct 24, 2020
33f3cfc
Fix inconsistencies in handling of inert attributes on statements
Aaron1011 Oct 23, 2020
e8731a9
Add large_types_passed_by_value lint
cauebs Oct 8, 2020
5c78d26
Auto merge of #6135 - cauebs:master, r=ebroto
bors Oct 24, 2020
29979ad
Auto merge of #6190 - montrivo:manual_result_unwrap_or, r=ebroto
bors Oct 24, 2020
b06856e
Auto merge of #6187 - geoffreycopin:master, r=ebroto
bors Oct 24, 2020
a675778
Auto merge of #6029 - Daniel-B-Smith:refcell_ref_await, r=flip1995
bors Oct 25, 2020
e0e617a
Auto merge of #6109 - patrickelectric:single_element_for_check, r=fli…
bors Oct 25, 2020
f82f9c2
Add lint for `&mut Mutex::lock`
FrancisMurillo Oct 2, 2020
6b01c39
Auto merge of #6181 - cgm616:undropped-manually-drops, r=flip1995
bors Oct 25, 2020
fb8a9cb
Change lint doc test
FrancisMurillo Oct 2, 2020
ec0c3af
Run update_lints
FrancisMurillo Oct 2, 2020
77e34a6
Inline is_mut_mutex_lock_call
FrancisMurillo Oct 5, 2020
292cb9b
Use `sugg_lint_and_help`
FrancisMurillo Oct 10, 2020
e7e03b7
Change from correctness to style and MaybeIncorrect instead of Machin…
FrancisMurillo Oct 18, 2020
df85532
Rollup merge of #78326 - Aaron1011:fix/min-stmt-lints, r=petrochenkov
JohnTitor Oct 25, 2020
fd62c18
Auto merge of #6162 - josephlr:empty-loop-no-std, r=flip1995
bors Oct 25, 2020
399732b
Auto merge of #6103 - FrancisMurillo:mut_mutex_lock, r=flip1995
bors Oct 25, 2020
d571389
Remove redundant `expect_local()` call
JohnTitor Oct 25, 2020
90cb25d
Auto merge of #6177 - rust-lang:manual-range-contains, r=flip1995
bors Oct 25, 2020
38be214
Auto merge of #6198 - montrivo:needless-lifetime, r=flip1995
bors Oct 25, 2020
718bb28
Auto merge of #6211 - ThibsG:NeedlessBoolCfg, r=flip1995
bors Oct 25, 2020
9c9aa2d
Auto merge of #6222 - JohnTitor:redundant-local-def-id, r=flip1995
bors Oct 25, 2020
db8380c
Add lint for unusually-grouped hex/binary literals
fhartwig Oct 31, 2018
f5a88b6
Allow hex literals to pass w/ groups of 2
cgm616 Oct 25, 2020
0c0f8db
Remove accidental test inclusion
cgm616 Oct 25, 2020
e7e4b35
Fix logic mistake
cgm616 Oct 25, 2020
3ce820b
Fix an invalid suggestion in `needless_collect` test
giraffate Oct 21, 2020
2f5d418
Add test case
giraffate Oct 25, 2020
312bbff
Integrate suggestions from code review
cgm616 Oct 25, 2020
77746b9
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Oct 25, 2020
4242ef8
Auto merge of #6224 - flip1995:rustup, r=flip1995
bors Oct 25, 2020
eceebc3
Auto merge of #6183 - cgm616:hex_bin_digit_grouping, r=flip1995
bors Oct 25, 2020
15f6fb9
Auto merge of #6194 - giraffate:remove_an_extra_blank_line, r=flip1995
bors Oct 25, 2020
83bb5ec
Auto merge of #6202 - giraffate:fix_invalid_suggestion_in_needless_co…
bors Oct 25, 2020
80b2168
Update triagebot.toml
flip1995 Oct 25, 2020
afbac89
Auto merge of #6225 - rust-lang:flip1995-patch-1, r=flip1995
bors Oct 25, 2020
a1bb10e
Remove lint from clippy
nathanwhit Sep 22, 2020
df59a44
rustc_span: improve bounds checks in byte_pos_to_line_and_col
tgnottingham Sep 21, 2020
cd259db
Do not ICE on invalid input
estebank Oct 26, 2020
66d56fe
Add `invalid_paths` internal lint
Oct 27, 2020
f79c4af
Fix invalid paths
Oct 27, 2020
650e3cb
Prefer new associated numeric consts in float error messages
Rustin170506 Oct 27, 2020
8823684
Auto merge of #6244 - mikerite:invalid_paths_20201027, r=flip1995
bors Oct 27, 2020
09e7053
simplify SpanlessEq::eq_path_segment
alex-700 Oct 24, 2020
2b7dd31
improve MATCH_LIKE_MATCHES_MACRO lint
alex-700 Oct 24, 2020
47dad31
rustc_span: represent line bounds with Range
tgnottingham Oct 27, 2020
de83f09
Auto merge of #6216 - alex-700:improve-match-like-matches-lint, r=ebroto
bors Oct 27, 2020
a3bff69
Use unwrapDIPtr because the Scope may be passed as None
danielframpton Oct 28, 2020
8e988e1
Merge remote-tracking branch 'upstream/master' into sync-from-rust
giraffate Oct 28, 2020
dace756
cargo dev update_lints
giraffate Oct 28, 2020
ffc2e66
Fix reference
giraffate Oct 28, 2020
c42a22d
Use `double_neg.stderr`
giraffate Oct 28, 2020
72016f4
Update cargo
ehuss Oct 28, 2020
a50d9e7
Deprecate temporary_cstr_as_ptr
ebroto Oct 28, 2020
e83e79f
Reinstate link to temporary_cstr_as_ptr
ebroto Oct 28, 2020
645ef50
Auto merge of #6257 - giraffate:sync-from-rust, r=ebroto
bors Oct 28, 2020
77da566
Merge commit '645ef505da378b6f810b1567806d1bcc2856395f' into clippyup
ebroto Oct 28, 2020
bd7cbae
Explain fully qualified syntax for `Rc` and `Arc`
camelid Aug 31, 2020
e0eed3c
Fix broken intra-doc link
camelid Aug 31, 2020
4e30e10
Don't say you "should" use fully qualified syntax
camelid Oct 28, 2020
0e88db7
Dogfood {exclusive,half-open} ranges in compiler (nfc)
workingjubilee Oct 22, 2020
e83666f
Prevent String::retain from creating non-utf8 strings when abusing panic
SkiFire13 Oct 28, 2020
1f6f917
Added test for issue #78498
SkiFire13 Oct 29, 2020
3fba948
Fix typos
bugadani Oct 29, 2020
2168210
Rollup merge of #75078 - ijackson:slice-strip, r=steveklabnik
jonas-schievink Oct 29, 2020
a384a58
Rollup merge of #76138 - camelid:rc-fully-qualified-syntax, r=stevekl…
jonas-schievink Oct 29, 2020
9867e54
Rollup merge of #78244 - workingjubilee:dogfood-fancy-ranges, r=varkor
jonas-schievink Oct 29, 2020
7fa9e39
Rollup merge of #78422 - estebank:fix-78372, r=pnkfelix
jonas-schievink Oct 29, 2020
151db25
Rollup merge of #78423 - tgnottingham:caching_source_map_bounds_check…
jonas-schievink Oct 29, 2020
31cfe63
Rollup merge of #78431 - Rustin-Liu:rustin-patch-lint, r=estebank
jonas-schievink Oct 29, 2020
38c3409
Rollup merge of #78462 - danielframpton:fixnullisa, r=nagisa
jonas-schievink Oct 29, 2020
a01e5f8
Rollup merge of #78493 - ehuss:update-cargo, r=ehuss
jonas-schievink Oct 29, 2020
48c4afb
Rollup merge of #78499 - SkiFire13:fix-string-retain, r=m-ou-se
jonas-schievink Oct 29, 2020
1d6e20e
Rollup merge of #78505 - ebroto:clippyup, r=oli-obk
jonas-schievink Oct 29, 2020
e656e60
Rollup merge of #78527 - bugadani:typo3, r=jonas-schievink
jonas-schievink Oct 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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