Skip to content

Commit b354133

Browse files
committed
Auto merge of rust-lang#157398 - jhpratt:rollup-qXar4uR, r=jhpratt
Rollup of 12 pull requests Successful merges: - rust-lang#157085 (powerpc: warn against incorrect values for ABI-relevant target features) - rust-lang#157170 (Use `impl` restrictions in `std`, `core`) - rust-lang#157217 ([tiny] remove unecessary `.into()` calls) - rust-lang#157262 (rustdoc: IXCRE: Preserve sizedness bounds on type params belonging to the parent item) - rust-lang#157379 (Some more simple per-owner resolver changes) - rust-lang#157381 (librustdoc: fix CSS border issue to support Firefox high contrast mode) - rust-lang#155512 (interpreter: improve comments and error message in mir_assign_valid_types) - rust-lang#157254 (Correct description of panic.rs) - rust-lang#157290 (interpret: fix mir::UnOp layout computation) - rust-lang#157332 (Rewrite target checking for `#[sanitize]`) - rust-lang#157351 (Avoid leaking the query-job collection warning into the panic query stack) - rust-lang#157389 (Add @clarfonthey to libs review rotation)
2 parents 9c963ee + c4f09d5 commit b354133

105 files changed

Lines changed: 568 additions & 725 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct LoweringContext<'a, 'hir> {
126126
is_in_dyn_type: bool,
127127

128128
current_hir_id_owner: hir::OwnerId,
129-
owner: &'a PerOwnerResolverData,
129+
owner: &'a PerOwnerResolverData<'hir>,
130130
item_local_id_counter: hir::ItemLocalId,
131131
trait_map: ItemLocalMap<&'hir [TraitCandidate<'hir>]>,
132132

@@ -288,11 +288,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
288288
.map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect())
289289
}
290290

291-
/// Obtains per-namespace resolutions for `use` statement with the given `NodeId`.
292-
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>> {
293-
self.import_res_map.get(&id).copied().unwrap_or_default()
294-
}
295-
296291
/// Obtain the list of lifetimes parameters to add to an item.
297292
///
298293
/// Extra lifetime parameters should only be added in places that can appear
@@ -810,8 +805,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
810805
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
811806
}
812807

813-
if let Some(traits) = self.resolver.trait_map.get(&ast_node_id) {
814-
self.trait_map.insert(hir_id.local_id, &traits[..]);
808+
if let Some(traits) = self.owner.trait_map.get(&ast_node_id) {
809+
self.trait_map.insert(hir_id.local_id, *traits);
815810
}
816811

817812
// Check whether the same `NodeId` is lowered more than once.
@@ -856,8 +851,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
856851
}
857852

