Skip to content

Commit a74d186

Browse files
committed
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

+5-9
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

+1-1
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
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

+2
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

+1-1
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

+1-1
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

+1-1
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

+4-4
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

+22-24
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

+16-4
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

+20-4
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

+4-3
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

+2-2
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

+3-2
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(),

0 commit comments

Comments
 (0)