Skip to content

Commit a74d186

Browse files
committedMay 14, 2020
Auto merge of #72202 - Dylan-DPC:rollup-6lbxh1s, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #71910 (Fix unused_parens false positive when using binary operations) - #72087 (Fix hang in lexical_region_resolve) - #72126 (Change `WorkProduct::saved_files` to an `Option`.) - #72127 (add long error explanation for E0228) - #72141 (Warn against thread::sleep in async fn) - #72170 (use `require_lang_item` over `unwrap`.) - #72191 (Clean up E0589 explanation) - #72194 (Don't ICE on missing `Unsize` impl) Failed merges: r? @ghost
2 parents af6d886 + 7b5bc61 commit a74d186

File tree

35 files changed

+246
-86
lines changed

35 files changed

+246
-86
lines changed
 

‎src/librustc_codegen_ssa/back/write.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_errors::{DiagnosticId, FatalError, Handler, Level};
2121
use rustc_fs_util::link_or_copy;
2222
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
2323
use rustc_incremental::{
24-
copy_cgu_workproducts_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
24+
copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
2525
};
2626
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
2727
use rustc_middle::middle::cstore::EncodedMetadata;
@@ -465,17 +465,13 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
465465
return work_products;
466466
}
467467

468-
let _timer = sess.timer("incr_comp_copy_cgu_workproducts");
468+
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");
469469

470470
for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
471-
let mut files = vec![];
472-
473-
if let Some(ref path) = module.object {
474-
files.push(path.clone());
475-
}
471+
let path = module.object.as_ref().map(|path| path.clone());
476472

