diff options
| author | bors <bors@rust-lang.org> | 2022-04-16 14:24:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-04-16 14:24:14 +0000 |
| commit | d9b3ff7d34335c5bc0b2afed640b65d64a85fe03 (patch) | |
| tree | 5e6cfdb26695ef535ca98195430c9f1ddbebede8 /compiler | |
| parent | febce1fc316f5618d5bb8f05d19e2e3ba868c007 (diff) | |
| parent | 4ed76271170ed781f0fc079ead9a5997a96f984f (diff) | |
| download | rust-d9b3ff7d34335c5bc0b2afed640b65d64a85fe03.tar.gz rust-d9b3ff7d34335c5bc0b2afed640b65d64a85fe03.zip | |
Auto merge of #96117 - Dylan-DPC:rollup-5traczf, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #95887 (resolve: Create dummy bindings for all unresolved imports) - #96023 (couple of clippy::perf fixes) - #96035 (Update GitHub Actions actions/checkout Version v2 -> v3) - #96038 (docs: add link from zip to unzip) - #96047 (:arrow_up: rust-analyzer) - #96059 (clarify doc(cfg) wording) - #96081 (Make some `usize`-typed masks definitions agnostic to the size of `usize`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler')
6 files changed, 33 insertions, 36 deletions
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 31bb9ed3185..d6e2c8ccdf4 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -372,7 +372,6 @@ fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>( // Build the type node for each field. let variant_field_infos: SmallVec<VariantFieldInfo<'ll>> = variant_range - .clone() .map(|variant_index| { let variant_struct_type_di_node = super::build_generator_variant_struct_type_di_node( cx, diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index cfad1fc01ab..416bc4e2e3b 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1208,7 +1208,7 @@ impl HandlerInner { (0, 0) => return, (0, _) => self.emitter.emit_diagnostic(&Diagnostic::new( Level::Warning, - DiagnosticMessage::Str(warnings.to_owned()), + DiagnosticMessage::Str(warnings), )), (_, 0) => { let _ = self.fatal(&errors); diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 63aac64989d..8f260e1cdb5 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -590,7 +590,7 @@ impl TtParser { (_, 0) => { // Dump all possible `next_mps` into `cur_mps` for the next iteration. Then // process the next token. - self.cur_mps.extend(self.next_mps.drain(..)); + self.cur_mps.append(&mut self.next_mps); parser.to_mut().bump(); } diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 44caa2ac076..58e484e413d 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -844,7 +844,7 @@ fn non_exhaustive_match<'p, 'tcx>( format!( "{}{}{} => todo!()", comma, - snippet.strip_prefix(",").unwrap_or(&snippet), + snippet.strip_prefix(',').unwrap_or(&snippet), pattern ), )); diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index aab0c1f9771..01dc727737a 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -310,18 +310,23 @@ impl<'a> Resolver<'a> { t } - // Define a "dummy" resolution containing a Res::Err as a placeholder for a - // failed resolution + // Define a dummy resolution containing a `Res::Err` as a placeholder for a failed resolution, + // also mark such failed imports as used to avoid duplicate diagnostics. fn import_dummy_binding(&mut self, import: &'a Import<'a>) { - if let ImportKind::Single { target, .. } = import.kind { + if let ImportKind::Single { target, ref target_bindings, .. } = import.kind { + if target_bindings.iter().any(|binding| binding.get().is_some()) { + return; // Has resolution, do not create the dummy binding + } let dummy_binding = self.dummy_binding; let dummy_binding = self.import(dummy_binding, import); self.per_ns(|this, ns| { let key = this.new_key(target, ns); let _ = this.try_define(import.parent_scope.module, key, dummy_binding); }); - // Consider erroneous imports used to avoid duplicate diagnostics. self.record_use(target, dummy_binding, false); + } else if import.imported_module.get().is_none() { + import.used.set(true); + self.used_imports.insert(import.id); } } } @@ -386,7 +391,13 @@ impl<'a, 'b> ImportResolver<'a, 'b> { .map(|i| (false, i)) .chain(indeterminate_imports.into_iter().map(|i| (true, i))) { - if let Some(err) = self.finalize_import(import) { + let unresolved_import_error = self.finalize_import(import); + + // If this import is unresolved then create a dummy import + // resolution for it so that later resolve stages won't complain. + self.r.import_dummy_binding(import); + + if let Some(err) = unresolved_import_error { if let ImportKind::Single { source, ref source_bindings, .. } = import.kind { if source.name == kw::SelfLower { // Silence `unresolved import` error if E0429 is already emitted @@ -396,9 +407,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> { } } - // If the error is a single failed import then create a "fake" import - // resolution for it so that later resolve stages won't complain. - self.r.import_dummy_binding(import); if prev_root_id.as_u32() != 0 && prev_root_id.as_u32() != import.root_id.as_u32() && !errors.is_empty() @@ -418,8 +426,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> { prev_root_id = import.root_id; } } else if is_indeterminate { - // Consider erroneous imports used to avoid duplicate diagnostics. - self.r.used_imports.insert(import.id); let path = import_path_to_string( &import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(), &import.kind, @@ -553,26 +559,23 @@ impl<'a, 'b> ImportResolver<'a, 'b> { Err(Undetermined) => indeterminate = true, // Don't update the resolution, because it was never added. Err(Determined) if target.name == kw::Underscore => {} - Err(Determined) => { + Ok(binding) if binding.is_importable() => { + let imported_binding = this.import(binding, import); + target_bindings[ns].set(Some(imported_binding)); + this.define(parent, target, ns, imported_binding); + } + source_binding @ (Ok(..) | Err(Determined)) => { + if source_binding.is_ok() { + let msg = format!("`{}` is not directly importable", target); + struct_span_err!(this.session, import.span, E0253, "{}", &msg) + .span_label(import.span, "cannot be imported directly") + .emit(); + } let key = this.new_key(target, ns); this.update_resolution(parent, key, |_, resolution| { resolution.single_imports.remove(&Interned::new_unchecked(import)); }); } - Ok(binding) if !binding.is_importable() => { - let msg = format!("`{}` is not directly importable", target); - struct_span_err!(this.session, import.span, E0253, "{}", &msg) - .span_label(import.span, "cannot be imported directly") - .emit(); - // Do not import this illegal binding. Import a dummy binding and pretend - // everything is fine - this.import_dummy_binding(import); - } - Ok(binding) => { - let imported_binding = this.import(binding, import); - target_bindings[ns].set(Some(imported_binding)); - this.define(parent, target, ns, imported_binding); - } } } }); @@ -605,10 +608,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> { ); let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len; import.vis.set(orig_vis); - if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res { - // Consider erroneous imports used to avoid duplicate diagnostics. - self.r.used_imports.insert(import.id); - } let module = match path_res { PathResult::Module(module) => { // Consistency checks, analogous to `finalize_macro_resolutions`. @@ -872,7 +871,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> { }) } else { // `resolve_ident_in_module` reported a privacy error. - self.r.import_dummy_binding(import); None }; } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index ead1f0126c4..7485c082f4e 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2724,9 +2724,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &format!( "consider annotating `{}` with `#[derive({})]`", trait_pred.skip_binder().self_ty(), - diagnostic_name.to_string(), + diagnostic_name, ), - format!("#[derive({})]\n", diagnostic_name.to_string()), + format!("#[derive({})]\n", diagnostic_name), Applicability::MaybeIncorrect, ); } |
