Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b17226f

Browse files
committed
Auto merge of rust-lang#94121 - matthiaskrgr:rollup-6ps95da, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#92683 (Suggest copying trait associated type bounds on lifetime error) - rust-lang#92933 (Deny mixing bin crate type with lib crate types) - rust-lang#92959 (Add more info and suggestions to use of #[test] on invalid items) - rust-lang#93024 (Do not ICE when inlining a function with un-satisfiable bounds) - rust-lang#93613 (Move `{core,std}::stream::Stream` to `{core,std}::async_iter::AsyncIterator`) - rust-lang#93634 (compiler: clippy::complexity fixes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b8c56fa + a144ea1 commit b17226f

File tree

59 files changed

+613
-221
lines changed

Some content is hidden

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

59 files changed

+613
-221
lines changed

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl AttrItem {
230230
}
231231

232232
pub fn meta_kind(&self) -> Option<MetaItemKind> {
233-
Some(MetaItemKind::from_mac_args(&self.args)?)
233+
MetaItemKind::from_mac_args(&self.args)
234234
}
235235
}
236236

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ fn maybe_stage_features(sess: &Session, krate: &ast::Crate) {
823823
);
824824
let mut all_stable = true;
825825
for ident in
826-
attr.meta_item_list().into_iter().flatten().map(|nested| nested.ident()).flatten()
826+
attr.meta_item_list().into_iter().flatten().flat_map(|nested| nested.ident())
827827
{
828828
let name = ident.name;
829829
let stable_since = lang_features

compiler/rustc_builtin_macros/src/proc_macro_harness.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub fn inject(
5656
is_proc_macro_crate: bool,
5757
has_proc_macro_decls: bool,
5858
is_test_crate: bool,
59-
num_crate_types: usize,
6059
handler: &rustc_errors::Handler,
6160
) -> ast::Crate {
6261
let ecfg = ExpansionConfig::default("proc_macro".to_string());
@@ -81,10 +80,6 @@ pub fn inject(
8180
return krate;
8281
}
8382

84-
if num_crate_types > 1 {
85-
handler.err("cannot mix `proc-macro` crate type with others");
86-
}
87-
8883
if is_test_crate {
8984
return krate;
9085
}

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_ast as ast;
66
use rustc_ast::attr;
77
use rustc_ast::ptr::P;
88
use rustc_ast_pretty::pprust;
9+
use rustc_errors::Applicability;
910
use rustc_expand::base::*;
1011
use rustc_session::Session;
1112
use rustc_span::symbol::{sym, Ident, Symbol};
@@ -102,11 +103,20 @@ pub fn expand_test_or_bench(
102103
}
103104
};
104105

105-
if let ast::ItemKind::MacCall(_) = item.kind {
106-
cx.sess.parse_sess.span_diagnostic.span_warn(
107-
item.span,
108-
"`#[test]` attribute should not be used on macros. Use `#[cfg(test)]` instead.",
109-
);
106+
// Note: non-associated fn items are already handled by `expand_test_or_bench`
107+
if !matches!(item.kind, ast::ItemKind::Fn(_)) {
108+
cx.sess
109+
.parse_sess
110+
.span_diagnostic
111+
.struct_span_err(
112+
attr_sp,
113+
"the `#[test]` attribute may only be used on a non-associated function",
114+
)
115+
.note("the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions")
116+
.span_label(item.span, format!("expected a non-associated function, found {} {}", item.kind.article(), item.kind.descr()))
117+
.span_suggestion(attr_sp, "replace with conditional compilation to make the item only exist when tests are being run", String::from("#[cfg(test)]"), Applicability::MaybeIncorrect)
118+
.emit();
119+
110120
return vec![Annotatable::Item(item)];
111121
}
112122

@@ -466,7 +476,7 @@ fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
466476
(false, _) => true,
467477
}
468478
} else {
469-
sd.span_err(i.span, "only functions may be used as tests");
479+
// should be unreachable because `is_test_fn_item` should catch all non-fn items
470480
false
471481
}
472482
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ pub unsafe fn create_module<'ll>(
292292
"sign-return-address-all\0".as_ptr().cast(),
293293
pac_opts.leaf.into(),
294294
);
295-
let is_bkey = if pac_opts.key == PAuthKey::A { false } else { true };
295+
let is_bkey: bool = pac_opts.key != PAuthKey::A;
296296
llvm::LLVMRustAddModuleFlag(
297297
llmod,
298298
llvm::LLVMModFlagBehavior::Error,

compiler/rustc_codegen_ssa/src/mir/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
476476
mir::ProjectionElem::Subslice { from, to, from_end } => {
477477
let mut subslice = cg_base.project_index(bx, bx.cx().const_usize(from as u64));
478478
let projected_ty =
479-
PlaceTy::from_ty(cg_base.layout.ty).projection_ty(tcx, elem.clone()).ty;
479+
PlaceTy::from_ty(cg_base.layout.ty).projection_ty(tcx, *elem).ty;
480480
subslice.layout = bx.cx().layout_of(self.monomorphize(projected_ty));
481481

482482
if subslice.layout.is_unsized() {

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ fn check_matcher_core(
10391039
));
10401040
err.span_suggestion(
10411041
span,
1042-
&format!("try a `pat_param` fragment specifier instead"),
1042+
"try a `pat_param` fragment specifier instead",
10431043
suggestion,
10441044
Applicability::MaybeIncorrect,
10451045
);

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> {
6464
.or_else(|| self.try_report_mismatched_static_lifetime())
6565
}
6666

67-
pub fn regions(&self) -> Option<(Span, ty::Region<'tcx>, ty::Region<'tcx>)> {
67+
pub(super) fn regions(&self) -> Option<(Span, ty::Region<'tcx>, ty::Region<'tcx>)> {
6868
match (&self.error, self.regions) {
6969
(Some(ConcreteFailure(origin, sub, sup)), None) => Some((origin.span(), *sub, *sup)),
7070
(Some(SubSupConflict(_, _, origin, sub, _, sup, _)), None) => {

compiler/rustc_infer/src/infer/error_reporting/note.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
102102
"...so that the definition in impl matches the definition from the trait",
103103
);
104104
}
105+
infer::CheckAssociatedTypeBounds { ref parent, .. } => {
106+
self.note_region_origin(err, &parent);
107+
}
105108
}
106109
}
107110

@@ -345,6 +348,55 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
345348
trait_item_def_id,
346349
&format!("`{}: {}`", sup, sub),
347350
),
351+
infer::CheckAssociatedTypeBounds { impl_item_def_id, trait_item_def_id, parent } => {
352+
let mut err = self.report_concrete_failure(*parent, sub, sup);
353+
354+
let trait_item_span = self.tcx.def_span(trait_item_def_id);
355+
let item_name = self.tcx.item_name(impl_item_def_id);
356+
err.span_label(
357+
trait_item_span,
358+
format!("definition of `{}` from trait", item_name),
359+
);
360+
361+
let trait_predicates = self.tcx.explicit_predicates_of(trait_item_def_id);
362+
let impl_predicates = self.tcx.explicit_predicates_of(impl_item_def_id);
363+
364+
let impl_predicates: rustc_data_structures::stable_set::FxHashSet<_> =
365+
impl_predicates.predicates.into_iter().map(|(pred, _)| pred).collect();
366+
let clauses: Vec<_> = trait_predicates
367+
.predicates
368+
.into_iter()
369+
.filter(|&(pred, _)| !impl_predicates.contains(pred))
370+
.map(|(pred, _)| format!("{}", pred))
371+
.collect();
372+
373+
if !clauses.is_empty() {
374+
let where_clause_span = self
375+
.tcx
376+
.hir()
377+
.get_generics(impl_item_def_id.expect_local())
378+
.unwrap()
379+
.where_clause
380+
.tail_span_for_suggestion();
381+
382+
let suggestion = format!(
383+
"{} {}",
384+
if !impl_predicates.is_empty() { "," } else { " where" },
385+
clauses.join(", "),
386+
);
387+
err.span_suggestion(
388+
where_clause_span,
389+
&format!(
390+
"try copying {} from the trait",
391+
if clauses.len() > 1 { "these clauses" } else { "this clause" }
392+
),
393+
suggestion,
394+
rustc_errors::Applicability::MaybeIncorrect,
395+
);
396+
}
397+
398+
err
399+
}
348400
}
349401
}
350402

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,13 @@ pub enum SubregionOrigin<'tcx> {
438438
/// Comparing the signature and requirements of an impl associated type
439439
/// against the containing trait
440440
CompareImplTypeObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },
441+
442+
/// Checking that the bounds of a trait's associated type hold for a given impl
443+
CheckAssociatedTypeBounds {
444+
parent: Box<SubregionOrigin<'tcx>>,
445+
impl_item_def_id: DefId,
446+
trait_item_def_id: DefId,
447+
},
441448
}
442449

443450
// `SubregionOrigin` is used a lot. Make sure it doesn't unintentionally get bigger.
@@ -1832,6 +1839,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
18321839
ReferenceOutlivesReferent(_, a) => a,
18331840
CompareImplMethodObligation { span, .. } => span,
18341841
CompareImplTypeObligation { span, .. } => span,
1842+
CheckAssociatedTypeBounds { ref parent, .. } => parent.span(),
18351843
}
18361844
}
18371845

@@ -1862,6 +1870,15 @@ impl<'tcx> SubregionOrigin<'tcx> {
18621870
trait_item_def_id,
18631871
},
18641872

1873+
traits::ObligationCauseCode::CheckAssociatedTypeBounds {
1874+
impl_item_def_id,
1875+
trait_item_def_id,
1876+
} => SubregionOrigin::CheckAssociatedTypeBounds {
1877+
impl_item_def_id,
1878+
trait_item_def_id,
1879+
parent: Box::new(default()),
1880+
},
1881+
18651882
_ => default(),
18661883
}
18671884
}

0 commit comments

Comments
 (0)