477473
if let Some((id, product)) =
478-
copy_cgu_workproducts_to_incr_comp_cache_dir(sess, &module.name, &files)
474+
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, &path)
479475
{
480476
work_products.insert(id, product);
481477
}
@@ -817,7 +813,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
817813
) -> Result<WorkItemResult<B>, FatalError> {
818814
let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
819815
let mut object = None;
820-
for saved_file in &module.source.saved_files {
816+
if let Some(saved_file) = module.source.saved_file {
821817
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name));
822818
object = Some(obj_out.clone());
823819
let source_file = in_incr_comp_dir(&incr_comp_session_dir, &saved_file);

‎src/librustc_error_codes/error_codes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ E0223: include_str!("./error_codes/E0223.md"),
120120
E0224: include_str!("./error_codes/E0224.md"),
121121
E0225: include_str!("./error_codes/E0225.md"),
122122
E0226: include_str!("./error_codes/E0226.md"),
123+
E0228: include_str!("./error_codes/E0228.md"),
123124
E0229: include_str!("./error_codes/E0229.md"),
124125
E0230: include_str!("./error_codes/E0230.md"),
125126
E0231: include_str!("./error_codes/E0231.md"),
@@ -482,7 +483,6 @@ E0753: include_str!("./error_codes/E0753.md"),
482483
// E0218, // no associated type defined
483484
// E0219, // associated type defined in higher-ranked supertrait
484485
E0227, // ambiguous lifetime bound, explicit lifetime bound required
485-
E0228, // explicit lifetime bound required
486486
// E0233,
487487
// E0234,
488488
// E0235, // structure constructor specifies a structure of type but
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
The lifetime bound for this object type cannot be deduced from context and must
2+
be specified.
3+
4+
Erroneous code example:
5+
6+
```compile_fail,E0228
7+
trait Trait { }
8+
9+
struct TwoBounds<'a, 'b, T: Sized + 'a + 'b> {
10+
x: &'a i32,
11+
y: &'b i32,
12+
z: T,
13+
}
14+
15+
type Foo<'a, 'b> = TwoBounds<'a, 'b, dyn Trait>;
16+
```
17+
18+
When a trait object is used as a type argument of a generic type, Rust will try
19+
to infer its lifetime if unspecified. However, this isn't possible when the
20+
containing type has more than one lifetime bound.
21+
22+
The above example can be resolved by either reducing the number of lifetime
23+
bounds to one or by making the trait object lifetime explicit, like so:
24+
25+
```
26+
trait Trait { }
27+
28+
struct TwoBounds<'a, 'b, T: Sized + 'a + 'b> {
29+
x: &'a i32,
30+
y: &'b i32,
31+
z: T,
32+
}
33+
34+
type Foo<'a, 'b> = TwoBounds<'a, 'b, dyn Trait + 'b>;
35+
```
36+
37+
For more information, see [RFC 599] and its amendment [RFC 1156].
38+
39+
[RFC 599]: https://github.com/rust-lang/rfcs/blob/master/text/0599-default-object-bound.md
40+
[RFC 1156]: https://github.com/rust-lang/rfcs/blob/master/text/1156-adjust-default-object-bounds.md

‎src/librustc_error_codes/error_codes/E0589.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
The value of `N` that was specified for `repr(align(N))` was not a power
22
of two, or was greater than 2^29.
33

4+
Erroneous code example:
5+
46
```compile_fail,E0589
57
#[repr(align(15))] // error: invalid `repr(align)` attribute: not a power of two
68
enum Foo {

‎src/librustc_incremental/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub mod assert_module_sources;
1515
mod persist;
1616

1717
pub use assert_dep_graph::assert_dep_graph;
18-
pub use persist::copy_cgu_workproducts_to_incr_comp_cache_dir;
18+
pub use persist::copy_cgu_workproduct_to_incr_comp_cache_dir;
1919
pub use persist::delete_workproduct_files;
2020
pub use persist::dep_graph_tcx_init;
2121
pub use persist::finalize_session_directory;

‎src/librustc_incremental/persist/load.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
134134

135135
for swp in work_products {
136136
let mut all_files_exist = true;
137-
for file_name in swp.work_product.saved_files.iter() {
137+
if let Some(ref file_name) = swp.work_product.saved_file {
138138
let path = in_incr_comp_dir_sess(sess, file_name);
139139
if !path.exists() {
140140
all_files_exist = false;

‎src/librustc_incremental/persist/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ pub use load::LoadResult;
2121
pub use load::{load_dep_graph, DepGraphFuture};
2222
pub use save::save_dep_graph;
2323
pub use save::save_work_product_index;
24-
pub use work_product::copy_cgu_workproducts_to_incr_comp_cache_dir;
24+
pub use work_product::copy_cgu_workproduct_to_incr_comp_cache_dir;
2525
pub use work_product::delete_workproduct_files;

‎src/librustc_incremental/persist/save.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ pub fn save_work_product_index(
7474
if !new_work_products.contains_key(id) {
7575
work_product::delete_workproduct_files(sess, wp);
7676
debug_assert!(
77-
wp.saved_files
78-
.iter()
79-
.all(|file_name| { !in_incr_comp_dir_sess(sess, file_name).exists() })
77+
wp.saved_file.as_ref().map_or(true, |file_name| {
78+
!in_incr_comp_dir_sess(sess, &file_name).exists()
79+
})
8080
);
8181
}
8282
}
@@ -85,7 +85,7 @@ pub fn save_work_product_index(
8585
debug_assert!({
8686
new_work_products
8787
.iter()
88-
.flat_map(|(_, wp)| wp.saved_files.iter())
88+
.flat_map(|(_, wp)| wp.saved_file.iter())
8989
.map(|name| in_incr_comp_dir_sess(sess, name))
9090
.all(|path| path.exists())
9191
});

‎src/librustc_incremental/persist/work_product.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,41 @@ use rustc_session::Session;
77
use std::fs as std_fs;
88
use std::path::PathBuf;
99

10-
pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
10+
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
1111
sess: &Session,
1212
cgu_name: &str,
13-
files: &[PathBuf],
13+
path: &Option<PathBuf>,
1414
) -> Option<(WorkProductId, WorkProduct)> {
15-
debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})", cgu_name, files);
15+
debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path);
1616
sess.opts.incremental.as_ref()?;
1717

18-
let saved_files = files
19-
.iter()
20-
.map(|path| {
21-
let file_name = format!("{}.o", cgu_name);
22-
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
23-
match link_or_copy(path, &path_in_incr_dir) {
24-
Ok(_) => Some(file_name),
25-
Err(err) => {
26-
sess.warn(&format!(
27-
"error copying object file `{}` \
28-
to incremental directory as `{}`: {}",
29-
path.display(),
30-
path_in_incr_dir.display(),
31-
err
32-
));
33-
None
34-
}
18+
let saved_file = if let Some(path) = path {
19+
let file_name = format!("{}.o", cgu_name);
20+
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
21+
match link_or_copy(path, &path_in_incr_dir) {
22+
Ok(_) => Some(file_name),
23+
Err(err) => {
24+
sess.warn(&format!(
25+
"error copying object file `{}` to incremental directory as `{}`: {}",
26+
path.display(),
27+
path_in_incr_dir.display(),
28+
err
29+
));
30+
return None;
3531
}
36-
})
37-
.collect::<Option<Vec<_>>>()?;
32+
}
33+
} else {
34+
None
35+
};
3836

39-
let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_files };
37+
let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };
4038

4139
let work_product_id = WorkProductId::from_cgu_name(cgu_name);
4240
Some((work_product_id, work_product))
4341
}
4442

4543
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
46-
for file_name in &work_product.saved_files {
44+
if let Some(ref file_name) = work_product.saved_file {
4745
let path = in_incr_comp_dir_sess(sess, file_name);
4846
match std_fs::remove_file(&path) {
4947
Ok(()) => {}

‎src/librustc_infer/infer/lexical_region_resolve/mod.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,21 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
325325
}
326326
}
327327

328-
debug!("enforce_member_constraint: final least choice = {:?}", least_choice);
329-
if least_choice != member_lower_bound {
328+
// (#72087) Different `ty::Regions` can be known to be equal, for
329+
// example, we know that `'a` and `'static` are equal in a function
330+
// with a parameter of type `&'static &'a ()`.
331+
//
332+
// When we have two equal regions like this `expansion` will use
333+
// `lub_concrete_regions` to pick a canonical representative. The same
334+
// choice is needed here so that we don't end up in a cycle of
335+
// `expansion` changing the region one way and the code here changing
336+
// it back.
337+
let lub = self.lub_concrete_regions(least_choice, member_lower_bound);
338+
debug!(
339+
"enforce_member_constraint: final least choice = {:?}\nlub = {:?}",
340+
least_choice, lub
341+
);
342+
if lub != member_lower_bound {
330343
*var_values.value_mut(member_vid) = VarValue::Value(least_choice);
331344
true
332345
} else {
@@ -578,8 +591,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
578591
self.tcx().mk_region(ReScope(lub))
579592
}
580593

581-
(&ReEarlyBound(_), &ReEarlyBound(_) | &ReFree(_))
582-
| (&ReFree(_), &ReEarlyBound(_) | &ReFree(_)) => {
594+
(&ReEarlyBound(_) | &ReFree(_), &ReEarlyBound(_) | &ReFree(_)) => {
583595
self.region_rels.lub_free_regions(a, b)
584596
}
585597

‎src/librustc_lint/unused.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,27 @@ trait UnusedDelimLint {
380380
);
381381

382382
fn is_expr_delims_necessary(inner: &ast::Expr, followed_by_block: bool) -> bool {
383-
followed_by_block
384-
&& match inner.kind {
385-
ExprKind::Ret(_) | ExprKind::Break(..) => true,
386-
_ => parser::contains_exterior_struct_lit(&inner),
383+
// Prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`
384+
let lhs_needs_parens = {
385+
let mut innermost = inner;
386+
loop {
387+
if let ExprKind::Binary(_, lhs, _rhs) = &innermost.kind {
388+
innermost = lhs;
389+
if !rustc_ast::util::classify::expr_requires_semi_to_be_stmt(innermost) {
390+
break true;
391+
}
392+
} else {
393+
break false;
394+
}
387395
}
396+
};
397+
398+
lhs_needs_parens
399+
|| (followed_by_block
400+
&& match inner.kind {
401+
ExprKind::Ret(_) | ExprKind::Break(..) => true,
402+
_ => parser::contains_exterior_struct_lit(&inner),
403+
})
388404
}
389405

