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

Rollup of 9 pull requests #99462

Merged
merged 23 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6d2bd54
use body's param-env when checking if type needs drop
compiler-errors Jul 17, 2022
a22934b
avoid `Symbol` to `&str` conversions
TaKO8Ki Jul 18, 2022
454313f
stabilize `core::task::ready!`
yoshuawuyts Jul 18, 2022
37c21d6
Do not suggest "wrapping the expression in `std::num::NonZeroU64`"
WaffleLapkin Jul 18, 2022
c0569f2
Revert "Stabilize $$ in Rust 1.63.0"
CAD97 Jul 18, 2022
7163e7f
Suggest a fix for `NonZero*` <- `*` coercion error
WaffleLapkin Jul 18, 2022
da2752e
check accessibility before suggesting wrapping expressions
WaffleLapkin Jul 18, 2022
821e9d5
Update mdbook
ehuss Jul 18, 2022
2edad7d
Apply suggestions from the review
WaffleLapkin Jul 18, 2022
5bd88df
Add a note about privacy to wrapping suggestion
WaffleLapkin Jul 18, 2022
959c215
:arrow_up: rust-analyzer
lnicola Jul 19, 2022
1cbacc0
Add E0790 as more specific variant of E0283
aticu Jun 12, 2022
38ea235
Don't use main; improve example
aticu Jun 13, 2022
e2ecb68
use `par_for_each_in` in `par_body_owners` and `collect_crate_mono_it…
SparrowLii Jul 19, 2022
bfefd58
Rollup merge of #98028 - aticu:master, r=estebank
matthiaskrgr Jul 19, 2022
3147392
Rollup merge of #99384 - compiler-errors:issue-99375, r=oli-obk
matthiaskrgr Jul 19, 2022
4815f94
Rollup merge of #99401 - TaKO8Ki:avoid-symbol-to-&str-conversions, r=…
matthiaskrgr Jul 19, 2022
7d75497
Rollup merge of #99419 - yoshuawuyts:stabilize-task-ready, r=Mark-Sim…
matthiaskrgr Jul 19, 2022
19932a5
Rollup merge of #99435 - CAD97:revert-dollar-dollar-crate, r=Mark-Sim…
matthiaskrgr Jul 19, 2022
e6a100b
Rollup merge of #99438 - WaffleLapkin:dont_wrap_in_non_zero, r=compil…
matthiaskrgr Jul 19, 2022
fae3e3a
Rollup merge of #99441 - ehuss:update-mdbook, r=Mark-Simulacrum
matthiaskrgr Jul 19, 2022
ae90a8f
Rollup merge of #99453 - lnicola:rust-analyzer-2022-07-19, r=lnicola
matthiaskrgr Jul 19, 2022
e6904fc
Rollup merge of #99457 - SparrowLii:para_iter, r=fee1-dead
matthiaskrgr Jul 19, 2022
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
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