.emit();
})
}
+
+ fn report_overridden_symbol_section(&self, cx: &EarlyContext<'_>, span: Span, msg: &str) {
+ self.report_unsafe(cx, span, |lint| {
+ lint.build(msg)
+ .note(
+ "the program's behavior with overridden link sections on items is unpredictable \
+ and Rust cannot provide guarantees when you manually override them",
+ )
+ .emit();
+ })
+ }
}
impl EarlyLintPass for UnsafeCode {
"declaration of a `no_mangle` function",
);
}
+
if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::export_name) {
self.report_overridden_symbol_name(
cx,
"declaration of a function with `export_name`",
);
}
+
+ if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::link_section) {
+ self.report_overridden_symbol_section(
+ cx,
+ attr.span,
+ "declaration of a function with `link_section`",
+ );
+ }
}
ast::ItemKind::Static(..) => {
"declaration of a `no_mangle` static",
);
}
+
if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::export_name) {
self.report_overridden_symbol_name(
cx,
"declaration of a static with `export_name`",
);
}
+
+ if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::link_section) {
+ self.report_overridden_symbol_section(
+ cx,
+ attr.span,
+ "declaration of a static with `link_section`",
+ );
+ }
}
_ => {}
.span_suggestion_short(
attr.span,
suggestion.unwrap_or("remove this attribute"),
- String::new(),
+ "",
Applicability::MachineApplicable,
)
.emit();
.span_suggestion_short(
no_mangle_attr.span,
"remove this attribute",
- String::new(),
+ "",
// Use of `#[no_mangle]` suggests FFI intent; correct
// fix may be to monomorphize source by hand
Applicability::MaybeIncorrect,
err.span_suggestion(
const_span,
"try a static value",
- "pub static".to_owned(),
+ "pub static",
Applicability::MachineApplicable,
);
err.emit();
impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
- use rustc_target::spec::abi::Abi::RustIntrinsic;
if let Some((&ty::Ref(_, _, from_mt), &ty::Ref(_, _, to_mt))) =
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind()))
{
}
fn def_id_is_transmute(cx: &LateContext<'_>, def_id: DefId) -> bool {
- cx.tcx.fn_sig(def_id).abi() == RustIntrinsic
- && cx.tcx.item_name(def_id) == sym::transmute
+ cx.tcx.is_intrinsic(def_id) && cx.tcx.item_name(def_id) == sym::transmute
}
}
}
let def_span = cx.tcx.sess.source_map().guess_head_span(span);
cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| {
let mut err = lint.build(&format!("unreachable `pub` {}", what));
- let replacement = if cx.tcx.features().crate_visibility_modifier {
- "crate"
- } else {
- "pub(crate)"
- }
- .to_owned();
err.span_suggestion(
vis_span,
"consider restricting its visibility",
- replacement,
+ "pub(crate)",
applicability,
);
if exportable {
err.span_suggestion(
type_alias_generics.where_clause_span,
"the clause will not be checked when the type alias is used, and should be removed",
- String::new(),
+ "",
Applicability::MachineApplicable,
);
if !suggested_changing_assoc_types {
hir::ItemKind::Const(_, body_id) => {
let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
// trigger the query once for all constants since that will already report the errors
- // FIXME: Use ensure here
- let _ = cx.tcx.const_eval_poly(def_id);
+ cx.tcx.ensure().const_eval_poly(def_id);
}
hir::ItemKind::Static(_, _, body_id) => {
let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
- // FIXME: Use ensure here
- let _ = cx.tcx.eval_static_initializer(def_id);
+ cx.tcx.ensure().eval_static_initializer(def_id);
}
_ => {}
}
});
}
} else {
- let replace = "..=".to_owned();
+ let replace = "..=";
if join.edition() >= Edition::Edition2021 {
let mut err =
rustc_errors::struct_span_err!(cx.sess(), pat.span, E0783, "{}", msg,);
tcx: TyCtxt<'tcx>,
bounds: &hir::GenericBounds<'_>,
inferred_outlives: &[ty::Region<'tcx>],
- infer_static: bool,
) -> Vec<(usize, Span)> {
use rustc_middle::middle::resolve_lifetime::Region;
.filter_map(|(i, bound)| {
if let hir::GenericBound::Outlives(lifetime) = bound {
let is_inferred = match tcx.named_region(lifetime.hir_id) {
- Some(Region::Static) if infer_static => {
- inferred_outlives.iter().any(|r| matches!(**r, ty::ReStatic))
- }
Some(Region::EarlyBound(index, ..)) => inferred_outlives.iter().any(|r| {
if let ty::ReEarlyBound(ebr) = **r { ebr.index == index } else { false }
}),
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
use rustc_middle::middle::resolve_lifetime::Region;
- let infer_static = cx.tcx.features().infer_static_outlives_requirements;
let def_id = item.def_id;
if let hir::ItemKind::Struct(_, ref hir_generics)
| hir::ItemKind::Enum(_, ref hir_generics)
continue;
}
- let bound_spans = self.collect_outlives_bound_spans(
- cx.tcx,
- bounds,
- &relevant_lifetimes,
- infer_static,
- );
+ let bound_spans =
+ self.collect_outlives_bound_spans(cx.tcx, bounds, &relevant_lifetimes);
bound_count += bound_spans.len();
let drop_predicate = bound_spans.len() == bounds.len();
// If all predicates are inferable, drop the entire clause
// (including the `where`)
- if hir_generics.has_where_clause && dropped_predicate_count == num_predicates {
- let where_span = hir_generics
- .where_clause_span()
- .expect("span of (nonempty) where clause should exist");
+ if hir_generics.has_where_clause_predicates && dropped_predicate_count == num_predicates
+ {
+ let where_span = hir_generics.where_clause_span;
// Extend the where clause back to the closing `>` of the
// generics, except for tuple struct, which have the `where`
// after the fields of the struct.
ty: Ty<'tcx>,
init: InitKind,
) -> Option<InitError> {
- use rustc_middle::ty::TyKind::*;
+ use rustc_type_ir::sty::TyKind::*;
match ty.kind() {
// Primitive types that don't like 0 as a value.
Ref(..) => Some(("references must be non-null".to_string(), None)),
}
impl ClashingExternDeclarations {
- crate fn new() -> Self {
+ pub(crate) fn new() -> Self {
ClashingExternDeclarations { seen_decls: FxHashMap::default() }
}
/// Insert a new foreign item into the seen set. If a symbol with the same name already exists
true
} else {
// Do a full, depth-first comparison between the two.
- use rustc_middle::ty::TyKind::*;
+ use rustc_type_ir::sty::TyKind::*;
let a_kind = a.kind();
let b_kind = b.kind();
}
(Array(a_ty, a_const), Array(b_ty, b_const)) => {
// For arrays, we also check the constness of the type.
- a_const.val() == b_const.val()
+ a_const.kind() == b_const.kind()
&& structurally_same_type_impl(seen_types, cx, *a_ty, *b_ty, ckind)
}
(Slice(a_ty), Slice(b_ty)) => {