390406
fn emit_unused_delims_expr(

‎src/librustc_middle/ty/adjustment.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::ty::subst::SubstsRef;
22
use crate::ty::{self, Ty, TyCtxt};
33
use rustc_hir as hir;
44
use rustc_hir::def_id::DefId;
5+
use rustc_hir::lang_items::{DerefMutTraitLangItem, DerefTraitLangItem};
56
use rustc_macros::HashStable;
67

78
#[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
@@ -117,11 +118,11 @@ pub struct OverloadedDeref<'tcx> {
117118
impl<'tcx> OverloadedDeref<'tcx> {
118119
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) {
119120
let trait_def_id = match self.mutbl {
120-
hir::Mutability::Not => tcx.lang_items().deref_trait(),
121-
hir::Mutability::Mut => tcx.lang_items().deref_mut_trait(),
121+
hir::Mutability::Not => tcx.require_lang_item(DerefTraitLangItem, None),
122+
hir::Mutability::Mut => tcx.require_lang_item(DerefMutTraitLangItem, None),
122123
};
123124
let method_def_id = tcx
124-
.associated_items(trait_def_id.unwrap())
125+
.associated_items(trait_def_id)
125126
.in_definition_order()
126127
.find(|m| m.kind == ty::AssocKind::Fn)
127128
.unwrap()

‎src/librustc_middle/ty/instance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable};
44
use rustc_errors::ErrorReported;
55
use rustc_hir::def::Namespace;
66
use rustc_hir::def_id::{CrateNum, DefId};
7-
use rustc_hir::lang_items::DropInPlaceFnLangItem;
7+
use rustc_hir::lang_items::{DropInPlaceFnLangItem, FnOnceTraitLangItem};
88
use rustc_macros::HashStable;
99

1010
use std::fmt;
@@ -375,7 +375,7 @@ impl<'tcx> Instance<'tcx> {
375375
substs: ty::SubstsRef<'tcx>,
376376
) -> Instance<'tcx> {
377377
debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, substs);
378-
let fn_once = tcx.lang_items().fn_once_trait().unwrap();
378+
let fn_once = tcx.require_lang_item(FnOnceTraitLangItem, None);
379379
let call_once = tcx
380380
.associated_items(fn_once)
381381
.in_definition_order()

