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

Fix issue 85435 by restricting Fake Read precision #55

Merged
merged 114 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
0202875
add TrustedRandomAccess specialization to vec::extend
the8472 Apr 1, 2021
c64a2ed
elision of generic argument in E0599 if the methode has not been foun…
ABouttefeux Apr 15, 2021
8789ab1
Update Docker to build the deprecated target alongside the new one
kulikjak May 13, 2021
b13185d
Improve comment
kulikjak May 13, 2021
c150772
rustdoc: avoid legacy Korean fonts in Windows
May 15, 2021
7e2e331
rustdoc: add the license of Noto Sans KR
May 15, 2021
b5e09dc
rustdoc: update static files
May 15, 2021
fe44fde
chore: format code
May 15, 2021
6b601d4
chore: update comment in rustdoc.css
May 15, 2021
8412d30
test: update unversioned-files.txt
May 18, 2021
8a2d663
test: fix the order in unversioned-files.txt
May 19, 2021
f749d88
Disallow shadowing const parameters
FabianWolff May 19, 2021
e587366
doc: clarify Mutex::try_lock, etc. errors
tlyu May 20, 2021
c441675
Add Weak may_dangle tests
dtolnay May 21, 2021
23a4050
Weak's type parameter may dangle on drop
dtolnay May 21, 2021
6efa14b
remove generic argument insead of displaying "_"
ABouttefeux May 21, 2021
1f130fb
Revert portion of PR #83521 that injected issue #85435 (and thus expo…
pnkfelix May 21, 2021
4742bbb
Regression test for issue 85435.
pnkfelix May 21, 2021
0d073c9
Apply suggestions from code review
pnkfelix May 21, 2021
5b802ed
Apply suggestions from code review
ABouttefeux May 22, 2021
120691c
change from review and show full type if it can be deref
ABouttefeux May 22, 2021
a50f1e9
Get rid of PreviousDepGraph.
cjgillot May 22, 2021
903e369
Fix boostrap using host exe suffix for cargo
jam1garner May 22, 2021
9e11b61
linkchecker: Organize state into a struct, and add report.
ehuss Jan 11, 2021
d7341f3
Don't reborrow self when computing the dest pointer in <[T]>::copy_wi…
SkiFire13 May 23, 2021
db8c6e0
Remove stray .stderr files
LeSeulArtichaut May 24, 2021
e0c9719
Avoid a double drop in Vec::dedup if a destructor panics
SkiFire13 May 24, 2021
c9595fa
Make Vec::dedup panicking test actually detect double panics
SkiFire13 May 24, 2021
0e4f8cb
minor rewording after review
tlyu May 24, 2021
1c1d4f9
Apply suggestions from code review
pnkfelix May 24, 2021
b63f7f9
Demote ControlFlow::{from|into}_try to pub(crate)
scottmcm May 24, 2021
ad30826
Revert "Move llvm submodule updates to rustbuild"
Mark-Simulacrum May 24, 2021
e238ee3
Update cc
ChrisDenton May 24, 2021
e9e6e66
Optimize linkchecker by caching all filesystem access.
ehuss May 24, 2021
b6532eb
Add some tests for the linkchecker.
ehuss May 24, 2021
37588e9
Document shared_from_cow functions
fee1-dead May 25, 2021
79a5b12
Fix tasklist example in rustdoc book.
ehuss May 25, 2021
8d954fa
Remove arrays/IntoIterator message from Iterator trait.
m-ou-se May 25, 2021
87cf2d4
Move stability attribute for methods under the `ip` feature from the …
CDirkx May 25, 2021
3ed90e2
fix matches! and assert_matches! on edition 2021
May 25, 2021
0baf898
Remove num_as_ne_bytes feature
hch12907 May 25, 2021
5d8e6ea
show list of candidates
ABouttefeux May 25, 2021
824c743
add regression test
May 25, 2021
d14dd9f
emit diagnostic after post-monomorphization errors
lqd May 16, 2021
6f61456
add test for issue 85155 and similar
lqd May 24, 2021
b083541
Handle `unsafe_op_in_unsafe_fn` properly in THIR unsafeck
LeSeulArtichaut May 24, 2021
f7916b4
Fix `unused_unsafe` in THIR unsafeck
LeSeulArtichaut May 24, 2021
f9e08cd
Run THIR unsafeck on `unsafe_op_in_unsafe_fn` test
LeSeulArtichaut May 24, 2021
caf6faf
Remove Iterator #[rustc_on_unimplemented]s that no longer apply.
m-ou-se May 25, 2021
072b85c
Update books
ehuss May 25, 2021
8a7dc0d
Update cargo
ehuss May 25, 2021
47a90f4
Auto merge of #85535 - dtolnay:weakdangle, r=kennytm
bors May 26, 2021
54bdfa1
Auto merge of #85252 - kulikjak:fix-solaris-CI, r=Mark-Simulacrum
bors May 26, 2021
0264f4f
Rollup merge of #84048 - konan8205:master, r=jsha
JohnTitor May 26, 2021
ae6a1a7
Rollup merge of #85529 - tlyu:trylock-errors, r=JohnTitor
JohnTitor May 26, 2021
d75521a
Rollup merge of #85590 - jam1garner:tool-bootstrap-su-fix, r=Mark-Sim…
JohnTitor May 26, 2021
b7b9ce3
Rollup merge of #85610 - SkiFire13:fix-copy-within-provenance, r=oli-obk
JohnTitor May 26, 2021
0bc3066
Rollup merge of #85623 - LeSeulArtichaut:stray-stderr, r=Mark-Simulacrum
JohnTitor May 26, 2021
587de8e
Rollup merge of #85645 - scottmcm:demote-from-into-try, r=yaahc
JohnTitor May 26, 2021
7508203
Rollup merge of #85647 - rust-lang:revert-81601-llvm-on-demand, r=jyn514
JohnTitor May 26, 2021
e87bc66
Rollup merge of #85666 - fee1-dead:document-shared-from-cow, r=dtolnay
JohnTitor May 26, 2021
1e51afa
Rollup merge of #85668 - ehuss:fix-rustdoc-tasklist, r=Mark-Simulacrum
JohnTitor May 26, 2021
7caf93f
Rollup merge of #85672 - CDirkx:ip, r=Mark-Simulacrum
JohnTitor May 26, 2021
bce257c
Rollup merge of #85699 - ehuss:update-books, r=ehuss
JohnTitor May 26, 2021
7c0677a
Rollup merge of #85701 - ehuss:update-cargo, r=ehuss
JohnTitor May 26, 2021
1969c2e
Auto merge of #85711 - JohnTitor:rollup-8why04t, r=JohnTitor
bors May 26, 2021
d1b69cf
Fix typo in core::array::IntoIter comment
BlackHoleFox May 26, 2021
128d385
stabilize member constraints
nikomatsakis Apr 29, 2021
45099e6
Add inline attr to private CString::into_inner
elichai May 26, 2021
52a3365
cleanup and fix compiling of libunwind
12101111 May 24, 2021
69c78a9
Rollup merge of #85478 - FabianWolff:issue-85348, r=petrochenkov
Dylan-DPC May 26, 2021
27899e3
Rollup merge of #85625 - SkiFire13:fix-85613-vec-dedup-drop-panics, r…
Dylan-DPC May 26, 2021
f5c5cca
Rollup merge of #85627 - LeSeulArtichaut:thir-unsafe-fn-lint, r=nikom…
Dylan-DPC May 26, 2021
4b0014e
Rollup merge of #85633 - lqd:stackless_span_stacks, r=oli-obk
Dylan-DPC May 26, 2021
12ab323
Rollup merge of #85670 - m-ou-se:array-intoiter-1, r=scottmcm
Dylan-DPC May 26, 2021
3c2a709
Rollup merge of #85678 - lukas-code:matches2021, r=dtolnay
Dylan-DPC May 26, 2021
f3b10dd
Rollup merge of #85679 - hch12907:master, r=Mark-Simulacrum
Dylan-DPC May 26, 2021
9ee87c7
Rollup merge of #85712 - BlackHoleFox:fix-iter-typo, r=jyn514
Dylan-DPC May 26, 2021
b36c45d
Update RLS
Xanewok May 26, 2021
f9499ea
* Fix bug where some <details> tags were not closed.
GuillaumeGomez May 26, 2021
3bed0be
Update trait toggle test
GuillaumeGomez May 26, 2021
f6a28aa
Auto merge of #85720 - Dylan-DPC:rollup-in5917x, r=Dylan-DPC
bors May 26, 2021
b3054d2
bless compare-mode=nll output
nikomatsakis May 26, 2021
9a700d2
Auto merge of #85721 - Xanewok:update-rls, r=Xanewok
bors May 26, 2021
ff8a387
Remove unneeded workaround
syvb May 26, 2021
9111b8a
Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum
bors May 26, 2021
fdc15ef
Don't hash `thir_body`
LeSeulArtichaut May 26, 2021
e7a3ada
Mention float workaround in Iterator::{min,max}
syvb May 26, 2021
86ac0b4
Auto merge of #85652 - ehuss:linkchecker-perf, r=Mark-Simulacrum
bors May 26, 2021
edef5bc
Lint against non-camelCase trait alias names
syvb May 26, 2021
7146a05
don't use unneeded closure
syvb May 27, 2021
b00f6fc
don't use unneeded closure
syvb May 27, 2021
f2810d5
Rollup merge of #84221 - ABouttefeux:generic-arg-elision, r=estebank
Dylan-DPC May 27, 2021
3530a78
Rollup merge of #84701 - nikomatsakis:stabilize-member-constraints-61…
Dylan-DPC May 27, 2021
9d4a644
Rollup merge of #85564 - pnkfelix:issue-85435-readd-capture-disjoint-…
Dylan-DPC May 27, 2021
e7c9469
Rollup merge of #85583 - cjgillot:no-previous-dg, r=petrochenkov
Dylan-DPC May 27, 2021
0c53acc
Rollup merge of #85649 - ChrisDenton:update-cc, r=matthewjasper
Dylan-DPC May 27, 2021
de1d7db
Rollup merge of #85689 - m-ou-se:array-intoiter-3, r=estebank
Dylan-DPC May 27, 2021
955e0f4
Rollup merge of #85719 - elichai:cstring-into_inner-inline, r=m-ou-se
Dylan-DPC May 27, 2021
85a408a
Rollup merge of #85725 - Smittyvb:rm-24159-workaround, r=RalfJung
Dylan-DPC May 27, 2021
c4ec606
Auto merge of #85734 - Dylan-DPC:rollup-q6iiees, r=Dylan-DPC
bors May 27, 2021
9814e83
Auto merge of #84124 - 12101111:libunwind, r=petrochenkov
bors May 27, 2021
3cafe2a
Rename opensbd to openbsd
370417 May 27, 2021
04d34a9
Enable Vec's calloc optimization for Option<NonZero>
scottmcm May 27, 2021
8d1e3d3
Auto merge of #85732 - Smittyvb:trait-alias-camelcase-lint, r=varkor
bors May 27, 2021
ea78d1e
Auto merge of #85737 - scottmcm:vec-calloc-option-nonzero, r=m-ou-se
bors May 27, 2021
9385be7
Update compiler/rustc_middle/src/query/mod.rs
nikomatsakis May 27, 2021
d854c3c
Auto merge of #85729 - LeSeulArtichaut:thir-no-hash, r=nikomatsakis
bors May 27, 2021
6ac83e1
Rollup merge of #85722 - GuillaumeGomez:trait-toggle, r=jsha
GuillaumeGomez May 27, 2021
e30192a
Rollup merge of #85730 - Smittyvb:iter-min-max-floats, r=m-ou-se
GuillaumeGomez May 27, 2021
48706ed
Rollup merge of #85738 - 370417:opensbd, r=m-ou-se
GuillaumeGomez May 27, 2021
e51830b
Auto merge of #85757 - GuillaumeGomez:rollup-k8hfhp8, r=GuillaumeGomez
bors May 27, 2021
027d73d
Restrict Fake Read precision
roxelo May 25, 2021
382338f
Remove feature gate
roxelo May 27, 2021
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
8 changes: 4 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ version = "0.1.0"

