Skip to content

Commit

Permalink
Auto merge of #109346 - Dylan-DPC:rollup-vszi5bn, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - #104100 (Allow using `Range` as an `Iterator` in const contexts. )
 - #105793 (Add note for mismatched types because of circular dependencies)
 - #108798 (move default backtrace setting to sys)
 - #108829 (Use Edition 2021 :pat in matches macro)
 - #108973 (Beautify pin! docs)
 - #109003 (Add `useless_anonymous_reexport` lint)
 - #109022 (read_buf_exact: on error, all read bytes are appended to the buffer)
 - #109212 (fix: don't suggest similar method when unstable)
 - #109243 (The name of NativeLib will be presented)
 - #109324 (Implement FixedSizeEncoding for UnusedGenericParams.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 19, 2023
2 parents ab9bb3e + 881c989 commit 8826b68
Show file tree
Hide file tree
Showing 47 changed files with 577 additions and 150 deletions.
19 changes: 9 additions & 10 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ fn link_rlib<'a>(
let (data, _) = create_wrapper_file(sess, b".bundled_lib".to_vec(), &src);
let wrapper_file = emit_wrapper_file(sess, &data, tmpdir, filename.as_str());
packed_bundled_libs.push(wrapper_file);
} else if let Some(name) = lib.name {
} else {
let path =
find_native_static_library(name.as_str(), lib.verbatim, &lib_search_paths, sess);
find_native_static_library(lib.name.as_str(), lib.verbatim, &lib_search_paths, sess);
ab.add_archive(&path, Box::new(|_| false)).unwrap_or_else(|error| {
sess.emit_fatal(errors::AddNativeLibrary { library_path: path, error })});
}
Expand Down Expand Up @@ -436,7 +436,7 @@ fn collate_raw_dylibs<'a, 'b>(
for lib in used_libraries {
if lib.kind == NativeLibKind::RawDylib {
let ext = if lib.verbatim { "" } else { ".dll" };
let name = format!("{}{}", lib.name.expect("unnamed raw-dylib library"), ext);
let name = format!("{}{}", lib.name, ext);
let imports = dylib_table.entry(name.clone()).or_default();
for import in &lib.dll_imports {
if let Some(old_import) = imports.insert(import.name, import) {
Expand Down Expand Up @@ -1296,7 +1296,7 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
.iter()
.filter(|l| relevant_lib(sess, l))
.filter_map(|lib| {
let name = lib.name?;
let name = lib.name;
match lib.kind {
NativeLibKind::Static { bundle: Some(false), .. }
| NativeLibKind::Dylib { .. }
Expand All @@ -1317,6 +1317,7 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
// These are included, no need to print them
NativeLibKind::Static { bundle: None | Some(true), .. }
| NativeLibKind::LinkArg
| NativeLibKind::WasmImportModule
| NativeLibKind::RawDylib => None,
}
})
Expand Down Expand Up @@ -2275,21 +2276,18 @@ fn add_native_libs_from_crate(

let mut last = (None, NativeLibKind::Unspecified, false);
for lib in native_libs {
let Some(name) = lib.name else {
continue;
};
if !relevant_lib(sess, lib) {
continue;
}

// Skip if this library is the same as the last.
last = if (lib.name, lib.kind, lib.verbatim) == last {
last = if (Some(lib.name), lib.kind, lib.verbatim) == last {
continue;
} else {
(lib.name, lib.kind, lib.verbatim)
(Some(lib.name), lib.kind, lib.verbatim)
};

let name = name.as_str();
let name = lib.name.as_str();
let verbatim = lib.verbatim;
match lib.kind {
NativeLibKind::Static { bundle, whole_archive } => {
Expand Down Expand Up @@ -2346,6 +2344,7 @@ fn add_native_libs_from_crate(
NativeLibKind::RawDylib => {
// Handled separately in `linker_with_args`.
}
NativeLibKind::WasmImportModule => {}
NativeLibKind::LinkArg => {
if link_static {
cmd.arg(name);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ fn wasm_import_module_map(tcx: TyCtxt<'_>, cnum: CrateNum) -> FxHashMap<DefId, S

let mut ret = FxHashMap::default();
for (def_id, lib) in tcx.foreign_modules(cnum).iter() {
let module = def_id_to_native_lib.get(&def_id).and_then(|s| s.wasm_import_module);
let module = def_id_to_native_lib.get(&def_id).and_then(|s| s.wasm_import_module());
let Some(module) = module else { continue };
ret.extend(lib.foreign_items.iter().map(|id| {
assert_eq!(id.krate, cnum);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ bitflags::bitflags! {
#[derive(Clone, Debug, Encodable, Decodable, HashStable)]
pub struct NativeLib {
pub kind: NativeLibKind,
pub name: Option<Symbol>,
pub name: Symbol,
pub filename: Option<Symbol>,
pub cfg: Option<ast::MetaItem>,
pub verbatim: bool,
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
true
}
})
// ensure that we don't suggest unstable methods
.filter(|candidate| {
// note that `DUMMY_SP` is ok here because it is only used for
// suggestions and macro stuff which isn't applicable here.
!matches!(
self.tcx.eval_stability(candidate.item.def_id, None, DUMMY_SP, None),
stability::EvalResult::Deny { .. }
)
})
.map(|candidate| candidate.item.ident(self.tcx))
.filter(|&name| set.insert(name))
.collect();
Expand Down
21 changes: 14 additions & 7 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}

let report_path_match = |err: &mut Diagnostic, did1: DefId, did2: DefId| {
// Only external crates, if either is from a local
// module we could have false positives
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
// Only report definitions from different crates. If both definitions
// are from a local module we could have false positives, e.g.
// let _ = [{struct Foo; Foo}, {struct Foo; Foo}];
if did1.krate != did2.krate {
let abs_path =
|def_id| AbsolutePathPrinter { tcx: self.tcx }.print_def_path(def_id, &[]);

Expand All @@ -629,10 +630,16 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
};
if same_path().unwrap_or(false) {
let crate_name = self.tcx.crate_name(did1.krate);
err.note(&format!(
"perhaps two different versions of crate `{}` are being used?",
crate_name
));
let msg = if did1.is_local() || did2.is_local() {
format!(
"the crate `{crate_name}` is compiled multiple times, possibly with different configurations"
)
} else {
format!(
"perhaps two different versions of crate `{crate_name}` are being used?"
)
};
err.note(msg);
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,6 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
.specifically = this associated type bound is unsatisfied for `{$proj_ty}`
lint_opaque_hidden_inferred_bound_sugg = add this bound
lint_useless_anonymous_reexport = useless anonymous re-export
.note = only anonymous re-exports of traits are useful, this is {$article} `{$desc}`
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mod opaque_hidden_inferred_bound;
mod pass_by_value;
mod passes;
mod redundant_semicolon;
mod reexports;
mod traits;
mod types;
mod unused;
Expand Down Expand Up @@ -111,6 +112,7 @@ use noop_method_call::*;
use opaque_hidden_inferred_bound::*;
use pass_by_value::*;
use redundant_semicolon::*;
use reexports::*;
use traits::*;
use types::*;
use unused::*;
Expand Down Expand Up @@ -242,6 +244,7 @@ late_lint_methods!(
OpaqueHiddenInferredBound: OpaqueHiddenInferredBound,
MultipleSupertraitUpcastable: MultipleSupertraitUpcastable,
MapUnitFn: MapUnitFn,
UselessAnonymousReexport: UselessAnonymousReexport,
]
]
);
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1528,3 +1528,11 @@ pub struct UnusedAllocationDiag;
#[derive(LintDiagnostic)]
#[diag(lint_unused_allocation_mut)]
pub struct UnusedAllocationMutDiag;

#[derive(LintDiagnostic)]
#[diag(lint_useless_anonymous_reexport)]
#[note]
pub struct UselessAnonymousReexportDiag {
pub article: &'static str,
pub desc: &'static str,
}
82 changes: 82 additions & 0 deletions compiler/rustc_lint/src/reexports.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use crate::lints::UselessAnonymousReexportDiag;
use crate::{LateContext, LateLintPass, LintContext};
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_hir::{Item, ItemKind, UseKind};
use rustc_middle::ty::Visibility;
use rustc_span::symbol::kw;
use rustc_span::Span;

declare_lint! {
/// The `useless_anonymous_reexport` lint checks if anonymous re-exports
/// are re-exports of traits.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(useless_anonymous_reexport)]
///
/// mod sub {
/// pub struct Bar;
/// }
///
/// pub use self::sub::Bar as _;
/// # fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Anonymous re-exports are only useful if it's a re-export of a trait
/// in case you want to give access to it. If you re-export any other kind,
/// you won't be able to use it since its name won't be accessible.
pub USELESS_ANONYMOUS_REEXPORT,
Warn,
"useless anonymous re-export"
}

declare_lint_pass!(UselessAnonymousReexport => [USELESS_ANONYMOUS_REEXPORT]);

fn emit_err(cx: &LateContext<'_>, span: Span, def_id: DefId) {
let article = cx.tcx.def_descr_article(def_id);
let desc = cx.tcx.def_descr(def_id);
cx.emit_spanned_lint(
USELESS_ANONYMOUS_REEXPORT,
span,
UselessAnonymousReexportDiag { article, desc },
);
}

impl<'tcx> LateLintPass<'tcx> for UselessAnonymousReexport {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
if let ItemKind::Use(path, kind) = item.kind &&
!matches!(kind, UseKind::Glob) &&
item.ident.name == kw::Underscore &&
// We only want re-exports. If it's just a `use X;`, then we ignore it.
match cx.tcx.local_visibility(item.owner_id.def_id) {
Visibility::Public => true,
Visibility::Restricted(level) => {
level != cx.tcx.parent_module_from_def_id(item.owner_id.def_id)
}
}
{
for def_id in path.res.iter().filter_map(|r| r.opt_def_id()) {
match cx.tcx.def_kind(def_id) {
DefKind::Trait | DefKind::TraitAlias => {}
DefKind::TyAlias => {
let ty = cx.tcx.type_of(def_id);
if !ty.0.is_trait() {
emit_err(cx, item.span, def_id);
break;
}
}
_ => {
emit_err(cx, item.span, def_id);
break;
}
}
}
}
}
}
Loading

0 comments on commit 8826b68

Please sign in to comment.