‎src/librustc_middle/ty/layout.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_ast::ast::{self, IntTy, UintTy};
88
use rustc_attr as attr;
99
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1010
use rustc_hir as hir;
11+
use rustc_hir::lang_items::{GeneratorStateLangItem, PinTypeLangItem};
1112
use rustc_index::bit_set::BitSet;
1213
use rustc_index::vec::{Idx, IndexVec};
1314
use rustc_session::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
@@ -2314,13 +2315,13 @@ impl<'tcx> ty::Instance<'tcx> {
23142315
let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
23152316
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
23162317

2317-
let pin_did = tcx.lang_items().pin_type().unwrap();
2318+
let pin_did = tcx.require_lang_item(PinTypeLangItem, None);
23182319
let pin_adt_ref = tcx.adt_def(pin_did);
23192320
let pin_substs = tcx.intern_substs(&[env_ty.into()]);
23202321
let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs);
23212322

23222323
sig.map_bound(|sig| {
2323-
let state_did = tcx.lang_items().gen_state().unwrap();
2324+
let state_did = tcx.require_lang_item(GeneratorStateLangItem, None);
23242325
let state_adt_ref = tcx.adt_def(state_did);
23252326
let state_substs = tcx.intern_substs(&[
23262327
sig.yield_ty.into(),

‎src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_errors::struct_span_err;
1111
use rustc_hir as hir;
1212
use rustc_hir::def_id::{DefId, LocalDefId};
13+
use rustc_hir::lang_items::{CoerceUnsizedTraitLangItem, CopyTraitLangItem, SizedTraitLangItem};
1314
use rustc_index::vec::{Idx, IndexVec};
1415
use rustc_infer::infer::canonical::QueryRegionConstraints;
1516
use rustc_infer::infer::outlives::env::RegionBoundPairs;
@@ -502,7 +503,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
502503
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
503504
let tcx = self.tcx();
504505
let trait_ref = ty::TraitRef {
505-
def_id: tcx.lang_items().copy_trait().unwrap(),
506+
def_id: tcx.require_lang_item(CopyTraitLangItem, Some(self.last_span)),
506507
substs: tcx.mk_substs_trait(place_ty.ty, &[]),
507508
};
508509

@@ -1468,7 +1469,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14681469
self.check_rvalue(body, rv, location);
14691470
if !self.tcx().features().unsized_locals {
14701471
let trait_ref = ty::TraitRef {
1471-
def_id: tcx.lang_items().sized_trait().unwrap(),
1472+
def_id: tcx.require_lang_item(SizedTraitLangItem, Some(self.last_span)),
14721473
substs: tcx.mk_substs_trait(place_ty, &[]),
14731474
};
14741475
self.prove_trait_ref(
@@ -2013,7 +2014,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20132014
ty::Predicate::Trait(
20142015
ty::Binder::bind(ty::TraitPredicate {
20152016
trait_ref: ty::TraitRef::new(
2016-
self.tcx().lang_items().copy_trait().unwrap(),
2017+
self.tcx().require_lang_item(
2018+
CopyTraitLangItem,
2019+
Some(self.last_span),
2020+
),
20172021
tcx.mk_substs_trait(ty, &[]),
20182022
),
20192023
}),
@@ -2037,7 +2041,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20372041
}
20382042

20392043
let trait_ref = ty::TraitRef {
2040-
def_id: tcx.lang_items().sized_trait().unwrap(),
2044+
def_id: tcx.require_lang_item(SizedTraitLangItem, Some(self.last_span)),
20412045
substs: tcx.mk_substs_trait(ty, &[]),
20422046
};
20432047

@@ -2135,7 +2139,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21352139
CastKind::Pointer(PointerCast::Unsize) => {
21362140
let &ty = ty;
21372141
let trait_ref = ty::TraitRef {
2138-
def_id: tcx.lang_items().coerce_unsized_trait().unwrap(),
2142+
def_id: tcx.require_lang_item(
2143+
CoerceUnsizedTraitLangItem,
2144+
Some(self.last_span),
2145+
),
21392146
substs: tcx.mk_substs_trait(op.ty(body, tcx), &[ty.into()]),
21402147
};
21412148

‎src/librustc_mir/monomorphize/collector.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,8 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
580580
}
581581
mir::Rvalue::NullaryOp(mir::NullOp::Box, _) => {
582582
let tcx = self.tcx;
583-
let exchange_malloc_fn_def_id = tcx
584-
.lang_items()
585-
.require(ExchangeMallocFnLangItem)
586-
.unwrap_or_else(|e| tcx.sess.fatal(&e));
583+
let exchange_malloc_fn_def_id =
584+
tcx.require_lang_item(ExchangeMallocFnLangItem, None);
587585
let instance = Instance::mono(tcx, exchange_malloc_fn_def_id);
588586
if should_monomorphize_locally(tcx, &instance) {
589587
self.output.push(create_fn_mono_item(instance));

‎src/librustc_mir/shim.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_hir as hir;
22
use rustc_hir::def_id::DefId;
3+
use rustc_hir::lang_items::FnMutTraitLangItem;
34
use rustc_middle::mir::*;
45
use rustc_middle::ty::query::Providers;
56
use rustc_middle::ty::subst::{InternalSubsts, Subst};
@@ -70,7 +71,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
7071
build_call_shim(tcx, instance, None, CallKind::Direct(def_id), None)
7172
}
7273
ty::InstanceDef::ClosureOnceShim { call_once: _ } => {
73-
let fn_mut = tcx.lang_items().fn_mut_trait().unwrap();
74+
let fn_mut = tcx.require_lang_item(FnMutTraitLangItem, None);
7475
let call_mut = tcx
7576
.associated_items(fn_mut)
7677
.in_definition_order()

‎src/librustc_mir/transform/generator.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use crate::util::storage;
6161
use rustc_data_structures::fx::FxHashMap;
6262
use rustc_hir as hir;
6363
use rustc_hir::def_id::DefId;
64+
use rustc_hir::lang_items::{GeneratorStateLangItem, PinTypeLangItem};
6465
use rustc_index::bit_set::{BitMatrix, BitSet};
6566
use rustc_index::vec::{Idx, IndexVec};
6667
use rustc_middle::mir::visit::{MutVisitor, PlaceContext};
@@ -381,7 +382,7 @@ fn make_generator_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Bo
381382
fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
382383
let ref_gen_ty = body.local_decls.raw[1].ty;
383384

384-
let pin_did = tcx.lang_items().pin_type().unwrap();
385+
let pin_did = tcx.require_lang_item(PinTypeLangItem, Some(body.span));
385386
let pin_adt_ref = tcx.adt_def(pin_did);
386387
let substs = tcx.intern_substs(&[ref_gen_ty.into()]);
387388
let pin_ref_gen_ty = tcx.mk_adt(pin_adt_ref, substs);
@@ -1207,7 +1208,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
12071208
};
12081209

12091210
// Compute GeneratorState<yield_ty, return_ty>
1210-
let state_did = tcx.lang_items().gen_state().unwrap();
1211+
let state_did = tcx.require_lang_item(GeneratorStateLangItem, None);
12111212
let state_adt_ref = tcx.adt_def(state_did);
12121213
let state_substs = tcx.intern_substs(&[yield_ty.into(), body.return_ty().into()]);
12131214
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);

‎src/librustc_mir/util/elaborate_drops.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::util::patch::MirPatch;
22
use rustc_hir as hir;
3-
use rustc_hir::lang_items;
3+
use rustc_hir::lang_items::{BoxFreeFnLangItem, DropTraitLangItem};
44
use rustc_index::vec::Idx;
55
use rustc_middle::mir::*;
66
use rustc_middle::traits::Reveal;
@@ -535,7 +535,7 @@ where
535535
fn destructor_call_block(&mut self, (succ, unwind): (BasicBlock, Unwind)) -> BasicBlock {
536536
debug!("destructor_call_block({:?}, {:?})", self, succ);
537537
let tcx = self.tcx();
538-
let drop_trait = tcx.lang_items().drop_trait().unwrap();
538+
let drop_trait = tcx.require_lang_item(DropTraitLangItem, None);
539539
let drop_fn = tcx.associated_items(drop_trait).in_definition_order().next().unwrap();
540540
let ty = self.place_ty(self.place);
541541
let substs = tcx.mk_substs_trait(ty, &[]);
@@ -877,8 +877,7 @@ where
877877
) -> BasicBlock {
878878
let tcx = self.tcx();
879879
let unit_temp = Place::from(self.new_temp(tcx.mk_unit()));
880-
let free_func =
881-
tcx.require_lang_item(lang_items::BoxFreeFnLangItem, Some(self.source_info.span));
880+
let free_func = tcx.require_lang_item(BoxFreeFnLangItem, Some(self.source_info.span));
882881
let args = adt.variants[VariantIdx::new(0)]
883882
.fields
884883
.iter()

‎src/librustc_mir_build/hair/pattern/const_to_pat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_hir as hir;
2+
use rustc_hir::lang_items::EqTraitLangItem;
23
use rustc_index::vec::Idx;
34
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
45
use rustc_middle::mir::Field;
@@ -140,7 +141,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
140141
// code at the moment, because types like `for <'a> fn(&'a ())` do
141142
// not *yet* implement `PartialEq`. So for now we leave this here.
142143
let ty_is_partial_eq: bool = {
143-
let partial_eq_trait_id = self.tcx().lang_items().eq_trait().unwrap();
144+
let partial_eq_trait_id = self.tcx().require_lang_item(EqTraitLangItem, None);
144145
let obligation: PredicateObligation<'_> = predicate_for_trait_def(
145146
self.tcx(),
146147
self.param_env,

‎src/librustc_query_system/dep_graph/graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,8 @@ impl<K: DepKind> DepGraph<K> {
860860
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
861861
pub struct WorkProduct {
862862
pub cgu_name: String,
863-
/// Saved files associated with this CGU.
864-
pub saved_files: Vec<String>,
863+
/// Saved file associated with this CGU.
864+
pub saved_file: Option<String>,
865865
}
866866

867867
#[derive(Clone)]

‎src/librustc_trait_selection/traits/error_reporting/mod.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
283283
.unwrap_or(false);
284284
let is_from = format!("{}", trait_ref.print_only_trait_path())
285285
.starts_with("std::convert::From<");
286+
let is_unsize =
287+
{ Some(trait_ref.def_id()) == self.tcx.lang_items().unsize_trait() };
286288
let (message, note) = if is_try && is_from {
287289
(
288290
Some(format!(
@@ -405,6 +407,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
405407
return;
406408
}
407409

410+
if is_unsize {
411+
// If the obligation failed due to a missing implementation of the
412+
// `Unsize` trait, give a pointer to why that might be the case
413+
err.note(
414+
"all implementations of `Unsize` are provided \
415+
automatically by the compiler, see \
416+
<https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> \
417+
for more information",
418+
);
419+
}
420+
408421
// Try to report a help message
409422
if !trait_ref.has_infer_types_or_consts()
410423
&& self.predicate_can_apply(obligation.param_env, trait_ref)
@@ -427,12 +440,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
427440
let impl_candidates = self.find_similar_impl_candidates(trait_ref);
428441
self.report_similar_impl_candidates(impl_candidates, &mut err);
429442
}
430-
self.suggest_change_mut(
431-
&obligation,
432-
&mut err,
433-
&trait_ref,
434-
points_at_arg,
435-
);
443+
// Changing mutability doesn't make a difference to whether we have
444+
// an `Unsize` impl (Fixes ICE in #71036)
445+
if !is_unsize {
446+
self.suggest_change_mut(
447+
&obligation,
448+
&mut err,
449+
&trait_ref,
450+
points_at_arg,
451+
);
452+
}
436453
}
437454

438455
// If this error is due to `!: Trait` not implemented but `(): Trait` is

‎src/librustc_trait_selection/traits/project.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::traits::error_reporting::InferCtxtExt;
2020
use rustc_data_structures::stack::ensure_sufficient_stack;
2121
use rustc_errors::ErrorReported;
2222
use rustc_hir::def_id::DefId;
23+
use rustc_hir::lang_items::{FnOnceTraitLangItem, GeneratorTraitLangItem};
2324
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
2425
use rustc_middle::ty::subst::{InternalSubsts, Subst};
2526
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, WithConstness};
@@ -1222,7 +1223,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
12221223

12231224
let tcx = selcx.tcx();
12241225

1225-
let gen_def_id = tcx.lang_items().gen_trait().unwrap();
1226+
let gen_def_id = tcx.require_lang_item(GeneratorTraitLangItem, None);
12261227

12271228
let predicate = super::util::generator_trait_ref_and_outputs(
12281229
tcx,
@@ -1309,7 +1310,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
13091310
debug!("confirm_callable_candidate({:?},{:?})", obligation, fn_sig);
13101311

13111312
// the `Output` associated type is declared on `FnOnce`
1312-
let fn_once_def_id = tcx.lang_items().fn_once_trait().unwrap();
1313+
let fn_once_def_id = tcx.require_lang_item(FnOnceTraitLangItem, None);
13131314

13141315
let predicate = super::util::closure_trait_ref_and_return_type(
13151316
tcx,

‎src/librustc_typeck/check/demand.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_trait_selection::traits::{self, ObligationCause};
77
use rustc_ast::util::parser::PREC_POSTFIX;
88
use rustc_errors::{Applicability, DiagnosticBuilder};
99
use rustc_hir as hir;
10+
use rustc_hir::lang_items::DerefTraitLangItem;
1011
use rustc_hir::{is_range_literal, Node};
1112
use rustc_middle::ty::adjustment::AllowTwoPhase;
1213
use rustc_middle::ty::{self, AssocItem, Ty, TypeAndMut};
@@ -634,7 +635,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
634635
_ if sp == expr.span && !is_macro => {
635636
// Check for `Deref` implementations by constructing a predicate to
636637
// prove: `<T as Deref>::Output == U`
637-
let deref_trait = self.tcx.lang_items().deref_trait().unwrap();
638+
let deref_trait = self.tcx.require_lang_item(DerefTraitLangItem, Some(expr.span));
638639
let item_def_id = self
639640
.tcx
640641
.associated_items(deref_trait)

‎src/libstd/thread/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ pub fn panicking() -> bool {
737737
/// The thread may sleep longer than the duration specified due to scheduling
738738
/// specifics or platform-dependent functionality. It will never sleep less.
739739
///
740+
/// This function is blocking, and should not be used in `async` functions.
741+
///
740742
/// # Platform-specific behavior
741743
///
742744
/// On Unix platforms, the underlying syscall may be interrupted by a
@@ -763,6 +765,8 @@ pub fn sleep_ms(ms: u32) {
763765
/// The thread may sleep longer than the duration specified due to scheduling
764766
/// specifics or platform-dependent functionality. It will never sleep less.
765767
///
768+
/// This function is blocking, and should not be used in `async` functions.
769+
///
766770
/// # Platform-specific behavior
767771
///
768772
/// On Unix platforms, the underlying syscall may be interrupted by a

‎src/test/ui/issues/issue-71036.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(unsize, dispatch_from_dyn)]
2+
3+
use std::marker::Unsize;
4+
use std::ops::DispatchFromDyn;
5+
6+
#[allow(unused)]
7+
struct Foo<'a, T: ?Sized> {
8+
_inner: &'a &'a T,
9+
}
10+
11+
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Foo<'a, U>> for Foo<'a, T> {}
12+
//~^ ERROR the trait bound `&'a T: std::marker::Unsize<&'a U>` is not satisfied
13+
//~| NOTE the trait `std::marker::Unsize<&'a U>` is not implemented for `&'a T`
14+
//~| NOTE all implementations of `Unsize` are provided automatically by the compiler
15+
//~| NOTE required because of the requirements on the impl
16+
17+
fn main() {}

‎src/test/ui/issues/issue-71036.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the trait bound `&'a T: std::marker::Unsize<&'a U>` is not satisfied
2+
--> $DIR/issue-71036.rs:11:1
3+
|
4+
LL | impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Foo<'a, U>> for Foo<'a, T> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unsize<&'a U>` is not implemented for `&'a T`
6+
|
7+
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
8+
= note: required because of the requirements on the impl of `std::ops::DispatchFromDyn<&'a &'a U>` for `&'a &'a T`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// check-pass
2+
// Make sure unused parens lint doesn't emit a false positive.
3+
// See https://github.com/rust-lang/rust/issues/71290 for details.
4+
#![deny(unused_parens)]
5+
6+
fn x() -> u8 {
7+
({ 0 }) + 1
8+
}
9+
10+
fn y() -> u8 {
11+
({ 0 } + 1)
12+
}
13+
14+
pub fn foo(a: bool, b: bool) -> u8 {
15+
(if a { 1 } else { 0 } + if b { 1 } else { 0 })
16+
}
17+
18+
pub fn bar() -> u8 {
19+
// Make sure nested expressions are handled correctly as well
20+
({ 0 } + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9)
21+
}
22+
23+
fn main() {}

‎src/test/ui/object-lifetime/object-lifetime-default-ambiguous.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ LL | fn f(t: &Ref2<dyn Test>) {
1818

1919
error: aborting due to 3 previous errors
2020

21+
For more information about this error, try `rustc --explain E0228`.

‎src/test/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic1.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | fn bar<'a>(x: &'a str) -> &'a dyn Foo<'a, Item = dyn Bar> { &() }
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0228`.

‎src/test/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic2.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | fn bar<'a>(x: &'a str) -> &'a dyn Foo<'a, Item = dyn Bar> { &() }
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0228`.

‎src/test/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic3.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | fn bar(x: &str) -> &dyn Foo<Item = dyn Bar> { &() }
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0228`.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Regression test for #72051, hang when resolving regions.
2+
3+
// check-pass
4+
// edition:2018
5+
6+
pub async fn query<'a>(_: &(), _: &(), _: (&(dyn std::any::Any + 'a),) ) {}
7+
fn main() {}

‎src/test/ui/suggestions/missing-lifetime-specifier.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,5 +252,5 @@ LL | static f: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, i32>>>>> = RefCell
252252

253253
error: aborting due to 28 previous errors
254254

255-
Some errors have detailed explanations: E0106, E0107.
255+
Some errors have detailed explanations: E0106, E0107, E0228.
256256
For more information about an error, try `rustc --explain E0106`.

‎src/test/ui/underscore-lifetime/dyn-trait-underscore-in-struct.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ LL | x: Box<dyn Debug + '_>,
1818

1919
error: aborting due to 2 previous errors
2020

21-
For more information about this error, try `rustc --explain E0106`.
21+
Some errors have detailed explanations: E0106, E0228.
22+
For more information about an error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)
Please sign in to comment.