Skip to content

Commit

Permalink
Auto merge of #72202 - Dylan-DPC:rollup-6lbxh1s, r=Dylan-DPC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 14, 2020
2 parents af6d886 + 7b5bc61 commit a74d186
Show file tree
Hide file tree
Showing 35 changed files with 246 additions and 86 deletions.
14 changes: 5 additions & 9 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_errors::{DiagnosticId, FatalError, Handler, Level};
use rustc_fs_util::link_or_copy;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_incremental::{
copy_cgu_workproducts_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
};
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::EncodedMetadata;
Expand Down Expand Up @@ -465,17 +465,13 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
return work_products;
}

let _timer = sess.timer("incr_comp_copy_cgu_workproducts");
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");

for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
let mut files = vec![];

if let Some(ref path) = module.object {
files.push(path.clone());
}
let path = module.object.as_ref().map(|path| path.clone());

if let Some((id, product)) =
copy_cgu_workproducts_to_incr_comp_cache_dir(sess, &module.name, &files)
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, &path)
{
work_products.insert(id, product);
}
Expand Down Expand Up @@ -817,7 +813,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
) -> Result<WorkItemResult<B>, FatalError> {
let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap();
let mut object = None;
for saved_file in &module.source.saved_files {
if let Some(saved_file) = module.source.saved_file {
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name));
object = Some(obj_out.clone());
let source_file = in_incr_comp_dir(&incr_comp_session_dir, &saved_file);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ E0223: include_str!("./error_codes/E0223.md"),
E0224: include_str!("./error_codes/E0224.md"),
E0225: include_str!("./error_codes/E0225.md"),
E0226: include_str!("./error_codes/E0226.md"),
E0228: include_str!("./error_codes/E0228.md"),
E0229: include_str!("./error_codes/E0229.md"),
E0230: include_str!("./error_codes/E0230.md"),
E0231: include_str!("./error_codes/E0231.md"),
Expand Down Expand Up @@ -482,7 +483,6 @@ E0753: include_str!("./error_codes/E0753.md"),
// E0218, // no associated type defined
// E0219, // associated type defined in higher-ranked supertrait
E0227, // ambiguous lifetime bound, explicit lifetime bound required
E0228, // explicit lifetime bound required
// E0233,
// E0234,
// E0235, // structure constructor specifies a structure of type but
Expand Down
40 changes: 40 additions & 0 deletions src/librustc_error_codes/error_codes/E0228.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
The lifetime bound for this object type cannot be deduced from context and must
be specified.

Erroneous code example:

```compile_fail,E0228
trait Trait { }
struct TwoBounds<'a, 'b, T: Sized + 'a + 'b> {
x: &'a i32,
y: &'b i32,
z: T,
}
type Foo<'a, 'b> = TwoBounds<'a, 'b, dyn Trait>;
```

When a trait object is used as a type argument of a generic type, Rust will try
to infer its lifetime if unspecified. However, this isn't possible when the
containing type has more than one lifetime bound.

The above example can be resolved by either reducing the number of lifetime
bounds to one or by making the trait object lifetime explicit, like so:

```
trait Trait { }
struct TwoBounds<'a, 'b, T: Sized + 'a + 'b> {
x: &'a i32,
y: &'b i32,
z: T,
}
type Foo<'a, 'b> = TwoBounds<'a, 'b, dyn Trait + 'b>;
```

For more information, see [RFC 599] and its amendment [RFC 1156].

[RFC 599]: https://github.com/rust-lang/rfcs/blob/master/text/0599-default-object-bound.md
[RFC 1156]: https://github.com/rust-lang/rfcs/blob/master/text/1156-adjust-default-object-bounds.md
2 changes: 2 additions & 0 deletions src/librustc_error_codes/error_codes/E0589.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
The value of `N` that was specified for `repr(align(N))` was not a power
of two, or was greater than 2^29.

Erroneous code example:

```compile_fail,E0589
#[repr(align(15))] // error: invalid `repr(align)` attribute: not a power of two
enum Foo {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod assert_module_sources;
mod persist;

pub use assert_dep_graph::assert_dep_graph;
pub use persist::copy_cgu_workproducts_to_incr_comp_cache_dir;
pub use persist::copy_cgu_workproduct_to_incr_comp_cache_dir;
pub use persist::delete_workproduct_files;
pub use persist::dep_graph_tcx_init;
pub use persist::finalize_session_directory;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {

for swp in work_products {
let mut all_files_exist = true;
for file_name in swp.work_product.saved_files.iter() {
if let Some(ref file_name) = swp.work_product.saved_file {
let path = in_incr_comp_dir_sess(sess, file_name);
if !path.exists() {
all_files_exist = false;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ pub use load::LoadResult;
pub use load::{load_dep_graph, DepGraphFuture};
pub use save::save_dep_graph;
pub use save::save_work_product_index;
pub use work_product::copy_cgu_workproducts_to_incr_comp_cache_dir;
pub use work_product::copy_cgu_workproduct_to_incr_comp_cache_dir;
pub use work_product::delete_workproduct_files;
8 changes: 4 additions & 4 deletions src/librustc_incremental/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ pub fn save_work_product_index(
if !new_work_products.contains_key(id) {
work_product::delete_workproduct_files(sess, wp);
debug_assert!(
wp.saved_files
.iter()
.all(|file_name| { !in_incr_comp_dir_sess(sess, file_name).exists() })
wp.saved_file.as_ref().map_or(true, |file_name| {
!in_incr_comp_dir_sess(sess, &file_name).exists()
})
);
}
}
Expand All @@ -85,7 +85,7 @@ pub fn save_work_product_index(
debug_assert!({
new_work_products
.iter()
.flat_map(|(_, wp)| wp.saved_files.iter())
.flat_map(|(_, wp)| wp.saved_file.iter())
.map(|name| in_incr_comp_dir_sess(sess, name))
.all(|path| path.exists())
});
Expand Down
46 changes: 22 additions & 24 deletions src/librustc_incremental/persist/work_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,41 @@ use rustc_session::Session;
use std::fs as std_fs;
use std::path::PathBuf;

pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
sess: &Session,
cgu_name: &str,
files: &[PathBuf],
path: &Option<PathBuf>,
) -> Option<(WorkProductId, WorkProduct)> {
debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})", cgu_name, files);
debug!("copy_cgu_workproduct_to_incr_comp_cache_dir({:?},{:?})", cgu_name, path);
sess.opts.incremental.as_ref()?;

let saved_files = files
.iter()
.map(|path| {
let file_name = format!("{}.o", cgu_name);
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
match link_or_copy(path, &path_in_incr_dir) {
Ok(_) => Some(file_name),
Err(err) => {
sess.warn(&format!(
"error copying object file `{}` \
to incremental directory as `{}`: {}",
path.display(),
path_in_incr_dir.display(),
err
));
None
}
let saved_file = if let Some(path) = path {
let file_name = format!("{}.o", cgu_name);
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);
match link_or_copy(path, &path_in_incr_dir) {
Ok(_) => Some(file_name),
Err(err) => {
sess.warn(&format!(
"error copying object file `{}` to incremental directory as `{}`: {}",
path.display(),
path_in_incr_dir.display(),
err
));
return None;
}
})
.collect::<Option<Vec<_>>>()?;
}
} else {
None
};

let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_files };
let work_product = WorkProduct { cgu_name: cgu_name.to_string(), saved_file };

let work_product_id = WorkProductId::from_cgu_name(cgu_name);
Some((work_product_id, work_product))
}

pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
for file_name in &work_product.saved_files {
if let Some(ref file_name) = work_product.saved_file {
let path = in_incr_comp_dir_sess(sess, file_name);
match std_fs::remove_file(&path) {
Ok(()) => {}
Expand Down
20 changes: 16 additions & 4 deletions src/librustc_infer/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,21 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
}
}

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

(&ReEarlyBound(_), &ReEarlyBound(_) | &ReFree(_))
| (&ReFree(_), &ReEarlyBound(_) | &ReFree(_)) => {
(&ReEarlyBound(_) | &ReFree(_), &ReEarlyBound(_) | &ReFree(_)) => {
self.region_rels.lub_free_regions(a, b)
}

Expand Down
24 changes: 20 additions & 4 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,27 @@ trait UnusedDelimLint {
);

fn is_expr_delims_necessary(inner: &ast::Expr, followed_by_block: bool) -> bool {
followed_by_block
&& match inner.kind {
ExprKind::Ret(_) | ExprKind::Break(..) => true,
_ => parser::contains_exterior_struct_lit(&inner),
// Prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`
let lhs_needs_parens = {
let mut innermost = inner;
loop {
if let ExprKind::Binary(_, lhs, _rhs) = &innermost.kind {
innermost = lhs;
if !rustc_ast::util::classify::expr_requires_semi_to_be_stmt(innermost) {
break true;
}
} else {
break false;
}
}
};

lhs_needs_parens
|| (followed_by_block
&& match inner.kind {
ExprKind::Ret(_) | ExprKind::Break(..) => true,
_ => parser::contains_exterior_struct_lit(&inner),
})
}

