Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #102926

Merged
merged 143 commits into from Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
ba64c93
Lower generator expression to HIR
lowr Sep 5, 2022
aeeb9e0
Add `TyBuilder` method to build `Substitution` for generator
lowr Sep 9, 2022
77c40f8
Implement type inference for generator and yield expressions
lowr Sep 6, 2022
447596c
Implement `RustIrDatabase::generator_datum()`
lowr Sep 9, 2022
4b5a66e
Add tests for type inference for generators
lowr Sep 9, 2022
997fc46
Implemented basic enum const eval
OleStrohm Aug 6, 2022
e28046c
Removed unnecessary TODO
OleStrohm Aug 6, 2022
b63234e
Cleaned up code
OleStrohm Aug 6, 2022
2f84b6e
Almost there
OleStrohm Aug 6, 2022
ad0a6bf
Added consteval tests
OleStrohm Aug 7, 2022
301b889
Added more consteval tests and fixed consteval result
OleStrohm Aug 7, 2022
5313bd1
Cleaned up code based on feedback
OleStrohm Sep 12, 2022
177ec82
Rebased
OleStrohm Sep 12, 2022
3931e55
Fixed lints
OleStrohm Sep 12, 2022
3d28a1a
Warn about safety of `fetch_update`
Riolku Sep 14, 2022
ed0cf1c
Add functionality to unwrap tuple declarations
harudagondi Sep 17, 2022
d9f5709
Simplify feature representation in CargoConfig
Veykril Sep 19, 2022
bc6d574
Auto merge of #13259 - Veykril:cargo-config-simplify, r=Veykril
bors Sep 19, 2022
a6c067c
Simplify
Veykril Sep 19, 2022
4f2c86e
Auto merge of #13260 - Veykril:simplify, r=Veykril
bors Sep 19, 2022
cdc362e
docs(inlay-hints): remove reference to Toggle inlay hints
didibear Sep 19, 2022
4d989b5
Auto merge of #13262 - DidiBear:master, r=lnicola
bors Sep 19, 2022
f87ad8d
Added FIXME for the repr type of the enum
OleStrohm Sep 19, 2022
9845e37
Ensure at least one trait bound in `TyKind::DynTy`
lowr Sep 19, 2022
bde76b9
Auto merge of #13264 - lowr:patch/no-dyn-without-trait, r=Veykril
bors Sep 19, 2022
7e8eac3
Simplify
Veykril Sep 20, 2022
027bfd6
Fix operator highlighting tags applying too broadly
Veykril Sep 20, 2022
09600a3
Auto merge of #13268 - Veykril:simplify, r=Veykril
bors Sep 20, 2022
817a6a8
Auto merge of #12966 - OleStrohm:master, r=Veykril
bors Sep 20, 2022
6d0d051
Simplify
Veykril Sep 20, 2022
9f233cd
Parse more repr options
Veykril Sep 20, 2022
b25f0ba
Properly set the enum variant body expected type
Veykril Sep 20, 2022
2119c1f
Fix using incorrect type for variants in DefWithBody::body_type
Veykril Sep 20, 2022
9bf386f
Fix default enum representation not being isize
Veykril Sep 20, 2022
5b49745
Auto merge of #13269 - Veykril:repr, r=Veykril
bors Sep 20, 2022
c2dc32c
return None instead of assert
harudagondi Sep 21, 2022
9ede5f0
Implement `HirDisplay` for `TyKind::Generator`
lowr Sep 21, 2022
40e8f03
docs(guide): fix Analysis and AnalysisHost doc links
oknozor Sep 22, 2022
729a9eb
Fix find_path using the wrong module for visibility calculations
Veykril Sep 22, 2022
fb0ce25
Add RequestFailed error code, as per spec 3.17
alanz Sep 23, 2022
f57cd83
Don't run proc-macro-srv tests on the rust-analyzer repo
Veykril Sep 23, 2022
1440078
Auto merge of #13286 - Veykril:proc-macro-srv-tests, r=Veykril
bors Sep 23, 2022
7ec9ffa
Properly support IDE functionality in enum variants
Veykril Sep 23, 2022
4e7bb5e
Auto merge of #13285 - Veykril:variant-body, r=Veykril
bors Sep 24, 2022
0231d19
Fix diagnostics not working in enum variant bodies
Veykril Sep 24, 2022
fa38c10
Auto merge of #13288 - Veykril:variant-body, r=Veykril
bors Sep 24, 2022
73f6af5
Use the sysroot proc-macro server for analysis-stats
Veykril Sep 24, 2022
73ab709
Auto merge of #13289 - rust-lang:analysis-stats-proc-server, r=Veykril
bors Sep 24, 2022
2ea770d
fs::get_path solarish version.
devnexen Sep 24, 2022
1f92965
Auto merge of #13209 - lowr:feat/inference-for-generator, r=Veykril
bors Sep 26, 2022
7929e9c
Remove obsolete in-rust-tree feature from sourcegen
Veykril Sep 26, 2022
1a24003
Auto merge of #13248 - harudagondi:unwrap-tuple, r=Veykril
bors Sep 26, 2022
aa093f5
Fix PackageInformation having the crate name instead of package name
Strum355 Sep 26, 2022
60b432b
fix model tests
Strum355 Sep 26, 2022
651c586
formatting
Strum355 Sep 26, 2022
89107d5
Emit unconfigured code diagnostics for fields
unexge Sep 4, 2022
b21bf25
Collect diagnostics in queries instead of nameres
unexge Sep 21, 2022
3a8d84b
Use `Arc<[DefDiagnostic]>` instead of `Arc<Vec<DefDiagnostic>>`
unexge Sep 26, 2022
7e5e517
Generate `From` impls manually
unexge Sep 26, 2022
8c7e376
Auto merge of #13275 - Veykril:find-path, r=Veykril
bors Sep 27, 2022
f972cdd
Auto merge of #13295 - rust-lang:sourcegen, r=Veykril
bors Sep 27, 2022
fb73644
Use cfg(any()) instead of cfg(FALSE) for disabling proc-macro test
Veykril Sep 27, 2022
b01cdd8
Auto merge of #13189 - unexge:unconfigured-diagnostics-for-fields, r=…
bors Sep 27, 2022
8805d05
Auto merge of #13296 - Strum355:package-information-package-name, r=V…
bors Sep 27, 2022
bd8c5b6
Auto merge of #13300 - Veykril:cfg-false, r=Veykril
bors Sep 27, 2022
c3a6c96
Amalgamate file changes for the same file ids in process_changes
Veykril Sep 15, 2022
093de32
Auto merge of #13237 - Veykril:process-changes, r=Veykril
bors Sep 27, 2022
03aa704
Auto merge of #13280 - alanz:errorcode-requestfailed, r=Veykril
bors Sep 27, 2022
b16b041
Auto merge of #13272 - oknozor:master, r=Veykril
bors Sep 27, 2022
1a6c159
Don't retry requests that have already been cancelled
Veykril Sep 7, 2022
9ba55ba
Auto merge of #13202 - Veykril:cancelled-retry, r=Veykril
bors Sep 27, 2022
f5fe6b1
Make assist tests panic again on empty source changes
Veykril Sep 27, 2022
ad752bd
Auto merge of #13301 - Veykril:empty-assist-source-changes, r=Veykril
bors Sep 27, 2022
9d5e3a1
Add `is_empty()` method to `core::ffi::CStr`.
jmillikin Sep 18, 2022
6d8903a
fix: infer for-loop item type with `IntoIterator` and `Iterator`
lowr Sep 29, 2022
97f8f4a
Auto merge of #13311 - lowr:fix/for-loop-item-resolution, r=Veykril
bors Sep 29, 2022
2c72ea7
Stabilize map_first_last
est31 Sep 12, 2022
8c433c7
Fix requests not being retried anymore
Veykril Sep 30, 2022
8132b42
Auto merge of #13319 - Veykril:req-retry, r=Veykril
bors Sep 30, 2022
3cd57c4
Fix annotations not resolving when lens location is set to whole item
Veykril Sep 30, 2022
77cfc9b
Fix type alias hovers not rendering generic parameters
Veykril Sep 30, 2022
17363b3
Auto merge of #13320 - Veykril:ty-alias-hover, r=Veykril
bors Sep 30, 2022
2293949
Auto merge of #13318 - Veykril:annotations, r=Veykril
bors Sep 30, 2022
3ad0334
Fix move_format_string_arg being tokentree unaware
Veykril Sep 30, 2022
5b7e400
Auto merge of #13321 - Veykril:format-str-args, r=Veykril
bors Sep 30, 2022
bfd5f00
Fix trait impl item completions using macro file text ranges
Veykril Oct 1, 2022
f88293f
Auto merge of #13324 - Veykril:trait-impl-completion, r=Veykril
bors Oct 1, 2022
26cf250
Do not use the sysroot proc-macro server when a server path is given …
Veykril Oct 1, 2022
bf5cad8
Auto merge of #13326 - Veykril:proc-macro-srv-config, r=Veykril
bors Oct 1, 2022
5424c51
Add config for supplying sysroot path
Veykril Oct 1, 2022
cdc5493
Auto merge of #13327 - Veykril:proc-macro-srv-config, r=Veykril
bors Oct 1, 2022
870825b
Add proc-macro dependency to rustc crates
Veykril Oct 1, 2022
5c28ad1
Auto merge of #13328 - Veykril:rustc-proc-macro, r=Veykril
bors Oct 1, 2022
f8f5a5e
refactor: use `cast()` instead of interning `GenericArgData`
lowr Oct 2, 2022
4385d3d
Change generic parameter/argument order
lowr Oct 2, 2022
78977cd
Adapt to the new generic parameter/argument order
lowr Oct 2, 2022
7556f74
Remove hack
lowr Oct 2, 2022
5916803
Prioritize restart messages in flycheck
Veykril Oct 3, 2022
f087ebe
Auto merge of #13338 - Veykril:flycheck, r=Veykril
bors Oct 3, 2022
5bd98e3
Auto merge of #13335 - lowr:patch/change-generic-param-order, r=Veykril
bors Oct 3, 2022
e0a161b
fix: treat enum variants as generic item on their own
lowr Oct 3, 2022
974caaf
Auto merge of #13339 - lowr:patch/change-generic-param-order, r=Veykril
bors Oct 3, 2022
e0c9e28
Revert "Add proc-macro dependency to rustc crates"
Veykril Oct 4, 2022
b429df2
Auto merge of #13342 - rust-lang:revert-13328-rustc-proc-macro, r=Vey…
bors Oct 4, 2022
ded3326
fix: use `BoundVar`s from current generic scope
lowr Oct 4, 2022
476d043
Auto merge of #13344 - lowr:patch/change-generic-param-order, r=Veykril
bors Oct 4, 2022
8bda133
Interpret EH actions properly
nbdd0121 Oct 5, 2022
8862fe6
Fix assertion failure in type inference (#13352)
wildbook Oct 5, 2022
a57ef6b
Fix go-to-def for shadowed `include*!`
WaffleLapkin Oct 6, 2022
f2f3528
Auto merge of #13356 - WaffleLapkin:go_to_def_shadow_include, r=Veykril
bors Oct 6, 2022
a415fb4
Auto merge of #13353 - wildbook:fix_type_inference_panic, r=Veykril
bors Oct 6, 2022
1c0ec9f
Fix go-to-def for `#[doc = include_str!("path")]`
WaffleLapkin Oct 7, 2022
8437e4b
Auto merge of #13362 - WaffleLapkin:go_to_def_fix_doc_include_str, r=…
bors Oct 7, 2022
b0b072d
ADD - codegen_ssa initial diags translations machinery
JhonnyBillM Oct 4, 2022
4e0de53
ADD - migrate lib.def write fatal error
JhonnyBillM Aug 25, 2022
0a2d7f8
UPDATE - LibDefWriteFailure to accept type instead of formatted string
JhonnyBillM Aug 27, 2022
086e70f
UPDATE - migrate linker.rs to new diagnostics infra
JhonnyBillM Oct 7, 2022
d9197db
UPDATE - migrate write.rs to new diagnostics infra
JhonnyBillM Aug 28, 2022
67eb01c
UPDATE - codege-ssa errors to new Diagnostic macro name
JhonnyBillM Sep 10, 2022
7548d95
UPDATE - resolve fixme and emit errors via Handler
JhonnyBillM Sep 10, 2022
0f97d4a
DELETE - unused error after PR# 100101 was merged
JhonnyBillM Sep 13, 2022
12aa84b
ADD - initial port of link.rs
JhonnyBillM Oct 3, 2022
a25f939
Address PR comments
JhonnyBillM Oct 4, 2022
13d4f27
ADD - implement IntoDiagnostic for thorin::Error wrapper
JhonnyBillM Oct 4, 2022
39fa8b5
internal: :arrow_up: xflags
matklad Oct 8, 2022
61504c8
Auto merge of #13366 - matklad:xflags, r=lnicola
bors Oct 8, 2022
61519b8
Add basename and dirname aliases
azdavis Oct 10, 2022
6826028
fix #102878
TaKO8Ki Oct 10, 2022
d1762d7
Do not alias for fs
azdavis Oct 11, 2022
1a8f177
rustc_hir: Less error-prone methods for accessing `PartialRes` resolu…
petrochenkov Oct 10, 2022
152cd63
Report duplicate definitions in trait impls during resolution.
cjgillot Aug 10, 2022
c867288
:arrow_up: rust-analyzer
lnicola Oct 11, 2022
6d58ff7
Rollup merge of #100387 - cjgillot:hygiene-trait-impl, r=petrochenkov
matthiaskrgr Oct 11, 2022
cadb37a
Rollup merge of #101727 - est31:stabilize_map_first_last, r=m-ou-se
matthiaskrgr Oct 11, 2022
d13f7ae
Rollup merge of #101774 - Riolku:atomic-update-aba, r=m-ou-se
matthiaskrgr Oct 11, 2022
51320b3
Rollup merge of #102227 - devnexen:solarish_get_path, r=m-ou-se
matthiaskrgr Oct 11, 2022
d10b47e
Rollup merge of #102445 - jmillikin:cstr-is-empty, r=Mark-Simulacrum
matthiaskrgr Oct 11, 2022
24722e8
Rollup merge of #102612 - JhonnyBillM:migrate-codegen-ssa-to-diagnost…
matthiaskrgr Oct 11, 2022
1b1223d
Rollup merge of #102685 - nbdd0121:unwind, r=m-ou-se
matthiaskrgr Oct 11, 2022
ccde95f
Rollup merge of #102869 - azdavis:master, r=joshtriplett
matthiaskrgr Oct 11, 2022
cb67283
Rollup merge of #102889 - petrochenkov:partres, r=cjgillot
matthiaskrgr Oct 11, 2022
a13c7da
Rollup merge of #102893 - TaKO8Ki:fix-102878, r=davidtwco
matthiaskrgr Oct 11, 2022
3e01d07
Rollup merge of #102912 - lnicola:rust-analyzer-2022-10-11, r=lnicola
matthiaskrgr Oct 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions compiler/rustc_ast_lowering/src/asm.rs
Expand Up @@ -205,13 +205,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let static_def_id = self
.resolver
.get_partial_res(sym.id)
.filter(|res| res.unresolved_segments() == 0)
.and_then(|res| {
if let Res::Def(DefKind::Static(_), def_id) = res.base_res() {
Some(def_id)
} else {
None
}
.and_then(|res| res.full_res())
.and_then(|res| match res {
Res::Def(DefKind::Static(_), def_id) => Some(def_id),
_ => None,
});

if let Some(def_id) = static_def_id {
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_ast_lowering/src/expr.rs
Expand Up @@ -1044,9 +1044,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
if let ExprKind::Path(qself, path) = &expr.kind {
// Does the path resolve to something disallowed in a tuple struct/variant pattern?
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
if partial_res.unresolved_segments() == 0
&& !partial_res.base_res().expected_in_tuple_struct_pat()
{
if let Some(res) = partial_res.full_res() && !res.expected_in_tuple_struct_pat() {
return None;
}
}
Expand All @@ -1066,9 +1064,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
if let ExprKind::Path(qself, path) = &expr.kind {
// Does the path resolve to something disallowed in a unit struct/variant pattern?
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
if partial_res.unresolved_segments() == 0
&& !partial_res.base_res().expected_in_unit_struct_pat()
{
if let Some(res) = partial_res.full_res() && !res.expected_in_unit_struct_pat() {
return None;
}
}
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_ast_lowering/src/item.rs
Expand Up @@ -947,7 +947,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
AssocItemKind::MacCall(..) => unimplemented!(),
},
trait_item_def_id: self.resolver.get_partial_res(i.id).map(|r| r.base_res().def_id()),
trait_item_def_id: self
.resolver
.get_partial_res(i.id)
.map(|r| r.expect_full_res().def_id()),
}
}

Expand Down Expand Up @@ -1349,9 +1352,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
match self
.resolver
.get_partial_res(bound_pred.bounded_ty.id)
.map(|d| (d.base_res(), d.unresolved_segments()))
.and_then(|r| r.full_res())
{
Some((Res::Def(DefKind::TyParam, def_id), 0))
Some(Res::Def(DefKind::TyParam, def_id))
if bound_pred.bound_generic_params.is_empty() =>
{
generics
Expand Down
24 changes: 8 additions & 16 deletions compiler/rustc_ast_lowering/src/lib.rs
Expand Up @@ -175,12 +175,7 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
return None;
}

let partial_res = self.partial_res_map.get(&expr.id)?;
if partial_res.unresolved_segments() != 0 {
return None;
}

if let Res::Def(DefKind::Fn, def_id) = partial_res.base_res() {
if let Res::Def(DefKind::Fn, def_id) = self.partial_res_map.get(&expr.id)?.full_res()? {
// We only support cross-crate argument rewriting. Uses
// within the same crate should be updated to use the new
// const generics style.
Expand Down Expand Up @@ -753,12 +748,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

fn expect_full_res(&mut self, id: NodeId) -> Res<NodeId> {
self.resolver.get_partial_res(id).map_or(Res::Err, |pr| {
if pr.unresolved_segments() != 0 {
panic!("path not fully resolved: {:?}", pr);
}
pr.base_res()
})
self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
}

fn expect_full_res_from_use(&mut self, id: NodeId) -> impl Iterator<Item = Res<NodeId>> {
Expand Down Expand Up @@ -1138,8 +1128,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// type and value namespaces. If we resolved the path in the value namespace, we
// transform it into a generic const argument.
TyKind::Path(ref qself, ref path) => {
if let Some(partial_res) = self.resolver.get_partial_res(ty.id) {
let res = partial_res.base_res();
if let Some(res) = self
.resolver
.get_partial_res(ty.id)
.and_then(|partial_res| partial_res.full_res())
{
if !res.matches_ns(Namespace::TypeNS) {
debug!(
"lower_generic_arg: Lowering type argument as const argument: {:?}",
Expand Down Expand Up @@ -1206,8 +1199,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// by `ty_path`.
if qself.is_none()
&& let Some(partial_res) = self.resolver.get_partial_res(t.id)
&& partial_res.unresolved_segments() == 0
&& let Res::Def(DefKind::Trait | DefKind::TraitAlias, _) = partial_res.base_res()
&& let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
{
let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
let poly_trait_ref = this.ast_arena.ptr.alloc(PolyTraitRef {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/pat.rs
Expand Up @@ -239,7 +239,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ident: Ident,
lower_sub: impl FnOnce(&mut Self) -> Option<&'hir hir::Pat<'hir>>,
) -> hir::PatKind<'hir> {
match self.resolver.get_partial_res(p.id).map(|d| d.base_res()) {
match self.resolver.get_partial_res(p.id).map(|d| d.expect_full_res()) {
// `None` can occur in body-less function signatures
res @ (None | Some(Res::Local(_))) => {
let canonical_id = match res {
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_ast_lowering/src/path.rs
Expand Up @@ -29,11 +29,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

let partial_res =
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));
let base_res = partial_res.base_res();
let unresolved_segments = partial_res.unresolved_segments();

let path_span_lo = p.span.shrink_to_lo();
let proj_start = p.segments.len() - partial_res.unresolved_segments();
let proj_start = p.segments.len() - unresolved_segments;
let path = self.arena.alloc(hir::Path {
res: self.lower_res(partial_res.base_res()),
res: self.lower_res(base_res),
segments: self.arena.alloc_from_iter(p.segments[..proj_start].iter().enumerate().map(
|(i, segment)| {
let param_mode = match (qself_position, param_mode) {
Expand All @@ -46,7 +48,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
_ => param_mode,
};

let parenthesized_generic_args = match partial_res.base_res() {
let parenthesized_generic_args = match base_res {
// `a::b::Trait(Args)`
Res::Def(DefKind::Trait, _) if i + 1 == proj_start => {
ParenthesizedGenericArgs::Ok
Expand Down Expand Up @@ -83,7 +85,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

// Simple case, either no projections, or only fully-qualified.
// E.g., `std::mem::size_of` or `<I as Iterator>::Item`.
if partial_res.unresolved_segments() == 0 {
if unresolved_segments == 0 {
return hir::QPath::Resolved(qself, path);
}

Expand Down
82 changes: 30 additions & 52 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Expand Up @@ -31,7 +31,9 @@ use super::command::Command;
use super::linker::{self, Linker};
use super::metadata::{create_rmeta_file, MetadataPosition};
use super::rpath::{self, RPathConfig};
use crate::{looks_like_rust_object_file, CodegenResults, CompiledModule, CrateInfo, NativeLib};
use crate::{
errors, looks_like_rust_object_file, CodegenResults, CompiledModule, CrateInfo, NativeLib,
};

use cc::windows_registry;
use regex::Regex;
Expand Down Expand Up @@ -93,7 +95,7 @@ pub fn link_binary<'a>(
let tmpdir = TempFileBuilder::new()
.prefix("rustc")
.tempdir()
.unwrap_or_else(|err| sess.fatal(&format!("couldn't create a temp dir: {}", err)));
.unwrap_or_else(|error| sess.emit_fatal(errors::CreateTempDir { error }));
let path = MaybeTempDir::new(tmpdir, sess.opts.cg.save_temps);
let out_filename = out_filename(
sess,
Expand Down Expand Up @@ -208,7 +210,7 @@ pub fn link_binary<'a>(
pub fn each_linked_rlib(
info: &CrateInfo,
f: &mut dyn FnMut(CrateNum, &Path),
) -> Result<(), String> {
) -> Result<(), errors::LinkRlibError> {
let crates = info.used_crates.iter();
let mut fmts = None;
for (ty, list) in info.dependency_formats.iter() {
Expand All @@ -224,26 +226,23 @@ pub fn each_linked_rlib(
}
}
let Some(fmts) = fmts else {
return Err("could not find formats for rlibs".to_string());
return Err(errors::LinkRlibError::MissingFormat);
};
for &cnum in crates {
match fmts.get(cnum.as_usize() - 1) {
Some(&Linkage::NotLinked | &Linkage::IncludedFromDylib) => continue,
Some(_) => {}
None => return Err("could not find formats for rlibs".to_string()),
None => return Err(errors::LinkRlibError::MissingFormat),
}
let name = info.crate_name[&cnum];
let crate_name = info.crate_name[&cnum];
let used_crate_source = &info.used_crate_source[&cnum];
if let Some((path, _)) = &used_crate_source.rlib {
f(cnum, &path);
} else {
if used_crate_source.rmeta.is_some() {
return Err(format!(
"could not find rlib for: `{}`, found rmeta (metadata) file",
name
));
return Err(errors::LinkRlibError::OnlyRmetaFound { crate_name });
} else {
return Err(format!("could not find rlib for: `{}`", name));
return Err(errors::LinkRlibError::NotFound { crate_name });
}
}
}
Expand Down Expand Up @@ -340,10 +339,7 @@ fn link_rlib<'a>(
// -whole-archive and it isn't clear how we can currently handle such a
// situation correctly.
// See https://github.com/rust-lang/rust/issues/88085#issuecomment-901050897
sess.err(
"the linking modifiers `+bundle` and `+whole-archive` are not compatible \
with each other when generating rlibs",
);
sess.emit_err(errors::IncompatibleLinkingModifiers);
}
NativeLibKind::Static { bundle: None | Some(true), .. } => {}
NativeLibKind::Static { bundle: Some(false), .. }
Expand All @@ -365,12 +361,8 @@ fn link_rlib<'a>(
));
continue;
}
ab.add_archive(&location, Box::new(|_| false)).unwrap_or_else(|e| {
sess.fatal(&format!(
"failed to add native library {}: {}",
location.to_string_lossy(),
e
));
ab.add_archive(&location, Box::new(|_| false)).unwrap_or_else(|error| {
sess.emit_fatal(errors::AddNativeLibrary { library_path: location, error });
});
}
}
Expand All @@ -385,8 +377,8 @@ fn link_rlib<'a>(
tmpdir.as_ref(),
);

ab.add_archive(&output_path, Box::new(|_| false)).unwrap_or_else(|e| {
sess.fatal(&format!("failed to add native library {}: {}", output_path.display(), e));
ab.add_archive(&output_path, Box::new(|_| false)).unwrap_or_else(|error| {
sess.emit_fatal(errors::AddNativeLibrary { library_path: output_path, error });
});
}

Expand Down Expand Up @@ -451,14 +443,11 @@ fn collate_raw_dylibs(
// FIXME: when we add support for ordinals, figure out if we need to do anything
// if we have two DllImport values with the same name but different ordinals.
if import.calling_convention != old_import.calling_convention {
sess.span_err(
import.span,
&format!(
"multiple declarations of external function `{}` from \
library `{}` have different calling conventions",
import.name, name,
),
);
sess.emit_err(errors::MultipleExternalFuncDecl {
span: import.span,
function: import.name,
library_name: &name,
});
}
}
}
Expand Down Expand Up @@ -560,7 +549,7 @@ fn link_staticlib<'a>(
all_native_libs.extend(codegen_results.crate_info.native_libraries[&cnum].iter().cloned());
});
if let Err(e) = res {
sess.fatal(&e);
sess.emit_fatal(e);
}

ab.build(out_filename);
Expand Down Expand Up @@ -673,9 +662,7 @@ fn link_dwarf_object<'a>(
}) {
Ok(()) => {}
Err(e) => {
sess.struct_err("linking dwarf objects with thorin failed")
.note(&format!("{:?}", e))
.emit();
sess.emit_err(errors::ThorinErrorWrapper(e));
sess.abort_if_errors();
}
}
Expand Down Expand Up @@ -879,23 +866,14 @@ fn link_natively<'a>(
let mut output = prog.stderr.clone();
output.extend_from_slice(&prog.stdout);
let escaped_output = escape_string(&output);
let mut err = sess.struct_err(&format!(
"linking with `{}` failed: {}",
linker_path.display(),
prog.status
));
err.note(&format!("{:?}", &cmd)).note(&escaped_output);
if escaped_output.contains("undefined reference to") {
err.help(
"some `extern` functions couldn't be found; some native libraries may \
need to be installed or have their path specified",
);
err.note("use the `-l` flag to specify native libraries to link");
err.note("use the `cargo:rustc-link-lib` directive to specify the native \
libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)");
}
err.emit();

// FIXME: Add UI tests for this error.
let err = errors::LinkingFailed {
linker_path: &linker_path,
exit_status: prog.status,
command: &cmd,
escaped_output: &escaped_output,
};
sess.diagnostic().emit_err(err);
// If MSVC's `link.exe` was expected but the return code
// is not a Microsoft LNK error then suggest a way to fix or
// install the Visual Studio build tools.
Expand Down