[[package]]
name = "cc"
version = "1.0.67"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787"
dependencies = [
"jobserver",
]
Expand Down Expand Up @@ -2845,9 +2845,9 @@ dependencies = [

[[package]]
name = "racer"
version = "2.1.46"
version = "2.1.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7cbda48a9124ed2e83766d2c15e3725710d344abca35fad8cf52341a55883b1"
checksum = "513c70e67444a0d62fdc581dffa521c6820942a5f08300d0864863f8d0e750e3"
dependencies = [
"bitflags",
"clap",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test = false

[dependencies]
bitflags = "1.2.1"
cc = "1.0.67"
cc = "1.0.68"
itertools = "0.9"
tracing = "0.1"
libc = "0.2.50"
Expand All @@ -24,7 +24,7 @@ rustc_middle = { path = "../rustc_middle" }
rustc_apfloat = { path = "../rustc_apfloat" }
rustc_attr = { path = "../rustc_attr" }
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
rustc_data_structures = { path = "../rustc_data_structures"}
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_fs_util = { path = "../rustc_fs_util" }
rustc_hir = { path = "../rustc_hir" }
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ declare_features! (
(accepted, extended_key_value_attributes, "1.54.0", Some(78835), None),
/// Allows unsizing coercions in `const fn`.
(accepted, const_fn_unsize, "1.54.0", Some(64992), None),
/// Allows `impl Trait` with multiple unrelated lifetimes.
(accepted, member_constraints, "1.54.0", Some(61997), None),

// -------------------------------------------------------------------------
// feature-group-end: accepted features
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,6 @@ declare_features! (
/// Allows explicit discriminants on non-unit enum variants.
(active, arbitrary_enum_discriminant, "1.37.0", Some(60553), None),

/// Allows `impl Trait` with multiple unrelated lifetimes.
(active, member_constraints, "1.37.0", Some(61997), None),

/// Allows `async || body` closures.
(active, async_closure, "1.37.0", Some(62290), None),

Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_incremental/src/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use rustc_data_structures::fx::FxHashMap;
use rustc_hir::definitions::DefPathTable;
use rustc_middle::dep_graph::{PreviousDepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
use rustc_middle::ty::query::OnDiskCache;
use rustc_serialize::opaque::Decoder;
use rustc_serialize::Decodable;
Expand All @@ -22,8 +22,8 @@ pub enum LoadResult<T> {
Error { message: String },
}

impl LoadResult<(PreviousDepGraph, WorkProductMap)> {
pub fn open(self, sess: &Session) -> (PreviousDepGraph, WorkProductMap) {
impl LoadResult<(SerializedDepGraph, WorkProductMap)> {
pub fn open(self, sess: &Session) -> (SerializedDepGraph, WorkProductMap) {
match self {
LoadResult::Error { message } => {
sess.warn(&message);
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<T> MaybeAsync<T> {
}
}

pub type DepGraphFuture = MaybeAsync<LoadResult<(PreviousDepGraph, WorkProductMap)>>;
pub type DepGraphFuture = MaybeAsync<LoadResult<(SerializedDepGraph, WorkProductMap)>>;

/// Launch a thread and load the dependency graph in the background.
pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
Expand Down Expand Up @@ -185,7 +185,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
let dep_graph = SerializedDepGraph::decode(&mut decoder)
.expect("Error reading cached dep-graph");

LoadResult::Ok { data: (PreviousDepGraph::new(dep_graph), prev_work_products) }
LoadResult::Ok { data: (dep_graph, prev_work_products) }
}
}
}))
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_incremental/src/persist/save.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::join;
use rustc_middle::dep_graph::{DepGraph, PreviousDepGraph, WorkProduct, WorkProductId};
use rustc_middle::dep_graph::{DepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
use rustc_middle::ty::TyCtxt;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use rustc_serialize::Encodable as RustcEncodable;
Expand Down Expand Up @@ -186,7 +186,7 @@ fn encode_query_cache(tcx: TyCtxt<'_>, encoder: &mut FileEncoder) -> FileEncodeR

pub fn build_dep_graph(
sess: &Session,
prev_graph: PreviousDepGraph,
prev_graph: SerializedDepGraph,
prev_work_products: FxHashMap<WorkProductId, WorkProduct>,
) -> Option<DepGraph> {
if sess.opts.incremental.is_none() {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
| ast::ItemKind::Struct(..)
| ast::ItemKind::Union(..) => self.check_case(cx, "type", &it.ident),
ast::ItemKind::Trait(..) => self.check_case(cx, "trait", &it.ident),
ast::ItemKind::TraitAlias(..) => self.check_case(cx, "trait alias", &it.ident),
_ => (),
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ libc = "0.2.73"

[build-dependencies]
build_helper = { path = "../../src/build_helper" }
cc = "1.0.67"
cc = "1.0.68"
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ crate use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
pub type DepGraphQuery = rustc_query_system::dep_graph::DepGraphQuery<DepKind>;
pub type PreviousDepGraph = rustc_query_system::dep_graph::PreviousDepGraph<DepKind>;
pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph<DepKind>;
pub type EdgeFilter = rustc_query_system::dep_graph::debug::EdgeFilter<DepKind>;

Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ impl<'tcx> MonoItem<'tcx> {
pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
crate::dep_graph::make_compile_mono_item(tcx, self)
}

/// Returns the item's `CrateNum`
pub fn krate(&self) -> CrateNum {
match self {
MonoItem::Fn(ref instance) => instance.def_id().krate,
MonoItem::Static(def_id) => def_id.krate,
MonoItem::GlobalAsm(..) => LOCAL_CRATE,
}
}
}

impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ rustc_queries! {

/// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
query thir_body(key: ty::WithOptConstParam<LocalDefId>) -> (&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId) {
// Perf tests revealed that hashing THIR is inefficient (see #85729).
no_hash
desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
}

Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_mir/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use rustc_target::abi::{Abi, Align, FieldsShape, TagEncoding};
use rustc_target::abi::{HasDataLayout, LayoutOf, Size, VariantIdx, Variants};

use super::{
alloc_range, mir_assign_valid_types, AllocId, AllocMap, AllocRef, AllocRefMut, Allocation,
ConstAlloc, ImmTy, Immediate, InterpCx, InterpResult, LocalValue, Machine, MemoryKind, OpTy,
Operand, Pointer, PointerArithmetic, Scalar, ScalarMaybeUninit,
alloc_range, mir_assign_valid_types, AllocRef, AllocRefMut, ConstAlloc, ImmTy, Immediate,
InterpCx, InterpResult, LocalValue, Machine, MemoryKind, OpTy, Operand, Pointer,
PointerArithmetic, Scalar, ScalarMaybeUninit,
};

#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)]
Expand Down Expand Up @@ -292,8 +292,6 @@ where
// FIXME: Working around https://github.com/rust-lang/rust/issues/54385
Tag: Debug + Copy + Eq + Hash + 'static,
M: Machine<'mir, 'tcx, PointerTag = Tag>,
// FIXME: Working around https://github.com/rust-lang/rust/issues/24159
M::MemoryMap: AllocMap<AllocId, (MemoryKind<M::MemoryKind>, Allocation<Tag, M::AllocExtra>)>,
{
/// Take a value, which represents a (thin or wide) reference, and make it a place.
/// Alignment is just based on the type. This is the inverse of `MemPlace::to_ref()`.
Expand Down
46 changes: 44 additions & 2 deletions compiler/rustc_mir/src/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator};
use rustc_errors::{ErrorReported, FatalError};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::GrowableBitSet;
Expand Down Expand Up @@ -342,7 +342,8 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<
.collect()
}

// Collect all monomorphized items reachable from `starting_point`
/// Collect all monomorphized items reachable from `starting_point`, and emit a note diagnostic if a
/// post-monorphization error is encountered during a collection step.
fn collect_items_rec<'tcx>(
tcx: TyCtxt<'tcx>,
starting_point: Spanned<MonoItem<'tcx>>,
Expand All @@ -359,6 +360,31 @@ fn collect_items_rec<'tcx>(
let mut neighbors = Vec::new();
let recursion_depth_reset;

//
// Post-monomorphization errors MVP
//
// We can encounter errors while monomorphizing an item, but we don't have a good way of
// showing a complete stack of spans ultimately leading to collecting the erroneous one yet.
// (It's also currently unclear exactly which diagnostics and information would be interesting
// to report in such cases)
//
// This leads to suboptimal error reporting: a post-monomorphization error (PME) will be
// shown with just a spanned piece of code causing the error, without information on where
// it was called from. This is especially obscure if the erroneous mono item is in a
// dependency. See for example issue #85155, where, before minimization, a PME happened two
// crates downstream from libcore's stdarch, without a way to know which dependency was the
// cause.
//
// If such an error occurs in the current crate, its span will be enough to locate the
// source. If the cause is in another crate, the goal here is to quickly locate which mono
// item in the current crate is ultimately responsible for causing the error.
//
// To give at least _some_ context to the user: while collecting mono items, we check the
// error count. If it has changed, a PME occurred, and we trigger some diagnostics about the
// current step of mono items collection.
//
let error_count = tcx.sess.diagnostic().err_count();

match starting_point.node {
MonoItem::Static(def_id) => {
let instance = Instance::mono(tcx, def_id);
Expand Down Expand Up @@ -411,6 +437,22 @@ fn collect_items_rec<'tcx>(
}
}

// Check for PMEs and emit a diagnostic if one happened. To try to show relevant edges of the
// mono item graph where the PME diagnostics are currently the most problematic (e.g. ones
// involving a dependency, and the lack of context is confusing) in this MVP, we focus on
// diagnostics on edges crossing a crate boundary: the collected mono items which are not
// defined in the local crate.
if tcx.sess.diagnostic().err_count() > error_count && starting_point.node.krate() != LOCAL_CRATE
{
tcx.sess.span_note_without_error(
starting_point.span,
&format!(
"the above error was encountered while instantiating `{}`",
starting_point.node
),
);
}

record_accesses(tcx, starting_point.node, neighbors.iter().map(|i| &i.node), inlining_map);

for neighbour in neighbors {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// match x { _ => () } // fake read of `x`
// };
// ```
//
for (thir_place, cause, hir_id) in fake_reads.into_iter() {
let place_builder =
unpack!(block = this.as_place_builder(block, &this.thir[*thir_place]));
Expand Down
41 changes: 25 additions & 16 deletions compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
self.warn_unused_unsafe(
hir_id,
block_span,
Some(self.tcx.sess.source_map().guess_head_span(enclosing_span)),
Some((self.tcx.sess.source_map().guess_head_span(enclosing_span), "block")),
);
f(self);
} else {
Expand All @@ -52,7 +52,15 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
f(self);

if let SafetyContext::UnsafeBlock { used: false, span, hir_id } = self.safety_context {
self.warn_unused_unsafe(hir_id, span, self.body_unsafety.unsafe_fn_sig_span());
self.warn_unused_unsafe(
hir_id,
span,
if self.unsafe_op_in_unsafe_fn_allowed() {
self.body_unsafety.unsafe_fn_sig_span().map(|span| (span, "fn"))
} else {
None
},
);
}
self.safety_context = prev_context;
return;
Expand All @@ -72,16 +80,20 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
SafetyContext::UnsafeFn if unsafe_op_in_unsafe_fn_allowed => {}
SafetyContext::UnsafeFn => {
// unsafe_op_in_unsafe_fn is disallowed
struct_span_err!(
self.tcx.sess,
self.tcx.struct_span_lint_hir(
UNSAFE_OP_IN_UNSAFE_FN,
self.hir_context,
span,
E0133,
"{} is unsafe and requires unsafe block",
description,
|lint| {
lint.build(&format!(
"{} is unsafe and requires unsafe block (error E0133)",
description,
))
.span_label(span, description)
.note(note)
.emit();
},
)
.span_label(span, description)
.note(note)
.emit();
}
SafetyContext::Safe => {
let fn_sugg = if unsafe_op_in_unsafe_fn_allowed { " function or" } else { "" };
Expand All @@ -104,18 +116,15 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
&self,
hir_id: hir::HirId,
block_span: Span,
enclosing_span: Option<Span>,
enclosing_unsafe: Option<(Span, &'static str)>,
) {
let block_span = self.tcx.sess.source_map().guess_head_span(block_span);
self.tcx.struct_span_lint_hir(UNUSED_UNSAFE, hir_id, block_span, |lint| {
let msg = "unnecessary `unsafe` block";
let mut db = lint.build(msg);
db.span_label(block_span, msg);
if let Some(enclosing_span) = enclosing_span {
db.span_label(
enclosing_span,
format!("because it's nested under this `unsafe` block"),
);
if let Some((span, kind)) = enclosing_unsafe {
db.span_label(span, format!("because it's nested under this `unsafe` {}", kind));
}
db.emit();
});
Expand Down
Loading