Skip to content

Commit

Permalink
Auto merge of rust-lang#99462 - matthiaskrgr:rollup-ihhwaru, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#98028 (Add E0790 as more specific variant of E0283)
 - rust-lang#99384 (use body's param-env when checking if type needs drop)
 - rust-lang#99401 (Avoid `Symbol` to `&str` conversions)
 - rust-lang#99419 (Stabilize `core::task::ready!`)
 - rust-lang#99435 (Revert "Stabilize $$ in Rust 1.63.0")
 - rust-lang#99438 (Improve suggestions for `NonZeroT` <- `T` coercion error)
 - rust-lang#99441 (Update mdbook)
 - rust-lang#99453 (:arrow_up: rust-analyzer)
 - rust-lang#99457 (use `par_for_each_in` in `par_body_owners` and `collect_crate_mono_items`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 19, 2022
2 parents 8bd12e8 + e6904fc commit a289cfc
Show file tree
Hide file tree
Showing 55 changed files with 705 additions and 204 deletions.
45 changes: 7 additions & 38 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ version = "3.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c11d40217d16aee8508cc8e5fde8b4ff24639758608e5374e731b53f85749fb9"
dependencies = [
"heck 0.4.0",
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
Expand Down Expand Up @@ -1202,17 +1202,14 @@ checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f"

[[package]]
name = "elasticlunr-rs"
version = "2.3.9"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35622eb004c8f0c5e7e2032815f3314a93df0db30a1ce5c94e62c1ecc81e22b9"
checksum = "e6dae5cac90640734ee881bc5f21b6e5123f4e5235e52428db114abffc2391d6"
dependencies = [
"lazy_static",
"regex",
"serde",
"serde_derive",
"serde_json",
"strum",
"strum_macros",
]

[[package]]
Expand Down Expand Up @@ -1735,15 +1732,6 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
dependencies = [
"unicode-segmentation",
]

[[package]]
name = "heck"
version = "0.4.0"
Expand Down Expand Up @@ -2360,17 +2348,17 @@ dependencies = [

[[package]]
name = "mdbook"
version = "0.4.18"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74612ae81a3e5ee509854049dfa4c7975ae033c06f5fc4735c7dfbe60ee2a39d"
checksum = "13cdad8057b09a519c6c63e6d7c93ea854f5d7fbfe284df864d5e1140d215a2d"
dependencies = [
"ammonia",
"anyhow",
"chrono",
"clap",
"clap_complete",
"elasticlunr-rs",
"env_logger 0.7.1",
"env_logger 0.9.0",
"handlebars",
"lazy_static",
"log",
Expand All @@ -2379,7 +2367,6 @@ dependencies = [
"pulldown-cmark",
"regex",
"serde",
"serde_derive",
"serde_json",
"shlex",
"tempfile",
Expand Down Expand Up @@ -3335,7 +3322,7 @@ dependencies = [
"difference",
"env_logger 0.9.0",
"futures 0.3.19",
"heck 0.4.0",
"heck",
"home",
"itertools",
"jsonrpc-core",
Expand Down Expand Up @@ -5134,24 +5121,6 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"

[[package]]
name = "strum"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57bd81eb48f4c437cadc685403cad539345bf703d78e63707418431cecd4522b"

[[package]]
name = "strum_macros"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c"
dependencies = [
"heck 0.3.1",
"proc-macro2",
"quote",
"syn",
]

[[package]]
name = "syn"
version = "1.0.91"
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
InlineAsmRegOrRegClass::Reg(s) => {
asm::InlineAsmRegOrRegClass::Reg(if let Some(asm_arch) = asm_arch {
asm::InlineAsmReg::parse(asm_arch, s).unwrap_or_else(|e| {
let msg = format!("invalid register `{}`: {}", s.as_str(), e);
let msg = format!("invalid register `{}`: {}", s, e);
sess.struct_span_err(*op_sp, &msg).emit();
asm::InlineAsmReg::Err
})
Expand All @@ -156,7 +156,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
InlineAsmRegOrRegClass::RegClass(s) => {
asm::InlineAsmRegOrRegClass::RegClass(if let Some(asm_arch) = asm_arch {
asm::InlineAsmRegClass::parse(asm_arch, s).unwrap_or_else(|e| {
let msg = format!("invalid register class `{}`: {}", s.as_str(), e);
let msg = format!("invalid register class `{}`: {}", s, e);
sess.struct_span_err(*op_sp, &msg).emit();
asm::InlineAsmRegClass::Err
})
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ impl<'a> PostExpansionVisitor<'a> {
let ast::StrLit { symbol_unescaped, span, .. } = abi;

if let ast::Const::Yes(_) = constness {
match symbol_unescaped.as_str() {
match symbol_unescaped {
// Stable
"Rust" | "C" => {}
sym::Rust | sym::C => {}
abi => gate_feature_post!(
&self,
const_extern_fn,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global<'ll>(cx: &CodegenCx<'ll, '
// The initial byte `4` instructs GDB that the following pretty printer
// is defined inline as opposed to in a standalone file.
section_contents.extend_from_slice(b"\x04");
let vis_name = format!("pretty-printer-{}-{}\n", crate_name.as_str(), index);
let vis_name = format!("pretty-printer-{}-{}\n", crate_name, index);
section_contents.extend_from_slice(vis_name.as_bytes());
section_contents.extend_from_slice(&visualizer.src);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ cfg_if! {
t.into_iter()
}

pub fn par_for_each_in<T: IntoIterator>(t: T, for_each: impl Fn(T::Item) + Sync + Send) {
pub fn par_for_each_in<T: IntoIterator>(t: T, mut for_each: impl FnMut(T::Item) + Sync + Send) {
// We catch panics here ensuring that all the loop iterations execute.
// This makes behavior consistent with the parallel compiler.
let mut panic = None;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ E0785: include_str!("./error_codes/E0785.md"),
E0786: include_str!("./error_codes/E0786.md"),
E0787: include_str!("./error_codes/E0787.md"),
E0788: include_str!("./error_codes/E0788.md"),
E0790: include_str!("./error_codes/E0790.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
Expand Down
45 changes: 12 additions & 33 deletions compiler/rustc_error_codes/src/error_codes/E0283.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,27 @@ An implementation cannot be chosen unambiguously because of lack of information.
Erroneous code example:

```compile_fail,E0283
trait Generator {
fn create() -> u32;
}
struct Impl;
impl Generator for Impl {
fn create() -> u32 { 1 }
}
struct AnotherImpl;
struct Foo;
impl Generator for AnotherImpl {
fn create() -> u32 { 2 }
impl Into<u32> for Foo {
fn into(self) -> u32 { 1 }
}
fn main() {
let cont: u32 = Generator::create();
// error, impossible to choose one of Generator trait implementation
// Should it be Impl or AnotherImpl, maybe something else?
}
let foo = Foo;
let bar: u32 = foo.into() * 1u32;
```

This error can be solved by adding type annotations that provide the missing
information to the compiler. In this case, the solution is to use a concrete
type:
information to the compiler. In this case, the solution is to specify the
trait's type parameter:

```
trait Generator {
fn create() -> u32;
}
struct AnotherImpl;
struct Foo;
impl Generator for AnotherImpl {
fn create() -> u32 { 2 }
impl Into<u32> for Foo {
fn into(self) -> u32 { 1 }
}
fn main() {
let gen1 = AnotherImpl::create();
// if there are multiple methods with same name (different traits)
let gen2 = <AnotherImpl as Generator>::create();
}
let foo = Foo;
let bar: u32 = Into::<u32>::into(foo) * 1u32;
```
47 changes: 47 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0790.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
You need to specify a specific implementation of the trait in order to call the
method.

Erroneous code example:

```compile_fail,E0790
trait Generator {
fn create() -> u32;
}
struct Impl;
impl Generator for Impl {
fn create() -> u32 { 1 }
}
struct AnotherImpl;
impl Generator for AnotherImpl {
fn create() -> u32 { 2 }
}
let cont: u32 = Generator::create();
// error, impossible to choose one of Generator trait implementation
// Should it be Impl or AnotherImpl, maybe something else?
```

This error can be solved by adding type annotations that provide the missing
information to the compiler. In this case, the solution is to use a concrete
type:

```
trait Generator {
fn create() -> u32;
}
struct AnotherImpl;
impl Generator for AnotherImpl {
fn create() -> u32 { 2 }
}
let gen1 = AnotherImpl::create();
// if there are multiple methods with same name (different traits)
let gen2 = <AnotherImpl as Generator>::create();
```
2 changes: 2 additions & 0 deletions compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ fn parse_tree(
sess,
&Token { kind: token::Dollar, span },
);
} else {
maybe_emit_macro_metavar_expr_feature(features, sess, span);
}
TokenTree::token(token::Dollar, span)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub fn suggest_adding_lifetime_params<'tcx>(
if is_impl {
sugg.push_str(" and update trait if needed");
}
err.multipart_suggestion(sugg.as_str(), suggestions, Applicability::MaybeIncorrect);
err.multipart_suggestion(sugg, suggestions, Applicability::MaybeIncorrect);

true
}
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,7 @@ impl<'hir> Map<'hir> {
}

pub fn par_body_owners<F: Fn(LocalDefId) + Sync + Send>(self, f: F) {
use rustc_data_structures::sync::{par_iter, ParallelIterator};

par_iter(&self.tcx.hir_crate_items(()).body_owners[..]).for_each(|&def_id| f(def_id));
par_for_each_in(&self.tcx.hir_crate_items(()).body_owners[..], |&def_id| f(def_id));
}

pub fn ty_param_owner(self, def_id: LocalDefId) -> LocalDefId {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/trait_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ impl TraitImpls {
pub fn blanket_impls(&self) -> &[DefId] {
self.blanket_impls.as_slice()
}

pub fn non_blanket_impls(&self) -> &FxIndexMap<SimplifiedType, Vec<DefId>> {
&self.non_blanket_impls
}
}

impl<'tcx> TraitDef {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
let lhs = &self.thir[lhs];
if let ty::Adt(adt_def, _) = lhs.ty.kind() && adt_def.is_union() {
if let Some((assigned_ty, assignment_span)) = self.assignment_info {
if assigned_ty.needs_drop(self.tcx, self.tcx.param_env(adt_def.did())) {
if assigned_ty.needs_drop(self.tcx, self.param_env) {
// This would be unsafe, but should be outright impossible since we reject such unions.
self.tcx.sess.delay_span_bug(assignment_span, "union fields that need dropping should be impossible");
self.tcx.sess.delay_span_bug(assignment_span, format!("union fields that need dropping should be impossible: {assigned_ty}"));
}
} else {
self.requires_unsafe(expr.span, AccessToUnionField);
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_mir_transform/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,11 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
// We have to check the actual type of the assignment, as that determines if the
// old value is being dropped.
let assigned_ty = place.ty(&self.body.local_decls, self.tcx).ty;
if assigned_ty.needs_drop(
self.tcx,
self.tcx.param_env(base_ty.ty_adt_def().unwrap().did()),
) {
if assigned_ty.needs_drop(self.tcx, self.param_env) {
// This would be unsafe, but should be outright impossible since we reject such unions.
self.tcx.sess.delay_span_bug(
self.source_info.span,
"union fields that need dropping should be impossible",
format!("union fields that need dropping should be impossible: {assigned_ty}")
);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
//! regardless of whether it is actually needed or not.

use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator};
use rustc_data_structures::sync::{par_for_each_in, MTLock, MTRef};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
Expand Down Expand Up @@ -346,7 +346,7 @@ pub fn collect_crate_mono_items(
let inlining_map: MTRef<'_, _> = &mut inlining_map;

tcx.sess.time("monomorphization_collector_graph_walk", || {
par_iter(roots).for_each(|root| {
par_for_each_in(roots, |root| {
let mut recursion_depths = DefIdMap::default();
collect_items_rec(
tcx,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn err_if_attr_found(ctxt: &EntryContext<'_>, attrs: &[Attribute], sym: Symbol)
.sess
.struct_span_err(
attr.span,
&format!("`{}` attribute can only be used on functions", sym.as_str()),
&format!("`{}` attribute can only be used on functions", sym),
)
.emit();
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ impl<'a> Resolver<'a> {
"{}{} `{}` defined here",
prefix,
suggestion.res.descr(),
suggestion.candidate.as_str(),
suggestion.candidate,
),
);
}
Expand Down
Loading

0 comments on commit a289cfc

Please sign in to comment.