fn emit_unused_delims_expr(
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_middle/ty/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::ty::subst::SubstsRef;
use crate::ty::{self, Ty, TyCtxt};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::{DerefMutTraitLangItem, DerefTraitLangItem};
use rustc_macros::HashStable;

#[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
Expand Down Expand Up @@ -117,11 +118,11 @@ pub struct OverloadedDeref<'tcx> {
impl<'tcx> OverloadedDeref<'tcx> {
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) {
let trait_def_id = match self.mutbl {
hir::Mutability::Not => tcx.lang_items().deref_trait(),
hir::Mutability::Mut => tcx.lang_items().deref_mut_trait(),
hir::Mutability::Not => tcx.require_lang_item(DerefTraitLangItem, None),
hir::Mutability::Mut => tcx.require_lang_item(DerefMutTraitLangItem, None),
};
let method_def_id = tcx
.associated_items(trait_def_id.unwrap())
.associated_items(trait_def_id)
.in_definition_order()
.find(|m| m.kind == ty::AssocKind::Fn)
.unwrap()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable};
use rustc_errors::ErrorReported;
use rustc_hir::def::Namespace;
use rustc_hir::def_id::{CrateNum, DefId};
use rustc_hir::lang_items::DropInPlaceFnLangItem;
use rustc_hir::lang_items::{DropInPlaceFnLangItem, FnOnceTraitLangItem};
use rustc_macros::HashStable;

use std::fmt;
Expand Down Expand Up @@ -375,7 +375,7 @@ impl<'tcx> Instance<'tcx> {
substs: ty::SubstsRef<'tcx>,
) -> Instance<'tcx> {
debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, substs);
let fn_once = tcx.lang_items().fn_once_trait().unwrap();
let fn_once = tcx.require_lang_item(FnOnceTraitLangItem, None);
let call_once = tcx
.associated_items(fn_once)
.in_definition_order()
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_middle/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_ast::ast::{self, IntTy, UintTy};
use rustc_attr as attr;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir as hir;
use rustc_hir::lang_items::{GeneratorStateLangItem, PinTypeLangItem};
use rustc_index::bit_set::BitSet;
use rustc_index::vec::{Idx, IndexVec};
use rustc_session::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
Expand Down Expand Up @@ -2314,13 +2315,13 @@ impl<'tcx> ty::Instance<'tcx> {
let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);

let pin_did = tcx.lang_items().pin_type().unwrap();
let pin_did = tcx.require_lang_item(PinTypeLangItem, None);
let pin_adt_ref = tcx.adt_def(pin_did);
let pin_substs = tcx.intern_substs(&[env_ty.into()]);
let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs);

sig.map_bound(|sig| {
let state_did = tcx.lang_items().gen_state().unwrap();
let state_did = tcx.require_lang_item(GeneratorStateLangItem, None);
let state_adt_ref = tcx.adt_def(state_did);
let state_substs = tcx.intern_substs(&[
sig.yield_ty.into(),
Expand Down
Loading

0 comments on commit a74d186

Please sign in to comment.