858853
fn lower_import_res(&mut self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
859-
let per_ns = self.resolver.get_import_res(id);
860-
let per_ns = per_ns.map(|res| res.map(|res| self.lower_res(res)));
854+
debug_assert_eq!(id, self.owner.id);
855+
let per_ns = self.owner.import_res.map(|res| res.map(|res| self.lower_res(res)));
861856
if per_ns.is_empty() {
862857
// Propagate the error to all namespaces, just to be sure.
863858
self.dcx().span_delayed_bug(span, "no resolution for an import");

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::attributes::AttributeSafety;
88
use crate::session_diagnostics::{
99
EmptyExportName, NakedFunctionIncompatibleAttribute, NullOnExport, NullOnObjcClass,
1010
NullOnObjcSelector, ObjcClassExpectedStringLiteral, ObjcSelectorExpectedStringLiteral,
11+
SanitizeInvalidStatic,
1112
};
1213
use crate::target_checking::Policy::AllowSilent;
1314

@@ -566,8 +567,18 @@ pub(crate) struct SanitizeParser;
566567

567568
impl SingleAttributeParser for SanitizeParser {
568569
const PATH: &[Symbol] = &[sym::sanitize];
569-
// FIXME: still checked in check_attrs.rs
570-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
570+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
571+
Allow(Target::Fn),
572+
Allow(Target::Closure),
573+
Allow(Target::Method(MethodKind::Inherent)),
574+
Allow(Target::Method(MethodKind::Trait { body: true })),
575+
Allow(Target::Method(MethodKind::TraitImpl)),
576+
Allow(Target::Impl { of_trait: false }),
577+
Allow(Target::Impl { of_trait: true }),
578+
Allow(Target::Mod),
579+
Allow(Target::Crate),
580+
Allow(Target::Static),
581+
]);
571582
const TEMPLATE: AttributeTemplate = template!(List: &[
572583
r#"address = "on|off""#,
573584
r#"kernel_address = "on|off""#,
@@ -668,6 +679,18 @@ impl SingleAttributeParser for SanitizeParser {
668679
}
669680
}
670681

682+
// The sanitizer attribute is only allowed on statics, if only address bits are set
683+
let all_set_except_address =
684+
(on_set | off_set) & !(SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS);
685+
if cx.target == Target::Static
686+
&& let Some(set) = all_set_except_address.iter().next()
687+
{
688+
cx.emit_err(SanitizeInvalidStatic {
689+
span: cx.attr_span,
690+
field: set.as_str().expect("Since this `SanitizerSet` is returned from an iterator, exactly one field is set")
691+
});
692+
}
693+
671694
Some(AttributeKind::Sanitize { on_set, off_set, rtsan, span: cx.attr_span })
672695
}
673696
}

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,3 +1023,12 @@ pub(crate) enum InvalidMachoSectionReason {
10231023
#[note("section name `{$section}` is longer than 16 bytes")]
10241024
SectionTooLong { section: String },
10251025
}
1026+
1027+
#[derive(Diagnostic)]
1028+
#[diag("`#[sanitize({$field} = ...)]` attribute cannot be used on statics")]
1029+
#[help("`#[sanitize]` can be used on statics if only the address is sanitized")]
1030+
pub(crate) struct SanitizeInvalidStatic {
1031+
#[primary_span]
1032+
pub span: Span,
1033+
pub field: &'static str,
1034+
}

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ pub(crate) fn allowed_targets_applied(
361361
Target::Method(MethodKind::Trait { body: true }),
362362
Target::Method(MethodKind::TraitImpl),
363363
];
364+
const FUNCTION_WITH_BODY_LIKE: &[Target] = &[
365+
Target::Fn,
366+
Target::Closure,
367+
Target::Method(MethodKind::Inherent),
368+
Target::Method(MethodKind::Trait { body: true }),
369+
Target::Method(MethodKind::TraitImpl),
370+
];
364371
const METHOD_LIKE: &[Target] = &[
365372
Target::Method(MethodKind::Inherent),
366373
Target::Method(MethodKind::Trait { body: false }),
@@ -379,6 +386,13 @@ pub(crate) fn allowed_targets_applied(
379386
target,
380387
&mut added_fake_targets,
381388
);
389+
filter_targets(
390+
&mut allowed_targets,
391+
FUNCTION_WITH_BODY_LIKE,
392+
"functions with a body",
393+
target,
394+
&mut added_fake_targets,
395+
);
382396
filter_targets(&mut allowed_targets, METHOD_LIKE, "methods", target, &mut added_fake_targets);
383397
filter_targets(&mut allowed_targets, IMPL_LIKE, "impl blocks", target, &mut added_fake_targets);
384398
filter_targets(&mut allowed_targets, ADT_LIKE, "data types", target, &mut added_fake_targets);

compiler/rustc_builtin_macros/src/format_foreign/shell/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn test_escape() {
2222
fn test_parse() {
2323
macro_rules! assert_pns_eq_sub {
2424
($in_:expr, $kind:ident($arg:expr, $pos:expr)) => {
25-
assert_eq!(pns(concat!($in_, "!")), Some((S::$kind($arg.into(), $pos), "!")))
25+
assert_eq!(pns(concat!($in_, "!")), Some((S::$kind($arg, $pos), "!")))
2626
};
2727
}
2828

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,25 +165,30 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
165165
}
166166

167167
/// Test if it is valid for a MIR assignment to assign `src`-typed place to `dest`-typed value.
168-
/// This test should be symmetric, as it is primarily about layout compatibility.
169168
pub(super) fn mir_assign_valid_types<'tcx>(
170169
tcx: TyCtxt<'tcx>,
171170
typing_env: TypingEnv<'tcx>,
172171
src: TyAndLayout<'tcx>,
173172
dest: TyAndLayout<'tcx>,
174173
) -> bool {
175-
// Type-changing assignments can happen when subtyping is used. While
176-
// all normal lifetimes are erased, higher-ranked types with their
177-
// late-bound lifetimes are still around and can lead to type
178-
// differences.
174+
// We *could* check `Invariant` here since all subtyping must be explicit post-borrowck.
175+
// However, this check is also used by the interpreter to figure out if a transmute can be
176+
// turned into a regular assignment (which has a more efficient codepath), so we want the check
177+
// to consider as many assignments as possible to be valid. Therefore we are happy to accept
178+
// one-way subtyping.
179179
if util::relate_types(tcx, typing_env, Variance::Covariant, src.ty, dest.ty) {
180-
// Make sure the layout is equal, too -- just to be safe. Miri really
181-
// needs layout equality. For performance reason we skip this check when
182-
// the types are equal. Equal types *can* have different layouts when
183-
// enum downcast is involved (as enum variants carry the type of the
184-
// enum), but those should never occur in assignments.
180+
// Make sure the layout is equal, too -- just to be safe. Miri really needs layout equality.
181+
// For performance reason we skip this check when the types are equal. Equal types *can*
182+
// have different layouts when enum downcast is involved (as enum variants carry the type of
183+
// the enum), but those should never occur in assignments.
185184
if cfg!(debug_assertions) || src.ty != dest.ty {
186-
assert_eq!(src.layout, dest.layout);
185+
assert_eq!(
186+
src.layout,
187+
dest.layout,
188+
"{src} is a subtype of {dest} but they have different layout",
189+
src = src.ty,
190+
dest = dest.ty,
191+
);
187192
}
188193
true
189194
} else {

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
190190
}
191191

192192
UnaryOp(un_op, ref operand) => {
193-
// The operand always has the same type as the result.
194-
let val = self.read_immediate(&self.eval_operand(operand, Some(dest.layout))?)?;
193+
let layout = util::unop_homogeneous(un_op).then_some(dest.layout);
194+
let val = self.read_immediate(&self.eval_operand(operand, layout)?)?;
195195
let result = self.unary_op(un_op, &val)?;
196196
assert_eq!(result.layout, dest.layout, "layout mismatch for result of {un_op:?}");
197197
self.write_immediate(*result, &dest)?;

compiler/rustc_const_eval/src/util/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ pub fn binop_right_homogeneous(op: mir::BinOp) -> bool {
3838
Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => false,
3939
}
4040
}
41+
42+
/// Classify whether an operator is "homogeneous", i.e., the operand has the
43+
/// same type as the result.
44+
#[inline]
45+
pub fn unop_homogeneous(op: mir::UnOp) -> bool {
46+
match op {
47+
mir::UnOp::Not | mir::UnOp::Neg => true,
48+
mir::UnOp::PtrMetadata => false,
49+
}
50+
}

compiler/rustc_hir/src/def.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,8 @@ impl IntoDiagArg for Namespace {
717717
}
718718

719719
/// Just a helper ‒ separate structure for each namespace.
720-
#[derive(Copy, Clone, Default, Debug, StableHash)]
720+
#[derive(Copy, Clone, Debug, StableHash)]
721+
#[derive_const(Default)]
721722
pub struct PerNS<T> {
722723
pub value_ns: T,
723724
pub type_ns: T,

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'tcx> InferCtxt<'tcx> {
286286
(GenericArgKind::Lifetime(v_o), GenericArgKind::Lifetime(v_r)) => {
287287
if v_o != v_r {
288288
output_query_region_constraints.constraints.push((
289-
ty::RegionEqPredicate(v_o.into(), v_r).into(),
289+
ty::RegionEqPredicate(v_o, v_r).into(),
290290
constraint_category,
291291
ty::VisibleForLeakCheck::Yes,
292292
));

0 commit comments

Comments
 (0)