Skip to content

Commit 0d53135

Browse files
committed
Auto merge of rust-lang#120715 - matthiaskrgr:rollup-sp1pp74, r=matthiaskrgr
Rollup of 12 pull requests Successful merges: - rust-lang#120520 (Some cleanups around diagnostic levels.) - rust-lang#120575 (Simplify codegen diagnostic handling) - rust-lang#120597 (Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved) - rust-lang#120602 (rustc_monomorphize: fix outdated comment in partition) - rust-lang#120609 (hir: Stop keeping prefixes for most of `use` list stems) - rust-lang#120631 (Emit a diagnostic for invalid target options) - rust-lang#120632 (For E0223, suggest associated functions that are similar to the path) - rust-lang#120670 (cleanup effect var handling) - rust-lang#120673 (rustc_metadata: fix typo) - rust-lang#120683 (miri: fix ICE with symbolic alignment check on extern static) - rust-lang#120690 (Remove b-naber from the compiler review rotation) - rust-lang#120713 (Make async closures test use async bound modifier) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4a2fe44 + d98a8a1 commit 0d53135

Some content is hidden

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

52 files changed

+665
-370
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
498498
}
499499
}
500500

501-
let res =
502-
self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
501+
let res = self.lower_import_res(id, path.span);
503502
let path = self.lower_use_path(res, &path, ParamMode::Explicit);
504503
hir::ItemKind::Use(path, hir::UseKind::Single)
505504
}
@@ -535,7 +534,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
535534
// for that we return the `{}` import (called the
536535
// `ListStem`).
537536

538-
let prefix = Path { segments, span: prefix.span.to(path.span), tokens: None };
537+
let span = prefix.span.to(path.span);
538+
let prefix = Path { segments, span, tokens: None };
539539

540540
// Add all the nested `PathListItem`s to the HIR.
541541
for &(ref use_tree, id) in trees {
@@ -569,9 +569,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
569569
});
570570
}
571571

572-
let res =
573-
self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
574-
let path = self.lower_use_path(res, &prefix, ParamMode::Explicit);
572+
let path = if trees.is_empty() && !prefix.segments.is_empty() {
573+
// For empty lists we need to lower the prefix so it is checked for things
574+
// like stability later.
575+
let res = self.lower_import_res(id, span);
576+
self.lower_use_path(res, &prefix, ParamMode::Explicit)
577+
} else {
578+
// For non-empty lists we can just drop all the data, the prefix is already
579+
// present in HIR as a part of nested imports.
580+
self.arena.alloc(hir::UsePath { res: smallvec![], segments: &[], span })
581+
};
575582
hir::ItemKind::Use(path, hir::UseKind::ListStem)
576583
}
577584
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
6464
use rustc_session::parse::{add_feature_diagnostics, feature_err};
6565
use rustc_span::symbol::{kw, sym, Ident, Symbol};
6666
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
67-
use smallvec::SmallVec;
67+
use smallvec::{smallvec, SmallVec};
6868
use std::collections::hash_map::Entry;
6969
use thin_vec::ThinVec;
7070

@@ -750,8 +750,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
750750
self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
751751
}
752752

753-
fn expect_full_res_from_use(&mut self, id: NodeId) -> impl Iterator<Item = Res<NodeId>> {
754-
self.resolver.get_import_res(id).present_items()
753+
fn lower_import_res(&mut self, id: NodeId, span: Span) -> SmallVec<[Res; 3]> {
754+
let res = self.resolver.get_import_res(id).present_items();
755+
let res: SmallVec<_> = res.map(|res| self.lower_res(res)).collect();
756+
if res.is_empty() {
757+
self.dcx().span_delayed_bug(span, "no resolution for an import");
758+
return smallvec![Res::Err];
759+
}
760+
res
755761
}
756762

757763
fn make_lang_item_qpath(&mut self, lang_item: hir::LangItem, span: Span) -> hir::QPath<'hir> {

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
196196
p: &Path,
197197
param_mode: ParamMode,
198198
) -> &'hir hir::UsePath<'hir> {
199+
assert!((1..=3).contains(&res.len()));
199200
self.arena.alloc(hir::UsePath {
200201
res,
201202
segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| {

compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ codegen_llvm_invalid_minimum_alignment_not_power_of_two =
2828
codegen_llvm_invalid_minimum_alignment_too_large =
2929
invalid minimum global alignment: {$align} is too large
3030
31+
codegen_llvm_invalid_target_feature_prefix = target feature `{$feature}` must begin with a `+` or `-`"
32+
3133
codegen_llvm_load_bitcode = failed to load bitcode of module "{$name}"
3234
codegen_llvm_load_bitcode_with_llvm_err = failed to load bitcode of module "{$name}": {$llvm_err}
3335

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,9 @@ pub struct MismatchedDataLayout<'a> {
253253
pub llvm_target: &'a str,
254254
pub llvm_layout: &'a str,
255255
}
256+
257+
#[derive(Diagnostic)]
258+
#[diag(codegen_llvm_invalid_target_feature_prefix)]
259+
pub(crate) struct InvalidTargetFeaturePrefix<'a> {
260+
pub feature: &'a str,
261+
}

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::back::write::create_informational_target_machine;
22
use crate::errors::{
3-
PossibleFeature, TargetFeatureDisableOrEnable, UnknownCTargetFeature,
4-
UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
3+
InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable,
4+
UnknownCTargetFeature, UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
55
};
66
use crate::llvm;
77
use libc::c_int;
@@ -511,7 +511,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
511511
sess.target
512512
.features
513513
.split(',')
514-
.filter(|v| !v.is_empty() && backend_feature_name(v).is_some())
514+
.filter(|v| !v.is_empty() && backend_feature_name(sess, v).is_some())
515515
.map(String::from),
516516
);
517517

@@ -535,7 +535,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
535535
}
536536
};
537537

