Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion compiler/rustc_attr_ir/src/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ impl<ScopeId> StrippedCfgItem<ScopeId> {
#[derive(StableHash, PrintAttribute)]
pub enum Linkage {
AvailableExternally,
Common,
ExternalWeak,
External,
Internal,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_attr_ir/src/encode_cross_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ impl AttributeKind {
Linkage(linkage, _) => match *linkage {
crate::Linkage::Internal => false,
crate::Linkage::AvailableExternally
| crate::Linkage::Common
| crate::Linkage::External
| crate::Linkage::ExternalWeak
| crate::Linkage::LinkOnceAny
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_attr_parsing/src/attributes/link_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,7 @@ impl SingleAttributeParser for LinkageParser {
]);
const TEMPLATE: AttributeTemplate = template!(NameValueStr: [
"available_externally",
"common",
"extern_weak",
"external",
"internal",
"linkonce",
"linkonce_odr",
"weak",
Expand All @@ -711,10 +708,7 @@ impl SingleAttributeParser for LinkageParser {
// and don't have to be, LLVM treats them as no-ops.
let linkage = match value {
sym::available_externally => Linkage::AvailableExternally,
sym::common => Linkage::Common,
sym::extern_weak => Linkage::ExternalWeak,
sym::external => Linkage::External,
sym::internal => Linkage::Internal,
sym::linkonce => Linkage::LinkOnceAny,
sym::linkonce_odr => Linkage::LinkOnceODR,
sym::weak => Linkage::WeakAny,
Expand All @@ -725,10 +719,7 @@ impl SingleAttributeParser for LinkageParser {
name_value.value_span,
&[
sym::available_externally,
sym::common,
sym::extern_weak,
sym::external,
sym::internal,
sym::linkonce,
sym::linkonce_odr,
sym::weak,
Expand Down
19 changes: 4 additions & 15 deletions compiler/rustc_codegen_gcc/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,14 @@ pub fn global_linkage_to_gcc(linkage: Linkage) -> GlobalKind {
| Linkage::LinkOnceODR
| Linkage::WeakAny
| Linkage::WeakODR
| Linkage::ExternalWeak
| Linkage::Common => GlobalKind::Exported,
| Linkage::ExternalWeak => GlobalKind::Exported,
}
}

/// The attribute a global *definition* needs on top of its [`GlobalKind`] to get this linkage.
#[cfg(feature = "master")]
pub fn global_linkage_attribute<'gcc>(linkage: Linkage) -> Option<VarAttribute<'gcc>> {
match linkage {
Linkage::Common => Some(VarAttribute::Common),
_ if linkage_needs_weak_attribute(linkage) => Some(VarAttribute::Weak),
_ => None,
}
if linkage_needs_weak_attribute(linkage) { Some(VarAttribute::Weak) } else { None }
}

/// The type of a function *definition* with an explicit `#[linkage]`.
Expand All @@ -85,26 +80,20 @@ pub fn linkage_to_gcc(linkage: Linkage) -> FunctionType {
| Linkage::LinkOnceODR
| Linkage::WeakAny
| Linkage::WeakODR
| Linkage::ExternalWeak
| Linkage::Common => FunctionType::Exported,
| Linkage::ExternalWeak => FunctionType::Exported,
}
}

/// Whether a definition with this linkage must carry the `weak` attribute, so that a strong
/// definition in another object file wins over it instead of clashing with it.
///
/// `common` is in here for functions only: GCC honours that attribute on a variable, but drops it
/// on a function, so a common function falls back to weak. Globals go through
/// `global_linkage_attribute` instead.
#[cfg(feature = "master")]
pub fn linkage_needs_weak_attribute(linkage: Linkage) -> bool {
match linkage {
Linkage::LinkOnceAny
| Linkage::LinkOnceODR
| Linkage::WeakAny
| Linkage::WeakODR
| Linkage::ExternalWeak
| Linkage::Common => true,
| Linkage::ExternalWeak => true,
Linkage::External | Linkage::AvailableExternally | Linkage::Internal => false,
}
}
Expand Down
21 changes: 2 additions & 19 deletions compiler/rustc_codegen_gcc/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use rustc_hir::def_id::LOCAL_CRATE;
use rustc_log::tracing::trace;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::interpret::{
self, Allocation, ConstAllocation, CtfeProvenance, ErrorHandled, Scalar as InterpScalar,
read_target_uint,
self, ConstAllocation, CtfeProvenance, ErrorHandled, Scalar as InterpScalar, read_target_uint,
};
use rustc_middle::mono::MonoItem;
use rustc_middle::ty::layout::LayoutOf;
Expand Down Expand Up @@ -113,12 +112,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
// NOTE: Alignment from attributes has already been applied to the allocation.
set_global_alignment(self, global, alloc.align);

// A common symbol is storage the linker allocates and zero-fills, so giving the definition
// an initializer — even an all-zero one — takes it back out of `.comm`. A non-zero one is
// kept: the symbol is then an ordinary definition, which is what GCC does with it too.
if attrs.linkage != Some(Linkage::Common) || !is_zero_initializer(alloc) {
global.global_set_initializer_rvalue(value);
}
global.global_set_initializer_rvalue(value);

// As an optimization, all shared statics which do not have interior
// mutability are placed into read-only memory.
Expand Down Expand Up @@ -458,17 +452,6 @@ pub(crate) fn const_alloc_to_gcc_uncached<'gcc>(
cx.const_struct(&llvals, true)
}

/// Whether this allocation is all zeroes, and so needs no initializer to be spelled out.
fn is_zero_initializer(alloc: &Allocation) -> bool {
alloc.provenance().ptrs().is_empty()
// This `inspect` is okay: it is within the bounds of the allocation, there is no provenance
// to misread, and it does not affect interpreter execution.
&& alloc
.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.size().bytes_usize())
.iter()
.all(|&byte| byte == 0)
}

fn codegen_static_initializer<'gcc, 'tcx>(
cx: &CodegenCx<'gcc, 'tcx>,
def_id: DefId,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ pub(crate) fn linkage_to_llvm(linkage: Linkage) -> llvm::Linkage {
Linkage::WeakODR => llvm::Linkage::WeakODRLinkage,
Linkage::Internal => llvm::Linkage::InternalLinkage,
Linkage::ExternalWeak => llvm::Linkage::ExternalWeakLinkage,
Linkage::Common => llvm::Linkage::CommonLinkage,
}
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ fn prefix_and_suffix<'tcx>(
// LTO can fail when internal linkage is used.
emit_fatal("naked functions may not have internal linkage")
}
Linkage::Common => emit_fatal("Functions may not have common linkage"),
Linkage::AvailableExternally => {
// this would make the function equal an extern definition
emit_fatal("Functions may not have available_externally linkage")
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,16 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
HandledOptions::HelpOnly(matches) => (matches, true),
};

let sopts = config::build_session_options(&mut default_early_dcx, &matches);
// fully initialize ice path static once unstable options are available as context
// For the purposes of checking that an --edition was passed, we ignore `-`.
let warn_unspecified_edition = match &matches.free[..] {
[] => false,
// We explicitly don't emit the note if we're consuming code from stdin. This can happen
// on some cargo invocations too.
[name] if name == "-" => false,
_ => true,
};
let sopts =
config::build_session_options(&mut default_early_dcx, &matches, warn_unspecified_edition);
let ice_file = ice_path_with_config(Some(&sopts.unstable_opts)).clone();

if let Some(ref code) = matches.opt_str("explain") {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_analysis/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub(crate) struct AssocKindMismatch {
#[primary_span]
#[label("unexpected {$got}")]
pub span: Span,
#[context]
pub item_span: Span,
#[context]
pub enclosing_span: Option<Span>,
pub expected: &'static str,
pub got: &'static str,
#[label("expected a {$expected} because of this associated {$expected}")]
Expand Down
23 changes: 23 additions & 0 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,31 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
(ident.span, None, assoc_tag, assoc_item.tag())
};

let def_kind = tcx.def_kind(self.item_def_id());
let item_span = tcx.def_span(self.item_def_id()).shrink_to_lo();
let (item_span, enclosing_span) = match def_kind {
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => (
item_span,
Some(tcx.def_span(tcx.parent(self.item_def_id().into())).shrink_to_lo()),
),
DefKind::OpaqueTy => {
let item_span = tcx.def_span(tcx.parent(self.item_def_id().into())).shrink_to_lo();
let enclosing_span =
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy =
tcx.def_kind(tcx.parent(self.item_def_id().into()))
{
Some(tcx.def_span(tcx.parent(self.item_def_id().into())).shrink_to_lo())
} else {
None
};
(item_span, enclosing_span)
}
_ => (item_span, None),
};
self.dcx().emit_err(diagnostics::AssocKindMismatch {
span,
item_span,
enclosing_span,
expected: assoc_tag_str(expected),
got: assoc_tag_str(got),
expected_because_label,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
{
let mut early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
let matches = optgroups().parse(args).unwrap();
let sessopts = build_session_options(&mut early_dcx, &matches);
let sessopts = build_session_options(&mut early_dcx, &matches, true);
let target = rustc_session::config::build_target_config(
&early_dcx,
&sessopts.target_triple,
Expand Down Expand Up @@ -941,7 +941,7 @@ fn test_edition_parsing() {
let mut early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());

let matches = optgroups().parse(&["--edition=2018".to_string()]).unwrap();
let sessopts = build_session_options(&mut early_dcx, &matches);
let sessopts = build_session_options(&mut early_dcx, &matches, false);
assert!(sessopts.edition == Edition::Edition2018)
}

Expand All @@ -952,7 +952,7 @@ fn test_assumptions_on_binders_enables_next_solver_globally() {

// `-Zassumptions-on-binders` alone enables the next solver globally.
let matches = optgroups().parse(&["-Zassumptions-on-binders".to_string()]).unwrap();
let opts = build_session_options(&mut early_dcx, &matches);
let opts = build_session_options(&mut early_dcx, &matches, false);
assert!(opts.unstable_opts.assumptions_on_binders);
assert_eq!(opts.unstable_opts.next_solver, globally);

Expand All @@ -963,7 +963,7 @@ fn test_assumptions_on_binders_enables_next_solver_globally() {
["-Znext-solver=coherence".to_string(), "-Zassumptions-on-binders".to_string()],
] {
let matches = optgroups().parse(&args).unwrap();
let opts = build_session_options(&mut early_dcx, &matches);
let opts = build_session_options(&mut early_dcx, &matches, false);
assert!(opts.unstable_opts.assumptions_on_binders);
assert_eq!(opts.unstable_opts.next_solver, globally);
}
Expand All @@ -976,7 +976,7 @@ fn test_assumptions_on_binders_enables_next_solver_globally() {
["-Znext-solver=no".to_string(), "-Zassumptions-on-binders".to_string()],
] {
let matches = optgroups().parse(&args).unwrap();
let opts = build_session_options(&mut early_dcx, &matches);
let opts = build_session_options(&mut early_dcx, &matches, false);
assert!(opts.unstable_opts.assumptions_on_binders);
assert_eq!(opts.unstable_opts.next_solver, globally);
}
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,16 @@ impl DiagnosticDeriveVariantBuilder {
match (&attr.meta, name.as_str()) {
(Meta::Path(_), "primary_span") => {
report_error_if_not_applied_to_span(attr, &info)?;

return Ok(quote! {
diag.span(#binding);
});
}
(Meta::Path(_), "context") => {
report_error_if_not_applied_to_span(attr, &info)?;
return Ok(quote! {
diag.span_context(#binding);
});
}
(Meta::Path(_), "subdiagnostic") => {
return Ok(quote! { diag.subdiagnostic(#binding); });
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ decl_derive!(
// field attributes
primary_span,
label,
context,
subdiagnostic,
suggestion)] =>
#[doc = "See <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html#derivediagnostic>"]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_monomorphize/src/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,6 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> MonoItemPartitio
Linkage::WeakODR => "WeakODR",
Linkage::Internal => "Internal",
Linkage::ExternalWeak => "ExternalWeak",
Linkage::Common => "Common",
};

output.push('[');
Expand Down
26 changes: 18 additions & 8 deletions compiler/rustc_resolve/src/diagnostics/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
code,
trait_item_span,
trait_path,
trait_span,
impl_span,
} => self
.dcx()
.create_err(diagnostics::TraitImplMismatch {
Expand All @@ -1407,16 +1409,24 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
kind,
trait_path,
trait_item_span,
trait_span,
impl_span,
})
.with_code(code),
ResolutionError::TraitImplDuplicate { name, trait_item_span, old_span } => {
self.dcx().create_err(diagnostics::TraitImplDuplicate {
span,
name,
trait_item_span,
old_span,
})
}
ResolutionError::TraitImplDuplicate {
name,
trait_item_span,
old_span,
trait_span,
impl_span,
} => self.dcx().create_err(diagnostics::TraitImplDuplicate {
span,
name,
trait_item_span,
trait_span,
impl_span,
old_span,
}),
ResolutionError::InvalidAsmSym => {
self.dcx().create_err(diagnostics::InvalidAsmSym { span })
}
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_resolve/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ pub(crate) struct TraitImplDuplicate {
pub(crate) old_span: Span,
#[label("item in trait")]
pub(crate) trait_item_span: Span,
#[context]
pub(crate) trait_span: Span,
#[context]
pub(crate) impl_span: Span,
pub(crate) name: Ident,
}

Expand Down Expand Up @@ -1410,6 +1414,10 @@ pub(crate) struct TraitImplMismatch {
pub(crate) trait_path: String,
#[label("item in trait")]
pub(crate) trait_item_span: Span,
#[context]
pub(crate) trait_span: Span,
#[context]
pub(crate) impl_span: Span,
}

#[derive(Diagnostic)]
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3902,12 +3902,16 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

match seen_trait_items.entry(id_in_trait) {
Entry::Occupied(entry) => {
let trait_span = decl.parent_module.unwrap().span.shrink_to_lo();
let impl_span = self.current_trait_ref.as_ref().unwrap().1.path.span;
self.report_error(
span,
ResolutionError::TraitImplDuplicate {
name: ident,
old_span: *entry.get(),
trait_item_span: decl.span,
trait_span,
impl_span,
},
);
return;
Expand Down Expand Up @@ -3940,6 +3944,8 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
}
};
let trait_path = path_names_to_string(path);
let trait_span = decl.parent_module.unwrap().span.shrink_to_lo();
let impl_span = self.current_trait_ref.as_ref().unwrap().1.path.span;
self.report_error(
span,
ResolutionError::TraitImplMismatch {
Expand All @@ -3948,6 +3954,8 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
code,
trait_path,
trait_item_span: decl.span,
trait_span,
impl_span,
},
);
}
Expand Down
Loading
Loading