538-
let feature = backend_feature_name(s)?;
538+
let feature = backend_feature_name(sess, s)?;
539539
// Warn against use of LLVM specific feature names and unstable features on the CLI.
540540
if diagnostics {
541541
let feature_state = supported_features.iter().find(|&&(v, _)| v == feature);
@@ -611,11 +611,11 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
611611
/// Returns a feature name for the given `+feature` or `-feature` string.
612612
///
613613
/// Only allows features that are backend specific (i.e. not [`RUSTC_SPECIFIC_FEATURES`].)
614-
fn backend_feature_name(s: &str) -> Option<&str> {
614+
fn backend_feature_name<'a>(sess: &Session, s: &'a str) -> Option<&'a str> {
615615
// features must start with a `+` or `-`.
616-
let feature = s.strip_prefix(&['+', '-'][..]).unwrap_or_else(|| {
617-
bug!("target feature `{}` must begin with a `+` or `-`", s);
618-
});
616+
let feature = s
617+
.strip_prefix(&['+', '-'][..])
618+
.unwrap_or_else(|| sess.dcx().emit_fatal(InvalidTargetFeaturePrefix { feature: s }));
619619
// Rustc-specific feature requests like `+crt-static` or `-crt-static`
620620
// are not passed down to LLVM.
621621
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,7 @@ impl Translate for SharedEmitter {
18101810
}
18111811

18121812
impl Emitter for SharedEmitter {
1813-
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
1813+
fn emit_diagnostic(&mut self, diag: rustc_errors::Diagnostic) {
18141814
let args: FxHashMap<DiagnosticArgName, DiagnosticArgValue> =
18151815
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
18161816
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
993993
// Complain about any other kind of error -- those are bad because we'd like to
994994
// report them in a way that shows *where* in the value the issue lies.
995995
Err(err) => {
996-
bug!(
997-
"Unexpected Undefined Behavior error during validation: {}",
998-
self.format_error(err)
999-
);
996+
bug!("Unexpected error during validation: {}", self.format_error(err));
1000997
}
1001998
}
1002999
}

compiler/rustc_error_messages/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl From<Cow<'static, str>> for DiagnosticMessage {
378378
}
379379
}
380380

381-
/// A workaround for "good path" ICEs when formatting types in disabled lints.
381+
/// A workaround for good_path_delayed_bug ICEs when formatting types in disabled lints.
382382
///
383383
/// Delays formatting until `.into(): DiagnosticMessage` is used.
384384
pub struct DelayDm<F>(pub F);

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ impl Translate for AnnotateSnippetEmitter {
4444

4545
impl Emitter for AnnotateSnippetEmitter {
4646
/// The entry point for the diagnostics generation
47-
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
47+
fn emit_diagnostic(&mut self, mut diag: Diagnostic) {
4848
let fluent_args = to_fluent_args(diag.args());
4949

50-
let mut children = diag.children.clone();
51-
let (mut primary_span, suggestions) = self.primary_span_formatted(diag, &fluent_args);
50+
let mut suggestions = diag.suggestions.unwrap_or(vec![]);
51+
self.primary_span_formatted(&mut diag.span, &mut suggestions, &fluent_args);
5252

5353
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
54-
&mut primary_span,
55-
&mut children,
54+
&mut diag.span,
55+
&mut diag.children,
5656
&diag.level,
5757
self.macro_backtrace,
5858
);
@@ -62,9 +62,9 @@ impl Emitter for AnnotateSnippetEmitter {
6262
&diag.messages,
6363
&fluent_args,
6464
&diag.code,
65-
&primary_span,
66-
&children,
67-
suggestions,
65+
&diag.span,
66+
&diag.children,
67+
&suggestions,
6868
);
6969
}
7070

@@ -85,7 +85,11 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
8585
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
8686
fn annotation_type_for_level(level: Level) -> AnnotationType {
8787
match level {
88-
Level::Bug | Level::DelayedBug(_) | Level::Fatal | Level::Error => AnnotationType::Error,
88+
Level::Bug
89+
| Level::Fatal
90+
| Level::Error
91+
| Level::DelayedBug
92+
| Level::GoodPathDelayedBug => AnnotationType::Error,
8993
Level::ForceWarning(_) | Level::Warning => AnnotationType::Warning,
9094
Level::Note | Level::OnceNote => AnnotationType::Note,
9195
Level::Help | Level::OnceHelp => AnnotationType::Help,

0 commit comments

Comments
 (0)